diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2012-12-10 21:09:59 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2012-12-13 03:33:43 +0800 |
commit | d09d8de870b6697c8a8b262e7e077b871a69b315 (patch) | |
tree | 3b718882e7a0bb0a996daf2967a033d91714c9b5 /widgets/table | |
parent | b61331ed03ac1c7a9b8614e25510040b9c60ae02 (diff) | |
download | gsoc2013-evolution-d09d8de870b6697c8a8b262e7e077b871a69b315.tar.gz gsoc2013-evolution-d09d8de870b6697c8a8b262e7e077b871a69b315.tar.zst gsoc2013-evolution-d09d8de870b6697c8a8b262e7e077b871a69b315.zip |
Consolidate base utility libraries into libeutil.
Evolution consists of entirely too many small utility libraries, which
increases linking and loading time, places a burden on higher layers of
the application (e.g. modules) which has to remember to link to all the
small in-tree utility libraries, and makes it difficult to generate API
documentation for these utility libraries in one Gtk-Doc module.
Merge the following utility libraries under the umbrella of libeutil,
and enforce a single-include policy on libeutil so we can reorganize
the files as desired without disrupting its pseudo-public API.
libemail-utils/libemail-utils.la
libevolution-utils/libevolution-utils.la
filter/libfilter.la
widgets/e-timezone-dialog/libetimezonedialog.la
widgets/menus/libmenus.la
widgets/misc/libemiscwidgets.la
widgets/table/libetable.la
widgets/text/libetext.la
This also merges libedataserverui from the Evolution-Data-Server module,
since Evolution is its only consumer nowadays, and I'd like to make some
improvements to those APIs without concern for backward-compatibility.
And finally, start a Gtk-Doc module for libeutil. It's going to be a
project just getting all the symbols _listed_ much less _documented_.
But the skeletal structure is in place and I'm off to a good start.
Diffstat (limited to 'widgets/table')
157 files changed, 0 insertions, 59312 deletions
diff --git a/widgets/table/Makefile.am b/widgets/table/Makefile.am deleted file mode 100644 index 216a9fee98..0000000000 --- a/widgets/table/Makefile.am +++ /dev/null @@ -1,193 +0,0 @@ -ui_DATA = \ - e-table-config.ui - -privsolib_LTLIBRARIES = libetable.la - -libetable_la_CPPFLAGS = \ - $(AM_CPPFLAGS) \ - -I$(top_srcdir) \ - -I$(top_srcdir)/widgets \ - $(EVOLUTION_DATA_SERVER_CFLAGS) \ - $(GNOME_PLATFORM_CFLAGS) \ - -DEVOLUTION_UIDIR=\"$(uidir)\" \ - -DG_LOG_DOMAIN=\"e-table\" - -libetable_la_SOURCES = \ - e-cell.c \ - e-cell-checkbox.c \ - e-cell-combo.c \ - e-cell-date.c \ - e-cell-date-edit.c \ - e-cell-number.c \ - e-cell-percent.c \ - e-cell-pixbuf.c \ - e-cell-popup.c \ - e-cell-size.c \ - e-cell-text.c \ - e-cell-toggle.c \ - e-cell-tree.c \ - e-cell-vbox.c \ - e-cell-hbox.c \ - e-popup-menu.c \ - e-table-click-to-add.c \ - e-table-col.c \ - e-table-column-specification.c \ - e-table-config.c \ - e-table-extras.c \ - e-table-field-chooser-dialog.c \ - e-table-field-chooser-item.c \ - e-table-field-chooser.c \ - e-table-group.c \ - e-table-group-container.c \ - e-table-group-leaf.c \ - e-table-header.c \ - e-table-header-item.c \ - e-table-header-utils.c \ - e-table-item.c \ - e-table-memory-callbacks.c \ - e-table-memory-store.c \ - e-table-memory.c \ - e-table-model.c \ - e-table-one.c \ - e-table-search.c \ - e-table-selection-model.c \ - e-table-sort-info.c \ - e-table-sorted.c \ - e-table-sorted-variable.c \ - e-table-sorter.c \ - e-table-sorting-utils.c \ - e-table-specification.c \ - e-table-state.c \ - e-table-subset.c \ - e-table-subset-variable.c \ - e-table-utils.c \ - e-table-without.c \ - e-table.c \ - e-tree-memory-callbacks.c \ - e-tree-memory.c \ - e-tree-model.c \ - e-tree-selection-model.c \ - e-tree-sorted.c \ - e-tree-table-adapter.c \ - e-tree.c \ - gal-a11y-e-cell.c \ - gal-a11y-e-cell-popup.c \ - gal-a11y-e-cell-registry.c \ - gal-a11y-e-cell-toggle.c \ - gal-a11y-e-cell-tree.c \ - gal-a11y-e-cell-vbox.c \ - gal-a11y-e-table.c \ - gal-a11y-e-table-click-to-add.c \ - gal-a11y-e-table-click-to-add-factory.c \ - gal-a11y-e-table-column-header.c \ - gal-a11y-e-table-factory.c \ - gal-a11y-e-table-item.c \ - gal-a11y-e-table-item-factory.c \ - gal-a11y-e-tree.c \ - gal-a11y-e-tree-factory.c - -libetableincludedir = $(privincludedir)/table - -libetableinclude_HEADERS = \ - e-cell.h \ - e-cell-checkbox.h \ - e-cell-combo.h \ - e-cell-date.h \ - e-cell-date-edit.h \ - e-cell-number.h \ - e-cell-percent.h \ - e-cell-pixbuf.h \ - e-cell-popup.h \ - e-cell-size.h \ - e-cell-text.h \ - e-cell-toggle.h \ - e-cell-tree.h \ - e-cell-vbox.h \ - e-cell-hbox.h \ - e-popup-menu.h \ - e-table-click-to-add.h \ - e-table-col-dnd.h \ - e-table-col.h \ - e-table-column-specification.h \ - e-table-config.h \ - e-table-defines.h \ - e-table-extras.h \ - e-table-field-chooser-dialog.h \ - e-table-field-chooser-item.h \ - e-table-field-chooser.h \ - e-table-group.h \ - e-table-group-container.h \ - e-table-group-leaf.h \ - e-table-header.h \ - e-table-header-item.h \ - e-table-header-utils.h \ - e-table-item.h \ - e-table-memory-callbacks.h \ - e-table-memory-store.h \ - e-table-memory.h \ - e-table-model.h \ - e-table-one.h \ - e-table-search.h \ - e-table-selection-model.h \ - e-table-sort-info.h \ - e-table-sorted.h \ - e-table-sorted-variable.h \ - e-table-sorter.h \ - e-table-sorting-utils.h \ - e-table-specification.h \ - e-table-state.h \ - e-table-subset.h \ - e-table-subset-variable.h \ - e-table-utils.h \ - e-table-without.h \ - e-table.h \ - e-tree-memory-callbacks.h \ - e-tree-memory.h \ - e-tree-model.h \ - e-tree-selection-model.h \ - e-tree-sorted.h \ - e-tree-table-adapter.h \ - e-tree.h \ - gal-a11y-e-cell.h \ - gal-a11y-e-cell-popup.h \ - gal-a11y-e-cell-registry.h \ - gal-a11y-e-cell-toggle.h \ - gal-a11y-e-cell-tree.h \ - gal-a11y-e-cell-vbox.h \ - gal-a11y-e-table.h \ - gal-a11y-e-table-click-to-add.h \ - gal-a11y-e-table-click-to-add-factory.h \ - gal-a11y-e-table-column-header.h \ - gal-a11y-e-table-factory.h \ - gal-a11y-e-table-item.h \ - gal-a11y-e-table-item-factory.h \ - gal-a11y-e-tree.h \ - gal-a11y-e-tree-factory.h - -libetable_la_LDFLAGS = -avoid-version $(NO_UNDEFINED) - -libetable_la_LIBADD = \ - $(top_builddir)/a11y/libevolution-a11y.la \ - $(top_builddir)/e-util/libeutil.la \ - $(top_builddir)/widgets/misc/libemiscwidgets.la \ - $(top_builddir)/widgets/text/libetext.la \ - $(top_builddir)/libgnomecanvas/libgnomecanvas.la \ - $(top_builddir)/libemail-utils/libemail-utils.la \ - $(top_builddir)/libevolution-utils/libevolution-utils.la \ - $(EVOLUTION_DATA_SERVER_LIBS) \ - $(GNOME_PLATFORM_LIBS) \ - $(MATH_LIB) - -icons = \ - arrow-down.xpm \ - arrow-up.xpm \ - check-empty.xpm \ - check-filled.xpm \ - tree-expanded.xpm \ - tree-unexpanded.xpm - -EXTRA_DIST = \ - $(icons) \ - $(ui_DATA) - --include $(top_srcdir)/git.mk 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/e-cell-checkbox.c b/widgets/table/e-cell-checkbox.c deleted file mode 100644 index 0d30031397..0000000000 --- a/widgets/table/e-cell-checkbox.c +++ /dev/null @@ -1,104 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Miguel de Icaza <miguel@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> -#include <libgnomecanvas/libgnomecanvas.h> - -#include "e-util/e-util.h" - -#include "e-table-item.h" -#include "e-cell-checkbox.h" - -#include "check-empty.xpm" -#include "check-filled.xpm" - -G_DEFINE_TYPE (ECellCheckbox, e_cell_checkbox, E_TYPE_CELL_TOGGLE) - -static GdkPixbuf *checks[2]; - -static void -ecc_print (ECellView *ecell_view, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width, - gdouble height) -{ - cairo_t *cr = gtk_print_context_get_cairo_context (context); - const gint value = GPOINTER_TO_INT ( - e_table_model_value_at ( - ecell_view->e_table_model, model_col, row)); - cairo_save (cr); - - if (value == 1) { - cairo_set_line_width (cr, 2); - cairo_move_to (cr, 3, 11); - cairo_line_to (cr, 7, 14); - cairo_line_to (cr, 11, 5); - cairo_stroke (cr); - } - - cairo_restore (cr); -} - -static void -e_cell_checkbox_class_init (ECellCheckboxClass *class) -{ - ECellClass *ecc = E_CELL_CLASS (class); - - ecc->print = ecc_print; - checks[0] = gdk_pixbuf_new_from_xpm_data (check_empty_xpm); - checks[1] = gdk_pixbuf_new_from_xpm_data (check_filled_xpm); -} - -static void -e_cell_checkbox_init (ECellCheckbox *eccb) -{ - GPtrArray *pixbufs; - - pixbufs = e_cell_toggle_get_pixbufs (E_CELL_TOGGLE (eccb)); - - g_ptr_array_add (pixbufs, g_object_ref (checks[0])); - g_ptr_array_add (pixbufs, g_object_ref (checks[1])); -} - -/** - * 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) -{ - return g_object_new (E_TYPE_CELL_CHECKBOX, NULL); -} diff --git a/widgets/table/e-cell-checkbox.h b/widgets/table/e-cell-checkbox.h deleted file mode 100644 index 8306b2d29a..0000000000 --- a/widgets/table/e-cell-checkbox.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Miguel de Icaza <miguel@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_CELL_CHECKBOX_H_ -#define _E_CELL_CHECKBOX_H_ - -#include <table/e-cell-toggle.h> - -/* Standard GObject macros */ -#define E_TYPE_CELL_CHECKBOX \ - (e_cell_checkbox_get_type ()) -#define E_CELL_CHECKBOX(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_CELL_CHECKBOX, ECellCheckbox)) -#define E_CELL_CHECKBOX_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_CELL_CHECKBOX, ECellCheckboxClass)) -#define E_IS_CELL_CHECKBOX(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_CELL_CHECKBOX)) -#define E_IS_CELL_CHECKBOX_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_CELL_CHECKBOX)) -#define E_CELL_CHECKBOX_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_CELL_CHECKBOX, ECellCheckboxClass)) - -G_BEGIN_DECLS - -typedef struct _ECellCheckbox ECellCheckbox; -typedef struct _ECellCheckboxClass ECellCheckboxClass; - -struct _ECellCheckbox { - ECellToggle parent; -}; - -struct _ECellCheckboxClass { - ECellToggleClass parent_class; -}; - -GType e_cell_checkbox_get_type (void) G_GNUC_CONST; -ECell * e_cell_checkbox_new (void); - -G_END_DECLS - -#endif /* _E_CELL_CHECKBOX_H_ */ - diff --git a/widgets/table/e-cell-combo.c b/widgets/table/e-cell-combo.c deleted file mode 100644 index bc82042d7a..0000000000 --- a/widgets/table/e-cell-combo.c +++ /dev/null @@ -1,839 +0,0 @@ -/* - * e-cell-combo.c: Combo cell renderer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Damon Chaplin <damon@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -/* - * ECellCombo - a subclass of ECellPopup used to support popup lists like a - * GtkCombo widget. It only supports a basic popup list of strings at present, - * with no auto-completion. - */ - -/* - * Notes: (handling pointer grabs and GTK+ grabs is a nightmare!) - * - * o We must grab the pointer when we show the popup, so that if any buttons - * are pressed outside the application we hide the popup. - * - * o We have to be careful when popping up any widgets which also grab the - * pointer at some point, since we will lose our own pointer grab. - * When we pop up a list it will grab the pointer itself when an item is - * selected, and release the grab when the button is released. - * Fortunately we hide the popup at this point, so it isn't a problem. - * But for other types of widgets in the popup it could cause trouble. - * - I think GTK+ should provide help for this (nested pointer grabs?). - * - * o We must set the 'owner_events' flag of the pointer grab to TRUE so that - * pointer events get reported to all the application windows as normal. - * If we don't do this then the widgets in the popup may not work properly. - * - * o We must do a gtk_grab_add() so that we only allow events to go to the - * widgets within the popup (though some special events still get reported - * to the widget owning the window). Doing th gtk_grab_add() on the toplevel - * popup window should be fine. We can then check for any events that should - * close the popup, like the Escape key, or a button press outside the popup. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> - -#include <glib/gi18n.h> -#include "e-util/e-util.h" -#include "e-util/e-unicode.h" - -#include "e-table-item.h" -#include "e-cell-combo.h" -#include "e-cell-text.h" - -#define d(x) - -/* The height to make the popup list if there aren't any items in it. */ -#define E_CELL_COMBO_LIST_EMPTY_HEIGHT 15 - -static void e_cell_combo_dispose (GObject *object); -static gint e_cell_combo_do_popup (ECellPopup *ecp, - GdkEvent *event, - gint row, - gint view_col); -static void e_cell_combo_select_matching_item - (ECellCombo *ecc); -static void e_cell_combo_show_popup (ECellCombo *ecc, - gint row, - gint view_col); -static void e_cell_combo_get_popup_pos (ECellCombo *ecc, - gint row, - gint view_col, - gint *x, - gint *y, - gint *height, - gint *width); -static void e_cell_combo_selection_changed (GtkTreeSelection *selection, - ECellCombo *ecc); -static gint e_cell_combo_button_press (GtkWidget *popup_window, - GdkEvent *button_event, - ECellCombo *ecc); -static gint e_cell_combo_button_release (GtkWidget *popup_window, - GdkEvent *button_event, - ECellCombo *ecc); -static gint e_cell_combo_key_press (GtkWidget *popup_window, - GdkEvent *key_event, - ECellCombo *ecc); -static void e_cell_combo_update_cell (ECellCombo *ecc); -static void e_cell_combo_restart_edit (ECellCombo *ecc); - -G_DEFINE_TYPE (ECellCombo, e_cell_combo, E_TYPE_CELL_POPUP) - -static void -e_cell_combo_class_init (ECellComboClass *class) -{ - ECellPopupClass *ecpc = E_CELL_POPUP_CLASS (class); - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->dispose = e_cell_combo_dispose; - - ecpc->popup = e_cell_combo_do_popup; -} - -static void -e_cell_combo_init (ECellCombo *ecc) -{ - GtkWidget *frame; - AtkObject *a11y; - GtkListStore *store; - GtkTreeSelection *selection; - GtkScrolledWindow *scrolled_window; - - /* We create one popup window for the ECell, since there will only - * ever be one popup in use at a time. */ - ecc->popup_window = gtk_window_new (GTK_WINDOW_POPUP); - - gtk_window_set_type_hint ( - GTK_WINDOW (ecc->popup_window), GDK_WINDOW_TYPE_HINT_COMBO); - gtk_window_set_resizable (GTK_WINDOW (ecc->popup_window), TRUE); - - frame = gtk_frame_new (NULL); - gtk_container_add (GTK_CONTAINER (ecc->popup_window), frame); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT); - gtk_widget_show (frame); - - ecc->popup_scrolled_window = gtk_scrolled_window_new (NULL, NULL); - scrolled_window = GTK_SCROLLED_WINDOW (ecc->popup_scrolled_window); - - gtk_scrolled_window_set_policy ( - scrolled_window, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_widget_set_can_focus ( - gtk_scrolled_window_get_hscrollbar (scrolled_window), FALSE); - gtk_widget_set_can_focus ( - gtk_scrolled_window_get_vscrollbar (scrolled_window), FALSE); - gtk_container_add (GTK_CONTAINER (frame), ecc->popup_scrolled_window); - gtk_widget_show (ecc->popup_scrolled_window); - - store = gtk_list_store_new (1, G_TYPE_STRING); - ecc->popup_tree_view = - gtk_tree_view_new_with_model (GTK_TREE_MODEL (store)); - g_object_unref (store); - - gtk_tree_view_append_column ( - GTK_TREE_VIEW (ecc->popup_tree_view), - gtk_tree_view_column_new_with_attributes ( - "Text", gtk_cell_renderer_text_new (), - "text", 0, NULL)); - - gtk_tree_view_set_headers_visible ( - GTK_TREE_VIEW (ecc->popup_tree_view), FALSE); - - selection = gtk_tree_view_get_selection ( - GTK_TREE_VIEW (ecc->popup_tree_view)); - gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); - gtk_scrolled_window_add_with_viewport ( - GTK_SCROLLED_WINDOW (ecc->popup_scrolled_window), - ecc->popup_tree_view); - gtk_container_set_focus_vadjustment ( - GTK_CONTAINER (ecc->popup_tree_view), - gtk_scrolled_window_get_vadjustment ( - GTK_SCROLLED_WINDOW (ecc->popup_scrolled_window))); - gtk_container_set_focus_hadjustment ( - GTK_CONTAINER (ecc->popup_tree_view), - gtk_scrolled_window_get_hadjustment ( - GTK_SCROLLED_WINDOW (ecc->popup_scrolled_window))); - gtk_widget_show (ecc->popup_tree_view); - - a11y = gtk_widget_get_accessible (ecc->popup_tree_view); - atk_object_set_name (a11y, _("popup list")); - - g_signal_connect ( - selection, "changed", - G_CALLBACK (e_cell_combo_selection_changed), ecc); - g_signal_connect ( - ecc->popup_window, "button_press_event", - G_CALLBACK (e_cell_combo_button_press), ecc); - g_signal_connect ( - ecc->popup_window, "button_release_event", - G_CALLBACK (e_cell_combo_button_release), ecc); - g_signal_connect ( - ecc->popup_window, "key_press_event", - G_CALLBACK (e_cell_combo_key_press), ecc); -} - -/** - * e_cell_combo_new: - * - * Creates a new ECellCombo renderer. - * - * Returns: an ECellCombo object. - */ -ECell * -e_cell_combo_new (void) -{ - return g_object_new (E_TYPE_CELL_COMBO, NULL); -} - -/* - * GObject::dispose method - */ -static void -e_cell_combo_dispose (GObject *object) -{ - ECellCombo *ecc = E_CELL_COMBO (object); - - if (ecc->popup_window != NULL) { - gtk_widget_destroy (ecc->popup_window); - ecc->popup_window = NULL; - } - - if (ecc->grabbed_keyboard != NULL) { - gdk_device_ungrab (ecc->grabbed_keyboard, GDK_CURRENT_TIME); - g_object_unref (ecc->grabbed_keyboard); - ecc->grabbed_keyboard = NULL; - } - - if (ecc->grabbed_pointer != NULL) { - gdk_device_ungrab (ecc->grabbed_pointer, GDK_CURRENT_TIME); - g_object_unref (ecc->grabbed_pointer); - ecc->grabbed_pointer = NULL; - } - - G_OBJECT_CLASS (e_cell_combo_parent_class)->dispose (object); -} - -void -e_cell_combo_set_popdown_strings (ECellCombo *ecc, - GList *strings) -{ - GList *elem; - GtkListStore *store; - - g_return_if_fail (E_IS_CELL_COMBO (ecc)); - g_return_if_fail (strings != NULL); - - store = GTK_LIST_STORE ( - gtk_tree_view_get_model ( - GTK_TREE_VIEW (ecc->popup_tree_view))); - gtk_list_store_clear (store); - - for (elem = strings; elem; elem = elem->next) { - GtkTreeIter iter; - gchar *utf8_text = elem->data; - - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, utf8_text, -1); - } -} - -static gint -e_cell_combo_do_popup (ECellPopup *ecp, - GdkEvent *event, - gint row, - gint view_col) -{ - ECellCombo *ecc = E_CELL_COMBO (ecp); - GtkTreeSelection *selection; - GdkGrabStatus grab_status; - GdkWindow *window; - GdkDevice *keyboard; - GdkDevice *pointer; - GdkDevice *event_device; - guint32 event_time; - - g_return_val_if_fail (ecc->grabbed_keyboard == NULL, FALSE); - g_return_val_if_fail (ecc->grabbed_pointer == NULL, FALSE); - - selection = gtk_tree_view_get_selection ( - GTK_TREE_VIEW (ecc->popup_tree_view)); - - g_signal_handlers_block_by_func ( - selection, e_cell_combo_selection_changed, ecc); - - e_cell_combo_show_popup (ecc, row, view_col); - e_cell_combo_select_matching_item (ecc); - - g_signal_handlers_unblock_by_func ( - selection, e_cell_combo_selection_changed, ecc); - - window = gtk_widget_get_window (ecc->popup_tree_view); - - event_device = gdk_event_get_device (event); - event_time = gdk_event_get_time (event); - - if (gdk_device_get_source (event_device) == GDK_SOURCE_KEYBOARD) { - keyboard = event_device; - pointer = gdk_device_get_associated_device (event_device); - } else { - keyboard = gdk_device_get_associated_device (event_device); - pointer = event_device; - } - - if (pointer != NULL) { - grab_status = gdk_device_grab ( - pointer, - window, - GDK_OWNERSHIP_NONE, - TRUE, - GDK_ENTER_NOTIFY_MASK | - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_POINTER_MOTION_HINT_MASK | - GDK_BUTTON1_MOTION_MASK, - NULL, - event_time); - - if (grab_status != GDK_GRAB_SUCCESS) - return FALSE; - - ecc->grabbed_pointer = g_object_ref (pointer); - } - - gtk_grab_add (ecc->popup_window); - - if (keyboard != NULL) { - grab_status = gdk_device_grab ( - keyboard, - window, - GDK_OWNERSHIP_NONE, - TRUE, - GDK_KEY_PRESS_MASK | - GDK_KEY_RELEASE_MASK, - NULL, - event_time); - - if (grab_status != GDK_GRAB_SUCCESS) { - if (ecc->grabbed_pointer != NULL) { - gdk_device_ungrab ( - ecc->grabbed_pointer, - event_time); - g_object_unref (ecc->grabbed_pointer); - ecc->grabbed_pointer = NULL; - } - return FALSE; - } - - ecc->grabbed_keyboard = g_object_ref (keyboard); - } - - return TRUE; -} - -static void -e_cell_combo_select_matching_item (ECellCombo *ecc) -{ - ECellPopup *ecp = E_CELL_POPUP (ecc); - ECellView *ecv = (ECellView *) ecp->popup_cell_view; - ECellText *ecell_text = E_CELL_TEXT (ecp->child); - ETableItem *eti; - ETableCol *ecol; - gboolean found = FALSE; - gchar *cell_text; - gboolean valid; - GtkTreeSelection *selection; - GtkTreeIter iter; - GtkTreeModel *model; - - eti = E_TABLE_ITEM (ecp->popup_cell_view->cell_view.e_table_item_view); - - ecol = e_table_header_get_column (eti->header, ecp->popup_view_col); - cell_text = e_cell_text_get_text ( - ecell_text, ecv->e_table_model, - ecol->col_idx, ecp->popup_row); - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (ecc->popup_tree_view)); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (ecc->popup_tree_view)); - - for (valid = gtk_tree_model_get_iter_first (model, &iter); - valid && !found; - valid = gtk_tree_model_iter_next (model, &iter)) { - gchar *str = NULL; - - gtk_tree_model_get (model, &iter, 0, &str, -1); - - if (str && g_str_equal (str, cell_text)) { - GtkTreePath *path; - - path = gtk_tree_model_get_path (model, &iter); - gtk_tree_view_set_cursor ( - GTK_TREE_VIEW (ecc->popup_tree_view), - path, NULL, FALSE); - gtk_tree_path_free (path); - - found = TRUE; - } - - g_free (str); - } - - if (!found) - gtk_tree_selection_unselect_all (selection); - - e_cell_text_free_text (ecell_text, cell_text); -} - -static void -e_cell_combo_show_popup (ECellCombo *ecc, - gint row, - gint view_col) -{ - GdkWindow *window; - GtkAllocation allocation; - gint x, y, width, height, old_width, old_height; - - gtk_widget_get_allocation (ecc->popup_window, &allocation); - - /* This code is practically copied from GtkCombo. */ - old_width = allocation.width; - old_height = allocation.height; - - e_cell_combo_get_popup_pos (ecc, row, view_col, &x, &y, &height, &width); - - /* workaround for gtk_scrolled_window_size_allocate bug */ - if (old_width != width || old_height != height) { - gtk_widget_hide ( - gtk_scrolled_window_get_hscrollbar ( - GTK_SCROLLED_WINDOW (ecc->popup_scrolled_window))); - gtk_widget_hide ( - gtk_scrolled_window_get_vscrollbar ( - GTK_SCROLLED_WINDOW (ecc->popup_scrolled_window))); - } - - gtk_window_move (GTK_WINDOW (ecc->popup_window), x, y); - gtk_widget_set_size_request (ecc->popup_window, width, height); - gtk_widget_realize (ecc->popup_window); - window = gtk_widget_get_window (ecc->popup_window); - gdk_window_resize (window, width, height); - gtk_widget_show (ecc->popup_window); - - e_cell_popup_set_shown (E_CELL_POPUP (ecc), TRUE); - d (g_print ("%s: popup_shown = TRUE\n", __FUNCTION__)); -} - -/* Calculates the size and position of the popup window (like GtkCombo). */ -static void -e_cell_combo_get_popup_pos (ECellCombo *ecc, - gint row, - gint view_col, - gint *x, - gint *y, - gint *height, - gint *width) -{ - ECellPopup *ecp = E_CELL_POPUP (ecc); - ETableItem *eti; - GtkWidget *canvas; - GtkWidget *widget; - GtkWidget *popwin_child; - GtkWidget *popup_child; - GtkStyle *popwin_style; - GtkStyle *popup_style; - GdkWindow *window; - GtkBin *popwin; - GtkScrolledWindow *popup; - GtkRequisition requisition; - GtkRequisition list_requisition; - gboolean show_vscroll = FALSE, show_hscroll = FALSE; - gint avail_height, avail_width, min_height, work_height, screen_width; - gint column_width, row_height, scrollbar_width; - gdouble x1, y1; - gdouble wx, wy; - - eti = E_TABLE_ITEM (ecp->popup_cell_view->cell_view.e_table_item_view); - canvas = GTK_WIDGET (GNOME_CANVAS_ITEM (eti)->canvas); - - /* This code is practically copied from GtkCombo. */ - popup = GTK_SCROLLED_WINDOW (ecc->popup_scrolled_window); - popwin = GTK_BIN (ecc->popup_window); - - window = gtk_widget_get_window (canvas); - gdk_window_get_origin (window, x, y); - - x1 = e_table_header_col_diff (eti->header, 0, view_col + 1); - y1 = e_table_item_row_diff (eti, 0, row + 1); - column_width = e_table_header_col_diff ( - eti->header, view_col, view_col + 1); - row_height = e_table_item_row_diff (eti, row, row + 1); - gnome_canvas_item_i2w (GNOME_CANVAS_ITEM (eti), &x1, &y1); - - gnome_canvas_world_to_window ( - GNOME_CANVAS (canvas), x1, y1, &wx, &wy); - - x1 = wx; - y1 = wy; - - *x += x1; - /* The ETable positions don't include the grid lines, I think, so we add 1. */ - *y += y1 + 1 - (gint) - gtk_adjustment_get_value ( - gtk_scrollable_get_vadjustment ( - GTK_SCROLLABLE (&((GnomeCanvas *) canvas)->layout))) - + ((GnomeCanvas *) canvas)->zoom_yofs; - - widget = gtk_scrolled_window_get_vscrollbar (popup); - gtk_widget_get_preferred_size (widget, &requisition, NULL); - - scrollbar_width = - requisition.width - + GTK_SCROLLED_WINDOW_CLASS (G_OBJECT_GET_CLASS (popup))->scrollbar_spacing; - - avail_height = gdk_screen_height () - *y; - - /* We'll use the entire screen width if needed, but we save space for - * the vertical scrollbar in case we need to show that. */ - screen_width = gdk_screen_width (); - avail_width = screen_width - scrollbar_width; - - widget = gtk_scrolled_window_get_vscrollbar (popup); - gtk_widget_get_preferred_size (widget, &requisition, NULL); - - gtk_widget_get_preferred_size (ecc->popup_tree_view, &list_requisition, NULL); - min_height = MIN (list_requisition.height, requisition.height); - if (!gtk_tree_model_iter_n_children ( - gtk_tree_view_get_model ( - GTK_TREE_VIEW (ecc->popup_tree_view)), NULL)) - list_requisition.height += E_CELL_COMBO_LIST_EMPTY_HEIGHT; - - popwin_child = gtk_bin_get_child (popwin); - popwin_style = gtk_widget_get_style (popwin_child); - - popup_child = gtk_bin_get_child (GTK_BIN (popup)); - popup_style = gtk_widget_get_style (popup_child); - - /* Calculate the desired width. */ - *width = list_requisition.width - + 2 * popwin_style->xthickness - + 2 * gtk_container_get_border_width (GTK_CONTAINER (popwin_child)) - + 2 * gtk_container_get_border_width (GTK_CONTAINER (popup)) - + 2 * gtk_container_get_border_width (GTK_CONTAINER (popup_child)) - + 2 * popup_style->xthickness; - - /* Use at least the same width as the column. */ - if (*width < column_width) - *width = column_width; - - /* If it is larger than the available width, use that instead and show - * the horizontal scrollbar. */ - if (*width > avail_width) { - *width = avail_width; - show_hscroll = TRUE; - } - - /* Calculate all the borders etc. that we need to add to the height. */ - work_height = (2 * popwin_style->ythickness - + 2 * gtk_container_get_border_width (GTK_CONTAINER (popwin_child)) - + 2 * gtk_container_get_border_width (GTK_CONTAINER (popup)) - + 2 * gtk_container_get_border_width (GTK_CONTAINER (popup_child)) - + 2 * popup_style->xthickness); - - widget = gtk_scrolled_window_get_hscrollbar (popup); - gtk_widget_get_preferred_size (widget, &requisition, NULL); - - /* Add on the height of the horizontal scrollbar if we need it. */ - if (show_hscroll) - work_height += - requisition.height + - GTK_SCROLLED_WINDOW_GET_CLASS (popup)->scrollbar_spacing; - - /* Check if it fits in the available height. */ - if (work_height + list_requisition.height > avail_height) { - /* It doesn't fit, so we see if we have the minimum space - * needed. */ - if (work_height + min_height > avail_height - && *y - row_height > avail_height) { - /* We don't, so we show the popup above the cell - * instead of below it. */ - avail_height = *y - row_height; - *y -= (work_height + list_requisition.height - + row_height); - if (*y < 0) - *y = 0; - } - } - - /* Check if we still need the vertical scrollbar. */ - if (work_height + list_requisition.height > avail_height) { - *width += scrollbar_width; - show_vscroll = TRUE; - } - - /* We try to line it up with the right edge of the column, but we don't - * want it to go off the edges of the screen. */ - if (*x > screen_width) - *x = screen_width; - *x -= *width; - if (*x < 0) - *x = 0; - - if (show_vscroll) - *height = avail_height; - else - *height = work_height + list_requisition.height; -} - -static void -e_cell_combo_selection_changed (GtkTreeSelection *selection, - ECellCombo *ecc) -{ - GtkTreeIter iter; - GtkTreeModel *model; - - if (!gtk_widget_get_realized (ecc->popup_window) || - !gtk_tree_selection_get_selected (selection, &model, &iter)) - return; - - e_cell_combo_update_cell (ecc); - e_cell_combo_restart_edit (ecc); -} - -/* This handles button press events in the popup window. - * Note that since we have a pointer grab on this window, we also get button - * press events for windows outside the application here, so we hide the popup - * window if that happens. We also get propagated events from child widgets - * which we ignore. */ -static gint -e_cell_combo_button_press (GtkWidget *popup_window, - GdkEvent *button_event, - ECellCombo *ecc) -{ - GtkWidget *event_widget; - guint32 event_time; - - event_time = gdk_event_get_time (button_event); - event_widget = gtk_get_event_widget (button_event); - - /* If the button press was for a widget inside the popup list, but - * not the popup window itself, then we ignore the event and return - * FALSE. Otherwise we will hide the popup. - * Note that since we have a pointer grab on the popup list, button - * presses outside the application will be reported to this window, - * which is why we hide the popup in this case. */ - while (event_widget) { - event_widget = gtk_widget_get_parent (event_widget); - if (event_widget == ecc->popup_tree_view) - return FALSE; - } - - gtk_grab_remove (ecc->popup_window); - - if (ecc->grabbed_keyboard != NULL) { - gdk_device_ungrab (ecc->grabbed_keyboard, event_time); - g_object_unref (ecc->grabbed_keyboard); - ecc->grabbed_keyboard = NULL; - } - - if (ecc->grabbed_pointer != NULL) { - gdk_device_ungrab (ecc->grabbed_pointer, event_time); - g_object_unref (ecc->grabbed_pointer); - ecc->grabbed_pointer = NULL; - } - - gtk_widget_hide (ecc->popup_window); - - e_cell_popup_set_shown (E_CELL_POPUP (ecc), FALSE); - d (g_print ("%s: popup_shown = FALSE\n", __FUNCTION__)); - - /* We don't want to update the cell here. Since the list is in browse - * mode there will always be one item selected, so when we popup the - * list one item is selected even if it doesn't match the current text - * in the cell. So if you click outside the popup (which is what has - * happened here) it is better to not update the cell. */ - /*e_cell_combo_update_cell (ecc);*/ - e_cell_combo_restart_edit (ecc); - - return TRUE; -} - -/* This handles button release events in the popup window. If the button is - * released inside the list, we want to hide the popup window and update the - * cell with the new selection. */ -static gint -e_cell_combo_button_release (GtkWidget *popup_window, - GdkEvent *button_event, - ECellCombo *ecc) -{ - GtkWidget *event_widget; - guint32 event_time; - - event_time = gdk_event_get_time (button_event); - event_widget = gtk_get_event_widget (button_event); - - /* See if the button was released in the list (or its children). */ - while (event_widget && event_widget != ecc->popup_tree_view) - event_widget = gtk_widget_get_parent (event_widget); - - /* If it wasn't, then we just ignore the event. */ - if (event_widget != ecc->popup_tree_view) - return FALSE; - - /* The button was released inside the list, so we hide the popup and - * update the cell to reflect the new selection. */ - - gtk_grab_remove (ecc->popup_window); - - if (ecc->grabbed_keyboard != NULL) { - gdk_device_ungrab (ecc->grabbed_keyboard, event_time); - g_object_unref (ecc->grabbed_keyboard); - ecc->grabbed_keyboard = NULL; - } - - if (ecc->grabbed_pointer != NULL) { - gdk_device_ungrab (ecc->grabbed_pointer, event_time); - g_object_unref (ecc->grabbed_pointer); - ecc->grabbed_pointer = NULL; - } - - gtk_widget_hide (ecc->popup_window); - - e_cell_popup_set_shown (E_CELL_POPUP (ecc), FALSE); - d (g_print ("%s: popup_shown = FALSE\n", __FUNCTION__)); - - e_cell_combo_update_cell (ecc); - e_cell_combo_restart_edit (ecc); - - return TRUE; -} - -/* This handles key press events in the popup window. If the Escape key is - * pressed we hide the popup, and do not change the cell contents. */ -static gint -e_cell_combo_key_press (GtkWidget *popup_window, - GdkEvent *key_event, - ECellCombo *ecc) -{ - guint event_keyval = 0; - guint32 event_time; - - gdk_event_get_keyval (key_event, &event_keyval); - event_time = gdk_event_get_time (key_event); - - /* If the Escape key is pressed we hide the popup. */ - if (event_keyval != GDK_KEY_Escape - && event_keyval != GDK_KEY_Return - && event_keyval != GDK_KEY_KP_Enter - && event_keyval != GDK_KEY_ISO_Enter - && event_keyval != GDK_KEY_3270_Enter) - return FALSE; - - if (event_keyval == GDK_KEY_Escape && - (!ecc->popup_window || !gtk_widget_get_visible (ecc->popup_window))) - return FALSE; - - gtk_grab_remove (ecc->popup_window); - - if (ecc->grabbed_keyboard != NULL) { - gdk_device_ungrab (ecc->grabbed_keyboard, event_time); - g_object_unref (ecc->grabbed_keyboard); - ecc->grabbed_keyboard = NULL; - } - - if (ecc->grabbed_pointer != NULL) { - gdk_device_ungrab (ecc->grabbed_pointer, event_time); - g_object_unref (ecc->grabbed_pointer); - ecc->grabbed_pointer = NULL; - } - - gtk_widget_hide (ecc->popup_window); - - e_cell_popup_set_shown (E_CELL_POPUP (ecc), FALSE); - d (g_print ("%s: popup_shown = FALSE\n", __FUNCTION__)); - - if (event_keyval != GDK_KEY_Escape) - e_cell_combo_update_cell (ecc); - - e_cell_combo_restart_edit (ecc); - - return TRUE; -} - -static void -e_cell_combo_update_cell (ECellCombo *ecc) -{ - ECellPopup *ecp = E_CELL_POPUP (ecc); - ECellView *ecv = (ECellView *) ecp->popup_cell_view; - ECellText *ecell_text = E_CELL_TEXT (ecp->child); - ETableItem *eti = E_TABLE_ITEM (ecv->e_table_item_view); - ETableCol *ecol; - GtkTreeSelection *selection = gtk_tree_view_get_selection ( - GTK_TREE_VIEW (ecc->popup_tree_view)); - GtkTreeModel *model; - GtkTreeIter iter; - gchar *text = NULL, *old_text; - - /* Return if no item is selected. */ - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) - return; - - /* Get the text of the selected item. */ - gtk_tree_model_get (model, &iter, 0, &text, -1); - g_return_if_fail (text != NULL); - - /* Compare it with the existing cell contents. */ - ecol = e_table_header_get_column (eti->header, ecp->popup_view_col); - - old_text = e_cell_text_get_text ( - ecell_text, ecv->e_table_model, - ecol->col_idx, ecp->popup_row); - - /* If they are different, update the cell contents. */ - if (old_text && strcmp (old_text, text)) { - e_cell_text_set_value ( - ecell_text, ecv->e_table_model, - ecol->col_idx, ecp->popup_row, text); - } - - e_cell_text_free_text (ecell_text, old_text); - g_free (text); -} - -static void -e_cell_combo_restart_edit (ECellCombo *ecc) -{ - /* This doesn't work. ETable stops the edit straight-away again. */ -#if 0 - ECellView *ecv = (ECellView *) ecc->popup_cell_view; - ETableItem *eti = E_TABLE_ITEM (ecv->e_table_item_view); - - e_table_item_enter_edit (eti, ecc->popup_view_col, ecc->popup_row); -#endif -} - diff --git a/widgets/table/e-cell-combo.h b/widgets/table/e-cell-combo.h deleted file mode 100644 index 3d2fb339de..0000000000 --- a/widgets/table/e-cell-combo.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Damon Chaplin <damon@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -/* - * ECellCombo - a subclass of ECellPopup used to support popup lists like a - * GtkCombo widget. It only supports a basic popup list of strings at present, - * with no auto-completion. The child ECell of the ECellPopup must be an - * ECellText or subclass. - */ - -#ifndef _E_CELL_COMBO_H_ -#define _E_CELL_COMBO_H_ - -#include <table/e-cell-popup.h> - -/* Standard GObject macros */ -#define E_TYPE_CELL_COMBO \ - (e_cell_combo_get_type ()) -#define E_CELL_COMBO(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_CELL_COMBO, ECellCombo)) -#define E_CELL_COMBO_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_CELL_COMBO, ECellComboClass)) -#define E_IS_CELL_COMBO(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_CELL_COMBO)) -#define E_IS_CELL_COMBO_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_CELL_COMBO)) -#define E_CELL_COMBO_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_CELL_COMBO, ECellComboClass)) - -G_BEGIN_DECLS - -typedef struct _ECellCombo ECellCombo; -typedef struct _ECellComboClass ECellComboClass; - -struct _ECellCombo { - ECellPopup parent; - - GtkWidget *popup_window; - GtkWidget *popup_scrolled_window; - GtkWidget *popup_tree_view; - - GdkDevice *grabbed_keyboard; - GdkDevice *grabbed_pointer; -}; - -struct _ECellComboClass { - ECellPopupClass parent_class; -}; - -GType e_cell_combo_get_type (void) G_GNUC_CONST; -ECell * e_cell_combo_new (void); - -/* These must be UTF-8. */ -void e_cell_combo_set_popdown_strings - (ECellCombo *ecc, - GList *strings); - -G_END_DECLS - -#endif /* _E_CELL_COMBO_H_ */ diff --git a/widgets/table/e-cell-date-edit.c b/widgets/table/e-cell-date-edit.c deleted file mode 100644 index be834f5686..0000000000 --- a/widgets/table/e-cell-date-edit.c +++ /dev/null @@ -1,1042 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Damon Chaplin <damon@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -/* - * ECellDateEdit - a subclass of ECellPopup used to show a date with a popup - * window to edit it. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "e-cell-date-edit.h" - -#include <string.h> -#include <time.h> - -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> - -#include "e-table-item.h" -#include "e-cell-text.h" - -#include <glib/gi18n.h> - -#include <libedataserver/libedataserver.h> - -/* This depends on ECalendar which is why I didn't put it in gal. */ -#include <misc/e-calendar.h> - -static void e_cell_date_edit_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec); -static void e_cell_date_edit_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec); -static void e_cell_date_edit_dispose (GObject *object); - -static gint e_cell_date_edit_do_popup (ECellPopup *ecp, - GdkEvent *event, - gint row, - gint view_col); -static void e_cell_date_edit_set_popup_values (ECellDateEdit *ecde); -static void e_cell_date_edit_select_matching_time (ECellDateEdit *ecde, - gchar *time); -static void e_cell_date_edit_show_popup (ECellDateEdit *ecde, - gint row, - gint view_col); -static void e_cell_date_edit_get_popup_pos (ECellDateEdit *ecde, - gint row, - gint view_col, - gint *x, - gint *y, - gint *height, - gint *width); - -static void e_cell_date_edit_rebuild_time_list (ECellDateEdit *ecde); - -static gint e_cell_date_edit_key_press (GtkWidget *popup_window, - GdkEventKey *event, - ECellDateEdit *ecde); -static gint e_cell_date_edit_button_press (GtkWidget *popup_window, - GdkEvent *button_event, - ECellDateEdit *ecde); -static void e_cell_date_edit_on_ok_clicked (GtkWidget *button, - ECellDateEdit *ecde); -static void e_cell_date_edit_show_time_invalid_warning (ECellDateEdit *ecde); -static void e_cell_date_edit_on_now_clicked (GtkWidget *button, - ECellDateEdit *ecde); -static void e_cell_date_edit_on_none_clicked (GtkWidget *button, - ECellDateEdit *ecde); -static void e_cell_date_edit_on_today_clicked (GtkWidget *button, - ECellDateEdit *ecde); -static void e_cell_date_edit_update_cell (ECellDateEdit *ecde, - const gchar *text); -static void e_cell_date_edit_on_time_selected (GtkTreeSelection *selection, - ECellDateEdit *ecde); -static void e_cell_date_edit_hide_popup (ECellDateEdit *ecde); - -/* Our arguments. */ -enum { - PROP_0, - PROP_SHOW_TIME, - PROP_SHOW_NOW_BUTTON, - PROP_SHOW_TODAY_BUTTON, - PROP_ALLOW_NO_DATE_SET, - PROP_USE_24_HOUR_FORMAT, - PROP_LOWER_HOUR, - PROP_UPPER_HOUR -}; - -G_DEFINE_TYPE (ECellDateEdit, e_cell_date_edit, E_TYPE_CELL_POPUP) - -static void -e_cell_date_edit_class_init (ECellDateEditClass *class) -{ - GObjectClass *object_class; - ECellPopupClass *ecpc; - - object_class = G_OBJECT_CLASS (class); - object_class->get_property = e_cell_date_edit_get_property; - object_class->set_property = e_cell_date_edit_set_property; - object_class->dispose = e_cell_date_edit_dispose; - - ecpc = E_CELL_POPUP_CLASS (class); - ecpc->popup = e_cell_date_edit_do_popup; - - g_object_class_install_property ( - object_class, - PROP_SHOW_TIME, - g_param_spec_boolean ( - "show_time", - NULL, - NULL, - TRUE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_SHOW_NOW_BUTTON, - g_param_spec_boolean ( - "show_now_button", - NULL, - NULL, - TRUE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_SHOW_TODAY_BUTTON, - g_param_spec_boolean ( - "show_today_button", - NULL, - NULL, - TRUE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_ALLOW_NO_DATE_SET, - g_param_spec_boolean ( - "allow_no_date_set", - NULL, - NULL, - TRUE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_USE_24_HOUR_FORMAT, - g_param_spec_boolean ( - "use_24_hour_format", - NULL, - NULL, - TRUE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_LOWER_HOUR, - g_param_spec_int ( - "lower_hour", - NULL, - NULL, - G_MININT, - G_MAXINT, - 0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_UPPER_HOUR, - g_param_spec_int ( - "upper_hour", - NULL, - NULL, - G_MININT, - G_MAXINT, - 24, - G_PARAM_READWRITE)); -} - -static void -e_cell_date_edit_init (ECellDateEdit *ecde) -{ - GtkWidget *frame, *vbox, *hbox, *vbox2; - GtkWidget *scrolled_window, *bbox, *tree_view; - GtkWidget *now_button, *today_button, *none_button, *ok_button; - GtkListStore *store; - - ecde->lower_hour = 0; - ecde->upper_hour = 24; - ecde->use_24_hour_format = TRUE; - ecde->need_time_list_rebuild = TRUE; - ecde->freeze_count = 0; - ecde->time_callback = NULL; - ecde->time_callback_data = NULL; - ecde->time_callback_destroy = NULL; - - /* We create one popup window for the ECell, since there will only - * ever be one popup in use at a time. */ - ecde->popup_window = gtk_window_new (GTK_WINDOW_POPUP); - - gtk_window_set_type_hint ( - GTK_WINDOW (ecde->popup_window), - GDK_WINDOW_TYPE_HINT_COMBO); - gtk_window_set_resizable (GTK_WINDOW (ecde->popup_window), TRUE); - - frame = gtk_frame_new (NULL); - gtk_container_add (GTK_CONTAINER (ecde->popup_window), frame); - gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT); - gtk_widget_show (frame); - - vbox = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (frame), vbox); - gtk_widget_show (vbox); - - hbox = gtk_hbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - gtk_widget_show (hbox); - - ecde->calendar = e_calendar_new (); - gnome_canvas_item_set ( - GNOME_CANVAS_ITEM (E_CALENDAR (ecde->calendar)->calitem), - "move_selection_when_moving", FALSE, - NULL); - gtk_box_pack_start (GTK_BOX (hbox), ecde->calendar, TRUE, TRUE, 0); - gtk_widget_show (ecde->calendar); - - vbox2 = gtk_vbox_new (FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), vbox2, TRUE, TRUE, 0); - gtk_widget_show (vbox2); - - ecde->time_entry = gtk_entry_new (); - gtk_widget_set_size_request (ecde->time_entry, 50, -1); - gtk_box_pack_start ( - GTK_BOX (vbox2), ecde->time_entry, - FALSE, FALSE, 0); - gtk_widget_show (ecde->time_entry); - - scrolled_window = gtk_scrolled_window_new (NULL, NULL); - gtk_box_pack_start (GTK_BOX (vbox2), scrolled_window, TRUE, TRUE, 0); - gtk_scrolled_window_set_policy ( - GTK_SCROLLED_WINDOW (scrolled_window), - GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); - gtk_widget_show (scrolled_window); - - store = gtk_list_store_new (1, G_TYPE_STRING); - tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store)); - g_object_unref (store); - - gtk_tree_view_append_column ( - GTK_TREE_VIEW (tree_view), - gtk_tree_view_column_new_with_attributes ( - "Text", gtk_cell_renderer_text_new (), "text", 0, NULL)); - - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE); - - gtk_scrolled_window_add_with_viewport ( - GTK_SCROLLED_WINDOW (scrolled_window), tree_view); - gtk_container_set_focus_vadjustment ( - GTK_CONTAINER (tree_view), - gtk_scrolled_window_get_vadjustment ( - GTK_SCROLLED_WINDOW (scrolled_window))); - gtk_container_set_focus_hadjustment ( - GTK_CONTAINER (tree_view), - gtk_scrolled_window_get_hadjustment ( - GTK_SCROLLED_WINDOW (scrolled_window))); - gtk_widget_show (tree_view); - ecde->time_tree_view = tree_view; - g_signal_connect ( - gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), "changed", - G_CALLBACK (e_cell_date_edit_on_time_selected), ecde); - - bbox = gtk_hbutton_box_new (); - gtk_container_set_border_width (GTK_CONTAINER (bbox), 4); - gtk_box_set_spacing (GTK_BOX (bbox), 2); - gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, FALSE, 0); - gtk_widget_show (bbox); - - now_button = gtk_button_new_with_label (_("Now")); - gtk_container_add (GTK_CONTAINER (bbox), now_button); - gtk_widget_show (now_button); - g_signal_connect ( - now_button, "clicked", - G_CALLBACK (e_cell_date_edit_on_now_clicked), ecde); - ecde->now_button = now_button; - - today_button = gtk_button_new_with_label (_("Today")); - gtk_container_add (GTK_CONTAINER (bbox), today_button); - gtk_widget_show (today_button); - g_signal_connect ( - today_button, "clicked", - G_CALLBACK (e_cell_date_edit_on_today_clicked), ecde); - ecde->today_button = today_button; - - /* Translators: "None" as a label of a button to unset date in a - * date table cell. */ - none_button = gtk_button_new_with_label (C_("table-date", "None")); - gtk_container_add (GTK_CONTAINER (bbox), none_button); - gtk_widget_show (none_button); - g_signal_connect ( - none_button, "clicked", - G_CALLBACK (e_cell_date_edit_on_none_clicked), ecde); - ecde->none_button = none_button; - - ok_button = gtk_button_new_with_label (_("OK")); - gtk_container_add (GTK_CONTAINER (bbox), ok_button); - gtk_widget_show (ok_button); - g_signal_connect ( - ok_button, "clicked", - G_CALLBACK (e_cell_date_edit_on_ok_clicked), ecde); - - g_signal_connect ( - ecde->popup_window, "key_press_event", - G_CALLBACK (e_cell_date_edit_key_press), ecde); - g_signal_connect ( - ecde->popup_window, "button_press_event", - G_CALLBACK (e_cell_date_edit_button_press), ecde); -} - -/** - * e_cell_date_edit_new: - * - * Creates a new ECellDateEdit renderer. - * - * Returns: an ECellDateEdit object. - */ -ECell * -e_cell_date_edit_new (void) -{ - return g_object_new (e_cell_date_edit_get_type (), NULL); -} - -static void -e_cell_date_edit_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ECellDateEdit *ecde; - - ecde = E_CELL_DATE_EDIT (object); - - switch (property_id) { - case PROP_SHOW_TIME: - g_value_set_boolean (value, gtk_widget_get_visible (ecde->time_entry)); - return; - case PROP_SHOW_NOW_BUTTON: - g_value_set_boolean (value, gtk_widget_get_visible (ecde->now_button)); - return; - case PROP_SHOW_TODAY_BUTTON: - g_value_set_boolean (value, gtk_widget_get_visible (ecde->today_button)); - return; - case PROP_ALLOW_NO_DATE_SET: - g_value_set_boolean (value, gtk_widget_get_visible (ecde->none_button)); - return; - case PROP_USE_24_HOUR_FORMAT: - g_value_set_boolean (value, ecde->use_24_hour_format); - return; - case PROP_LOWER_HOUR: - g_value_set_int (value, ecde->lower_hour); - return; - case PROP_UPPER_HOUR: - g_value_set_int (value, ecde->upper_hour); - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -e_cell_date_edit_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ECellDateEdit *ecde; - gint ivalue; - gboolean bvalue; - - ecde = E_CELL_DATE_EDIT (object); - - switch (property_id) { - case PROP_SHOW_TIME: - if (g_value_get_boolean (value)) { - gtk_widget_show (ecde->time_entry); - gtk_widget_show (ecde->time_tree_view); - } else { - gtk_widget_hide (ecde->time_entry); - gtk_widget_hide (ecde->time_tree_view); - } - return; - case PROP_SHOW_NOW_BUTTON: - if (g_value_get_boolean (value)) { - gtk_widget_show (ecde->now_button); - } else { - gtk_widget_hide (ecde->now_button); - } - return; - case PROP_SHOW_TODAY_BUTTON: - if (g_value_get_boolean (value)) { - gtk_widget_show (ecde->today_button); - } else { - gtk_widget_hide (ecde->today_button); - } - return; - case PROP_ALLOW_NO_DATE_SET: - if (g_value_get_boolean (value)) { - gtk_widget_show (ecde->none_button); - } else { - /* FIXME: What if we have no date set now. */ - gtk_widget_hide (ecde->none_button); - } - return; - case PROP_USE_24_HOUR_FORMAT: - bvalue = g_value_get_boolean (value); - if (ecde->use_24_hour_format != bvalue) { - ecde->use_24_hour_format = bvalue; - ecde->need_time_list_rebuild = TRUE; - } - return; - case PROP_LOWER_HOUR: - ivalue = g_value_get_int (value); - ivalue = CLAMP (ivalue, 0, 24); - if (ecde->lower_hour != ivalue) { - ecde->lower_hour = ivalue; - ecde->need_time_list_rebuild = TRUE; - } - return; - case PROP_UPPER_HOUR: - ivalue = g_value_get_int (value); - ivalue = CLAMP (ivalue, 0, 24); - if (ecde->upper_hour != ivalue) { - ecde->upper_hour = ivalue; - ecde->need_time_list_rebuild = TRUE; - } - return; - } - - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); -} - -static void -e_cell_date_edit_dispose (GObject *object) -{ - ECellDateEdit *ecde = E_CELL_DATE_EDIT (object); - - e_cell_date_edit_set_get_time_callback (ecde, NULL, NULL, NULL); - - if (ecde->popup_window != NULL) { - gtk_widget_destroy (ecde->popup_window); - ecde->popup_window = NULL; - } - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (e_cell_date_edit_parent_class)->dispose (object); -} - -static gint -e_cell_date_edit_do_popup (ECellPopup *ecp, - GdkEvent *event, - gint row, - gint view_col) -{ - ECellDateEdit *ecde = E_CELL_DATE_EDIT (ecp); - GdkWindow *window; - - e_cell_date_edit_show_popup (ecde, row, view_col); - e_cell_date_edit_set_popup_values (ecde); - - gtk_grab_add (ecde->popup_window); - - /* Set the focus to the first widget. */ - gtk_widget_grab_focus (ecde->time_entry); - window = gtk_widget_get_window (ecde->popup_window); - gdk_window_focus (window, GDK_CURRENT_TIME); - - return TRUE; -} - -static void -e_cell_date_edit_set_popup_values (ECellDateEdit *ecde) -{ - ECellPopup *ecp = E_CELL_POPUP (ecde); - ECellText *ecell_text = E_CELL_TEXT (ecp->child); - ECellView *ecv = (ECellView *) ecp->popup_cell_view; - ETableItem *eti; - ETableCol *ecol; - gchar *cell_text; - ETimeParseStatus status; - struct tm date_tm; - GDate date; - ECalendarItem *calitem; - gchar buffer[64]; - gboolean is_date = TRUE; - - eti = E_TABLE_ITEM (ecp->popup_cell_view->cell_view.e_table_item_view); - ecol = e_table_header_get_column (eti->header, ecp->popup_view_col); - - cell_text = e_cell_text_get_text ( - ecell_text, ecv->e_table_model, - ecol->col_idx, ecp->popup_row); - - /* Try to parse just a date first. If the value is only a date, we - * use a DATE value. */ - status = e_time_parse_date (cell_text, &date_tm); - if (status == E_TIME_PARSE_INVALID) { - is_date = FALSE; - status = e_time_parse_date_and_time (cell_text, &date_tm); - } - - /* If there is no date and time set, or the date is invalid, we clear - * the selections, else we select the appropriate date & time. */ - calitem = E_CALENDAR_ITEM (E_CALENDAR (ecde->calendar)->calitem); - if (status == E_TIME_PARSE_NONE || status == E_TIME_PARSE_INVALID) { - gtk_entry_set_text (GTK_ENTRY (ecde->time_entry), ""); - e_calendar_item_set_selection (calitem, NULL, NULL); - gtk_tree_selection_unselect_all ( - gtk_tree_view_get_selection ( - GTK_TREE_VIEW (ecde->time_tree_view))); - } else { - if (is_date) { - buffer[0] = '\0'; - } else { - e_time_format_time ( - &date_tm, ecde->use_24_hour_format, - FALSE, buffer, sizeof (buffer)); - } - gtk_entry_set_text (GTK_ENTRY (ecde->time_entry), buffer); - - g_date_clear (&date, 1); - g_date_set_dmy ( - &date, - date_tm.tm_mday, - date_tm.tm_mon + 1, - date_tm.tm_year + 1900); - e_calendar_item_set_selection (calitem, &date, &date); - - if (is_date) { - gtk_tree_selection_unselect_all ( - gtk_tree_view_get_selection ( - GTK_TREE_VIEW (ecde->time_tree_view))); - } else { - e_cell_date_edit_select_matching_time (ecde, buffer); - } - } - - e_cell_text_free_text (ecell_text, cell_text); -} - -static void -e_cell_date_edit_select_matching_time (ECellDateEdit *ecde, - gchar *time) -{ - gboolean found = FALSE; - gboolean valid; - GtkTreeSelection *selection; - GtkTreeIter iter; - GtkTreeModel *model; - - model = gtk_tree_view_get_model (GTK_TREE_VIEW (ecde->time_tree_view)); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (ecde->time_tree_view)); - - for (valid = gtk_tree_model_get_iter_first (model, &iter); - valid && !found; - valid = gtk_tree_model_iter_next (model, &iter)) { - gchar *str = NULL; - - gtk_tree_model_get (model, &iter, 0, &str, -1); - - if (g_str_equal (str, time)) { - GtkTreePath *path = gtk_tree_model_get_path (model, &iter); - - gtk_tree_view_set_cursor ( - GTK_TREE_VIEW (ecde->time_tree_view), - path, NULL, FALSE); - gtk_tree_view_scroll_to_cell ( - GTK_TREE_VIEW (ecde->time_tree_view), - path, NULL, FALSE, 0.0, 0.0); - gtk_tree_path_free (path); - - found = TRUE; - } - - g_free (str); - } - - if (!found) { - gtk_tree_selection_unselect_all (selection); - gtk_tree_view_scroll_to_point (GTK_TREE_VIEW (ecde->time_tree_view), 0, 0); - } -} - -static void -e_cell_date_edit_show_popup (ECellDateEdit *ecde, - gint row, - gint view_col) -{ - GdkWindow *window; - gint x, y, width, height; - - if (ecde->need_time_list_rebuild) - e_cell_date_edit_rebuild_time_list (ecde); - - /* This code is practically copied from GtkCombo. */ - - e_cell_date_edit_get_popup_pos (ecde, row, view_col, &x, &y, &height, &width); - - window = gtk_widget_get_window (ecde->popup_window); - gtk_window_move (GTK_WINDOW (ecde->popup_window), x, y); - gtk_widget_set_size_request (ecde->popup_window, width, height); - gtk_widget_realize (ecde->popup_window); - gdk_window_resize (window, width, height); - gtk_widget_show (ecde->popup_window); - - e_cell_popup_set_shown (E_CELL_POPUP (ecde), TRUE); -} - -/* Calculates the size and position of the popup window (like GtkCombo). */ -static void -e_cell_date_edit_get_popup_pos (ECellDateEdit *ecde, - gint row, - gint view_col, - gint *x, - gint *y, - gint *height, - gint *width) -{ - ECellPopup *ecp = E_CELL_POPUP (ecde); - ETableItem *eti; - GtkWidget *canvas; - GtkRequisition popup_requisition; - GtkAdjustment *adjustment; - GtkScrollable *scrollable; - GdkWindow *window; - gint avail_height, screen_width, column_width, row_height; - gdouble x1, y1, wx, wy; - gint value; - - eti = E_TABLE_ITEM (ecp->popup_cell_view->cell_view.e_table_item_view); - canvas = GTK_WIDGET (GNOME_CANVAS_ITEM (eti)->canvas); - - window = gtk_widget_get_window (canvas); - gdk_window_get_origin (window, x, y); - - x1 = e_table_header_col_diff (eti->header, 0, view_col + 1); - y1 = e_table_item_row_diff (eti, 0, row + 1); - column_width = e_table_header_col_diff ( - eti->header, view_col, view_col + 1); - row_height = e_table_item_row_diff (eti, row, row + 1); - gnome_canvas_item_i2w (GNOME_CANVAS_ITEM (eti), &x1, &y1); - - gnome_canvas_world_to_window ( - GNOME_CANVAS (canvas), x1, y1, &wx, &wy); - - x1 = wx; - y1 = wy; - - *x += x1; - /* The ETable positions don't include the grid lines, I think, so we - * add 1. */ - scrollable = GTK_SCROLLABLE (&GNOME_CANVAS (canvas)->layout); - adjustment = gtk_scrollable_get_vadjustment (scrollable); - value = (gint) gtk_adjustment_get_value (adjustment); - *y += y1 + 1 - value + ((GnomeCanvas *)canvas)->zoom_yofs; - - avail_height = gdk_screen_height () - *y; - - /* We'll use the entire screen width if needed, but we save space for - * the vertical scrollbar in case we need to show that. */ - screen_width = gdk_screen_width (); - - gtk_widget_get_preferred_size (ecde->popup_window, &popup_requisition, NULL); - - /* Calculate the desired width. */ - *width = popup_requisition.width; - - /* Use at least the same width as the column. */ - if (*width < column_width) - *width = column_width; - - /* Check if it fits in the available height. */ - if (popup_requisition.height > avail_height) { - /* It doesn't fit, so we see if we have the minimum space - * needed. */ - if (*y - row_height > avail_height) { - /* We don't, so we show the popup above the cell - * instead of below it. */ - *y -= (popup_requisition.height + row_height); - if (*y < 0) - *y = 0; - } - } - - /* We try to line it up with the right edge of the column, but we don't - * want it to go off the edges of the screen. */ - if (*x > screen_width) - *x = screen_width; - *x -= *width; - if (*x < 0) - *x = 0; - - *height = popup_requisition.height; -} - -/* This handles key press events in the popup window. If the Escape key is - * pressed we hide the popup, and do not change the cell contents. */ -static gint -e_cell_date_edit_key_press (GtkWidget *popup_window, - GdkEventKey *event, - ECellDateEdit *ecde) -{ - /* If the Escape key is pressed we hide the popup. */ - if (event->keyval != GDK_KEY_Escape) - return FALSE; - - e_cell_date_edit_hide_popup (ecde); - - return TRUE; -} - -/* This handles button press events in the popup window. If the button is - * pressed outside the popup, we hide it and do not change the cell contents. -*/ -static gint -e_cell_date_edit_button_press (GtkWidget *popup_window, - GdkEvent *button_event, - ECellDateEdit *ecde) -{ - GtkWidget *event_widget; - - event_widget = gtk_get_event_widget (button_event); - - if (gtk_widget_get_toplevel (event_widget) != popup_window) - e_cell_date_edit_hide_popup (ecde); - - return TRUE; -} - -/* Clears the time list and rebuilds it using the lower_hour, upper_hour - * and use_24_hour_format settings. */ -static void -e_cell_date_edit_rebuild_time_list (ECellDateEdit *ecde) -{ - GtkListStore *store; - gchar buffer[40]; - struct tm tmp_tm; - gint hour, min; - - store = GTK_LIST_STORE (gtk_tree_view_get_model ( - GTK_TREE_VIEW (ecde->time_tree_view))); - gtk_list_store_clear (store); - - /* Fill the struct tm with some sane values. */ - tmp_tm.tm_year = 2000; - tmp_tm.tm_mon = 0; - tmp_tm.tm_mday = 1; - tmp_tm.tm_sec = 0; - tmp_tm.tm_isdst = 0; - - for (hour = ecde->lower_hour; hour <= ecde->upper_hour; hour++) { - /* We don't want to display midnight at the end, since that is - * really in the next day. */ - if (hour == 24) - break; - - /* We want to finish on upper_hour, with min == 0. */ - for (min = 0; - min == 0 || (min < 60 && hour != ecde->upper_hour); - min += 30) { - GtkTreeIter iter; - - tmp_tm.tm_hour = hour; - tmp_tm.tm_min = min; - e_time_format_time (&tmp_tm, ecde->use_24_hour_format, - FALSE, buffer, sizeof (buffer)); - - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, buffer, -1); - } - } - - ecde->need_time_list_rebuild = FALSE; -} - -static void -e_cell_date_edit_on_ok_clicked (GtkWidget *button, - ECellDateEdit *ecde) -{ - ECalendarItem *calitem; - GDate start_date, end_date; - gboolean day_selected; - struct tm date_tm; - gchar buffer[64]; - const gchar *text; - ETimeParseStatus status; - gboolean is_date = FALSE; - - calitem = E_CALENDAR_ITEM (E_CALENDAR (ecde->calendar)->calitem); - day_selected = e_calendar_item_get_selection ( - calitem, &start_date, &end_date); - - text = gtk_entry_get_text (GTK_ENTRY (ecde->time_entry)); - status = e_time_parse_time (text, &date_tm); - if (status == E_TIME_PARSE_INVALID) { - e_cell_date_edit_show_time_invalid_warning (ecde); - return; - } else if (status == E_TIME_PARSE_NONE) { - is_date = TRUE; - } - - if (day_selected) { - date_tm.tm_year = g_date_get_year (&start_date) - 1900; - date_tm.tm_mon = g_date_get_month (&start_date) - 1; - date_tm.tm_mday = g_date_get_day (&start_date); - /* We need to call this to set the weekday. */ - mktime (&date_tm); - e_time_format_date_and_time (&date_tm, - ecde->use_24_hour_format, - !is_date, FALSE, - buffer, sizeof (buffer)); - } else { - buffer[0] = '\0'; - } - - e_cell_date_edit_update_cell (ecde, buffer); - e_cell_date_edit_hide_popup (ecde); -} - -static void -e_cell_date_edit_show_time_invalid_warning (ECellDateEdit *ecde) -{ - GtkWidget *dialog; - struct tm date_tm; - gchar buffer[64]; - - /* Create a useful error message showing the correct format. */ - date_tm.tm_year = 100; - date_tm.tm_mon = 0; - date_tm.tm_mday = 1; - date_tm.tm_hour = 1; - date_tm.tm_min = 30; - date_tm.tm_sec = 0; - date_tm.tm_isdst = -1; - e_time_format_time (&date_tm, ecde->use_24_hour_format, FALSE, - buffer, sizeof (buffer)); - - /* FIXME: Fix transient settings - I'm not sure it works with popup - * windows. Maybe we need to use a normal window without decorations.*/ - dialog = gtk_message_dialog_new ( - GTK_WINDOW (ecde->popup_window), - GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, - _("The time must be in the format: %s"), - buffer); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); -} - -static void -e_cell_date_edit_on_now_clicked (GtkWidget *button, - ECellDateEdit *ecde) -{ - struct tm tmp_tm; - time_t t; - gchar buffer[64]; - - if (ecde->time_callback) { - tmp_tm = ecde->time_callback ( - ecde, ecde->time_callback_data); - } else { - t = time (NULL); - tmp_tm = *localtime (&t); - } - - e_time_format_date_and_time ( - &tmp_tm, ecde->use_24_hour_format, - TRUE, FALSE, buffer, sizeof (buffer)); - - e_cell_date_edit_update_cell (ecde, buffer); - e_cell_date_edit_hide_popup (ecde); -} - -static void -e_cell_date_edit_on_none_clicked (GtkWidget *button, - ECellDateEdit *ecde) -{ - e_cell_date_edit_update_cell (ecde, ""); - e_cell_date_edit_hide_popup (ecde); -} - -static void -e_cell_date_edit_on_today_clicked (GtkWidget *button, - ECellDateEdit *ecde) -{ - struct tm tmp_tm; - time_t t; - gchar buffer[64]; - - if (ecde->time_callback) { - tmp_tm = ecde->time_callback ( - ecde, ecde->time_callback_data); - } else { - t = time (NULL); - tmp_tm = *localtime (&t); - } - - tmp_tm.tm_hour = 0; - tmp_tm.tm_min = 0; - tmp_tm.tm_sec = 0; - - e_time_format_date_and_time ( - &tmp_tm, ecde->use_24_hour_format, - FALSE, FALSE, buffer, sizeof (buffer)); - - e_cell_date_edit_update_cell (ecde, buffer); - e_cell_date_edit_hide_popup (ecde); -} - -static void -e_cell_date_edit_update_cell (ECellDateEdit *ecde, - const gchar *text) -{ - ECellPopup *ecp = E_CELL_POPUP (ecde); - ECellText *ecell_text = E_CELL_TEXT (ecp->child); - ECellView *ecv = (ECellView *) ecp->popup_cell_view; - ETableItem *eti = E_TABLE_ITEM (ecv->e_table_item_view); - ETableCol *ecol; - gchar *old_text; - - /* Compare the new text with the existing cell contents. */ - ecol = e_table_header_get_column (eti->header, ecp->popup_view_col); - - old_text = e_cell_text_get_text ( - ecell_text, ecv->e_table_model, - ecol->col_idx, ecp->popup_row); - - /* If they are different, update the cell contents. */ - if (strcmp (old_text, text)) { - e_cell_text_set_value ( - ecell_text, ecv->e_table_model, - ecol->col_idx, ecp->popup_row, text); - e_cell_leave_edit ( - ecv, ecp->popup_view_col, - ecol->col_idx, ecp->popup_row, NULL); - } - - e_cell_text_free_text (ecell_text, old_text); -} - -static void -e_cell_date_edit_on_time_selected (GtkTreeSelection *selection, - ECellDateEdit *ecde) -{ - gchar *list_item_text = NULL; - GtkTreeIter iter; - GtkTreeModel *model; - - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) - return; - - gtk_tree_model_get (model, &iter, 0, &list_item_text, -1); - - g_return_if_fail (list_item_text != NULL); - - gtk_entry_set_text (GTK_ENTRY (ecde->time_entry), list_item_text); - - g_free (list_item_text); -} - -static void -e_cell_date_edit_hide_popup (ECellDateEdit *ecde) -{ - gtk_grab_remove (ecde->popup_window); - gtk_widget_hide (ecde->popup_window); - e_cell_popup_set_shown (E_CELL_POPUP (ecde), FALSE); -} - -/* These freeze and thaw the rebuilding of the time list. They are useful when - * setting several properties which result in rebuilds of the list, e.g. the - * lower_hour, upper_hour and use_24_hour_format properties. */ -void -e_cell_date_edit_freeze (ECellDateEdit *ecde) -{ - g_return_if_fail (E_IS_CELL_DATE_EDIT (ecde)); - - ecde->freeze_count++; -} - -void -e_cell_date_edit_thaw (ECellDateEdit *ecde) -{ - g_return_if_fail (E_IS_CELL_DATE_EDIT (ecde)); - - if (ecde->freeze_count > 0) { - ecde->freeze_count--; - - if (ecde->freeze_count == 0) - e_cell_date_edit_rebuild_time_list (ecde); - } -} - -/* Sets a callback to use to get the current time. This is useful if the - * application needs to use its own timezone data rather than rely on the - * Unix timezone. */ -void -e_cell_date_edit_set_get_time_callback (ECellDateEdit *ecde, - ECellDateEditGetTimeCallback cb, - gpointer data, - GDestroyNotify destroy) -{ - g_return_if_fail (E_IS_CELL_DATE_EDIT (ecde)); - - if (ecde->time_callback_data && ecde->time_callback_destroy) - (*ecde->time_callback_destroy) (ecde->time_callback_data); - - ecde->time_callback = cb; - ecde->time_callback_data = data; - ecde->time_callback_destroy = destroy; -} diff --git a/widgets/table/e-cell-date-edit.h b/widgets/table/e-cell-date-edit.h deleted file mode 100644 index 186302d79a..0000000000 --- a/widgets/table/e-cell-date-edit.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Damon Chaplin <damon@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -/* - * ECellDateEdit - a subclass of ECellPopup used to show a date with a popup - * window to edit it. - */ - -#ifndef _E_CELL_DATE_EDIT_H_ -#define _E_CELL_DATE_EDIT_H_ - -#include <time.h> -#include <table/e-cell-popup.h> - -/* Standard GObject macros */ -#define E_TYPE_CELL_DATE_EDIT \ - (e_cell_date_edit_get_type ()) -#define E_CELL_DATE_EDIT(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_CELL_DATE_EDIT, ECellDateEdit)) -#define E_CELL_DATE_EDIT_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_CELL_DATE_EDIT, ECellDateEditClass)) -#define E_IS_CELL_DATE_EDIT(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_CELL_DATE_EDIT)) -#define E_IS_CELL_DATE_EDIT_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_CELL_DATE_EDIT)) -#define E_CELL_DATE_EDIT_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_CELL_DATE_EDIT, ECellDateEditClass)) - -G_BEGIN_DECLS - -typedef struct _ECellDateEdit ECellDateEdit; -typedef struct _ECellDateEditClass ECellDateEditClass; - -/* The type of the callback function optionally used to get the current time. - */ -typedef struct tm (*ECellDateEditGetTimeCallback) (ECellDateEdit *ecde, - gpointer data); - -struct _ECellDateEdit { - ECellPopup parent; - - GtkWidget *popup_window; - GtkWidget *calendar; - GtkWidget *time_entry; - GtkWidget *time_tree_view; - - GtkWidget *now_button; - GtkWidget *today_button; - GtkWidget *none_button; - - /* This is the range of hours we show in the time list. */ - gint lower_hour; - gint upper_hour; - - /* TRUE if we use 24-hour format for the time list and entry. */ - gboolean use_24_hour_format; - - /* This is TRUE if we need to rebuild the list of times. */ - gboolean need_time_list_rebuild; - - /* The freeze count for rebuilding the time list. We only rebuild when - * this is 0. */ - gint freeze_count; - - ECellDateEditGetTimeCallback time_callback; - gpointer time_callback_data; - GDestroyNotify time_callback_destroy; -}; - -struct _ECellDateEditClass { - ECellPopupClass parent_class; -}; - -GType e_cell_date_edit_get_type (void) G_GNUC_CONST; -ECell * e_cell_date_edit_new (void); - -/* These freeze and thaw the rebuilding of the time list. They are useful when - * setting several properties which result in rebuilds of the list, e.g. the - * lower_hour, upper_hour and use_24_hour_format properties. */ -void e_cell_date_edit_freeze (ECellDateEdit *ecde); -void e_cell_date_edit_thaw (ECellDateEdit *ecde); - -/* Sets a callback to use to get the current time. This is useful if the - * application needs to use its own timezone data rather than rely on the - * Unix timezone. */ -void e_cell_date_edit_set_get_time_callback - (ECellDateEdit *ecde, - ECellDateEditGetTimeCallback cb, - gpointer data, - GDestroyNotify destroy); - -G_END_DECLS - -#endif /* _E_CELL_DATE_EDIT_H_ */ diff --git a/widgets/table/e-cell-date.c b/widgets/table/e-cell-date.c deleted file mode 100644 index 79534aff45..0000000000 --- a/widgets/table/e-cell-date.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <sys/time.h> -#include <time.h> -#include <unistd.h> -#include <string.h> - -#include <glib/gi18n.h> -#include "e-util/e-util.h" -#include "e-util/e-unicode.h" -#include "e-util/e-datetime-format.h" - -#include "e-cell-date.h" - -G_DEFINE_TYPE (ECellDate, e_cell_date, E_TYPE_CELL_TEXT) - -static gchar * -ecd_get_text (ECellText *cell, - ETableModel *model, - gint col, - gint row) -{ - time_t date = GPOINTER_TO_INT (e_table_model_value_at (model, col, row)); - const gchar *fmt_component, *fmt_part = NULL; - - if (date == 0) { - return g_strdup (_("?")); - } - - fmt_component = g_object_get_data ((GObject *) cell, "fmt-component"); - if (!fmt_component || !*fmt_component) - fmt_component = "Default"; - else - fmt_part = "table"; - - return e_datetime_format_format ( - fmt_component, fmt_part, DTFormatKindDateTime, date); -} - -static void -ecd_free_text (ECellText *cell, - gchar *text) -{ - g_free (text); -} - -static void -e_cell_date_class_init (ECellDateClass *class) -{ - ECellTextClass *ectc = E_CELL_TEXT_CLASS (class); - - ectc->get_text = ecd_get_text; - ectc->free_text = ecd_free_text; -} - -static void -e_cell_date_init (ECellDate *ecd) -{ -} - -/** - * 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", "underline_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, underline, 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 gchar *fontname, - GtkJustification justify) -{ - ECellDate *ecd = g_object_new (E_TYPE_CELL_DATE, NULL); - - e_cell_text_construct (E_CELL_TEXT (ecd), fontname, justify); - - return (ECell *) ecd; -} - -void -e_cell_date_set_format_component (ECellDate *ecd, - const gchar *fmt_component) -{ - g_return_if_fail (ecd != NULL); - - g_object_set_data_full ( - G_OBJECT (ecd), "fmt-component", - g_strdup (fmt_component), g_free); -} diff --git a/widgets/table/e-cell-date.h b/widgets/table/e-cell-date.h deleted file mode 100644 index c498095241..0000000000 --- a/widgets/table/e-cell-date.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_CELL_DATE_H -#define E_CELL_DATE_H - -#include <table/e-cell-text.h> - -/* Standard GObject macros */ -#define E_TYPE_CELL_DATE \ - (e_cell_date_get_type ()) -#define E_CELL_DATE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_CELL_DATE, ECellDate)) -#define E_CELL_DATE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_CELL_DATE, ECellDateClass)) -#define E_IS_CELL_DATE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_CELL_DATE)) -#define E_IS_CELL_DATE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_CELL_DATE)) -#define E_CELL_DATE_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_CELL_DATE, ECellDateClass)) - -G_BEGIN_DECLS - -typedef struct _ECellDate ECellDate; -typedef struct _ECellDateClass ECellDateClass; - -struct _ECellDate { - ECellText parent; -}; - -struct _ECellDateClass { - ECellTextClass parent_class; -}; - -GType e_cell_date_get_type (void) G_GNUC_CONST; -ECell * e_cell_date_new (const gchar *fontname, - GtkJustification justify); -void e_cell_date_set_format_component - (ECellDate *ecd, - const gchar *fmt_component); - -G_END_DECLS - -#endif /* E_CELL_DATE_H */ diff --git a/widgets/table/e-cell-hbox.c b/widgets/table/e-cell-hbox.c deleted file mode 100644 index 74301a773c..0000000000 --- a/widgets/table/e-cell-hbox.c +++ /dev/null @@ -1,354 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Srinivasa Ragavan <sragavan@novell.com> - * - * A majority of code taken from: - * - * the ECellText renderer. - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <ctype.h> -#include <math.h> -#include <stdio.h> - -#include <gtk/gtk.h> - -/* #include "a11y/gal-a11y-e-cell-registry.h" */ -/* #include "a11y/gal-a11y-e-cell-vbox.h" */ -#include "e-util/e-util.h" - -#include "e-cell-hbox.h" -#include "e-table-item.h" - -G_DEFINE_TYPE (ECellHbox, e_cell_hbox, E_TYPE_CELL) - -#define INDENT_AMOUNT 16 -#define MAX_CELL_SIZE 25 - -/* - * ECell::new_view method - */ -static ECellView * -ecv_new_view (ECell *ecell, - ETableModel *table_model, - gpointer e_table_item_view) -{ - ECellHbox *ecv = E_CELL_HBOX (ecell); - ECellHboxView *hbox_view = g_new0 (ECellHboxView, 1); - gint i; - - hbox_view->cell_view.ecell = ecell; - hbox_view->cell_view.e_table_model = table_model; - hbox_view->cell_view.e_table_item_view = e_table_item_view; - hbox_view->cell_view.kill_view_cb = NULL; - hbox_view->cell_view.kill_view_cb_data = NULL; - - /* create our subcell view */ - hbox_view->subcell_view_count = ecv->subcell_count; - hbox_view->subcell_views = g_new (ECellView *, hbox_view->subcell_view_count); - hbox_view->model_cols = g_new (int, hbox_view->subcell_view_count); - hbox_view->def_size_cols = g_new (int, hbox_view->subcell_view_count); - - for (i = 0; i < hbox_view->subcell_view_count; i++) { - hbox_view->subcell_views[i] = e_cell_new_view (ecv->subcells[i], table_model, e_table_item_view /* XXX */); - hbox_view->model_cols[i] = ecv->model_cols[i]; - hbox_view->def_size_cols[i] = ecv->def_size_cols[i]; - } - - return (ECellView *) hbox_view; -} - -/* - * ECell::kill_view method - */ -static void -ecv_kill_view (ECellView *ecv) -{ - ECellHboxView *hbox_view = (ECellHboxView *) ecv; - gint i; - - if (hbox_view->cell_view.kill_view_cb) - (hbox_view->cell_view.kill_view_cb)(ecv, hbox_view->cell_view.kill_view_cb_data); - - if (hbox_view->cell_view.kill_view_cb_data) - g_list_free (hbox_view->cell_view.kill_view_cb_data); - - /* kill our subcell view */ - for (i = 0; i < hbox_view->subcell_view_count; i++) - e_cell_kill_view (hbox_view->subcell_views[i]); - - g_free (hbox_view->model_cols); - g_free (hbox_view->def_size_cols); - g_free (hbox_view->subcell_views); - g_free (hbox_view); -} - -/* - * ECell::realize method - */ -static void -ecv_realize (ECellView *ecell_view) -{ - ECellHboxView *hbox_view = (ECellHboxView *) ecell_view; - gint i; - - /* realize our subcell view */ - for (i = 0; i < hbox_view->subcell_view_count; i++) - e_cell_realize (hbox_view->subcell_views[i]); - - if (E_CELL_CLASS (e_cell_hbox_parent_class)->realize) - (* E_CELL_CLASS (e_cell_hbox_parent_class)->realize) (ecell_view); -} - -/* - * ECell::unrealize method - */ -static void -ecv_unrealize (ECellView *ecv) -{ - ECellHboxView *hbox_view = (ECellHboxView *) ecv; - gint i; - - /* unrealize our subcell view. */ - for (i = 0; i < hbox_view->subcell_view_count; i++) - e_cell_unrealize (hbox_view->subcell_views[i]); - - if (E_CELL_CLASS (e_cell_hbox_parent_class)->unrealize) - (* E_CELL_CLASS (e_cell_hbox_parent_class)->unrealize) (ecv); -} - -/* - * ECell::draw method - */ -static void -ecv_draw (ECellView *ecell_view, - cairo_t *cr, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - gint x1, - gint y1, - gint x2, - gint y2) -{ - ECellHboxView *hbox_view = (ECellHboxView *) ecell_view; - - gint subcell_offset = 0; - gint i; - gint allotted_width = x2 - x1; - - for (i = 0; i < hbox_view->subcell_view_count; i++) { - /* Now cause our subcells to draw their contents, - * shifted by subcell_offset pixels */ - gint width = allotted_width * hbox_view->def_size_cols[i] / 100; - /* e_cell_max_width_by_row (hbox_view->subcell_views[i], hbox_view->model_cols[i], view_col, row); - if (width < hbox_view->def_size_cols[i]) - width = hbox_view->def_size_cols[i]; - printf ("width of %d %d of %d\n", width,hbox_view->def_size_cols[i], allotted_width); */ - - e_cell_draw ( - hbox_view->subcell_views[i], cr, - hbox_view->model_cols[i], view_col, row, flags, - x1 + subcell_offset , y1, - x1 + subcell_offset + width, y2); - - subcell_offset += width; /* e_cell_max_width_by_row (hbox_view->subcell_views[i], hbox_view->model_cols[i], view_col, row); */ - } -} - -/* - * ECell::event method - */ -static gint -ecv_event (ECellView *ecell_view, - GdkEvent *event, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - ECellActions *actions) -{ - ECellHboxView *hbox_view = (ECellHboxView *) ecell_view; - gint y = 0; - gint i; - gint subcell_offset = 0; - - switch (event->type) { - case GDK_BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - y = event->button.y; - break; - case GDK_MOTION_NOTIFY: - y = event->motion.y; - break; - default: - /* nada */ - break; - } - - for (i = 0; i < hbox_view->subcell_view_count; i++) { - gint width = e_cell_max_width_by_row (hbox_view->subcell_views[i], hbox_view->model_cols[i], view_col, row); - if (width < hbox_view->def_size_cols[i]) - width = hbox_view->def_size_cols[i]; - if (y < subcell_offset + width) - return e_cell_event (hbox_view->subcell_views[i], event, hbox_view->model_cols[i], view_col, row, flags, actions); - subcell_offset += width; - } - return 0; -} - -/* - * ECell::height method - */ -static gint -ecv_height (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row) -{ - ECellHboxView *hbox_view = (ECellHboxView *) ecell_view; - gint height = 0, max_height = 0; - gint i; - - for (i = 0; i < hbox_view->subcell_view_count; i++) { - height = e_cell_height (hbox_view->subcell_views[i], hbox_view->model_cols[i], view_col, row); - max_height = MAX (max_height, height); - } - return max_height; -} - -/* - * ECell::max_width method - */ -static gint -ecv_max_width (ECellView *ecell_view, - gint model_col, - gint view_col) -{ - ECellHboxView *hbox_view = (ECellHboxView *) ecell_view; - gint width = 0; - gint i; - - for (i = 0; i < hbox_view->subcell_view_count; i++) { - gint cell_width = e_cell_max_width (hbox_view->subcell_views[i], hbox_view->model_cols[i], view_col); - - if (cell_width < hbox_view->def_size_cols[i]) - cell_width = hbox_view->def_size_cols[i]; - width += cell_width; - } - - return width; -} - -/* - * GObject::dispose method - */ -static void -ecv_dispose (GObject *object) -{ - ECellHbox *ecv = E_CELL_HBOX (object); - gint i; - - /* destroy our subcell */ - for (i = 0; i < ecv->subcell_count; i++) - if (ecv->subcells[i]) - g_object_unref (ecv->subcells[i]); - g_free (ecv->subcells); - ecv->subcells = NULL; - ecv->subcell_count = 0; - - g_free (ecv->model_cols); - ecv->model_cols = NULL; - - g_free (ecv->def_size_cols); - ecv->def_size_cols = NULL; - - G_OBJECT_CLASS (e_cell_hbox_parent_class)->dispose (object); -} - -static void -e_cell_hbox_class_init (ECellHboxClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - ECellClass *ecc = E_CELL_CLASS (class); - - object_class->dispose = ecv_dispose; - - ecc->new_view = ecv_new_view; - ecc->kill_view = ecv_kill_view; - ecc->realize = ecv_realize; - ecc->unrealize = ecv_unrealize; - ecc->draw = ecv_draw; - ecc->event = ecv_event; - ecc->height = ecv_height; - - ecc->max_width = ecv_max_width; - -/* gal_a11y_e_cell_registry_add_cell_type (NULL, E_TYPE_CELL_HBOX, gal_a11y_e_cell_hbox_new); */ -} - -static void -e_cell_hbox_init (ECellHbox *ecv) -{ - ecv->subcells = NULL; - ecv->subcell_count = 0; -} - -/** - * e_cell_hbox_new: - * - * Creates a new ECell renderer that can be used to render multiple - * child cells. - * - * Return value: an ECell object that can be used to render multiple - * child cells. - **/ -ECell * -e_cell_hbox_new (void) -{ - return g_object_new (E_TYPE_CELL_HBOX, NULL); -} - -void -e_cell_hbox_append (ECellHbox *hbox, - ECell *subcell, - gint model_col, - gint size) -{ - hbox->subcell_count++; - - hbox->subcells = g_renew (ECell *, hbox->subcells, hbox->subcell_count); - hbox->model_cols = g_renew (int, hbox->model_cols, hbox->subcell_count); - hbox->def_size_cols = g_renew (int, hbox->def_size_cols, hbox->subcell_count); - - hbox->subcells[hbox->subcell_count - 1] = subcell; - hbox->model_cols[hbox->subcell_count - 1] = model_col; - hbox->def_size_cols[hbox->subcell_count - 1] = size; - - if (subcell) - g_object_ref_sink (subcell); -} diff --git a/widgets/table/e-cell-hbox.h b/widgets/table/e-cell-hbox.h deleted file mode 100644 index 41cc01e6a1..0000000000 --- a/widgets/table/e-cell-hbox.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Srinivasa Ragavan <sragavan@novell.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_CELL_HBOX_H_ -#define _E_CELL_HBOX_H_ - -#include <libgnomecanvas/libgnomecanvas.h> -#include <table/e-cell.h> - -/* Standard GObject macros */ -#define E_TYPE_CELL_HBOX \ - (e_cell_hbox_get_type ()) -#define E_CELL_HBOX(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_CELL_HBOX, ECellHbox)) -#define E_CELL_HBOX_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_CELL_HBOX, ECellHboxClass)) -#define E_IS_CELL_HBOX(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_CELL_HBOX)) -#define E_IS_CELL_HBOX_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_CELL_HBOX)) -#define E_CELL_HBOX_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_CELL_HBOX, ECellHboxClass)) - -G_BEGIN_DECLS - -typedef struct _ECellHbox ECellHbox; -typedef struct _ECellHboxView ECellHboxView; -typedef struct _ECellHboxClass ECellHboxClass; - -struct _ECellHbox { - ECell parent; - - gint subcell_count; - ECell **subcells; - gint *model_cols; - gint *def_size_cols; -}; - -struct _ECellHboxView { - ECellView cell_view; - - gint subcell_view_count; - ECellView **subcell_views; - gint *model_cols; - gint *def_size_cols; -}; - -struct _ECellHboxClass { - ECellClass parent_class; -}; - -GType e_cell_hbox_get_type (void) G_GNUC_CONST; -ECell * e_cell_hbox_new (void); -void e_cell_hbox_append (ECellHbox *vbox, - ECell *subcell, - gint model_col, - gint size); - -G_END_DECLS - -#endif /* _E_CELL_HBOX_H_ */ diff --git a/widgets/table/e-cell-number.c b/widgets/table/e-cell-number.c deleted file mode 100644 index 6e2f685a86..0000000000 --- a/widgets/table/e-cell-number.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <sys/time.h> -#include <unistd.h> - -#include <glib/gi18n.h> -#include "e-util/e-util.h" - -#include "e-cell-number.h" - -G_DEFINE_TYPE (ECellNumber, e_cell_number, E_TYPE_CELL_TEXT) - -static gchar * -ecn_get_text (ECellText *cell, - ETableModel *model, - gint col, - gint row) -{ - gpointer value; - - value = e_table_model_value_at (model, col, row); - - return e_format_number (GPOINTER_TO_INT (value)); -} - -static void -ecn_free_text (ECellText *cell, - gchar *text) -{ - g_free (text); -} - -static void -e_cell_number_class_init (ECellNumberClass *class) -{ - ECellTextClass *ectc = E_CELL_TEXT_CLASS (class); - - ectc->get_text = ecn_get_text; - ectc->free_text = ecn_free_text; -} - -static void -e_cell_number_init (ECellNumber *cell_number) -{ -} - -/** - * 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 gchar *fontname, - GtkJustification justify) -{ - ECellNumber *ecn = g_object_new (E_TYPE_CELL_NUMBER, NULL); - - e_cell_text_construct (E_CELL_TEXT (ecn), fontname, justify); - - return (ECell *) ecn; -} - diff --git a/widgets/table/e-cell-number.h b/widgets/table/e-cell-number.h deleted file mode 100644 index 539f27679e..0000000000 --- a/widgets/table/e-cell-number.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_CELL_NUMBER_H -#define E_CELL_NUMBER_H - -#include <table/e-cell-text.h> - -/* Standard GObject macros */ -#define E_TYPE_CELL_NUMBER \ - (e_cell_number_get_type ()) -#define E_CELL_NUMBER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_CELL_NUMBER, ECellNumber)) -#define E_CELL_NUMBER_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_CELL_NUMBER, ECellNumberClass)) -#define E_IS_CELL_NUMBER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_CELL_NUMBER)) -#define E_IS_CELL_NUMBER_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_CELL_NUMBER)) -#define E_CELL_NUMBER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_CELL_NUMBER, ECellNumberClass)) - -G_BEGIN_DECLS - -typedef struct _ECellNumber ECellNumber; -typedef struct _ECellNumberClass ECellNumberClass; - -struct _ECellNumber { - ECellText parent; -}; - -struct _ECellNumberClass { - ECellTextClass parent_class; -}; - -GType e_cell_number_get_type (void) G_GNUC_CONST; -ECell * e_cell_number_new (const gchar *fontname, - GtkJustification justify); - -G_END_DECLS - -#endif /* E_CELL_NUMBER_H */ diff --git a/widgets/table/e-cell-percent.c b/widgets/table/e-cell-percent.c deleted file mode 100644 index 81465d5a62..0000000000 --- a/widgets/table/e-cell-percent.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Damon Chaplin <damon@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -/* - * ECellPercent - a subclass of ECellText used to show an integer percentage - * in an ETable. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <ctype.h> - -#include <sys/time.h> -#include <unistd.h> -#include <stdio.h> -#include <glib/gi18n.h> - -#include "e-cell-percent.h" - -G_DEFINE_TYPE (ECellPercent, e_cell_percent, E_TYPE_CELL_TEXT) - -static gchar * -ecp_get_text (ECellText *cell, - ETableModel *model, - gint col, - gint row) -{ - gint percent; - static gchar buffer[8]; - - percent = GPOINTER_TO_INT (e_table_model_value_at (model, col, row)); - - /* A -ve value means the property is not set. */ - if (percent < 0) { - buffer[0] = '\0'; - } else { - g_snprintf (buffer, sizeof (buffer), "%i%%", percent); - } - - return buffer; -} - -static void -ecp_free_text (ECellText *cell, - gchar *text) -{ - /* Do Nothing. */ -} - -/* FIXME: We need to set the "transient_for" property for the dialog. */ -static void -show_percent_warning (void) -{ - GtkWidget *dialog; - - dialog = gtk_message_dialog_new ( - NULL, 0, - GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, - "%s", _("The percent value must be between 0 and 100, inclusive")); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); -} - -static void -ecp_set_value (ECellText *cell, - ETableModel *model, - gint col, - gint row, - const gchar *text) -{ - gint matched, percent; - gboolean empty = TRUE; - const gchar *p; - - if (text) { - p = text; - while (*p) { - if (!isspace ((guchar) *p)) { - empty = FALSE; - break; - } - p++; - } - } - - if (empty) { - percent = -1; - } else { - matched = sscanf (text, "%i", &percent); - - if (matched != 1 || percent < 0 || percent > 100) { - show_percent_warning (); - return; - } - } - - e_table_model_set_value_at ( - model, col, row, - GINT_TO_POINTER (percent)); -} - -static void -e_cell_percent_class_init (ECellPercentClass *ecpc) -{ - ECellTextClass *ectc = (ECellTextClass *) ecpc; - - ectc->get_text = ecp_get_text; - ectc->free_text = ecp_free_text; - ectc->set_value = ecp_set_value; -} - -static void -e_cell_percent_init (ECellPercent *ecp) -{ -} - -/** - * e_cell_percent_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 an integer - * percentage that comes 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_percent_new (const gchar *fontname, - GtkJustification justify) -{ - ECellPercent *ecn = g_object_new (E_TYPE_CELL_PERCENT, NULL); - - e_cell_text_construct (E_CELL_TEXT (ecn), fontname, justify); - - return (ECell *) ecn; -} diff --git a/widgets/table/e-cell-percent.h b/widgets/table/e-cell-percent.h deleted file mode 100644 index be4fdac9b7..0000000000 --- a/widgets/table/e-cell-percent.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Damon Chaplin <damon@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -/* - * ECellPercent - a subclass of ECellText used to show an integer percentage - * in an ETable. - */ - -#ifndef E_CELL_PERCENT_H -#define E_CELL_PERCENT_H - -#include <table/e-cell-text.h> - -/* Standard GObject macros */ -#define E_TYPE_CELL_PERCENT \ - (e_cell_percent_get_type ()) -#define E_CELL_PERCENT(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_CELL_PERCENT, ECellPercent)) -#define E_CELL_PERCENT_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_CELL_PERCENT, ECellPercentClass)) -#define E_IS_CELL_NUMBER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_CELL_PERCENT)) -#define E_IS_CELL_NUMBER_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_CELL_PERCENT)) -#define E_CELL_NUMBER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_CELL_PERCENT, ECellPercentClass)) - -G_BEGIN_DECLS - -typedef struct _ECellPercent ECellPercent; -typedef struct _ECellPercentClass ECellPercentClass; - -struct _ECellPercent { - ECellText parent; -}; - -struct _ECellPercentClass { - ECellTextClass parent_class; -}; - -GType e_cell_percent_get_type (void) G_GNUC_CONST; -ECell * e_cell_percent_new (const gchar *fontname, - GtkJustification justify); - -G_END_DECLS - -#endif /* E_CELL_PERCENT_H */ diff --git a/widgets/table/e-cell-pixbuf.c b/widgets/table/e-cell-pixbuf.c deleted file mode 100644 index 41b030ec5a..0000000000 --- a/widgets/table/e-cell-pixbuf.c +++ /dev/null @@ -1,389 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Vladimir Vukicevic <vladimir@ximian.com> - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> - -#include <libgnomecanvas/libgnomecanvas.h> - -#include <glib/gi18n.h> -#include <gtk/gtk.h> -#include "e-cell-pixbuf.h" - -G_DEFINE_TYPE (ECellPixbuf, e_cell_pixbuf, E_TYPE_CELL) - -typedef struct _ECellPixbufView ECellPixbufView; - -struct _ECellPixbufView { - ECellView cell_view; - GnomeCanvas *canvas; -}; - -/* Object argument IDs */ -enum { - PROP_0, - - PROP_SELECTED_COLUMN, - PROP_FOCUSED_COLUMN, - PROP_UNSELECTED_COLUMN -}; - -/* - * ECellPixbuf functions - */ - -ECell * -e_cell_pixbuf_new (void) -{ - return g_object_new (E_TYPE_CELL_PIXBUF, NULL); -} - -/* - * ECell methods - */ - -static ECellView * -pixbuf_new_view (ECell *ecell, - ETableModel *table_model, - gpointer e_table_item_view) -{ - ECellPixbufView *pixbuf_view = g_new0 (ECellPixbufView, 1); - ETableItem *eti = E_TABLE_ITEM (e_table_item_view); - GnomeCanvas *canvas = GNOME_CANVAS_ITEM (eti)->canvas; - - pixbuf_view->cell_view.ecell = ecell; - pixbuf_view->cell_view.e_table_model = table_model; - pixbuf_view->cell_view.e_table_item_view = e_table_item_view; - pixbuf_view->cell_view.kill_view_cb = NULL; - pixbuf_view->cell_view.kill_view_cb_data = NULL; - - pixbuf_view->canvas = canvas; - - return (ECellView *) pixbuf_view; -} - -static void -pixbuf_kill_view (ECellView *ecell_view) -{ - ECellPixbufView *pixbuf_view = (ECellPixbufView *) ecell_view; - - if (pixbuf_view->cell_view.kill_view_cb) - pixbuf_view->cell_view.kill_view_cb ( - ecell_view, pixbuf_view->cell_view.kill_view_cb_data); - - if (pixbuf_view->cell_view.kill_view_cb_data) - g_list_free (pixbuf_view->cell_view.kill_view_cb_data); - - g_free (pixbuf_view); -} - -static void -pixbuf_draw (ECellView *ecell_view, - cairo_t *cr, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - gint x1, - gint y1, - gint x2, - gint y2) -{ - GdkPixbuf *cell_pixbuf; - gint real_x, real_y; - gint pix_w, pix_h; - - cell_pixbuf = e_table_model_value_at (ecell_view->e_table_model, - 1, row); - - /* we can't make sure we really got a pixbuf since, well, it's a Gdk thing */ - - if (x2 - x1 == 0) - return; - - if (!cell_pixbuf) - return; - - pix_w = gdk_pixbuf_get_width (cell_pixbuf); - pix_h = gdk_pixbuf_get_height (cell_pixbuf); - - /* We center the pixbuf within our allocated space */ - if (x2 - x1 > pix_w) { - gint diff = (x2 - x1) - pix_w; - real_x = x1 + diff / 2; - } else { - real_x = x1; - } - - if (y2 - y1 > pix_h) { - gint diff = (y2 - y1) - pix_h; - real_y = y1 + diff / 2; - } else { - real_y = y1; - } - - cairo_save (cr); - gdk_cairo_set_source_pixbuf (cr, cell_pixbuf, real_x, real_y); - cairo_paint_with_alpha (cr, 1); - cairo_restore (cr); -} - -static gint -pixbuf_event (ECellView *ecell_view, - GdkEvent *event, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - ECellActions *actions) -{ - /* noop */ - - return FALSE; -} - -static gint -pixbuf_height (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row) -{ - GdkPixbuf *pixbuf; - if (row == -1) { - if (e_table_model_row_count (ecell_view->e_table_model) > 0) { - row = 0; - } else { - return 6; - } - } - - pixbuf = (GdkPixbuf *) e_table_model_value_at (ecell_view->e_table_model, 1, row); - if (!pixbuf) - return 0; - - /* We give ourselves 3 pixels of padding on either side */ - return gdk_pixbuf_get_height (pixbuf) + 6; -} - -/* - * ECell::print method - */ -static void -pixbuf_print (ECellView *ecell_view, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width, - gdouble height) -{ - GdkPixbuf *pixbuf; - gint scale; - cairo_t *cr = gtk_print_context_get_cairo_context (context); - - pixbuf = (GdkPixbuf *) e_table_model_value_at (ecell_view->e_table_model, 1, row); - if (pixbuf == NULL) - return; - - scale = gdk_pixbuf_get_height (pixbuf); - cairo_save (cr); - cairo_translate (cr, 0, (gdouble)(height - scale) / (gdouble) 2); - gdk_cairo_set_source_pixbuf (cr, pixbuf, (gdouble) scale, (gdouble) scale); - cairo_paint (cr); - cairo_restore (cr); -} - -static gdouble -pixbuf_print_height (ECellView *ecell_view, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width) -{ - GdkPixbuf *pixbuf; - - if (row == -1) { - if (e_table_model_row_count (ecell_view->e_table_model) > 0) { - row = 0; - } else { - return 6; - } - } - - pixbuf = (GdkPixbuf *) e_table_model_value_at (ecell_view->e_table_model, 1, row); - if (!pixbuf) - return 0; - - /* We give ourselves 3 pixels of padding on either side */ - return gdk_pixbuf_get_height (pixbuf); -} - -static gint -pixbuf_max_width (ECellView *ecell_view, - gint model_col, - gint view_col) -{ - gint pw; - gint num_rows, i; - gint max_width = -1; - - if (model_col == 0) { - num_rows = e_table_model_row_count (ecell_view->e_table_model); - - for (i = 0; i <= num_rows; i++) { - GdkPixbuf *pixbuf = (GdkPixbuf *) e_table_model_value_at - (ecell_view->e_table_model, - 1, - i); - if (!pixbuf) - continue; - pw = gdk_pixbuf_get_width (pixbuf); - if (max_width < pw) - max_width = pw; - } - } else { - return -1; - } - - return max_width; -} - -static void -pixbuf_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ECellPixbuf *pixbuf; - - pixbuf = E_CELL_PIXBUF (object); - - switch (property_id) { - case PROP_SELECTED_COLUMN: - pixbuf->selected_column = g_value_get_int (value); - break; - - case PROP_FOCUSED_COLUMN: - pixbuf->focused_column = g_value_get_int (value); - break; - - case PROP_UNSELECTED_COLUMN: - pixbuf->unselected_column = g_value_get_int (value); - break; - - default: - return; - } -} - -/* Get_arg handler for the pixbuf item */ -static void -pixbuf_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ECellPixbuf *pixbuf; - - pixbuf = E_CELL_PIXBUF (object); - - switch (property_id) { - case PROP_SELECTED_COLUMN: - g_value_set_int (value, pixbuf->selected_column); - break; - - case PROP_FOCUSED_COLUMN: - g_value_set_int (value, pixbuf->focused_column); - break; - - case PROP_UNSELECTED_COLUMN: - g_value_set_int (value, pixbuf->unselected_column); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -e_cell_pixbuf_init (ECellPixbuf *ecp) -{ - ecp->selected_column = -1; - ecp->focused_column = -1; - ecp->unselected_column = -1; -} - -static void -e_cell_pixbuf_class_init (ECellPixbufClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - ECellClass *ecc = E_CELL_CLASS (class); - - object_class->set_property = pixbuf_set_property; - object_class->get_property = pixbuf_get_property; - - ecc->new_view = pixbuf_new_view; - ecc->kill_view = pixbuf_kill_view; - ecc->draw = pixbuf_draw; - ecc->event = pixbuf_event; - ecc->height = pixbuf_height; - ecc->print = pixbuf_print; - ecc->print_height = pixbuf_print_height; - ecc->max_width = pixbuf_max_width; - - g_object_class_install_property ( - object_class, - PROP_SELECTED_COLUMN, - g_param_spec_int ( - "selected_column", - "Selected Column", - NULL, - 0, G_MAXINT, 0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_FOCUSED_COLUMN, - g_param_spec_int ( - "focused_column", - "Focused Column", - NULL, - 0, G_MAXINT, 0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_UNSELECTED_COLUMN, - g_param_spec_int ( - "unselected_column", - "Unselected Column", - NULL, - 0, G_MAXINT, 0, - G_PARAM_READWRITE)); -} - diff --git a/widgets/table/e-cell-pixbuf.h b/widgets/table/e-cell-pixbuf.h deleted file mode 100644 index f4848f7430..0000000000 --- a/widgets/table/e-cell-pixbuf.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * e-cell-pixbuf.h - An ECell that displays a GdkPixbuf - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Vladimir Vukicevic <vladimir@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_CELL_PIXBUF_H_ -#define _E_CELL_PIXBUF_H_ - -#include <table/e-table.h> - -/* Standard GObject macros */ -#define E_TYPE_CELL_PIXBUF \ - (e_cell_pixbuf_get_type ()) -#define E_CELL_PIXBUF(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_CELL_PIXBUF, ECellPixbuf)) -#define E_CELL_PIXBUF_CLASS(cls) \ - (G_TYPE_CHECK_INSTANCE_CAST_CLASS \ - ((cls), E_TYPE_CELL_PIXBUF, ECellPixbufClass)) -#define E_IS_CELL_PIXBUF(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_CELL_PIXBUF)) -#define E_IS_CELL_PIXBUF_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_CELL_PIXBUF)) -#define E_CELL_PIXBUF_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_CELL_PIXBUF, ECellPixbufClass)) - -G_BEGIN_DECLS - -typedef struct _ECellPixbuf ECellPixbuf; -typedef struct _ECellPixbufClass ECellPixbufClass; - -struct _ECellPixbuf { - ECell parent; - - gint selected_column; - gint focused_column; - gint unselected_column; -}; - -struct _ECellPixbufClass { - ECellClass parent_class; -}; - -GType e_cell_pixbuf_get_type (void) G_GNUC_CONST; -ECell * e_cell_pixbuf_new (void); - -G_END_DECLS - -#endif /* _E_CELL_PIXBUF_H */ diff --git a/widgets/table/e-cell-popup.c b/widgets/table/e-cell-popup.c deleted file mode 100644 index ce821700f3..0000000000 --- a/widgets/table/e-cell-popup.c +++ /dev/null @@ -1,551 +0,0 @@ -/* - * e-cell-popup.c: Popup cell renderer - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -/* - * ECellPopup - an abstract ECell class used to support popup selections like - * a GtkCombo widget. It contains a child ECell, e.g. an ECellText, but when - * selected it displays an arrow on the right edge which the user can click to - * show a popup. Subclasses implement the popup class function to show the - * popup. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gdk/gdkkeysyms.h> - -#include "gal-a11y-e-cell-popup.h" -#include "gal-a11y-e-cell-registry.h" -#include "e-util/e-util.h" - -#include "e-cell-popup.h" -#include "e-table-item.h" -#include <gtk/gtk.h> - -#define E_CELL_POPUP_ARROW_SIZE 16 -#define E_CELL_POPUP_ARROW_PAD 3 - -static void e_cell_popup_dispose (GObject *object); - -static ECellView * ecp_new_view (ECell *ecell, - ETableModel *table_model, - void *e_table_item_view); -static void ecp_kill_view (ECellView *ecv); -static void ecp_realize (ECellView *ecv); -static void ecp_unrealize (ECellView *ecv); -static void ecp_draw (ECellView *ecv, - cairo_t *cr, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - gint x1, - gint y1, - gint x2, - gint y2); -static gint ecp_event (ECellView *ecv, - GdkEvent *event, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - ECellActions *actions); -static gint ecp_height (ECellView *ecv, - gint model_col, - gint view_col, - gint row); -static gpointer ecp_enter_edit (ECellView *ecv, - gint model_col, - gint view_col, - gint row); -static void ecp_leave_edit (ECellView *ecv, - gint model_col, - gint view_col, - gint row, - void *edit_context); -static void ecp_print (ECellView *ecv, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width, - gdouble height); -static gdouble ecp_print_height (ECellView *ecv, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width); -static gint ecp_max_width (ECellView *ecv, - gint model_col, - gint view_col); -static gchar *ecp_get_bg_color (ECellView *ecell_view, gint row); - -static gint e_cell_popup_do_popup (ECellPopupView *ecp_view, - GdkEvent *event, - gint row, - gint model_col); - -G_DEFINE_TYPE (ECellPopup, e_cell_popup, E_TYPE_CELL) - -static void -e_cell_popup_class_init (ECellPopupClass *class) -{ - ECellClass *ecc = E_CELL_CLASS (class); - - G_OBJECT_CLASS (class)->dispose = e_cell_popup_dispose; - - ecc->new_view = ecp_new_view; - ecc->kill_view = ecp_kill_view; - ecc->realize = ecp_realize; - ecc->unrealize = ecp_unrealize; - ecc->draw = ecp_draw; - ecc->event = ecp_event; - ecc->height = ecp_height; - ecc->enter_edit = ecp_enter_edit; - ecc->leave_edit = ecp_leave_edit; - ecc->print = ecp_print; - ecc->print_height = ecp_print_height; - ecc->max_width = ecp_max_width; - ecc->get_bg_color = ecp_get_bg_color; - - gal_a11y_e_cell_registry_add_cell_type ( - NULL, E_TYPE_CELL_POPUP, - gal_a11y_e_cell_popup_new); -} - -static void -e_cell_popup_init (ECellPopup *ecp) -{ - ecp->popup_shown = FALSE; - ecp->popup_model = NULL; -} - -/** - * e_cell_popup_new: - * - * Creates a new ECellPopup renderer. - * - * Returns: an ECellPopup object. - */ -ECell * -e_cell_popup_new (void) -{ - return g_object_new (E_TYPE_CELL_POPUP, NULL); -} - -static void -e_cell_popup_dispose (GObject *object) -{ - ECellPopup *ecp = E_CELL_POPUP (object); - - if (ecp->child) - g_object_unref (ecp->child); - ecp->child = NULL; - - G_OBJECT_CLASS (e_cell_popup_parent_class)->dispose (object); -} - -/* - * ECell::new_view method - */ -static ECellView * -ecp_new_view (ECell *ecell, - ETableModel *table_model, - gpointer e_table_item_view) -{ - ECellPopup *ecp = E_CELL_POPUP (ecell); - ECellPopupView *ecp_view; - - /* We must have a child ECell before we create any views. */ - g_return_val_if_fail (ecp->child != NULL, NULL); - - ecp_view = g_new0 (ECellPopupView, 1); - - ecp_view->cell_view.ecell = ecell; - ecp_view->cell_view.e_table_model = table_model; - ecp_view->cell_view.e_table_item_view = e_table_item_view; - ecp_view->cell_view.kill_view_cb = NULL; - ecp_view->cell_view.kill_view_cb_data = NULL; - - ecp_view->child_view = e_cell_new_view ( - ecp->child, table_model, - e_table_item_view); - - return (ECellView *) ecp_view; -} - -/* - * ECell::kill_view method - */ -static void -ecp_kill_view (ECellView *ecv) -{ - ECellPopupView *ecp_view = (ECellPopupView *) ecv; - - if (ecp_view->cell_view.kill_view_cb) - ecp_view->cell_view.kill_view_cb ( - ecv, ecp_view->cell_view.kill_view_cb_data); - - if (ecp_view->cell_view.kill_view_cb_data) - g_list_free (ecp_view->cell_view.kill_view_cb_data); - - if (ecp_view->child_view) - e_cell_kill_view (ecp_view->child_view); - - g_free (ecp_view); -} - -/* - * ECell::realize method - */ -static void -ecp_realize (ECellView *ecv) -{ - ECellPopupView *ecp_view = (ECellPopupView *) ecv; - - e_cell_realize (ecp_view->child_view); - - if (E_CELL_CLASS (e_cell_popup_parent_class)->realize) - (* E_CELL_CLASS (e_cell_popup_parent_class)->realize) (ecv); -} - -/* - * ECell::unrealize method - */ -static void -ecp_unrealize (ECellView *ecv) -{ - ECellPopupView *ecp_view = (ECellPopupView *) ecv; - - e_cell_unrealize (ecp_view->child_view); - - if (E_CELL_CLASS (e_cell_popup_parent_class)->unrealize) - (* E_CELL_CLASS (e_cell_popup_parent_class)->unrealize) (ecv); -} - -/* - * ECell::draw method - */ -static void -ecp_draw (ECellView *ecv, - cairo_t *cr, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - gint x1, - gint y1, - gint x2, - gint y2) -{ - ECellPopup *ecp = E_CELL_POPUP (ecv->ecell); - ECellPopupView *ecp_view = (ECellPopupView *) ecv; - GtkWidget *canvas; - gboolean show_popup_arrow; - - cairo_save (cr); - - canvas = GTK_WIDGET (GNOME_CANVAS_ITEM (ecv->e_table_item_view)->canvas); - - /* Display the popup arrow if we are the cursor cell, or the popup - * is shown for this cell. */ - show_popup_arrow = - e_table_model_is_cell_editable ( - ecv->e_table_model, model_col, row) && - (flags & E_CELL_CURSOR || - (ecp->popup_shown && ecp->popup_view_col == view_col - && ecp->popup_row == row - && ecp->popup_model == ((ECellView *) ecp_view)->e_table_model)); - - if (flags & E_CELL_CURSOR) - ecp->popup_arrow_shown = show_popup_arrow; - - if (show_popup_arrow) { - GtkStyleContext *style_context; - GdkRGBA color; - gint arrow_x; - gint arrow_y; - gint arrow_size; - gint midpoint_y; - - e_cell_draw ( - ecp_view->child_view, cr, model_col, - view_col, row, flags, - x1, y1, x2 - E_CELL_POPUP_ARROW_SIZE, y2); - - midpoint_y = y1 + ((y2 - y1 + 1) / 2); - - arrow_x = x2 - E_CELL_POPUP_ARROW_SIZE; - arrow_y = midpoint_y - E_CELL_POPUP_ARROW_SIZE / 2; - arrow_size = E_CELL_POPUP_ARROW_SIZE; - - style_context = gtk_widget_get_style_context (canvas); - - gtk_style_context_save (style_context); - - gtk_style_context_add_class ( - style_context, GTK_STYLE_CLASS_CELL); - - gtk_style_context_get_background_color ( - style_context, GTK_STATE_FLAG_NORMAL, &color); - - cairo_save (cr); - gdk_cairo_set_source_rgba (cr, &color); - gtk_render_background ( - style_context, cr, - (gdouble) arrow_x, - (gdouble) arrow_y, - (gdouble) arrow_size, - (gdouble) arrow_size); - cairo_restore (cr); - - arrow_x += E_CELL_POPUP_ARROW_PAD; - arrow_y += E_CELL_POPUP_ARROW_PAD; - arrow_size -= (E_CELL_POPUP_ARROW_PAD * 2); - - cairo_save (cr); - gtk_render_arrow ( - style_context, cr, G_PI, - (gdouble) arrow_x, - (gdouble) arrow_y, - (gdouble) arrow_size); - cairo_restore (cr); - - gtk_style_context_restore (style_context); - } else { - e_cell_draw ( - ecp_view->child_view, cr, model_col, - view_col, row, flags, x1, y1, x2, y2); - } - - cairo_restore (cr); -} - -/* - * ECell::event method - */ -static gint -ecp_event (ECellView *ecv, - GdkEvent *event, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - ECellActions *actions) -{ - ECellPopupView *ecp_view = (ECellPopupView *) ecv; - ECellPopup *ecp = E_CELL_POPUP (ecp_view->cell_view.ecell); - ETableItem *eti = E_TABLE_ITEM (ecv->e_table_item_view); - gint width; - - switch (event->type) { - case GDK_BUTTON_PRESS: - if (e_table_model_is_cell_editable (ecv->e_table_model, model_col, row) && - flags & E_CELL_CURSOR - && ecp->popup_arrow_shown) { - width = e_table_header_col_diff ( - eti->header, view_col, - view_col + 1); - - /* FIXME: The event coords seem to be relative to the - * text within the cell, so we have to add 4. */ - if (event->button.x + 4 >= width - E_CELL_POPUP_ARROW_SIZE) { - return e_cell_popup_do_popup (ecp_view, event, row, view_col); - } - } - break; - case GDK_KEY_PRESS: - if (e_table_model_is_cell_editable (ecv->e_table_model, model_col, row) && - event->key.state & GDK_MOD1_MASK - && event->key.keyval == GDK_KEY_Down) { - return e_cell_popup_do_popup (ecp_view, event, row, view_col); - } - break; - default: - break; - } - - return e_cell_event ( - ecp_view->child_view, event, model_col, view_col, - row, flags, actions); -} - -/* - * ECell::height method - */ -static gint -ecp_height (ECellView *ecv, - gint model_col, - gint view_col, - gint row) -{ - ECellPopupView *ecp_view = (ECellPopupView *) ecv; - - return e_cell_height (ecp_view->child_view, model_col, view_col, row); -} - -/* - * ECellView::enter_edit method - */ -static gpointer -ecp_enter_edit (ECellView *ecv, - gint model_col, - gint view_col, - gint row) -{ - ECellPopupView *ecp_view = (ECellPopupView *) ecv; - - return e_cell_enter_edit (ecp_view->child_view, model_col, view_col, row); -} - -/* - * ECellView::leave_edit method - */ -static void -ecp_leave_edit (ECellView *ecv, - gint model_col, - gint view_col, - gint row, - gpointer edit_context) -{ - ECellPopupView *ecp_view = (ECellPopupView *) ecv; - - e_cell_leave_edit ( - ecp_view->child_view, model_col, view_col, row, - edit_context); -} - -static void -ecp_print (ECellView *ecv, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width, - gdouble height) -{ - ECellPopupView *ecp_view = (ECellPopupView *) ecv; - - e_cell_print ( - ecp_view->child_view, context, model_col, view_col, row, - width, height); -} - -static gdouble -ecp_print_height (ECellView *ecv, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width) -{ - ECellPopupView *ecp_view = (ECellPopupView *) ecv; - - return e_cell_print_height ( - ecp_view->child_view, context, model_col, - view_col, row, width); -} - -static gint -ecp_max_width (ECellView *ecv, - gint model_col, - gint view_col) -{ - ECellPopupView *ecp_view = (ECellPopupView *) ecv; - - return e_cell_max_width (ecp_view->child_view, model_col, view_col); -} - -static gchar * -ecp_get_bg_color (ECellView *ecell_view, - gint row) -{ - ECellPopupView *ecp_view = (ECellPopupView *) ecell_view; - - return e_cell_get_bg_color (ecp_view->child_view, row); -} - -ECell * -e_cell_popup_get_child (ECellPopup *ecp) -{ - g_return_val_if_fail (E_IS_CELL_POPUP (ecp), NULL); - - return ecp->child; -} - -void -e_cell_popup_set_child (ECellPopup *ecp, - ECell *child) -{ - g_return_if_fail (E_IS_CELL_POPUP (ecp)); - - if (ecp->child) - g_object_unref (ecp->child); - - ecp->child = child; - g_object_ref (child); -} - -static gint -e_cell_popup_do_popup (ECellPopupView *ecp_view, - GdkEvent *event, - gint row, - gint view_col) -{ - ECellPopup *ecp = E_CELL_POPUP (ecp_view->cell_view.ecell); - gint (*popup_func) (ECellPopup *ecp, GdkEvent *event, gint row, gint view_col); - - ecp->popup_cell_view = ecp_view; - - popup_func = E_CELL_POPUP_CLASS (G_OBJECT_GET_CLASS (ecp))->popup; - - ecp->popup_view_col = view_col; - ecp->popup_row = row; - ecp->popup_model = ((ECellView *) ecp_view)->e_table_model; - - return popup_func ? popup_func (ecp, event, row, view_col) : FALSE; -} - -/* This redraws the popup cell. Only use this if you know popup_view_col and - * popup_row are valid. */ -void -e_cell_popup_queue_cell_redraw (ECellPopup *ecp) -{ - ETableItem *eti; - - eti = E_TABLE_ITEM (ecp->popup_cell_view->cell_view.e_table_item_view); - - e_table_item_redraw_range ( - eti, ecp->popup_view_col, ecp->popup_row, - ecp->popup_view_col, ecp->popup_row); -} - -void -e_cell_popup_set_shown (ECellPopup *ecp, - gboolean shown) -{ - ecp->popup_shown = shown; - e_cell_popup_queue_cell_redraw (ecp); -} diff --git a/widgets/table/e-cell-popup.h b/widgets/table/e-cell-popup.h deleted file mode 100644 index bc99196eaf..0000000000 --- a/widgets/table/e-cell-popup.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Damon Chaplin <damon@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -/* - * ECellPopup - an ECell used to support popup selections like a GtkCombo - * widget. It contains a child ECell, e.g. an ECellText, but when selected it - * displays an arrow on the right edge which the user can click to show a - * popup. It will support subclassing or signals so that different types of - * popup can be provided. - */ - -#ifndef _E_CELL_POPUP_H_ -#define _E_CELL_POPUP_H_ - -#include <libgnomecanvas/libgnomecanvas.h> -#include <table/e-cell.h> - -/* Standard GObject macros */ -#define E_TYPE_CELL_POPUP \ - (e_cell_popup_get_type ()) -#define E_CELL_POPUP(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_CELL_POPUP, ECellPopup)) -#define E_CELL_POPUP_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_CELL_POPUP, ECellPopupClass)) -#define E_IS_CELL_POPUP(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_CELL_POPUP)) -#define E_IS_CELL_POPUP_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_CELL_POPUP)) -#define E_CELL_POPUP_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_CELL_POPUP, ECellPopupClass)) - -G_BEGIN_DECLS - -typedef struct _ECellPopup ECellPopup; -typedef struct _ECellPopupView ECellPopupView; -typedef struct _ECellPopupClass ECellPopupClass; - -struct _ECellPopup { - ECell parent; - - ECell *child; - - /* This is TRUE if the popup window is shown for the cell being - * edited. While shown we display the arrow indented. */ - gboolean popup_shown; - - /* This is TRUE if the popup arrow is shown for the cell being edited. - * This is needed to stop the first click on the cell from popping up - * the popup window. We only popup the window after we have drawn the - * arrow. */ - gboolean popup_arrow_shown; - - /* The view in which the popup is shown. */ - ECellPopupView *popup_cell_view; - - gint popup_view_col; - gint popup_row; - ETableModel *popup_model; -}; - -struct _ECellPopupView { - ECellView cell_view; - - ECellView *child_view; -}; - -struct _ECellPopupClass { - ECellClass parent_class; - - /* Virtual function for subclasses to override. */ - gint (*popup) (ECellPopup *ecp, - GdkEvent *event, - gint row, - gint view_col); -}; - -GType e_cell_popup_get_type (void) G_GNUC_CONST; -ECell * e_cell_popup_new (void); -ECell * e_cell_popup_get_child (ECellPopup *ecp); -void e_cell_popup_set_child (ECellPopup *ecp, - ECell *child); -void e_cell_popup_set_shown (ECellPopup *ecp, - gboolean shown); -void e_cell_popup_queue_cell_redraw (ECellPopup *ecp); - -G_END_DECLS - -#endif /* _E_CELL_POPUP_H_ */ diff --git a/widgets/table/e-cell-size.c b/widgets/table/e-cell-size.c deleted file mode 100644 index 8f01847d7c..0000000000 --- a/widgets/table/e-cell-size.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <sys/time.h> -#include <unistd.h> - -#include "e-util/e-util.h" - -#include "e-cell-size.h" - -G_DEFINE_TYPE (ECellSize, e_cell_size, E_TYPE_CELL_TEXT) - -static gchar * -ecd_get_text (ECellText *cell, - ETableModel *model, - gint col, - gint row) -{ - gint size = GPOINTER_TO_INT (e_table_model_value_at (model, col, row)); - gfloat fsize; - - if (size < 1024) { - return g_strdup_printf ("%d bytes", size); - } else { - fsize = ((gfloat) size) / 1024.0; - if (fsize < 1024.0) { - return g_strdup_printf ("%d K", (gint) fsize); - } else { - fsize /= 1024.0; - return g_strdup_printf ("%.1f MB", fsize); - } - } -} - -static void -ecd_free_text (ECellText *cell, - gchar *text) -{ - g_free (text); -} - -static void -e_cell_size_class_init (ECellSizeClass *class) -{ - ECellTextClass *ectc = E_CELL_TEXT_CLASS (class); - - ectc->get_text = ecd_get_text; - ectc->free_text = ecd_free_text; -} - -static void -e_cell_size_init (ECellSize *e_cell_size) -{ -} - -/** - * 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, underline, - * bold, color and a size filter. - * - * The arguments "strikeout_column", "underline_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, underline, 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 gchar *fontname, - GtkJustification justify) -{ - ECellSize *ecd = g_object_new (E_TYPE_CELL_SIZE, NULL); - - e_cell_text_construct (E_CELL_TEXT (ecd), fontname, justify); - - return (ECell *) ecd; -} - diff --git a/widgets/table/e-cell-size.h b/widgets/table/e-cell-size.h deleted file mode 100644 index 8b52343b8a..0000000000 --- a/widgets/table/e-cell-size.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * e-cell-size.h: Size item for e-table. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_CELL_SIZE_H -#define E_CELL_SIZE_H - -#include <table/e-cell-text.h> - -/* Standard GObject macros */ -#define E_TYPE_CELL_SIZE \ - (e_cell_size_get_type ()) -#define E_CELL_SIZE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_CELL_SIZE, ECellSize)) -#define E_CELL_SIZE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_CELL_SIZE, ECellSizeClass)) -#define E_IS_CELL_SIZE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_CELL_SIZE)) -#define E_IS_CELL_SIZE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_CELL_SIZE)) -#define E_CELL_SIZE_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_CELL_SIZE, ECellSizeClass)) - -G_BEGIN_DECLS - -typedef struct _ECellSize ECellSize; -typedef struct _ECellSizeClass ECellSizeClass; - -struct _ECellSize { - ECellText parent; -}; - -struct _ECellSizeClass { - ECellTextClass parent_class; -}; - -GType e_cell_size_get_type (void) G_GNUC_CONST; -ECell * e_cell_size_new (const gchar *fontname, - GtkJustification justify); - -G_END_DECLS - -#endif /* E_CELL_SIZE_H */ diff --git a/widgets/table/e-cell-text.c b/widgets/table/e-cell-text.c deleted file mode 100644 index 6ad47b4c50..0000000000 --- a/widgets/table/e-cell-text.c +++ /dev/null @@ -1,2811 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Miguel de Icaza <miguel@ximian.com> - * Chris Lahey <clahey@ximian.com> - * - * 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> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <ctype.h> -#include <math.h> -#include <string.h> - -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> -#include <libgnomecanvas/libgnomecanvas.h> - -#include "text/e-text.h" -#include <glib/gi18n.h> -#include "e-util/e-text-event-processor.h" -#include "e-util/e-text-event-processor-emacs-like.h" -#include "e-util/e-util.h" -#include "misc/e-canvas.h" -#include "e-util/e-unicode.h" - -#include "e-table.h" -#include "e-cell-text.h" -#include "e-table-item.h" - -#define d(x) -#define DO_SELECTION 1 -#define VIEW_TO_CELL(view) E_CELL_TEXT (((ECellView *)view)->ecell) - -#if d(!)0 -#define e_table_item_leave_edit_(x) (e_table_item_leave_edit((x)), g_print ("%s: e_table_item_leave_edit\n", __FUNCTION__)) -#else -#define e_table_item_leave_edit_(x) (e_table_item_leave_edit((x))) -#endif - -/* This defines a line of text */ -struct line { - gchar *text; /* Line's text UTF-8, it is a pointer into the text->text string */ - gint length; /* Line's length in BYTES */ - gint width; /* Line's width in pixels */ - gint ellipsis_length; /* Length before adding ellipsis in BYTES */ -}; - -/* Object argument IDs */ -enum { - PROP_0, - - PROP_STRIKEOUT_COLUMN, - PROP_UNDERLINE_COLUMN, - PROP_BOLD_COLUMN, - PROP_COLOR_COLUMN, - PROP_EDITABLE, - PROP_BG_COLOR_COLUMN -}; - -enum { - E_SELECTION_PRIMARY, - E_SELECTION_CLIPBOARD -}; - -/* signals */ -enum { - TEXT_INSERTED, - TEXT_DELETED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0 }; - -static GdkAtom clipboard_atom = GDK_NONE; - -G_DEFINE_TYPE (ECellText, e_cell_text, E_TYPE_CELL) - -#define UTF8_ATOM gdk_atom_intern ("UTF8_STRING", FALSE) - -#define TEXT_PAD 4 - -typedef struct { - gpointer lines; /* Text split into lines (private field) */ - gint num_lines; /* Number of lines of text */ - gint max_width; - gint ref_count; -} ECellTextLineBreaks; - -typedef struct _CellEdit CellEdit; - -typedef struct { - ECellView cell_view; - GdkCursor *i_cursor; - - GnomeCanvas *canvas; - - /* - * During editing. - */ - CellEdit *edit; - - gint xofs, yofs; /* This gets added to the x - and y for the cell text. */ - gdouble ellipsis_width[2]; /* The width of the ellipsis. */ -} ECellTextView; - -struct _CellEdit { - - ECellTextView *text_view; - - gint model_col, view_col, row; - gint cell_width; - - PangoLayout *layout; - - gchar *text; - - gchar *old_text; - - /* - * Where the editing is taking place - */ - - gint 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. */ - gint selection_start; /* Start of selection - IN BYTES */ - gint 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 */ - - gboolean has_selection; /* TRUE if we have the selection */ - - guint pointer_in : 1; - guint default_cursor_shown : 1; - GtkIMContext *im_context; - gboolean need_im_reset; - gboolean im_context_signals_registered; - - guint16 preedit_length; /* length of preedit string, in bytes */ - gint preedit_pos; /* position of preedit cursor */ - - 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, gchar *data, gint length); - -static void _get_tep (CellEdit *edit); - -static gint get_position_from_xy (CellEdit *edit, gint x, gint y); -static gboolean _blink_scroll_timeout (gpointer data); - -static void e_cell_text_preedit_changed_cb (GtkIMContext *context, ECellTextView *text_view); -static void e_cell_text_commit_cb (GtkIMContext *context, const gchar *str, ECellTextView *text_view); -static gboolean e_cell_text_retrieve_surrounding_cb (GtkIMContext *context, ECellTextView *text_view); -static gboolean e_cell_text_delete_surrounding_cb (GtkIMContext *context, gint offset, gint n_chars, ECellTextView *text_view); -static void _insert (ECellTextView *text_view, const gchar *string, gint value); -static void _delete_selection (ECellTextView *text_view); -static PangoAttrList * build_attr_list (ECellTextView *text_view, gint row, gint text_length); -static void update_im_cursor_location (ECellTextView *tv); - -static gchar * -ect_real_get_text (ECellText *cell, - ETableModel *model, - gint col, - gint row) -{ - return e_table_model_value_at (model, col, row); -} - -static void -ect_real_free_text (ECellText *cell, - gchar *text) -{ -} - -/* This is the default method for setting the ETableModel value based on - * the text in the ECellText. This simply uses the text as it is - it assumes - * the value in the model is a gchar *. Subclasses may parse the text into - * data structures to pass to the model. */ -static void -ect_real_set_value (ECellText *cell, - ETableModel *model, - gint col, - gint row, - const gchar *text) -{ - e_table_model_set_value_at (model, col, row, text); -} - -static void -ect_queue_redraw (ECellTextView *text_view, - gint view_col, - gint view_row) -{ - e_table_item_redraw_range ( - text_view->cell_view.e_table_item_view, - view_col, view_row, view_col, view_row); -} - -/* - * Shuts down the editing process - */ -static void -ect_stop_editing (ECellTextView *text_view, - gboolean commit) -{ - GdkWindow *window; - CellEdit *edit = text_view->edit; - gint row, view_col, model_col; - gchar *old_text, *text; - - if (!edit) - return; - - window = gtk_widget_get_window (GTK_WIDGET (text_view->canvas)); - - row = edit->row; - view_col = edit->view_col; - model_col = edit->model_col; - - old_text = edit->old_text; - text = edit->text; - if (edit->tep) - g_object_unref (edit->tep); - if (!edit->default_cursor_shown) { - gdk_window_set_cursor (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_signal_handlers_disconnect_matched ( - edit->im_context, - G_SIGNAL_MATCH_DATA, 0, 0, - NULL, NULL, text_view); - - if (edit->layout) - g_object_unref (edit->layout); - - g_free (edit); - - text_view->edit = NULL; - if (commit) { - /* - * Accept the currently edited text. if it's the same as what's in the cell, do nothing. - */ - ECellView *ecell_view = (ECellView *) text_view; - ECellText *ect = (ECellText *) ecell_view->ecell; - - if (strcmp (old_text, text)) { - e_cell_text_set_value ( - ect, ecell_view->e_table_model, - model_col, row, text); - } - } - g_free (text); - g_free (old_text); - - ect_queue_redraw (text_view, view_col, row); -} - -/* - * Cancels the edits - */ -static void -ect_cancel_edit (ECellTextView *text_view) -{ - ect_stop_editing (text_view, FALSE); - e_table_item_leave_edit_ (text_view->cell_view.e_table_item_view); -} - -/* - * ECell::new_view method - */ -static ECellView * -ect_new_view (ECell *ecell, - ETableModel *table_model, - gpointer e_table_item_view) -{ - 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; - text_view->cell_view.kill_view_cb = NULL; - text_view->cell_view.kill_view_cb_data = NULL; - - 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; - - if (text_view->cell_view.kill_view_cb) - (text_view->cell_view.kill_view_cb)(ecv, text_view->cell_view.kill_view_cb_data); - - if (text_view->cell_view.kill_view_cb_data) - g_list_free (text_view->cell_view.kill_view_cb_data); - - g_free (text_view); -} - -/* - * ECell::realize method - */ -static void -ect_realize (ECellView *ecell_view) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - - text_view->i_cursor = gdk_cursor_new (GDK_XTERM); - - if (E_CELL_CLASS (e_cell_text_parent_class)->realize) - (* E_CELL_CLASS (e_cell_text_parent_class)->realize) (ecell_view); -} - -/* - * ECell::unrealize method - */ -static void -ect_unrealize (ECellView *ecv) -{ - ECellTextView *text_view = (ECellTextView *) ecv; - - if (text_view->edit) { - ect_cancel_edit (text_view); - } - - g_object_unref (text_view->i_cursor); - - if (E_CELL_CLASS (e_cell_text_parent_class)->unrealize) - (* E_CELL_CLASS (e_cell_text_parent_class)->unrealize) (ecv); - -} - -static PangoAttrList * -build_attr_list (ECellTextView *text_view, - gint row, - gint text_length) -{ - - ECellView *ecell_view = (ECellView *) text_view; - ECellText *ect = E_CELL_TEXT (ecell_view->ecell); - PangoAttrList *attrs = pango_attr_list_new (); - gboolean bold, strikeout, underline; - - bold = ect->bold_column >= 0 && - row >= 0 && - e_table_model_value_at (ecell_view->e_table_model, ect->bold_column, row); - strikeout = ect->strikeout_column >= 0 && - row >= 0 && - e_table_model_value_at (ecell_view->e_table_model, ect->strikeout_column, row); - underline = ect->underline_column >= 0 && - row >= 0 && - e_table_model_value_at (ecell_view->e_table_model, ect->underline_column, row); - - if (bold || strikeout || underline) { - if (bold) { - PangoAttribute *attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD); - attr->start_index = 0; - attr->end_index = text_length; - - pango_attr_list_insert_before (attrs, attr); - } - if (strikeout) { - PangoAttribute *attr = pango_attr_strikethrough_new (TRUE); - attr->start_index = 0; - attr->end_index = text_length; - - pango_attr_list_insert_before (attrs, attr); - } - if (underline) { - PangoAttribute *attr = pango_attr_underline_new (TRUE); - attr->start_index = 0; - attr->end_index = text_length; - - pango_attr_list_insert_before (attrs, attr); - } - } - return attrs; -} - -static PangoLayout * -layout_with_preedit (ECellTextView *text_view, - gint row, - const gchar *text, - gint width) -{ - CellEdit *edit = text_view->edit; - PangoAttrList *attrs; - PangoLayout *layout; - GString *tmp_string = g_string_new (NULL); - PangoAttrList *preedit_attrs = NULL; - gchar *preedit_string = NULL; - gint preedit_length = 0; - gint text_length = strlen (text); - gint mlen = MIN (edit->selection_start,text_length); - - gtk_im_context_get_preedit_string ( - edit->im_context, - &preedit_string,&preedit_attrs, - NULL); - preedit_length = edit->preedit_length = strlen (preedit_string);; - - layout = edit->layout; - - g_string_prepend_len (tmp_string, text,text_length); - - if (preedit_length) { - - /* mlen is the text_length in bytes, not chars - * check whether we are not inserting into - * the middle of a utf8 character - */ - - if (mlen < text_length) { - if (!g_utf8_validate (text + mlen, -1, NULL)) { - gchar *tc; - tc = g_utf8_find_next_char (text + mlen,NULL); - if (tc) { - mlen = (gint) (tc - text); - } - } - } - - g_string_insert (tmp_string, mlen, preedit_string); - } - - pango_layout_set_text (layout, tmp_string->str, tmp_string->len); - - attrs = (PangoAttrList *) build_attr_list (text_view, row, text_length); - - if (preedit_length) - pango_attr_list_splice (attrs, preedit_attrs, mlen, preedit_length); - pango_layout_set_attributes (layout, attrs); - g_string_free (tmp_string, TRUE); - if (preedit_string) - g_free (preedit_string); - if (preedit_attrs) - pango_attr_list_unref (preedit_attrs); - pango_attr_list_unref (attrs); - - update_im_cursor_location (text_view); - - return layout; -} - -static PangoLayout * -build_layout (ECellTextView *text_view, - gint row, - const gchar *text, - gint width) -{ - ECellView *ecell_view = (ECellView *) text_view; - ECellText *ect = E_CELL_TEXT (ecell_view->ecell); - PangoAttrList *attrs; - PangoLayout *layout; - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (((GnomeCanvasItem *) ecell_view->e_table_item_view)->canvas), text); - - attrs = (PangoAttrList *) build_attr_list (text_view, row, text ? strlen (text) : 0); - - pango_layout_set_attributes (layout, attrs); - pango_attr_list_unref (attrs); - - if (text_view->edit || width <= 0) - return layout; - - if (ect->font_name) - { - PangoFontDescription *desc = NULL, *fixed_desc = NULL; - gchar *fixed_family = NULL; - gint fixed_size = 0; - gboolean fixed_points = TRUE; - - fixed_desc = pango_font_description_from_string (ect->font_name); - if (fixed_desc) { - fixed_family = (gchar *) pango_font_description_get_family (fixed_desc); - fixed_size = pango_font_description_get_size (fixed_desc); - fixed_points = !pango_font_description_get_size_is_absolute (fixed_desc); - } - - desc = pango_font_description_copy (gtk_widget_get_style (GTK_WIDGET (((GnomeCanvasItem *) ecell_view->e_table_item_view)->canvas))->font_desc); - pango_font_description_set_family (desc, fixed_family); - if (fixed_points) - pango_font_description_set_size (desc, fixed_size); - else - pango_font_description_set_absolute_size (desc, fixed_size); -/* pango_font_description_set_style (desc, PANGO_STYLE_OBLIQUE); */ - pango_layout_set_font_description (layout, desc); - pango_font_description_free (desc); - pango_font_description_free (fixed_desc); - } - - pango_layout_set_width (layout, width * PANGO_SCALE); - pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR); - - pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); - pango_layout_set_height (layout, 0); - - switch (ect->justify) { - case GTK_JUSTIFY_RIGHT: - pango_layout_set_alignment (layout, PANGO_ALIGN_RIGHT); - break; - case GTK_JUSTIFY_CENTER: - pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); - break; - case GTK_JUSTIFY_LEFT: - default: - break; - } - - return layout; -} - -static PangoLayout * -generate_layout (ECellTextView *text_view, - gint model_col, - gint view_col, - gint row, - gint width) -{ - ECellView *ecell_view = (ECellView *) text_view; - ECellText *ect = E_CELL_TEXT (ecell_view->ecell); - PangoLayout *layout; - CellEdit *edit = text_view->edit; - - if (edit && edit->layout && edit->model_col == model_col && edit->row == row) { - g_object_ref (edit->layout); - return edit->layout; - } - - if (row >= 0) { - gchar *temp = e_cell_text_get_text (ect, ecell_view->e_table_model, model_col, row); - layout = build_layout (text_view, row, temp ? temp : "?", width); - e_cell_text_free_text (ect, temp); - } else - layout = build_layout (text_view, row, "Mumbo Jumbo", width); - - return layout; -} - -static void -draw_cursor (cairo_t *cr, - gint x1, - gint y1, - PangoRectangle rect) -{ - gdouble scaled_x; - gdouble scaled_y; - gdouble scaled_height; - - /* Pango stores each cursor position as a zero-width rectangle. */ - scaled_x = x1 + ((gdouble) rect.x) / PANGO_SCALE; - scaled_y = y1 + ((gdouble) rect.y) / PANGO_SCALE; - scaled_height = ((gdouble) rect.height) / PANGO_SCALE; - - /* Adding 0.5 to scaled_x gives a sharp, one-pixel line. */ - cairo_move_to (cr, scaled_x + 0.5, scaled_y); - cairo_line_to (cr, scaled_x + 0.5, scaled_y + scaled_height); - cairo_set_line_width (cr, 1); - cairo_stroke (cr); -} - -static gboolean -show_pango_rectangle (CellEdit *edit, - PangoRectangle rect) -{ - gint x1 = rect.x / PANGO_SCALE; - gint x2 = (rect.x + rect.width) / PANGO_SCALE; -#if 0 - gint y1 = rect.y / PANGO_SCALE; - gint y2 = (rect.y + rect.height) / PANGO_SCALE; -#endif - - gint new_xofs_edit = edit->xofs_edit; - gint new_yofs_edit = edit->yofs_edit; - - if (x1 < new_xofs_edit) - new_xofs_edit = x1; - if (2 + x2 - edit->cell_width > new_xofs_edit) - new_xofs_edit = 2 + x2 - edit->cell_width; - if (new_xofs_edit < 0) - new_xofs_edit = 0; - -#if 0 - if (y1 < new_yofs_edit) - new_yofs_edit = y1; - if (2 + y2 - edit->cell_height > new_yofs_edit) - new_yofs_edit = 2 + y2 - edit->cell_height; - if (new_yofs_edit < 0) - new_yofs_edit = 0; -#endif - - if (new_xofs_edit != edit->xofs_edit || - new_yofs_edit != edit->yofs_edit) { - edit->xofs_edit = new_xofs_edit; - edit->yofs_edit = new_yofs_edit; - return TRUE; - } - - return FALSE; -} - -static gint -get_vertical_spacing (GtkWidget *canvas) -{ - GtkWidget *widget; - gint vspacing = 0; - - g_return_val_if_fail (E_IS_CANVAS (canvas), 3); - - /* The parent should be either an ETable or ETree. */ - widget = gtk_widget_get_parent (canvas); - - gtk_widget_style_get (widget, "vertical-spacing", &vspacing, NULL); - - return vspacing; -} - -/* - * ECell::draw method - */ -static void -ect_draw (ECellView *ecell_view, - cairo_t *cr, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - gint x1, - gint y1, - gint x2, - gint y2) -{ - PangoLayout *layout; - ECellTextView *text_view = (ECellTextView *) ecell_view; - ECellText *ect = E_CELL_TEXT (ecell_view->ecell); - CellEdit *edit = text_view->edit; - gboolean selected; - GtkWidget *canvas = GTK_WIDGET (text_view->canvas); - GtkStyle *style; - gint x_origin, y_origin, vspacing; - - cairo_save (cr); - style = gtk_widget_get_style (canvas); - - selected = flags & E_CELL_SELECTED; - - if (selected) { - if (gtk_widget_has_focus (canvas)) - gdk_cairo_set_source_color (cr, &style->fg[GTK_STATE_SELECTED]); - else - gdk_cairo_set_source_color (cr, &style->fg[GTK_STATE_ACTIVE]); - } else { - gdk_cairo_set_source_color (cr, &style->text[GTK_STATE_NORMAL]); - - if (ect->color_column != -1) { - gchar *color_spec; - GdkColor color; - - color_spec = e_table_model_value_at ( - ecell_view->e_table_model, - ect->color_column, row); - if (color_spec && gdk_color_parse (color_spec, &color)) - gdk_cairo_set_source_color (cr, &color); - } - } - - vspacing = get_vertical_spacing (canvas); - - x1 += 4; - y1 += vspacing; - x2 -= 4; - y2 -= vspacing; - - x_origin = x1 + ect->x + text_view->xofs - (edit ? edit->xofs_edit : 0); - y_origin = y1 + ect->y + text_view->yofs - (edit ? edit->yofs_edit : 0); - - cairo_rectangle (cr, x1, y1, x2 - x1, y2 - y1); - cairo_clip (cr); - - layout = generate_layout (text_view, model_col, view_col, row, x2 - x1); - - if (edit && edit->view_col == view_col && edit->row == row) { - layout = layout_with_preedit (text_view, row, edit->text ? edit->text : "?", x2 - x1); - } - - cairo_move_to (cr, x_origin, y_origin); - pango_cairo_show_layout (cr, layout); - - if (edit && edit->view_col == view_col && edit->row == row) { - if (edit->selection_start != edit->selection_end) { - cairo_region_t *clip_region; - gint indices[2]; - GtkStateType state; - - state = edit->has_selection ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE; - - indices[0] = MIN (edit->selection_start, edit->selection_end); - indices[1] = MAX (edit->selection_start, edit->selection_end); - - clip_region = gdk_pango_layout_get_clip_region ( - layout, x_origin, y_origin, indices, 1); - gdk_cairo_region (cr, clip_region); - cairo_clip (cr); - cairo_region_destroy (clip_region); - - gdk_cairo_set_source_color (cr, &style->base[state]); - cairo_paint (cr); - - gdk_cairo_set_source_color (cr, &style->text[state]); - cairo_move_to (cr, x_origin, y_origin); - pango_cairo_show_layout (cr, layout); - } else { - if (edit->show_cursor) { - PangoRectangle strong_pos, weak_pos; - pango_layout_get_cursor_pos (layout, edit->selection_start + edit->preedit_length, &strong_pos, &weak_pos); - - draw_cursor (cr, x_origin, y_origin, strong_pos); - if (strong_pos.x != weak_pos.x || - strong_pos.y != weak_pos.y || - strong_pos.width != weak_pos.width || - strong_pos.height != weak_pos.height) - draw_cursor (cr, x_origin, y_origin, weak_pos); - } - } - } - - g_object_unref (layout); - cairo_restore (cr); -} - -/* - * Get the background color - */ -static gchar * -ect_get_bg_color (ECellView *ecell_view, - gint row) -{ - ECellText *ect = E_CELL_TEXT (ecell_view->ecell); - gchar *color_spec; - - if (ect->bg_color_column == -1) - return NULL; - - color_spec = e_table_model_value_at ( - ecell_view->e_table_model, - ect->bg_color_column, row); - - return color_spec; -} - -/* - * Selects the entire string - */ - -static void -ect_edit_select_all (ECellTextView *text_view) -{ - g_return_if_fail (text_view->edit); - - text_view->edit->selection_start = 0; - text_view->edit->selection_end = strlen (text_view->edit->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, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - ECellActions *actions) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - ETextEventProcessorEvent e_tep_event; - gboolean edit_display = FALSE; - gint preedit_len; - CellEdit *edit = text_view->edit; - GtkWidget *canvas = GTK_WIDGET (text_view->canvas); - gint return_val = 0; - d (gboolean press = FALSE); - - if (!(flags & E_CELL_EDITING)) - return 0; - - if (edit && !edit->preedit_length && flags & E_CELL_PREEDIT) - return 1; - - if (edit && edit->view_col == view_col && edit->row == row) { - edit_display = TRUE; - } - - e_tep_event.type = event->type; - switch (event->type) { - case GDK_FOCUS_CHANGE: - break; - case GDK_KEY_PRESS: /* Fall Through */ - if (edit_display) { - edit->show_cursor = FALSE; - } else { - ect_stop_editing (text_view, TRUE); - } - return_val = TRUE; - /* Fallthrough */ - case GDK_KEY_RELEASE: - preedit_len = edit_display ? edit->preedit_length : 0; - if (edit_display && edit->im_context && - gtk_im_context_filter_keypress (\ - edit->im_context, - (GdkEventKey *) event)) { - - edit->need_im_reset = TRUE; - if (preedit_len && flags & E_CELL_PREEDIT) - return 0; - else - return 1; - } - - if (event->key.keyval == GDK_KEY_Escape) { - /* if not changed, then pass this even to parent */ - return_val = text_view->edit != NULL && text_view->edit->text && text_view->edit->old_text && 0 != strcmp (text_view->edit->text, text_view->edit->old_text); - ect_cancel_edit (text_view); - 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; - edit_display = TRUE; - } - if (edit_display) { - GdkEventKey key = event->key; - if (key.type == GDK_KEY_PRESS && - (key.keyval == GDK_KEY_KP_Enter || key.keyval == GDK_KEY_Return)) { - /* stop editing when it's only GDK_KEY_PRESS event */ - 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); - if (e_tep_event.key.string) - g_free ((gpointer) e_tep_event.key.string); - break; - } - } - - break; - case GDK_BUTTON_PRESS: /* Fall Through */ - d (press = TRUE); - case GDK_BUTTON_RELEASE: - d (g_print ("%s: %s\n", __FUNCTION__, press ? "GDK_BUTTON_PRESS" : "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; - 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 (edit, event->button.x, event->button.y); - e_tep_event.button.device = - gdk_event_get_device (event); - _get_tep (edit); - edit->actions = 0; - 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 (edit, event->button.x, event->button.y); - e_tep_event.button.device = - gdk_event_get_device (event); - _get_tep (edit); - edit->actions = 0; - 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 (edit, event->motion.x, event->motion.y); - _get_tep (edit); - edit->actions = 0; - 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) { - GdkWindow *window; - - window = gtk_widget_get_window (canvas); - gdk_window_set_cursor (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) { - GdkWindow *window; - - window = gtk_widget_get_window (canvas); - gdk_window_set_cursor (window, NULL); - edit->default_cursor_shown = TRUE; - } - } - break; - default: - break; - } - - return return_val; -} - -/* - * ECell::height method - */ -static gint -ect_height (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - gint height; - PangoLayout *layout; - - layout = generate_layout (text_view, model_col, view_col, row, 0); - pango_layout_get_pixel_size (layout, NULL, &height); - g_object_unref (layout); - return height + (get_vertical_spacing (GTK_WIDGET (text_view->canvas)) * 2); -} - -/* - * ECellView::enter_edit method - */ -static gpointer -ect_enter_edit (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - CellEdit *edit; - ECellText *ect = E_CELL_TEXT (ecell_view->ecell); - gchar *temp; - - edit = g_new0 (CellEdit, 1); - text_view->edit = edit; - - edit->im_context = E_CANVAS (text_view->canvas)->im_context; - edit->need_im_reset = FALSE; - edit->im_context_signals_registered = FALSE; - edit->view_col = -1; - edit->model_col = -1; - edit->row = -1; - - edit->text_view = text_view; - edit->model_col = model_col; - edit->view_col = view_col; - edit->row = row; - edit->cell_width = e_table_header_get_column ( - ((ETableItem *) ecell_view->e_table_item_view)->header, - view_col)->width - 8; - - edit->layout = generate_layout (text_view, model_col, view_col, row, edit->cell_width); - - 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->pointer_in = FALSE; - edit->default_cursor_shown = TRUE; - - temp = e_cell_text_get_text (ect, ecell_view->e_table_model, model_col, row); - edit->old_text = g_strdup (temp); - e_cell_text_free_text (ect, temp); - edit->text = g_strdup (edit->old_text); - - if (edit->im_context) { - gtk_im_context_reset (edit->im_context); - if (!edit->im_context_signals_registered) { - g_signal_connect ( - edit->im_context, "preedit_changed", - G_CALLBACK (e_cell_text_preedit_changed_cb), - text_view); - g_signal_connect ( - edit->im_context, "commit", - G_CALLBACK (e_cell_text_commit_cb), - text_view); - g_signal_connect ( - edit->im_context, "retrieve_surrounding", - G_CALLBACK (e_cell_text_retrieve_surrounding_cb), - text_view); - g_signal_connect ( - edit->im_context, "delete_surrounding", - G_CALLBACK (e_cell_text_delete_surrounding_cb), - text_view); - - edit->im_context_signals_registered = TRUE; - } - gtk_im_context_focus_in (edit->im_context); - } - -#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, - gint model_col, - gint view_col, - gint row, - gpointer edit_context) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - CellEdit *edit = text_view->edit; - - if (edit) { - if (edit->im_context) { - gtk_im_context_focus_out (edit->im_context); - - if (edit->im_context_signals_registered) { - g_signal_handlers_disconnect_matched (edit->im_context, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, edit); - edit->im_context_signals_registered = FALSE; - } - } - ect_stop_editing (text_view, TRUE); - } else { - /* - * We did invoke this leave edit internally - */ - } -} - -/* - * ECellView::save_state method - */ -static gpointer -ect_save_state (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gpointer edit_context) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - CellEdit *edit = text_view->edit; - - gint *save_state = g_new (int, 2); - - save_state[0] = edit->selection_start; - save_state[1] = edit->selection_end; - return save_state; -} - -/* - * ECellView::load_state method - */ -static void -ect_load_state (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gpointer edit_context, - gpointer save_state) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - CellEdit *edit = text_view->edit; - gint length; - gint *selection = save_state; - - length = strlen (edit->text); - - edit->selection_start = MIN (selection[0], length); - edit->selection_end = MIN (selection[1], length); - - ect_queue_redraw (text_view, view_col, row); -} - -/* - * ECellView::free_state method - */ -static void -ect_free_state (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gpointer save_state) -{ - g_free (save_state); -} - -static void -get_font_size (PangoLayout *layout, - PangoFontDescription *font, - const gchar *text, - gdouble *width, - gdouble *height) -{ - gint w; - gint h; - - g_return_if_fail (layout != NULL); - pango_layout_set_font_description (layout, font); - pango_layout_set_text (layout, text, -1); - pango_layout_set_width (layout, -1); - pango_layout_set_indent (layout, 0); - - pango_layout_get_size (layout, &w, &h); - - *width = (gdouble)w/(gdouble)PANGO_SCALE; - *height = (gdouble)h/(gdouble)PANGO_SCALE; -} - -static void -ect_print (ECellView *ecell_view, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width, - gdouble height) -{ - PangoFontDescription *font_des; - PangoLayout *layout; - PangoContext *pango_context; - PangoFontMetrics *font_metrics; - ECellText *ect = E_CELL_TEXT (ecell_view->ecell); - ECellTextView *ectView = (ECellTextView *) ecell_view; - GtkWidget *canvas = GTK_WIDGET (ectView->canvas); - GtkStyle *style; - PangoDirection dir; - gboolean strikeout, underline; - cairo_t *cr; - gchar *string; - gdouble ty, ly, text_width = 0.0, text_height = 0.0; - - cr = gtk_print_context_get_cairo_context (context); - string = e_cell_text_get_text (ect, ecell_view->e_table_model, model_col, row); - - cairo_save (cr); - layout = gtk_print_context_create_pango_layout (context); - font_des = pango_font_description_from_string ("sans 10"); /* fix me font hardcoded */ - pango_layout_set_font_description (layout, font_des); - - pango_layout_set_text (layout, string, -1); - get_font_size (layout, font_des, string, &text_width, &text_height); - - cairo_move_to (cr, 2, 2); - cairo_rectangle (cr, 2, 2, width + 2, height + 2); - cairo_clip (cr); - - style = gtk_widget_get_style (canvas); - pango_context = gtk_widget_get_pango_context (canvas); - font_metrics = pango_context_get_metrics ( - pango_context, style->font_desc, - pango_context_get_language (pango_context)); - ty = (gdouble)(text_height - - pango_font_metrics_get_ascent (font_metrics) - - pango_font_metrics_get_descent (font_metrics)) / 2.0 /(gdouble) PANGO_SCALE; - - strikeout = ect->strikeout_column >= 0 && row >= 0 && - e_table_model_value_at (ecell_view->e_table_model, ect->strikeout_column, row); - underline = ect->underline_column >= 0 && row >= 0 && - e_table_model_value_at (ecell_view->e_table_model, ect->underline_column, row); - - dir = pango_find_base_dir (string, strlen (string)); - - if (underline) { - ly = ty + (gdouble) pango_font_metrics_get_underline_position (font_metrics) / (gdouble) PANGO_SCALE; - cairo_new_path (cr); - if (dir == PANGO_DIRECTION_RTL) { - cairo_move_to (cr, width - 2, ly + text_height + 6); - cairo_line_to (cr, MAX (width - 2 - text_width, 2), ly + text_height + 6); - } - else { - cairo_move_to (cr, 2, ly + text_height + 6); - cairo_line_to (cr, MIN (2 + text_width, width - 2), ly + text_height + 6); - } - cairo_set_line_width (cr, (gdouble) pango_font_metrics_get_underline_thickness (font_metrics) / (gdouble) PANGO_SCALE); - cairo_stroke (cr); - } - - if (strikeout) { - ly = ty + (gdouble) pango_font_metrics_get_strikethrough_position (font_metrics) / (gdouble) PANGO_SCALE; - cairo_new_path (cr); - if (dir == PANGO_DIRECTION_RTL) { - cairo_move_to (cr, width - 2, ly + text_height + 6); - cairo_line_to (cr, MAX (width - 2 - text_width, 2), ly + text_height + 6); - } - else { - cairo_move_to (cr, 2, ly + text_height + 6); - cairo_line_to (cr, MIN (2 + text_width, width - 2), ly + text_height + 6); - } - cairo_set_line_width (cr,(gdouble) pango_font_metrics_get_strikethrough_thickness (font_metrics) / (gdouble) PANGO_SCALE); - - cairo_stroke (cr); - } - - cairo_move_to (cr, 2, text_height- 5); - pango_layout_set_width (layout, (width - 4) * PANGO_SCALE); - pango_layout_set_wrap (layout, PANGO_WRAP_CHAR); - pango_cairo_show_layout (cr, layout); - cairo_restore (cr); - - pango_font_description_free (font_des); - g_object_unref (layout); - e_cell_text_free_text (ect, string); -} - -static gdouble -ect_print_height (ECellView *ecell_view, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width) -{ - /* - * Font size is 16 by default. To leave some margin for cell - * text area, 2 for footer, 2 for header, actual print height - * should be 16 + 4. - * Height of some special font is much higher than others, - * such as Arabic. So leave some more margin for cell. - */ - PangoFontDescription *font_des; - PangoLayout *layout; - ECellText *ect = E_CELL_TEXT (ecell_view->ecell); - gchar *string; - gdouble text_width = 0.0, text_height = 0.0; - gint lines = 1; - - string = e_cell_text_get_text (ect, ecell_view->e_table_model, model_col, row); - - layout = gtk_print_context_create_pango_layout (context); - font_des = pango_font_description_from_string ("sans 10"); /* fix me font hardcoded */ - pango_layout_set_font_description (layout, font_des); - - pango_layout_set_text (layout, string, -1); - get_font_size (layout, font_des, string, &text_width, &text_height); - /* Checking if the text width goes beyond the column width to increase the - * number of lines. - */ - if (text_width > width - 4) - lines = (text_width / (width - 4)) + 1; - return 16 *lines + 8; -} - -static gint -ect_max_width (ECellView *ecell_view, - gint model_col, - gint view_col) -{ - /* New ECellText */ - ECellTextView *text_view = (ECellTextView *) ecell_view; - gint row; - gint number_of_rows; - gint max_width = 0; - - number_of_rows = e_table_model_row_count (ecell_view->e_table_model); - - for (row = 0; row < number_of_rows; row++) { - PangoLayout *layout = generate_layout (text_view, model_col, view_col, row, 0); - gint width; - - pango_layout_get_pixel_size (layout, &width, NULL); - - max_width = MAX (max_width, width); - g_object_unref (layout); - } - - return max_width + 8; -} - -static gint -ect_max_width_by_row (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row) -{ - /* New ECellText */ - ECellTextView *text_view = (ECellTextView *) ecell_view; - gint width; - PangoLayout *layout; - - if (row >= e_table_model_row_count (ecell_view->e_table_model)) - return 0; - - layout = generate_layout (text_view, model_col, view_col, row, 0); - pango_layout_get_pixel_size (layout, &width, NULL); - g_object_unref (layout); - - return width + 8; -} - -static void -ect_finalize (GObject *object) -{ - ECellText *ect = E_CELL_TEXT (object); - - g_free (ect->font_name); - - G_OBJECT_CLASS (e_cell_text_parent_class)->finalize (object); -} - -/* Set_arg handler for the text item */ -static void -ect_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ECellText *text; - - text = E_CELL_TEXT (object); - - switch (property_id) { - case PROP_STRIKEOUT_COLUMN: - text->strikeout_column = g_value_get_int (value); - break; - - case PROP_UNDERLINE_COLUMN: - text->underline_column = g_value_get_int (value); - break; - - case PROP_BOLD_COLUMN: - text->bold_column = g_value_get_int (value); - break; - - case PROP_COLOR_COLUMN: - text->color_column = g_value_get_int (value); - break; - - case PROP_EDITABLE: - text->editable = g_value_get_boolean (value); - break; - - case PROP_BG_COLOR_COLUMN: - text->bg_color_column = g_value_get_int (value); - break; - - default: - return; - } -} - -/* Get_arg handler for the text item */ -static void -ect_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ECellText *text; - - text = E_CELL_TEXT (object); - - switch (property_id) { - case PROP_STRIKEOUT_COLUMN: - g_value_set_int (value, text->strikeout_column); - break; - - case PROP_UNDERLINE_COLUMN: - g_value_set_int (value, text->underline_column); - break; - - case PROP_BOLD_COLUMN: - g_value_set_int (value, text->bold_column); - break; - - case PROP_COLOR_COLUMN: - g_value_set_int (value, text->color_column); - break; - - case PROP_EDITABLE: - g_value_set_boolean (value, text->editable); - break; - - case PROP_BG_COLOR_COLUMN: - g_value_set_int (value, text->bg_color_column); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static gchar *ellipsis_default = NULL; -static gboolean use_ellipsis_default = TRUE; - -static void -e_cell_text_class_init (ECellTextClass *class) -{ - ECellClass *ecc = E_CELL_CLASS (class); - GObjectClass *object_class = G_OBJECT_CLASS (class); - const gchar *ellipsis_env; - - object_class->finalize = ect_finalize; - - 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->save_state = ect_save_state; - ecc->load_state = ect_load_state; - ecc->free_state = ect_free_state; - ecc->print = ect_print; - ecc->print_height = ect_print_height; - ecc->max_width = ect_max_width; - ecc->max_width_by_row = ect_max_width_by_row; - ecc->get_bg_color = ect_get_bg_color; - - class->get_text = ect_real_get_text; - class->free_text = ect_real_free_text; - class->set_value = ect_real_set_value; - - object_class->get_property = ect_get_property; - object_class->set_property = ect_set_property; - - signals[TEXT_INSERTED] = g_signal_new ( - "text_inserted", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (ECellTextClass, text_inserted), - NULL, NULL, - e_marshal_VOID__POINTER_INT_INT_INT_INT, - G_TYPE_NONE, 5, - G_TYPE_POINTER, - G_TYPE_INT, - G_TYPE_INT, - G_TYPE_INT, - G_TYPE_INT); - - signals[TEXT_DELETED] = g_signal_new ( - "text_deleted", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (ECellTextClass, text_deleted), - NULL, NULL, - e_marshal_VOID__POINTER_INT_INT_INT_INT, - G_TYPE_NONE, 5, - G_TYPE_POINTER, - G_TYPE_INT, - G_TYPE_INT, - G_TYPE_INT, - G_TYPE_INT); - - g_object_class_install_property ( - object_class, - PROP_STRIKEOUT_COLUMN, - g_param_spec_int ( - "strikeout_column", - "Strikeout Column", - NULL, - -1, G_MAXINT, -1, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_UNDERLINE_COLUMN, - g_param_spec_int ( - "underline_column", - "Underline Column", - NULL, - -1, G_MAXINT, -1, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_BOLD_COLUMN, - g_param_spec_int ( - "bold_column", - "Bold Column", - NULL, - -1, G_MAXINT, -1, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_COLOR_COLUMN, - g_param_spec_int ( - "color_column", - "Color Column", - NULL, - -1, G_MAXINT, -1, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_EDITABLE, - g_param_spec_boolean ( - "editable", - "Editable", - NULL, - FALSE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_BG_COLOR_COLUMN, - g_param_spec_int ( - "bg_color_column", - "BG Color Column", - NULL, - -1, G_MAXINT, -1, - G_PARAM_READWRITE)); - - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); - - ellipsis_env = g_getenv ("GAL_ELLIPSIS"); - if (ellipsis_env) { - if (*ellipsis_env) { - ellipsis_default = g_strdup (ellipsis_env); - } else { - use_ellipsis_default = FALSE; - } - } -} - -/* IM Context Callbacks */ - -static void -e_cell_text_get_cursor_locations (ECellTextView *tv, - GdkRectangle *strong_pos, - GdkRectangle *weak_pos) -{ - GdkRectangle area; - CellEdit *edit = tv->edit; - ECellView *cell_view = (ECellView *) tv; - ETableItem *item = E_TABLE_ITEM ((cell_view)->e_table_item_view); - GnomeCanvasItem *parent_item = GNOME_CANVAS_ITEM (item)->parent; - PangoRectangle pango_strong_pos; - PangoRectangle pango_weak_pos; - gint x, y, col, row; - gdouble x1,y1; - gint cx, cy; - gint index; - - row = edit->row; - col = edit->view_col; - - e_table_item_get_cell_geometry ( - item, &row, &col, &x, &y, NULL, &area.height); - - gnome_canvas_item_get_bounds (GNOME_CANVAS_ITEM (parent_item), &x1, &y1, NULL, NULL); - - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (GNOME_CANVAS_ITEM (parent_item)->canvas), &cx, &cy); - - index = edit->selection_end + edit->preedit_pos; - - pango_layout_get_cursor_pos ( - edit->layout, - index, - strong_pos ? &pango_strong_pos : NULL, - weak_pos ? &pango_weak_pos : NULL); - - if (strong_pos) { - strong_pos->x = x + x1 - cx - edit->xofs_edit + pango_strong_pos.x / PANGO_SCALE; - strong_pos->y = y + y1 - cy - edit->yofs_edit + pango_strong_pos.y / PANGO_SCALE; - strong_pos->width = 0; - strong_pos->height = pango_strong_pos.height / PANGO_SCALE; - } - - if (weak_pos) { - weak_pos->x = x + x1 - cx - edit->xofs_edit + pango_weak_pos.x / PANGO_SCALE; - weak_pos->y = y + y1 - cy - edit->yofs_edit + pango_weak_pos.y / PANGO_SCALE; - weak_pos->width = 0; - weak_pos->height = pango_weak_pos.height / PANGO_SCALE; - } -} - -static void -update_im_cursor_location (ECellTextView *tv) -{ - CellEdit *edit = tv->edit; - GdkRectangle area; - - e_cell_text_get_cursor_locations (tv, &area, NULL); - - gtk_im_context_set_cursor_location (edit->im_context, &area); -} - -static void -e_cell_text_preedit_changed_cb (GtkIMContext *context, - ECellTextView *tv) -{ - gchar *preedit_string; - gint cursor_pos; - CellEdit *edit = tv->edit; - gtk_im_context_get_preedit_string ( - edit->im_context, &preedit_string, - NULL, &cursor_pos); - - edit->preedit_length = strlen (preedit_string); - cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1)); - edit->preedit_pos = g_utf8_offset_to_pointer (preedit_string, cursor_pos) - preedit_string; - g_free (preedit_string); - - ect_queue_redraw (tv, edit->view_col, edit->row); -} - -static void -e_cell_text_commit_cb (GtkIMContext *context, - const gchar *str, - ECellTextView *tv) -{ - CellEdit *edit = tv->edit; - ETextEventProcessorCommand command = { 0 }; - - if (g_utf8_validate (str, strlen (str), NULL)) { - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.string = (gchar *) str; - command.value = strlen (str); - e_cell_text_view_command (edit->tep, &command, edit); - } - -} - -static gboolean -e_cell_text_retrieve_surrounding_cb (GtkIMContext *context, - ECellTextView *tv) -{ - CellEdit *edit = tv->edit; - - gtk_im_context_set_surrounding ( - context, - edit->text, - strlen (edit->text), - MIN (edit->selection_start, edit->selection_end)); - - return TRUE; -} - -static gboolean -e_cell_text_delete_surrounding_cb (GtkIMContext *context, - gint offset, - gint n_chars, - ECellTextView *tv) -{ - gint begin_pos, end_pos; - glong text_len; - CellEdit *edit = tv->edit; - - text_len = g_utf8_strlen (edit->text, -1); - begin_pos = g_utf8_pointer_to_offset ( - edit->text, - edit->text + MIN (edit->selection_start, edit->selection_end)); - begin_pos += offset; - end_pos = begin_pos + n_chars; - if (begin_pos < 0 || text_len < begin_pos) - return FALSE; - if (end_pos > text_len) - end_pos = text_len; - edit->selection_start = g_utf8_offset_to_pointer (edit->text, begin_pos) - - edit->text; - edit->selection_end = g_utf8_offset_to_pointer (edit->text, end_pos) - - edit->text; - - _delete_selection (tv); - - return TRUE; -} - -static void -e_cell_text_init (ECellText *ect) -{ - ect->ellipsis = g_strdup (ellipsis_default); - ect->use_ellipsis = use_ellipsis_default; - ect->strikeout_column = -1; - ect->underline_column = -1; - ect->bold_column = -1; - ect->color_column = -1; - ect->bg_color_column = -1; - ect->editable = TRUE; -} - -/** - * e_cell_text_new: - * @fontname: this param is no longer used, but left here for api stability - * @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 gchar *. - * - * 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, underline, bold, and color. - * - * The arguments "strikeout_column", "underline_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 gchar *fontname, - GtkJustification justify) -{ - ECellText *ect = g_object_new (E_TYPE_CELL_TEXT, NULL); - - e_cell_text_construct (ect, fontname, justify); - - return (ECell *) ect; -} - -/** - * e_cell_text_construct: - * @cell: The cell to construct - * @fontname: this param is no longer used, but left here for api stability - * @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 gchar *fontname, - GtkJustification justify) -{ - if (!cell) - return E_CELL (NULL); - if (fontname) - cell->font_name = g_strdup (fontname); - cell->justify = justify; - return E_CELL (cell); -} - -gchar * -e_cell_text_get_text (ECellText *cell, - ETableModel *model, - gint col, - gint row) -{ - ECellTextClass *class; - - g_return_val_if_fail (E_IS_CELL_TEXT (cell), NULL); - - class = E_CELL_TEXT_GET_CLASS (cell); - if (class->get_text == NULL) - return NULL; - - return class->get_text (cell, model, col, row); -} - -void -e_cell_text_free_text (ECellText *cell, - gchar *text) -{ - ECellTextClass *class; - - g_return_if_fail (E_IS_CELL_TEXT (cell)); - - class = E_CELL_TEXT_GET_CLASS (cell); - if (class->free_text == NULL) - return; - - class->free_text (cell, text); -} - -void -e_cell_text_set_value (ECellText *cell, - ETableModel *model, - gint col, - gint row, - const gchar *text) -{ - ECellTextClass *class; - - g_return_if_fail (E_IS_CELL_TEXT (cell)); - - class = E_CELL_TEXT_GET_CLASS (cell); - if (class->set_value == NULL) - return; - - class->set_value (cell, model, col, row, text); -} - -/* fixme: Handle Font attributes */ -/* position is in BYTES */ - -static gint -get_position_from_xy (CellEdit *edit, - gint x, - gint y) -{ - gint index; - gint trailing; - const gchar *text; - - PangoLayout *layout = generate_layout (edit->text_view, edit->model_col, edit->view_col, edit->row, edit->cell_width); - ECellTextView *text_view = edit->text_view; - ECellText *ect = (ECellText *) ((ECellView *) text_view)->ecell; - - x -= (ect->x + text_view->xofs - edit->xofs_edit); - y -= (ect->y + text_view->yofs - edit->yofs_edit); - - pango_layout_xy_to_index (layout, x * PANGO_SCALE, y * PANGO_SCALE, &index, &trailing); - - text = pango_layout_get_text (layout); - - return g_utf8_offset_to_pointer (text + index, trailing) - text; -} - -#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; - - gulong current_time; - gboolean scroll = FALSE; - gboolean redraw = FALSE; - gint width, height; - - 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; - } - - pango_layout_get_pixel_size (edit->layout, &width, &height); - - if (scroll && edit->button_down) { - /* FIXME: Copy this for y. */ - if (edit->lastx - ect->x > edit->cell_width) { - if (edit->xofs_edit < width - edit->cell_width) { - edit->xofs_edit += 4; - if (edit->xofs_edit > width - edit->cell_width + 1) - edit->xofs_edit = width - edit->cell_width + 1; - redraw = TRUE; - } - } - 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 (edit, 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->view_col, edit->row); - } - return TRUE; -} - -static gint -next_word (CellEdit *edit, - gint start) -{ - gchar *p; - gint length; - - length = strlen (edit->text); - if (start >= length) - return length; - - p = g_utf8_next_char (edit->text + start); - - while (*p && g_unichar_validate (g_utf8_get_char (p))) { - gunichar unival = g_utf8_get_char (p); - if (g_unichar_isspace (unival)) - return p - edit->text; - p = g_utf8_next_char (p); - } - - return p - edit->text; -} - -static gint -_get_position (ECellTextView *text_view, - ETextEventProcessorCommand *command) -{ - gint length; - CellEdit *edit = text_view->edit; - gchar *p; - gint unival; - gint index; - gint trailing; - - 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 (edit->text); - - case E_TEP_START_OF_LINE: - - if (edit->selection_end < 1) return 0; - - p = g_utf8_find_prev_char (edit->text, edit->text + edit->selection_end); - - if (p == edit->text) return 0; - - p = g_utf8_find_prev_char (edit->text, p); - - while (p && p > edit->text) { - if (*p == '\n') return p - edit->text + 1; - p = g_utf8_find_prev_char (edit->text, p); - } - - return 0; - - case E_TEP_END_OF_LINE: - - length = strlen (edit->text); - if (edit->selection_end >= length) return length; - - p = g_utf8_next_char (edit->text + edit->selection_end); - - while (*p && g_unichar_validate (g_utf8_get_char (p))) { - if (*p == '\n') return p - edit->text; - p = g_utf8_next_char (p); - } - - return p - edit->text; - - case E_TEP_FORWARD_CHARACTER: - - length = strlen (edit->text); - if (edit->selection_end >= length) return length; - - p = g_utf8_next_char (edit->text + edit->selection_end); - - return p - edit->text; - - case E_TEP_BACKWARD_CHARACTER: - - if (edit->selection_end < 1) return 0; - - p = g_utf8_find_prev_char (edit->text, edit->text + edit->selection_end); - - if (p == NULL) return 0; - - return p - edit->text; - - case E_TEP_FORWARD_WORD: - return next_word (edit, edit->selection_end); - - case E_TEP_BACKWARD_WORD: - - if (edit->selection_end < 1) return 0; - - p = g_utf8_find_prev_char (edit->text, edit->text + edit->selection_end); - - if (p == edit->text) return 0; - - p = g_utf8_find_prev_char (edit->text, p); - - while (p && p > edit->text && g_unichar_validate (g_utf8_get_char (p))) { - unival = g_utf8_get_char (p); - if (g_unichar_isspace (unival)) { - return (g_utf8_next_char (p) - edit->text); - } - p = g_utf8_find_prev_char (edit->text, p); - } - - return 0; - - case E_TEP_FORWARD_LINE: - pango_layout_move_cursor_visually ( - edit->layout, - TRUE, - edit->selection_end, - 0, - TRUE, - &index, - &trailing); - index = g_utf8_offset_to_pointer (edit->text + index, trailing) - edit->text; - if (index < 0) - return 0; - length = strlen (edit->text); - if (index >= length) - return length; - return index; - case E_TEP_BACKWARD_LINE: - pango_layout_move_cursor_visually ( - edit->layout, - TRUE, - edit->selection_end, - 0, - TRUE, - &index, - &trailing); - - index = g_utf8_offset_to_pointer (edit->text + index, trailing) - edit->text; - if (index < 0) - return 0; - length = strlen (edit->text); - if (index >= length) - return length; - return index; - 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_return_val_if_reached (0); - - return 0; /* Kill warning */ -} - -static void -_delete_selection (ECellTextView *text_view) -{ - CellEdit *edit = text_view->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 = edit->text + edit->selection_start; - ep = edit->text + edit->selection_end; - length = strlen (ep) + 1; - - memmove (sp, ep, length); - - edit->selection_end = edit->selection_start; - - g_signal_emit (VIEW_TO_CELL (text_view), signals[TEXT_DELETED], 0, text_view, edit->selection_start, ep - sp, edit->row, edit->model_col); -} - -/* fixme: */ -/* NB! We expect value to be length IN BYTES */ - -static void -_insert (ECellTextView *text_view, - const gchar *string, - gint value) -{ - CellEdit *edit = text_view->edit; - gchar *temp; - - if (value <= 0) return; - - edit->selection_start = MIN (strlen (edit->text), edit->selection_start); - - temp = g_new (gchar, strlen (edit->text) + value + 1); - - strncpy (temp, edit->text, edit->selection_start); - strncpy (temp + edit->selection_start, string, value); - strcpy (temp + edit->selection_start + value, edit->text + edit->selection_end); - - g_free (edit->text); - - edit->text = temp; - - edit->selection_start += value; - edit->selection_end = edit->selection_start; - - g_signal_emit (VIEW_TO_CELL (text_view), signals[TEXT_INSERTED], 0, text_view, edit->selection_end - value, value, edit->row, edit->model_col); -} - -static void -capitalize (CellEdit *edit, - gint start, - gint end, - ETextEventProcessorCaps type) -{ - ECellTextView *text_view = edit->text_view; - - gboolean first = TRUE; - gint character_length = g_utf8_strlen (edit->text + start, start - end); - const gchar *p = edit->text + start; - const gchar *text_end = edit->text + end; - gchar *new_text = g_new0 (char, character_length * 6 + 1); - gchar *output = new_text; - - while (p && *p && p < text_end && g_unichar_validate (g_utf8_get_char (p))) { - gunichar unival = g_utf8_get_char (p); - gunichar newval = unival; - - switch (type) { - case E_TEP_CAPS_UPPER: - newval = g_unichar_toupper (unival); - break; - case E_TEP_CAPS_LOWER: - newval = g_unichar_tolower (unival); - break; - case E_TEP_CAPS_TITLE: - if (g_unichar_isalpha (unival)) { - if (first) - newval = g_unichar_totitle (unival); - else - newval = g_unichar_tolower (unival); - first = FALSE; - } else { - first = TRUE; - } - break; - } - g_unichar_to_utf8 (newval, output); - output = g_utf8_next_char (output); - - p = g_utf8_next_char (p); - } - *output = 0; - - edit->selection_end = end; - edit->selection_start = start; - _delete_selection (text_view); - - _insert (text_view, new_text, output - new_text); - - g_free (new_text); -} - -static void -e_cell_text_view_command (ETextEventProcessor *tep, - ETextEventProcessorCommand *command, - gpointer data) -{ - CellEdit *edit = (CellEdit *) data; - ECellTextView *text_view = edit->text_view; - ECellText *ect = E_CELL_TEXT (text_view->cell_view.ecell); - - gboolean change = FALSE; - gboolean redraw = FALSE; - - gint sel_start, sel_end; - - /* If the EText isn't editable, then ignore any commands that would - * modify the text. */ - if (!ect->editable && (command->action == E_TEP_DELETE - || command->action == E_TEP_INSERT - || command->action == E_TEP_PASTE - || command->action == E_TEP_GET_SELECTION)) - return; - - 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, - edit->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->preedit_length && 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, - edit->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_CAPS: - if (edit->selection_start == edit->selection_end) { - capitalize (edit, edit->selection_start, next_word (edit, edit->selection_start), command->value); - } else { - gint selection_start = MIN (edit->selection_start, edit->selection_end); - gint selection_end = edit->selection_start + edit->selection_end - selection_start; /* Slightly faster than MAX */ - capitalize (edit, selection_start, selection_end, command->value); - } - if (edit->timer) { - g_timer_reset (edit->timer); - } - redraw = TRUE; - change = TRUE; - break; - case E_TEP_NOP: - break; - } - - if (change) { - if (edit->layout) - g_object_unref (edit->layout); - edit->layout = build_layout (text_view, edit->row, edit->text, edit->cell_width); - } - - if (!edit->button_down) { - PangoRectangle strong_pos, weak_pos; - pango_layout_get_cursor_pos (edit->layout, edit->selection_end, &strong_pos, &weak_pos); - if (strong_pos.x != weak_pos.x || - strong_pos.y != weak_pos.y || - strong_pos.width != weak_pos.width || - strong_pos.height != weak_pos.height) { - if (show_pango_rectangle (edit, weak_pos)) - redraw = TRUE; - } - if (show_pango_rectangle (edit, strong_pos)) { - redraw = TRUE; - } - } - - if (redraw) { - ect_queue_redraw (text_view, edit->view_col, edit->row); - } -} - -static void -e_cell_text_view_supply_selection (CellEdit *edit, - guint time, - GdkAtom selection, - gchar *data, - gint length) -{ -#if DO_SELECTION - GtkClipboard *clipboard; - - clipboard = gtk_widget_get_clipboard (GTK_WIDGET (edit->text_view->canvas), selection); - - if (selection == GDK_SELECTION_PRIMARY) { - edit->has_selection = TRUE; - } - - gtk_clipboard_set_text (clipboard, data, length); -#endif -} - -#ifdef DO_SELECTION -static void -paste_received (GtkClipboard *clipboard, - const gchar *text, - gpointer data) -{ - CellEdit *edit; - - g_return_if_fail (data); - - edit = (CellEdit *) data; - - if (text && g_utf8_validate (text, strlen (text), NULL)) { - ETextEventProcessorCommand command = { 0 }; - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.string = (gchar *) text; - command.value = strlen (text); - command.time = GDK_CURRENT_TIME; - e_cell_text_view_command (edit->tep, &command, edit); - } -} -#endif - -static void -e_cell_text_view_get_selection (CellEdit *edit, - GdkAtom selection, - guint32 time) -{ -#if DO_SELECTION - gtk_clipboard_request_text ( - gtk_widget_get_clipboard (GTK_WIDGET (edit->text_view->canvas), - selection), - paste_received, edit); -#endif -} - -static void -_get_tep (CellEdit *edit) -{ - if (!edit->tep) { - edit->tep = e_text_event_processor_emacs_like_new (); - g_signal_connect ( - edit->tep, "command", - G_CALLBACK (e_cell_text_view_command), edit); - } -} - -/** - * e_cell_text_set_selection: - * @cell_view: the given cell view - * @col: column of the given cell in the view - * @row: row of the given cell in the view - * @start: start offset of the selection - * @end: end offset of the selection - * - * Sets the selection of given text cell. - * If the current editing cell is not the given cell, this function - * will return FALSE; - * - * If success, the [start, end) part of the text will be selected. - * - * This API is most likely to be used by a11y implementations. - * - * Returns: whether the action is successful. - */ -gboolean -e_cell_text_set_selection (ECellView *cell_view, - gint col, - gint row, - gint start, - gint end) -{ - ECellTextView *ectv; - CellEdit *edit; - ETextEventProcessorCommand command1 = { 0 }, command2 = { 0 }; - - g_return_val_if_fail (cell_view != NULL, FALSE); - - ectv = (ECellTextView *) cell_view; - edit = ectv->edit; - if (!edit) - return FALSE; - - if (edit->view_col != col || edit->row != row) - return FALSE; - - command1.action = E_TEP_MOVE; - command1.position = E_TEP_VALUE; - command1.value = start; - e_cell_text_view_command (edit->tep, &command1, edit); - - command2.action = E_TEP_SELECT; - command2.position = E_TEP_VALUE; - command2.value = end; - e_cell_text_view_command (edit->tep, &command2, edit); - - return TRUE; -} - -/** - * e_cell_text_get_selection: - * @cell_view: the given cell view - * @col: column of the given cell in the view - * @row: row of the given cell in the view - * @start: a pointer to an gint value indicates the start offset of the selection - * @end: a pointer to an gint value indicates the end offset of the selection - * - * Gets the selection of given text cell. - * If the current editing cell is not the given cell, this function - * will return FALSE; - * - * This API is most likely to be used by a11y implementations. - * - * Returns: whether the action is successful. - */ -gboolean -e_cell_text_get_selection (ECellView *cell_view, - gint col, - gint row, - gint *start, - gint *end) -{ - ECellTextView *ectv; - CellEdit *edit; - - g_return_val_if_fail (cell_view != NULL, FALSE); - - ectv = (ECellTextView *) cell_view; - edit = ectv->edit; - if (!edit) - return FALSE; - - if (edit->view_col != col || edit->row != row) - return FALSE; - - if (start) - *start = edit->selection_start; - if (end) - *end = edit->selection_end; - return TRUE; -} - -/** - * e_cell_text_copy_clipboard: - * @cell_view: the given cell view - * @col: column of the given cell in the view - * @row: row of the given cell in the view - * - * Copys the selected text to clipboard. - * - * This API is most likely to be used by a11y implementations. - */ -void -e_cell_text_copy_clipboard (ECellView *cell_view, - gint col, - gint row) -{ - ECellTextView *ectv; - CellEdit *edit; - ETextEventProcessorCommand command = { 0 }; - - g_return_if_fail (cell_view != NULL); - - ectv = (ECellTextView *) cell_view; - edit = ectv->edit; - if (!edit) - return; - - if (edit->view_col != col || edit->row != row) - return; - - command.action = E_TEP_COPY; - command.time = GDK_CURRENT_TIME; - e_cell_text_view_command (edit->tep, &command, edit); -} - -/** - * e_cell_text_paste_clipboard: - * @cell_view: the given cell view - * @col: column of the given cell in the view - * @row: row of the given cell in the view - * - * Pastes the text from the clipboardt. - * - * This API is most likely to be used by a11y implementations. - */ -void -e_cell_text_paste_clipboard (ECellView *cell_view, - gint col, - gint row) -{ - ECellTextView *ectv; - CellEdit *edit; - ETextEventProcessorCommand command = { 0 }; - - g_return_if_fail (cell_view != NULL); - - ectv = (ECellTextView *) cell_view; - edit = ectv->edit; - if (!edit) - return; - - if (edit->view_col != col || edit->row != row) - return; - - command.action = E_TEP_PASTE; - command.time = GDK_CURRENT_TIME; - e_cell_text_view_command (edit->tep, &command, edit); -} - -/** - * e_cell_text_delete_selection: - * @cell_view: the given cell view - * @col: column of the given cell in the view - * @row: row of the given cell in the view - * - * Deletes the selected text of the cell. - * - * This API is most likely to be used by a11y implementations. - */ -void -e_cell_text_delete_selection (ECellView *cell_view, - gint col, - gint row) -{ - ECellTextView *ectv; - CellEdit *edit; - ETextEventProcessorCommand command = { 0 }; - - g_return_if_fail (cell_view != NULL); - - ectv = (ECellTextView *) cell_view; - edit = ectv->edit; - if (!edit) - return; - - if (edit->view_col != col || edit->row != row) - return; - - command.action = E_TEP_DELETE; - command.position = E_TEP_SELECTION; - e_cell_text_view_command (edit->tep, &command, edit); -} - -/** - * e_cell_text_get_text_by_view: - * @cell_view: the given cell view - * @col: column of the given cell in the model - * @row: row of the given cell in the model - * - * Get the cell's text directly from CellEdit, - * during editting this cell, the cell's text value maybe inconsistant - * with the text got from table_model. - * The caller should free the text after using it. - * - * This API is most likely to be used by a11y implementations. - */ -gchar * -e_cell_text_get_text_by_view (ECellView *cell_view, - gint col, - gint row) -{ - ECellTextView *ectv; - CellEdit *edit; - gchar *ret, *model_text; - - g_return_val_if_fail (cell_view != NULL, NULL); - - ectv = (ECellTextView *) cell_view; - edit = ectv->edit; - - if (edit && ectv->edit->row == row && ectv->edit->model_col == col) { /* being editted now */ - ret = g_strdup (edit->text); - } else{ - model_text = e_cell_text_get_text ( - E_CELL_TEXT (cell_view->ecell), - cell_view->e_table_model, col, row); - ret = g_strdup (model_text); - e_cell_text_free_text (E_CELL_TEXT (cell_view->ecell), model_text); - } - - return ret; - -} diff --git a/widgets/table/e-cell-text.h b/widgets/table/e-cell-text.h deleted file mode 100644 index 850d0caf29..0000000000 --- a/widgets/table/e-cell-text.h +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Text cell renderer. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Miguel de Icaza <miguel@ximian.com> - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - * 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> - * - */ - -#ifndef E_CELL_TEXT_H -#define E_CELL_TEXT_H - -#include <gtk/gtk.h> -#include <libgnomecanvas/libgnomecanvas.h> -#include <table/e-cell.h> - -/* Standard GObject macros */ -#define E_TYPE_CELL_TEXT \ - (e_cell_text_get_type ()) -#define E_CELL_TEXT(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_CELL_TEXT, ECellText)) -#define E_CELL_TEXT_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_CELL_TEXT, ECellTextClass)) -#define E_IS_CELL_TEXT(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_CELL_TEXT)) -#define E_IS_CELL_TEXT_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_CELL_TEXT)) -#define E_CELL_TEXT_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_CELL_TEXT, ECellTextClass)) - -G_BEGIN_DECLS - -typedef struct _ECellText ECellText; -typedef struct _ECellTextClass ECellTextClass; - -struct _ECellText { - ECell parent; - - GtkJustification justify; - gchar *font_name; - - gdouble x, y; /* Position at anchor */ - - gulong pixel; /* Fill color */ - - /* Clip handling */ - gchar *ellipsis; /* The ellipsis characters. NULL = "...". */ - - guint use_ellipsis : 1; /* Whether to use the ellipsis. */ - guint editable : 1; /* Whether the text can be edited. */ - - gint strikeout_column; - gint underline_column; - gint 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. */ - gint color_column; - gint bg_color_column; -}; - -struct _ECellTextClass { - ECellClass parent_class; - - /* Methods */ - gchar * (*get_text) (ECellText *cell, - ETableModel *model, - gint col, - gint row); - void (*free_text) (ECellText *cell, - gchar *text); - void (*set_value) (ECellText *cell, - ETableModel *model, - gint col, - gint row, - const gchar *text); - - /* Signals */ - void (*text_inserted) (ECellText *cell, - ECellView *cell_view, - gint pos, - gint len, - gint row, - gint model_col); - void (*text_deleted) (ECellText *cell, - ECellView *cell_view, - gint pos, - gint len, - gint row, - gint model_col); -}; - -GType e_cell_text_get_type (void) G_GNUC_CONST; -ECell * e_cell_text_new (const gchar *fontname, - GtkJustification justify); -ECell * e_cell_text_construct (ECellText *cell, - const gchar *fontname, - GtkJustification justify); - -/* Gets the value from the model and converts it into a string. In ECellText - * itself, the value is assumed to be a gchar * and so needs no conversion. - * In subclasses the ETableModel value may be a more complicated datatype. */ -gchar * e_cell_text_get_text (ECellText *cell, - ETableModel *model, - gint col, - gint row); - -/* Frees the value returned by e_cell_text_get_text(). */ -void e_cell_text_free_text (ECellText *cell, - gchar *text); - -/* Sets the ETableModel value, based on the given string. */ -void e_cell_text_set_value (ECellText *cell, - ETableModel *model, - gint col, - gint row, - const gchar *text); - -/* Sets the selection of given text cell */ -gboolean e_cell_text_set_selection (ECellView *cell_view, - gint col, - gint row, - gint start, - gint end); - -/* Gets the selection of given text cell */ -gboolean e_cell_text_get_selection (ECellView *cell_view, - gint col, - gint row, - gint *start, - gint *end); - -/* Copys the selected text to the clipboard */ -void e_cell_text_copy_clipboard (ECellView *cell_view, - gint col, - gint row); - -/* Pastes the text from the clipboard */ -void e_cell_text_paste_clipboard (ECellView *cell_view, - gint col, - gint row); - -/* Deletes selected text */ -void e_cell_text_delete_selection (ECellView *cell_view, - gint col, - gint row); - -/* get text directly from view, both col and row are model format */ -gchar * e_cell_text_get_text_by_view (ECellView *cell_view, - gint col, - gint row); - -G_END_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 f4de9d6922..0000000000 --- a/widgets/table/e-cell-toggle.c +++ /dev/null @@ -1,470 +0,0 @@ -/* - * e-cell-toggle.c - Multi-state image toggle cell object. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Miguel de Icaza <miguel@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> -#include <libgnomecanvas/libgnomecanvas.h> - -#include "art/empty.xpm" - -#include "gal-a11y-e-cell-toggle.h" -#include "gal-a11y-e-cell-registry.h" -#include "e-util/e-util.h" - -#include "e-cell-toggle.h" -#include "e-table-item.h" - -#define E_CELL_TOGGLE_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), E_TYPE_CELL_TOGGLE, ECellTogglePrivate)) - -struct _ECellTogglePrivate { - gchar **icon_names; - guint n_icon_names; - - GdkPixbuf *empty; - GPtrArray *pixbufs; - gint height; -}; - -G_DEFINE_TYPE (ECellToggle, e_cell_toggle, E_TYPE_CELL) - -typedef struct { - ECellView cell_view; - GnomeCanvas *canvas; -} ECellToggleView; - -static void -cell_toggle_load_icons (ECellToggle *cell_toggle) -{ - GtkIconTheme *icon_theme; - gint width, height; - gint max_height = 0; - guint ii; - GError *error = NULL; - - icon_theme = gtk_icon_theme_get_default (); - gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height); - - g_ptr_array_set_size (cell_toggle->priv->pixbufs, 0); - - for (ii = 0; ii < cell_toggle->priv->n_icon_names; ii++) { - const gchar *icon_name = cell_toggle->priv->icon_names[ii]; - GdkPixbuf *pixbuf = NULL; - - if (icon_name != NULL) - pixbuf = gtk_icon_theme_load_icon ( - icon_theme, icon_name, height, 0, &error); - - if (error != NULL) { - g_warning ("%s", error->message); - g_clear_error (&error); - } - - if (pixbuf == NULL) - pixbuf = g_object_ref (cell_toggle->priv->empty); - - g_ptr_array_add (cell_toggle->priv->pixbufs, pixbuf); - max_height = MAX (max_height, gdk_pixbuf_get_height (pixbuf)); - } - - cell_toggle->priv->height = max_height; -} - -static void -cell_toggle_dispose (GObject *object) -{ - ECellTogglePrivate *priv; - - priv = E_CELL_TOGGLE_GET_PRIVATE (object); - - if (priv->empty != NULL) { - g_object_unref (priv->empty); - priv->empty = NULL; - } - - /* This unrefs all the elements. */ - g_ptr_array_set_size (priv->pixbufs, 0); - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (e_cell_toggle_parent_class)->dispose (object); -} - -static void -cell_toggle_finalize (GObject *object) -{ - ECellTogglePrivate *priv; - guint ii; - - priv = E_CELL_TOGGLE_GET_PRIVATE (object); - - /* The array is not NULL-terminated, - * so g_strfreev() will not work. */ - for (ii = 0; ii < priv->n_icon_names; ii++) - g_free (priv->icon_names[ii]); - g_free (priv->icon_names); - - g_ptr_array_free (priv->pixbufs, TRUE); - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (e_cell_toggle_parent_class)->finalize (object); -} - -static ECellView * -cell_toggle_new_view (ECell *ecell, - ETableModel *table_model, - gpointer 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->cell_view.kill_view_cb = NULL; - toggle_view->cell_view.kill_view_cb_data = NULL; - toggle_view->canvas = canvas; - - return (ECellView *) toggle_view; -} - -static void -cell_toggle_kill_view (ECellView *ecell_view) -{ - ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; - - if (toggle_view->cell_view.kill_view_cb) - toggle_view->cell_view.kill_view_cb ( - ecell_view, toggle_view->cell_view.kill_view_cb_data); - - if (toggle_view->cell_view.kill_view_cb_data) - g_list_free (toggle_view->cell_view.kill_view_cb_data); - - g_free (ecell_view); -} - -static void -cell_toggle_draw (ECellView *ecell_view, - cairo_t *cr, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - gint x1, - gint y1, - gint x2, - gint y2) -{ - ECellTogglePrivate *priv; - GdkPixbuf *image; - gint x, y; - - const gint value = GPOINTER_TO_INT ( - e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - - priv = E_CELL_TOGGLE_GET_PRIVATE (ecell_view->ecell); - - if (value < 0 || value >= priv->pixbufs->len) - return; - - image = g_ptr_array_index (priv->pixbufs, value); - - if ((x2 - x1) < gdk_pixbuf_get_width (image)) - x = x1; - else - x = x1 + ((x2 - x1) - gdk_pixbuf_get_width (image)) / 2; - - if ((y2 - y1) < gdk_pixbuf_get_height (image)) - y = y1; - else - y = y1 + ((y2 - y1) - gdk_pixbuf_get_height (image)) / 2; - - cairo_save (cr); - gdk_cairo_set_source_pixbuf (cr, image, x, y); - cairo_paint_with_alpha (cr, 1); - cairo_restore (cr); -} - -static void -etog_set_value (ECellToggleView *toggle_view, - gint model_col, - gint view_col, - gint row, - gint value) -{ - ECellTogglePrivate *priv; - - priv = E_CELL_TOGGLE_GET_PRIVATE (toggle_view->cell_view.ecell); - - if (value >= priv->pixbufs->len) - value = 0; - - e_table_model_set_value_at ( - toggle_view->cell_view.e_table_model, - model_col, row, GINT_TO_POINTER (value)); -} - -static gint -cell_toggle_event (ECellView *ecell_view, - GdkEvent *event, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - ECellActions *actions) -{ - ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; - gpointer _value = e_table_model_value_at ( - ecell_view->e_table_model, model_col, row); - const gint value = GPOINTER_TO_INT (_value); - - switch (event->type) { - case GDK_KEY_PRESS: - if (event->key.keyval != GDK_KEY_space) - return FALSE; - /* Fall through */ - case GDK_BUTTON_PRESS: - 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; - - default: - return FALSE; - } -} - -static gint -cell_toggle_height (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row) -{ - ECellTogglePrivate *priv; - - priv = E_CELL_TOGGLE_GET_PRIVATE (ecell_view->ecell); - - return priv->height; -} - -static void -cell_toggle_print (ECellView *ecell_view, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width, - gdouble height) -{ - ECellTogglePrivate *priv; - GdkPixbuf *image; - gdouble image_width, image_height; - const gint value = GPOINTER_TO_INT ( - e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - - cairo_t *cr; - - priv = E_CELL_TOGGLE_GET_PRIVATE (ecell_view->ecell); - - if (value >= priv->pixbufs->len) - return; - - image = g_ptr_array_index (priv->pixbufs, value); - if (image) { - cr = gtk_print_context_get_cairo_context (context); - cairo_save (cr); - cairo_translate (cr, 0 , 0); - image = gdk_pixbuf_add_alpha (image, TRUE, 255, 255, 255); - image_width = (gdouble) gdk_pixbuf_get_width (image); - image_height = (gdouble) gdk_pixbuf_get_height (image); - cairo_rectangle ( - cr, - image_width / 7, - image_height / 3, - image_width - image_width / 4, - image_width - image_height / 7); - cairo_clip (cr); - gdk_cairo_set_source_pixbuf (cr, image, 0, image_height / 4); - cairo_paint (cr); - cairo_restore (cr); - } -} - -static gdouble -cell_toggle_print_height (ECellView *ecell_view, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width) -{ - ECellTogglePrivate *priv; - - priv = E_CELL_TOGGLE_GET_PRIVATE (ecell_view->ecell); - - return priv->height; -} - -static gint -cell_toggle_max_width (ECellView *ecell_view, - gint model_col, - gint view_col) -{ - ECellTogglePrivate *priv; - gint max_width = 0; - gint number_of_rows; - gint row; - - priv = E_CELL_TOGGLE_GET_PRIVATE (ecell_view->ecell); - - number_of_rows = e_table_model_row_count (ecell_view->e_table_model); - for (row = 0; row < number_of_rows; row++) { - GdkPixbuf *pixbuf; - gpointer value; - - value = e_table_model_value_at ( - ecell_view->e_table_model, model_col, row); - pixbuf = g_ptr_array_index ( - priv->pixbufs, GPOINTER_TO_INT (value)); - - max_width = MAX (max_width, gdk_pixbuf_get_width (pixbuf)); - } - - return max_width; -} - -static void -e_cell_toggle_class_init (ECellToggleClass *class) -{ - GObjectClass *object_class; - ECellClass *cell_class; - - g_type_class_add_private (class, sizeof (ECellTogglePrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->dispose = cell_toggle_dispose; - object_class->finalize = cell_toggle_finalize; - - cell_class = E_CELL_CLASS (class); - cell_class->new_view = cell_toggle_new_view; - cell_class->kill_view = cell_toggle_kill_view; - cell_class->draw = cell_toggle_draw; - cell_class->event = cell_toggle_event; - cell_class->height = cell_toggle_height; - cell_class->print = cell_toggle_print; - cell_class->print_height = cell_toggle_print_height; - cell_class->max_width = cell_toggle_max_width; - - gal_a11y_e_cell_registry_add_cell_type ( - NULL, E_TYPE_CELL_TOGGLE, gal_a11y_e_cell_toggle_new); -} - -static void -e_cell_toggle_init (ECellToggle *cell_toggle) -{ - cell_toggle->priv = E_CELL_TOGGLE_GET_PRIVATE (cell_toggle); - - cell_toggle->priv->empty = - gdk_pixbuf_new_from_xpm_data (empty_xpm); - - cell_toggle->priv->pixbufs = - g_ptr_array_new_with_free_func (g_object_unref); -} - -/** - * e_cell_toggle_construct: - * @cell_toggle: a fresh ECellToggle object - * @icon_names: array of icon names, some of which may be %NULL - * @n_icon_names: length of the @icon_names array - * - * Constructs the @cell_toggle object with the @icon_names and @n_icon_names - * arguments. - */ -void -e_cell_toggle_construct (ECellToggle *cell_toggle, - const gchar **icon_names, - guint n_icon_names) -{ - guint ii; - - g_return_if_fail (E_IS_CELL_TOGGLE (cell_toggle)); - g_return_if_fail (icon_names != NULL); - g_return_if_fail (n_icon_names > 0); - - cell_toggle->priv->icon_names = g_new (gchar *, n_icon_names); - cell_toggle->priv->n_icon_names = n_icon_names; - - for (ii = 0; ii < n_icon_names; ii++) - cell_toggle->priv->icon_names[ii] = g_strdup (icon_names[ii]); - - cell_toggle_load_icons (cell_toggle); -} - -/** - * e_cell_toggle_new: - * @icon_names: array of icon names, some of which may be %NULL - * @n_icon_names: length of the @icon_names array - * - * Creates a new ECell renderer that can be used to render toggle - * buttons with the icons specified in @icon_names. The value returned - * by ETableModel::get_value is typecast into an integer and clamped - * to the [0..n_icon_names) range. That will select the image rendered. - * - * %NULL elements in @icon_names will show no icon for the corresponding - * integer value. - * - * Returns: an ECell object that can be used to render multi-state - * toggle cells. - */ -ECell * -e_cell_toggle_new (const gchar **icon_names, - guint n_icon_names) -{ - ECellToggle *cell_toggle; - - g_return_val_if_fail (icon_names != NULL, NULL); - g_return_val_if_fail (n_icon_names > 0, NULL); - - cell_toggle = g_object_new (E_TYPE_CELL_TOGGLE, NULL); - e_cell_toggle_construct (cell_toggle, icon_names, n_icon_names); - - return (ECell *) cell_toggle; -} - -GPtrArray * -e_cell_toggle_get_pixbufs (ECellToggle *cell_toggle) -{ - g_return_val_if_fail (E_IS_CELL_TOGGLE (cell_toggle), NULL); - - return cell_toggle->priv->pixbufs; -} diff --git a/widgets/table/e-cell-toggle.h b/widgets/table/e-cell-toggle.h deleted file mode 100644 index 3bc223c229..0000000000 --- a/widgets/table/e-cell-toggle.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * - * Multi-state image toggle cell object. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Miguel de Icaza <miguel@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_CELL_TOGGLE_H -#define E_CELL_TOGGLE_H - -#include <libgnomecanvas/libgnomecanvas.h> -#include <gdk-pixbuf/gdk-pixbuf.h> -#include <table/e-cell.h> - -/* Standard GObject macros */ -#define E_TYPE_CELL_TOGGLE \ - (e_cell_toggle_get_type ()) -#define E_CELL_TOGGLE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_CELL_TOGGLE, ECellToggle)) -#define E_CELL_TOGGLE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_CELL_TOGGLE, ECellToggleClass)) -#define E_IS_CELL_TOGGLE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_CELL_TOGGLE)) -#define E_IS_CELL_TOGGLE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_CELL_TOGGLE)) -#define E_CELL_TOGGLE_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_CELL_TOGGLE, ECellToggleClass)) - -G_BEGIN_DECLS - -typedef struct _ECellToggle ECellToggle; -typedef struct _ECellToggleClass ECellToggleClass; -typedef struct _ECellTogglePrivate ECellTogglePrivate; - -struct _ECellToggle { - ECell parent; - ECellTogglePrivate *priv; -}; - -struct _ECellToggleClass { - ECellClass parent_class; -}; - -GType e_cell_toggle_get_type (void) G_GNUC_CONST; -ECell * e_cell_toggle_new (const gchar **icon_names, - guint n_icon_names); -void e_cell_toggle_construct (ECellToggle *cell_toggle, - const gchar **icon_names, - guint n_icon_names); -GPtrArray * e_cell_toggle_get_pixbufs (ECellToggle *cell_toggle); - -G_END_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 00d096f4e6..0000000000 --- a/widgets/table/e-cell-tree.c +++ /dev/null @@ -1,881 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-cell-tree.c - Tree cell object. - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - * Authors: - * Chris Toshok <toshok@ximian.com> - * - * A majority of code taken from: - * - * the ECellText renderer. - * Copyright 1998, The Free Software Foundation - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <ctype.h> -#include <math.h> -#include <stdio.h> - -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> -#include <libgnomecanvas/libgnomecanvas.h> - -#include "gal-a11y-e-cell-registry.h" -#include "gal-a11y-e-cell-tree.h" -#include "e-util/e-util.h" - -#include "e-cell-tree.h" -#include "e-table-item.h" -#include "e-tree.h" -#include "e-tree-model.h" -#include "e-tree-table-adapter.h" - -G_DEFINE_TYPE (ECellTree, e_cell_tree, E_TYPE_CELL) - -typedef struct { - ECellView cell_view; - ECellView *subcell_view; - - GnomeCanvas *canvas; - gboolean prelit; - gint animate_timeout; - -} ECellTreeView; - -#define INDENT_AMOUNT 16 - -ECellView * -e_cell_tree_view_get_subcell_view (ECellView *ect) -{ - return ((ECellTreeView *) ect)->subcell_view; -} - -static ETreePath -e_cell_tree_get_node (ETableModel *table_model, - gint row) -{ - return e_table_model_value_at (table_model, -1, row); -} - -static ETreeModel * -e_cell_tree_get_tree_model (ETableModel *table_model, - gint row) -{ - return e_table_model_value_at (table_model, -2, row); -} - -static ETreeTableAdapter * -e_cell_tree_get_tree_table_adapter (ETableModel *table_model, - gint row) -{ - return e_table_model_value_at (table_model, -3, row); -} - -static gint -visible_depth_of_node (ETableModel *model, - gint row) -{ - ETreeModel *tree_model = e_cell_tree_get_tree_model (model, row); - ETreeTableAdapter *adapter = e_cell_tree_get_tree_table_adapter (model, row); - ETreePath path = e_cell_tree_get_node (model, row); - return (e_tree_model_node_depth (tree_model, path) - - (e_tree_table_adapter_root_node_is_visible (adapter) ? 0 : 1)); -} - -/* If this is changed to not include the width of the expansion pixmap - * if the path is not expandable, then max_width needs to change as - * well. */ -static gint -offset_of_node (ETableModel *table_model, - gint row) -{ - ETreeModel *tree_model = e_cell_tree_get_tree_model (table_model, row); - ETreePath path = e_cell_tree_get_node (table_model, row); - - if (visible_depth_of_node (table_model, row) >= 0 || - e_tree_model_node_is_expandable (tree_model, path)) { - return (visible_depth_of_node (table_model, row) + 1) * INDENT_AMOUNT; - } else { - return 0; - } -} - -/* - * ECell::new_view method - */ -static ECellView * -ect_new_view (ECell *ecell, - ETableModel *table_model, - gpointer 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; - tree_view->cell_view.kill_view_cb = NULL; - tree_view->cell_view.kill_view_cb_data = NULL; - - /* 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; - - if (tree_view->cell_view.kill_view_cb) - (tree_view->cell_view.kill_view_cb)(ecv, tree_view->cell_view.kill_view_cb_data); - - if (tree_view->cell_view.kill_view_cb_data) - g_list_free (tree_view->cell_view.kill_view_cb_data); - - /* 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); - - if (E_CELL_CLASS (e_cell_tree_parent_class)->realize) - (* E_CELL_CLASS (e_cell_tree_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); - - if (E_CELL_CLASS (e_cell_tree_parent_class)->unrealize) - (* E_CELL_CLASS (e_cell_tree_parent_class)->unrealize) (ecv); -} - -static void -draw_expander (ECellTreeView *ectv, - cairo_t *cr, - GtkExpanderStyle expander_style, - GtkStateType state, - GdkRectangle *rect) -{ - GtkStyleContext *style_context; - GtkWidget *tree; - GtkStateFlags flags = 0; - gint exp_size; - - tree = gtk_widget_get_parent (GTK_WIDGET (ectv->canvas)); - style_context = gtk_widget_get_style_context (tree); - - gtk_style_context_save (style_context); - - gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_EXPANDER); - - switch (state) { - case GTK_STATE_PRELIGHT: - flags |= GTK_STATE_FLAG_PRELIGHT; - break; - case GTK_STATE_SELECTED: - flags |= GTK_STATE_FLAG_SELECTED; - break; - case GTK_STATE_INSENSITIVE: - flags |= GTK_STATE_FLAG_INSENSITIVE; - break; - default: - break; - } - - if (expander_style == GTK_EXPANDER_EXPANDED) - flags |= GTK_STATE_FLAG_ACTIVE; - - gtk_style_context_set_state (style_context, flags); - - gtk_widget_style_get (tree, "expander_size", &exp_size, NULL); - - cairo_save (cr); - - gtk_render_expander ( - style_context, cr, - (gdouble) rect->x + rect->width - exp_size, - (gdouble) (rect->y + rect->height / 2) - (exp_size / 2), - (gdouble) exp_size, - (gdouble) exp_size); - - cairo_restore (cr); - - gtk_style_context_restore (style_context); -} - -/* - * ECell::draw method - */ -static void -ect_draw (ECellView *ecell_view, - cairo_t *cr, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - gint x1, - gint y1, - gint x2, - gint y2) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - ETreeModel *tree_model = e_cell_tree_get_tree_model (ecell_view->e_table_model, row); - ETreeTableAdapter *tree_table_adapter = e_cell_tree_get_tree_table_adapter (ecell_view->e_table_model, row); - ETreePath node; - GdkRectangle rect; - gint offset, subcell_offset; - - cairo_save (cr); - - /* only draw the tree effects if we're the active sort */ - if (/* XXX */ TRUE) { - GdkPixbuf *node_image; - gint node_image_width = 0, node_image_height = 0; - - tree_view->prelit = FALSE; - - node = e_cell_tree_get_node (ecell_view->e_table_model, row); - - offset = offset_of_node (ecell_view->e_table_model, row); - subcell_offset = offset; - - node_image = e_tree_model_icon_at (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; - - /* now draw our icon if we're expandable */ - if (e_tree_model_node_is_expandable (tree_model, node)) { - gboolean expanded = e_tree_table_adapter_node_is_expanded (tree_table_adapter, node); - GdkRectangle r; - - r = rect; - r.width -= node_image_width + 2; - draw_expander (tree_view, cr, expanded ? GTK_EXPANDER_EXPANDED : GTK_EXPANDER_COLLAPSED, GTK_STATE_NORMAL, &r); - } - - if (node_image) { - gdk_cairo_set_source_pixbuf ( - cr, node_image, - x1 + subcell_offset, - y1 + (y2 - y1) / 2 - node_image_height / 2); - cairo_paint (cr); - - 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, cr, - model_col, view_col, row, flags, - x1 + subcell_offset, y1, x2, y2); - - cairo_restore (cr); -} - -static void -adjust_event_position (GdkEvent *event, - gint offset) -{ - 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: - break; - } -} - -static gboolean -event_in_expander (GdkEvent *event, - gint offset, - gint height) -{ - switch (event->type) { - case GDK_BUTTON_PRESS: - return (event->button.x > (offset - INDENT_AMOUNT) && event->button.x < offset); - case GDK_MOTION_NOTIFY: - return (event->motion.x > (offset - INDENT_AMOUNT) && event->motion.x < offset && - event->motion.y > 2 && event->motion.y < (height - 2)); - default: - break; - } - - return FALSE; -} - -/* - * ECell::height method - */ -static gint -ect_height (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - - return (((e_cell_height (tree_view->subcell_view, model_col, view_col, row)) + 1) / 2) * 2; -} - -typedef struct { - ECellTreeView *ectv; - ETreeTableAdapter *etta; - ETreePath node; - gboolean expanded; - gboolean finish; - GdkRectangle area; -} animate_closure_t; - -static gboolean -animate_expander (gpointer data) -{ - GtkLayout *layout; - GdkWindow *window; - animate_closure_t *closure = (animate_closure_t *) data; - cairo_t *cr; - - if (closure->finish) { - e_tree_table_adapter_node_set_expanded (closure->etta, closure->node, !closure->expanded); - closure->ectv->animate_timeout = 0; - g_free (data); - return FALSE; - } - - layout = GTK_LAYOUT (closure->ectv->canvas); - window = gtk_layout_get_bin_window (layout); - - cr = gdk_cairo_create (window); - - draw_expander ( - closure->ectv, cr, closure->expanded ? - GTK_EXPANDER_SEMI_COLLAPSED : - GTK_EXPANDER_SEMI_EXPANDED, - GTK_STATE_NORMAL, &closure->area); - closure->finish = TRUE; - - cairo_destroy (cr); - - return TRUE; -} - -/* - * ECell::event method - */ -static gint -ect_event (ECellView *ecell_view, - GdkEvent *event, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - ECellActions *actions) -{ - GtkLayout *layout; - GdkWindow *window; - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - ETreeModel *tree_model = e_cell_tree_get_tree_model (ecell_view->e_table_model, row); - ETreeTableAdapter *etta = e_cell_tree_get_tree_table_adapter (ecell_view->e_table_model, row); - ETreePath node = e_cell_tree_get_node (ecell_view->e_table_model, row); - gint offset = offset_of_node (ecell_view->e_table_model, row); - gint result; - - layout = GTK_LAYOUT (tree_view->canvas); - window = gtk_layout_get_bin_window (layout); - - switch (event->type) { - case GDK_BUTTON_PRESS: - - if (event_in_expander (event, offset, 0)) { - if (e_tree_model_node_is_expandable (tree_model, node)) { - gboolean expanded = e_tree_table_adapter_node_is_expanded (etta, node); - gint tmp_row = row; - GdkRectangle area; - animate_closure_t *closure = g_new0 (animate_closure_t, 1); - cairo_t *cr; - gint hgt; - - e_table_item_get_cell_geometry ( - tree_view->cell_view.e_table_item_view, - &tmp_row, &view_col, &area.x, &area.y, NULL, &area.height); - area.width = offset - 2; - hgt = e_cell_height (ecell_view, model_col, view_col, row); - - if (hgt != area.height) /* Composite cells */ - area.height += hgt; - - cr = gdk_cairo_create (window); - draw_expander ( - tree_view, cr, expanded ? - GTK_EXPANDER_SEMI_EXPANDED : - GTK_EXPANDER_SEMI_COLLAPSED, - GTK_STATE_NORMAL, &area); - cairo_destroy (cr); - - closure->ectv = tree_view; - closure->etta = etta; - closure->node = node; - closure->expanded = expanded; - closure->area = area; - tree_view->animate_timeout = g_timeout_add (50, animate_expander, closure); - return TRUE; - } - } - else if (event->button.x < (offset - INDENT_AMOUNT)) - return FALSE; - break; - - case GDK_MOTION_NOTIFY: - - if (e_tree_model_node_is_expandable (tree_model, node)) { - gint height = ect_height (ecell_view, model_col, view_col, row); - GdkRectangle area; - gboolean in_expander = event_in_expander (event, offset, height); - - if (tree_view->prelit ^ in_expander) { - gint tmp_row = row; - cairo_t *cr; - - e_table_item_get_cell_geometry ( - tree_view->cell_view.e_table_item_view, - &tmp_row, &view_col, &area.x, &area.y, NULL, &area.height); - area.width = offset - 2; - - cr = gdk_cairo_create (window); - draw_expander ( - tree_view, cr, - e_tree_table_adapter_node_is_expanded (etta, node) ? - GTK_EXPANDER_EXPANDED : GTK_EXPANDER_COLLAPSED, - in_expander ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL, &area); - cairo_destroy (cr); - - tree_view->prelit = in_expander; - return TRUE; - } - - } - break; - - case GDK_LEAVE_NOTIFY: - - if (tree_view->prelit) { - gint tmp_row = row; - GdkRectangle area; - cairo_t *cr; - - e_table_item_get_cell_geometry ( - tree_view->cell_view.e_table_item_view, - &tmp_row, &view_col, &area.x, &area.y, NULL, &area.height); - area.width = offset - 2; - - cr = gdk_cairo_create (window); - draw_expander ( - tree_view, cr, - e_tree_table_adapter_node_is_expanded (etta, node) ? - GTK_EXPANDER_EXPANDED : GTK_EXPANDER_COLLAPSED, - GTK_STATE_NORMAL, &area); - cairo_destroy (cr); - - tree_view->prelit = FALSE; - } - return TRUE; - - default: - break; - } - - adjust_event_position (event, -offset); - result = e_cell_event (tree_view->subcell_view, event, model_col, view_col, row, flags, actions); - adjust_event_position (event, offset); - - return result; -} - -/* - * ECell::max_width method - */ -static gint -ect_max_width (ECellView *ecell_view, - gint model_col, - gint view_col) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - gint row; - gint number_of_rows; - gint max_width = 0; - gint width = 0; - gint subcell_max_width = 0; - gboolean per_row = e_cell_max_width_by_row_implemented (tree_view->subcell_view); - - number_of_rows = e_table_model_row_count (ecell_view->e_table_model); - - if (!per_row) - 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; - gint node_image_width = 0; - - gint offset, subcell_offset; -#if 0 - gboolean expanded, expandable; - ETreeTableAdapter *tree_table_adapter = e_cell_tree_get_tree_table_adapter (ecell_view->e_table_model, row); -#endif - - node = e_cell_tree_get_node (ecell_view->e_table_model, row); - - offset = offset_of_node (ecell_view->e_table_model, row); - subcell_offset = offset; - - node_image = e_tree_model_icon_at (tree_model, node); - - if (node_image) { - node_image_width = gdk_pixbuf_get_width (node_image); - } - - width = subcell_offset + node_image_width; - - if (per_row) - width += e_cell_max_width_by_row (tree_view->subcell_view, model_col, view_col, row); - else - width += subcell_max_width; - -#if 0 - expandable = e_tree_model_node_is_expandable (tree_model, node); - expanded = e_tree_table_adapter_node_is_expanded (tree_table_adapter, node); - - /* This is unnecessary since this is already handled - * by the offset_of_node function. If that changes, - * this will have to change too. */ - - 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); - } -#endif - - max_width = MAX (max_width, width); - } - - return max_width; -} - -/* - * ECellView::get_bg_color method - */ -static gchar * -ect_get_bg_color (ECellView *ecell_view, - gint row) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - - return e_cell_get_bg_color (tree_view->subcell_view, row); -} - -/* - * ECellView::enter_edit method - */ -static gpointer -ect_enter_edit (ECellView *ecell_view, - gint model_col, - gint view_col, - gint 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, - gint model_col, - gint view_col, - gint row, - gpointer 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, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width, - gdouble height) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - cairo_t *cr = gtk_print_context_get_cairo_context (context); - - cairo_save (cr); - - 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); - ETreeTableAdapter *tree_table_adapter = e_cell_tree_get_tree_table_adapter (ecell_view->e_table_model, row); - ETreePath node = e_cell_tree_get_node (ecell_view->e_table_model, row); - gint offset = offset_of_node (ecell_view->e_table_model, row); - gint subcell_offset = offset; - gboolean expandable = e_tree_model_node_is_expandable (tree_model, node); - - /* draw our lines */ - if (E_CELL_TREE (tree_view->cell_view.ecell)->draw_lines) { - gint depth; - - if (!e_tree_model_node_is_root (tree_model, node) - || e_tree_model_node_get_children (tree_model, node, NULL) > 0) { - cairo_move_to ( - cr, - offset - INDENT_AMOUNT / 2, - height / 2); - cairo_line_to (cr, offset, height / 2); - } - - if (visible_depth_of_node (ecell_view->e_table_model, row) != 0) { - cairo_move_to ( - cr, - offset - INDENT_AMOUNT / 2, height); - cairo_line_to ( - cr, - offset - INDENT_AMOUNT / 2, - e_tree_table_adapter_node_get_next - (tree_table_adapter, 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); - depth = visible_depth_of_node (ecell_view->e_table_model, row) - 1; - offset -= INDENT_AMOUNT; - while (node && depth != 0) { - if (e_tree_table_adapter_node_get_next (tree_table_adapter, node)) { - cairo_move_to ( - cr, - offset - INDENT_AMOUNT / 2, - height); - cairo_line_to ( - cr, - offset - INDENT_AMOUNT / 2, 0); - } - node = e_tree_model_node_get_parent (tree_model, node); - depth--; - offset -= INDENT_AMOUNT; - } - } - - /* now draw our icon if we're expandable */ - if (expandable) { - gboolean expanded; - GdkRectangle r; - gint exp_size = 0; - - gtk_widget_style_get (GTK_WIDGET (gtk_widget_get_parent (GTK_WIDGET (tree_view->canvas))), "expander_size", &exp_size, NULL); - - node = e_cell_tree_get_node (ecell_view->e_table_model, row); - expanded = e_tree_table_adapter_node_is_expanded (tree_table_adapter, node); - - r.x = 0; - r.y = 0; - r.width = MIN (width, exp_size); - r.height = height; - - draw_expander (tree_view, cr, expanded ? GTK_EXPANDER_EXPANDED : GTK_EXPANDER_COLLAPSED, GTK_STATE_NORMAL, &r); - } - - cairo_stroke (cr); - - cairo_translate (cr, subcell_offset, 0); - width -= subcell_offset; - } - - cairo_restore (cr); - - e_cell_print (tree_view->subcell_view, context, model_col, view_col, row, width, height); -} - -static gdouble -ect_print_height (ECellView *ecell_view, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width) -{ - return 12; /* XXX */ -} - -/* - * GObject::dispose method - */ -static void -ect_dispose (GObject *object) -{ - ECellTree *ect = E_CELL_TREE (object); - - /* destroy our subcell */ - if (ect->subcell) - g_object_unref (ect->subcell); - ect->subcell = NULL; - - G_OBJECT_CLASS (e_cell_tree_parent_class)->dispose (object); -} - -static void -e_cell_tree_class_init (ECellTreeClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - ECellClass *ecc = E_CELL_CLASS (class); - - object_class->dispose = ect_dispose; - - 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->get_bg_color = ect_get_bg_color; - - gal_a11y_e_cell_registry_add_cell_type (NULL, E_TYPE_CELL_TREE, gal_a11y_e_cell_tree_new); -} - -static void -e_cell_tree_init (ECellTree *ect) -{ - /* nothing to do */ -} - -/** - * e_cell_tree_construct: - * @ect: the ECellTree we're constructing. - * @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, - gboolean draw_lines, - ECell *subcell) -{ - ect->subcell = subcell; - if (subcell) - g_object_ref_sink (subcell); - - ect->draw_lines = draw_lines; -} - -/** - * e_cell_tree_new: - * @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 (gboolean draw_lines, - ECell *subcell) -{ - ECellTree *ect = g_object_new (E_TYPE_CELL_TREE, NULL); - - e_cell_tree_construct (ect, 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 cf43c47a1c..0000000000 --- a/widgets/table/e-cell-tree.h +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-cell-tree.h - Tree cell object. - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - * Authors: - * Chris Toshok <toshok@ximian.com> - * - * A majority of code taken from: - * - * the ECellText renderer. - * Copyright 1998, The Free Software Foundation - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#ifndef _E_CELL_TREE_H_ -#define _E_CELL_TREE_H_ - -#include <libgnomecanvas/libgnomecanvas.h> -#include <table/e-cell.h> - -/* Standard GObject macros */ -#define E_TYPE_CELL_TREE \ - (e_cell_tree_get_type ()) -#define E_CELL_TREE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_CELL_TREE, ECellTree)) -#define E_CELL_TREE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_CELL_TREE, ECellTreeClass)) -#define E_IS_CELL_TREE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_CELL_TREE)) -#define E_IS_CELL_TREE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_CELL_TREE)) -#define E_CELL_TREE_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_CELL_TREE, ECellTreeClass)) - -G_BEGIN_DECLS - -typedef struct _ECellTree ECellTree; -typedef struct _ECellTreeClass ECellTreeClass; - -struct _ECellTree { - ECell parent; - - gboolean draw_lines; - - ECell *subcell; -}; - -struct _ECellTreeClass { - ECellClass parent_class; -}; - -GType e_cell_tree_get_type (void) G_GNUC_CONST; -ECell * e_cell_tree_new (gboolean draw_lines, - ECell *subcell); -void e_cell_tree_construct (ECellTree *ect, - gboolean draw_lines, - ECell *subcell); -ECellView * e_cell_tree_view_get_subcell_view - (ECellView *ect); - -G_END_DECLS - -#endif /* _E_CELL_TREE_H_ */ - diff --git a/widgets/table/e-cell-vbox.c b/widgets/table/e-cell-vbox.c deleted file mode 100644 index bce40a8a2e..0000000000 --- a/widgets/table/e-cell-vbox.c +++ /dev/null @@ -1,342 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Toshok <toshok@ximian.com> - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <ctype.h> -#include <math.h> -#include <stdio.h> - -#include <gtk/gtk.h> - -#include "gal-a11y-e-cell-registry.h" -#include "gal-a11y-e-cell-vbox.h" -#include "e-util/e-util.h" - -#include "e-cell-vbox.h" -#include "e-table-item.h" - -G_DEFINE_TYPE (ECellVbox, e_cell_vbox, E_TYPE_CELL) - -#define INDENT_AMOUNT 16 - -/* - * ECell::new_view method - */ -static ECellView * -ecv_new_view (ECell *ecell, - ETableModel *table_model, - gpointer e_table_item_view) -{ - ECellVbox *ecv = E_CELL_VBOX (ecell); - ECellVboxView *vbox_view = g_new0 (ECellVboxView, 1); - gint i; - - vbox_view->cell_view.ecell = ecell; - vbox_view->cell_view.e_table_model = table_model; - vbox_view->cell_view.e_table_item_view = e_table_item_view; - vbox_view->cell_view.kill_view_cb = NULL; - vbox_view->cell_view.kill_view_cb_data = NULL; - - /* create our subcell view */ - vbox_view->subcell_view_count = ecv->subcell_count; - vbox_view->subcell_views = g_new (ECellView *, vbox_view->subcell_view_count); - vbox_view->model_cols = g_new (int, vbox_view->subcell_view_count); - - for (i = 0; i < vbox_view->subcell_view_count; i++) { - vbox_view->subcell_views[i] = e_cell_new_view (ecv->subcells[i], table_model, e_table_item_view /* XXX */); - vbox_view->model_cols[i] = ecv->model_cols[i]; - } - - return (ECellView *) vbox_view; -} - -/* - * ECell::kill_view method - */ -static void -ecv_kill_view (ECellView *ecv) -{ - ECellVboxView *vbox_view = (ECellVboxView *) ecv; - gint i; - - if (vbox_view->cell_view.kill_view_cb) - (vbox_view->cell_view.kill_view_cb)(ecv, vbox_view->cell_view.kill_view_cb_data); - - if (vbox_view->cell_view.kill_view_cb_data) - g_list_free (vbox_view->cell_view.kill_view_cb_data); - - /* kill our subcell view */ - for (i = 0; i < vbox_view->subcell_view_count; i++) - e_cell_kill_view (vbox_view->subcell_views[i]); - - g_free (vbox_view->model_cols); - g_free (vbox_view->subcell_views); - g_free (vbox_view); -} - -/* - * ECell::realize method - */ -static void -ecv_realize (ECellView *ecell_view) -{ - ECellVboxView *vbox_view = (ECellVboxView *) ecell_view; - gint i; - - /* realize our subcell view */ - for (i = 0; i < vbox_view->subcell_view_count; i++) - e_cell_realize (vbox_view->subcell_views[i]); - - if (E_CELL_CLASS (e_cell_vbox_parent_class)->realize) - (* E_CELL_CLASS (e_cell_vbox_parent_class)->realize) (ecell_view); -} - -/* - * ECell::unrealize method - */ -static void -ecv_unrealize (ECellView *ecv) -{ - ECellVboxView *vbox_view = (ECellVboxView *) ecv; - gint i; - - /* unrealize our subcell view. */ - for (i = 0; i < vbox_view->subcell_view_count; i++) - e_cell_unrealize (vbox_view->subcell_views[i]); - - if (E_CELL_CLASS (e_cell_vbox_parent_class)->unrealize) - (* E_CELL_CLASS (e_cell_vbox_parent_class)->unrealize) (ecv); -} - -/* - * ECell::draw method - */ -static void -ecv_draw (ECellView *ecell_view, - cairo_t *cr, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - gint x1, - gint y1, - gint x2, - gint y2) -{ - ECellVboxView *vbox_view = (ECellVboxView *) ecell_view; - - gint subcell_offset = 0; - gint i; - - for (i = 0; i < vbox_view->subcell_view_count; i++) { - /* Now cause our subcells to draw their contents, - * shifted by subcell_offset pixels */ - gint height; - - height = e_cell_height ( - vbox_view->subcell_views[i], - vbox_view->model_cols[i], view_col, row); - e_cell_draw ( - vbox_view->subcell_views[i], cr, - vbox_view->model_cols[i], view_col, row, flags, - x1, y1 + subcell_offset, x2, - y1 + subcell_offset + height); - - subcell_offset += e_cell_height ( - vbox_view->subcell_views[i], - vbox_view->model_cols[i], view_col, row); - } -} - -/* - * ECell::event method - */ -static gint -ecv_event (ECellView *ecell_view, - GdkEvent *event, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - ECellActions *actions) -{ - ECellVboxView *vbox_view = (ECellVboxView *) ecell_view; - gint y = 0; - gint i; - gint subcell_offset = 0; - - switch (event->type) { - case GDK_BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - y = event->button.y; - break; - case GDK_MOTION_NOTIFY: - y = event->motion.y; - break; - default: - /* nada */ - break; - } - - for (i = 0; i < vbox_view->subcell_view_count; i++) { - gint height = e_cell_height (vbox_view->subcell_views[i], vbox_view->model_cols[i], view_col, row); - if (y < subcell_offset + height) - return e_cell_event (vbox_view->subcell_views[i], event, vbox_view->model_cols[i], view_col, row, flags, actions); - subcell_offset += height; - } - return 0; -} - -/* - * ECell::height method - */ -static gint -ecv_height (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row) -{ - ECellVboxView *vbox_view = (ECellVboxView *) ecell_view; - gint height = 0; - gint i; - - for (i = 0; i < vbox_view->subcell_view_count; i++) { - height += e_cell_height (vbox_view->subcell_views[i], vbox_view->model_cols[i], view_col, row); - } - return height; -} - -/* - * ECell::max_width method - */ -static gint -ecv_max_width (ECellView *ecell_view, - gint model_col, - gint view_col) -{ - ECellVboxView *vbox_view = (ECellVboxView *) ecell_view; - gint max_width = 0; - gint i; - - for (i = 0; i < vbox_view->subcell_view_count; i++) { - gint width = e_cell_max_width (vbox_view->subcell_views[i], vbox_view->model_cols[i], view_col); - max_width = MAX (width, max_width); - } - - return max_width; -} - -/* - * GObject::dispose method - */ -static void -ecv_dispose (GObject *object) -{ - ECellVbox *ecv = E_CELL_VBOX (object); - gint i; - - /* destroy our subcell */ - for (i = 0; i < ecv->subcell_count; i++) - if (ecv->subcells[i]) - g_object_unref (ecv->subcells[i]); - g_free (ecv->subcells); - ecv->subcells = NULL; - ecv->subcell_count = 0; - - G_OBJECT_CLASS (e_cell_vbox_parent_class)->dispose (object); -} - -static void -ecv_finalize (GObject *object) -{ - ECellVbox *ecv = E_CELL_VBOX (object); - - g_free (ecv->model_cols); - - G_OBJECT_CLASS (e_cell_vbox_parent_class)->finalize (object); -} - -static void -e_cell_vbox_class_init (ECellVboxClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - ECellClass *ecc = E_CELL_CLASS (class); - - object_class->dispose = ecv_dispose; - object_class->finalize = ecv_finalize; - - ecc->new_view = ecv_new_view; - ecc->kill_view = ecv_kill_view; - ecc->realize = ecv_realize; - ecc->unrealize = ecv_unrealize; - ecc->draw = ecv_draw; - ecc->event = ecv_event; - ecc->height = ecv_height; - ecc->max_width = ecv_max_width; - - gal_a11y_e_cell_registry_add_cell_type (NULL, E_TYPE_CELL_VBOX, gal_a11y_e_cell_vbox_new); -} - -static void -e_cell_vbox_init (ECellVbox *ecv) -{ - ecv->subcells = NULL; - ecv->subcell_count = 0; -} - -/** - * e_cell_vbox_new: - * - * Creates a new ECell renderer that can be used to render multiple - * child cells. - * - * Return value: an ECell object that can be used to render multiple - * child cells. - **/ -ECell * -e_cell_vbox_new (void) -{ - return g_object_new (E_TYPE_CELL_VBOX, NULL); -} - -void -e_cell_vbox_append (ECellVbox *vbox, - ECell *subcell, - gint model_col) -{ - vbox->subcell_count++; - - vbox->subcells = g_renew (ECell *, vbox->subcells, vbox->subcell_count); - vbox->model_cols = g_renew (int, vbox->model_cols, vbox->subcell_count); - - vbox->subcells[vbox->subcell_count - 1] = subcell; - vbox->model_cols[vbox->subcell_count - 1] = model_col; - - if (subcell) - g_object_ref_sink (subcell); -} diff --git a/widgets/table/e-cell-vbox.h b/widgets/table/e-cell-vbox.h deleted file mode 100644 index 2ab522c4ae..0000000000 --- a/widgets/table/e-cell-vbox.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Toshok <toshok@ximian.com> - * Chris Lahey <clahey@ximina.com - * - * A majority of code taken from: - * the ECellText renderer. - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_CELL_VBOX_H_ -#define _E_CELL_VBOX_H_ - -#include <libgnomecanvas/libgnomecanvas.h> -#include <table/e-cell.h> - -/* Standard GObject macros */ -#define E_TYPE_CELL_VBOX \ - (e_cell_vbox_get_type ()) -#define E_CELL_VBOX(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_CELL_VBOX, ECellVbox)) -#define E_CELL_VBOX_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_CELL_VBOX, ECellVboxClass)) -#define E_IS_CELL_VBOX(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_CELL_VBOX)) -#define E_IS_CELL_VBOX_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_CELL_VBOX)) -#define E_CELL_VBOX_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_CELL_VBOX, ECellVboxClass)) - -G_BEGIN_DECLS - -typedef struct _ECellVbox ECellVbox; -typedef struct _ECellVboxView ECellVboxView; -typedef struct _ECellVboxClass ECellVboxClass; - -struct _ECellVbox { - ECell parent; - - gint subcell_count; - ECell **subcells; - gint *model_cols; -}; - -struct _ECellVboxView { - ECellView cell_view; - - gint subcell_view_count; - ECellView **subcell_views; - gint *model_cols; -}; - -struct _ECellVboxClass { - ECellClass parent_class; -}; - -GType e_cell_vbox_get_type (void) G_GNUC_CONST; -ECell * e_cell_vbox_new (void); -void e_cell_vbox_append (ECellVbox *vbox, - ECell *subcell, - gint model_col); - -G_END_DECLS - -#endif /* _E_CELL_VBOX_H_ */ diff --git a/widgets/table/e-cell.c b/widgets/table/e-cell.c deleted file mode 100644 index b9b96eecb0..0000000000 --- a/widgets/table/e-cell.c +++ /dev/null @@ -1,680 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Miguel de Icaza <miguel@ximian.com> - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtk.h> -#include "e-util/e-util.h" - -#include "e-cell.h" - -G_DEFINE_TYPE (ECell, e_cell, G_TYPE_OBJECT) - -static ECellView * -ec_new_view (ECell *ecell, - ETableModel *table_model, - gpointer 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, - cairo_t *cr, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - gint x1, - gint y1, - gint x2, - gint y2) -{ - g_critical ("e-cell-draw invoked"); -} - -static gint -ec_event (ECellView *ecell_view, - GdkEvent *event, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - ECellActions *actions) -{ - g_critical ("e-cell-event invoked"); - - return 0; -} - -static gint -ec_height (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row) -{ - g_critical ("e-cell-height invoked"); - - return 0; -} - -static void -ec_focus (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gint x1, - gint y1, - gint x2, - gint 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 gpointer -ec_enter_edit (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row) -{ - return NULL; -} - -static void -ec_leave_edit (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gpointer context) -{ -} - -static gpointer -ec_save_state (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gpointer context) -{ - return NULL; -} - -static void -ec_load_state (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gpointer context, - gpointer save_state) -{ -} - -static void -ec_free_state (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gpointer save_state) -{ -} - -static void -e_cell_class_init (ECellClass *class) -{ - class->realize = ec_realize; - class->unrealize = ec_unrealize; - class->new_view = ec_new_view; - class->kill_view = ec_kill_view; - class->draw = ec_draw; - class->event = ec_event; - class->focus = ec_focus; - class->unfocus = ec_unfocus; - class->height = ec_height; - class->enter_edit = ec_enter_edit; - class->leave_edit = ec_leave_edit; - class->save_state = ec_save_state; - class->load_state = ec_load_state; - class->free_state = ec_free_state; - class->print = NULL; - class->print_height = NULL; - class->max_width = NULL; - class->max_width_by_row = NULL; -} - -static void -e_cell_init (ECell *cell) -{ -} - -/** - * 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, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - ECellActions *actions) -{ - ECellClass *class; - - class = E_CELL_GET_CLASS (ecell_view->ecell); - - return class->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, - gpointer e_table_item_view) -{ - return E_CELL_GET_CLASS (ecell)->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) -{ - ECellClass *class; - - class = E_CELL_GET_CLASS (ecell_view->ecell); - g_return_if_fail (class->realize != NULL); - - class->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) -{ - ECellClass *class; - - class = E_CELL_GET_CLASS (ecell_view->ecell); - g_return_if_fail (class->kill_view != NULL); - - class->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) -{ - ECellClass *class; - - class = E_CELL_GET_CLASS (ecell_view->ecell); - g_return_if_fail (class->unrealize != NULL); - - class->unrealize (ecell_view); -} - -/** - * e_cell_draw: - * @ecell_view: the ECellView to redraw - * @cr: a Cairo context - * @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 Cairo context. - * 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, - cairo_t *cr, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - gint x1, - gint y1, - gint x2, - gint y2) -{ - ECellClass *class; - - 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)); - - class = E_CELL_GET_CLASS (ecell_view->ecell); - g_return_if_fail (class->draw != NULL); - - cairo_save (cr); - - class->draw ( - ecell_view, cr, - model_col, view_col, - row, flags, x1, y1, x2, y2); - - cairo_restore (cr); -} - -/** - * e_cell_print: - * @ecell_view: the ECellView to redraw - * @context: The GtkPrintContext 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, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width, - gdouble height) -{ - ECellClass *class; - - class = E_CELL_GET_CLASS (ecell_view->ecell); - - if (class->print != NULL) - class->print ( - ecell_view, context, - model_col, view_col, - row, width, height); -} - -/** - * e_cell_print: - * - * FIXME: - */ -gdouble -e_cell_print_height (ECellView *ecell_view, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width) -{ - ECellClass *class; - - class = E_CELL_GET_CLASS (ecell_view->ecell); - - if (class->print_height == NULL) - return 0.0; - - return class->print_height ( - ecell_view, context, - model_col, view_col, - row, width); -} - -/** - * 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. - */ -gint -e_cell_height (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row) -{ - ECellClass *class; - - class = E_CELL_GET_CLASS (ecell_view->ecell); - g_return_val_if_fail (class->height != NULL, 0); - - return class->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. - */ -gpointer -e_cell_enter_edit (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row) -{ - ECellClass *class; - - class = E_CELL_GET_CLASS (ecell_view->ecell); - g_return_val_if_fail (class->enter_edit != NULL, NULL); - - return class->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, - gint model_col, - gint view_col, - gint row, - gpointer edit_context) -{ - ECellClass *class; - - class = E_CELL_GET_CLASS (ecell_view->ecell); - g_return_if_fail (class->leave_edit != NULL); - - class->leave_edit (ecell_view, model_col, view_col, row, edit_context); -} - -/** - * e_cell_save_state: - * @ecell_view: the ECellView to save - * @model_col: the column in the model - * @view_col: the column in the view - * @row: the row - * @edit_context: the editing context - * - * Returns: The save state. - * - * Requests that the ECellView return a gpointer representing the state - * of the ECell. This is primarily intended for things like selection - * or scrolling. - */ -gpointer -e_cell_save_state (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gpointer edit_context) -{ - ECellClass *class; - - class = E_CELL_GET_CLASS (ecell_view->ecell); - - if (class->save_state == NULL) - return NULL; - - return class->save_state ( - ecell_view, model_col, view_col, row, edit_context); -} - -/** - * e_cell_load_state: - * @ecell_view: the ECellView to load - * @model_col: the column in the model - * @view_col: the column in the view - * @row: the row - * @edit_context: the editing context - * @save_state: the save state to load from - * - * Requests that the ECellView load from the given save state. - */ -void -e_cell_load_state (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gpointer edit_context, - gpointer save_state) -{ - ECellClass *class; - - class = E_CELL_GET_CLASS (ecell_view->ecell); - - if (class->load_state != NULL) - class->load_state ( - ecell_view, model_col, view_col, - row, edit_context, save_state); -} - -/** - * e_cell_free_state: - * @ecell_view: the ECellView - * @model_col: the column in the model - * @view_col: the column in the view - * @row: the row - * @edit_context: the editing context - * @save_state: the save state to free - * - * Requests that the ECellView free the given save state. - */ -void -e_cell_free_state (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gpointer save_state) -{ - ECellClass *class; - - class = E_CELL_GET_CLASS (ecell_view->ecell); - - if (class->free_state != NULL) - class->free_state ( - ecell_view, model_col, view_col, row, save_state); -} - -/** - * 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 - */ -gint -e_cell_max_width (ECellView *ecell_view, - gint model_col, - gint view_col) -{ - ECellClass *class; - - class = E_CELL_GET_CLASS (ecell_view->ecell); - g_return_val_if_fail (class->max_width != NULL, 0); - - return class->max_width (ecell_view, model_col, view_col); -} - -/** - * e_cell_max_width_by_row: - * @ecell_view: the ECellView that we are curious about - * @model_col: the column in the model - * @view_col: the column in the view. - * @row: The row in the model. - * - * Returns: the maximum width for the ECellview at @model_col which - * is being rendered as @view_col for the data in @row. - */ -gint -e_cell_max_width_by_row (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row) -{ - ECellClass *class; - - class = E_CELL_GET_CLASS (ecell_view->ecell); - - if (class->max_width_by_row == NULL) - return e_cell_max_width (ecell_view, model_col, view_col); - - return class->max_width_by_row (ecell_view, model_col, view_col, row); -} - -/** - * e_cell_max_width_by_row_implemented: - * @ecell_view: the ECellView that we are curious about - * @model_col: the column in the model - * @view_col: the column in the view. - * @row: The row in the model. - * - * Returns: the maximum width for the ECellview at @model_col which - * is being rendered as @view_col for the data in @row. - */ -gboolean -e_cell_max_width_by_row_implemented (ECellView *ecell_view) -{ - ECellClass *class; - - class = E_CELL_GET_CLASS (ecell_view->ecell); - - return (class->max_width_by_row != NULL); -} - -gchar * -e_cell_get_bg_color (ECellView *ecell_view, - gint row) -{ - ECellClass *class; - - class = E_CELL_GET_CLASS (ecell_view->ecell); - - if (class->get_bg_color == NULL) - return NULL; - - return class->get_bg_color (ecell_view, row); -} - -void -e_cell_style_set (ECellView *ecell_view, - GtkStyle *previous_style) -{ - ECellClass *class; - - class = E_CELL_GET_CLASS (ecell_view->ecell); - - if (class->style_set != NULL) - class->style_set (ecell_view, previous_style); -} - diff --git a/widgets/table/e-cell.h b/widgets/table/e-cell.h deleted file mode 100644 index 38fcc68c32..0000000000 --- a/widgets/table/e-cell.h +++ /dev/null @@ -1,294 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Miguel de Icaza <miguel@ximian.com> - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_CELL_H_ -#define _E_CELL_H_ - -#include <gtk/gtk.h> -#include <table/e-table-model.h> - -/* Standard GObject macros */ -#define E_TYPE_CELL \ - (e_cell_get_type ()) -#define E_CELL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_CELL, ECell)) -#define E_CELL_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_CELL, ECellClass)) -#define E_CELL_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_CELL, ECellClass)) -#define E_IS_CELL(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_CELL)) -#define E_IS_CELL_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_CELL)) -#define E_CELL_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_CELL, ECellClass)) - -G_BEGIN_DECLS - -typedef struct _ECell ECell; -typedef struct _ECellClass ECellClass; -typedef struct _ECellView ECellView; - -typedef gboolean (*ETableSearchFunc) (gconstpointer haystack, - const gchar *needle); - -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, - - E_CELL_CURSOR = 1 << 5, - - E_CELL_PREEDIT = 1 << 6 -} ECellFlags; - -typedef enum { - E_CELL_GRAB = 1 << 0, - E_CELL_UNGRAB = 1 << 1 -} ECellActions; - -struct _ECellView { - 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; - - void (*kill_view_cb) (struct _ECellView *, gpointer); - GList *kill_view_cb_data; -}; - -#define E_CELL_IS_FOCUSED(ecell_view) (ecell_view->focus_x1 != -1) - -struct _ECell { - GObject parent; -}; - -struct _ECellClass { - GObjectClass parent_class; - - ECellView * (*new_view) (ECell *ecell, - ETableModel *table_model, - gpointer 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, - cairo_t *cr, - gint model_col, - gint view_col, gint row, - ECellFlags flags, - gint x1, - gint y1, - gint x2, - gint y2); - gint (*event) (ECellView *ecell_view, - GdkEvent *event, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - ECellActions *actions); - void (*focus) (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gint x1, - gint y1, - gint x2, - gint y2); - void (*unfocus) (ECellView *ecell_view); - gint (*height) (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row); - - gpointer (*enter_edit) (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row); - void (*leave_edit) (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gpointer context); - gpointer (*save_state) (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gpointer context); - void (*load_state) (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gpointer context, - gpointer save_state); - void (*free_state) (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gpointer save_state); - void (*print) (ECellView *ecell_view, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width, - gdouble height); - gdouble (*print_height) (ECellView *ecell_view, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width); - gint (*max_width) (ECellView *ecell_view, - gint model_col, - gint view_col); - gint (*max_width_by_row) (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row); - gchar * (*get_bg_color) (ECellView *ecell_view, - gint row); - - void (*style_set) (ECellView *ecell_view, - GtkStyle *previous_style); -}; - -GType e_cell_get_type (void) G_GNUC_CONST; - -/* View creation methods. */ -ECellView * e_cell_new_view (ECell *ecell, - ETableModel *table_model, - gpointer e_table_item_view); -void e_cell_kill_view (ECellView *ecell_view); - -/* Cell View methods. */ -gint e_cell_event (ECellView *ecell_view, - GdkEvent *event, - gint model_col, - gint view_col, - gint 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, - cairo_t *cr, - gint model_col, - gint view_col, - gint row, - ECellFlags flags, - gint x1, - gint y1, - gint x2, - gint y2); -void e_cell_print (ECellView *ecell_view, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width, - gdouble height); -gdouble e_cell_print_height (ECellView *ecell_view, - GtkPrintContext *context, - gint model_col, - gint view_col, - gint row, - gdouble width); -gint e_cell_max_width (ECellView *ecell_view, - gint model_col, - gint view_col); -gint e_cell_max_width_by_row (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row); -gboolean e_cell_max_width_by_row_implemented - (ECellView *ecell_view); -gchar * e_cell_get_bg_color (ECellView *ecell_view, - gint row); -void e_cell_style_set (ECellView *ecell_view, - GtkStyle *previous_style); - -void e_cell_focus (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gint x1, - gint y1, - gint x2, - gint y2); -void e_cell_unfocus (ECellView *ecell_view); -gint e_cell_height (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row); -gpointer e_cell_enter_edit (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row); -void e_cell_leave_edit (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gpointer edit_context); -gpointer e_cell_save_state (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gpointer edit_context); -void e_cell_load_state (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gpointer edit_context, - gpointer state); -void e_cell_free_state (ECellView *ecell_view, - gint model_col, - gint view_col, - gint row, - gpointer state); - -G_END_DECLS - -#endif /* _E_CELL_H_ */ diff --git a/widgets/table/e-popup-menu.c b/widgets/table/e-popup-menu.c deleted file mode 100644 index 3e82496748..0000000000 --- a/widgets/table/e-popup-menu.c +++ /dev/null @@ -1,112 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Miguel de Icaza <miguel@ximian.com> - * Jody Goldberg (jgoldberg@home.com) - * Jeffrey Stedfast <fejj@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <libintl.h> -#include <string.h> - -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> - -#include "e-popup-menu.h" - -/* - * Creates an item with an optional icon - */ -static void -make_item (GtkMenu *menu, - GtkMenuItem *item, - const gchar *name) -{ - GtkWidget *label; - - if (*name == '\0') - return; - - /* - * Ugh. This needs to go into Gtk+ - */ - label = gtk_label_new_with_mnemonic (name); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_widget_show (label); - - gtk_container_add (GTK_CONTAINER (item), label); -} - -GtkMenu * -e_popup_menu_create_with_domain (EPopupMenu *menu_list, - guint32 disable_mask, - guint32 hide_mask, - gpointer default_closure, - const gchar *domain) -{ - GtkMenu *menu = GTK_MENU (gtk_menu_new ()); - gboolean last_item_separator = TRUE; - gint last_non_separator = -1; - gint i; - - for (i = 0; menu_list[i].name; i++) { - if (strcmp ("", menu_list[i].name) && !(menu_list[i].disable_mask & hide_mask)) { - last_non_separator = i; - } - } - - for (i = 0; i <= last_non_separator; i++) { - gboolean separator; - - separator = !strcmp ("", menu_list[i].name); - - if ((!(separator && last_item_separator)) && !(menu_list[i].disable_mask & hide_mask)) { - GtkWidget *item = NULL; - - if (!separator) { - item = gtk_menu_item_new (); - - make_item (menu, GTK_MENU_ITEM (item), dgettext (domain, menu_list[i].name)); - } else { - item = gtk_menu_item_new (); - } - - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - - if (menu_list[i].fn) - g_signal_connect ( - item, "activate", - G_CALLBACK (menu_list[i].fn), - default_closure); - - if (menu_list[i].disable_mask & disable_mask) - gtk_widget_set_sensitive (item, FALSE); - - gtk_widget_show (item); - - last_item_separator = separator; - } - } - - return menu; -} diff --git a/widgets/table/e-popup-menu.h b/widgets/table/e-popup-menu.h deleted file mode 100644 index 9fd3616eb2..0000000000 --- a/widgets/table/e-popup-menu.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Miguel de Icaza <miguel@ximian.com> - * Jody Goldberg (jgoldberg@home.com) - * Jeffrey Stedfast <fejj@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_POPUP_MENU_H -#define E_POPUP_MENU_H - -#include <gtk/gtk.h> - -G_BEGIN_DECLS - -#define E_POPUP_SEPARATOR { (gchar *) "", NULL, (NULL), 0 } -#define E_POPUP_TERMINATOR { NULL, NULL, (NULL), 0 } - -#define E_POPUP_ITEM(name,fn,disable_mask) \ - { (gchar *) (name), NULL, (fn), (disable_mask) } - -typedef struct _EPopupMenu EPopupMenu; - -struct _EPopupMenu { - gchar *name; - gchar *pixname; - GCallback fn; - guint32 disable_mask; -}; - -GtkMenu * e_popup_menu_create_with_domain (EPopupMenu *menu_list, - guint32 disable_mask, - guint32 hide_mask, - gpointer default_closure, - const gchar *domain); - -G_END_DECLS - -#endif /* E_POPUP_MENU_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 b08d3fcf39..0000000000 --- a/widgets/table/e-table-click-to-add.c +++ /dev/null @@ -1,666 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> -#include <libgnomecanvas/libgnomecanvas.h> -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include "gal-a11y-e-table-click-to-add.h" -#include "text/e-text.h" -#include <glib/gi18n.h> -#include "e-util/e-util.h" -#include "misc/e-canvas-utils.h" -#include "misc/e-canvas.h" - -#include "e-table-click-to-add.h" -#include "e-table-defines.h" -#include "e-table-header.h" -#include "e-table-one.h" - -enum { - CURSOR_CHANGE, - STYLE_SET, - LAST_SIGNAL -}; - -static guint etcta_signals[LAST_SIGNAL] = { 0 }; - -/* workaround for avoiding APi breakage */ -#define etcta_get_type e_table_click_to_add_get_type -G_DEFINE_TYPE (ETableClickToAdd, etcta, GNOME_TYPE_CANVAS_GROUP) - -enum { - PROP_0, - PROP_HEADER, - PROP_MODEL, - PROP_MESSAGE, - PROP_WIDTH, - PROP_HEIGHT -}; - -static void -etcta_cursor_change (GObject *object, - gint row, - gint col, - ETableClickToAdd *etcta) -{ - g_signal_emit ( - etcta, - etcta_signals[CURSOR_CHANGE], 0, - row, col); -} - -static void -etcta_style_set (ETableClickToAdd *etcta, - GtkStyle *previous_style) -{ - GtkWidget *widget; - GtkStyle *style; - - widget = GTK_WIDGET (GNOME_CANVAS_ITEM (etcta)->canvas); - style = gtk_widget_get_style (widget); - - if (etcta->rect) - gnome_canvas_item_set ( - etcta->rect, - "outline_color_gdk", &style->fg[GTK_STATE_NORMAL], - "fill_color_gdk", &style->bg[GTK_STATE_NORMAL], - NULL); - - if (etcta->text) - gnome_canvas_item_set ( - etcta->text, - "fill_color_gdk", &style->text[GTK_STATE_NORMAL], - NULL); -} - -static void -etcta_add_table_header (ETableClickToAdd *etcta, - ETableHeader *header) -{ - etcta->eth = header; - if (etcta->eth) - g_object_ref (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) -{ - if (!etcta->eth) - return; - - g_object_unref (etcta->eth); - etcta->eth = NULL; -} - -static void -etcta_add_one (ETableClickToAdd *etcta, - ETableModel *one) -{ - etcta->one = one; - if (etcta->one) - g_object_ref (etcta->one); - if (etcta->row) - gnome_canvas_item_set ( - GNOME_CANVAS_ITEM (etcta->row), - "ETableModel", one, - NULL); - g_object_set ( - etcta->selection, - "model", one, - NULL); -} - -static void -etcta_drop_one (ETableClickToAdd *etcta) -{ - if (!etcta->one) - return; - g_object_unref (etcta->one); - etcta->one = NULL; - g_object_set ( - etcta->selection, - "model", NULL, - NULL); -} - -static void -etcta_add_model (ETableClickToAdd *etcta, - ETableModel *model) -{ - etcta->model = model; - if (etcta->model) - g_object_ref (etcta->model); -} - -static void -etcta_drop_model (ETableClickToAdd *etcta) -{ - etcta_drop_one (etcta); - if (!etcta->model) - return; - g_object_unref (etcta->model); - etcta->model = NULL; -} - -static void -etcta_add_message (ETableClickToAdd *etcta, - const gchar *message) -{ - etcta->message = g_strdup (message); -} - -static void -etcta_drop_message (ETableClickToAdd *etcta) -{ - g_free (etcta->message); - etcta->message = NULL; -} - -static void -etcta_dispose (GObject *object) -{ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (object); - - etcta_drop_table_header (etcta); - etcta_drop_model (etcta); - etcta_drop_message (etcta); - if (etcta->selection) - g_object_unref (etcta->selection); - etcta->selection = NULL; - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (etcta_parent_class)->dispose (object); -} - -static void -etcta_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - GnomeCanvasItem *item; - ETableClickToAdd *etcta; - - item = GNOME_CANVAS_ITEM (object); - etcta = E_TABLE_CLICK_TO_ADD (object); - - switch (property_id) { - case PROP_HEADER: - etcta_drop_table_header (etcta); - etcta_add_table_header (etcta, E_TABLE_HEADER (g_value_get_object (value))); - break; - case PROP_MODEL: - etcta_drop_model (etcta); - etcta_add_model (etcta, E_TABLE_MODEL (g_value_get_object (value))); - break; - case PROP_MESSAGE: - etcta_drop_message (etcta); - etcta_add_message (etcta, g_value_get_string (value)); - break; - case PROP_WIDTH: - etcta->width = g_value_get_double (value); - 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 ? 4 : etcta->width) - 4, - NULL); - if (etcta->rect) - gnome_canvas_item_set ( - etcta->rect, - "x2", etcta->width - 1, - NULL); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - return; - - } - gnome_canvas_item_request_update (item); -} - -static void -create_rect_and_text (ETableClickToAdd *etcta) -{ - GtkWidget *widget; - GtkStyle *style; - - widget = GTK_WIDGET (GNOME_CANVAS_ITEM (etcta)->canvas); - style = gtk_widget_get_style (widget); - - if (!etcta->rect) - etcta->rect = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (etcta), - gnome_canvas_rect_get_type (), - "x1", (gdouble) 0, - "y1", (gdouble) 0, - "x2", (gdouble) etcta->width - 1, - "y2", (gdouble) etcta->height - 1, - "outline_color_gdk", &style->fg[GTK_STATE_NORMAL], - "fill_color_gdk", &style->bg[GTK_STATE_NORMAL], - NULL); - - if (!etcta->text) - etcta->text = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (etcta), - e_text_get_type (), - "text", etcta->message ? etcta->message : "", - "width", etcta->width - 4, - "fill_color_gdk", &style->text[GTK_STATE_NORMAL], - NULL); -} - -static void -etcta_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ETableClickToAdd *etcta; - - etcta = E_TABLE_CLICK_TO_ADD (object); - - switch (property_id) { - case PROP_HEADER: - g_value_set_object (value, etcta->eth); - break; - case PROP_MODEL: - g_value_set_object (value, etcta->model); - break; - case PROP_MESSAGE: - g_value_set_string (value, etcta->message); - break; - case PROP_WIDTH: - g_value_set_double (value, etcta->width); - break; - case PROP_HEIGHT: - g_value_set_double (value, etcta->height); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -etcta_realize (GnomeCanvasItem *item) -{ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item); - - create_rect_and_text (etcta); - 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); - - e_canvas_item_request_reflow (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 void finish_editing (ETableClickToAdd *etcta); - -static gint -item_key_press (ETableItem *item, - gint row, - gint col, - GdkEvent *event, - ETableClickToAdd *etcta) -{ - switch (event->key.keyval) { - case GDK_KEY_Return: - case GDK_KEY_KP_Enter: - case GDK_KEY_ISO_Enter: - case GDK_KEY_3270_Enter: - finish_editing (etcta); - return TRUE; - } - return FALSE; -} - -static void -set_initial_selection (ETableClickToAdd *etcta) -{ - e_selection_model_do_something ( - E_SELECTION_MODEL (etcta->selection), - 0, e_table_header_prioritized_column (etcta->eth), - 0); -} - -static void -finish_editing (ETableClickToAdd *etcta) -{ - if (etcta->row) { - ETableModel *one; - - e_table_item_leave_edit (E_TABLE_ITEM (etcta->row)); - e_table_one_commit (E_TABLE_ONE (etcta->one)); - etcta_drop_one (etcta); - g_object_run_dispose (G_OBJECT (etcta->row)); - etcta->row = NULL; - - one = e_table_one_new (etcta->model); - etcta_add_one (etcta, one); - g_object_unref (one); - - e_selection_model_clear (E_SELECTION_MODEL (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, - "horizontal_draw_grid", TRUE, - "vertical_draw_grid", TRUE, - "selection_model", etcta->selection, - "cursor_mode", E_CURSOR_SPREADSHEET, - NULL); - - g_signal_connect ( - etcta->row, "key_press", - G_CALLBACK (item_key_press), etcta); - - set_initial_selection (etcta); - } -} - -/* Handles the events on the ETableClickToAdd, particularly - * it creates the ETableItem and passes in some events. */ -static gint -etcta_event (GnomeCanvasItem *item, - GdkEvent *e) -{ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item); - - switch (e->type) { - case GDK_FOCUS_CHANGE: - if (!e->focus_change.in) - return TRUE; - - case GDK_BUTTON_PRESS: - if (etcta->text) { - g_object_run_dispose (G_OBJECT (etcta->text)); - etcta->text = NULL; - } - if (etcta->rect) { - g_object_run_dispose (G_OBJECT (etcta->rect)); - etcta->rect = NULL; - } - if (!etcta->row) { - ETableModel *one; - - one = e_table_one_new (etcta->model); - etcta_add_one (etcta, one); - g_object_unref (one); - - e_selection_model_clear (E_SELECTION_MODEL (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, - "horizontal_draw_grid", TRUE, - "vertical_draw_grid", TRUE, - "selection_model", etcta->selection, - "cursor_mode", E_CURSOR_SPREADSHEET, - NULL); - - g_signal_connect ( - etcta->row, "key_press", - G_CALLBACK (item_key_press), etcta); - - e_canvas_item_grab_focus (GNOME_CANVAS_ITEM (etcta->row), TRUE); - - set_initial_selection (etcta); - } - break; - - case GDK_KEY_PRESS: - switch (e->key.keyval) { - case GDK_KEY_Tab: - case GDK_KEY_KP_Tab: - case GDK_KEY_ISO_Left_Tab: - finish_editing (etcta); - break; - default: - return FALSE; - case GDK_KEY_Escape: - if (etcta->row) { - e_table_item_leave_edit (E_TABLE_ITEM (etcta->row)); - etcta_drop_one (etcta); - g_object_run_dispose (G_OBJECT (etcta->row)); - etcta->row = NULL; - create_rect_and_text (etcta); - e_canvas_item_move_absolute (etcta->text, 3, 3); - } - break; - } - break; - - default: - return FALSE; - } - return TRUE; -} - -static void -etcta_reflow (GnomeCanvasItem *item, - gint flags) -{ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item); - - gdouble old_height = etcta->height; - - if (etcta->text) { - g_object_get ( - etcta->text, - "height", &etcta->height, - NULL); - etcta->height += 6; - } - if (etcta->row) { - g_object_get ( - etcta->row, - "height", &etcta->height, - NULL); - } - - if (etcta->rect) { - g_object_set ( - 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 *class) -{ - GnomeCanvasItemClass *item_class = GNOME_CANVAS_ITEM_CLASS (class); - GObjectClass *object_class = G_OBJECT_CLASS (class); - - class->cursor_change = NULL; - class->style_set = etcta_style_set; - - object_class->dispose = etcta_dispose; - object_class->set_property = etcta_set_property; - object_class->get_property = etcta_get_property; - - item_class->realize = etcta_realize; - item_class->unrealize = etcta_unrealize; - item_class->event = etcta_event; - - g_object_class_install_property ( - object_class, - PROP_HEADER, - g_param_spec_object ( - "header", - "Header", - NULL, - E_TYPE_TABLE_HEADER, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_MODEL, - g_param_spec_object ( - "model", - "Model", - NULL, - E_TYPE_TABLE_MODEL, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_MESSAGE, - g_param_spec_string ( - "message", - "Message", - NULL, - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_WIDTH, - g_param_spec_double ( - "width", - "Width", - NULL, - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE | - G_PARAM_LAX_VALIDATION)); - - g_object_class_install_property ( - object_class, - PROP_HEIGHT, - g_param_spec_double ( - "height", - "Height", - NULL, - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READABLE | - G_PARAM_LAX_VALIDATION)); - - etcta_signals[CURSOR_CHANGE] = g_signal_new ( - "cursor_change", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClickToAddClass, cursor_change), - NULL, NULL, - e_marshal_VOID__INT_INT, - G_TYPE_NONE, 2, - G_TYPE_INT, - G_TYPE_INT); - - etcta_signals[STYLE_SET] = g_signal_new ( - "style_set", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClickToAddClass, style_set), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - GTK_TYPE_STYLE); - - gal_a11y_e_table_click_to_add_init (); -} - -static void -etcta_init (ETableClickToAdd *etcta) -{ - AtkObject *a11y; - - etcta->one = NULL; - etcta->model = NULL; - etcta->eth = NULL; - - etcta->message = NULL; - - etcta->row = NULL; - etcta->text = NULL; - etcta->rect = NULL; - - /* Pick some arbitrary defaults. */ - etcta->width = 12; - etcta->height = 6; - - etcta->selection = e_table_selection_model_new (); - g_signal_connect ( - etcta->selection, "cursor_changed", - G_CALLBACK (etcta_cursor_change), etcta); - - e_canvas_item_set_reflow_callback (GNOME_CANVAS_ITEM (etcta), etcta_reflow); - - /* create its a11y object at this time if accessibility is enabled*/ - if (atk_get_root () != NULL) { - a11y = atk_gobject_accessible_for_object (G_OBJECT (etcta)); - atk_object_set_name (a11y, _("click to add")); - } -} - -/* 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); - g_object_run_dispose (G_OBJECT (etcta->row)); - etcta->row = NULL; - } - create_rect_and_text (etcta); - 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 b92672d387..0000000000 --- a/widgets/table/e-table-click-to-add.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_CLICK_TO_ADD_H_ -#define _E_TABLE_CLICK_TO_ADD_H_ - -#include <libxml/tree.h> -#include <libgnomecanvas/libgnomecanvas.h> -#include <table/e-table-header.h> -#include <table/e-table-sort-info.h> -#include <table/e-table-item.h> -#include <table/e-table-selection-model.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_CLICK_TO_ADD \ - (e_table_click_to_add_get_type ()) -#define E_TABLE_CLICK_TO_ADD(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_CLICK_TO_ADD, ETableClickToAdd)) -#define E_TABLE_CLICK_TO_ADD_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_CLICK_TO_ADD, ETableClickToAddClass)) -#define E_IS_TABLE_CLICK_TO_ADD(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_CLICK_TO_ADD)) -#define E_IS_TABLE_CLICK_TO_ADD_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_CLICK_TO_ADD)) -#define E_TABLE_CLICK_TO_ADD_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_CLICK_TO_ADD, ETableClickToAddClass)) - -G_BEGIN_DECLS - -typedef struct _ETableClickToAdd ETableClickToAdd; -typedef struct _ETableClickToAddClass ETableClickToAddClass; - -struct _ETableClickToAdd { - GnomeCanvasGroup parent; - - ETableModel *one; /* The ETableOne. */ - - ETableModel *model; /* The backend model. */ - ETableHeader *eth; /* This is just to give to the ETableItem. */ - - gchar *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; -}; - -struct _ETableClickToAddClass { - GnomeCanvasGroupClass parent_class; - - /* Signals */ - void (*cursor_change) (ETableClickToAdd *etcta, - gint row, - gint col); - void (*style_set) (ETableClickToAdd *etcta, - GtkStyle *previous_style); -}; - -GType e_table_click_to_add_get_type (void) G_GNUC_CONST; -void e_table_click_to_add_commit (ETableClickToAdd *etcta); - -G_END_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 100a4d94d9..0000000000 --- a/widgets/table/e-table-col-dnd.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_COL_DND_H_ -#define _E_TABLE_COL_DND_H_ - -#include <glib.h> - -G_BEGIN_DECLS - -#define TARGET_ETABLE_COL_TYPE "application/x-etable-column-header" - -enum { - TARGET_ETABLE_COL_HEADER -}; - -G_END_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 823aba415d..0000000000 --- a/widgets/table/e-table-col.c +++ /dev/null @@ -1,223 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Miguel de Icaza <miguel@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib/gi18n.h> -#include "e-util/e-util.h" - -#include "e-table-col.h" - -G_DEFINE_TYPE (ETableCol, e_table_col, G_TYPE_OBJECT) - -enum { - PROP_0, - PROP_COMPARE_COL -}; - -static void -etc_load_icon (ETableCol *etc) -{ - /* FIXME This ignores theme changes. */ - - GtkIconTheme *icon_theme; - gint width, height; - GError *error = NULL; - - icon_theme = gtk_icon_theme_get_default (); - gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &width, &height); - - etc->pixbuf = gtk_icon_theme_load_icon ( - icon_theme, etc->icon_name, height, 0, &error); - - if (error != NULL) { - g_warning ("%s", error->message); - g_error_free (error); - } -} - -static void -etc_dispose (GObject *object) -{ - ETableCol *etc = E_TABLE_COL (object); - - if (etc->ecell) - g_object_unref (etc->ecell); - etc->ecell = NULL; - - if (etc->pixbuf) - g_object_unref (etc->pixbuf); - etc->pixbuf = NULL; - - g_free (etc->text); - etc->text = NULL; - - g_free (etc->icon_name); - etc->icon_name = NULL; - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (e_table_col_parent_class)->dispose (object); -} - -static void -etc_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ETableCol *etc = E_TABLE_COL (object); - - switch (property_id) { - case PROP_COMPARE_COL: - etc->compare_col = g_value_get_int (value); - break; - default: - break; - } -} - -static void -etc_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ETableCol *etc = E_TABLE_COL (object); - - switch (property_id) { - case PROP_COMPARE_COL: - g_value_set_int (value, etc->compare_col); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -e_table_col_class_init (ETableColClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->dispose = etc_dispose; - object_class->set_property = etc_set_property; - object_class->get_property = etc_get_property; - - g_object_class_install_property ( - object_class, - PROP_COMPARE_COL, - g_param_spec_int ( - "compare_col", - "Width", - "Width", - 0, G_MAXINT, 0, - G_PARAM_READWRITE)); -} - -static void -e_table_col_init (ETableCol *etc) -{ - etc->width = 0; - etc->sortable = 1; - etc->groupable = 1; - etc->justification = GTK_JUSTIFY_LEFT; - etc->priority = 0; -} - -/** - * e_table_col_new: - * @col_idx: the column we represent in the model - * @text: a title for this column - * @icon_name: name of the icon to be used for the header, or %NULL - * @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 - * @priority: FIXME - * - * 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. - * - * Data passed to @compare can be (if not %NULL) a cmp_cache, which - * can be accessed by e_table_sorting_utils_add_to_cmp_cache() and - * e_table_sorting_utils_lookup_cmp_cache(). - * - * Returns: the newly created ETableCol object. - */ -ETableCol * -e_table_col_new (gint col_idx, - const gchar *text, - const gchar *icon_name, - gdouble expansion, - gint min_width, - ECell *ecell, - GCompareDataFunc compare, - gboolean resizable, - gboolean disabled, - gint priority) -{ - 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 = g_object_new (E_TYPE_TABLE_COL, NULL); - - etc->col_idx = col_idx; - etc->compare_col = col_idx; - etc->text = g_strdup (text); - etc->icon_name = g_strdup (icon_name); - etc->pixbuf = NULL; - etc->expansion = expansion; - etc->min_width = min_width; - etc->ecell = ecell; - etc->compare = compare; - etc->disabled = disabled; - etc->priority = priority; - - etc->selected = 0; - etc->resizable = resizable; - - g_object_ref (etc->ecell); - - if (etc->icon_name != NULL) - etc_load_icon (etc); - - return etc; -} diff --git a/widgets/table/e-table-col.h b/widgets/table/e-table-col.h deleted file mode 100644 index 042137b40a..0000000000 --- a/widgets/table/e-table-col.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Miguel de Icaza <miguel@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_TABLE_COL_H -#define E_TABLE_COL_H - -#include <gdk-pixbuf/gdk-pixbuf.h> -#include <table/e-cell.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_COL \ - (e_table_col_get_type ()) -#define E_TABLE_COL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_COL, ETableCol)) -#define E_TABLE_COL_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_COL, ETableColClass)) -#define E_IS_TABLE_COL(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_COL)) -#define E_IS_TABLE_COL_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_COL)) -#define E_TABLE_COL_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_COL, ETableColClass)) - -G_BEGIN_DECLS - -typedef enum { - E_TABLE_COL_ARROW_NONE = 0, - E_TABLE_COL_ARROW_UP, - E_TABLE_COL_ARROW_DOWN -} ETableColArrow; - -typedef struct _ETableCol ETableCol; -typedef struct _ETableColClass ETableColClass; - -/* - * Information about a single column - */ -struct _ETableCol { - GObject parent; - - gchar *text; - gchar *icon_name; - GdkPixbuf *pixbuf; - gint min_width; - gint width; - gdouble expansion; - gshort x; - GCompareDataFunc compare; - ETableSearchFunc search; - - guint selected : 1; - guint resizable : 1; - guint disabled : 1; - guint sortable : 1; - guint groupable : 1; - - gint col_idx; - gint compare_col; - gint priority; - - GtkJustification justification; - - ECell *ecell; -}; - -struct _ETableColClass { - GObjectClass parent_class; -}; - -GType e_table_col_get_type (void) G_GNUC_CONST; -ETableCol * e_table_col_new (gint col_idx, - const gchar *text, - const gchar *icon_name, - gdouble expansion, - gint min_width, - ECell *ecell, - GCompareDataFunc compare, - gboolean resizable, - gboolean disabled, - gint priority); - -G_END_DECLS - -#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 033b693073..0000000000 --- a/widgets/table/e-table-column-specification.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - * e-table-column-specification.c - Savable specification of a column. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> - -#include <libxml/parser.h> -#include <libxml/xmlmemory.h> - -#include "e-util/e-util.h" -#include "libevolution-utils/e-xml-utils.h" - -#include "e-table-column-specification.h" - -/* workaround for avoiding API breakage */ -#define etcs_get_type e_table_column_specification_get_type -G_DEFINE_TYPE (ETableColumnSpecification, etcs, G_TYPE_OBJECT) - -static void -free_strings (ETableColumnSpecification *etcs) -{ - g_free (etcs->title); - etcs->title = NULL; - g_free (etcs->pixbuf); - etcs->pixbuf = NULL; - g_free (etcs->cell); - etcs->cell = NULL; - g_free (etcs->compare); - etcs->compare = NULL; - g_free (etcs->search); - etcs->search = NULL; - g_free (etcs->sortable); - etcs->sortable = NULL; -} - -static void -etcs_finalize (GObject *object) -{ - ETableColumnSpecification *etcs = E_TABLE_COLUMN_SPECIFICATION (object); - - free_strings (etcs); - - G_OBJECT_CLASS (etcs_parent_class)->finalize (object); -} - -static void -etcs_class_init (ETableColumnSpecificationClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->finalize = etcs_finalize; -} - -static void -etcs_init (ETableColumnSpecification *specification) -{ - specification->model_col = 0; - specification->compare_col = 0; - specification->title = g_strdup (""); - specification->pixbuf = NULL; - - specification->expansion = 0; - specification->minimum_width = 0; - specification->resizable = FALSE; - specification->disabled = FALSE; - - specification->cell = NULL; - specification->compare = NULL; - specification->search = NULL; - specification->priority = 0; -} - -ETableColumnSpecification * -e_table_column_specification_new (void) -{ - return g_object_new (E_TYPE_TABLE_COLUMN_SPECIFICATION, NULL); -} - -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, (const guchar *)"model_col"); - etcs->compare_col = e_xml_get_integer_prop_by_name_with_default (node, (const guchar *)"compare_col", etcs->model_col); - etcs->title = e_xml_get_string_prop_by_name (node, (const guchar *)"_title"); - etcs->pixbuf = e_xml_get_string_prop_by_name (node, (const guchar *)"pixbuf"); - - etcs->expansion = e_xml_get_double_prop_by_name (node, (const guchar *)"expansion"); - etcs->minimum_width = e_xml_get_integer_prop_by_name (node, (const guchar *)"minimum_width"); - etcs->resizable = e_xml_get_bool_prop_by_name (node, (const guchar *)"resizable"); - etcs->disabled = e_xml_get_bool_prop_by_name (node, (const guchar *)"disabled"); - - etcs->cell = e_xml_get_string_prop_by_name (node, (const guchar *)"cell"); - etcs->compare = e_xml_get_string_prop_by_name (node, (const guchar *)"compare"); - etcs->search = e_xml_get_string_prop_by_name (node, (const guchar *)"search"); - etcs->sortable = e_xml_get_string_prop_by_name (node, (const guchar *)"sortable"); - etcs->priority = e_xml_get_integer_prop_by_name_with_default (node, (const guchar *)"priority", 0); - - 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, (const guchar *)"ETableColumn", NULL); - else - node = xmlNewNode (NULL, (const guchar *)"ETableColumn"); - - e_xml_set_integer_prop_by_name (node, (const guchar *)"model_col", specification->model_col); - if (specification->compare_col != specification->model_col) - e_xml_set_integer_prop_by_name (node, (const guchar *)"compare_col", specification->compare_col); - e_xml_set_string_prop_by_name (node, (const guchar *)"_title", specification->title); - e_xml_set_string_prop_by_name (node, (const guchar *)"pixbuf", specification->pixbuf); - - e_xml_set_double_prop_by_name (node, (const guchar *)"expansion", specification->expansion); - e_xml_set_integer_prop_by_name (node, (const guchar *)"minimum_width", specification->minimum_width); - e_xml_set_bool_prop_by_name (node, (const guchar *)"resizable", specification->resizable); - e_xml_set_bool_prop_by_name (node, (const guchar *)"disabled", specification->disabled); - - e_xml_set_string_prop_by_name (node, (const guchar *)"cell", specification->cell); - e_xml_set_string_prop_by_name (node, (const guchar *)"compare", specification->compare); - e_xml_set_string_prop_by_name (node, (const guchar *)"search", specification->search); - if (specification->priority != 0) - e_xml_set_integer_prop_by_name (node, (const guchar *)"priority", specification->priority); - - 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 e20d7de6b5..0000000000 --- a/widgets/table/e-table-column-specification.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_COLUMN_SPECIFICATION_H_ -#define _E_TABLE_COLUMN_SPECIFICATION_H_ - -#include <glib-object.h> -#include <libxml/tree.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_COLUMN_SPECIFICATION \ - (e_table_column_specification_get_type ()) -#define E_TABLE_COLUMN_SPECIFICATION(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_COLUMN_SPECIFICATION, ETableColumnSpecification)) -#define E_TABLE_COLUMN_SPECIFICATION_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_COLUMN_SPECIFICATION, ETableColumnSpecificationClass)) -#define E_IS_TABLE_COLUMN_SPECIFICATION(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_COLUMN_SPECIFICATION)) -#define E_IS_TABLE_COLUMN_SPECIFICATION_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_COLUMN_SPECIFICATION)) -#define E_TABLE_COLUMN_SPECIFICATION_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_COLUMN_SPECIFICATION, ETableColumnSpecificationClass)) - -G_BEGIN_DECLS - -typedef struct _ETableColumnSpecification ETableColumnSpecification; -typedef struct _ETableColumnSpecificationClass ETableColumnSpecificationClass; - -struct _ETableColumnSpecification { - GObject parent; - - gint model_col; - gint compare_col; - gchar *title; - gchar *pixbuf; - - gdouble expansion; - gint minimum_width; - guint resizable : 1; - guint disabled : 1; - - gchar *cell; - gchar *compare; - gchar *search; - gchar *sortable; - gint priority; -}; - -struct _ETableColumnSpecificationClass { - GObjectClass parent_class; -}; - -GType e_table_column_specification_get_type (void) G_GNUC_CONST; -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); - -G_END_DECLS - -#endif /* _E_TABLE_COLUMN_SPECIFICATION_H_ */ diff --git a/widgets/table/e-table-config.c b/widgets/table/e-table-config.c deleted file mode 100644 index 3be7539ada..0000000000 --- a/widgets/table/e-table-config.c +++ /dev/null @@ -1,1482 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -/* - * FIXME: - * Sort Dialog: when text is selected, the toggle button switches state. - * Make Clear all work. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <string.h> - -#include <gtk/gtk.h> - -#include <glib/gi18n.h> -#include "e-util/e-util-private.h" -#include "e-util/e-util.h" -#include "e-util/e-unicode.h" - -#include "e-table-config.h" -#include "e-table-memory-store.h" -#include "e-table-without.h" - -G_DEFINE_TYPE (ETableConfig, e_table_config, G_TYPE_OBJECT) - -enum { - CHANGED, - LAST_SIGNAL -}; - -enum { - PROP_0, - PROP_STATE -}; - -enum { - COLUMN_ITEM, - COLUMN_VALUE -}; - -static guint e_table_config_signals[LAST_SIGNAL] = { 0, }; - -static void -config_finalize (GObject *object) -{ - ETableConfig *config = E_TABLE_CONFIG (object); - - if (config->state) - g_object_unref (config->state); - config->state = NULL; - - if (config->source_state) - g_object_unref (config->source_state); - config->source_state = NULL; - - if (config->source_spec) - g_object_unref (config->source_spec); - config->source_spec = NULL; - - g_free (config->header); - config->header = NULL; - - g_slist_free (config->column_names); - config->column_names = NULL; - - g_free (config->domain); - config->domain = NULL; - - G_OBJECT_CLASS (e_table_config_parent_class)->finalize (object); -} - -static void -e_table_config_changed (ETableConfig *config, - ETableState *state) -{ - g_return_if_fail (E_IS_TABLE_CONFIG (config)); - - g_signal_emit (config, e_table_config_signals[CHANGED], 0, state); -} - -static void -config_dialog_changed (ETableConfig *config) -{ - /* enable the apply/ok buttons */ - gtk_dialog_set_response_sensitive ( - GTK_DIALOG (config->dialog_toplevel), - GTK_RESPONSE_APPLY, TRUE); - gtk_dialog_set_response_sensitive ( - GTK_DIALOG (config->dialog_toplevel), - GTK_RESPONSE_OK, TRUE); -} - -static void -config_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ETableConfig *config = E_TABLE_CONFIG (object); - - switch (property_id) { - case PROP_STATE: - g_value_set_object (value, config->state); - break; - default: - break; - } -} - -static void -e_table_config_class_init (ETableConfigClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - class->changed = NULL; - - object_class->finalize = config_finalize; - object_class->get_property = config_get_property; - - e_table_config_signals[CHANGED] = g_signal_new ( - "changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableConfigClass, changed), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - g_object_class_install_property ( - object_class, - PROP_STATE, - g_param_spec_object ( - "state", - "State", - NULL, - E_TYPE_TABLE_STATE, - G_PARAM_READABLE)); -} - -static void -configure_combo_box_add (GtkComboBox *combo_box, - const gchar *item, - const gchar *value) -{ - GtkTreeRowReference *reference; - GtkTreeModel *model; - GtkTreePath *path; - GHashTable *index; - GtkTreeIter iter; - - model = gtk_combo_box_get_model (combo_box); - gtk_list_store_append (GTK_LIST_STORE (model), &iter); - - gtk_list_store_set ( - GTK_LIST_STORE (model), &iter, - COLUMN_ITEM, item, COLUMN_VALUE, value, -1); - - index = g_object_get_data (G_OBJECT (combo_box), "index"); - g_return_if_fail (index != NULL); - - /* Add an entry to the tree model index. */ - path = gtk_tree_model_get_path (model, &iter); - reference = gtk_tree_row_reference_new (model, path); - g_return_if_fail (reference != NULL); - g_hash_table_insert (index, g_strdup (value), reference); - gtk_tree_path_free (path); -} - -static gchar * -configure_combo_box_get_active (GtkComboBox *combo_box) -{ - GtkTreeIter iter; - gchar *value = NULL; - - if (gtk_combo_box_get_active_iter (combo_box, &iter)) - gtk_tree_model_get ( - gtk_combo_box_get_model (combo_box), &iter, - COLUMN_VALUE, &value, -1); - - if (value != NULL && *value == '\0') { - g_free (value); - value = NULL; - } - - return value; -} - -static void -configure_combo_box_set_active (GtkComboBox *combo_box, - const gchar *value) -{ - GtkTreeRowReference *reference; - GHashTable *index; - - index = g_object_get_data (G_OBJECT (combo_box), "index"); - g_return_if_fail (index != NULL); - - reference = g_hash_table_lookup (index, value); - if (reference != NULL) { - GtkTreeModel *model; - GtkTreePath *path; - GtkTreeIter iter; - - model = gtk_tree_row_reference_get_model (reference); - path = gtk_tree_row_reference_get_path (reference); - - if (path == NULL) - return; - - if (gtk_tree_model_get_iter (model, &iter, path)) - gtk_combo_box_set_active_iter (combo_box, &iter); - - gtk_tree_path_free (path); - } -} - -static ETableColumnSpecification * -find_column_in_spec (ETableSpecification *spec, - gint model_col) -{ - ETableColumnSpecification **column; - - for (column = spec->columns; *column; column++) { - if ((*column)->disabled) - continue; - if ((*column)->model_col != model_col) - continue; - - return *column; - } - - return NULL; -} - -static gint -find_model_column_by_name (ETableSpecification *spec, - const gchar *s) -{ - ETableColumnSpecification **column; - - for (column = spec->columns; *column; column++) { - - if ((*column)->disabled) - continue; - if (g_ascii_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; - gint 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); - const gchar *text = ""; - - gtk_widget_set_sensitive (widgets[i].frames, sensitive); - - /* - * Sorting is set, auto select the text - */ - g_signal_handler_block ( - widgets[i].radio_ascending, - widgets[i].toggled_id); - g_signal_handler_block ( - widgets[i].combo, - widgets[i].changed_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; - } - - text = column->title; - - /* - * 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); - - if (is_sort) - g_return_if_fail ( - widgets[i].radio_ascending != - config->group[i].radio_ascending); - else - g_return_if_fail ( - widgets[i].radio_ascending != - config->sort[i].radio_ascending); - gtk_toggle_button_set_active (t, 1); - } - - /* Set the text */ - configure_combo_box_set_active ( - GTK_COMBO_BOX (widgets[i].combo), text); - - g_signal_handler_unblock ( - widgets[i].radio_ascending, - widgets[i].toggled_id); - g_signal_handler_unblock ( - widgets[i].combo, - widgets[i].changed_id); - } -} - -static void -config_sort_info_update (ETableConfig *config) -{ - ETableSortInfo *info = config->state->sort_info; - GString *res; - gint 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, dgettext (config->domain, (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; - gint count, i; - - if (!e_table_sort_info_get_can_group (info)) - return; - - count = e_table_sort_info_grouping_get_count (info); - 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, dgettext (config->domain, (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 -setup_fields (ETableConfig *config) -{ - gint i; - - e_table_model_freeze ((ETableModel *) config->available_model); - e_table_model_freeze ((ETableModel *) config->shown_model); - e_table_without_show_all (config->available_model); - e_table_subset_variable_clear (config->shown_model); - - if (config->temp_state) { - for (i = 0; i < config->temp_state->col_count; i++) { - gint j, idx; - for (j = 0, idx = 0; j < config->temp_state->columns[i]; j++) - if (!config->source_spec->columns[j]->disabled) - idx++; - - e_table_subset_variable_add (config->shown_model, idx); - e_table_without_hide (config->available_model, GINT_TO_POINTER (idx)); - } - } - e_table_model_thaw ((ETableModel *) config->available_model); - e_table_model_thaw ((ETableModel *) config->shown_model); -} - -static void -config_fields_info_update (ETableConfig *config) -{ - ETableColumnSpecification **column; - GString *res = g_string_new (""); - gint i, j; - - for (i = 0; i < config->state->col_count; i++) { - for (j = 0, column = config->source_spec->columns; *column; column++, j++) { - - if ((*column)->disabled) - continue; - - if (config->state->columns[i] != j) - continue; - - g_string_append (res, dgettext (config->domain, (*column)->title)); - if (i + 1 < config->state->col_count) - g_string_append (res, ", "); - - break; - } - } - - 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) -{ - GtkDialog *dialog; - gint response, 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 = GTK_DIALOG (config->dialog_sort); - else - dialog = GTK_DIALOG (config->dialog_group_by); - - gtk_window_set_transient_for ( - GTK_WINDOW (dialog), GTK_WINDOW (config->dialog_toplevel)); - - do { - response = gtk_dialog_run (dialog); - switch (response) { - case 0: /* clear fields */ - if (is_sort) { - e_table_sort_info_sorting_truncate ( - config->temp_state->sort_info, 0); - } else { - e_table_sort_info_grouping_truncate ( - config->temp_state->sort_info, 0); - } - update_sort_and_group_config_dialog (config, is_sort); - break; - - case GTK_RESPONSE_OK: - g_object_unref (config->state); - config->state = config->temp_state; - config->temp_state = NULL; - running = 0; - config_dialog_changed (config); - break; - - case GTK_RESPONSE_DELETE_EVENT: - case GTK_RESPONSE_CANCEL: - g_object_unref (config->temp_state); - config->temp_state = NULL; - running = 0; - break; - } - - } while (running); - gtk_widget_hide (GTK_WIDGET (dialog)); - - if (is_sort) - config_sort_info_update (config); - else - config_group_info_update (config); -} - -static void -do_fields_config_dialog (ETableConfig *config) -{ - GtkDialog *dialog; - GtkWidget *widget; - gint response, running = 1; - - dialog = GTK_DIALOG (config->dialog_show_fields); - - gtk_widget_ensure_style (config->dialog_show_fields); - - widget = gtk_dialog_get_content_area (dialog); - gtk_container_set_border_width (GTK_CONTAINER (widget), 0); - - widget = gtk_dialog_get_action_area (dialog); - gtk_container_set_border_width (GTK_CONTAINER (widget), 12); - - config->temp_state = e_table_state_duplicate (config->state); - - setup_fields (config); - - gtk_window_set_transient_for ( - GTK_WINDOW (config->dialog_show_fields), - GTK_WINDOW (config->dialog_toplevel)); - - do { - response = gtk_dialog_run (GTK_DIALOG (config->dialog_show_fields)); - switch (response) { - case GTK_RESPONSE_OK: - g_object_unref (config->state); - config->state = config->temp_state; - config->temp_state = NULL; - running = 0; - config_dialog_changed (config); - break; - - case GTK_RESPONSE_DELETE_EVENT: - case GTK_RESPONSE_CANCEL: - g_object_unref (config->temp_state); - config->temp_state = NULL; - running = 0; - break; - } - - } while (running); - gtk_widget_hide (GTK_WIDGET (config->dialog_show_fields)); - - config_fields_info_update (config); -} - -static ETableMemoryStoreColumnInfo store_columns[] = { - E_TABLE_MEMORY_STORE_STRING, - E_TABLE_MEMORY_STORE_INTEGER, - E_TABLE_MEMORY_STORE_TERMINATOR -}; - -static ETableModel * -create_store (ETableConfig *config) -{ - gint i; - ETableModel *store; - - store = e_table_memory_store_new (store_columns); - for (i = 0; config->source_spec->columns[i]; i++) { - - gchar *text; - - if (config->source_spec->columns[i]->disabled) - continue; - - text = g_strdup (dgettext ( - config->domain, - config->source_spec->columns[i]->title)); - e_table_memory_store_insert_adopt ( - E_TABLE_MEMORY_STORE (store), -1, NULL, text, i); - } - - return store; -} - -static const gchar *spec = -"<ETableSpecification gettext-domain=\"" GETTEXT_PACKAGE "\"" -" no-headers=\"true\" cursor-mode=\"line\" draw-grid=\"false\" " -" draw-focus=\"true\" selection-mode=\"browse\">" -"<ETableColumn model_col= \"0\" _title=\"Name\" minimum_width=\"30\"" -" resizable=\"true\" cell=\"string\" compare=\"string\"/>" -"<ETableState> <column source=\"0\"/>" -"<grouping/>" -"</ETableState>" -"</ETableSpecification>"; - -static GtkWidget * -e_table_proxy_etable_shown_new (ETableModel *store) -{ - ETableModel *model = NULL; - GtkWidget *widget; - - model = e_table_subset_variable_new (store); - - widget = e_table_new (model, NULL, spec, NULL); - - atk_object_set_name ( - gtk_widget_get_accessible (widget), - _("Show Fields")); - - return widget; -} - -static GtkWidget * -e_table_proxy_etable_available_new (ETableModel *store) -{ - ETableModel *model; - GtkWidget *widget; - - model = e_table_without_new ( - store, NULL, NULL, NULL, NULL, NULL, NULL, NULL); - - e_table_without_show_all (E_TABLE_WITHOUT (model)); - - widget = e_table_new (model, NULL, spec, NULL); - - atk_object_set_name ( - gtk_widget_get_accessible (widget), - _("Available Fields")); - - return widget; -} - -static void -config_button_fields (GtkWidget *widget, - ETableConfig *config) -{ - do_fields_config_dialog (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 (gpointer data, - GObject *where_object_was) -{ - ETableConfig *config = data; - g_object_unref (config); -} - -static void -dialog_response (GtkWidget *dialog, - gint response_id, - ETableConfig *config) -{ - if (response_id == GTK_RESPONSE_APPLY - || response_id == GTK_RESPONSE_OK) { - e_table_config_changed (config, config->state); - } - - if (response_id == GTK_RESPONSE_CANCEL - || response_id == GTK_RESPONSE_OK) { - gtk_widget_destroy (dialog); - } -} - -/* - * Invoked by the GtkBuilder auto-connect code - */ -static GtkWidget * -e_table_proxy_gtk_combo_text_new (void) -{ - GtkCellRenderer *renderer; - GtkListStore *store; - GtkWidget *combo_box; - GHashTable *index; - - store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING); - combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store)); - - renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start ( - GTK_CELL_LAYOUT (combo_box), renderer, FALSE); - gtk_cell_layout_add_attribute ( - GTK_CELL_LAYOUT (combo_box), renderer, "text", COLUMN_ITEM); - - /* Embed a reverse-lookup index into the widget. */ - index = g_hash_table_new_full ( - g_str_hash, g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) gtk_tree_row_reference_free); - g_object_set_data_full ( - G_OBJECT (combo_box), "index", index, - (GDestroyNotify) g_hash_table_destroy); - - return combo_box; -} - -static void -connect_button (ETableConfig *config, - GtkBuilder *builder, - const gchar *widget_name, - GCallback cback) -{ - GtkWidget *button = e_builder_get_widget (builder, widget_name); - - if (button) - g_signal_connect (button, "clicked", cback, config); -} - -static gint -get_source_model_col_index (ETableConfig *config, - gint idx) -{ - gint visible_index; - ETableModel *src_model; - - src_model = E_TABLE_SUBSET (config->available_model)->source; - - visible_index = e_table_subset_view_to_model_row ( - E_TABLE_SUBSET (config->available_model), idx); - - return GPOINTER_TO_INT (e_table_model_value_at (src_model, 1, visible_index)); -} - -static void -sort_combo_changed (GtkComboBox *combo_box, - ETableConfigSortWidgets *sort) -{ - ETableConfig *config = sort->e_table_config; - ETableSortInfo *sort_info = config->temp_state->sort_info; - ETableConfigSortWidgets *base = &config->sort[0]; - GtkToggleButton *toggle_button; - gint idx = sort - base; - gchar *s; - - s = configure_combo_box_get_active (combo_box); - - if (s != NULL) { - ETableSortColumn c; - gint col; - - col = find_model_column_by_name (config->source_spec, s); - if (col == -1) { - g_warning ("sort: This should not happen (%s)", s); - g_free (s); - return; - } - - toggle_button = GTK_TOGGLE_BUTTON ( - config->sort[idx].radio_ascending); - c.ascending = gtk_toggle_button_get_active (toggle_button); - 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); - } - - g_free (s); -} - -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]; - gint idx = sort - base; - ETableSortColumn c; - - c = e_table_sort_info_sorting_get_nth (si, idx); - c.ascending = gtk_toggle_button_get_active (t); - e_table_sort_info_sorting_set_nth (si, idx, c); -} - -static void -configure_sort_dialog (ETableConfig *config, - GtkBuilder *builder) -{ - GSList *l; - gint i; - - const gchar *algs[] = { - "alignment4", - "alignment3", - "alignment2", - "alignment1", - NULL - }; - - for (i = 0; i < 4; i++) { - gchar buffer[80]; - - snprintf (buffer, sizeof (buffer), "sort-combo-%d", i + 1); - config->sort[i].combo = e_table_proxy_gtk_combo_text_new (); - gtk_widget_show (GTK_WIDGET (config->sort[i].combo)); - gtk_container_add ( - GTK_CONTAINER (e_builder_get_widget ( - builder, algs[i])), config->sort[i].combo); - configure_combo_box_add ( - GTK_COMBO_BOX (config->sort[i].combo), "", ""); - - snprintf (buffer, sizeof (buffer), "frame-sort-%d", i + 1); - config->sort[i].frames = - e_builder_get_widget (builder, buffer); - - snprintf ( - buffer, sizeof (buffer), - "radiobutton-ascending-sort-%d", i + 1); - config->sort[i].radio_ascending = e_builder_get_widget ( - builder, buffer); - - snprintf ( - buffer, sizeof (buffer), - "radiobutton-descending-sort-%d", i + 1); - config->sort[i].radio_descending = e_builder_get_widget ( - builder, buffer); - - config->sort[i].e_table_config = config; - } - - for (l = config->column_names; l; l = l->next) { - gchar *label = l->data; - - for (i = 0; i < 4; i++) { - configure_combo_box_add ( - GTK_COMBO_BOX (config->sort[i].combo), - dgettext (config->domain, label), label); - } - } - - /* - * After we have runtime modified things, signal connect - */ - for (i = 0; i < 4; i++) { - config->sort[i].changed_id = g_signal_connect ( - config->sort[i].combo, - "changed", G_CALLBACK (sort_combo_changed), - &config->sort[i]); - - config->sort[i].toggled_id = g_signal_connect ( - config->sort[i].radio_ascending, - "toggled", G_CALLBACK (sort_ascending_toggled), - &config->sort[i]); - } -} - -static void -group_combo_changed (GtkComboBox *combo_box, - ETableConfigSortWidgets *group) -{ - ETableConfig *config = group->e_table_config; - ETableSortInfo *sort_info = config->temp_state->sort_info; - ETableConfigSortWidgets *base = &config->group[0]; - gint idx = group - base; - gchar *s; - - s = configure_combo_box_get_active (combo_box); - - if (s != NULL) { - GtkToggleButton *toggle_button; - ETableSortColumn c; - gint col; - - col = find_model_column_by_name (config->source_spec, s); - if (col == -1) { - g_warning ("grouping: this should not happen, %s", s); - g_free (s); - return; - } - - toggle_button = GTK_TOGGLE_BUTTON ( - config->group[idx].radio_ascending); - c.ascending = gtk_toggle_button_get_active (toggle_button); - c.column = col; - e_table_sort_info_grouping_set_nth (sort_info, idx, c); - - update_sort_and_group_config_dialog (config, FALSE); - } else { - e_table_sort_info_grouping_truncate (sort_info, idx); - update_sort_and_group_config_dialog (config, FALSE); - } - - g_free (s); -} - -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]; - gint idx = group - base; - ETableSortColumn c; - - c = e_table_sort_info_grouping_get_nth (si, idx); - c.ascending = gtk_toggle_button_get_active (t); - e_table_sort_info_grouping_set_nth (si, idx, c); -} - -static void -configure_group_dialog (ETableConfig *config, - GtkBuilder *builder) -{ - GSList *l; - gint i; - const gchar *vboxes[] = {"vbox7", "vbox9", "vbox11", "vbox13", NULL}; - - for (i = 0; i < 4; i++) { - gchar buffer[80]; - - snprintf (buffer, sizeof (buffer), "group-combo-%d", i + 1); - config->group[i].combo = e_table_proxy_gtk_combo_text_new (); - gtk_widget_show (GTK_WIDGET (config->group[i].combo)); - gtk_box_pack_start ( - GTK_BOX (e_builder_get_widget (builder, vboxes[i])), - config->group[i].combo, FALSE, FALSE, 0); - - configure_combo_box_add ( - GTK_COMBO_BOX (config->group[i].combo), "", ""); - - snprintf (buffer, sizeof (buffer), "frame-group-%d", i + 1); - config->group[i].frames = - e_builder_get_widget (builder, buffer); - - snprintf ( - buffer, sizeof (buffer), - "radiobutton-ascending-group-%d", i + 1); - config->group[i].radio_ascending = e_builder_get_widget ( - builder, buffer); - - snprintf ( - buffer, sizeof (buffer), - "radiobutton-descending-group-%d", i + 1); - config->group[i].radio_descending = e_builder_get_widget ( - builder, buffer); - - snprintf ( - buffer, sizeof (buffer), - "checkbutton-group-%d", i + 1); - config->group[i].view_check = e_builder_get_widget ( - builder, buffer); - - config->group[i].e_table_config = config; - } - - for (l = config->column_names; l; l = l->next) { - gchar *label = l->data; - - for (i = 0; i < 4; i++) { - configure_combo_box_add ( - GTK_COMBO_BOX (config->group[i].combo), - dgettext (config->domain, label), label); - } - } - - /* - * After we have runtime modified things, signal connect - */ - for (i = 0; i < 4; i++) { - config->group[i].changed_id = g_signal_connect ( - config->group[i].combo, - "changed", G_CALLBACK (group_combo_changed), - &config->group[i]); - - config->group[i].toggled_id = g_signal_connect ( - config->group[i].radio_ascending, - "toggled", G_CALLBACK (group_ascending_toggled), - &config->group[i]); - } -} - -static void -add_column (gint model_row, - gpointer closure) -{ - GList **columns = closure; - *columns = g_list_prepend (*columns, GINT_TO_POINTER (model_row)); -} - -static void -config_button_add (GtkWidget *widget, - ETableConfig *config) -{ - GList *columns = NULL; - GList *column; - gint count; - gint i; - - e_table_selected_row_foreach (config->available, add_column, &columns); - columns = g_list_reverse (columns); - - count = g_list_length (columns); - - config->temp_state->columns = g_renew ( - int, config->temp_state->columns, - config->temp_state->col_count + count); - config->temp_state->expansions = g_renew ( - gdouble, config->temp_state->expansions, - config->temp_state->col_count + count); - i = config->temp_state->col_count; - for (column = columns; column; column = column->next) { - config->temp_state->columns[i] = - get_source_model_col_index ( - config, GPOINTER_TO_INT (column->data)); - config->temp_state->expansions[i] = - config->source_spec->columns - [config->temp_state->columns[i]]->expansion; - i++; - } - config->temp_state->col_count += count; - - g_list_free (columns); - - setup_fields (config); -} - -static void -config_button_remove (GtkWidget *widget, - ETableConfig *config) -{ - GList *columns = NULL; - GList *column; - - e_table_selected_row_foreach (config->shown, add_column, &columns); - - for (column = columns; column; column = column->next) { - gint row = GPOINTER_TO_INT (column->data); - - memmove ( - config->temp_state->columns + row, - config->temp_state->columns + row + 1, - sizeof (gint) * (config->temp_state->col_count - row - 1)); - memmove ( - config->temp_state->expansions + row, - config->temp_state->expansions + row + 1, - sizeof (gdouble) * (config->temp_state->col_count - row - 1)); - config->temp_state->col_count--; - } - config->temp_state->columns = g_renew ( - int, config->temp_state->columns, - config->temp_state->col_count); - config->temp_state->expansions = g_renew ( - gdouble, config->temp_state->expansions, - config->temp_state->col_count); - - g_list_free (columns); - - setup_fields (config); -} - -static void -config_button_up (GtkWidget *widget, - ETableConfig *config) -{ - GList *columns = NULL; - GList *column; - gint *new_shown; - gdouble *new_expansions; - gint next_col; - gdouble next_expansion; - gint i; - - e_table_selected_row_foreach (config->shown, add_column, &columns); - - /* if no columns left, just return */ - if (columns == NULL) - return; - - columns = g_list_reverse (columns); - - new_shown = g_new (int, config->temp_state->col_count); - new_expansions = g_new (double, config->temp_state->col_count); - - column = columns; - - next_col = config->temp_state->columns[0]; - next_expansion = config->temp_state->expansions[0]; - - for (i = 1; i < config->temp_state->col_count; i++) { - if (column && (GPOINTER_TO_INT (column->data) == i)) { - new_expansions[i - 1] = config->temp_state->expansions[i]; - new_shown[i - 1] = config->temp_state->columns[i]; - column = column->next; - } else { - new_shown[i - 1] = next_col; - next_col = config->temp_state->columns[i]; - - new_expansions[i - 1] = next_expansion; - next_expansion = config->temp_state->expansions[i]; - } - } - - new_shown[i - 1] = next_col; - new_expansions[i - 1] = next_expansion; - - g_free (config->temp_state->columns); - g_free (config->temp_state->expansions); - - config->temp_state->columns = new_shown; - config->temp_state->expansions = new_expansions; - - g_list_free (columns); - - setup_fields (config); -} - -static void -config_button_down (GtkWidget *widget, - ETableConfig *config) -{ - GList *columns = NULL; - GList *column; - gint *new_shown; - gdouble *new_expansions; - gint next_col; - gdouble next_expansion; - gint i; - - e_table_selected_row_foreach (config->shown, add_column, &columns); - - /* if no columns left, just return */ - if (columns == NULL) - return; - - new_shown = g_new (gint, config->temp_state->col_count); - new_expansions = g_new (gdouble, config->temp_state->col_count); - - column = columns; - - next_col = - config->temp_state->columns[config->temp_state->col_count - 1]; - next_expansion = - config->temp_state->expansions[config->temp_state->col_count - 1]; - - for (i = config->temp_state->col_count - 1; i > 0; i--) { - if (column && (GPOINTER_TO_INT (column->data) == i - 1)) { - new_expansions[i] = config->temp_state->expansions[i - 1]; - new_shown[i] = config->temp_state->columns[i - 1]; - column = column->next; - } else { - new_shown[i] = next_col; - next_col = config->temp_state->columns[i - 1]; - - new_expansions[i] = next_expansion; - next_expansion = config->temp_state->expansions[i - 1]; - } - } - - new_shown[0] = next_col; - new_expansions[0] = next_expansion; - - g_free (config->temp_state->columns); - g_free (config->temp_state->expansions); - - config->temp_state->columns = new_shown; - config->temp_state->expansions = new_expansions; - - g_list_free (columns); - - setup_fields (config); -} - -static void -configure_fields_dialog (ETableConfig *config, - GtkBuilder *builder) -{ - GtkWidget *scrolled; - GtkWidget *etable; - ETableModel *store = create_store (config); - - /* "custom-available" widget */ - etable = e_table_proxy_etable_available_new (store); - gtk_widget_show (etable); - scrolled = e_builder_get_widget (builder, "available-scrolled"); - gtk_container_add (GTK_CONTAINER (scrolled), etable); - config->available = E_TABLE (etable); - g_object_get ( - config->available, - "model", &config->available_model, - NULL); - gtk_widget_show_all (etable); - gtk_label_set_mnemonic_widget ( - GTK_LABEL (e_builder_get_widget ( - builder, "label-available")), etable); - - /* "custom-shown" widget */ - etable = e_table_proxy_etable_shown_new (store); - gtk_widget_show (etable); - scrolled = e_builder_get_widget (builder, "shown-scrolled"); - gtk_container_add (GTK_CONTAINER (scrolled), etable); - config->shown = E_TABLE (etable); - g_object_get ( - config->shown, - "model", &config->shown_model, - NULL); - gtk_widget_show_all (etable); - gtk_label_set_mnemonic_widget ( - GTK_LABEL (e_builder_get_widget ( - builder, "label-displayed")), etable); - - connect_button ( - config, builder, "button-add", - G_CALLBACK (config_button_add)); - connect_button ( - config, builder, "button-remove", - G_CALLBACK (config_button_remove)); - connect_button ( - config, builder, "button-up", - G_CALLBACK (config_button_up)); - connect_button ( - config, builder, "button-down", - G_CALLBACK (config_button_down)); - - setup_fields (config); - - g_object_unref (store); -} - -static void -setup_gui (ETableConfig *config) -{ - GtkBuilder *builder; - gboolean can_group; - - can_group = e_table_sort_info_get_can_group (config->state->sort_info); - builder = gtk_builder_new (); - e_load_ui_builder_definition (builder, "e-table-config.ui"); - - config->dialog_toplevel = e_builder_get_widget ( - builder, "e-table-config"); - - if (config->header) - gtk_window_set_title ( - GTK_WINDOW (config->dialog_toplevel), - config->header); - - config->dialog_show_fields = e_builder_get_widget ( - builder, "dialog-show-fields"); - config->dialog_group_by = e_builder_get_widget ( - builder, "dialog-group-by"); - config->dialog_sort = e_builder_get_widget ( - builder, "dialog-sort"); - - config->sort_label = e_builder_get_widget ( - builder, "label-sort"); - config->group_label = e_builder_get_widget ( - builder, "label-group"); - config->fields_label = e_builder_get_widget ( - builder, "label-fields"); - - connect_button ( - config, builder, "button-sort", - G_CALLBACK (config_button_sort)); - connect_button ( - config, builder, "button-group", - G_CALLBACK (config_button_group)); - connect_button ( - config, builder, "button-fields", - G_CALLBACK (config_button_fields)); - - if (!can_group) { - GtkWidget *w; - - w = e_builder_get_widget (builder, "button-group"); - if (w) - gtk_widget_hide (w); - - w = e_builder_get_widget (builder, "label3"); - if (w) - gtk_widget_hide (w); - - w = config->group_label; - if (w) - gtk_widget_hide (w); - } - - configure_sort_dialog (config, builder); - configure_group_dialog (config, builder); - configure_fields_dialog (config, builder); - - g_object_weak_ref ( - G_OBJECT (config->dialog_toplevel), - dialog_destroyed, config); - - g_signal_connect ( - config->dialog_toplevel, "response", - G_CALLBACK (dialog_response), config); - - g_object_unref (builder); -} - -static void -e_table_config_init (ETableConfig *config) -{ - config->domain = NULL; -} - -ETableConfig * -e_table_config_construct (ETableConfig *config, - const gchar *header, - ETableSpecification *spec, - ETableState *state, - GtkWindow *parent_window) -{ - 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; - config->header = g_strdup (header); - - g_object_ref (config->source_spec); - g_object_ref (config->source_state); - - config->state = e_table_state_duplicate (state); - - config->domain = g_strdup (spec->domain); - - for (column = config->source_spec->columns; *column; column++) { - gchar *label = (*column)->title; - - if ((*column)->disabled) - continue; - - config->column_names = g_slist_append ( - config->column_names, label); - } - - setup_gui (config); - - gtk_window_set_transient_for (GTK_WINDOW (config->dialog_toplevel), - parent_window); - - 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 gchar *header, - ETableSpecification *spec, - ETableState *state, - GtkWindow *parent_window) -{ - ETableConfig *config; - GtkDialog *dialog; - GtkWidget *widget; - - config = g_object_new (E_TYPE_TABLE_CONFIG, NULL); - - e_table_config_construct ( - config, header, spec, state, parent_window); - - dialog = GTK_DIALOG (config->dialog_toplevel); - - gtk_widget_ensure_style (config->dialog_toplevel); - - widget = gtk_dialog_get_content_area (dialog); - gtk_container_set_border_width (GTK_CONTAINER (widget), 0); - - widget = gtk_dialog_get_action_area (dialog); - gtk_container_set_border_width (GTK_CONTAINER (widget), 12); - - gtk_dialog_set_response_sensitive ( - GTK_DIALOG (config->dialog_toplevel), - GTK_RESPONSE_APPLY, FALSE); - 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) -{ - GdkWindow *window; - - window = gtk_widget_get_window (GTK_WIDGET (config->dialog_toplevel)); - gdk_window_raise (window); -} - diff --git a/widgets/table/e-table-config.h b/widgets/table/e-table-config.h deleted file mode 100644 index 083160772f..0000000000 --- a/widgets/table/e-table-config.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_CONFIG_H_ -#define _E_TABLE_CONFIG_H_ - -#include <table/e-table-sort-info.h> -#include <table/e-table-specification.h> -#include <table/e-table-without.h> -#include <table/e-table-subset-variable.h> -#include <table/e-table.h> -#include <gtk/gtk.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_CONFIG \ - (e_table_config_get_type ()) -#define E_TABLE_CONFIG(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_CONFIG, ETableConfig)) -#define E_TABLE_CONFIG_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_CONFIG, ETableConfigClass)) -#define E_IS_TABLE_CONFIG(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_CONFIG)) -#define E_IS_TABLE_CONFIG_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_CONFIG)) -#define E_TABLE_CONFIG_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_CONFIG, ETableConfigClass)) - -G_BEGIN_DECLS - -typedef struct _ETableConfigSortWidgets ETableConfigSortWidgets; - -typedef struct _ETableConfig ETableConfig; -typedef struct _ETableConfigClass ETableConfigClass; - -struct _ETableConfigSortWidgets { - GtkWidget *combo; - GtkWidget *frames; - GtkWidget *radio_ascending; - GtkWidget *radio_descending; - GtkWidget *view_check; /* Only for group dialog */ - guint changed_id, toggled_id; - gpointer e_table_config; -}; - -struct _ETableConfig { - GObject parent; - - gchar *header; - - /* - * 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]; - - ETable *available; - ETableWithout *available_model; - ETable *shown; - ETableSubsetVariable *shown_model; - gchar *domain; - - /* - * List of valid column names - */ - GSList *column_names; -}; - -struct _ETableConfigClass { - GObjectClass parent_class; - - /* Signals */ - void (*changed) (ETableConfig *config); -}; - -GType e_table_config_get_type (void) G_GNUC_CONST; -ETableConfig * e_table_config_new (const gchar *header, - ETableSpecification *spec, - ETableState *state, - GtkWindow *parent_window); -ETableConfig *e_table_config_construct (ETableConfig *etco, - const gchar *header, - ETableSpecification *spec, - ETableState *state, - GtkWindow *parent_window); -void e_table_config_raise (ETableConfig *config); - -G_END_DECLS - -#endif /* _E_TABLE_CONFIG_H */ diff --git a/widgets/table/e-table-config.ui b/widgets/table/e-table-config.ui deleted file mode 100644 index cfc6cb57fc..0000000000 --- a/widgets/table/e-table-config.ui +++ /dev/null @@ -1,1594 +0,0 @@ -<?xml version="1.0"?> -<interface> - <!-- interface-requires gtk+ 2.12 --> - <!-- interface-naming-policy toplevel-contextual --> - <object class="GtkDialog" id="dialog-show-fields"> - <property name="title" translatable="yes">Show Fields</property> - <property name="modal">True</property> - <property name="type_hint">dialog</property> - <child internal-child="vbox"> - <object class="GtkVBox" id="dialog-vbox3"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <property name="spacing">8</property> - <child> - <object class="GtkVBox" id="vbox2"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <property name="spacing">6</property> - <child> - <object class="GtkTable" id="table2"> - <property name="visible">True</property> - <property name="n_columns">5</property> - <property name="column_spacing">6</property> - <property name="row_spacing">6</property> - <property name="homogeneous">True</property> - <child> - <object class="GtkLabel" id="label-available"> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">A_vailable Fields:</property> - <property name="use_underline">True</property> - </object> - <packing> - <property name="right_attach">2</property> - <property name="y_options">GTK_FILL</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label-displayed"> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">_Show these fields in order:</property> - <property name="use_underline">True</property> - </object> - <packing> - <property name="left_attach">3</property> - <property name="right_attach">5</property> - <property name="y_options">GTK_FILL</property> - </packing> - </child> - <child> - <placeholder/> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkTable" id="table3"> - <property name="visible">True</property> - <property name="n_columns">5</property> - <property name="column_spacing">6</property> - <property name="row_spacing">6</property> - <property name="homogeneous">True</property> - <child> - <object class="GtkVBox" id="vbox4"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <property name="spacing">6</property> - <child> - <object class="GtkScrolledWindow" id="available-scrolled"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="hscrollbar_policy">automatic</property> - <property name="vscrollbar_policy">automatic</property> - <property name="shadow_type">in</property> - <child> - <placeholder/> - </child> - </object> - <packing> - <property name="position">0</property> - </packing> - </child> - </object> - <packing> - <property name="right_attach">2</property> - </packing> - </child> - <child> - <object class="GtkVBox" id="vbox5"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <property name="spacing">6</property> - <child> - <object class="GtkScrolledWindow" id="shown-scrolled"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="hscrollbar_policy">automatic</property> - <property name="vscrollbar_policy">automatic</property> - <property name="shadow_type">in</property> - <child> - <placeholder/> - </child> - </object> - <packing> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkHBox" id="hbox4"> - <property name="visible">True</property> - <property name="spacing">6</property> - <property name="homogeneous">True</property> - <child> - <object class="GtkButton" id="button-up"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <child> - <object class="GtkAlignment" id="alignment7"> - <property name="visible">True</property> - <property name="xscale">0</property> - <property name="yscale">0</property> - <child> - <object class="GtkHBox" id="hbox19"> - <property name="visible">True</property> - <property name="spacing">2</property> - <child> - <object class="GtkImage" id="image3"> - <property name="visible">True</property> - <property name="stock">gtk-go-up</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label29"> - <property name="visible">True</property> - <property name="label" translatable="yes">Move _Up</property> - <property name="use_underline">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - </child> - </object> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkButton" id="button-down"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">True</property> - <child> - <object class="GtkAlignment" id="alignment8"> - <property name="visible">True</property> - <property name="xscale">0</property> - <property name="yscale">0</property> - <child> - <object class="GtkHBox" id="hbox20"> - <property name="visible">True</property> - <property name="spacing">2</property> - <child> - <object class="GtkImage" id="image4"> - <property name="visible">True</property> - <property name="stock">gtk-go-down</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label30"> - <property name="visible">True</property> - <property name="label" translatable="yes">Move _Down</property> - <property name="use_underline">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - </child> - </object> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="left_attach">3</property> - <property name="right_attach">5</property> - </packing> - </child> - <child> - <object class="GtkVBox" id="vbox6"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <property name="spacing">6</property> - <child> - <object class="GtkButton" id="button-add"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <child> - <object class="GtkAlignment" id="alignment5"> - <property name="visible">True</property> - <property name="xalign">0.69999998807907104</property> - <property name="xscale">0</property> - <property name="yscale">0</property> - <child> - <object class="GtkHBox" id="hbox17"> - <property name="visible">True</property> - <property name="spacing">2</property> - <child> - <object class="GtkLabel" id="label31"> - <property name="visible">True</property> - <property name="label" translatable="yes">_Add</property> - <property name="use_underline">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkImage" id="image5"> - <property name="visible">True</property> - <property name="stock">gtk-go-forward</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - </child> - </object> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkButton" id="button-remove"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <child> - <object class="GtkAlignment" id="alignment6"> - <property name="visible">True</property> - <property name="xscale">0</property> - <property name="yscale">0</property> - <child> - <object class="GtkHBox" id="hbox18"> - <property name="visible">True</property> - <property name="spacing">2</property> - <child> - <object class="GtkImage" id="image1"> - <property name="visible">True</property> - <property name="stock">gtk-go-back</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label27"> - <property name="visible">True</property> - <property name="label" translatable="yes">_Remove</property> - <property name="use_underline">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - </child> - </object> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - <child> - <placeholder/> - </child> - </object> - <packing> - <property name="left_attach">2</property> - <property name="right_attach">3</property> - </packing> - </child> - </object> - <packing> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="position">2</property> - </packing> - </child> - <child internal-child="action_area"> - <object class="GtkHButtonBox" id="dialog-action_area3"> - <property name="visible">True</property> - <property name="layout_style">end</property> - <child> - <object class="GtkButton" id="button22"> - <property name="label">gtk-cancel</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="receives_default">False</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkButton" id="button20"> - <property name="label">gtk-ok</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="receives_default">False</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="pack_type">end</property> - <property name="position">0</property> - </packing> - </child> - </object> - </child> - <action-widgets> - <action-widget response="-6">button22</action-widget> - <action-widget response="-5">button20</action-widget> - </action-widgets> - </object> - <object class="GtkDialog" id="dialog-group-by"> - <property name="title" translatable="yes">Group</property> - <property name="modal">True</property> - <property name="type_hint">dialog</property> - <child internal-child="vbox"> - <object class="GtkVBox" id="dialog-vbox4"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <property name="spacing">8</property> - <child> - <object class="GtkVBox" id="vbox24"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <child> - <object class="GtkHBox" id="hbox13"> - <property name="visible">True</property> - <property name="spacing">6</property> - <child> - <object class="GtkFrame" id="frame-group-1"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <child> - <object class="GtkHBox" id="hbox5"> - <property name="visible">True</property> - <property name="spacing">6</property> - <child> - <object class="GtkVBox" id="vbox7"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <child> - <object class="GtkCheckButton" id="checkbutton-group-1"> - <property name="label" translatable="yes">_Show field in View</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - </object> - <packing> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkVBox" id="vbox8"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <child> - <object class="GtkRadioButton" id="radiobutton-ascending-group-1"> - <property name="label" translatable="yes">Ascending</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkRadioButton" id="radiobutton-descending-group-1"> - <property name="label" translatable="yes">Descending</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - <property name="group">radiobutton-ascending-group-1</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - </child> - <child type="label"> - <object class="GtkLabel" id="label1"> - <property name="visible">True</property> - <property name="label" translatable="yes">Group Items By</property> - </object> - </child> - </object> - <packing> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label8"> - <property name="visible">True</property> - <property name="justify">center</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label9"> - <property name="visible">True</property> - <property name="justify">center</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">2</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label10"> - <property name="visible">True</property> - <property name="justify">center</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">3</property> - </packing> - </child> - </object> - <packing> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkHBox" id="hbox14"> - <property name="visible">True</property> - <property name="spacing">6</property> - <child> - <object class="GtkLabel" id="label11"> - <property name="visible">True</property> - <property name="justify">center</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkFrame" id="frame-group-2"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <child> - <object class="GtkHBox" id="hbox6"> - <property name="visible">True</property> - <property name="spacing">6</property> - <child> - <object class="GtkVBox" id="vbox9"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <child> - <object class="GtkCheckButton" id="checkbutton-group-2"> - <property name="label" translatable="yes">Show _field in View</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - </object> - <packing> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkVBox" id="vbox10"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <child> - <object class="GtkRadioButton" id="radiobutton-ascending-group-2"> - <property name="label" translatable="yes">Ascending</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkRadioButton" id="radiobutton-descending-group-2"> - <property name="label" translatable="yes">Descending</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - <property name="group">radiobutton-ascending-group-2</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - </child> - <child type="label"> - <object class="GtkLabel" id="label12"> - <property name="visible">True</property> - <property name="label" translatable="yes">Then By</property> - </object> - </child> - </object> - <packing> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label19"> - <property name="visible">True</property> - <property name="justify">center</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">2</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label18"> - <property name="visible">True</property> - <property name="justify">center</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">3</property> - </packing> - </child> - </object> - <packing> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="GtkHBox" id="hbox15"> - <property name="visible">True</property> - <property name="spacing">6</property> - <child> - <object class="GtkLabel" id="label13"> - <property name="visible">True</property> - <property name="justify">center</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label32"> - <property name="visible">True</property> - <property name="justify">center</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="GtkFrame" id="frame-group-3"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <child> - <object class="GtkHBox" id="hbox7"> - <property name="visible">True</property> - <property name="spacing">6</property> - <child> - <object class="GtkVBox" id="vbox11"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <child> - <object class="GtkCheckButton" id="checkbutton-group-3"> - <property name="label" translatable="yes">Show field i_n View</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - </object> - <packing> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkVBox" id="vbox12"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <child> - <object class="GtkRadioButton" id="radiobutton-ascending-group-3"> - <property name="label" translatable="yes">Ascending</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkRadioButton" id="radiobutton-descending-group-3"> - <property name="label" translatable="yes">Descending</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - <property name="group">radiobutton-ascending-group-3</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - </child> - <child type="label"> - <object class="GtkLabel" id="label20"> - <property name="visible">True</property> - <property name="label" translatable="yes">Then By</property> - </object> - </child> - </object> - <packing> - <property name="position">2</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label17"> - <property name="visible">True</property> - <property name="justify">center</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">3</property> - </packing> - </child> - </object> - <packing> - <property name="position">2</property> - </packing> - </child> - <child> - <object class="GtkHBox" id="hbox16"> - <property name="visible">True</property> - <property name="spacing">6</property> - <child> - <object class="GtkLabel" id="label14"> - <property name="visible">True</property> - <property name="justify">center</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label16"> - <property name="visible">True</property> - <property name="justify">center</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label15"> - <property name="visible">True</property> - <property name="justify">center</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">2</property> - </packing> - </child> - <child> - <object class="GtkFrame" id="frame-group-4"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <child> - <object class="GtkHBox" id="hbox8"> - <property name="visible">True</property> - <property name="spacing">6</property> - <child> - <object class="GtkVBox" id="vbox13"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <child> - <object class="GtkCheckButton" id="checkbutton-group-4"> - <property name="label" translatable="yes">Show field in _View</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - </object> - <packing> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkVBox" id="vbox14"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <child> - <object class="GtkRadioButton" id="radiobutton-ascending-group-4"> - <property name="label" translatable="yes">Ascending</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkRadioButton" id="radiobutton-descending-group-4"> - <property name="label" translatable="yes">Descending</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - <property name="group">radiobutton-ascending-group-4</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - </child> - <child type="label"> - <object class="GtkLabel" id="label21"> - <property name="visible">True</property> - <property name="label" translatable="yes">Then By</property> - </object> - </child> - </object> - <packing> - <property name="position">3</property> - </packing> - </child> - </object> - <packing> - <property name="position">3</property> - </packing> - </child> - </object> - <packing> - <property name="position">2</property> - </packing> - </child> - <child internal-child="action_area"> - <object class="GtkHButtonBox" id="dialog-action_area4"> - <property name="visible">True</property> - <property name="layout_style">end</property> - <child> - <object class="GtkButton" id="button39"> - <property name="label" translatable="yes">Clear _All</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkButton" id="button42"> - <property name="label">gtk-cancel</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="receives_default">False</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="GtkButton" id="button41"> - <property name="label">gtk-ok</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="receives_default">False</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">2</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="pack_type">end</property> - <property name="position">0</property> - </packing> - </child> - </object> - </child> - <action-widgets> - <action-widget response="0">button39</action-widget> - <action-widget response="-6">button42</action-widget> - <action-widget response="-5">button41</action-widget> - </action-widgets> - </object> - <object class="GtkDialog" id="dialog-sort"> - <property name="title" translatable="yes">Sort</property> - <property name="modal">True</property> - <property name="type_hint">dialog</property> - <child internal-child="vbox"> - <object class="GtkVBox" id="vbox15"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <property name="spacing">8</property> - <child> - <object class="GtkTable" id="table5"> - <property name="visible">True</property> - <property name="n_rows">4</property> - <property name="column_spacing">6</property> - <property name="row_spacing">6</property> - <child> - <object class="GtkFrame" id="frame-sort-4"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <child> - <object class="GtkHBox" id="hbox9"> - <property name="visible">True</property> - <property name="spacing">6</property> - <child> - <object class="GtkAlignment" id="alignment1"> - <property name="visible">True</property> - <property name="yscale">0</property> - </object> - <packing> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkVBox" id="vbox17"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <child> - <object class="GtkRadioButton" id="radiobutton-ascending-sort-4"> - <property name="label" translatable="yes">Ascending</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkRadioButton" id="radiobutton-descending-sort-4"> - <property name="label" translatable="yes">Descending</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - <property name="group">radiobutton-ascending-sort-4</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - </child> - <child type="label"> - <object class="GtkLabel" id="label22"> - <property name="visible">True</property> - <property name="label" translatable="yes">Then By</property> - </object> - </child> - </object> - <packing> - <property name="top_attach">3</property> - <property name="bottom_attach">4</property> - <property name="y_options">GTK_FILL</property> - </packing> - </child> - <child> - <object class="GtkFrame" id="frame-sort-3"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <child> - <object class="GtkHBox" id="hbox10"> - <property name="visible">True</property> - <property name="spacing">6</property> - <child> - <object class="GtkAlignment" id="alignment2"> - <property name="visible">True</property> - <property name="yscale">0</property> - </object> - <packing> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkVBox" id="vbox19"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <child> - <object class="GtkRadioButton" id="radiobutton-ascending-sort-3"> - <property name="label" translatable="yes">Ascending</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkRadioButton" id="radiobutton-descending-sort-3"> - <property name="label" translatable="yes">Descending</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - <property name="group">radiobutton-ascending-sort-3</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - </child> - <child type="label"> - <object class="GtkLabel" id="label23"> - <property name="visible">True</property> - <property name="label" translatable="yes">Then By</property> - </object> - </child> - </object> - <packing> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - <property name="y_options">GTK_FILL</property> - </packing> - </child> - <child> - <object class="GtkFrame" id="frame-sort-2"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <child> - <object class="GtkHBox" id="hbox11"> - <property name="visible">True</property> - <property name="spacing">6</property> - <child> - <object class="GtkAlignment" id="alignment3"> - <property name="visible">True</property> - <property name="yscale">0</property> - </object> - <packing> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkVBox" id="vbox21"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <child> - <object class="GtkRadioButton" id="radiobutton-ascending-sort-2"> - <property name="label" translatable="yes">Ascending</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkRadioButton" id="radiobutton-descending-sort-2"> - <property name="label" translatable="yes">Descending</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - <property name="group">radiobutton-ascending-sort-2</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - </child> - <child type="label"> - <object class="GtkLabel" id="label24"> - <property name="visible">True</property> - <property name="label" translatable="yes">Then By</property> - </object> - </child> - </object> - <packing> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="y_options">GTK_FILL</property> - </packing> - </child> - <child> - <object class="GtkFrame" id="frame-sort-1"> - <property name="visible">True</property> - <property name="label_xalign">0</property> - <child> - <object class="GtkHBox" id="hbox12"> - <property name="visible">True</property> - <property name="spacing">6</property> - <child> - <object class="GtkAlignment" id="alignment4"> - <property name="visible">True</property> - <property name="yscale">0</property> - </object> - <packing> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkVBox" id="vbox23"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <child> - <object class="GtkRadioButton" id="radiobutton-ascending-sort-1"> - <property name="label" translatable="yes">Ascending</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkRadioButton" id="radiobutton-descending-sort-1"> - <property name="label" translatable="yes">Descending</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <property name="draw_indicator">True</property> - <property name="group">radiobutton-ascending-sort-1</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="position">1</property> - </packing> - </child> - </object> - </child> - <child type="label"> - <object class="GtkLabel" id="label25"> - <property name="visible">True</property> - <property name="label" translatable="yes">Sort Items By</property> - </object> - </child> - </object> - <packing> - <property name="y_options">GTK_FILL</property> - </packing> - </child> - </object> - <packing> - <property name="position">2</property> - </packing> - </child> - <child internal-child="action_area"> - <object class="GtkHButtonBox" id="hbuttonbox1"> - <property name="visible">True</property> - <property name="layout_style">end</property> - <child> - <object class="GtkButton" id="button43"> - <property name="label" translatable="yes">Clear All</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkButton" id="button45"> - <property name="label">gtk-cancel</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="receives_default">False</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="GtkButton" id="button44"> - <property name="label">gtk-ok</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="has_default">True</property> - <property name="receives_default">False</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">2</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="pack_type">end</property> - <property name="position">0</property> - </packing> - </child> - </object> - </child> - <action-widgets> - <action-widget response="0">button43</action-widget> - <action-widget response="-6">button45</action-widget> - <action-widget response="-5">button44</action-widget> - </action-widgets> - </object> - <object class="GtkDialog" id="e-table-config"> - <property name="title">dialog1</property> - <property name="resizable">False</property> - <property name="modal">True</property> - <property name="window_position">center-on-parent</property> - <property name="type_hint">dialog</property> - <child internal-child="vbox"> - <object class="GtkVBox" id="dialog-vbox6"> - <property name="visible">True</property> - <property name="orientation">vertical</property> - <child> - <object class="GtkFrame" id="top-frame"> - <property name="visible">True</property> - <property name="border_width">2</property> - <property name="label_xalign">0</property> - <child> - <object class="GtkTable" id="table1"> - <property name="visible">True</property> - <property name="border_width">2</property> - <property name="n_rows">3</property> - <property name="n_columns">3</property> - <property name="column_spacing">4</property> - <property name="row_spacing">2</property> - <child> - <object class="GtkButton" id="button-sort"> - <property name="label" translatable="yes">_Sort...</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <signal name="clicked" handler="on_sort_clicked"/> - </object> - <packing> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - <property name="x_options">GTK_FILL</property> - <property name="y_options"></property> - </packing> - </child> - <child> - <object class="GtkButton" id="button-group"> - <property name="label" translatable="yes">_Group By...</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <signal name="clicked" handler="on_group_by_clicked"/> - </object> - <packing> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">GTK_FILL</property> - <property name="y_options"></property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label-sort"> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="wrap">True</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - <property name="y_options">GTK_FILL</property> - </packing> - </child> - <child> - <object class="GtkButton" id="button-fields"> - <property name="label" translatable="yes">_Fields Shown...</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="receives_default">False</property> - <property name="use_underline">True</property> - <signal name="clicked" handler="on_group_by_clicked"/> - </object> - <packing> - <property name="x_options">GTK_FILL</property> - <property name="y_options"></property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label-fields"> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="wrap">True</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="y_options">GTK_FILL</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label3"> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="justify">center</property> - </object> - <packing> - <property name="left_attach">2</property> - <property name="right_attach">3</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">GTK_FILL</property> - <property name="y_options">GTK_FILL</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label4"> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="justify">center</property> - </object> - <packing> - <property name="left_attach">2</property> - <property name="right_attach">3</property> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - <property name="x_options">GTK_FILL</property> - <property name="y_options">GTK_FILL</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label33"> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="justify">center</property> - </object> - <packing> - <property name="left_attach">2</property> - <property name="right_attach">3</property> - <property name="x_options">GTK_FILL</property> - <property name="y_options">GTK_FILL</property> - </packing> - </child> - <child> - <object class="GtkLabel" id="label-group"> - <property name="visible">True</property> - <property name="xalign">0</property> - <property name="wrap">True</property> - </object> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">GTK_FILL</property> - <property name="y_options"></property> - </packing> - </child> - </object> - </child> - <child type="label"> - <object class="GtkLabel" id="label26"> - <property name="visible">True</property> - <property name="label" translatable="yes">Description</property> - </object> - </child> - </object> - <packing> - <property name="position">2</property> - </packing> - </child> - <child internal-child="action_area"> - <object class="GtkHButtonBox" id="dialog-action_area6"> - <property name="visible">True</property> - <property name="layout_style">end</property> - <child> - <object class="GtkButton" id="cancelbutton2"> - <property name="label">gtk-cancel</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="receives_default">False</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> - </packing> - </child> - <child> - <object class="GtkButton" id="applybutton2"> - <property name="label">gtk-apply</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="receives_default">False</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="GtkButton" id="okbutton2"> - <property name="label">gtk-ok</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="can_default">True</property> - <property name="receives_default">False</property> - <property name="use_stock">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">2</property> - </packing> - </child> - </object> - <packing> - <property name="expand">False</property> - <property name="pack_type">end</property> - <property name="position">0</property> - </packing> - </child> - </object> - </child> - <action-widgets> - <action-widget response="-6">cancelbutton2</action-widget> - <action-widget response="-10">applybutton2</action-widget> - <action-widget response="-5">okbutton2</action-widget> - </action-widgets> - </object> -</interface> diff --git a/widgets/table/e-table-defines.h b/widgets/table/e-table-defines.h deleted file mode 100644 index d7b261160b..0000000000 --- a/widgets/table/e-table-defines.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __E_TABLE_DEFINES__ -#define __E_TABLE_DEFINES__ 1 - -G_BEGIN_DECLS - -#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 3 - -#define MIN_ARROW_SIZE 10 - -G_END_DECLS - -#endif diff --git a/widgets/table/e-table-extras.c b/widgets/table/e-table-extras.c deleted file mode 100644 index d39677bbc8..0000000000 --- a/widgets/table/e-table-extras.c +++ /dev/null @@ -1,412 +0,0 @@ -/* - * e-table-extras.c - Set of hash table sort of thingies. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <string.h> - -#include <gtk/gtk.h> - -#include "e-util/e-util.h" - -#include "e-cell-checkbox.h" -#include "e-cell-date.h" -#include "e-cell-number.h" -#include "e-cell-pixbuf.h" -#include "e-cell-size.h" -#include "e-cell-text.h" -#include "e-cell-tree.h" -#include "e-table-extras.h" -#include "e-table-sorting-utils.h" - -#define E_TABLE_EXTRAS_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), E_TYPE_TABLE_EXTRAS, ETableExtrasPrivate)) - -struct _ETableExtrasPrivate { - GHashTable *cells; - GHashTable *compares; - GHashTable *icon_names; - GHashTable *searches; -}; - -/* workaround for avoiding API breakage */ -#define ete_get_type e_table_extras_get_type -G_DEFINE_TYPE (ETableExtras, ete, G_TYPE_OBJECT) - -static void -ete_finalize (GObject *object) -{ - ETableExtrasPrivate *priv; - - priv = E_TABLE_EXTRAS_GET_PRIVATE (object); - - if (priv->cells) { - g_hash_table_destroy (priv->cells); - priv->cells = NULL; - } - - if (priv->compares) { - g_hash_table_destroy (priv->compares); - priv->compares = NULL; - } - - if (priv->searches) { - g_hash_table_destroy (priv->searches); - priv->searches = NULL; - } - - if (priv->icon_names) { - g_hash_table_destroy (priv->icon_names); - priv->icon_names = NULL; - } - - G_OBJECT_CLASS (ete_parent_class)->finalize (object); -} - -static void -ete_class_init (ETableExtrasClass *class) -{ - GObjectClass *object_class; - - g_type_class_add_private (class, sizeof (ETableExtrasPrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->finalize = ete_finalize; -} - -static gint -e_strint_compare (gconstpointer data1, - gconstpointer data2) -{ - gint int1 = atoi (data1); - gint int2 = atoi (data2); - - return e_int_compare (GINT_TO_POINTER (int1), GINT_TO_POINTER (int2)); -} - -/* UTF-8 strncasecmp - not optimized */ - -static gint -g_utf8_strncasecmp (const gchar *s1, - const gchar *s2, - guint n) -{ - gunichar c1, c2; - - g_return_val_if_fail (s1 != NULL && g_utf8_validate (s1, -1, NULL), 0); - g_return_val_if_fail (s2 != NULL && g_utf8_validate (s2, -1, NULL), 0); - - while (n && *s1 && *s2) - { - - n -= 1; - - c1 = g_unichar_tolower (g_utf8_get_char (s1)); - c2 = g_unichar_tolower (g_utf8_get_char (s2)); - - /* Collation is locale-dependent, so this - * totally fails to do the right thing. */ - if (c1 != c2) - return c1 < c2 ? -1 : 1; - - s1 = g_utf8_next_char (s1); - s2 = g_utf8_next_char (s2); - } - - if (n == 0 || (*s1 == '\0' && *s2 == '\0')) - return 0; - - return *s1 ? 1 : -1; -} - -static gboolean -e_string_search (gconstpointer haystack, - const gchar *needle) -{ - gint length; - if (haystack == NULL) - return FALSE; - - length = g_utf8_strlen (needle, -1); - if (g_utf8_strncasecmp (haystack, needle, length) == 0) - return TRUE; - else - return FALSE; -} - -static gint -e_table_str_case_compare (gconstpointer x, - gconstpointer y, - gpointer cmp_cache) -{ - const gchar *cx = NULL, *cy = NULL; - - if (!cmp_cache) - return e_str_case_compare (x, y); - - if (x == NULL || y == NULL) { - if (x == y) - return 0; - else - return x ? -1 : 1; - } - - #define prepare_value(_z, _cz) \ - _cz = e_table_sorting_utils_lookup_cmp_cache (cmp_cache, _z); \ - if (!_cz) { \ - gchar *tmp = g_utf8_casefold (_z, -1); \ - _cz = g_utf8_collate_key (tmp, -1); \ - g_free (tmp); \ - \ - e_table_sorting_utils_add_to_cmp_cache ( \ - cmp_cache, _z, (gchar *) _cz); \ - } - - prepare_value (x, cx); - prepare_value (y, cy); - - #undef prepare_value - - return strcmp (cx, cy); -} - -static gint -e_table_collate_compare (gconstpointer x, - gconstpointer y, - gpointer cmp_cache) -{ - const gchar *cx = NULL, *cy = NULL; - - if (!cmp_cache) - return e_collate_compare (x, y); - - if (x == NULL || y == NULL) { - if (x == y) - return 0; - else - return x ? -1 : 1; - } - - #define prepare_value(_z, _cz) \ - _cz = e_table_sorting_utils_lookup_cmp_cache (cmp_cache, _z); \ - if (!_cz) { \ - _cz = g_utf8_collate_key (_z, -1); \ - \ - e_table_sorting_utils_add_to_cmp_cache ( \ - cmp_cache, _z, (gchar *) _cz); \ - } - - prepare_value (x, cx); - prepare_value (y, cy); - - #undef prepare_value - - return strcmp (cx, cy); -} - -static void -safe_unref (gpointer object) -{ - if (object != NULL) - g_object_unref (object); -} - -static void -ete_init (ETableExtras *extras) -{ - ECell *cell, *sub_cell; - - extras->priv = E_TABLE_EXTRAS_GET_PRIVATE (extras); - - extras->priv->cells = g_hash_table_new_full ( - g_str_hash, g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) safe_unref); - - extras->priv->compares = g_hash_table_new_full ( - g_str_hash, g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) NULL); - - extras->priv->icon_names = g_hash_table_new_full ( - g_str_hash, g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) g_free); - - extras->priv->searches = g_hash_table_new_full ( - g_str_hash, g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) NULL); - - e_table_extras_add_compare ( - extras, "string", - (GCompareDataFunc) e_str_compare); - e_table_extras_add_compare ( - extras, "stringcase", - (GCompareDataFunc) e_table_str_case_compare); - e_table_extras_add_compare ( - extras, "collate", - (GCompareDataFunc) e_table_collate_compare); - e_table_extras_add_compare ( - extras, "integer", - (GCompareDataFunc) e_int_compare); - e_table_extras_add_compare ( - extras, "string-integer", - (GCompareDataFunc) e_strint_compare); - - e_table_extras_add_search (extras, "string", e_string_search); - - cell = e_cell_checkbox_new (); - e_table_extras_add_cell (extras, "checkbox", cell); - g_object_unref (cell); - - cell = e_cell_date_new (NULL, GTK_JUSTIFY_LEFT); - e_table_extras_add_cell (extras, "date", cell); - g_object_unref (cell); - - cell = e_cell_number_new (NULL, GTK_JUSTIFY_RIGHT); - e_table_extras_add_cell (extras, "number", cell); - g_object_unref (cell); - - cell = e_cell_pixbuf_new (); - e_table_extras_add_cell (extras, "pixbuf", cell); - g_object_unref (cell); - - cell = e_cell_size_new (NULL, GTK_JUSTIFY_RIGHT); - e_table_extras_add_cell (extras, "size", cell); - g_object_unref (cell); - - cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT); - e_table_extras_add_cell (extras, "string", cell); - g_object_unref (cell); - - sub_cell = e_cell_text_new (NULL, GTK_JUSTIFY_LEFT); - cell = e_cell_tree_new (TRUE, sub_cell); - e_table_extras_add_cell (extras, "tree-string", cell); - g_object_unref (sub_cell); - g_object_unref (cell); -} - -ETableExtras * -e_table_extras_new (void) -{ - return g_object_new (E_TYPE_TABLE_EXTRAS, NULL); -} - -void -e_table_extras_add_cell (ETableExtras *extras, - const gchar *id, - ECell *cell) -{ - g_return_if_fail (E_IS_TABLE_EXTRAS (extras)); - g_return_if_fail (id != NULL); - - if (cell != NULL) - g_object_ref_sink (cell); - - g_hash_table_insert (extras->priv->cells, g_strdup (id), cell); -} - -ECell * -e_table_extras_get_cell (ETableExtras *extras, - const gchar *id) -{ - g_return_val_if_fail (E_IS_TABLE_EXTRAS (extras), NULL); - g_return_val_if_fail (id != NULL, NULL); - - return g_hash_table_lookup (extras->priv->cells, id); -} - -void -e_table_extras_add_compare (ETableExtras *extras, - const gchar *id, - GCompareDataFunc compare) -{ - g_return_if_fail (E_IS_TABLE_EXTRAS (extras)); - g_return_if_fail (id != NULL); - - g_hash_table_insert ( - extras->priv->compares, - g_strdup (id), (gpointer) compare); -} - -GCompareDataFunc -e_table_extras_get_compare (ETableExtras *extras, - const gchar *id) -{ - g_return_val_if_fail (E_IS_TABLE_EXTRAS (extras), NULL); - g_return_val_if_fail (id != NULL, NULL); - - return g_hash_table_lookup (extras->priv->compares, id); -} - -void -e_table_extras_add_search (ETableExtras *extras, - const gchar *id, - ETableSearchFunc search) -{ - g_return_if_fail (E_IS_TABLE_EXTRAS (extras)); - g_return_if_fail (id != NULL); - - g_hash_table_insert ( - extras->priv->searches, - g_strdup (id), (gpointer) search); -} - -ETableSearchFunc -e_table_extras_get_search (ETableExtras *extras, - const gchar *id) -{ - g_return_val_if_fail (E_IS_TABLE_EXTRAS (extras), NULL); - g_return_val_if_fail (id != NULL, NULL); - - return g_hash_table_lookup (extras->priv->searches, id); -} - -void -e_table_extras_add_icon_name (ETableExtras *extras, - const gchar *id, - const gchar *icon_name) -{ - g_return_if_fail (E_IS_TABLE_EXTRAS (extras)); - g_return_if_fail (id != NULL); - - g_hash_table_insert ( - extras->priv->icon_names, - g_strdup (id), g_strdup (icon_name)); -} - -const gchar * -e_table_extras_get_icon_name (ETableExtras *extras, - const gchar *id) -{ - g_return_val_if_fail (E_IS_TABLE_EXTRAS (extras), NULL); - g_return_val_if_fail (id != NULL, NULL); - - return g_hash_table_lookup (extras->priv->icon_names, id); -} diff --git a/widgets/table/e-table-extras.h b/widgets/table/e-table-extras.h deleted file mode 100644 index 6b1ed4200f..0000000000 --- a/widgets/table/e-table-extras.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_TABLE_EXTRAS_H -#define E_TABLE_EXTRAS_H - -#include <table/e-cell.h> -#include <gdk-pixbuf/gdk-pixbuf.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_EXTRAS \ - (e_table_extras_get_type ()) -#define E_TABLE_EXTRAS(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_EXTRAS, ETableExtras)) -#define E_TABLE_EXTRAS_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_EXTRAS, ETableExtrasClass)) -#define E_IS_TABLE_EXTRAS(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_EXTRAS)) -#define E_IS_TABLE_EXTRAS_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_EXTRAS)) -#define E_TABLE_EXTRAS_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_EXTRAS, ETableExtrasClass)) - -G_BEGIN_DECLS - -typedef struct _ETableExtras ETableExtras; -typedef struct _ETableExtrasClass ETableExtrasClass; -typedef struct _ETableExtrasPrivate ETableExtrasPrivate; - -struct _ETableExtras { - GObject parent; - ETableExtrasPrivate *priv; -}; - -struct _ETableExtrasClass { - GObjectClass parent_class; -}; - -GType e_table_extras_get_type (void) G_GNUC_CONST; -ETableExtras * e_table_extras_new (void); -void e_table_extras_add_cell (ETableExtras *extras, - const gchar *id, - ECell *cell); -ECell * e_table_extras_get_cell (ETableExtras *extras, - const gchar *id); -void e_table_extras_add_compare (ETableExtras *extras, - const gchar *id, - GCompareDataFunc compare); -GCompareDataFunc e_table_extras_get_compare (ETableExtras *extras, - const gchar *id); -void e_table_extras_add_search (ETableExtras *extras, - const gchar *id, - ETableSearchFunc search); -ETableSearchFunc - e_table_extras_get_search (ETableExtras *extras, - const gchar *id); -void e_table_extras_add_icon_name (ETableExtras *extras, - const gchar *id, - const gchar *icon_name); -const gchar * e_table_extras_get_icon_name (ETableExtras *extras, - const gchar *id); - -G_END_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 fb005ed30f..0000000000 --- a/widgets/table/e-table-field-chooser-dialog.c +++ /dev/null @@ -1,236 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtk.h> - -#include <glib/gi18n.h> -#include "e-util/e-util.h" - -#include "e-table-field-chooser-dialog.h" - -enum { - PROP_0, - PROP_DND_CODE, - PROP_FULL_HEADER, - PROP_HEADER -}; - -G_DEFINE_TYPE ( - ETableFieldChooserDialog, - e_table_field_chooser_dialog, - GTK_TYPE_DIALOG) - -static void -e_table_field_chooser_dialog_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ETableFieldChooserDialog *etfcd = E_TABLE_FIELD_CHOOSER_DIALOG (object); - switch (property_id) { - case PROP_DND_CODE: - g_free (etfcd->dnd_code); - etfcd->dnd_code = g_strdup (g_value_get_string (value)); - if (etfcd->etfc) - g_object_set ( - etfcd->etfc, - "dnd_code", etfcd->dnd_code, - NULL); - break; - case PROP_FULL_HEADER: - if (etfcd->full_header) - g_object_unref (etfcd->full_header); - if (g_value_get_object (value)) - etfcd->full_header = E_TABLE_HEADER (g_value_get_object (value)); - else - etfcd->full_header = NULL; - if (etfcd->full_header) - g_object_ref (etfcd->full_header); - if (etfcd->etfc) - g_object_set ( - etfcd->etfc, - "full_header", etfcd->full_header, - NULL); - break; - case PROP_HEADER: - if (etfcd->header) - g_object_unref (etfcd->header); - if (g_value_get_object (value)) - etfcd->header = E_TABLE_HEADER (g_value_get_object (value)); - else - etfcd->header = NULL; - if (etfcd->header) - g_object_ref (etfcd->header); - if (etfcd->etfc) - g_object_set ( - etfcd->etfc, - "header", etfcd->header, - NULL); - break; - default: - break; - } -} - -static void -e_table_field_chooser_dialog_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ETableFieldChooserDialog *etfcd = E_TABLE_FIELD_CHOOSER_DIALOG (object); - switch (property_id) { - case PROP_DND_CODE: - g_value_set_string (value, etfcd->dnd_code); - break; - case PROP_FULL_HEADER: - g_value_set_object (value, etfcd->full_header); - break; - case PROP_HEADER: - g_value_set_object (value, etfcd->header); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -e_table_field_chooser_dialog_dispose (GObject *object) -{ - ETableFieldChooserDialog *etfcd = E_TABLE_FIELD_CHOOSER_DIALOG (object); - - if (etfcd->dnd_code) - g_free (etfcd->dnd_code); - etfcd->dnd_code = NULL; - - if (etfcd->full_header) - g_object_unref (etfcd->full_header); - etfcd->full_header = NULL; - - if (etfcd->header) - g_object_unref (etfcd->header); - etfcd->header = NULL; - - G_OBJECT_CLASS (e_table_field_chooser_dialog_parent_class)->dispose (object); -} - -static void -e_table_field_chooser_dialog_response (GtkDialog *dialog, - gint id) -{ - if (id == GTK_RESPONSE_OK) - gtk_widget_destroy (GTK_WIDGET (dialog)); -} - -static void -e_table_field_chooser_dialog_class_init (ETableFieldChooserDialogClass *class) -{ - GObjectClass *object_class; - GtkDialogClass *dialog_class; - - object_class = G_OBJECT_CLASS (class); - object_class->set_property = e_table_field_chooser_dialog_set_property; - object_class->get_property = e_table_field_chooser_dialog_get_property; - object_class->dispose = e_table_field_chooser_dialog_dispose; - - dialog_class = GTK_DIALOG_CLASS (class); - dialog_class->response = e_table_field_chooser_dialog_response; - - g_object_class_install_property ( - object_class, - PROP_DND_CODE, - g_param_spec_string ( - "dnd_code", - "DnD code", - NULL, - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_FULL_HEADER, - g_param_spec_object ( - "full_header", - "Full Header", - NULL, - E_TYPE_TABLE_HEADER, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_HEADER, - g_param_spec_object ( - "header", - "Header", - NULL, - E_TYPE_TABLE_HEADER, - G_PARAM_READWRITE)); -} - -static void -e_table_field_chooser_dialog_init (ETableFieldChooserDialog *e_table_field_chooser_dialog) -{ - GtkDialog *dialog; - GtkWidget *content_area; - GtkWidget *widget; - - dialog = GTK_DIALOG (e_table_field_chooser_dialog); - - e_table_field_chooser_dialog->etfc = NULL; - e_table_field_chooser_dialog->dnd_code = g_strdup (""); - e_table_field_chooser_dialog->full_header = NULL; - e_table_field_chooser_dialog->header = NULL; - - gtk_dialog_add_button (dialog, GTK_STOCK_CLOSE, GTK_RESPONSE_OK); - - gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE); - - widget = e_table_field_chooser_new (); - e_table_field_chooser_dialog->etfc = E_TABLE_FIELD_CHOOSER (widget); - - g_object_set ( - widget, - "dnd_code", e_table_field_chooser_dialog->dnd_code, - "full_header", e_table_field_chooser_dialog->full_header, - "header", e_table_field_chooser_dialog->header, - NULL); - - content_area = gtk_dialog_get_content_area (dialog); - gtk_box_pack_start (GTK_BOX (content_area), widget, TRUE, TRUE, 0); - - gtk_widget_show (GTK_WIDGET (widget)); - - gtk_window_set_title (GTK_WINDOW (dialog), _("Add a Column")); -} - -GtkWidget * -e_table_field_chooser_dialog_new (void) -{ - return g_object_new (E_TYPE_TABLE_FIELD_CHOOSER_DIALOG, NULL); -} - 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 bd378bc89d..0000000000 --- a/widgets/table/e-table-field-chooser-dialog.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __E_TABLE_FIELD_CHOOSER_DIALOG_H__ -#define __E_TABLE_FIELD_CHOOSER_DIALOG_H__ - -#include <gtk/gtk.h> -#include <table/e-table-field-chooser.h> -#include <table/e-table-header.h> - -#define E_TYPE_TABLE_FIELD_CHOOSER_DIALOG \ - (e_table_field_chooser_dialog_get_type ()) -#define E_TABLE_FIELD_CHOOSER_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_FIELD_CHOOSER_DIALOG, ETableFieldChooserDialog)) -#define E_TABLE_FIELD_CHOOSER_DIALOG_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_FIELD_CHOOSER_DIALOG, ETableFieldChooserDialogClass)) -#define E_IS_TABLE_FIELD_CHOOSER_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_FIELD_CHOOSER_DIALOG)) -#define E_IS_TABLE_FIELD_CHOOSER_DIALOG_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_FIELD_CHOOSER_DIALOG)) -#define E_TABLE_FIELD_CHOOSER_DIALOG_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_FIELD_CHOOSER_DIALOG, ETableFieldChooserDialogClass)) - -G_BEGIN_DECLS - -typedef struct _ETableFieldChooserDialog ETableFieldChooserDialog; -typedef struct _ETableFieldChooserDialogClass ETableFieldChooserDialogClass; - -struct _ETableFieldChooserDialog { - GtkDialog parent; - - /* item specific fields */ - ETableFieldChooser *etfc; - gchar *dnd_code; - ETableHeader *full_header; - ETableHeader *header; -}; - -struct _ETableFieldChooserDialogClass { - GtkDialogClass parent_class; -}; - -GType e_table_field_chooser_dialog_get_type (void) G_GNUC_CONST; -GtkWidget * e_table_field_chooser_dialog_new (void); - -G_END_DECLS - -#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 3c6c33cdcf..0000000000 --- a/widgets/table/e-table-field-chooser-item.c +++ /dev/null @@ -1,751 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include <gtk/gtk.h> -#include <libgnomecanvas/libgnomecanvas.h> -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include <glib/gi18n.h> -#include "e-util/e-util.h" -#include "libevolution-utils/e-xml-utils.h" -#include "misc/e-canvas.h" - -#include "e-table-col-dnd.h" -#include "e-table-defines.h" -#include "e-table-field-chooser-item.h" -#include "e-table-header-utils.h" -#include "e-table-header.h" - -#define d(x) - -#if 0 -enum { - BUTTON_PRESSED, - LAST_SIGNAL -}; - -static guint etfci_signals[LAST_SIGNAL] = { 0, }; -#endif - -/* workaround for avoiding API breakage */ -#define etfci_get_type e_table_field_chooser_item_get_type -G_DEFINE_TYPE (ETableFieldChooserItem, etfci, GNOME_TYPE_CANVAS_ITEM) - -static void etfci_drop_table_header (ETableFieldChooserItem *etfci); -static void etfci_drop_full_header (ETableFieldChooserItem *etfci); - -enum { - PROP_0, - PROP_FULL_HEADER, - PROP_HEADER, - PROP_DND_CODE, - PROP_WIDTH, - PROP_HEIGHT -}; - -static void -etfci_dispose (GObject *object) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (object); - - etfci_drop_table_header (etfci); - etfci_drop_full_header (etfci); - - if (etfci->combined_header) - g_object_unref (etfci->combined_header); - etfci->combined_header = NULL; - - if (etfci->font_desc) - pango_font_description_free (etfci->font_desc); - etfci->font_desc = NULL; - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (etfci_parent_class)->dispose (object); -} - -static gint -etfci_find_button (ETableFieldChooserItem *etfci, - gdouble loc) -{ - gint i; - gint count; - gdouble height = 0; - - count = e_table_header_count (etfci->combined_header); - for (i = 0; i < count; i++) { - ETableCol *ecol; - - ecol = e_table_header_get_column (etfci->combined_header, i); - if (ecol->disabled) - continue; - height += e_table_header_compute_height ( - ecol, GTK_WIDGET (GNOME_CANVAS_ITEM (etfci)->canvas)); - if (height > loc) - return i; - } - return MAX (0, count - 1); -} - -static void -etfci_rebuild_combined (ETableFieldChooserItem *etfci) -{ - gint count; - GHashTable *hash; - gint i; - - if (etfci->combined_header != NULL) - g_object_unref (etfci->combined_header); - - etfci->combined_header = e_table_header_new (); - - hash = g_hash_table_new (NULL, NULL); - - count = e_table_header_count (etfci->header); - for (i = 0; i < count; i++) { - ETableCol *ecol = e_table_header_get_column (etfci->header, i); - if (ecol->disabled) - continue; - g_hash_table_insert ( - hash, GINT_TO_POINTER (ecol->col_idx), - GINT_TO_POINTER (1)); - } - - count = e_table_header_count (etfci->full_header); - for (i = 0; i < count; i++) { - ETableCol *ecol = e_table_header_get_column (etfci->full_header, i); - if (ecol->disabled) - continue; - if (!(GPOINTER_TO_INT (g_hash_table_lookup ( - hash, GINT_TO_POINTER (ecol->col_idx))))) - e_table_header_add_column (etfci->combined_header, ecol, -1); - } - - g_hash_table_destroy (hash); -} - -static void -etfci_reflow (GnomeCanvasItem *item, - gint flags) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - gdouble old_height; - gint i; - gint count; - gdouble height = 0; - - etfci_rebuild_combined (etfci); - - old_height = etfci->height; - - count = e_table_header_count (etfci->combined_header); - for (i = 0; i < count; i++) { - ETableCol *ecol; - - ecol = e_table_header_get_column (etfci->combined_header, i); - if (ecol->disabled) - continue; - height += e_table_header_compute_height ( - ecol, GTK_WIDGET (GNOME_CANVAS_ITEM (etfci)->canvas)); - } - - 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, - const cairo_matrix_t *i2c, - gint flags) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - gdouble x1, y1, x2, y2; - - if (GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)->update) - GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)->update ( - item, i2c, flags); - - x1 = y1 = 0; - x2 = etfci->width; - y2 = etfci->height; - - gnome_canvas_matrix_transform_rect (i2c, &x1, &y1, &x2, &y2); - - if (item->x1 != x1 || - item->y1 != y1 || - item->x2 != x2 || - item->y2 != y2) - { - gnome_canvas_request_redraw ( - item->canvas, item->x1, - item->y1, item->x2, item->y2); - item->x1 = x1; - item->y1 = y1; - item->x2 = x2; - item->y2 = y2; -/* FIXME: Group Child bounds !? */ -#if 0 - gnome_canvas_group_child_bounds ( - GNOME_CANVAS_GROUP (item->parent), item); -#endif - } - gnome_canvas_request_redraw ( - item->canvas, item->x1, item->y1, item->x2, item->y2); -} - -static void -etfci_font_load (ETableFieldChooserItem *etfci) -{ - GtkWidget *widget; - GtkStyle *style; - - if (etfci->font_desc) - pango_font_description_free (etfci->font_desc); - - widget = GTK_WIDGET (GNOME_CANVAS_ITEM (etfci)->canvas); - style = gtk_widget_get_style (widget); - etfci->font_desc = pango_font_description_copy (style->font_desc); -} - -static void -etfci_drop_full_header (ETableFieldChooserItem *etfci) -{ - GObject *header; - - if (!etfci->full_header) - return; - - header = G_OBJECT (etfci->full_header); - if (etfci->full_header_structure_change_id) - g_signal_handler_disconnect ( - header, etfci->full_header_structure_change_id); - if (etfci->full_header_dimension_change_id) - g_signal_handler_disconnect ( - header, etfci->full_header_dimension_change_id); - etfci->full_header_structure_change_id = 0; - etfci->full_header_dimension_change_id = 0; - - if (header) - g_object_unref (header); - etfci->full_header = NULL; - etfci->height = 0; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etfci)); -} - -static void -full_header_structure_changed (ETableHeader *header, - ETableFieldChooserItem *etfci) -{ - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etfci)); -} - -static void -full_header_dimension_changed (ETableHeader *header, - gint col, - ETableFieldChooserItem *etfci) -{ - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etfci)); -} - -static void -etfci_add_full_header (ETableFieldChooserItem *etfci, - ETableHeader *header) -{ - etfci->full_header = header; - g_object_ref (etfci->full_header); - - etfci->full_header_structure_change_id = g_signal_connect ( - header, "structure_change", - G_CALLBACK (full_header_structure_changed), etfci); - etfci->full_header_dimension_change_id = g_signal_connect ( - header, "dimension_change", - G_CALLBACK (full_header_dimension_changed), etfci); - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etfci)); -} - -static void -etfci_drop_table_header (ETableFieldChooserItem *etfci) -{ - GObject *header; - - if (!etfci->header) - return; - - header = G_OBJECT (etfci->header); - if (etfci->table_header_structure_change_id) - g_signal_handler_disconnect ( - header, etfci->table_header_structure_change_id); - if (etfci->table_header_dimension_change_id) - g_signal_handler_disconnect ( - header, etfci->table_header_dimension_change_id); - etfci->table_header_structure_change_id = 0; - etfci->table_header_dimension_change_id = 0; - - if (header) - g_object_unref (header); - etfci->header = NULL; - etfci->height = 0; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etfci)); -} - -static void -table_header_structure_changed (ETableHeader *header, - ETableFieldChooserItem *etfci) -{ - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etfci)); -} - -static void -table_header_dimension_changed (ETableHeader *header, - gint col, - ETableFieldChooserItem *etfci) -{ - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etfci)); -} - -static void -etfci_add_table_header (ETableFieldChooserItem *etfci, - ETableHeader *header) -{ - etfci->header = header; - g_object_ref (etfci->header); - - etfci->table_header_structure_change_id = g_signal_connect ( - header, "structure_change", - G_CALLBACK (table_header_structure_changed), etfci); - etfci->table_header_dimension_change_id = g_signal_connect ( - header, "dimension_change", - G_CALLBACK (table_header_dimension_changed), etfci); - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etfci)); -} - -static void -etfci_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - GnomeCanvasItem *item; - ETableFieldChooserItem *etfci; - - item = GNOME_CANVAS_ITEM (object); - etfci = E_TABLE_FIELD_CHOOSER_ITEM (object); - - switch (property_id) { - case PROP_FULL_HEADER: - etfci_drop_full_header (etfci); - if (g_value_get_object (value)) - etfci_add_full_header ( - etfci, E_TABLE_HEADER ( - g_value_get_object (value))); - break; - - case PROP_HEADER: - etfci_drop_table_header (etfci); - if (g_value_get_object (value)) - etfci_add_table_header ( - etfci, E_TABLE_HEADER ( - g_value_get_object (value))); - break; - - case PROP_DND_CODE: - g_free (etfci->dnd_code); - etfci->dnd_code = g_strdup (g_value_get_string (value)); - break; - - case PROP_WIDTH: - etfci->width = g_value_get_double (value); - gnome_canvas_item_request_update (item); - break; - } -} - -static void -etfci_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ETableFieldChooserItem *etfci; - - etfci = E_TABLE_FIELD_CHOOSER_ITEM (object); - - switch (property_id) { - - case PROP_DND_CODE: - g_value_set_string (value, etfci->dnd_code); - break; - case PROP_WIDTH: - g_value_set_double (value, etfci->width); - break; - case PROP_HEIGHT: - g_value_set_double (value, etfci->height); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - 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]), - (guchar *) 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); - - if (GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)-> realize) - (*GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)->realize)(item); - - if (!etfci->font_desc) - etfci_font_load (etfci); - - etfci->drag_end_id = g_signal_connect ( - item->canvas, "drag_end", - G_CALLBACK (etfci_drag_end), etfci); - etfci->drag_data_get_id = g_signal_connect ( - item->canvas, "drag_data_get", - G_CALLBACK (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_desc) - pango_font_description_free (etfci->font_desc); - etfci->font_desc = NULL; - - g_signal_handler_disconnect (item->canvas, etfci->drag_end_id); - etfci->drag_end_id = 0; - g_signal_handler_disconnect (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, - cairo_t *cr, - gint x, - gint y, - gint width, - gint height) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - gint rows; - gint y1, y2; - gint row; - - if (etfci->combined_header == NULL) - return; - - rows = e_table_header_count (etfci->combined_header); - - y1 = y2 = 0; - for (row = 0; row < rows; row++, y1 = y2) { - ETableCol *ecol; - - ecol = e_table_header_get_column (etfci->combined_header, row); - - if (ecol->disabled) - continue; - - y2 += e_table_header_compute_height (ecol, GTK_WIDGET (canvas)); - - if (y1 > (y + height)) - break; - - if (y2 < y) - continue; - - cairo_save (cr); - - e_table_header_draw_button ( - cr, ecol, - GTK_WIDGET (canvas), - -x, y1 - y, - width, height, - etfci->width, y2 - y1, - E_TABLE_COL_ARROW_NONE); - - cairo_restore (cr); - } -} - -static GnomeCanvasItem * -etfci_point (GnomeCanvasItem *item, - gdouble x, - gdouble y, - gint cx, - gint cy) -{ - return item; -} - -static gboolean -etfci_maybe_start_drag (ETableFieldChooserItem *etfci, - gint x, - gint 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, - gdouble x, - gdouble y) -{ - GtkWidget *widget = GTK_WIDGET (GNOME_CANVAS_ITEM (etfci)->canvas); - GtkTargetList *list; - GdkDragContext *context; - ETableCol *ecol; - cairo_surface_t *cs; - cairo_t *cr; - gint drag_col; - gint button_height; - - GtkTargetEntry etfci_drag_types[] = { - { (gchar *) TARGET_ETABLE_COL_TYPE, 0, TARGET_ETABLE_COL_HEADER }, - }; - - if (etfci->combined_header == NULL) - return; - - drag_col = etfci_find_button (etfci, y); - - if (drag_col < 0 || drag_col > e_table_header_count (etfci->combined_header)) - return; - - ecol = e_table_header_get_column (etfci->combined_header, drag_col); - - if (ecol->disabled) - return; - - etfci->drag_col = ecol->col_idx; - - etfci_drag_types[0].target = g_strdup_printf ( - "%s-%s", etfci_drag_types[0].target, etfci->dnd_code); - d (g_print ("etfci - %s\n", etfci_drag_types[0].target)); - list = gtk_target_list_new (etfci_drag_types, G_N_ELEMENTS (etfci_drag_types)); - context = gtk_drag_begin (widget, list, GDK_ACTION_MOVE, 1, event); - g_free ((gpointer) etfci_drag_types[0].target); - - button_height = e_table_header_compute_height (ecol, widget); - cs = cairo_image_surface_create ( - CAIRO_FORMAT_ARGB32, - etfci->width, button_height); - cr = cairo_create (cs); - - e_table_header_draw_button ( - cr, ecol, - widget, 0, 0, - etfci->width, button_height, - etfci->width, button_height, - E_TABLE_COL_ARROW_NONE); - - gtk_drag_set_icon_surface (context, cs); - - cairo_surface_destroy (cs); - cairo_destroy (cr); - etfci->maybe_drag = FALSE; -} - -/* - * Handles the events on the ETableFieldChooserItem - */ -static gint -etfci_event (GnomeCanvasItem *item, - GdkEvent *e) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - gint 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 (ETableFieldChooserItemClass *class) -{ - GnomeCanvasItemClass *item_class = GNOME_CANVAS_ITEM_CLASS (class); - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->dispose = etfci_dispose; - object_class->set_property = etfci_set_property; - object_class->get_property = etfci_get_property; - - 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; - - g_object_class_install_property ( - object_class, - PROP_DND_CODE, - g_param_spec_string ( - "dnd_code", - "DnD code", - NULL, - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_FULL_HEADER, - g_param_spec_object ( - "full_header", - "Full Header", - NULL, - E_TYPE_TABLE_HEADER, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_HEADER, - g_param_spec_object ( - "header", - "Header", - NULL, - E_TYPE_TABLE_HEADER, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_WIDTH, - g_param_spec_double ( - "width", - "Width", - NULL, - 0, G_MAXDOUBLE, 0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_HEIGHT, - g_param_spec_double ( - "height", - "Height", - NULL, - 0, G_MAXDOUBLE, 0, - G_PARAM_READABLE)); -} - -static void -etfci_init (ETableFieldChooserItem *etfci) -{ - etfci->full_header = NULL; - etfci->header = NULL; - etfci->combined_header = NULL; - - etfci->height = etfci->width = 0; - - etfci->font_desc = NULL; - - etfci->full_header_structure_change_id = 0; - etfci->full_header_dimension_change_id = 0; - etfci->table_header_structure_change_id = 0; - etfci->table_header_dimension_change_id = 0; - - etfci->dnd_code = NULL; - - etfci->maybe_drag = 0; - etfci->drag_end_id = 0; - - e_canvas_item_set_reflow_callback (GNOME_CANVAS_ITEM (etfci), etfci_reflow); -} - 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 f08b94ac6f..0000000000 --- a/widgets/table/e-table-field-chooser-item.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_FIELD_CHOOSER_ITEM_H_ -#define _E_TABLE_FIELD_CHOOSER_ITEM_H_ - -#include <libgnomecanvas/libgnomecanvas.h> -#include <libxml/tree.h> -#include <table/e-table-header.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_FIELD_CHOOSER_ITEM \ - (e_table_field_chooser_item_get_type ()) -#define E_TABLE_FIELD_CHOOSER_ITEM(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_FIELD_CHOOSER_ITEM, ETableFieldChooserItem)) -#define E_TABLE_FIELD_CHOOSER_ITEM_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_FIELD_CHOOSER_ITEM, ETableFieldChooserItemClass)) -#define E_IS_TABLE_FIELD_CHOOSER_ITEM(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_FIELD_CHOOSER_ITEM)) -#define E_IS_TABLE_FIELD_CHOOSER_ITEM_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_FIELD_CHOOSER_ITEM)) -#define E_TABLE_FIELD_CHOOSER_ITEM_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_FIELD_CHOOSER_ITEM, ETableFieldChooserItemClass)) - -G_BEGIN_DECLS - -typedef struct _ETableFieldChooserItem ETableFieldChooserItem; -typedef struct _ETableFieldChooserItemClass ETableFieldChooserItemClass; - -struct _ETableFieldChooserItem { - GnomeCanvasItem parent; - - ETableHeader *full_header; - ETableHeader *header; - ETableHeader *combined_header; - - gdouble height, width; - - PangoFontDescription *font_desc; - - /* - * Ids - */ - gint full_header_structure_change_id, full_header_dimension_change_id; - gint table_header_structure_change_id, table_header_dimension_change_id; - - gchar *dnd_code; - - /* - * For dragging columns - */ - guint maybe_drag : 1; - gint click_x, click_y; - gint drag_col; - guint drag_data_get_id; - guint drag_end_id; -}; - -struct _ETableFieldChooserItemClass { - GnomeCanvasItemClass parent_class; -}; - -GType e_table_field_chooser_item_get_type (void) G_GNUC_CONST; - -G_END_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 50f8267109..0000000000 --- a/widgets/table/e-table-field-chooser.c +++ /dev/null @@ -1,337 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtk.h> -#include <libgnomecanvas/libgnomecanvas.h> - -#include <glib/gi18n.h> -#include "e-util/e-util.h" -#include "e-util/e-util-private.h" - -#include "misc/e-canvas.h" - -#include "e-table-field-chooser.h" -#include "e-table-field-chooser-item.h" - -static void e_table_field_chooser_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); -static void e_table_field_chooser_get_property (GObject *object, guint property_id, GValue *value, GParamSpec *pspec); -static void e_table_field_chooser_dispose (GObject *object); - -enum { - PROP_0, - PROP_FULL_HEADER, - PROP_HEADER, - PROP_DND_CODE -}; - -G_DEFINE_TYPE (ETableFieldChooser, e_table_field_chooser, GTK_TYPE_VBOX) - -static void -e_table_field_chooser_class_init (ETableFieldChooserClass *class) -{ - GObjectClass *object_class; - - object_class = (GObjectClass *) class; - - object_class->set_property = e_table_field_chooser_set_property; - object_class->get_property = e_table_field_chooser_get_property; - object_class->dispose = e_table_field_chooser_dispose; - - g_object_class_install_property ( - object_class, - PROP_DND_CODE, - g_param_spec_string ( - "dnd_code", - "DnD code", - NULL, - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_FULL_HEADER, - g_param_spec_object ( - "full_header", - "Full Header", - NULL, - E_TYPE_TABLE_HEADER, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_HEADER, - g_param_spec_object ( - "header", - "Header", - NULL, - E_TYPE_TABLE_HEADER, - G_PARAM_READWRITE)); -} - -static void -ensure_nonzero_step_increments (ETableFieldChooser *etfc) -{ - GtkAdjustment *va, *ha; - - va = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (etfc->canvas)); - ha = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (etfc->canvas)); - - /* - it looks pretty complicated to get height of column header - so use 16 pixels which should be OK - */ - if (va) - gtk_adjustment_set_step_increment (va, 16.0); - if (ha) - gtk_adjustment_set_step_increment (ha, 16.0); -} - -static void allocate_callback (GtkWidget *canvas, GtkAllocation *allocation, ETableFieldChooser *etfc) -{ - gdouble height; - etfc->last_alloc = *allocation; - gnome_canvas_item_set ( - etfc->item, - "width", (gdouble) allocation->width, - NULL); - g_object_get ( - 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", (gdouble) allocation->width, - "y2", (gdouble) height, - NULL); - ensure_nonzero_step_increments (etfc); -} - -static void resize (GnomeCanvas *canvas, ETableFieldChooser *etfc) -{ - gdouble height; - g_object_get ( - 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", (gdouble) etfc->last_alloc.width, - "y2", (gdouble) height, - NULL); - ensure_nonzero_step_increments (etfc); -} - -static GtkWidget * -create_content (GnomeCanvas **canvas) -{ - GtkWidget *vbox_top; - GtkWidget *label1; - GtkWidget *scrolledwindow1; - GtkWidget *canvas_buttons; - - g_return_val_if_fail (canvas != NULL, NULL); - - vbox_top = gtk_vbox_new (FALSE, 4); - gtk_widget_show (vbox_top); - - label1 = gtk_label_new (_("To add a column to your table, drag it into\nthe location in which you want it to appear.")); - gtk_widget_show (label1); - gtk_box_pack_start (GTK_BOX (vbox_top), label1, FALSE, FALSE, 0); - gtk_label_set_justify (GTK_LABEL (label1), GTK_JUSTIFY_CENTER); - - scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL); - gtk_widget_show (scrolledwindow1); - gtk_box_pack_start (GTK_BOX (vbox_top), scrolledwindow1, TRUE, TRUE, 0); - gtk_widget_set_can_focus (scrolledwindow1, FALSE); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - - canvas_buttons = e_canvas_new (); - gtk_widget_show (canvas_buttons); - gtk_container_add (GTK_CONTAINER (scrolledwindow1), canvas_buttons); - gtk_widget_set_can_focus (canvas_buttons, FALSE); - gtk_widget_set_can_default (canvas_buttons, FALSE); - - *canvas = GNOME_CANVAS (canvas_buttons); - - return vbox_top; -} - -static void -e_table_field_chooser_init (ETableFieldChooser *etfc) -{ - GtkWidget *widget; - - widget = create_content (&etfc->canvas); - if (!widget) { - return; - } - - gtk_widget_set_size_request (widget, -1, 250); - gtk_box_pack_start (GTK_BOX (etfc), widget, TRUE, TRUE, 0); - - etfc->rect = gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (etfc->canvas)), - gnome_canvas_rect_get_type (), - "x1", (gdouble) 0, - "y1", (gdouble) 0, - "x2", (gdouble) 100, - "y2", (gdouble) 100, - "fill_color", "white", - NULL); - - etfc->item = gnome_canvas_item_new ( - gnome_canvas_root (etfc->canvas), - e_table_field_chooser_item_get_type (), - "width", (gdouble) 100, - "full_header", etfc->full_header, - "header", etfc->header, - "dnd_code", etfc->dnd_code, - NULL); - - g_signal_connect ( - etfc->canvas, "reflow", - G_CALLBACK (resize), etfc); - - gnome_canvas_set_scroll_region ( - GNOME_CANVAS (etfc->canvas), - 0, 0, 100, 100); - - /* Connect the signals */ - g_signal_connect ( - etfc->canvas, "size_allocate", - G_CALLBACK (allocate_callback), etfc); - - gtk_widget_show_all (widget); -} - -static void -e_table_field_chooser_dispose (GObject *object) -{ - ETableFieldChooser *etfc = E_TABLE_FIELD_CHOOSER (object); - - g_free (etfc->dnd_code); - etfc->dnd_code = NULL; - - if (etfc->full_header) - g_object_unref (etfc->full_header); - etfc->full_header = NULL; - - if (etfc->header) - g_object_unref (etfc->header); - etfc->header = NULL; - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (e_table_field_chooser_parent_class)->dispose (object); -} - -GtkWidget * -e_table_field_chooser_new (void) -{ - return g_object_new (E_TYPE_TABLE_FIELD_CHOOSER, NULL); -} - -static void -e_table_field_chooser_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ETableFieldChooser *etfc = E_TABLE_FIELD_CHOOSER (object); - - switch (property_id) { - case PROP_DND_CODE: - g_free (etfc->dnd_code); - etfc->dnd_code = g_strdup (g_value_get_string (value)); - if (etfc->item) - g_object_set ( - etfc->item, - "dnd_code", etfc->dnd_code, - NULL); - break; - case PROP_FULL_HEADER: - if (etfc->full_header) - g_object_unref (etfc->full_header); - if (g_value_get_object (value)) - etfc->full_header = E_TABLE_HEADER (g_value_get_object (value)); - else - etfc->full_header = NULL; - if (etfc->full_header) - g_object_ref (etfc->full_header); - if (etfc->item) - g_object_set ( - etfc->item, - "full_header", etfc->full_header, - NULL); - break; - case PROP_HEADER: - if (etfc->header) - g_object_unref (etfc->header); - if (g_value_get_object (value)) - etfc->header = E_TABLE_HEADER (g_value_get_object (value)); - else - etfc->header = NULL; - if (etfc->header) - g_object_ref (etfc->header); - if (etfc->item) - g_object_set ( - etfc->item, - "header", etfc->header, - NULL); - break; - default: - break; - } -} - -static void -e_table_field_chooser_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ETableFieldChooser *etfc = E_TABLE_FIELD_CHOOSER (object); - - switch (property_id) { - case PROP_DND_CODE: - g_value_set_string (value, etfc->dnd_code); - break; - case PROP_FULL_HEADER: - g_value_set_object (value, etfc->full_header); - break; - case PROP_HEADER: - g_value_set_object (value, etfc->header); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} diff --git a/widgets/table/e-table-field-chooser.h b/widgets/table/e-table-field-chooser.h deleted file mode 100644 index a594fa2ae5..0000000000 --- a/widgets/table/e-table-field-chooser.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __E_TABLE_FIELD_CHOOSER_H__ -#define __E_TABLE_FIELD_CHOOSER_H__ - -#include <gtk/gtk.h> -#include <table/e-table-header.h> -#include <libgnomecanvas/libgnomecanvas.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_FIELD_CHOOSER \ - (e_table_field_chooser_get_type ()) -#define E_TABLE_FIELD_CHOOSER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_FIELD_CHOOSER, ETableFieldChooser)) -#define E_TABLE_FIELD_CHOOSER_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_FIELD_CHOOSER, ETableFieldChooserClass)) -#define E_IS_TABLE_FIELD_CHOOSER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_FIELD_CHOOSER)) -#define E_IS_TABLE_FIELD_CHOOSER_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_FIELD_CHOOSER)) -#define E_TABLE_FIELD_CHOOSER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_FIELD_CHOOSER, ETableFieldChooserClass)) - -G_BEGIN_DECLS - -typedef struct _ETableFieldChooser ETableFieldChooser; -typedef struct _ETableFieldChooserClass ETableFieldChooserClass; - -struct _ETableFieldChooser { - GtkBox parent; - - /* item specific fields */ - GnomeCanvas *canvas; - GnomeCanvasItem *item; - - GnomeCanvasItem *rect; - GtkAllocation last_alloc; - - gchar *dnd_code; - ETableHeader *full_header; - ETableHeader *header; -}; - -struct _ETableFieldChooserClass { - GtkBoxClass parent_class; -}; - -GType e_table_field_chooser_get_type (void) G_GNUC_CONST; -GtkWidget * e_table_field_chooser_new (void); - -G_END_DECLS - -#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 27f3116d26..0000000000 --- a/widgets/table/e-table-group-container.c +++ /dev/null @@ -1,1668 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtk.h> -#include <gdk/gdkkeysyms.h> -#include <libgnomecanvas/libgnomecanvas.h> - -#include "text/e-text.h" -#include <glib/gi18n.h> -#include "e-util/e-util.h" -#include "misc/e-canvas-utils.h" -#include "misc/e-canvas.h" -#include "e-util/e-unicode.h" - -#include "e-table-defines.h" -#include "e-table-group-container.h" -#include "e-table-group-leaf.h" -#include "e-table-item.h" -#include "e-table-sorting-utils.h" - -#define TITLE_HEIGHT 16 - -/* workaround for avoiding API breakage */ -#define etgc_get_type e_table_group_container_get_type -G_DEFINE_TYPE (ETableGroupContainer, etgc, E_TYPE_TABLE_GROUP) - -enum { - PROP_0, - PROP_HEIGHT, - PROP_WIDTH, - PROP_MINIMUM_WIDTH, - PROP_FROZEN, - PROP_TABLE_ALTERNATING_ROW_COLORS, - PROP_TABLE_HORIZONTAL_DRAW_GRID, - PROP_TABLE_VERTICAL_DRAW_GRID, - PROP_TABLE_DRAW_FOCUS, - PROP_CURSOR_MODE, - PROP_SELECTION_MODEL, - PROP_LENGTH_THRESHOLD, - PROP_UNIFORM_ROW_HEIGHT -}; - -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; - - g_object_run_dispose (G_OBJECT (child)); - e_table_model_free_value ( - etg->model, etgc->ecol->col_idx, - child_node->key); - g_free (child_node->string); - g_object_run_dispose (G_OBJECT (child_node->text)); - g_object_run_dispose (G_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); - etgc->children = NULL; -} - -static void -etgc_dispose (GObject *object) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (object); - - if (etgc->children) - e_table_group_container_list_free (etgc); - - if (etgc->font_desc) - pango_font_description_free (etgc->font_desc); - etgc->font_desc = NULL; - - if (etgc->ecol) - g_object_unref (etgc->ecol); - etgc->ecol = NULL; - - if (etgc->sort_info) - g_object_unref (etgc->sort_info); - etgc->sort_info = NULL; - - if (etgc->selection_model) - g_object_unref (etgc->selection_model); - etgc->selection_model = NULL; - - if (etgc->rect) - g_object_run_dispose (G_OBJECT (etgc->rect)); - etgc->rect = NULL; - - G_OBJECT_CLASS (etgc_parent_class)->dispose (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, - gint n) -{ - ETableCol *col; - ETableSortColumn column = e_table_sort_info_grouping_get_nth (sort_info, n); - GtkWidget *widget; - GtkStyle *style; - - 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; - g_object_ref (etgc->ecol); - etgc->sort_info = sort_info; - g_object_ref (etgc->sort_info); - etgc->n = n; - etgc->ascending = column.ascending; - - widget = GTK_WIDGET (GNOME_CANVAS_ITEM (etgc)->canvas); - style = gtk_widget_get_style (widget); - etgc->font_desc = pango_font_description_copy (style->font_desc); - - 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, - gint n) -{ - ETableGroupContainer *etgc; - - g_return_val_if_fail (parent != NULL, NULL); - - etgc = g_object_new (E_TYPE_TABLE_GROUP_CONTAINER, NULL); - - e_table_group_container_construct ( - parent, etgc, full_header, header, - model, sort_info, n); - return E_TABLE_GROUP (etgc); -} - -static gint -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_KEY_Tab || - event->key.keyval == GDK_KEY_KP_Tab || - event->key.keyval == GDK_KEY_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_KEY_Left || - event->key.keyval == GDK_KEY_KP_Left) { - change_focus = TRUE; - use_col = TRUE; - start_col = -1; - direction = E_FOCUS_END; - } else if (event->key.keyval == GDK_KEY_Right || - event->key.keyval == GDK_KEY_KP_Right) { - change_focus = TRUE; - use_col = TRUE; - start_col = 0; - direction = E_FOCUS_START; - } else if (event->key.keyval == GDK_KEY_Down || - event->key.keyval == GDK_KEY_KP_Down) { - change_focus = TRUE; - use_col = FALSE; - direction = E_FOCUS_START; - } else if (event->key.keyval == GDK_KEY_Up || - event->key.keyval == GDK_KEY_KP_Up) { - change_focus = TRUE; - use_col = FALSE; - direction = E_FOCUS_END; - } else if (event->key.keyval == GDK_KEY_Return || - event->key.keyval == GDK_KEY_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) -{ - 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) { - /* Translators: This text is used as a special row when an ETable - * has turned on grouping on a column, which has set a title. - * The first %s is replaced with a column title. - * The second %s is replaced with an actual group value. - * Finally the %d is replaced with count of items in this group. - * Example: "Family name: Smith (13 items)" - */ - text = g_strdup_printf ( - ngettext ( - "%s: %s (%d item)", - "%s: %s (%d items)", - child_node->count), - etgc->ecol->text, child_node->string, - (gint) child_node->count); - } else { - /* Translators: This text is used as a special row when an ETable - * has turned on grouping on a column, which doesn't have set a title. - * The %s is replaced with an actual group value. - * The %d is replaced with count of items in this group. - * Example: "Smith (13 items)" - */ - text = g_strdup_printf ( - ngettext ( - "%s (%d item)", - "%s (%d items)", - child_node->count), - child_node->string, - (gint) child_node->count); - } - gnome_canvas_item_set ( - child_node->text, - "text", text, - NULL); - g_free (text); -} - -static void -child_cursor_change (ETableGroup *etg, - gint row, - ETableGroupContainer *etgc) -{ - e_table_group_cursor_change (E_TABLE_GROUP (etgc), row); -} - -static void -child_cursor_activated (ETableGroup *etg, - gint row, - ETableGroupContainer *etgc) -{ - e_table_group_cursor_activated (E_TABLE_GROUP (etgc), row); -} - -static void -child_double_click (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event, - ETableGroupContainer *etgc) -{ - e_table_group_double_click (E_TABLE_GROUP (etgc), row, col, event); -} - -static gboolean -child_right_click (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event, - ETableGroupContainer *etgc) -{ - return e_table_group_right_click (E_TABLE_GROUP (etgc), row, col, event); -} - -static gboolean -child_click (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event, - ETableGroupContainer *etgc) -{ - return e_table_group_click (E_TABLE_GROUP (etgc), row, col, event); -} - -static gboolean -child_key_press (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event, - ETableGroupContainer *etgc) -{ - return e_table_group_key_press (E_TABLE_GROUP (etgc), row, col, event); -} - -static gboolean -child_start_drag (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event, - ETableGroupContainer *etgc) -{ - return e_table_group_start_drag (E_TABLE_GROUP (etgc), row, col, event); -} - -static ETableGroupContainerChildNode * -create_child_node (ETableGroupContainer *etgc, - gpointer val) -{ - ETableGroup *child; - ETableGroupContainerChildNode *child_node; - ETableGroup *etg = E_TABLE_GROUP (etgc); - - 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 (), - "fill_color", "black", - 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), - "alternating_row_colors", etgc->alternating_row_colors, - "horizontal_draw_grid", etgc->horizontal_draw_grid, - "vertical_draw_grid", etgc->vertical_draw_grid, - "drawfocus", etgc->draw_focus, - "cursor_mode", etgc->cursor_mode, - "selection_model", etgc->selection_model, - "length_threshold", etgc->length_threshold, - "uniform_row_height", etgc->uniform_row_height, - "minimum_width", etgc->minimum_width - GROUP_INDENT, - NULL); - - g_signal_connect ( - child, "cursor_change", - G_CALLBACK (child_cursor_change), etgc); - g_signal_connect ( - child, "cursor_activated", - G_CALLBACK (child_cursor_activated), etgc); - g_signal_connect ( - child, "double_click", - G_CALLBACK (child_double_click), etgc); - g_signal_connect ( - child, "right_click", - G_CALLBACK (child_right_click), etgc); - g_signal_connect ( - child, "click", - G_CALLBACK (child_click), etgc); - g_signal_connect ( - child, "key_press", - G_CALLBACK (child_key_press), etgc); - g_signal_connect ( - child, "start_drag", - G_CALLBACK (child_start_drag), 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 = 0; - - return child_node; -} - -static void -etgc_add (ETableGroup *etg, - gint row) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (etg); - gpointer val = e_table_model_value_at (etg->model, etgc->ecol->col_idx, row); - GCompareDataFunc comp = etgc->ecol->compare; - gpointer cmp_cache = e_table_sorting_utils_create_cmp_cache (); - GList *list = etgc->children; - ETableGroup *child; - ETableGroupContainerChildNode *child_node; - gint i = 0; - - for (; list; list = g_list_next (list), i++) { - gint comp_val; - - child_node = list->data; - comp_val = (*comp)(child_node->key, val, cmp_cache); - if (comp_val == 0) { - e_table_sorting_utils_free_cmp_cache (cmp_cache); - 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; - } - e_table_sorting_utils_free_cmp_cache (cmp_cache); - child_node = create_child_node (etgc, val); - child = child_node->child; - 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_array (ETableGroup *etg, - const gint *array, - gint count) -{ - gint i; - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (etg); - gpointer lastval = NULL; - gint laststart = 0; - GCompareDataFunc comp = etgc->ecol->compare; - gpointer cmp_cache; - ETableGroupContainerChildNode *child_node; - ETableGroup *child; - - if (count <= 0) - return; - - e_table_group_container_list_free (etgc); - etgc->children = NULL; - cmp_cache = e_table_sorting_utils_create_cmp_cache (); - - lastval = e_table_model_value_at (etg->model, etgc->ecol->col_idx, array[0]); - - for (i = 1; i < count; i++) { - gpointer val = e_table_model_value_at (etg->model, etgc->ecol->col_idx, array[i]); - gint comp_val; - - comp_val = (*comp)(lastval, val, cmp_cache); - if (comp_val != 0) { - child_node = create_child_node (etgc, lastval); - child = child_node->child; - - e_table_group_add_array (child, array + laststart, i - laststart); - child_node->count = i - laststart; - - etgc->children = g_list_append (etgc->children, child_node); - compute_text (etgc, child_node); - laststart = i; - lastval = val; - } - } - - e_table_sorting_utils_free_cmp_cache (cmp_cache); - - child_node = create_child_node (etgc, lastval); - child = child_node->child; - - e_table_group_add_array (child, array + laststart, i - laststart); - child_node->count = i - laststart; - - 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) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (etg); - ESorter *sorter = etgc->selection_model->sorter; - gint *array; - gint count; - - e_sorter_get_sorted_to_model_array (sorter, &array, &count); - - etgc_add_array (etg, array, count); -} - -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 gint -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; - - 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; - - 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, - gint *x, - gint *y, - gint *prow, - gint *pcol) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (etg); - gint row = -1, 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) - break; - } - } - - if (prow) - *prow = row; - if (pcol) - *pcol = col; -} - -static void -etgc_get_mouse_over (ETableGroup *etg, - gint *row, - gint *col) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (etg); - - if (row) - *row = -1; - if (col) - *col = -1; - - if (etgc->children) { - gint row_plus = 0; - GList *list; - - for (list = etgc->children; list; list = list->next) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data; - ETableGroup *child = child_node->child; - - e_table_group_get_mouse_over (child, row, col); - - if ((!row || *row != -1) && (!col || *col != -1)) { - if (row) - *row += row_plus; - return; - } - - row_plus += e_table_group_row_count (child); - } - } -} - -static void -etgc_get_cell_geometry (ETableGroup *etg, - gint *row, - gint *col, - gint *x, - gint *y, - gint *width, - gint *height) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (etg); - - gint ypos; - - ypos = 0; - - if (etgc->children) { - GList *list; - for (list = etgc->children; list; list = list->next) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data; - ETableGroup *child = child_node->child; - gint thisy; - - e_table_group_get_cell_geometry (child, row, col, x, &thisy, width, height); - ypos += thisy; - if ((*row == -1) || (*col == -1)) { - ypos += TITLE_HEIGHT; - *x += GROUP_INDENT; - *y = ypos; - return; - } - } - } -} - -static void etgc_thaw (ETableGroup *etg) -{ - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etg)); -} - -static void -etgc_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (object); - GList *list; - - switch (property_id) { - case PROP_FROZEN: - if (g_value_get_boolean (value)) - etg->frozen = TRUE; - else { - etg->frozen = FALSE; - etgc_thaw (etg); - } - break; - case PROP_MINIMUM_WIDTH: - case PROP_WIDTH: - etgc->minimum_width = g_value_get_double (value); - - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data; - g_object_set ( - child_node->child, - "minimum_width", etgc->minimum_width - GROUP_INDENT, - NULL); - } - break; - case PROP_LENGTH_THRESHOLD: - etgc->length_threshold = g_value_get_int (value); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data; - g_object_set ( - child_node->child, - "length_threshold", etgc->length_threshold, - NULL); - } - break; - case PROP_UNIFORM_ROW_HEIGHT: - etgc->uniform_row_height = g_value_get_boolean (value); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data; - g_object_set ( - child_node->child, - "uniform_row_height", etgc->uniform_row_height, - NULL); - } - break; - - case PROP_SELECTION_MODEL: - if (etgc->selection_model) - g_object_unref (etgc->selection_model); - etgc->selection_model = E_SELECTION_MODEL (g_value_get_object (value)); - if (etgc->selection_model) - g_object_ref (etgc->selection_model); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data; - g_object_set ( - child_node->child, - "selection_model", etgc->selection_model, - NULL); - } - break; - - case PROP_TABLE_ALTERNATING_ROW_COLORS: - etgc->alternating_row_colors = g_value_get_boolean (value); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data; - g_object_set ( - child_node->child, - "alternating_row_colors", etgc->alternating_row_colors, - NULL); - } - break; - - case PROP_TABLE_HORIZONTAL_DRAW_GRID: - etgc->horizontal_draw_grid = g_value_get_boolean (value); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data; - g_object_set ( - child_node->child, - "horizontal_draw_grid", etgc->horizontal_draw_grid, - NULL); - } - break; - - case PROP_TABLE_VERTICAL_DRAW_GRID: - etgc->vertical_draw_grid = g_value_get_boolean (value); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data; - g_object_set ( - child_node->child, - "vertical_draw_grid", etgc->vertical_draw_grid, - NULL); - } - break; - - case PROP_TABLE_DRAW_FOCUS: - etgc->draw_focus = g_value_get_boolean (value); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data; - g_object_set ( - child_node->child, - "drawfocus", etgc->draw_focus, - NULL); - } - break; - - case PROP_CURSOR_MODE: - etgc->cursor_mode = g_value_get_int (value); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data; - g_object_set ( - child_node->child, - "cursor_mode", etgc->cursor_mode, - NULL); - } - break; - default: - break; - } -} - -static void -etgc_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (object); - - switch (property_id) { - case PROP_FROZEN: - g_value_set_boolean (value, etg->frozen); - break; - case PROP_HEIGHT: - g_value_set_double (value, etgc->height); - break; - case PROP_WIDTH: - g_value_set_double (value, etgc->width); - break; - case PROP_MINIMUM_WIDTH: - g_value_set_double (value, etgc->minimum_width); - break; - case PROP_UNIFORM_ROW_HEIGHT: - g_value_set_boolean (value, etgc->uniform_row_height); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -etgc_class_init (ETableGroupContainerClass *class) -{ - GnomeCanvasItemClass *item_class = GNOME_CANVAS_ITEM_CLASS (class); - GObjectClass *object_class = G_OBJECT_CLASS (class); - ETableGroupClass *e_group_class = E_TABLE_GROUP_CLASS (class); - - object_class->dispose = etgc_dispose; - object_class->set_property = etgc_set_property; - object_class->get_property = etgc_get_property; - - item_class->event = etgc_event; - item_class->realize = etgc_realize; - item_class->unrealize = etgc_unrealize; - - e_group_class->add = etgc_add; - e_group_class->add_array = etgc_add_array; - 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; - e_group_class->get_mouse_over = etgc_get_mouse_over; - e_group_class->get_cell_geometry = etgc_get_cell_geometry; - - g_object_class_install_property ( - object_class, - PROP_TABLE_ALTERNATING_ROW_COLORS, - g_param_spec_boolean ( - "alternating_row_colors", - "Alternating Row Colors", - "Alternating Row Colors", - FALSE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_TABLE_HORIZONTAL_DRAW_GRID, - g_param_spec_boolean ( - "horizontal_draw_grid", - "Horizontal Draw Grid", - "Horizontal Draw Grid", - FALSE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_TABLE_VERTICAL_DRAW_GRID, - g_param_spec_boolean ( - "vertical_draw_grid", - "Vertical Draw Grid", - "Vertical Draw Grid", - FALSE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_TABLE_DRAW_FOCUS, - g_param_spec_boolean ( - "drawfocus", - "Draw focus", - "Draw focus", - FALSE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_CURSOR_MODE, - g_param_spec_int ( - "cursor_mode", - "Cursor mode", - "Cursor mode", - E_CURSOR_LINE, - E_CURSOR_SPREADSHEET, - E_CURSOR_LINE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_SELECTION_MODEL, - g_param_spec_object ( - "selection_model", - "Selection model", - "Selection model", - E_TYPE_SELECTION_MODEL, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_LENGTH_THRESHOLD, - g_param_spec_int ( - "length_threshold", - "Length Threshold", - "Length Threshold", - -1, G_MAXINT, 0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_UNIFORM_ROW_HEIGHT, - g_param_spec_boolean ( - "uniform_row_height", - "Uniform row height", - "Uniform row height", - FALSE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_FROZEN, - g_param_spec_boolean ( - "frozen", - "Frozen", - "Frozen", - FALSE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_HEIGHT, - g_param_spec_double ( - "height", - "Height", - "Height", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_WIDTH, - g_param_spec_double ( - "width", - "Width", - "Width", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_MINIMUM_WIDTH, - g_param_spec_double ( - "minimum_width", - "Minimum width", - "Minimum Width", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); -} - -static void -etgc_reflow (GnomeCanvasItem *item, - gint flags) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (item); - gboolean frozen; - - g_object_get ( - etgc, - "frozen", &frozen, - NULL); - - if (frozen) - return; - - if (item->flags & 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_desc) { - PangoContext *context; - PangoFontMetrics *metrics; - - context = gtk_widget_get_pango_context (GTK_WIDGET (item->canvas)); - metrics = pango_context_get_metrics (context, etgc->font_desc, NULL); - extra_height += - PANGO_PIXELS (pango_font_metrics_get_ascent (metrics)) + - PANGO_PIXELS (pango_font_metrics_get_descent (metrics)) + - BUTTON_PADDING * 2; - pango_font_metrics_unref (metrics); - } - - 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; - - g_object_get ( - 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; - g_object_get ( - child, - "height", &item_height, - NULL); - - e_canvas_item_move_absolute ( - GNOME_CANVAS_ITEM (child_node->text), - GROUP_INDENT, - running_height - GROUP_INDENT - 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", (gdouble) 0, - "x2", (gdouble) running_width + GROUP_INDENT, - "y1", (gdouble) running_height - extra_height, - "y2", (gdouble) 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 (ETableGroupContainer *container) -{ - container->children = NULL; - - e_canvas_item_set_reflow_callback (GNOME_CANVAS_ITEM (container), etgc_reflow); - - container->alternating_row_colors = 1; - container->horizontal_draw_grid = 1; - container->vertical_draw_grid = 1; - container->draw_focus = 1; - container->cursor_mode = E_CURSOR_SIMPLE; - container->length_threshold = -1; - container->selection_model = NULL; - container->uniform_row_height = FALSE; -} - -void -e_table_group_apply_to_leafs (ETableGroup *etg, - ETableGroupLeafFn fn, - gpointer closure) -{ - if (E_IS_TABLE_GROUP_CONTAINER (etg)) { - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (etg); - GList *list; - - /* Protect from unrefs in the callback functions */ - g_object_ref (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); - } - - g_object_unref (etg); - } else if (E_IS_TABLE_GROUP_LEAF (etg)) { - (*fn) (E_TABLE_GROUP_LEAF (etg)->item, closure); - } else { - g_error ( - "Unknown ETableGroup found: %s", - g_type_name (G_TYPE_FROM_INSTANCE (etg))); - } -} - -typedef struct { - ETableGroupContainer *etgc; - GList *child; - EPrintable *child_printable; -} ETGCPrintContext; - -#define CHECK(x) if((x) == -1) return -1; - -#if 0 -static gint -gp_draw_rect (GtkPrintContext *context, - gdouble x, - gdouble y, - gdouble width, - gdouble height) -{ - cairo_t *cr; - cr = gtk_print_context_get_cairo_context (context); - cairo_move_to (cr, x, y); - cairo_rectangle (cr, x, y, x + width, y + height); - cairo_fill (cr); -} -#endif - -#define TEXT_HEIGHT (12) -#define TEXT_AREA_HEIGHT (TEXT_HEIGHT + 4) - -static void -e_table_group_container_print_page (EPrintable *ep, - GtkPrintContext *context, - gdouble width, - gdouble height, - gboolean quantize, - ETGCPrintContext *groupcontext) -{ - cairo_t *cr = NULL; - GtkPageSetup *setup; - gdouble yd; - gdouble page_height, page_margin; - gdouble child_height, child_margin = 0; - ETableGroupContainerChildNode *child_node; - GList *child; - EPrintable *child_printable; - gchar *string; - PangoLayout *layout; - PangoFontDescription *desc; - - child_printable = groupcontext->child_printable; - child = groupcontext->child; - setup = gtk_print_context_get_page_setup (context); - page_height = gtk_page_setup_get_page_height (setup, GTK_UNIT_POINTS); - page_margin = gtk_page_setup_get_bottom_margin (setup, GTK_UNIT_POINTS) + gtk_page_setup_get_top_margin (setup, GTK_UNIT_POINTS); - yd = page_height - page_margin; - - if (child_printable) { - if (child) - child_node = child->data; - else - child_node = NULL; - g_object_ref (child_printable); - } else { - if (!child) { - return; - } else { - child_node = child->data; - child_printable = e_table_group_get_printable (child_node->child); - if (child_printable) - g_object_ref (child_printable); - e_printable_reset (child_printable); - } - } - - layout = gtk_print_context_create_pango_layout (context); - - desc = pango_font_description_new (); - pango_font_description_set_family_static (desc, "Helvetica"); - pango_font_description_set_size (desc, TEXT_HEIGHT); - pango_layout_set_font_description (layout, desc); - pango_font_description_free (desc); - - while (1) { - child_height = e_printable_height (child_printable, context, width,yd, quantize); - if (child_height < 0) - child_height = -child_height; - if (cr && yd < 2 * TEXT_AREA_HEIGHT + 20 + child_height) { - cairo_show_page (cr); - cairo_translate (cr, -2 * TEXT_AREA_HEIGHT, -TEXT_AREA_HEIGHT); - break; - } - - cr = gtk_print_context_get_cairo_context (context); - cairo_save (cr); - cairo_rectangle (cr, 0.0, 0.0, width, TEXT_AREA_HEIGHT); - cairo_rectangle (cr, 0.0, 0.0, 2 * TEXT_AREA_HEIGHT, child_height + 2 * TEXT_AREA_HEIGHT); - cairo_set_source_rgb (cr, .7, .7, .7); - cairo_fill (cr); - cairo_restore (cr); - child_margin = TEXT_AREA_HEIGHT; - - cairo_save (cr); - cairo_rectangle (cr, 2 * TEXT_AREA_HEIGHT, TEXT_AREA_HEIGHT, width - 2 * TEXT_AREA_HEIGHT, TEXT_AREA_HEIGHT); - cairo_clip (cr); - cairo_restore (cr); - - if (child_node) { - cairo_move_to (cr, 0, 0); - 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"); - pango_layout_set_text (layout, string, -1); - pango_cairo_show_layout (cr, layout); - g_free (string); - } - - cairo_translate (cr, 2 * TEXT_AREA_HEIGHT, TEXT_AREA_HEIGHT); - cairo_move_to (cr, 0, 0); - cairo_save (cr); - cairo_rectangle (cr, 0, child_margin, width - 2 * TEXT_AREA_HEIGHT, child_height + child_margin + 20); - cairo_clip (cr); - - e_printable_print_page (child_printable, context, width - 2 * TEXT_AREA_HEIGHT, child_margin, quantize); - yd -= child_height + TEXT_AREA_HEIGHT; - - if (e_printable_data_left (child_printable)) { - cairo_restore (cr); - cairo_translate (cr, -2 * TEXT_AREA_HEIGHT, -TEXT_AREA_HEIGHT); - break; - } - - child = child->next; - if (!child) { - child_printable = NULL; - break; - } - - child_node = child->data; - if (child_printable) - g_object_unref (child_printable); - - child_printable = e_table_group_get_printable (child_node->child); - cairo_restore (cr); - cairo_translate (cr, -2 * TEXT_AREA_HEIGHT, child_height + child_margin + 20); - - if (child_printable) - g_object_ref (child_printable); - e_printable_reset (child_printable); - } - if (groupcontext->child_printable) - g_object_unref (groupcontext->child_printable); - groupcontext->child_printable = child_printable; - groupcontext->child = child; - - g_object_unref (layout); -} - -static gboolean -e_table_group_container_data_left (EPrintable *ep, - ETGCPrintContext *groupcontext) -{ - g_signal_stop_emission_by_name (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) - g_object_unref (groupcontext->child_printable); - groupcontext->child_printable = NULL; -} - -static gdouble -e_table_group_container_height (EPrintable *ep, - GtkPrintContext *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) - g_object_ref (child_printable); - else { - if (!child) { - g_signal_stop_emission_by_name (ep, "height"); - return 0; - } else { - child_node = child->data; - child_printable = e_table_group_get_printable (child_node->child); - if (child_printable) - g_object_ref (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) - g_object_unref (child_printable); - child_printable = e_table_group_get_printable (child_node->child); - if (child_printable) - g_object_ref (child_printable); - e_printable_reset (child_printable); - } - if (child_printable) - g_object_unref (child_printable); - g_signal_stop_emission_by_name (ep, "height"); - return height; -} - -static gboolean -e_table_group_container_will_fit (EPrintable *ep, - GtkPrintContext *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) - g_object_ref (child_printable); - else { - if (!child) { - g_signal_stop_emission_by_name (ep, "will_fit"); - return will_fit; - } else { - child_node = child->data; - child_printable = e_table_group_get_printable (child_node->child); - if (child_printable) - g_object_ref (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) - g_object_unref (child_printable); - child_printable = e_table_group_get_printable (child_node->child); - if (child_printable) - g_object_ref (child_printable); - e_printable_reset (child_printable); - } - } - - if (child_printable) - g_object_unref (child_printable); - - g_signal_stop_emission_by_name (ep, "will_fit"); - return will_fit; -} - -static void -e_table_group_container_printable_destroy (gpointer data, - GObject *where_object_was) - -{ - ETGCPrintContext *groupcontext = data; - - g_object_unref (groupcontext->etgc); - if (groupcontext->child_printable) - g_object_ref (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; - g_object_ref (etgc); - groupcontext->child = etgc->children; - groupcontext->child_printable = NULL; - - g_signal_connect ( - printable, "print_page", - G_CALLBACK (e_table_group_container_print_page), - groupcontext); - g_signal_connect ( - printable, "data_left", - G_CALLBACK (e_table_group_container_data_left), - groupcontext); - g_signal_connect ( - printable, "reset", - G_CALLBACK (e_table_group_container_reset), - groupcontext); - g_signal_connect ( - printable, "height", - G_CALLBACK (e_table_group_container_height), - groupcontext); - g_signal_connect ( - printable, "will_fit", - G_CALLBACK (e_table_group_container_will_fit), - groupcontext); - g_object_weak_ref ( - G_OBJECT (printable), - 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 ac5f7c9033..0000000000 --- a/widgets/table/e-table-group-container.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_GROUP_CONTAINER_H_ -#define _E_TABLE_GROUP_CONTAINER_H_ - -#include <libgnomecanvas/libgnomecanvas.h> -#include <table/e-table-model.h> -#include <table/e-table-header.h> -#include <table/e-table-group.h> -#include <table/e-table-item.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_GROUP_CONTAINER \ - (e_table_group_container_get_type ()) -#define E_TABLE_GROUP_CONTAINER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_GROUP_CONTAINER, ETableGroupContainer)) -#define E_TABLE_GROUP_CONTAINER_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_GROUP_CONTAINER, ETableGroupContainerClass)) -#define E_IS_TABLE_GROUP_CONTAINER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_GROUP_CONTAINER)) -#define E_IS_TABLE_GROUP_CONTAINER_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_GROUP_CONTAINER)) -#define E_TABLE_GROUP_CONTAINER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_GROUP_CONTAINER, ETableGroupContainerClass)) - -G_BEGIN_DECLS - -typedef struct _ETableGroupContainer ETableGroupContainer; -typedef struct _ETableGroupContainerClass ETableGroupContainerClass; - -typedef struct _ETableGroupContainerChildNode ETableGroupContainerChildNode; - -struct _ETableGroupContainer { - 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; - - PangoFontDescription *font_desc; - - gdouble width, height, minimum_width; - - ETableSortInfo *sort_info; - gint n; - gint length_threshold; - - ESelectionModel *selection_model; - - guint alternating_row_colors : 1; - guint horizontal_draw_grid : 1; - guint vertical_draw_grid : 1; - guint draw_focus : 1; - guint uniform_row_height : 1; - ECursorMode cursor_mode; - - /* - * State: the ETableGroup is open or closed - */ - guint open : 1; -}; - -struct _ETableGroupContainerClass { - ETableGroupClass parent_class; -}; - -struct _ETableGroupContainerChildNode { - ETableGroup *child; - gpointer key; - gchar *string; - GnomeCanvasItem *text; - GnomeCanvasItem *rect; - gint count; -}; - -GType e_table_group_container_get_type - (void) G_GNUC_CONST; -ETableGroup * e_table_group_container_new (GnomeCanvasGroup *parent, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info, - gint n); -void e_table_group_container_construct - (GnomeCanvasGroup *parent, - ETableGroupContainer *etgc, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info, - gint n); - -G_END_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 2da75bf006..0000000000 --- a/widgets/table/e-table-group-leaf.c +++ /dev/null @@ -1,816 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtk.h> -#include <libgnomecanvas/libgnomecanvas.h> - -#include <glib/gi18n.h> -#include "e-util/e-util.h" -#include "misc/e-canvas.h" - -#include "e-table-item.h" -#include "e-table-group-leaf.h" -#include "e-table-sorted.h" -#include "e-table-sorted-variable.h" - -/* workaround for avoiding APi breakage */ -#define etgl_get_type e_table_group_leaf_get_type -G_DEFINE_TYPE (ETableGroupLeaf, etgl, E_TYPE_TABLE_GROUP) - -enum { - PROP_0, - PROP_HEIGHT, - PROP_WIDTH, - PROP_MINIMUM_WIDTH, - PROP_FROZEN, - PROP_TABLE_ALTERNATING_ROW_COLORS, - PROP_TABLE_HORIZONTAL_DRAW_GRID, - PROP_TABLE_VERTICAL_DRAW_GRID, - PROP_TABLE_DRAW_FOCUS, - PROP_CURSOR_MODE, - PROP_LENGTH_THRESHOLD, - PROP_SELECTION_MODEL, - PROP_UNIFORM_ROW_HEIGHT -}; - -static void -etgl_dispose (GObject *object) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (object); - - if (etgl->ets) { - g_object_unref (etgl->ets); - etgl->ets = NULL; - } - - if (etgl->item) { - if (etgl->etgl_cursor_change_id != 0) - g_signal_handler_disconnect ( - etgl->item, - etgl->etgl_cursor_change_id); - if (etgl->etgl_cursor_activated_id != 0) - g_signal_handler_disconnect ( - etgl->item, - etgl->etgl_cursor_activated_id); - if (etgl->etgl_double_click_id != 0) - g_signal_handler_disconnect ( - etgl->item, - etgl->etgl_double_click_id); - if (etgl->etgl_right_click_id != 0) - g_signal_handler_disconnect ( - etgl->item, - etgl->etgl_right_click_id); - if (etgl->etgl_click_id != 0) - g_signal_handler_disconnect ( - etgl->item, - etgl->etgl_click_id); - if (etgl->etgl_key_press_id != 0) - g_signal_handler_disconnect ( - etgl->item, - etgl->etgl_key_press_id); - if (etgl->etgl_start_drag_id != 0) - g_signal_handler_disconnect ( - etgl->item, - etgl->etgl_start_drag_id); - - etgl->etgl_cursor_change_id = 0; - etgl->etgl_cursor_activated_id = 0; - etgl->etgl_double_click_id = 0; - etgl->etgl_right_click_id = 0; - etgl->etgl_click_id = 0; - etgl->etgl_key_press_id = 0; - etgl->etgl_start_drag_id = 0; - - g_object_run_dispose (G_OBJECT (etgl->item)); - etgl->item = NULL; - } - - if (etgl->selection_model) { - g_object_unref (etgl->selection_model); - etgl->selection_model = NULL; - } - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (etgl_parent_class)->dispose (object); -} - -static void -e_table_group_leaf_construct (GnomeCanvasGroup *parent, - ETableGroupLeaf *etgl, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info) -{ - etgl->is_grouped = - (e_table_sort_info_grouping_get_count (sort_info) > 0); - - if (etgl->is_grouped) - etgl->ets = E_TABLE_SUBSET ( - e_table_sorted_variable_new ( - model, full_header, sort_info)); - else - etgl->ets = E_TABLE_SUBSET ( - e_table_sorted_new ( - model, full_header, sort_info)); - - 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 = g_object_new (E_TYPE_TABLE_GROUP_LEAF, NULL); - - e_table_group_leaf_construct ( - parent, etgl, full_header, - header, model, sort_info); - - return E_TABLE_GROUP (etgl); -} - -static void -etgl_cursor_change (GObject *object, - gint row, - ETableGroupLeaf *etgl) -{ - if (row < E_TABLE_SUBSET (etgl->ets)->n_map) - e_table_group_cursor_change ( - E_TABLE_GROUP (etgl), - E_TABLE_SUBSET (etgl->ets)->map_table[row]); -} - -static void -etgl_cursor_activated (GObject *object, - gint view_row, - ETableGroupLeaf *etgl) -{ - if (view_row < E_TABLE_SUBSET (etgl->ets)->n_map) - e_table_group_cursor_activated ( - E_TABLE_GROUP (etgl), - E_TABLE_SUBSET (etgl->ets)->map_table[view_row]); -} - -static void -etgl_double_click (GObject *object, - gint model_row, - gint model_col, - GdkEvent *event, - ETableGroupLeaf *etgl) -{ - e_table_group_double_click ( - E_TABLE_GROUP (etgl), model_row, model_col, event); -} - -static gboolean -etgl_key_press (GObject *object, - gint row, - gint col, - GdkEvent *event, - ETableGroupLeaf *etgl) -{ - if (row < E_TABLE_SUBSET (etgl->ets)->n_map && row >= 0) - return e_table_group_key_press ( - E_TABLE_GROUP (etgl), - E_TABLE_SUBSET (etgl->ets)->map_table[row], - col, event); - else - return FALSE; -} - -static gboolean -etgl_start_drag (GObject *object, - gint model_row, - gint model_col, - GdkEvent *event, - ETableGroupLeaf *etgl) -{ - return e_table_group_start_drag ( - E_TABLE_GROUP (etgl), model_row, model_col, event); -} - -static gboolean -etgl_right_click (GObject *object, - gint view_row, - gint model_col, - GdkEvent *event, - ETableGroupLeaf *etgl) -{ - if (view_row < E_TABLE_SUBSET (etgl->ets)->n_map) - return e_table_group_right_click ( - E_TABLE_GROUP (etgl), - E_TABLE_SUBSET (etgl->ets)->map_table[view_row], - model_col, event); - else - return FALSE; -} - -static gboolean -etgl_click (GObject *object, - gint row, - gint col, - GdkEvent *event, - ETableGroupLeaf *etgl) -{ - if (row < E_TABLE_SUBSET (etgl->ets)->n_map) - return e_table_group_click ( - E_TABLE_GROUP (etgl), - E_TABLE_SUBSET (etgl->ets)->map_table[row], - col, event); - else - return FALSE; -} - -static void -etgl_reflow (GnomeCanvasItem *item, - gint flags) -{ - ETableGroupLeaf *leaf = E_TABLE_GROUP_LEAF (item); - - g_object_get (leaf->item, "height", &leaf->height, NULL); - g_object_get (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->ets, - "alternating_row_colors", etgl->alternating_row_colors, - "horizontal_draw_grid", etgl->horizontal_draw_grid, - "vertical_draw_grid", etgl->vertical_draw_grid, - "drawfocus", etgl->draw_focus, - "cursor_mode", etgl->cursor_mode, - "minimum_width", etgl->minimum_width, - "length_threshold", etgl->length_threshold, - "selection_model", etgl->selection_model, - "uniform_row_height", etgl->uniform_row_height, - NULL)); - - etgl->etgl_cursor_change_id = g_signal_connect ( - etgl->item, "cursor_change", - G_CALLBACK (etgl_cursor_change), etgl); - - etgl->etgl_cursor_activated_id = g_signal_connect ( - etgl->item, "cursor_activated", - G_CALLBACK (etgl_cursor_activated), etgl); - - etgl->etgl_double_click_id = g_signal_connect ( - etgl->item, "double_click", - G_CALLBACK (etgl_double_click), etgl); - - etgl->etgl_right_click_id = g_signal_connect ( - etgl->item, "right_click", - G_CALLBACK (etgl_right_click), etgl); - - etgl->etgl_click_id = g_signal_connect ( - etgl->item, "click", - G_CALLBACK (etgl_click), etgl); - - etgl->etgl_key_press_id = g_signal_connect ( - etgl->item, "key_press", - G_CALLBACK (etgl_key_press), etgl); - - etgl->etgl_start_drag_id = g_signal_connect ( - etgl->item, "start_drag", - G_CALLBACK (etgl_start_drag), etgl); - - e_canvas_item_request_reflow (item); -} - -static void -etgl_add (ETableGroup *etg, - gint row) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - - if (E_IS_TABLE_SUBSET_VARIABLE (etgl->ets)) { - e_table_subset_variable_add ( - E_TABLE_SUBSET_VARIABLE (etgl->ets), row); - } -} - -static void -etgl_add_array (ETableGroup *etg, - const gint *array, - gint count) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - - if (E_IS_TABLE_SUBSET_VARIABLE (etgl->ets)) { - e_table_subset_variable_add_array ( - E_TABLE_SUBSET_VARIABLE (etgl->ets), array, count); - } -} - -static void -etgl_add_all (ETableGroup *etg) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - - if (E_IS_TABLE_SUBSET_VARIABLE (etgl->ets)) { - e_table_subset_variable_add_all ( - E_TABLE_SUBSET_VARIABLE (etgl->ets)); - } -} - -static gboolean -etgl_remove (ETableGroup *etg, - gint row) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - - if (E_IS_TABLE_SUBSET_VARIABLE (etgl->ets)) { - return e_table_subset_variable_remove ( - E_TABLE_SUBSET_VARIABLE (etgl->ets), row); - } - return FALSE; -} - -static void -etgl_increment (ETableGroup *etg, - gint position, - gint amount) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - - if (E_IS_TABLE_SUBSET_VARIABLE (etgl->ets)) { - e_table_subset_variable_increment ( - E_TABLE_SUBSET_VARIABLE (etgl->ets), - position, amount); - } -} - -static void -etgl_decrement (ETableGroup *etg, - gint position, - gint amount) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - - if (E_IS_TABLE_SUBSET_VARIABLE (etgl->ets)) { - e_table_subset_variable_decrement ( - E_TABLE_SUBSET_VARIABLE (etgl->ets), - position, amount); - } -} - -static gint -etgl_row_count (ETableGroup *etg) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - - return e_table_model_row_count (E_TABLE_MODEL (etgl->ets)); -} - -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->ets)) - 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, - gint *x, - gint *y, - gint *row, - gint *col) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - - e_table_item_compute_location (etgl->item, x, y, row, col); -} - -static void -etgl_get_mouse_over (ETableGroup *etg, - gint *row, - gint *col) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - - if (etgl->item && etgl->item->motion_row > -1 && etgl->item->motion_col > -1) { - if (row) - *row = etgl->item->motion_row; - if (col) - *col = etgl->item->motion_col; - } -} - -static void -etgl_get_cell_geometry (ETableGroup *etg, - gint *row, - gint *col, - gint *x, - gint *y, - gint *width, - gint *height) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - - e_table_item_get_cell_geometry (etgl->item, row, col, x, y, width, height); -} - -static void -etgl_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (object); - - switch (property_id) { - case PROP_FROZEN: - etg->frozen = g_value_get_boolean (value); - break; - case PROP_MINIMUM_WIDTH: - case PROP_WIDTH: - etgl->minimum_width = g_value_get_double (value); - if (etgl->item) { - gnome_canvas_item_set ( - GNOME_CANVAS_ITEM (etgl->item), - "minimum_width", etgl->minimum_width, - NULL); - } - break; - case PROP_LENGTH_THRESHOLD: - etgl->length_threshold = g_value_get_int (value); - if (etgl->item) { - gnome_canvas_item_set ( - GNOME_CANVAS_ITEM (etgl->item), - "length_threshold", etgl->length_threshold, - NULL); - } - break; - case PROP_SELECTION_MODEL: - if (etgl->selection_model) - g_object_unref (etgl->selection_model); - etgl->selection_model = E_SELECTION_MODEL (g_value_get_object (value)); - if (etgl->selection_model) { - g_object_ref (etgl->selection_model); - } - if (etgl->item) { - gnome_canvas_item_set ( - GNOME_CANVAS_ITEM (etgl->item), - "selection_model", etgl->selection_model, - NULL); - } - break; - - case PROP_UNIFORM_ROW_HEIGHT: - etgl->uniform_row_height = g_value_get_boolean (value); - if (etgl->item) { - gnome_canvas_item_set ( - GNOME_CANVAS_ITEM (etgl->item), - "uniform_row_height", etgl->uniform_row_height, - NULL); - } - break; - - case PROP_TABLE_ALTERNATING_ROW_COLORS: - etgl->alternating_row_colors = g_value_get_boolean (value); - if (etgl->item) { - gnome_canvas_item_set ( - GNOME_CANVAS_ITEM (etgl->item), - "alternating_row_colors", etgl->alternating_row_colors, - NULL); - } - break; - - case PROP_TABLE_HORIZONTAL_DRAW_GRID: - etgl->horizontal_draw_grid = g_value_get_boolean (value); - if (etgl->item) { - gnome_canvas_item_set ( - GNOME_CANVAS_ITEM (etgl->item), - "horizontal_draw_grid", etgl->horizontal_draw_grid, - NULL); - } - break; - - case PROP_TABLE_VERTICAL_DRAW_GRID: - etgl->vertical_draw_grid = g_value_get_boolean (value); - if (etgl->item) { - gnome_canvas_item_set ( - GNOME_CANVAS_ITEM (etgl->item), - "vertical_draw_grid", etgl->vertical_draw_grid, - NULL); - } - break; - - case PROP_TABLE_DRAW_FOCUS: - etgl->draw_focus = g_value_get_boolean (value); - if (etgl->item) { - gnome_canvas_item_set ( - GNOME_CANVAS_ITEM (etgl->item), - "drawfocus", etgl->draw_focus, - NULL); - } - break; - - case PROP_CURSOR_MODE: - etgl->cursor_mode = g_value_get_int (value); - if (etgl->item) { - gnome_canvas_item_set ( - GNOME_CANVAS_ITEM (etgl->item), - "cursor_mode", etgl->cursor_mode, - NULL); - } - break; - default: - break; - } -} - -static void -etgl_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (object); - - switch (property_id) { - case PROP_FROZEN: - g_value_set_boolean (value, etg->frozen); - break; - case PROP_HEIGHT: - g_value_set_double (value, etgl->height); - break; - case PROP_WIDTH: - g_value_set_double (value, etgl->width); - break; - case PROP_MINIMUM_WIDTH: - g_value_set_double (value, etgl->minimum_width); - break; - case PROP_UNIFORM_ROW_HEIGHT: - g_value_set_boolean (value, etgl->uniform_row_height); - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -etgl_class_init (ETableGroupLeafClass *class) -{ - GnomeCanvasItemClass *item_class = GNOME_CANVAS_ITEM_CLASS (class); - ETableGroupClass *e_group_class = E_TABLE_GROUP_CLASS (class); - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->dispose = etgl_dispose; - object_class->set_property = etgl_set_property; - object_class->get_property = etgl_get_property; - - item_class->realize = etgl_realize; - - e_group_class->add = etgl_add; - e_group_class->add_array = etgl_add_array; - 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; - e_group_class->get_mouse_over = etgl_get_mouse_over; - e_group_class->get_cell_geometry = etgl_get_cell_geometry; - - g_object_class_install_property ( - object_class, - PROP_TABLE_ALTERNATING_ROW_COLORS, - g_param_spec_boolean ( - "alternating_row_colors", - "Alternating Row Colors", - "Alternating Row Colors", - FALSE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_TABLE_HORIZONTAL_DRAW_GRID, - g_param_spec_boolean ( - "horizontal_draw_grid", - "Horizontal Draw Grid", - "Horizontal Draw Grid", - FALSE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_TABLE_VERTICAL_DRAW_GRID, - g_param_spec_boolean ( - "vertical_draw_grid", - "Vertical Draw Grid", - "Vertical Draw Grid", - FALSE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_TABLE_DRAW_FOCUS, - g_param_spec_boolean ( - "drawfocus", - "Draw focus", - "Draw focus", - FALSE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_CURSOR_MODE, - g_param_spec_int ( - "cursor_mode", - "Cursor mode", - "Cursor mode", - E_CURSOR_LINE, - E_CURSOR_SPREADSHEET, - E_CURSOR_LINE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_LENGTH_THRESHOLD, - g_param_spec_int ( - "length_threshold", - "Length Threshold", - "Length Threshold", - -1, G_MAXINT, 0, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_SELECTION_MODEL, - g_param_spec_object ( - "selection_model", - "Selection model", - "Selection model", - E_TYPE_SELECTION_MODEL, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_HEIGHT, - g_param_spec_double ( - "height", - "Height", - "Height", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READABLE)); - - g_object_class_install_property ( - object_class, - PROP_WIDTH, - g_param_spec_double ( - "width", - "Width", - "Width", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_MINIMUM_WIDTH, - g_param_spec_double ( - "minimum_width", - "Minimum width", - "Minimum Width", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_FROZEN, - g_param_spec_boolean ( - "frozen", - "Frozen", - "Frozen", - FALSE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_UNIFORM_ROW_HEIGHT, - g_param_spec_boolean ( - "uniform_row_height", - "Uniform row height", - "Uniform row height", - FALSE, - G_PARAM_READWRITE)); -} - -static void -etgl_init (ETableGroupLeaf *etgl) -{ - etgl->width = 1; - etgl->height = 1; - etgl->minimum_width = 0; - - etgl->ets = NULL; - etgl->item = NULL; - - etgl->etgl_cursor_change_id = 0; - etgl->etgl_cursor_activated_id = 0; - etgl->etgl_double_click_id = 0; - etgl->etgl_right_click_id = 0; - etgl->etgl_click_id = 0; - etgl->etgl_key_press_id = 0; - etgl->etgl_start_drag_id = 0; - - etgl->alternating_row_colors = 1; - etgl->horizontal_draw_grid = 1; - etgl->vertical_draw_grid = 1; - etgl->draw_focus = 1; - etgl->cursor_mode = E_CURSOR_SIMPLE; - etgl->length_threshold = -1; - - etgl->selection_model = NULL; - etgl->uniform_row_height = FALSE; - - e_canvas_item_set_reflow_callback (GNOME_CANVAS_ITEM (etgl), etgl_reflow); -} - diff --git a/widgets/table/e-table-group-leaf.h b/widgets/table/e-table-group-leaf.h deleted file mode 100644 index beed62e7d1..0000000000 --- a/widgets/table/e-table-group-leaf.h +++ /dev/null @@ -1,105 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_GROUP_LEAF_H_ -#define _E_TABLE_GROUP_LEAF_H_ - -#include <libgnomecanvas/libgnomecanvas.h> -#include <table/e-table-group.h> -#include <table/e-table-subset.h> -#include <table/e-table-item.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_GROUP_LEAF \ - (e_table_group_leaf_get_type ()) -#define E_TABLE_GROUP_LEAF(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_GROUP_LEAF, ETableGroupLeaf)) -#define E_TABLE_GROUP_LEAF_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_GROUP_LEAF, ETableGroupLeafClass)) -#define E_IS_TABLE_GROUP_LEAF(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_GROUP_LEAF)) -#define E_IS_TABLE_GROUP_LEAF_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_GROUP_LEAF)) -#define E_TABLE_GROUP_LEAF_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_GROUP_LEAF, ETableGroupLeafClass)) - -G_BEGIN_DECLS - -typedef struct _ETableGroupLeaf ETableGroupLeaf; -typedef struct _ETableGroupLeafClass ETableGroupLeafClass; - -struct _ETableGroupLeaf { - ETableGroup group; - - /* - * Item. - */ - ETableItem *item; - - gdouble height; - gdouble width; - gdouble minimum_width; - - gint length_threshold; - - ETableSubset *ets; - guint is_grouped : 1; - - guint alternating_row_colors : 1; - guint horizontal_draw_grid : 1; - guint vertical_draw_grid : 1; - guint draw_focus : 1; - guint uniform_row_height : 1; - ECursorMode cursor_mode; - - gint etgl_cursor_change_id; - gint etgl_cursor_activated_id; - gint etgl_double_click_id; - gint etgl_right_click_id; - gint etgl_click_id; - gint etgl_key_press_id; - gint etgl_start_drag_id; - - ESelectionModel *selection_model; -}; - -struct _ETableGroupLeafClass { - ETableGroupClass parent_class; -}; - -GType e_table_group_leaf_get_type (void) G_GNUC_CONST; -ETableGroup * e_table_group_leaf_new (GnomeCanvasGroup *parent, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info); - -G_END_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 032ec7dd88..0000000000 --- a/widgets/table/e-table-group.c +++ /dev/null @@ -1,773 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtk.h> -#include <libgnomecanvas/libgnomecanvas.h> - -#include "e-util/e-util.h" - -#include "e-table-group.h" -#include "e-table-group-container.h" -#include "e-table-group-leaf.h" -#include "e-table-item.h" - -/* workaround for avoiding API breakage*/ -#define etg_get_type e_table_group_get_type -G_DEFINE_TYPE (ETableGroup, etg, GNOME_TYPE_CANVAS_GROUP) - -#define ETG_CLASS(e) (E_TABLE_GROUP_CLASS(G_OBJECT_GET_CLASS(e))) - -enum { - CURSOR_CHANGE, - CURSOR_ACTIVATED, - DOUBLE_CLICK, - RIGHT_CLICK, - CLICK, - KEY_PRESS, - START_DRAG, - LAST_SIGNAL -}; - -static guint etg_signals[LAST_SIGNAL] = { 0, }; - -static gboolean etg_get_focus (ETableGroup *etg); - -static void -etg_dispose (GObject *object) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - - if (etg->header) { - g_object_unref (etg->header); - etg->header = NULL; - } - - if (etg->full_header) { - g_object_unref (etg->full_header); - etg->full_header = NULL; - } - - if (etg->model) { - g_object_unref (etg->model); - etg->model = NULL; - } - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (etg_parent_class)->dispose (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, - gint 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); - } -} - -/** - * 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; - g_object_ref (etg->full_header); - etg->header = header; - g_object_ref (etg->header); - etg->model = model; - g_object_ref (etg->model); - g_object_set (etg, "parent", parent, 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)); - - g_return_if_fail (ETG_CLASS (etg)->add != NULL); - ETG_CLASS (etg)->add (etg, row); -} - -/** - * e_table_group_add_array - * @etg: The %ETableGroup to add to - * @array: The array to add. - * @count: The number of times to add - * - * This routine adds all the rows in the array to this set of rows. - * It assumes that the array is already sorted properly. - */ -void -e_table_group_add_array (ETableGroup *etg, - const gint *array, - gint count) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - g_return_if_fail (ETG_CLASS (etg)->add_array != NULL); - ETG_CLASS (etg)->add_array (etg, array, count); -} - -/** - * 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)); - - g_return_if_fail (ETG_CLASS (etg)->add_all != NULL); - 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); - - g_return_val_if_fail (ETG_CLASS (etg)->remove != NULL, FALSE); - return ETG_CLASS (etg)->remove (etg, row); -} - -/** - * 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)); - - g_return_if_fail (ETG_CLASS (etg)->increment != NULL); - 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)); - - g_return_if_fail (ETG_CLASS (etg)->decrement != NULL); - 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), -1); - - g_return_val_if_fail (ETG_CLASS (etg)->row_count != NULL, -1); - return ETG_CLASS (etg)->row_count (etg); -} - -/** - * 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)); - - g_return_if_fail (ETG_CLASS (etg)->set_focus != NULL); - 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); - - g_return_val_if_fail (ETG_CLASS (etg)->get_focus != NULL, FALSE); - return ETG_CLASS (etg)->get_focus (etg); -} - -/** - * 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, -1); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), -1); - - g_return_val_if_fail (ETG_CLASS (etg)->get_focus_column != NULL, -1); - return ETG_CLASS (etg)->get_focus_column (etg); -} - -/** - * 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); - - g_return_val_if_fail (ETG_CLASS (etg)->get_printable != NULL, NULL); - return ETG_CLASS (etg)->get_printable (etg); -} - -/** - * 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, - gint *x, - gint *y, - gint *row, - gint *col) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - g_return_if_fail (ETG_CLASS (etg)->compute_location != NULL); - ETG_CLASS (etg)->compute_location (etg, x, y, row, col); -} - -void -e_table_group_get_mouse_over (ETableGroup *etg, - gint *row, - gint *col) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - g_return_if_fail (ETG_CLASS (etg)->get_mouse_over != NULL); - ETG_CLASS (etg)->get_mouse_over (etg, row, col); -} - -/** - * e_table_group_get_position - * @eti: %ETableGroup to look in. - * @x: A pointer to the location to store the found x location in. - * @y: A pointer to the location to store the found y location in. - * @row: A pointer to the row number to find. - * @col: A pointer to the col number to find. - * - * This routine finds the view cell (row, col) in the #ETableGroup. - * If that location is in the #ETableGroup *@x and *@y are set to the - * upper left hand corner of the cell found. If that location is not - * in the #ETableGroup, the number of rows in the #ETableGroup is - * removed from the value row points to. - */ -void -e_table_group_get_cell_geometry (ETableGroup *etg, - gint *row, - gint *col, - gint *x, - gint *y, - gint *width, - gint *height) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - g_return_if_fail (ETG_CLASS (etg)->get_cell_geometry != NULL); - ETG_CLASS (etg)->get_cell_geometry (etg, row, col, x, y, width, height); -} - -/** - * 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)); - - g_signal_emit ( - e_table_group, - etg_signals[CURSOR_CHANGE], 0, - 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)); - - g_signal_emit ( - e_table_group, - etg_signals[CURSOR_ACTIVATED], 0, - 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)); - - g_signal_emit ( - e_table_group, - etg_signals[DOUBLE_CLICK], 0, - 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. - */ -gboolean -e_table_group_right_click (ETableGroup *e_table_group, - gint row, - gint col, - GdkEvent *event) -{ - gboolean return_val = FALSE; - - g_return_val_if_fail (e_table_group != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_GROUP (e_table_group), FALSE); - - g_signal_emit ( - e_table_group, - etg_signals[RIGHT_CLICK], 0, - 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. - */ -gboolean -e_table_group_click (ETableGroup *e_table_group, - gint row, - gint col, - GdkEvent *event) -{ - gboolean return_val = FALSE; - - g_return_val_if_fail (e_table_group != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_GROUP (e_table_group), FALSE); - - g_signal_emit ( - e_table_group, - etg_signals[CLICK], 0, - 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. - */ -gboolean -e_table_group_key_press (ETableGroup *e_table_group, - gint row, - gint col, - GdkEvent *event) -{ - gboolean return_val = FALSE; - - g_return_val_if_fail (e_table_group != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_GROUP (e_table_group), FALSE); - - g_signal_emit ( - e_table_group, - etg_signals[KEY_PRESS], 0, - row, col, event, &return_val); - - return return_val; -} - -/** - * e_table_group_start_drag - * @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 "start_drag" signal. - */ -gboolean -e_table_group_start_drag (ETableGroup *e_table_group, - gint row, - gint col, - GdkEvent *event) -{ - gboolean return_val = FALSE; - - g_return_val_if_fail (e_table_group != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_GROUP (e_table_group), FALSE); - - g_signal_emit ( - e_table_group, - etg_signals[START_DRAG], 0, - 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 gint -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; - break; - - 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 (ETableGroupClass *class) -{ - GnomeCanvasItemClass *item_class = GNOME_CANVAS_ITEM_CLASS (class); - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->dispose = etg_dispose; - - item_class->event = etg_event; - - class->cursor_change = NULL; - class->cursor_activated = NULL; - class->double_click = NULL; - class->right_click = NULL; - class->click = NULL; - class->key_press = NULL; - class->start_drag = NULL; - - class->add = NULL; - class->add_array = NULL; - class->add_all = NULL; - class->remove = NULL; - class->row_count = NULL; - class->increment = NULL; - class->decrement = NULL; - class->set_focus = NULL; - class->get_focus = etg_get_focus; - class->get_printable = NULL; - class->compute_location = NULL; - class->get_mouse_over = NULL; - class->get_cell_geometry = NULL; - - etg_signals[CURSOR_CHANGE] = g_signal_new ( - "cursor_change", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableGroupClass, cursor_change), - NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, - G_TYPE_INT); - - etg_signals[CURSOR_ACTIVATED] = g_signal_new ( - "cursor_activated", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableGroupClass, cursor_activated), - NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, - G_TYPE_INT); - - etg_signals[DOUBLE_CLICK] = g_signal_new ( - "double_click", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableGroupClass, double_click), - NULL, NULL, - e_marshal_NONE__INT_INT_BOXED, - G_TYPE_NONE, 3, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - etg_signals[RIGHT_CLICK] = g_signal_new ( - "right_click", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableGroupClass, right_click), - g_signal_accumulator_true_handled, NULL, - e_marshal_BOOLEAN__INT_INT_BOXED, - G_TYPE_BOOLEAN, 3, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - etg_signals[CLICK] = g_signal_new ( - "click", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableGroupClass, click), - g_signal_accumulator_true_handled, NULL, - e_marshal_BOOLEAN__INT_INT_BOXED, - G_TYPE_BOOLEAN, 3, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - etg_signals[KEY_PRESS] = g_signal_new ( - "key_press", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableGroupClass, key_press), - g_signal_accumulator_true_handled, NULL, - e_marshal_BOOLEAN__INT_INT_BOXED, - G_TYPE_BOOLEAN, 3, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - etg_signals[START_DRAG] = g_signal_new ( - "start_drag", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableGroupClass, start_drag), - g_signal_accumulator_true_handled, NULL, - e_marshal_BOOLEAN__INT_INT_BOXED, - G_TYPE_BOOLEAN, 3, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); -} - -static void -etg_init (ETableGroup *etg) -{ - /* nothing to do */ -} diff --git a/widgets/table/e-table-group.h b/widgets/table/e-table-group.h deleted file mode 100644 index 5731dfdeaf..0000000000 --- a/widgets/table/e-table-group.h +++ /dev/null @@ -1,237 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_GROUP_H_ -#define _E_TABLE_GROUP_H_ - -#include <libgnomecanvas/libgnomecanvas.h> -#include <table/e-table-model.h> -#include <table/e-table-header.h> -#include <table/e-table-sort-info.h> -#include <table/e-table-defines.h> -#include <e-util/e-util.h> -#include <misc/e-printable.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_GROUP \ - (e_table_group_get_type ()) -#define E_TABLE_GROUP(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_GROUP, ETableGroup)) -#define E_TABLE_GROUP_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_GROUP, ETableGroupClass)) -#define E_IS_TABLE_GROUP(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_GROUP)) -#define E_IS_TABLE_GROUP_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_GROUP)) -#define E_TABLE_GROUP_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_GROUP, ETableGroupClass)) - -G_BEGIN_DECLS - -typedef struct _ETableGroup ETableGroup; -typedef struct _ETableGroupClass ETableGroupClass; - -struct _ETableGroup { - 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; -}; - -struct _ETableGroupClass { - GnomeCanvasGroupClass parent_class; - - /* Signals */ - void (*cursor_change) (ETableGroup *etg, - gint row); - void (*cursor_activated) (ETableGroup *etg, - gint row); - void (*double_click) (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event); - gboolean (*right_click) (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event); - gboolean (*click) (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event); - gboolean (*key_press) (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event); - gint (*start_drag) (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event); - - /* Virtual functions. */ - void (*add) (ETableGroup *etg, - gint row); - void (*add_array) (ETableGroup *etg, - const gint *array, - gint count); - 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, - gint *x, - gint *y, - gint *row, - gint *col); - void (*get_mouse_over) (ETableGroup *etg, - gint *row, - gint *col); - void (*get_cell_geometry) (ETableGroup *etg, - gint *row, - gint *col, - gint *x, - gint *y, - gint *width, - gint *height); -}; - -GType e_table_group_get_type (void) G_GNUC_CONST; -ETableGroup * e_table_group_new (GnomeCanvasGroup *parent, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info, - gint n); -void e_table_group_construct (GnomeCanvasGroup *parent, - ETableGroup *etg, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model); - -/* Virtual functions */ -void e_table_group_add (ETableGroup *etg, - gint row); -void e_table_group_add_array (ETableGroup *etg, - const gint *array, - gint count); -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, - gint *x, - gint *y, - gint *row, - gint *col); -void e_table_group_get_mouse_over (ETableGroup *etg, - gint *row, - gint *col); -void e_table_group_get_cell_geometry (ETableGroup *etg, - gint *row, - gint *col, - gint *x, - gint *y, - gint *width, - gint *height); - -/* 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); -gboolean e_table_group_right_click (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event); -gboolean e_table_group_click (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event); -gboolean e_table_group_key_press (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event); -gint e_table_group_start_drag (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event); - -typedef void (*ETableGroupLeafFn) (gpointer e_table_item, gpointer closure); -void e_table_group_apply_to_leafs (ETableGroup *etg, - ETableGroupLeafFn fn, - gpointer closure); - -G_END_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 44d3979e1c..0000000000 --- a/widgets/table/e-table-header-item.c +++ /dev/null @@ -1,2227 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Miguel de Icaza <miguel@gnu.org> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include <gtk/gtk.h> -#include <libgnomecanvas/libgnomecanvas.h> -#include <gdk-pixbuf/gdk-pixbuf.h> -#include <gdk/gdkkeysyms.h> - -#include <glib/gi18n.h> -#include "e-util/e-util.h" -#include "libevolution-utils/e-xml-utils.h" -#include "misc/e-canvas.h" - -#include "e-popup-menu.h" -#include "e-table.h" -#include "e-table-col-dnd.h" -#include "e-table-config.h" -#include "e-table-defines.h" -#include "e-table-field-chooser-dialog.h" -#include "e-table-header.h" -#include "e-table-header-utils.h" - -#include "e-table-header-item.h" - -#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 ethi_get_type e_table_header_item_get_type -G_DEFINE_TYPE (ETableHeaderItem, ethi, GNOME_TYPE_CANVAS_ITEM) - -#define d(x) - -static void ethi_drop_table_header (ETableHeaderItem *ethi); - -/* - * They display the arrows for the drop location. - */ - -static GtkWidget *arrow_up, *arrow_down; - -enum { - PROP_0, - PROP_TABLE_HEADER, - PROP_FULL_HEADER, - PROP_DND_CODE, - PROP_TABLE_FONT_DESC, - PROP_SORT_INFO, - PROP_TABLE, - PROP_TREE -}; - -enum { - ET_SCROLL_UP = 1 << 0, - ET_SCROLL_DOWN = 1 << 1, - ET_SCROLL_LEFT = 1 << 2, - ET_SCROLL_RIGHT = 1 << 3 -}; - -static void scroll_off (ETableHeaderItem *ethi); -static void scroll_on (ETableHeaderItem *ethi, guint scroll_direction); - -static void -ethi_dispose (GObject *object) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (object); - - ethi_drop_table_header (ethi); - - scroll_off (ethi); - - if (ethi->resize_cursor) { - g_object_unref (ethi->resize_cursor); - ethi->resize_cursor = NULL; - } - - if (ethi->dnd_code) { - g_free (ethi->dnd_code); - ethi->dnd_code = NULL; - } - - if (ethi->sort_info) { - if (ethi->sort_info_changed_id) - g_signal_handler_disconnect ( - ethi->sort_info, ethi->sort_info_changed_id); - if (ethi->group_info_changed_id) - g_signal_handler_disconnect ( - ethi->sort_info, ethi->group_info_changed_id); - g_object_unref (ethi->sort_info); - ethi->sort_info = NULL; - } - - if (ethi->full_header) - g_object_unref (ethi->full_header); - ethi->full_header = NULL; - - if (ethi->etfcd.widget) - g_object_remove_weak_pointer ( - G_OBJECT (ethi->etfcd.widget), ði->etfcd.pointer); - - if (ethi->config) - g_object_unref (ethi->config); - ethi->config = NULL; - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (ethi_parent_class)->dispose (object); -} - -static gint -e_table_header_item_get_height (ETableHeaderItem *ethi) -{ - ETableHeader *eth; - gint numcols, col; - gint maxheight; - - 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; - - for (col = 0; col < numcols; col++) { - ETableCol *ecol = e_table_header_get_column (eth, col); - gint height; - - height = e_table_header_compute_height ( - ecol, GTK_WIDGET (GNOME_CANVAS_ITEM (ethi)->canvas)); - - if (height > maxheight) - maxheight = height; - } - - return maxheight; -} - -static void -ethi_update (GnomeCanvasItem *item, - const cairo_matrix_t *i2c, - gint flags) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - gdouble x1, y1, x2, y2; - - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->update) - GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->update ( - item, i2c, 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; - - x1 = y1 = 0; - x2 = ethi->width; - y2 = ethi->height; - - gnome_canvas_matrix_transform_rect (i2c, &x1, &y1, &x2, &y2); - - if (item->x1 != x1 || - item->y1 != y1 || - item->x2 != x2 || - item->y2 != y2) { - gnome_canvas_request_redraw ( - item->canvas, - item->x1, item->y1, - item->x2, item->y2); - item->x1 = x1; - item->y1 = y1; - item->x2 = x2; - item->y2 = y2; - } - gnome_canvas_request_redraw ( - item->canvas, item->x1, item->y1, item->x2, item->y2); -} - -static void -ethi_font_set (ETableHeaderItem *ethi, - PangoFontDescription *font_desc) -{ - if (ethi->font_desc) - pango_font_description_free (ethi->font_desc); - - ethi->font_desc = pango_font_description_copy (font_desc); - - ethi->height = e_table_header_item_get_height (ethi); - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (ethi)); -} - -static void -ethi_drop_table_header (ETableHeaderItem *ethi) -{ - GObject *header; - - if (!ethi->eth) - return; - - header = G_OBJECT (ethi->eth); - g_signal_handler_disconnect (header, ethi->structure_change_id); - g_signal_handler_disconnect (header, ethi->dimension_change_id); - - g_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, - gint 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; - g_object_ref (ethi->eth); - - ethi->height = e_table_header_item_get_height (ethi); - - ethi->structure_change_id = g_signal_connect ( - header, "structure_change", - G_CALLBACK (structure_changed), ethi); - ethi->dimension_change_id = g_signal_connect ( - header, "dimension_change", - G_CALLBACK (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_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - GnomeCanvasItem *item; - ETableHeaderItem *ethi; - - item = GNOME_CANVAS_ITEM (object); - ethi = E_TABLE_HEADER_ITEM (object); - - switch (property_id) { - case PROP_TABLE_HEADER: - ethi_drop_table_header (ethi); - ethi_add_table_header (ethi, E_TABLE_HEADER (g_value_get_object (value))); - break; - - case PROP_FULL_HEADER: - if (ethi->full_header) - g_object_unref (ethi->full_header); - ethi->full_header = E_TABLE_HEADER (g_value_get_object (value)); - if (ethi->full_header) - g_object_ref (ethi->full_header); - break; - - case PROP_DND_CODE: - g_free (ethi->dnd_code); - ethi->dnd_code = g_strdup (g_value_get_string (value)); - break; - - case PROP_TABLE_FONT_DESC: - ethi_font_set (ethi, g_value_get_boxed (value)); - break; - - case PROP_SORT_INFO: - if (ethi->sort_info) { - if (ethi->sort_info_changed_id) - g_signal_handler_disconnect ( - ethi->sort_info, - ethi->sort_info_changed_id); - - if (ethi->group_info_changed_id) - g_signal_handler_disconnect ( - ethi->sort_info, - ethi->group_info_changed_id); - g_object_unref (ethi->sort_info); - } - ethi->sort_info = g_value_get_object (value); - g_object_ref (ethi->sort_info); - ethi->sort_info_changed_id = - g_signal_connect ( - ethi->sort_info, "sort_info_changed", - G_CALLBACK (ethi_sort_info_changed), ethi); - ethi->group_info_changed_id = - g_signal_connect ( - ethi->sort_info, "group_info_changed", - G_CALLBACK (ethi_sort_info_changed), ethi); - break; - case PROP_TABLE: - if (g_value_get_object (value)) - ethi->table = E_TABLE (g_value_get_object (value)); - else - ethi->table = NULL; - break; - case PROP_TREE: - if (g_value_get_object (value)) - ethi->tree = E_TREE (g_value_get_object (value)); - else - ethi->tree = NULL; - break; - } - gnome_canvas_item_request_update (item); -} - -static void -ethi_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ETableHeaderItem *ethi; - - ethi = E_TABLE_HEADER_ITEM (object); - - switch (property_id) { - case PROP_FULL_HEADER: - g_value_set_object (value, ethi->full_header); - break; - case PROP_DND_CODE: - g_value_set_string (value, ethi->dnd_code); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static gint -ethi_find_col_by_x (ETableHeaderItem *ethi, - gint x) -{ - const gint cols = e_table_header_count (ethi->eth); - gint x1 = 0; - gint col; - - d (g_print ("%s:%d: x = %d, x1 = %d\n", __FUNCTION__, __LINE__, x, x1)); - - x1 += ethi->group_indent_width; - - if (x < x1) { - d (g_print ("%s:%d: Returning 0\n", __FUNCTION__, __LINE__)); - return 0; - } - - for (col = 0; col < cols; col++) { - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - - if ((x >= x1) && (x <= x1 + ecol->width)) { - d (g_print ("%s:%d: Returning %d\n", __FUNCTION__, __LINE__, col)); - return col; - } - - x1 += ecol->width; - } - d (g_print ("%s:%d: Returning %d\n", __FUNCTION__, __LINE__, cols - 1)); - return cols - 1; -} - -static gint -ethi_find_col_by_x_nearest (ETableHeaderItem *ethi, - gint x) -{ - const gint cols = e_table_header_count (ethi->eth); - gint x1 = 0; - gint col; - - x1 += ethi->group_indent_width; - - if (x < x1) - return 0; - - 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 gchar **xpm) -{ - GdkPixbuf *pixbuf; - GtkWidget *win, *pix; - - pixbuf = gdk_pixbuf_new_from_xpm_data (xpm); - - win = gtk_window_new (GTK_WINDOW_POPUP); - gtk_window_set_type_hint (GTK_WINDOW (win), GDK_WINDOW_TYPE_HINT_NOTIFICATION); - - pix = gtk_image_new_from_pixbuf (pixbuf); - gtk_widget_realize (win); - gtk_container_add (GTK_CONTAINER (win), pix); - - g_object_unref (pixbuf); - - return win; -} - -static void -ethi_add_drop_marker (ETableHeaderItem *ethi, - gint col, - gboolean recreate) -{ - GnomeCanvas *canvas; - GtkAdjustment *adjustment; - GdkWindow *window; - gint rx, ry; - gint x; - - if (!recreate && 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); - } - - canvas = GNOME_CANVAS_ITEM (ethi)->canvas; - window = gtk_widget_get_window (GTK_WIDGET (canvas)); - gdk_window_get_origin (window, &rx, &ry); - - adjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (canvas)); - rx -= gtk_adjustment_get_value (adjustment); - - adjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (canvas)); - ry -= gtk_adjustment_get_value (adjustment); - - gtk_window_move ( - GTK_WINDOW (arrow_down), - rx + x - ARROW_PTR, - ry - ARROW_DOWN_HEIGHT); - gtk_widget_show_all (arrow_down); - - gtk_window_move ( - GTK_WINDOW (arrow_up), - rx + x - ARROW_PTR, - ry + ethi->height); - gtk_widget_show_all (arrow_up); -} - -static void -ethi_add_destroy_marker (ETableHeaderItem *ethi) -{ - gdouble x1; - - if (ethi->remove_item) - g_object_run_dispose (G_OBJECT (ethi->remove_item)); - - x1 = (gdouble) 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", (gdouble) 1, - "x2", (gdouble) x1 + e_table_header_col_diff ( - ethi->eth, ethi->drag_col, ethi->drag_col + 1) - 2, - - "y2", (gdouble) ethi->height - 2, - "fill_color_rgba", 0xFF000080, - NULL); -} - -static void -ethi_remove_destroy_marker (ETableHeaderItem *ethi) -{ - if (!ethi->remove_item) - return; - - g_object_run_dispose (G_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 void -do_drag_motion (ETableHeaderItem *ethi, - GdkDragContext *context, - gint x, - gint y, - guint time, - gboolean recreate) -{ - if ((x >= 0) && (x <= (ethi->width)) && - (y >= 0) && (y <= (ethi->height))) { - GdkDragAction suggested_action; - gint col; - d (g_print ("In header\n")); - - col = ethi_find_col_by_x_nearest (ethi, x); - suggested_action = gdk_drag_context_get_suggested_action (context); - - if (ethi->drag_col != -1 && (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, suggested_action, time); - } - else if (col != -1) { - if (ethi->drag_col != -1) - ethi_remove_destroy_marker (ethi); - - ethi_add_drop_marker (ethi, col, recreate); - gdk_drag_status (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); - } -} - -static gboolean -scroll_timeout (gpointer data) -{ - ETableHeaderItem *ethi = data; - gint dx = 0; - GtkAdjustment *adjustment; - GtkScrollable *scrollable; - gdouble hadjustment_value; - gdouble vadjustment_value; - gdouble page_size; - gdouble lower; - gdouble upper; - gdouble value; - - if (ethi->scroll_direction & ET_SCROLL_RIGHT) - dx += 20; - if (ethi->scroll_direction & ET_SCROLL_LEFT) - dx -= 20; - - scrollable = GTK_SCROLLABLE (GNOME_CANVAS_ITEM (ethi)->canvas); - - adjustment = gtk_scrollable_get_hadjustment (scrollable); - hadjustment_value = gtk_adjustment_get_value (adjustment); - - adjustment = gtk_scrollable_get_vadjustment (scrollable); - vadjustment_value = gtk_adjustment_get_value (adjustment); - - value = hadjustment_value; - - adjustment = gtk_scrollable_get_hadjustment (scrollable); - page_size = gtk_adjustment_get_page_size (adjustment); - lower = gtk_adjustment_get_lower (adjustment); - upper = gtk_adjustment_get_upper (adjustment); - - gtk_adjustment_set_value ( - adjustment, CLAMP ( - hadjustment_value + dx, lower, upper - page_size)); - - hadjustment_value = gtk_adjustment_get_value (adjustment); - - if (hadjustment_value != value) - do_drag_motion ( - ethi, - ethi->last_drop_context, - ethi->last_drop_x + hadjustment_value, - ethi->last_drop_y + vadjustment_value, - ethi->last_drop_time, - TRUE); - - return TRUE; -} - -static void -scroll_on (ETableHeaderItem *ethi, - guint scroll_direction) -{ - if (ethi->scroll_idle_id == 0 || scroll_direction != ethi->scroll_direction) { - if (ethi->scroll_idle_id != 0) - g_source_remove (ethi->scroll_idle_id); - ethi->scroll_direction = scroll_direction; - ethi->scroll_idle_id = g_timeout_add (100, scroll_timeout, ethi); - } -} - -static void -scroll_off (ETableHeaderItem *ethi) -{ - if (ethi->scroll_idle_id) { - g_source_remove (ethi->scroll_idle_id); - ethi->scroll_idle_id = 0; - } -} - -static void -context_destroyed (gpointer data) -{ - ETableHeaderItem *ethi = data; - - ethi->last_drop_x = 0; - ethi->last_drop_y = 0; - ethi->last_drop_time = 0; - ethi->last_drop_context = NULL; - scroll_off (ethi); - - g_object_unref (ethi); -} - -static void -context_connect (ETableHeaderItem *ethi, - GdkDragContext *context) -{ - if (g_dataset_get_data (context, "e-table-header-item") == NULL) - g_dataset_set_data_full ( - context, "e-table-header-item", - g_object_ref (ethi), context_destroyed); -} - -static gboolean -ethi_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETableHeaderItem *ethi) -{ - GtkAllocation allocation; - GtkAdjustment *adjustment; - GList *targets; - gdouble hadjustment_value; - gdouble vadjustment_value; - gchar *droptype, *headertype; - guint direction = 0; - - gdk_drag_status (context, 0, time); - - targets = gdk_drag_context_list_targets (context); - droptype = gdk_atom_name (GDK_POINTER_TO_ATOM (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); - - gtk_widget_get_allocation (widget, &allocation); - - if (x < 20) - direction |= ET_SCROLL_LEFT; - if (x > allocation.width - 20) - direction |= ET_SCROLL_RIGHT; - - ethi->last_drop_x = x; - ethi->last_drop_y = y; - ethi->last_drop_time = time; - ethi->last_drop_context = context; - context_connect (ethi, context); - - adjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (widget)); - hadjustment_value = gtk_adjustment_get_value (adjustment); - - adjustment = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (widget)); - vadjustment_value = gtk_adjustment_get_value (adjustment); - - do_drag_motion ( - ethi, context, - x + hadjustment_value, - y + vadjustment_value, - time, FALSE); - - if (direction != 0) - scroll_on (ethi, direction); - else - scroll_off (ethi); - - return TRUE; -} - -static void -ethi_drag_end (GtkWidget *canvas, - GdkDragContext *context, - ETableHeaderItem *ethi) -{ - ethi_remove_drop_marker (ethi); - ethi_remove_destroy_marker (ethi); - ethi->drag_col = -1; - scroll_off (ethi); -} - -static void -ethi_drag_data_received (GtkWidget *canvas, - GdkDragContext *drag_context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time, - ETableHeaderItem *ethi) -{ - const guchar *data; - gint found = FALSE; - gint count; - gint column; - gint drop_col; - gint i; - - data = gtk_selection_data_get_data (selection_data); - - if (data != NULL) { - count = e_table_header_count (ethi->eth); - column = atoi ((gchar *) data); - drop_col = ethi->drop_col; - ethi->drop_col = -1; - - if (column >= 0) { - 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; - - 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]), - (guchar *) 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))) { - gint col; - - col = ethi_find_col_by_x_nearest (ethi, x); - - ethi_add_drop_marker (ethi, col, FALSE); - - ethi->drop_col = col; - - if (col != -1) { - gchar *target = g_strdup_printf ( - "%s-%s", TARGET_ETABLE_COL_TYPE, ethi->dnd_code); - d (g_print ("ethi - %s\n", target)); - gtk_drag_get_data ( - canvas, context, - gdk_atom_intern (target, FALSE), - time); - g_free (target); - } - } - gtk_drag_finish (context, successful, successful, time); - scroll_off (ethi); - 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); - GtkStyle *style; - GtkTargetEntry ethi_drop_types[] = { - { (gchar *) 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); - - style = gtk_widget_get_style (GTK_WIDGET (item->canvas)); - - if (!ethi->font_desc) - ethi_font_set (ethi, style->font_desc); - - /* - * 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, - G_N_ELEMENTS (ethi_drop_types), GDK_ACTION_MOVE); - g_free ((gpointer) ethi_drop_types[0].target); - - /* Drop signals */ - ethi->drag_motion_id = g_signal_connect ( - item->canvas, "drag_motion", - G_CALLBACK (ethi_drag_motion), ethi); - ethi->drag_leave_id = g_signal_connect ( - item->canvas, "drag_leave", - G_CALLBACK (ethi_drag_leave), ethi); - ethi->drag_drop_id = g_signal_connect ( - item->canvas, "drag_drop", - G_CALLBACK (ethi_drag_drop), ethi); - ethi->drag_data_received_id = g_signal_connect ( - item->canvas, "drag_data_received", - G_CALLBACK (ethi_drag_data_received), ethi); - - /* Drag signals */ - ethi->drag_end_id = g_signal_connect ( - item->canvas, "drag_end", - G_CALLBACK (ethi_drag_end), ethi); - ethi->drag_data_get_id = g_signal_connect ( - item->canvas, "drag_data_get", - G_CALLBACK (ethi_drag_data_get), ethi); - -} - -static void -ethi_unrealize (GnomeCanvasItem *item) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - - if (ethi->font_desc != NULL) { - pango_font_description_free (ethi->font_desc); - ethi->font_desc = NULL; - } - - g_signal_handler_disconnect (item->canvas, ethi->drag_motion_id); - g_signal_handler_disconnect (item->canvas, ethi->drag_leave_id); - g_signal_handler_disconnect (item->canvas, ethi->drag_drop_id); - g_signal_handler_disconnect (item->canvas, ethi->drag_data_received_id); - - g_signal_handler_disconnect (item->canvas, ethi->drag_end_id); - g_signal_handler_disconnect (item->canvas, ethi->drag_data_get_id); - - gtk_drag_dest_unset (GTK_WIDGET (item->canvas)); - - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->unrealize)(item); -} - -static void -ethi_draw (GnomeCanvasItem *item, - cairo_t *cr, - gint x, - gint y, - gint width, - gint height) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - const gint cols = e_table_header_count (ethi->eth); - gint x1, x2; - gint col; - GHashTable *arrows = g_hash_table_new (NULL, NULL); - GtkStyleContext *context; - - if (ethi->sort_info) { - gint length; - gint i; - - length = e_table_sort_info_grouping_get_count (ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column; - - column = e_table_sort_info_grouping_get_nth ( - ethi->sort_info, i); - - g_hash_table_insert ( - arrows, - GINT_TO_POINTER ((gint) column.column), - GINT_TO_POINTER ( - column.ascending ? - E_TABLE_COL_ARROW_DOWN : - E_TABLE_COL_ARROW_UP)); - } - - length = e_table_sort_info_sorting_get_count (ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column; - - column = e_table_sort_info_sorting_get_nth ( - ethi->sort_info, i); - - g_hash_table_insert ( - arrows, - GINT_TO_POINTER ((gint) column.column), - GINT_TO_POINTER ( - column.ascending ? - E_TABLE_COL_ARROW_DOWN : - E_TABLE_COL_ARROW_UP)); - } - } - - ethi->width = e_table_header_total_width (ethi->eth) + ethi->group_indent_width; - x1 = x2 = 0; - x2 += ethi->group_indent_width; - - context = gtk_widget_get_style_context (GTK_WIDGET (canvas)); - - for (col = 0; col < cols; col++, x1 = x2) { - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - gint col_width; - GtkRegionFlags flags = 0; - - col_width = ecol->width; - - x2 += col_width; - - if (x1 > (x + width)) - break; - - if (x2 < x) - continue; - - if (x2 <= x1) - continue; - - if (((col + 1) % 2) == 0) - flags |= GTK_REGION_EVEN; - else - flags |= GTK_REGION_ODD; - - if (col == 0) - flags |= GTK_REGION_FIRST; - - if (col + 1 == cols) - flags |= GTK_REGION_LAST; - - gtk_style_context_save (context); - gtk_style_context_add_region ( - context, GTK_STYLE_REGION_COLUMN_HEADER, flags); - - e_table_header_draw_button ( - cr, ecol, GTK_WIDGET (canvas), - x1 - x, -y, width, height, - x2 - x1, ethi->height, - (ETableColArrow) g_hash_table_lookup ( - arrows, GINT_TO_POINTER (ecol->col_idx))); - - gtk_style_context_restore (context); - } - - g_hash_table_destroy (arrows); -} - -static GnomeCanvasItem * -ethi_point (GnomeCanvasItem *item, - gdouble x, - gdouble y, - gint cx, - gint cy) -{ - return item; -} - -/* - * 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, - gint pos, - gint *the_total, - gint *return_col) -{ - const gint cols = e_table_header_count (ethi->eth); - gint 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 (return_col) - *return_col = col; - - 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, - gint pos) -{ - GnomeCanvas *canvas; - GdkWindow *window; - gboolean resizable = FALSE; - gint col; - - canvas = GNOME_CANVAS_ITEM (ethi)->canvas; - window = gtk_widget_get_window (GTK_WIDGET (canvas)); - - /* We might be invoked before we are realized */ - if (window == NULL) - return; - - if (is_pointer_on_division (ethi, pos, NULL, &col)) { - gint last_col = ethi->eth->col_count - 1; - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - - /* Last column is not resizable */ - if (ecol->resizable && col != last_col) { - gint 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->resizable) { - resizable = TRUE; - break; - } - } - } - } - - if (resizable) - gdk_window_set_cursor (window, ethi->resize_cursor); - else - gdk_window_set_cursor (window, NULL); -} - -static void -ethi_end_resize (ETableHeaderItem *ethi) -{ - ethi->resize_col = -1; - ethi->resize_guide = GINT_TO_POINTER (0); - - if (ethi->table) - e_table_thaw_state_change (ethi->table); - else if (ethi->tree) - e_tree_thaw_state_change (ethi->tree); - - 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; - gint col_width; - cairo_surface_t *s; - cairo_t *cr; - - gint group_indent = 0; - GHashTable *arrows = g_hash_table_new (NULL, NULL); - - GtkTargetEntry ethi_drag_types[] = { - { (gchar *) TARGET_ETABLE_COL_TYPE, 0, TARGET_ETABLE_COL_HEADER }, - }; - - widget = GTK_WIDGET (GNOME_CANVAS_ITEM (ethi)->canvas); - ethi->drag_col = ethi_find_col_by_x (ethi, event->motion.x); - - if (ethi->drag_col == -1) - return; - - if (ethi->sort_info) { - gint length = e_table_sort_info_grouping_get_count (ethi->sort_info); - gint 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, - GINT_TO_POINTER ((gint) column.column), - GINT_TO_POINTER ( - column.ascending ? - E_TABLE_COL_ARROW_DOWN : - E_TABLE_COL_ARROW_UP)); - } - 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, - GINT_TO_POINTER ((gint) column.column), - GINT_TO_POINTER ( - column.ascending ? - E_TABLE_COL_ARROW_DOWN : - E_TABLE_COL_ARROW_UP)); - } - } - - 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, G_N_ELEMENTS (ethi_drag_types)); - context = gtk_drag_begin (widget, list, GDK_ACTION_MOVE, 1, event); - g_free ((gpointer) ethi_drag_types[0].target); - - ecol = e_table_header_get_column (ethi->eth, ethi->drag_col); - col_width = ecol->width; - s = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, col_width, ethi->height); - cr = cairo_create (s); - - e_table_header_draw_button ( - cr, ecol, - widget, 0, 0, - col_width, ethi->height, - col_width, ethi->height, - (ETableColArrow) g_hash_table_lookup ( - arrows, GINT_TO_POINTER (ecol->col_idx))); - gtk_drag_set_icon_surface (context, s); - cairo_surface_destroy (s); - - ethi->maybe_drag = FALSE; - g_hash_table_destroy (arrows); -} - -typedef struct { - ETableHeaderItem *ethi; - gint col; -} EthiHeaderInfo; - -static void -ethi_popup_sort_ascending (GtkWidget *widget, - EthiHeaderInfo *info) -{ - ETableCol *col; - gint model_col = -1; - gint length; - gint i; - gint found = FALSE; - ETableHeaderItem *ethi = info->ethi; - - col = e_table_header_get_column (ethi->eth, info->col); - if (col->sortable) - 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 || model_col == -1) { - column.ascending = 1; - e_table_sort_info_sorting_set_nth ( - ethi->sort_info, i, column); - found = 1; - if (model_col != -1) - break; - } - } - } - if (!found) { - ETableSortColumn column; - column.column = model_col; - column.ascending = 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; - gint model_col=-1; - gint length; - gint i; - gint found = FALSE; - ETableHeaderItem *ethi = info->ethi; - - col = e_table_header_get_column (ethi->eth, info->col); - if (col->sortable) - 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 || model_col == -1) { - column.ascending = 0; - e_table_sort_info_sorting_set_nth ( - ethi->sort_info, i, column); - found = 1; - if (model_col != -1) - break; - } - } - } - if (!found) { - ETableSortColumn column; - column.column = model_col; - column.ascending = 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; - gint 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 = info->ethi->etfcd.widget; - - if (etfcd) { - gtk_window_present (GTK_WINDOW (etfcd)); - - return; - } - - info->ethi->etfcd.widget = e_table_field_chooser_dialog_new (); - etfcd = info->ethi->etfcd.widget; - - g_object_add_weak_pointer (G_OBJECT (etfcd), &info->ethi->etfcd.pointer); - - g_object_set ( - info->ethi->etfcd.widget, - "full_header", info->ethi->full_header, - "header", info->ethi->eth, - "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; - gint width; - - g_signal_emit_by_name ( - 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 (gpointer data, - GObject *where_object_was) -{ - ETableHeaderItem *ethi = data; - ethi->config = NULL; -} - -static void -apply_changes (ETableConfig *config, - ETableHeaderItem *ethi) -{ - gchar *state = e_table_state_save_to_string (config->state); - - if (ethi->table) - e_table_set_state (ethi->table, state); - if (ethi->tree) - e_tree_set_state (ethi->tree, state); - g_free (state); - - gtk_dialog_set_response_sensitive ( - GTK_DIALOG (config->dialog_toplevel), - GTK_RESPONSE_APPLY, FALSE); -} - -static void -ethi_popup_customize_view (GtkWidget *widget, - EthiHeaderInfo *info) -{ - ETableHeaderItem *ethi = info->ethi; - ETableState *state; - ETableSpecification *spec; - - if (ethi->config) - e_table_config_raise (E_TABLE_CONFIG (ethi->config)); - else { - if (ethi->table) { - state = e_table_get_state_object (ethi->table); - spec = ethi->table->spec; - } else if (ethi->tree) { - state = e_tree_get_state_object (ethi->tree); - spec = e_tree_get_spec (ethi->tree); - } else - return; - - ethi->config = e_table_config_new ( - _("Customize Current View"), - spec, state, GTK_WINDOW (gtk_widget_get_toplevel (widget))); - g_object_weak_ref ( - G_OBJECT (ethi->config), - config_destroyed, ethi); - g_signal_connect ( - ethi->config, "changed", - G_CALLBACK (apply_changes), ethi); - } -} - -static void -free_popup_info (GtkWidget *w, - EthiHeaderInfo *info) -{ - g_free (info); -} - -/* 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[] = { - E_POPUP_ITEM ( - N_("Sort _Ascending"), - G_CALLBACK (ethi_popup_sort_ascending), 2), - E_POPUP_ITEM ( - N_("Sort _Descending"), - G_CALLBACK (ethi_popup_sort_descending), 2), - E_POPUP_ITEM ( - N_("_Unsort"), G_CALLBACK (ethi_popup_unsort), 0), - E_POPUP_SEPARATOR, - E_POPUP_ITEM ( - N_("Group By This _Field"), - G_CALLBACK (ethi_popup_group_field), 16), - E_POPUP_ITEM ( - N_("Group By _Box"), - G_CALLBACK (ethi_popup_group_box), 128), - E_POPUP_SEPARATOR, - E_POPUP_ITEM ( - N_("Remove This _Column"), - G_CALLBACK (ethi_popup_remove_column), 8), - E_POPUP_ITEM ( - N_("Add a C_olumn..."), - G_CALLBACK (ethi_popup_field_chooser), 0), - E_POPUP_SEPARATOR, - E_POPUP_ITEM ( - N_("A_lignment"), - G_CALLBACK (ethi_popup_alignment), 128), - E_POPUP_ITEM ( - N_("B_est Fit"), - G_CALLBACK (ethi_popup_best_fit), 2), - E_POPUP_ITEM ( - N_("Format Column_s..."), - G_CALLBACK (ethi_popup_format_columns), 128), - E_POPUP_SEPARATOR, - E_POPUP_ITEM ( - N_("Custo_mize Current View..."), - G_CALLBACK (ethi_popup_customize_view), 4), - E_POPUP_TERMINATOR -}; - -static void -sort_by_id (GtkWidget *menu_item, - ETableHeaderItem *ethi) -{ - ETableCol *ecol; - gboolean clearfirst; - gint col; - - col = GPOINTER_TO_INT (g_object_get_data ( - G_OBJECT (menu_item), "col-number")); - ecol = e_table_header_get_column (ethi->full_header, col); - clearfirst = e_table_sort_info_sorting_get_count (ethi->sort_info) > 1; - - if (!clearfirst && ecol && - e_table_sort_info_sorting_get_count (ethi->sort_info) == 1) { - ETableSortColumn column; - - column = e_table_sort_info_sorting_get_nth (ethi->sort_info, 0); - clearfirst = ecol->sortable && ecol->col_idx != column.column; - } - - if (clearfirst) - e_table_sort_info_sorting_truncate (ethi->sort_info, 0); - - ethi_change_sort_state (ethi, ecol); -} - -static void -popup_custom (GtkWidget *menu_item, - EthiHeaderInfo *info) -{ - ethi_popup_customize_view (menu_item, info); -} - -static void -ethi_header_context_menu (ETableHeaderItem *ethi, - GdkEvent *button_event) -{ - EthiHeaderInfo *info = g_new (EthiHeaderInfo, 1); - GtkMenu *popup; - gint ncol, sort_count, sort_col; - GtkWidget *menu_item, *sub_menu; - ETableSortColumn column; - gboolean ascending = TRUE; - gdouble event_x_win = 0; - gdouble event_y_win = 0; - guint event_button = 0; - guint32 event_time; - - d (g_print ("ethi_header_context_menu: \n")); - - gdk_event_get_button (button_event, &event_button); - gdk_event_get_coords (button_event, &event_x_win, &event_y_win); - event_time = gdk_event_get_time (button_event); - - info->ethi = ethi; - info->col = ethi_find_col_by_x (ethi, event_x_win); - - popup = e_popup_menu_create_with_domain ( - ethi_context_menu, - 1 + - ((ethi->table || ethi->tree) ? 0 : 4) + - ((e_table_header_count (ethi->eth) > 1) ? 0 : 8), - ((e_table_sort_info_get_can_group (ethi->sort_info)) ? 0 : 16) + - 128, info, GETTEXT_PACKAGE); - - menu_item = gtk_menu_item_new_with_mnemonic (_("_Sort By")); - gtk_widget_show (menu_item); - sub_menu = gtk_menu_new (); - gtk_widget_show (sub_menu); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu); - gtk_menu_shell_prepend (GTK_MENU_SHELL (popup), menu_item); - - sort_count = e_table_sort_info_sorting_get_count (ethi->sort_info); - - if (sort_count > 1 || sort_count < 1) - sort_col = -1; /* Custom sorting */ - else { - column = e_table_sort_info_sorting_get_nth (ethi->sort_info, 0); - sort_col = column.column; - ascending = column.ascending; - } - - /* Custom */ - menu_item = gtk_check_menu_item_new_with_mnemonic (_("_Custom")); - gtk_widget_show (menu_item); - gtk_menu_shell_prepend (GTK_MENU_SHELL (sub_menu), menu_item); - if (sort_col == -1) - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), TRUE); - gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (menu_item), TRUE); - g_signal_connect ( - menu_item, "activate", - G_CALLBACK (popup_custom), info); - - /* Show a seperator */ - menu_item = gtk_separator_menu_item_new (); - gtk_widget_show (menu_item); - gtk_menu_shell_prepend (GTK_MENU_SHELL (sub_menu), menu_item); - /* Headers */ - for (ncol = 0; ncol < ethi->full_header->col_count; ncol++) - { - gchar *text = NULL; - - if (!ethi->full_header->columns[ncol]->sortable || - ethi->full_header->columns[ncol]->disabled) - continue; - - if (ncol == sort_col) { - text = g_strdup_printf ( - "%s (%s)", - ethi->full_header->columns[ncol]->text, - ascending ? _("Ascending"):_("Descending")); - menu_item = gtk_check_menu_item_new_with_label (text); - g_free (text); - } else - menu_item = gtk_check_menu_item_new_with_label ( - ethi->full_header->columns[ncol]->text); - - gtk_widget_show (menu_item); - gtk_menu_shell_prepend (GTK_MENU_SHELL (sub_menu), menu_item); - - if (ncol == sort_col) - gtk_check_menu_item_set_active ( - GTK_CHECK_MENU_ITEM (menu_item), TRUE); - gtk_check_menu_item_set_draw_as_radio ( - GTK_CHECK_MENU_ITEM (menu_item), TRUE); - g_object_set_data ( - G_OBJECT (menu_item), "col-number", - GINT_TO_POINTER (ncol)); - g_signal_connect ( - menu_item, "activate", - G_CALLBACK (sort_by_id), ethi); - } - - g_object_ref_sink (popup); - g_signal_connect ( - popup, "selection-done", - G_CALLBACK (free_popup_info), info); - - gtk_menu_popup ( - GTK_MENU (popup), - NULL, NULL, NULL, NULL, - event_button, event_time); -} - -static void -ethi_button_pressed (ETableHeaderItem *ethi, - GdkEvent *button_event) -{ - g_signal_emit (ethi, ethi_signals[BUTTON_PRESSED], 0, button_event); -} - -void -ethi_change_sort_state (ETableHeaderItem *ethi, - ETableCol *col) -{ - gint model_col = -1; - gint length; - gint i; - gboolean found = FALSE; - - if (col == NULL) - return; - - if (col->sortable) - model_col = col->col_idx; - - length = e_table_sort_info_grouping_get_count (ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column; - - column = e_table_sort_info_grouping_get_nth ( - ethi->sort_info, i); - - if (model_col == column.column || model_col == -1) { - gint ascending = column.ascending; - ascending = !ascending; - column.ascending = ascending; - e_table_sort_info_grouping_set_nth (ethi->sort_info, i, column); - found = TRUE; - if (model_col != -1) - break; - } - } - - if (!found) { - length = e_table_sort_info_sorting_get_count (ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column; - - column = e_table_sort_info_sorting_get_nth ( - ethi->sort_info, i); - - if (model_col == column.column || model_col == -1) { - gint ascending = column.ascending; - - if (ascending == 0 && model_col != -1) { - /* - * This means the user has clicked twice - * already, lets kill sorting of this column now. - */ - gint j; - - for (j = i + 1; j < length; j++) - e_table_sort_info_sorting_set_nth ( - ethi->sort_info, j - 1, - e_table_sort_info_sorting_get_nth ( - ethi->sort_info, j)); - - e_table_sort_info_sorting_truncate ( - ethi->sort_info, length - 1); - length--; - i--; - } else { - ascending = !ascending; - column.ascending = ascending; - e_table_sort_info_sorting_set_nth ( - ethi->sort_info, i, column); - } - found = TRUE; - if (model_col != -1) - break; - } - } - } - - if (!found && model_col != -1) { - ETableSortColumn column; - column.column = model_col; - column.ascending = 1; - e_table_sort_info_sorting_truncate (ethi->sort_info, 0); - e_table_sort_info_sorting_set_nth (ethi->sort_info, 0, column); - } -} - -/* - * Handles the events on the ETableHeaderItem, particularly it handles resizing - */ -static gint -ethi_event (GnomeCanvasItem *item, - GdkEvent *event) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - GdkWindow *window; - const gboolean resizing = ETHI_RESIZING (ethi); - gint x, y, start, col; - gint was_maybe_drag = 0; - GdkModifierType event_state = 0; - guint event_button = 0; - guint event_keyval = 0; - gdouble event_x_win = 0; - gdouble event_y_win = 0; - guint32 event_time; - - /* Don't fetch the device here. GnomeCanvas frequently emits - * synthesized events, and calling gdk_event_get_device() on them - * will trigger a runtime warning. Fetch the device where needed. */ - gdk_event_get_button (event, &event_button); - gdk_event_get_coords (event, &event_x_win, &event_y_win); - gdk_event_get_keyval (event, &event_keyval); - gdk_event_get_state (event, &event_state); - event_time = gdk_event_get_time (event); - - switch (event->type) { - case GDK_ENTER_NOTIFY: - convert (canvas, event_x_win, event_y_win, &x, &y); - set_cursor (ethi, x); - break; - - case GDK_LEAVE_NOTIFY: - window = gtk_widget_get_window (GTK_WIDGET (canvas)); - gdk_window_set_cursor (window, NULL); - break; - - case GDK_MOTION_NOTIFY: - - convert (canvas, event_x_win, event_y_win, &x, &y); - if (resizing) { - gint new_width; - - if (ethi->resize_guide == NULL) { - GdkDevice *event_device; - - /* Quick hack until I actually bind the views */ - ethi->resize_guide = GINT_TO_POINTER (1); - - event_device = gdk_event_get_device (event); - - gnome_canvas_item_grab ( - item, - GDK_POINTER_MOTION_MASK | - GDK_BUTTON_RELEASE_MASK, - ethi->resize_cursor, - event_device, - event_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, &event->motion)) { - ethi_start_drag (ethi, event); - } else - set_cursor (ethi, x); - break; - - case GDK_BUTTON_PRESS: - if (event_button > 3) - return FALSE; - - convert (canvas, event_x_win, event_y_win, &x, &y); - - if (is_pointer_on_division (ethi, x, &start, &col) && - event_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->resizable) - break; - ethi->resize_col = col; - ethi->resize_start_pos = start - ecol->width; - ethi->resize_min_width = ecol->min_width; - - if (ethi->table) - e_table_freeze_state_change (ethi->table); - else if (ethi->tree) - e_tree_freeze_state_change (ethi->tree); - } else { - if (event_button == 1) { - ethi->click_x = event_x_win; - ethi->click_y = event_y_win; - ethi->maybe_drag = TRUE; - is_pointer_on_division (ethi, x, &start, &col); - ethi->selected_col = col; - if (gtk_widget_get_can_focus (GTK_WIDGET (item->canvas))) - e_canvas_item_grab_focus (item, TRUE); - } else if (event_button == 3) { - ethi_header_context_menu (ethi, event); - } else - ethi_button_pressed (ethi, event); - } - break; - - case GDK_2BUTTON_PRESS: - if (!resizing) - break; - - if (event_button != 1) - break; - else { - gint width = 0; - g_signal_emit_by_name ( - ethi->eth, - "request_width", - (gint) 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) { - ETableCol *ecol; - - col = ethi_find_col_by_x (ethi, event_x_win); - ecol = e_table_header_get_column (ethi->eth, col); - ethi_change_sort_state (ethi, ecol); - } - - if (needs_ungrab) - gnome_canvas_item_ungrab (item, event_time); - - break; - } - case GDK_KEY_PRESS: - if ((event_keyval == GDK_KEY_F10) && (event_state & GDK_SHIFT_MASK)) { - EthiHeaderInfo *info = g_new (EthiHeaderInfo, 1); - ETableCol *ecol; - GtkMenu *popup; - - info->ethi = ethi; - info->col = ethi->selected_col; - ecol = e_table_header_get_column (ethi->eth, info->col); - - popup = e_popup_menu_create_with_domain ( - ethi_context_menu, - 1 + - (ecol->sortable ? 0 : 2) + - ((ethi->table || ethi->tree) ? 0 : 4) + - ((e_table_header_count (ethi->eth) > 1) ? 0 : 8), - ((e_table_sort_info_get_can_group ( - ethi->sort_info)) ? 0 : 16) + - 128, info, GETTEXT_PACKAGE); - g_object_ref_sink (popup); - g_signal_connect ( - popup, "selection-done", - G_CALLBACK (free_popup_info), info); - gtk_menu_popup ( - GTK_MENU (popup), - NULL, NULL, NULL, NULL, - 0, GDK_CURRENT_TIME); - } else if (event_keyval == GDK_KEY_space) { - ETableCol *ecol; - - ecol = e_table_header_get_column (ethi->eth, ethi->selected_col); - ethi_change_sort_state (ethi, ecol); - } else if ((event_keyval == GDK_KEY_Right) || - (event_keyval == GDK_KEY_KP_Right)) { - ETableCol *ecol; - - if ((ethi->selected_col < 0) || - (ethi->selected_col >= ethi->eth->col_count - 1)) - ethi->selected_col = 0; - else - ethi->selected_col++; - ecol = e_table_header_get_column (ethi->eth, ethi->selected_col); - ethi_change_sort_state (ethi, ecol); - } else if ((event_keyval == GDK_KEY_Left) || - (event_keyval == GDK_KEY_KP_Left)) { - ETableCol *ecol; - - if ((ethi->selected_col <= 0) || - (ethi->selected_col >= ethi->eth->col_count)) - ethi->selected_col = ethi->eth->col_count - 1; - else - ethi->selected_col--; - ecol = e_table_header_get_column (ethi->eth, ethi->selected_col); - ethi_change_sort_state (ethi, ecol); - } - break; - - default: - return FALSE; - } - return TRUE; -} - -static void -ethi_class_init (ETableHeaderItemClass *class) -{ - GnomeCanvasItemClass *item_class = GNOME_CANVAS_ITEM_CLASS (class); - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->dispose = ethi_dispose; - object_class->set_property = ethi_set_property; - object_class->get_property = ethi_get_property; - - 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; - - g_object_class_install_property ( - object_class, - PROP_DND_CODE, - g_param_spec_string ( - "dnd_code", - "DnD code", - NULL, - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_TABLE_FONT_DESC, - g_param_spec_boxed ( - "font-desc", - "Font Description", - NULL, - PANGO_TYPE_FONT_DESCRIPTION, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_FULL_HEADER, - g_param_spec_object ( - "full_header", - "Full Header", - NULL, - E_TYPE_TABLE_HEADER, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_TABLE_HEADER, - g_param_spec_object ( - "ETableHeader", - "Header", - NULL, - E_TYPE_TABLE_HEADER, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_SORT_INFO, - g_param_spec_object ( - "sort_info", - "Sort Info", - NULL, - E_TYPE_TABLE_SORT_INFO, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_TABLE, - g_param_spec_object ( - "table", - "Table", - NULL, - E_TYPE_TABLE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_TREE, - g_param_spec_object ( - "tree", - "Tree", - NULL, - E_TYPE_TREE, - G_PARAM_WRITABLE)); - - ethi_signals[BUTTON_PRESSED] = g_signal_new ( - "button_pressed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableHeaderItemClass, button_pressed), - NULL, NULL, - g_cclosure_marshal_VOID__BOXED, - G_TYPE_NONE, 1, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); -} - -static void -ethi_init (ETableHeaderItem *ethi) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (ethi); - - ethi->resize_cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW); - - 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; - ethi->tree = NULL; - - ethi->selected_col = 0; -} - diff --git a/widgets/table/e-table-header-item.h b/widgets/table/e-table-header-item.h deleted file mode 100644 index baaa07cacf..0000000000 --- a/widgets/table/e-table-header-item.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_HEADER_ITEM_H_ -#define _E_TABLE_HEADER_ITEM_H_ - -#include <table/e-table.h> -#include <table/e-tree.h> -#include <libgnomecanvas/libgnomecanvas.h> -#include <libxml/tree.h> -#include <table/e-table-header.h> -#include <table/e-table-sort-info.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_HEADER_ITEM \ - (e_table_header_item_get_type ()) -#define E_TABLE_HEADER_ITEM(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_HEADER_ITEM, ETableHeaderItem)) -#define E_TABLE_HEADER_ITEM_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_HEADER_ITEM, ETableHeaderItemClass)) -#define E_IS_TABLE_HEADER_ITEM(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_HEADER_ITEM)) -#define E_IS_TABLE_HEADER_ITEM_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_HEADER_ITEM)) -#define E_TABLE_HEADER_ITEM_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_HEADER_ITEM, ETableHeaderItemClass)) - -G_BEGIN_DECLS - -typedef struct _ETableHeaderItem ETableHeaderItem; -typedef struct _ETableHeaderItemClass ETableHeaderItemClass; - -struct _ETableHeaderItem { - GnomeCanvasItem parent; - ETableHeader *eth; - - GdkCursor *change_cursor; - GdkCursor *resize_cursor; - - gshort height, width; - PangoFontDescription *font_desc; - - /* - * Used during resizing; Could be shorts - */ - gint resize_col; - gint resize_start_pos; - gint resize_min_width; - - gpointer resize_guide; - - gint group_indent_width; - - /* - * Ids - */ - gint structure_change_id, dimension_change_id; - - /* - * For dragging columns - */ - guint maybe_drag : 1; - guint dnd_ready : 1; - gint click_x, click_y; - gint drag_col, drop_col, drag_mark; - guint drag_motion_id; - guint drag_end_id; - guint drag_leave_id; - guint drag_drop_id; - guint drag_data_received_id; - guint drag_data_get_id; - guint sort_info_changed_id, group_info_changed_id; - GnomeCanvasItem *remove_item; - - gchar *dnd_code; - - /* - * For column sorting info - */ - ETableSortInfo *sort_info; - - guint scroll_direction : 4; - gint last_drop_x; - gint last_drop_y; - gint last_drop_time; - GdkDragContext *last_drop_context; - gint scroll_idle_id; - - /* For adding fields. */ - ETableHeader *full_header; - ETable *table; - ETree *tree; - gpointer config; - - union { - GtkWidget *widget; - gpointer pointer; - } etfcd; - - /* For keyboard navigation*/ - gint selected_col; -}; - -struct _ETableHeaderItemClass { - GnomeCanvasItemClass parent_class; - - /* Signals */ - void (*button_pressed) (ETableHeaderItem *ethi, - GdkEvent *button_event); -}; - -GType e_table_header_item_get_type (void) G_GNUC_CONST; -void ethi_change_sort_state (ETableHeaderItem *ethi, - ETableCol *col); - -G_END_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 e3d4ced22c..0000000000 --- a/widgets/table/e-table-header-utils.c +++ /dev/null @@ -1,282 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> /* strlen() */ - -#include <gtk/gtk.h> - -#include "e-util/e-unicode.h" - -#include "e-table-defines.h" -#include "e-table-header-utils.h" - -static void -get_button_padding (GtkWidget *widget, - GtkBorder *padding) -{ - GtkStyleContext *context; - GtkStateFlags state_flags; - - context = gtk_widget_get_style_context (widget); - state_flags = gtk_widget_get_state_flags (widget); - - gtk_style_context_save (context); - gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON); - gtk_style_context_get_padding (context, state_flags, padding); - - gtk_style_context_restore (context); -} - -/** - * e_table_header_compute_height: - * @ecol: Table column description. - * @widget: The widget from which to build the PangoLayout. - * - * Computes the minimum height required for a table header button. - * - * Return value: The height of the button, in pixels. - **/ -gdouble -e_table_header_compute_height (ETableCol *ecol, - GtkWidget *widget) -{ - gint height; - PangoLayout *layout; - GtkBorder padding; - - g_return_val_if_fail (ecol != NULL, -1); - g_return_val_if_fail (E_IS_TABLE_COL (ecol), -1); - g_return_val_if_fail (GTK_IS_WIDGET (widget), -1); - - get_button_padding (widget, &padding); - - layout = gtk_widget_create_pango_layout (widget, ecol->text); - - pango_layout_get_pixel_size (layout, NULL, &height); - - if (ecol->icon_name != NULL) { - g_return_val_if_fail (ecol->pixbuf != NULL, -1); - height = MAX (height, gdk_pixbuf_get_height (ecol->pixbuf)); - } - - height = MAX (height, MIN_ARROW_SIZE); - height += padding.top + padding.bottom + 2 * HEADER_PADDING; - - g_object_unref (layout); - - return height; -} - -gdouble -e_table_header_width_extras (GtkWidget *widget) -{ - GtkBorder padding; - - get_button_padding (widget, &padding); - return padding.left + padding.right + 2 * HEADER_PADDING; -} - -/** - * e_table_header_draw_button: - * @drawable: Destination drawable. - * @ecol: Table column for the header information. - * @widget: The table widget. - * @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 (cairo_t *cr, - ETableCol *ecol, - GtkWidget *widget, - gint x, - gint y, - gint width, - gint height, - gint button_width, - gint button_height, - ETableColArrow arrow) -{ - gint inner_x, inner_y; - gint inner_width, inner_height; - gint arrow_width = 0, arrow_height = 0; - PangoContext *pango_context; - PangoLayout *layout; - GtkStyleContext *context; - GtkBorder padding; - GtkStateFlags state_flags; - - g_return_if_fail (cr != NULL); - g_return_if_fail (ecol != NULL); - g_return_if_fail (E_IS_TABLE_COL (ecol)); - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_WIDGET (widget)); - g_return_if_fail (button_width > 0 && button_height > 0); - - /* Button bevel */ - context = gtk_widget_get_style_context (widget); - state_flags = gtk_widget_get_state_flags (widget); - - gtk_style_context_save (context); - gtk_style_context_set_state (context, state_flags); - gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON); - - gtk_style_context_get_padding (context, state_flags, &padding); - - gtk_render_background ( - context, cr, x, y, - button_width, button_height); - gtk_render_frame ( - context, cr, x, y, - button_width, button_height); - - /* Inside area */ - - inner_width = - button_width - - (padding.left + padding.right + 2 * HEADER_PADDING); - inner_height = - button_height - - (padding.top + padding.bottom + 2 * HEADER_PADDING); - - if (inner_width < 1 || inner_height < 1) { - return; /* nothing fits */ - } - - inner_x = x + padding.left + HEADER_PADDING; - inner_y = y + padding.top + HEADER_PADDING; - - /* Arrow space */ - - switch (arrow) { - case E_TABLE_COL_ARROW_NONE: - break; - - case E_TABLE_COL_ARROW_UP: - case E_TABLE_COL_ARROW_DOWN: - arrow_width = MIN (MIN_ARROW_SIZE, inner_width); - arrow_height = MIN (MIN_ARROW_SIZE, inner_height); - - if (ecol->icon_name == NULL) - inner_width -= arrow_width + HEADER_PADDING; - break; - default: - cairo_restore (cr); - g_return_if_reached (); - } - - if (inner_width < 1) { - gtk_style_context_restore (context); - return; /* nothing else fits */ - } - - pango_context = gtk_widget_create_pango_context (widget); - layout = pango_layout_new (pango_context); - g_object_unref (pango_context); - - pango_layout_set_text (layout, ecol->text, -1); - pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); - - /* Pixbuf or label */ - if (ecol->icon_name != NULL) { - gint pwidth, pheight; - gint clip_height; - gint xpos; - - g_return_if_fail (ecol->pixbuf != NULL); - - pwidth = gdk_pixbuf_get_width (ecol->pixbuf); - pheight = gdk_pixbuf_get_height (ecol->pixbuf); - - clip_height = MIN (pheight, inner_height); - - xpos = inner_x; - - if (inner_width - pwidth > 11) { - gint ypos; - - pango_layout_get_pixel_size (layout, &width, NULL); - - if (width < inner_width - (pwidth + 1)) { - xpos = inner_x + (inner_width - width - (pwidth + 1)) / 2; - } - - ypos = inner_y; - - pango_layout_set_width ( - layout, (inner_width - (xpos - inner_x)) * - PANGO_SCALE); - - gtk_render_layout ( - context, cr, xpos + pwidth + 1, - ypos, layout); - } - - gtk_render_icon ( - context, cr, ecol->pixbuf, xpos, - inner_y + (inner_height - clip_height) / 2); - - } else { - pango_layout_set_width (layout, inner_width * PANGO_SCALE); - - gtk_render_layout (context, cr, inner_x, inner_y, layout); - } - - switch (arrow) { - case E_TABLE_COL_ARROW_NONE: - break; - - case E_TABLE_COL_ARROW_UP: - case E_TABLE_COL_ARROW_DOWN: { - if (ecol->icon_name == NULL) - inner_width += arrow_width + HEADER_PADDING; - - gtk_render_arrow ( - context, cr, - (arrow == E_TABLE_COL_ARROW_UP) ? 0 : G_PI, - inner_x + inner_width - arrow_width, - inner_y + (inner_height - arrow_height) / 2, - MAX (arrow_width, arrow_height)); - - break; - } - - default: - cairo_restore (cr); - g_return_if_reached (); - } - - g_object_unref (layout); - gtk_style_context_restore (context); -} diff --git a/widgets/table/e-table-header-utils.h b/widgets/table/e-table-header-utils.h deleted file mode 100644 index e6d2aaba1d..0000000000 --- a/widgets/table/e-table-header-utils.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * Federico Mena-Quintero <federico@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_TABLE_HEADER_UTILS_H -#define E_TABLE_HEADER_UTILS_H - -#include <table/e-table-col.h> - -G_BEGIN_DECLS - -gdouble e_table_header_compute_height (ETableCol *ecol, - GtkWidget *widget); -gdouble e_table_header_width_extras (GtkWidget *widget); -void e_table_header_draw_button (cairo_t *cr, - ETableCol *ecol, - GtkWidget *widget, - gint x, - gint y, - gint width, - gint height, - gint button_width, - gint button_height, - ETableColArrow arrow); - -G_END_DECLS - -#endif /* E_TABLE_HEADER_UTILS_H */ diff --git a/widgets/table/e-table-header.c b/widgets/table/e-table-header.c deleted file mode 100644 index 325390d559..0000000000 --- a/widgets/table/e-table-header.c +++ /dev/null @@ -1,1014 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include <gtk/gtk.h> - -#include "e-util/e-util.h" - -#include "e-table-defines.h" -#include "e-table-header.h" - -enum { - PROP_0, - PROP_SORT_INFO, - PROP_WIDTH, - PROP_WIDTH_EXTRAS -}; - -enum { - STRUCTURE_CHANGE, - DIMENSION_CHANGE, - EXPANSION_CHANGE, - REQUEST_WIDTH, - LAST_SIGNAL -}; - -static void eth_set_size (ETableHeader *eth, gint idx, gint size); -static void eth_calc_widths (ETableHeader *eth); - -static guint eth_signals[LAST_SIGNAL] = { 0, }; - -G_DEFINE_TYPE (ETableHeader, e_table_header, G_TYPE_OBJECT) - -struct two_ints { - gint column; - gint width; -}; - -static void -eth_set_width (ETableHeader *eth, - gint width) -{ - eth->width = width; -} - -static void -dequeue (ETableHeader *eth, - gint *column, - gint *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) -{ - gint 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, - gint column, - gint 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, - gint idx, - gint 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, - gint idx, - gboolean do_unref) -{ - if (do_unref) - g_object_unref (eth->columns[idx]); - - memmove ( - ð->columns[idx], ð->columns[idx + 1], - sizeof (ETableCol *) * (eth->col_count - idx - 1)); - eth->col_count--; -} - -static void -eth_finalize (GObject *object) -{ - ETableHeader *eth = E_TABLE_HEADER (object); - const gint cols = eth->col_count; - gint i; - - if (eth->sort_info) { - if (eth->sort_info_group_change_id) - g_signal_handler_disconnect ( - eth->sort_info, - eth->sort_info_group_change_id); - g_object_unref (eth->sort_info); - eth->sort_info = NULL; - } - - if (eth->idle) - g_source_remove (eth->idle); - eth->idle = 0; - - if (eth->change_queue) { - g_slist_foreach (eth->change_queue, (GFunc) g_free, NULL); - g_slist_free (eth->change_queue); - eth->change_queue = NULL; - } - - /* - * Destroy columns - */ - for (i = cols - 1; i >= 0; i--) { - eth_do_remove (eth, i, TRUE); - } - g_free (eth->columns); - - eth->col_count = 0; - eth->columns = NULL; - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (e_table_header_parent_class)->finalize (object); -} - -static void -eth_group_info_changed (ETableSortInfo *info, - ETableHeader *eth) -{ - enqueue (eth, -1, eth->nominal_width); -} - -static void -eth_set_property (GObject *object, - guint property_id, - const GValue *val, - GParamSpec *pspec) -{ - ETableHeader *eth = E_TABLE_HEADER (object); - - switch (property_id) { - case PROP_WIDTH: - eth->nominal_width = g_value_get_double (val); - enqueue (eth, -1, eth->nominal_width); - break; - case PROP_WIDTH_EXTRAS: - eth->width_extras = g_value_get_double (val); - enqueue (eth, -1, eth->nominal_width); - break; - case PROP_SORT_INFO: - if (eth->sort_info) { - if (eth->sort_info_group_change_id) - g_signal_handler_disconnect ( - eth->sort_info, - eth->sort_info_group_change_id); - g_object_unref (eth->sort_info); - } - eth->sort_info = E_TABLE_SORT_INFO (g_value_get_object (val)); - if (eth->sort_info) { - g_object_ref (eth->sort_info); - eth->sort_info_group_change_id = g_signal_connect ( - eth->sort_info, "group_info_changed", - G_CALLBACK (eth_group_info_changed), eth); - } - enqueue (eth, -1, eth->nominal_width); - break; - default: - break; - } -} - -static void -eth_get_property (GObject *object, - guint property_id, - GValue *val, - GParamSpec *pspec) -{ - ETableHeader *eth = E_TABLE_HEADER (object); - - switch (property_id) { - case PROP_SORT_INFO: - g_value_set_object (val, eth->sort_info); - break; - case PROP_WIDTH: - g_value_set_double (val, eth->nominal_width); - break; - case PROP_WIDTH_EXTRAS: - g_value_set_double (val, eth->width_extras); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -e_table_header_class_init (ETableHeaderClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->finalize = eth_finalize; - object_class->set_property = eth_set_property; - object_class->get_property = eth_get_property; - - g_object_class_install_property ( - object_class, - PROP_WIDTH, - g_param_spec_double ( - "width", "Width", "Width", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_WIDTH_EXTRAS, - g_param_spec_double ( - "width_extras", - "Width of Extras", - "Width of Extras", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_SORT_INFO, - g_param_spec_object ( - "sort_info", - "Sort Info", - "Sort Info", - E_TYPE_TABLE_SORT_INFO, - G_PARAM_READWRITE)); - - eth_signals[STRUCTURE_CHANGE] = g_signal_new ( - "structure_change", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableHeaderClass, structure_change), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - eth_signals[DIMENSION_CHANGE] = g_signal_new ( - "dimension_change", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableHeaderClass, dimension_change), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, - G_TYPE_INT); - - eth_signals[EXPANSION_CHANGE] = g_signal_new ( - "expansion_change", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableHeaderClass, expansion_change), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - eth_signals[REQUEST_WIDTH] = g_signal_new ( - "request_width", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableHeaderClass, request_width), - (GSignalAccumulator) NULL, NULL, - e_marshal_INT__INT, - G_TYPE_INT, 1, - G_TYPE_INT); - - class->structure_change = NULL; - class->dimension_change = NULL; - class->expansion_change = NULL; - class->request_width = NULL; -} - -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) -{ - - return g_object_new (E_TYPE_TABLE_HEADER, NULL); -} - -static void -eth_update_offsets (ETableHeader *eth) -{ - gint i; - gint 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, - gint 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. The header will assume ownership of the @tc; you should not - * unref it after you add it. - * - * 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, - gint 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 - */ - g_object_ref (tc); - - eth_do_insert (eth, pos, tc); - - enqueue (eth, -1, eth->nominal_width); - g_signal_emit (eth, eth_signals[STRUCTURE_CHANGE], 0); -} - -/** - * 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, - gint 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, - gint col_idx) -{ - gint 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. - */ -gint -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. */ -gint -e_table_header_index (ETableHeader *eth, - gint 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. - */ -gint -e_table_header_get_index_at (ETableHeader *eth, - gint x_offset) -{ - gint 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 g_object_unref every element returned - */ -ETableCol ** -e_table_header_get_columns (ETableHeader *eth) -{ - ETableCol **ret; - gint i; - - g_return_val_if_fail (eth != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), NULL); - - 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++) { - g_object_ref (ret[i]); - } - - return ret; -} - -/** - * e_table_header_get_selected: - * @eth: The ETableHeader to query - * - * Returns: The number of selected columns in the @eth object. - */ -gint -e_table_header_get_selected (ETableHeader *eth) -{ - gint i; - gint 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 - */ -gint -e_table_header_total_width (ETableHeader *eth) -{ - gint 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_min_width: - * @eth: The ETableHeader to query - * - * Returns: the minimum number of pixels required by the @eth object. - **/ -gint -e_table_header_min_width (ETableHeader *eth) -{ - gint 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]->min_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, - gint source_index, - gint 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); - - /* Can be moved beyond the last item. */ - g_return_if_fail (target_index < eth->col_count + 1); - - 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); - - g_signal_emit (eth, eth_signals[DIMENSION_CHANGE], 0, eth->width); - g_signal_emit (eth, eth_signals[STRUCTURE_CHANGE], 0); -} - -/** - * 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, - gint 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); - g_signal_emit (eth, eth_signals[STRUCTURE_CHANGE], 0); -} - -/* - * 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, - gint idx, - gint size) -{ - gdouble expansion; - gdouble old_expansion; - gint min_width; - gint left_width; - gint total_extra; - gint expandable_count; - gint usable_width; - gint 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]->resizable) - 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]->resizable) { - 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; - } - - g_signal_emit (eth, eth_signals[EXPANSION_CHANGE], 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; - } - g_signal_emit (eth, eth_signals[EXPANSION_CHANGE], 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; - } - g_signal_emit (eth, eth_signals[EXPANSION_CHANGE], 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 * (((gdouble)(size - (eth->columns[idx]->min_width + - eth->width_extras))) / ((gdouble) 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]->resizable) { - /* expandable_count != 0 by (1) */ - eth->columns[i]->expansion = expansion / expandable_count; - } - } - g_signal_emit (eth, eth_signals[EXPANSION_CHANGE], 0); - return; - } - - for (i = idx + 1; i < eth->col_count; i++) { - if (eth->columns[idx]->resizable) { - /* old_expansion != 0 by (2) */ - eth->columns[i]->expansion *= expansion / old_expansion; - } - } - g_signal_emit (eth, eth_signals[EXPANSION_CHANGE], 0); -} - -/** - * 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 - */ -gint -e_table_header_col_diff (ETableHeader *eth, - gint start_col, - gint end_col) -{ - gint 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) -{ - gint i; - gint extra; - gdouble expansion; - gint last_position = 0; - gdouble next_position = 0; - gint last_resizable = -1; - gint *widths; - gboolean changed; - - widths = g_new (int, eth->col_count); - - /* - 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]->resizable && eth->columns[i]->expansion > 0) - last_resizable = i; - expansion += eth->columns[i]->resizable ? eth->columns[i]->expansion : 0; - widths[i] = 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) { - for (i = 0; i < last_resizable; i++) { - next_position += - extra * (eth->columns[i]->resizable ? - eth->columns[i]->expansion : 0) / expansion; - widths[i] += next_position - last_position; - last_position = next_position; - } - widths[i] += extra - last_position; - } - - changed = FALSE; - - for (i = 0; i < eth->col_count; i++) { - if (eth->columns[i]->width != widths[i]) { - changed = TRUE; - eth->columns[i]->width = widths[i]; - } - } - g_free (widths); - if (changed) - g_signal_emit (eth, eth_signals[DIMENSION_CHANGE], 0, eth->width); - eth_update_offsets (eth); -} - -void -e_table_header_update_horizontal (ETableHeader *eth) -{ - gint i; - gint cols; - - cols = eth->col_count; - - for (i = 0; i < cols; i++) { - gint width = 0; - - g_signal_emit_by_name ( - eth, "request_width", i, &width); - eth->columns[i]->min_width = width + 10; - eth->columns[i]->expansion = 1; - } - enqueue (eth, -1, eth->nominal_width); - g_signal_emit (eth, eth_signals[EXPANSION_CHANGE], 0); -} - -gint -e_table_header_prioritized_column (ETableHeader *eth) -{ - gint best_model_col = 0; - gint best_priority; - gint i; - gint count; - - count = e_table_header_count (eth); - if (count == 0) - return -1; - best_priority = e_table_header_get_column (eth, 0)->priority; - best_model_col = e_table_header_get_column (eth, 0)->col_idx; - for (i = 1; i < count; i++) { - gint priority = e_table_header_get_column (eth, i)->priority; - if (priority > best_priority) { - best_priority = priority; - best_model_col = e_table_header_get_column (eth, i)->col_idx; - } - } - return best_model_col; -} - -ETableCol * -e_table_header_prioritized_column_selected (ETableHeader *eth, - ETableColCheckFunc check_func, - gpointer user_data) -{ - ETableCol *best_col = NULL; - gint best_priority = G_MININT; - gint i; - gint count; - - count = e_table_header_count (eth); - if (count == 0) - return NULL; - for (i = 1; i < count; i++) { - ETableCol *col = e_table_header_get_column (eth, i); - if (col) { - if ((best_col == NULL || col->priority > best_priority) - && check_func (col, user_data)) { - best_priority = col->priority; - best_col = col; - } - } - } - return best_col; -} diff --git a/widgets/table/e-table-header.h b/widgets/table/e-table-header.h deleted file mode 100644 index 1ac3016c8f..0000000000 --- a/widgets/table/e-table-header.h +++ /dev/null @@ -1,139 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_COLUMN_H_ -#define _E_TABLE_COLUMN_H_ - -#include <gdk/gdk.h> -#include <table/e-table-sort-info.h> -#include <table/e-table-col.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_HEADER \ - (e_table_header_get_type ()) -#define E_TABLE_HEADER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_HEADER, ETableHeader)) -#define E_TABLE_HEADER_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_HEADER, ETableHeaderClass)) -#define E_IS_TABLE_HEADER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_HEADER)) -#define E_IS_TABLE_HEADER_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_HEADER)) -#define E_TABLE_HEADER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_HEADER, ETableHeaderClass)) - -G_BEGIN_DECLS - -typedef struct _ETableHeader ETableHeader; -typedef struct _ETableHeaderClass ETableHeaderClass; - -typedef gboolean (*ETableColCheckFunc) (ETableCol *col, gpointer user_data); - -/* - * A Column header. - */ -struct _ETableHeader { - GObject parent; - - gint col_count; - gint width; - gint nominal_width; - gint width_extras; - - ETableSortInfo *sort_info; - gint sort_info_group_change_id; - - ETableCol **columns; - - GSList *change_queue, *change_tail; - gint idle; -}; - -struct _ETableHeaderClass { - GObjectClass parent_class; - - void (*structure_change) (ETableHeader *eth); - void (*dimension_change) (ETableHeader *eth, - gint width); - void (*expansion_change) (ETableHeader *eth); - gint (*request_width) (ETableHeader *eth, - gint col); -}; - -GType e_table_header_get_type (void) G_GNUC_CONST; -ETableHeader * e_table_header_new (void); - -void e_table_header_add_column (ETableHeader *eth, - ETableCol *tc, - gint pos); -ETableCol * e_table_header_get_column (ETableHeader *eth, - gint column); -ETableCol * e_table_header_get_column_by_col_idx - (ETableHeader *eth, - gint col_idx); -gint e_table_header_count (ETableHeader *eth); -gint e_table_header_index (ETableHeader *eth, - gint col); -gint e_table_header_get_index_at (ETableHeader *eth, - gint x_offset); -ETableCol ** e_table_header_get_columns (ETableHeader *eth); -gint e_table_header_get_selected (ETableHeader *eth); - -gint e_table_header_total_width (ETableHeader *eth); -gint e_table_header_min_width (ETableHeader *eth); -void e_table_header_move (ETableHeader *eth, - gint source_index, - gint target_index); -void e_table_header_remove (ETableHeader *eth, - gint idx); -void e_table_header_set_size (ETableHeader *eth, - gint idx, - gint size); -void e_table_header_set_selection (ETableHeader *eth, - gboolean allow_selection); -gint e_table_header_col_diff (ETableHeader *eth, - gint start_col, - gint 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); -gint e_table_header_prioritized_column - (ETableHeader *eth); -ETableCol * e_table_header_prioritized_column_selected - (ETableHeader *eth, - ETableColCheckFunc check_func, - gpointer user_data); - -G_END_DECLS - -#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 ddf7d0ac62..0000000000 --- a/widgets/table/e-table-item.c +++ /dev/null @@ -1,4041 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-item.c - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Miguel de Icaza <miguel@gnu.org> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - */ -/* - * TODO: - * Add a border to the thing, so that focusing works properly. - */ -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <math.h> -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -#include <gtk/gtk.h> -#include <gdk/gdkkeysyms.h> - -#include "gal-a11y-e-table-item-factory.h" -#include "gal-a11y-e-table-item.h" -#include <glib/gi18n.h> -#include "e-util/e-util.h" -#include "misc/e-canvas.h" -#include "misc/e-canvas-utils.h" - -#include "e-cell.h" -#include "e-table-item.h" -#include "e-table-subset.h" - -/* workaround for avoiding API breakage */ -#define eti_get_type e_table_item_get_type -G_DEFINE_TYPE (ETableItem, eti, GNOME_TYPE_CANVAS_ITEM) - -#define FOCUSED_BORDER 2 - -#define d(x) - -#if d(!)0 -#define e_table_item_leave_edit_(x) (e_table_item_leave_edit((x)), g_print ("%s: e_table_item_leave_edit\n", __FUNCTION__)) -#else -#define e_table_item_leave_edit_(x) (e_table_item_leave_edit((x))) -#endif - -static void eti_check_cursor_bounds (ETableItem *eti); -static void eti_cancel_drag_due_to_model_change (ETableItem *eti); - -/* FIXME: Do an analysis of which cell functions are needed before - * realize and make sure that all of them are doable by all the cells - * and that all of the others are only done after realization. */ - -enum { - CURSOR_CHANGE, - CURSOR_ACTIVATED, - DOUBLE_CLICK, - RIGHT_CLICK, - CLICK, - KEY_PRESS, - START_DRAG, - STYLE_SET, - SELECTION_MODEL_REMOVED, - SELECTION_MODEL_ADDED, - LAST_SIGNAL -}; - -static guint eti_signals[LAST_SIGNAL] = { 0, }; - -enum { - PROP_0, - PROP_TABLE_HEADER, - PROP_TABLE_MODEL, - PROP_SELECTION_MODEL, - PROP_TABLE_ALTERNATING_ROW_COLORS, - PROP_TABLE_HORIZONTAL_DRAW_GRID, - PROP_TABLE_VERTICAL_DRAW_GRID, - PROP_TABLE_DRAW_FOCUS, - PROP_CURSOR_MODE, - PROP_LENGTH_THRESHOLD, - PROP_CURSOR_ROW, - PROP_UNIFORM_ROW_HEIGHT, - - PROP_MINIMUM_WIDTH, - PROP_WIDTH, - PROP_HEIGHT -}; - -#define DOUBLE_CLICK_TIME 250 -#define TRIPLE_CLICK_TIME 500 - -static gint eti_get_height (ETableItem *eti); -static gint eti_row_height (ETableItem *eti, gint row); -static void e_table_item_focus (ETableItem *eti, gint col, gint row, GdkModifierType state); -static void eti_cursor_change (ESelectionModel *selection, gint row, gint col, ETableItem *eti); -static void eti_cursor_activated (ESelectionModel *selection, gint row, gint col, ETableItem *eti); -static void eti_selection_change (ESelectionModel *selection, ETableItem *eti); -static void eti_selection_row_change (ESelectionModel *selection, gint row, ETableItem *eti); -static void e_table_item_redraw_row (ETableItem *eti, gint row); - -#define ETI_SINGLE_ROW_HEIGHT(eti) ((eti)->uniform_row_height_cache != -1 ? (eti)->uniform_row_height_cache : eti_row_height((eti), -1)) -#define ETI_MULTIPLE_ROW_HEIGHT(eti,row) ((eti)->height_cache && (eti)->height_cache[(row)] != -1 ? (eti)->height_cache[(row)] : eti_row_height((eti),(row))) -#define ETI_ROW_HEIGHT(eti,row) ((eti)->uniform_row_height ? ETI_SINGLE_ROW_HEIGHT ((eti)) : ETI_MULTIPLE_ROW_HEIGHT((eti),(row))) - -/* tweak_hsv is a really tweaky function. it modifies its first argument, which - * should be the color you want tweaked. delta_h, delta_s and delta_v specify - * how much you want their respective channels modified (and in what direction). - * if it can't do the specified modification, it does it in the oppositon direction */ -static void -e_hsv_tweak (GdkColor *color, - gdouble delta_h, - gdouble delta_s, - gdouble delta_v) -{ - gdouble h, s, v, r, g, b; - - r = color->red / 65535.0f; - g = color->green / 65535.0f; - b = color->blue / 65535.0f; - - gtk_rgb_to_hsv (r, g, b, &h, &s, &v); - - if (h + delta_h < 0) { - h -= delta_h; - } else { - h += delta_h; - } - - if (s + delta_s < 0) { - s -= delta_s; - } else { - s += delta_s; - } - - if (v + delta_v < 0) { - v -= delta_v; - } else { - v += delta_v; - } - - gtk_hsv_to_rgb (h, s, v, &r, &g, &b); - - color->red = r * 65535.0f; - color->green = g * 65535.0f; - color->blue = b * 65535.0f; -} - -inline static gint -model_to_view_row (ETableItem *eti, - gint row) -{ - gint i; - if (row == -1) - return -1; - 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, - gint row) -{ - if (eti->uses_source_model) { - ETableSubset *etss = E_TABLE_SUBSET (eti->table_model); - if (row >= 0 && row < etss->n_map) { - eti->row_guess = row; - return etss->map_table[row]; - } else - return -1; - } else - return row; -} - -inline static gint -model_to_view_col (ETableItem *eti, - gint col) -{ - gint i; - if (col == -1) - return -1; - 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, - gint col) -{ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - return ecol ? ecol->col_idx : -1; -} - -static void -grab_cancelled (ECanvas *canvas, - GnomeCanvasItem *item, - gpointer data) -{ - ETableItem *eti = data; - - eti->grab_cancelled = TRUE; -} - -inline static void -eti_grab (ETableItem *eti, - GdkDevice *device, - guint32 time) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); - d (g_print ("%s: time: %d\n", __FUNCTION__, time)); - if (eti->grabbed_count == 0) { - GdkGrabStatus grab_status; - - eti->gtk_grabbed = FALSE; - eti->grab_cancelled = FALSE; - - grab_status = e_canvas_item_grab ( - E_CANVAS (item->canvas), - item, - GDK_BUTTON1_MOTION_MASK | - GDK_BUTTON2_MOTION_MASK | - GDK_BUTTON3_MOTION_MASK | - GDK_POINTER_MOTION_MASK | - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK, - NULL, - device, time, - grab_cancelled, - eti); - - if (grab_status != GDK_GRAB_SUCCESS) { - d (g_print ("%s: gtk_grab_add\n", __FUNCTION__)); - gtk_grab_add (GTK_WIDGET (item->canvas)); - eti->gtk_grabbed = TRUE; - } - } - eti->grabbed_count++; -} - -inline static void -eti_ungrab (ETableItem *eti, - guint32 time) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); - d (g_print ("%s: time: %d\n", __FUNCTION__, time)); - eti->grabbed_count--; - if (eti->grabbed_count == 0) { - if (eti->grab_cancelled) { - eti->grab_cancelled = FALSE; - } else { - if (eti->gtk_grabbed) { - d (g_print ("%s: gtk_grab_remove\n", __FUNCTION__)); - gtk_grab_remove (GTK_WIDGET (item->canvas)); - eti->gtk_grabbed = FALSE; - } - gnome_canvas_item_ungrab (item, time); - eti->grabbed_col = -1; - eti->grabbed_row = -1; - } - } -} - -inline static gboolean -eti_editing (ETableItem *eti) -{ - d (g_print ("%s: %s\n", __FUNCTION__, (eti->editing_col == -1) ? "false":"true")); - - if (eti->editing_col == -1) - return FALSE; - else - return TRUE; -} - -inline static GdkColor * -eti_get_cell_background_color (ETableItem *eti, - gint row, - gint col, - gboolean selected, - gboolean *allocatedp) -{ - ECellView *ecell_view = eti->cell_views[col]; - GtkWidget *canvas; - GdkColor *background, bg; - GtkStyle *style; - gchar *color_spec = NULL; - gboolean allocated = FALSE; - - canvas = GTK_WIDGET (GNOME_CANVAS_ITEM (eti)->canvas); - style = gtk_widget_get_style (canvas); - - if (selected) { - if (gtk_widget_has_focus (canvas)) - background = &style->bg[GTK_STATE_SELECTED]; - else - background = &style->bg[GTK_STATE_ACTIVE]; - } else { - background = &style->base[GTK_STATE_NORMAL]; - } - - color_spec = e_cell_get_bg_color (ecell_view, row); - - if (color_spec != NULL) { - if (gdk_color_parse (color_spec, &bg)) { - background = gdk_color_copy (&bg); - allocated = TRUE; - } - } - - if (eti->alternating_row_colors) { - if (row % 2) { - - } else { - if (!allocated) { - background = gdk_color_copy (background); - allocated = TRUE; - } - e_hsv_tweak (background, 0.0f, 0.0f, -0.07f); - } - } - if (allocatedp) - *allocatedp = allocated; - - return background; -} - -inline static GdkColor * -eti_get_cell_foreground_color (ETableItem *eti, - gint row, - gint col, - gboolean selected, - gboolean *allocated) -{ - GtkWidget *canvas; - GdkColor *foreground; - GtkStyle *style; - - canvas = GTK_WIDGET (GNOME_CANVAS_ITEM (eti)->canvas); - style = gtk_widget_get_style (canvas); - - if (allocated) - *allocated = FALSE; - - if (selected) { - if (gtk_widget_has_focus (canvas)) - foreground = &style->fg[GTK_STATE_SELECTED]; - else - foreground = &style->fg[GTK_STATE_ACTIVE]; - } else { - foreground = &style->text[GTK_STATE_NORMAL]; - } - - return foreground; -} - -static void -eti_free_save_state (ETableItem *eti) -{ - if (eti->save_row == -1 || - !eti->cell_views_realized) - return; - - e_cell_free_state ( - eti->cell_views[eti->save_col], view_to_model_col (eti, eti->save_col), - eti->save_col, eti->save_row, eti->save_state); - eti->save_row = -1; - eti->save_col = -1; - eti->save_state = NULL; -} - -/* - * 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) -{ - GnomeCanvasItem *item; - gint i; - - item = GNOME_CANVAS_ITEM (eti); - - if (eti->cell_views_realized) - return; - - if (!(item->flags & GNOME_CANVAS_ITEM_REALIZED)) - return; - - 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) -{ - gint i; - - g_return_if_fail (eti->header); - g_return_if_fail (eti->table_model); - - /* this is just c&p from model pre change, but it fixes things */ - eti_cancel_drag_due_to_model_change (eti); - eti_check_cursor_bounds (eti); - if (eti_editing (eti)) - e_table_item_leave_edit_(eti); - eti->motion_row = -1; - eti->motion_col = -1; - - /* - * 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) -{ - gint i; - - if (eti->cell_views_realized == 0) - return; - - eti_free_save_state (eti); - - 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) -{ - gint i; - - eti_free_save_state (eti); - - 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, - gdouble *x1, - gdouble *y1, - gdouble *x2, - gdouble *y2) -{ - cairo_matrix_t i2c; - ETableItem *eti = E_TABLE_ITEM (item); - - /* Wrong BBox's are the source of redraw nightmares */ - - *x1 = 0; - *y1 = 0; - *x2 = eti->width; - *y2 = eti->height; - - gnome_canvas_item_i2c_matrix (GNOME_CANVAS_ITEM (eti), &i2c); - gnome_canvas_matrix_transform_rect (&i2c, x1, y1, x2, y2); -} - -static void -eti_reflow (GnomeCanvasItem *item, - gint flags) -{ - ETableItem *eti = E_TABLE_ITEM (item); - - if (eti->needs_compute_height) { - gint 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) { - gint new_width = e_table_header_total_width (eti->header); - 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, - const cairo_matrix_t *i2c, - gint flags) -{ - ETableItem *eti = E_TABLE_ITEM (item); - gdouble x1, x2, y1, y2; - - if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->update) - (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->update)(item, i2c, flags); - - x1 = item->x1; - y1 = item->y1; - x2 = item->x2; - y2 = item->y2; - - eti_bounds (item, &item->x1, &item->y1, &item->x2, &item->y2); - if (item->x1 != x1 || - item->y1 != y1 || - item->x2 != x2 || - item->y2 != y2) { - gnome_canvas_request_redraw (item->canvas, x1, y1, x2, y2); - 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; - - g_signal_handler_disconnect ( - eti->table_model, - eti->table_model_pre_change_id); - g_signal_handler_disconnect ( - eti->table_model, - eti->table_model_no_change_id); - g_signal_handler_disconnect ( - eti->table_model, - eti->table_model_change_id); - g_signal_handler_disconnect ( - eti->table_model, - eti->table_model_row_change_id); - g_signal_handler_disconnect ( - eti->table_model, - eti->table_model_cell_change_id); - g_signal_handler_disconnect ( - eti->table_model, - eti->table_model_rows_inserted_id); - g_signal_handler_disconnect ( - eti->table_model, - eti->table_model_rows_deleted_id); - g_object_unref (eti->table_model); - if (eti->source_model) - g_object_unref (eti->source_model); - - eti->table_model_pre_change_id = 0; - eti->table_model_no_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_rows_inserted_id = 0; - eti->table_model_rows_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_selection_model (ETableItem *eti) -{ - if (!eti->selection) - return; - - g_signal_handler_disconnect ( - eti->selection, - eti->selection_change_id); - g_signal_handler_disconnect ( - eti->selection, - eti->selection_row_change_id); - g_signal_handler_disconnect ( - eti->selection, - eti->cursor_change_id); - g_signal_handler_disconnect ( - eti->selection, - eti->cursor_activated_id); - g_object_unref (eti->selection); - - eti->selection_change_id = 0; - eti->selection_row_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; - - g_signal_handler_disconnect ( - eti->header, - eti->header_structure_change_id); - g_signal_handler_disconnect ( - eti->header, - eti->header_dim_change_id); - g_signal_handler_disconnect ( - eti->header, - eti->header_request_width_id); - - if (eti->cell_views) { - eti_unrealize_cell_views (eti); - eti_detach_cell_views (eti); - } - g_object_unref (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 gint -eti_row_height_real (ETableItem *eti, - gint row) -{ - const gint cols = e_table_header_count (eti->header); - gint col; - gint h, max_h; - - g_return_val_if_fail (cols == 0 || eti->cell_views, 0); - - 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 void -confirm_height_cache (ETableItem *eti) -{ - gint i; - - if (eti->uniform_row_height || eti->height_cache) - return; - eti->height_cache = g_new (int, eti->rows); - for (i = 0; i < eti->rows; i++) { - eti->height_cache[i] = -1; - } -} - -static gboolean -height_cache_idle (ETableItem *eti) -{ - gint changed = 0; - gint i; - confirm_height_cache (eti); - 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) -{ - GnomeCanvasItem *item; - - item = GNOME_CANVAS_ITEM (eti); - - if (item->flags & GNOME_CANVAS_ITEM_REALIZED) { - if (eti->height_cache) - g_free (eti->height_cache); - eti->height_cache = NULL; - eti->height_cache_idle_count = 0; - eti->uniform_row_height_cache = -1; - - if (eti->uniform_row_height && eti->height_cache_idle_id != 0) { - g_source_remove (eti->height_cache_idle_id); - eti->height_cache_idle_id = 0; - } - - if ((!eti->uniform_row_height) && 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) -{ - free_height_cache (eti); - confirm_height_cache (eti); -} - -/* - * eti_row_height: - * - * Returns the height used by row @row. This does not include the one-pixel - * used as a separator between rows - */ -static gint -eti_row_height (ETableItem *eti, - gint row) -{ - if (eti->uniform_row_height) { - eti->uniform_row_height_cache = eti_row_height_real (eti, -1); - return eti->uniform_row_height_cache; - } else { - 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 gint -eti_get_height (ETableItem *eti) -{ - const gint rows = eti->rows; - gint height_extra = eti->horizontal_draw_grid ? 1 : 0; - - if (rows == 0) - return 0; - - if (eti->uniform_row_height) { - gint row_height = ETI_ROW_HEIGHT (eti, -1); - return ((row_height + height_extra) * rows + height_extra); - } else { - gint height; - gint row; - if (eti->length_threshold != -1) { - if (rows > eti->length_threshold) { - gint 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 + height_extra) * (rows - row); - break; - } - else - height += eti->height_cache[row] + height_extra; - } - } else - height = (ETI_ROW_HEIGHT (eti, 0) + height_extra) * rows; - - /* - * 1 pixel at the top - */ - return height + height_extra; - } - } - - height = height_extra; - for (row = 0; row < rows; row++) - height += ETI_ROW_HEIGHT (eti, row) + height_extra; - - return height; - } -} - -static void -eti_item_region_redraw (ETableItem *eti, - gint x0, - gint y0, - gint x1, - gint y1) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); - gdouble dx1, dy1, dx2, dy2; - cairo_matrix_t i2c; - - dx1 = x0; - dy1 = y0; - dx2 = x1; - dy2 = y1; - - gnome_canvas_item_i2c_matrix (item, &i2c); - gnome_canvas_matrix_transform_rect (&i2c, &dx1, &dy1, &dx2, &dy2); - - gnome_canvas_request_redraw (item->canvas, floor (dx1), floor (dy1), ceil (dx2), ceil (dy2)); -} - -/* - * Computes the distance between @start_row and @end_row in pixels - */ -gint -e_table_item_row_diff (ETableItem *eti, - gint start_row, - gint end_row) -{ - gint height_extra = eti->horizontal_draw_grid ? 1 : 0; - - if (start_row < 0) - start_row = 0; - if (end_row > eti->rows) - end_row = eti->rows; - - if (eti->uniform_row_height) { - return ((end_row - start_row) * (ETI_ROW_HEIGHT (eti, -1) + height_extra)); - } else { - gint row, total; - total = 0; - for (row = start_row; row < end_row; row++) - total += ETI_ROW_HEIGHT (eti, row) + height_extra; - - return total; - } -} - -static void -eti_get_region (ETableItem *eti, - gint start_col, - gint start_row, - gint end_col, - gint end_row, - gint *x1p, - gint *y1p, - gint *x2p, - gint *y2p) -{ - gint x1, y1, x2, y2; - - x1 = e_table_header_col_diff (eti->header, 0, start_col); - y1 = e_table_item_row_diff (eti, 0, start_row); - x2 = x1 + e_table_header_col_diff (eti->header, start_col, end_col + 1); - y2 = y1 + e_table_item_row_diff (eti, start_row, end_row + 1); - if (x1p) - *x1p = x1; - if (y1p) - *y1p = y1; - if (x2p) - *x2p = x2; - if (y2p) - *y2p = y2; -} - -/* - * 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, - gint start_col, - gint start_row, - gint end_col, - gint end_row, - gint border) -{ - gint x1, y1, x2, y2; - - if (eti->rows > 0) { - - eti_get_region ( - eti, - start_col, start_row, - end_col, end_row, - &x1, &y1, &x2, &y2); - - eti_item_region_redraw ( - eti, - x1 - border, - y1 - border, - x2 + 1 + border, - y2 + 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, - gint start_col, - gint start_row, - gint end_col, - gint end_row, - gint delay) -{ - gint x1, y1, x2, y2; - - eti_get_region ( - eti, - start_col, start_row, - end_col, end_row, - &x1, &y1, &x2, &y2); - - 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_show_cursor (ETableItem *eti, - gint delay) -{ - GnomeCanvasItem *item; - gint cursor_row; - - item = GNOME_CANVAS_ITEM (eti); - - if (!((item->flags & GNOME_CANVAS_ITEM_REALIZED) && eti->cell_views_realized)) - return; - - if (eti->frozen_count > 0) { - eti->queue_show_cursor = TRUE; - return; - } - -#if 0 - g_object_get ( - eti->selection, - "cursor_row", &cursor_row, - NULL); -#else - cursor_row = e_selection_model_cursor_row (eti->selection); -#endif - - d (g_print ("%s: cursor row: %d\n", __FUNCTION__, cursor_row)); - - if (cursor_row != -1) { - cursor_row = model_to_view_row (eti, cursor_row); - eti_request_region_show ( - eti, - 0, cursor_row, eti->cols - 1, cursor_row, - delay); - } -} - -static void -eti_check_cursor_bounds (ETableItem *eti) -{ - GnomeCanvasItem *item; - gint x1, y1, x2, y2; - gint cursor_row; - - item = GNOME_CANVAS_ITEM (eti); - - if (!((item->flags & GNOME_CANVAS_ITEM_REALIZED) && eti->cell_views_realized)) - return; - - if (eti->frozen_count > 0) { - return; - } - - g_object_get ( - eti->selection, - "cursor_row", &cursor_row, - NULL); - - if (cursor_row == -1) { - eti->cursor_x1 = -1; - eti->cursor_y1 = -1; - eti->cursor_x2 = -1; - eti->cursor_y2 = -1; - eti->cursor_on_screen = TRUE; - return; - } - - d (g_print ("%s: model cursor row: %d\n", __FUNCTION__, cursor_row)); - - cursor_row = model_to_view_row (eti, cursor_row); - - d (g_print ("%s: cursor row: %d\n", __FUNCTION__, cursor_row)); - - eti_get_region ( - eti, - 0, cursor_row, eti->cols - 1, cursor_row, - &x1, &y1, &x2, &y2); - eti->cursor_x1 = x1; - eti->cursor_y1 = y1; - eti->cursor_x2 = x2; - eti->cursor_y2 = y2; - eti->cursor_on_screen = e_canvas_item_area_shown (GNOME_CANVAS_ITEM (eti), x1, y1, x2, y2); - - d (g_print ("%s: cursor on screen: %s\n", __FUNCTION__, eti->cursor_on_screen ? "TRUE" : "FALSE")); -} - -static void -eti_maybe_show_cursor (ETableItem *eti, - gint delay) -{ - d (g_print ("%s: cursor on screen: %s\n", __FUNCTION__, eti->cursor_on_screen ? "TRUE" : "FALSE")); - if (eti->cursor_on_screen) - eti_show_cursor (eti, delay); - eti_check_cursor_bounds (eti); -} - -static gboolean -eti_idle_show_cursor_cb (gpointer data) -{ - ETableItem *eti = data; - - if (eti->selection) { - eti_show_cursor (eti, 0); - eti_check_cursor_bounds (eti); - } - - eti->cursor_idle_id = 0; - g_object_unref (eti); - return FALSE; -} - -static void -eti_idle_maybe_show_cursor (ETableItem *eti) -{ - d (g_print ("%s: cursor on screen: %s\n", __FUNCTION__, eti->cursor_on_screen ? "TRUE" : "FALSE")); - if (eti->cursor_on_screen) { - g_object_ref (eti); - if (!eti->cursor_idle_id) - eti->cursor_idle_id = g_idle_add (eti_idle_show_cursor_cb, eti); - } -} - -static void -eti_cancel_drag_due_to_model_change (ETableItem *eti) -{ - if (eti->maybe_in_drag) { - eti->maybe_in_drag = FALSE; - if (!eti->maybe_did_something) - e_selection_model_do_something (E_SELECTION_MODEL (eti->selection), eti->drag_row, eti->drag_col, eti->drag_state); - } - if (eti->in_drag) { - eti->in_drag = FALSE; - } -} - -static void -eti_freeze (ETableItem *eti) -{ - eti->frozen_count++; - d (g_print ("%s: %d\n", __FUNCTION__, eti->frozen_count)); -} - -static void -eti_unfreeze (ETableItem *eti) -{ - if (eti->frozen_count <= 0) - return; - - eti->frozen_count--; - d (g_print ("%s: %d\n", __FUNCTION__, eti->frozen_count)); - if (eti->frozen_count == 0 && eti->queue_show_cursor) { - eti_show_cursor (eti, 0); - eti_check_cursor_bounds (eti); - eti->queue_show_cursor = FALSE; - } -} - -/* - * Callback routine: invoked before the ETableModel suffers a change - */ -static void -eti_table_model_pre_change (ETableModel *table_model, - ETableItem *eti) -{ - eti_cancel_drag_due_to_model_change (eti); - eti_check_cursor_bounds (eti); - if (eti_editing (eti)) - e_table_item_leave_edit_(eti); - eti->motion_row = -1; - eti->motion_col = -1; - eti_freeze (eti); -} - -/* - * Callback routine: invoked when the ETableModel has not suffered a change - */ -static void -eti_table_model_no_change (ETableModel *table_model, - ETableItem *eti) -{ - eti_unfreeze (eti); -} - -/* - * Callback routine: invoked when the ETableModel has suffered a change - */ - -static void -eti_table_model_changed (ETableModel *table_model, - ETableItem *eti) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); - - if (!(item->flags & GNOME_CANVAS_ITEM_REALIZED)) { - eti_unfreeze (eti); - return; - } - - eti->rows = e_table_model_row_count (eti->table_model); - - free_height_cache (eti); - - eti_unfreeze (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)); - - eti_idle_maybe_show_cursor (eti); -} - -static void -eti_table_model_row_changed (ETableModel *table_model, - gint row, - ETableItem *eti) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); - - if (!(item->flags & GNOME_CANVAS_ITEM_REALIZED)) { - eti_unfreeze (eti); - return; - } - - if ((!eti->uniform_row_height) && 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_unfreeze (eti); - - e_table_item_redraw_row (eti, row); -} - -static void -eti_table_model_cell_changed (ETableModel *table_model, - gint col, - gint row, - ETableItem *eti) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); - - if (!(item->flags & GNOME_CANVAS_ITEM_REALIZED)) { - eti_unfreeze (eti); - return; - } - - if ((!eti->uniform_row_height) && 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_unfreeze (eti); - - e_table_item_redraw_row (eti, row); -} - -static void -eti_table_model_rows_inserted (ETableModel *table_model, - gint row, - gint count, - ETableItem *eti) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); - - if (!(item->flags & GNOME_CANVAS_ITEM_REALIZED)) { - eti_unfreeze (eti); - return; - } - eti->rows = e_table_model_row_count (eti->table_model); - - if (eti->height_cache) { - gint i; - eti->height_cache = g_renew (int, eti->height_cache, eti->rows); - memmove (eti->height_cache + row + count, eti->height_cache + row, (eti->rows - count - row) * sizeof (gint)); - for (i = row; i < row + count; i++) - eti->height_cache[i] = -1; - } - - eti_unfreeze (eti); - - eti_idle_maybe_show_cursor (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_table_model_rows_deleted (ETableModel *table_model, - gint row, - gint count, - ETableItem *eti) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); - - if (!(item->flags & GNOME_CANVAS_ITEM_REALIZED)) { - eti_unfreeze (eti); - return; - } - - eti->rows = e_table_model_row_count (eti->table_model); - - if (eti->height_cache && (eti->rows > row)) { - memmove (eti->height_cache + row, eti->height_cache + row + count, (eti->rows - row) * sizeof (gint)); - } - - eti_unfreeze (eti); - - eti_idle_maybe_show_cursor (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)); -} - -/** - * 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, - gint start_col, - gint start_row, - gint end_col, - gint end_row) -{ - gint border; - gint cursor_col, cursor_row; - - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - g_object_get ( - 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 -e_table_item_redraw_row (ETableItem *eti, - gint row) -{ - if (row != -1) - e_table_item_redraw_range (eti, 0, row, eti->cols - 1, row); -} - -static void -eti_add_table_model (ETableItem *eti, - ETableModel *table_model) -{ - g_return_if_fail (eti->table_model == NULL); - - eti->table_model = table_model; - g_object_ref (eti->table_model); - - eti->table_model_pre_change_id = g_signal_connect ( - table_model, "model_pre_change", - G_CALLBACK (eti_table_model_pre_change), eti); - - eti->table_model_no_change_id = g_signal_connect ( - table_model, "model_no_change", - G_CALLBACK (eti_table_model_no_change), eti); - - eti->table_model_change_id = g_signal_connect ( - table_model, "model_changed", - G_CALLBACK (eti_table_model_changed), eti); - - eti->table_model_row_change_id = g_signal_connect ( - table_model, "model_row_changed", - G_CALLBACK (eti_table_model_row_changed), eti); - - eti->table_model_cell_change_id = g_signal_connect ( - table_model, "model_cell_changed", - G_CALLBACK (eti_table_model_cell_changed), eti); - - eti->table_model_rows_inserted_id = g_signal_connect ( - table_model, "model_rows_inserted", - G_CALLBACK (eti_table_model_rows_inserted), eti); - - eti->table_model_rows_deleted_id = g_signal_connect ( - table_model, "model_rows_deleted", - G_CALLBACK (eti_table_model_rows_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) - g_object_ref (eti->source_model); - } - - eti_freeze (eti); - - eti_table_model_changed (table_model, eti); -} - -static void -eti_add_selection_model (ETableItem *eti, - ESelectionModel *selection) -{ - g_return_if_fail (eti->selection == NULL); - - eti->selection = selection; - g_object_ref (eti->selection); - - eti->selection_change_id = g_signal_connect ( - selection, "selection_changed", - G_CALLBACK (eti_selection_change), eti); - - eti->selection_row_change_id = g_signal_connect ( - selection, "selection_row_changed", - G_CALLBACK (eti_selection_row_change), eti); - - eti->cursor_change_id = g_signal_connect ( - selection, "cursor_changed", - G_CALLBACK (eti_cursor_change), eti); - - eti->cursor_activated_id = g_signal_connect ( - selection, "cursor_activated", - G_CALLBACK (eti_cursor_activated), eti); - - eti_selection_change (selection, eti); - g_signal_emit_by_name (eti, "selection_model_added", eti->selection); -} - -static void -eti_header_dim_changed (ETableHeader *eth, - gint col, - ETableItem *eti) -{ - eti->needs_compute_width = 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_header_structure_changed (ETableHeader *eth, - ETableItem *eti) -{ - eti->cols = e_table_header_count (eti->header); - - /* - * There should be at least one column - * BUT: then you can't remove all columns from a header and add new ones. - */ - - 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_attach_cell_views (eti); - eti_realize_cell_views (eti); - } - } - eti->needs_compute_width = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); -} - -static gint -eti_request_column_width (ETableHeader *eth, - gint col, - ETableItem *eti) -{ - gint width = 0; - - if (eti->cell_views && eti->cell_views_realized) { - 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_return_if_fail (eti->header == NULL); - - eti->header = header; - g_object_ref (header); - - eti_header_structure_changed (header, eti); - - eti->header_dim_change_id = g_signal_connect ( - header, "dimension_change", - G_CALLBACK (eti_header_dim_changed), eti); - - eti->header_structure_change_id = g_signal_connect ( - header, "structure_change", - G_CALLBACK (eti_header_structure_changed), eti); - - eti->header_request_width_id = g_signal_connect ( - header, "request_width", - G_CALLBACK (eti_request_column_width), eti); -} - -/* - * GObject::dispose method - */ -static void -eti_dispose (GObject *object) -{ - ETableItem *eti = E_TABLE_ITEM (object); - - eti_remove_header_model (eti); - eti_remove_table_model (eti); - eti_remove_selection_model (eti); - - if (eti->height_cache_idle_id) { - g_source_remove (eti->height_cache_idle_id); - eti->height_cache_idle_id = 0; - } - eti->height_cache_idle_count = 0; - - if (eti->cursor_idle_id) { - g_source_remove (eti->cursor_idle_id); - eti->cursor_idle_id = 0; - } - - if (eti->height_cache) - g_free (eti->height_cache); - eti->height_cache = NULL; - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (eti_parent_class)->dispose (object); -} - -static void -eti_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (object); - ETableItem *eti = E_TABLE_ITEM (object); - gint cursor_col; - - switch (property_id) { - case PROP_TABLE_HEADER: - eti_remove_header_model (eti); - eti_add_header_model (eti, E_TABLE_HEADER (g_value_get_object (value))); - break; - - case PROP_TABLE_MODEL: - eti_remove_table_model (eti); - eti_add_table_model (eti, E_TABLE_MODEL (g_value_get_object (value))); - break; - - case PROP_SELECTION_MODEL: - g_signal_emit_by_name ( - eti, "selection_model_removed", eti->selection); - eti_remove_selection_model (eti); - if (g_value_get_object (value)) - eti_add_selection_model (eti, E_SELECTION_MODEL (g_value_get_object (value))); - break; - - case PROP_LENGTH_THRESHOLD: - eti->length_threshold = g_value_get_int (value); - break; - - case PROP_TABLE_ALTERNATING_ROW_COLORS: - eti->alternating_row_colors = g_value_get_boolean (value); - break; - - case PROP_TABLE_HORIZONTAL_DRAW_GRID: - eti->horizontal_draw_grid = g_value_get_boolean (value); - break; - - case PROP_TABLE_VERTICAL_DRAW_GRID: - eti->vertical_draw_grid = g_value_get_boolean (value); - break; - - case PROP_TABLE_DRAW_FOCUS: - eti->draw_focus = g_value_get_boolean (value); - break; - - case PROP_CURSOR_MODE: - eti->cursor_mode = g_value_get_int (value); - break; - - case PROP_MINIMUM_WIDTH: - case PROP_WIDTH: - if ((eti->minimum_width == eti->width && g_value_get_double (value) > eti->width) || - g_value_get_double (value) < eti->width) { - eti->needs_compute_width = 1; - e_canvas_item_request_reflow (item); - } - eti->minimum_width = g_value_get_double (value); - break; - case PROP_CURSOR_ROW: - g_object_get ( - eti->selection, - "cursor_col", &cursor_col, - NULL); - - e_table_item_focus (eti, cursor_col != -1 ? cursor_col : 0, view_to_model_row (eti, g_value_get_int (value)), 0); - break; - case PROP_UNIFORM_ROW_HEIGHT: - if (eti->uniform_row_height != g_value_get_boolean (value)) { - eti->uniform_row_height = g_value_get_boolean (value); - if (item->flags & GNOME_CANVAS_ITEM_REALIZED) { - free_height_cache (eti); - eti->needs_compute_height = 1; - e_canvas_item_request_reflow (item); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (item); - } - } - break; - } - eti->needs_redraw = 1; - gnome_canvas_item_request_update (item); -} - -static void -eti_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ETableItem *eti; - gint row; - - eti = E_TABLE_ITEM (object); - - switch (property_id) { - case PROP_WIDTH: - g_value_set_double (value, eti->width); - break; - case PROP_HEIGHT: - g_value_set_double (value, eti->height); - break; - case PROP_MINIMUM_WIDTH: - g_value_set_double (value, eti->minimum_width); - break; - case PROP_CURSOR_ROW: - g_object_get ( - eti->selection, - "cursor_row", &row, - NULL); - g_value_set_int (value, model_to_view_row (eti, row)); - break; - case PROP_UNIFORM_ROW_HEIGHT: - g_value_set_boolean (value, eti->uniform_row_height); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -eti_init (ETableItem *eti) -{ - eti->motion_row = -1; - eti->motion_col = -1; - eti->editing_col = -1; - eti->editing_row = -1; - eti->height = 0; - eti->width = 0; - eti->minimum_width = 0; - - eti->save_col = -1; - eti->save_row = -1; - eti->save_state = NULL; - - eti->click_count = 0; - - eti->height_cache = NULL; - eti->height_cache_idle_id = 0; - eti->height_cache_idle_count = 0; - - eti->length_threshold = -1; - eti->uniform_row_height = FALSE; - - eti->uses_source_model = 0; - eti->source_model = NULL; - - eti->row_guess = -1; - eti->cursor_mode = E_CURSOR_SIMPLE; - - eti->selection_change_id = 0; - eti->selection_row_change_id = 0; - eti->cursor_change_id = 0; - eti->cursor_activated_id = 0; - eti->selection = NULL; - - eti->old_cursor_row = -1; - - eti->needs_redraw = 0; - eti->needs_compute_height = 0; - - eti->in_key_press = 0; - - eti->maybe_did_something = TRUE; - - eti->grabbed_count = 0; - eti->gtk_grabbed = 0; - - eti->in_drag = 0; - eti->maybe_in_drag = 0; - eti->grabbed = 0; - - eti->grabbed_col = -1; - eti->grabbed_row = -1; - - eti->cursor_on_screen = FALSE; - eti->cursor_x1 = -1; - eti->cursor_y1 = -1; - eti->cursor_x2 = -1; - eti->cursor_y2 = -1; - - eti->rows = -1; - eti->cols = -1; - - eti->frozen_count = 0; - eti->queue_show_cursor = FALSE; - - e_canvas_item_set_reflow_callback (GNOME_CANVAS_ITEM (eti), eti_reflow); -} - -#define gray50_width 2 -#define gray50_height 2 -static const gchar gray50_bits[] = { - 0x02, 0x01, }; - -static gboolean -eti_tree_unfreeze (GtkWidget *widget, - GdkEvent *event, - ETableItem *eti) -{ - - if (widget) - g_object_set_data (G_OBJECT (widget), "freeze-cursor", NULL); - - return FALSE; -} - -static void -eti_realize (GnomeCanvasItem *item) -{ - ETableItem *eti = E_TABLE_ITEM (item); - - if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->realize) - (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->realize)(item); - - eti->rows = e_table_model_row_count (eti->table_model); - - g_signal_connect ( - item->canvas, "scroll_event", - G_CALLBACK (eti_tree_unfreeze), eti); - - if (eti->cell_views == NULL) - eti_attach_cell_views (eti); - - eti_realize_cell_views (eti); - - free_height_cache (eti); - - if (item->canvas->focused_item == NULL && eti->selection) { - gint row; - - row = e_selection_model_cursor_row (E_SELECTION_MODEL (eti->selection)); - row = model_to_view_row (eti, row); - if (row != -1) { - e_canvas_item_grab_focus (item, FALSE); - eti_show_cursor (eti, 0); - eti_check_cursor_bounds (eti); - } - } - - eti->needs_compute_height = 1; - eti->needs_compute_width = 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->grabbed_count > 0) { - d (g_print ("%s: eti_ungrab\n", __FUNCTION__)); - eti_ungrab (eti, -1); - } - - if (eti_editing (eti)) - e_table_item_leave_edit_(eti); - - if (eti->height_cache_idle_id) { - g_source_remove (eti->height_cache_idle_id); - eti->height_cache_idle_id = 0; - } - - if (eti->height_cache) - g_free (eti->height_cache); - eti->height_cache = NULL; - eti->height_cache_idle_count = 0; - - 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_grid_line (ETableItem *eti, - cairo_t *cr, - GtkStyle *style, - gint x1, - gint y1, - gint x2, - gint y2) -{ - cairo_save (cr); - - cairo_set_line_width (cr, 1.0); - gdk_cairo_set_source_color (cr, &style->dark[GTK_STATE_NORMAL]); - - cairo_move_to (cr, x1 + 0.5, y1 + 0.5); - cairo_line_to (cr, x2 + 0.5, y2 + 0.5); - cairo_stroke (cr); - - cairo_restore (cr); -} - -static void -eti_draw (GnomeCanvasItem *item, - cairo_t *cr, - gint x, - gint y, - gint width, - gint height) -{ - ETableItem *eti = E_TABLE_ITEM (item); - const gint rows = eti->rows; - const gint cols = eti->cols; - gint row, col; - gint first_col, last_col, x_offset; - gint first_row, last_row, y_offset, yd; - gint x1, x2; - gint f_x1, f_x2, f_y1, f_y2; - gboolean f_found; - cairo_matrix_t i2c; - gdouble eti_base_x, eti_base_y, lower_right_y, lower_right_x; - GtkWidget *canvas = GTK_WIDGET (item->canvas); - GtkStyle *style = gtk_widget_get_style (canvas); - gint height_extra = eti->horizontal_draw_grid ? 1 : 0; - - /* - * Find out our real position after grouping - */ - gnome_canvas_item_i2c_matrix (item, &i2c); - eti_base_x = 0; - eti_base_y = 0; - cairo_matrix_transform_point (&i2c, &eti_base_x, &eti_base_y); - - lower_right_x = eti->width; - lower_right_y = eti->height; - cairo_matrix_transform_point (&i2c, &lower_right_x, &lower_right_y); - - /* - * First column to draw, last column to draw - */ - first_col = -1; - x_offset = 0; - x1 = 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. - */ - if (eti->uniform_row_height) { - first_row = (y - floor (eti_base_y) - height_extra) / (ETI_ROW_HEIGHT (eti, -1) + height_extra); - last_row = (y + height - floor (eti_base_y) ) / (ETI_ROW_HEIGHT (eti, -1) + height_extra) + 1; - if (first_row > last_row) - return; - y_offset = floor (eti_base_y) - y + height_extra + first_row * (ETI_ROW_HEIGHT (eti, -1) + height_extra); - if (first_row < 0) - first_row = 0; - if (last_row > eti->rows) - last_row = eti->rows; - } else { - gint y1, y2; - - y_offset = 0; - first_row = -1; - - y1 = y2 = floor (eti_base_y) + height_extra; - for (row = 0; row < rows; row++, y1 = y2) { - - y2 += ETI_ROW_HEIGHT (eti, row) + height_extra; - - 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; - } - - if (first_row == -1) - return; - - /* - * Draw cells - */ - yd = y_offset; - f_x1 = f_x2 = f_y1 = f_y2 = -1; - f_found = FALSE; - - if (eti->horizontal_draw_grid && first_row == 0) - eti_draw_grid_line (eti, cr, style, eti_base_x - x, yd, eti_base_x + eti->width - x, yd); - - yd += height_extra; - - for (row = first_row; row < last_row; row++) { - gint xd; - gboolean selected; - gint cursor_col, cursor_row; - - height = ETI_ROW_HEIGHT (eti, row); - - xd = x_offset; - - selected = e_selection_model_is_row_selected (E_SELECTION_MODEL (eti->selection), view_to_model_row (eti,row)); - - g_object_get ( - 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; - gboolean cursor = FALSE; - ECellFlags flags; - gboolean free_background; - GdkColor *background; - gint x1, x2, y1, y2; - cairo_pattern_t *pat; - - switch (eti->cursor_mode) { - case E_CURSOR_SIMPLE: - case E_CURSOR_SPREADSHEET: - if (cursor_col == ecol->col_idx && cursor_row == view_to_model_row (eti, row)) { - col_selected = !col_selected; - cursor = TRUE; - } - break; - case E_CURSOR_LINE: - /* Nothing */ - break; - } - - x1 = xd; - y1 = yd + 1; - x2 = x1 + ecol->width; - y2 = yd + height; - - background = eti_get_cell_background_color (eti, row, col, col_selected, &free_background); - - cairo_save (cr); - pat = cairo_pattern_create_linear (0, y1, 0, y2); - cairo_pattern_add_color_stop_rgba ( - pat, 0.0, background->red / 65535.0 , - background->green / 65535.0, - background->blue / 65535.0, selected ? 0.8: 1.0); - if (selected) - cairo_pattern_add_color_stop_rgba ( - pat, 0.5, background->red / 65535.0 , - background->green / 65535.0, - background->blue / 65535.0, 0.9); - - cairo_pattern_add_color_stop_rgba ( - pat, 1, background->red / 65535.0 , - background->green / 65535.0, - background->blue / 65535.0, selected ? 0.8 : 1.0); - cairo_rectangle (cr, x1, y1, ecol->width, height - 1); - cairo_set_source (cr, pat); - cairo_fill_preserve (cr); - cairo_pattern_destroy (pat); - cairo_set_line_width (cr, 0); - cairo_stroke (cr); - cairo_restore (cr); - - cairo_save (cr); - cairo_set_line_width (cr, 1.0); - cairo_set_source_rgba ( - cr, background->red / 65535.0 , - background->green / 65535.0, - background->blue / 65535.0, 1); - cairo_move_to (cr, x1, y1); - cairo_line_to (cr, x2, y1); - cairo_stroke (cr); - - cairo_set_line_width (cr, 1.0); - cairo_set_source_rgba ( - cr, background->red / 65535.0 , - background->green / 65535.0, - background->blue / 65535.0, 1); - cairo_move_to (cr, x1, y2); - cairo_line_to (cr, x2, y2); - cairo_stroke (cr); - cairo_restore (cr); - - if (free_background) - gdk_color_free (background); - - flags = col_selected ? E_CELL_SELECTED : 0; - flags |= gtk_widget_has_focus (canvas) ? E_CELL_FOCUSED : 0; - flags |= cursor ? E_CELL_CURSOR : 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, cr, ecol->col_idx, col, row, flags, - xd, yd, xd + ecol->width, yd + height); - - if (!f_found && !selected) { - switch (eti->cursor_mode) { - case E_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 + 1; - f_y2 = yd + height; - f_found = TRUE; - } - break; - case E_CURSOR_SIMPLE: - case E_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->horizontal_draw_grid) { - eti_draw_grid_line (eti, cr, style, eti_base_x - x, yd, eti_base_x + eti->width - x, yd); - yd++; - } - } - - if (eti->vertical_draw_grid) { - gint xd = x_offset; - - for (col = first_col; col <= last_col; col++) { - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - eti_draw_grid_line (eti, cr, style, 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) { - static const double dash[] = { 1.0, 1.0 }; - cairo_set_line_width (cr, 1.0); - cairo_rectangle ( - cr, - f_x1 + 0.5, f_x2 + 0.5, - f_x2 - f_x1 - 1, f_y2 - f_y1); - - gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]); - cairo_stroke_preserve (cr); - - cairo_set_dash (cr, dash, G_N_ELEMENTS (dash), 0.0); - gdk_cairo_set_source_color (cr, &style->fg[GTK_STATE_NORMAL]); - cairo_stroke (cr); - } -} - -static GnomeCanvasItem * -eti_point (GnomeCanvasItem *item, - gdouble x, - gdouble y, - gint cx, - gint cy) -{ - return item; -} - -static gboolean -find_cell (ETableItem *eti, - gdouble x, - gdouble y, - gint *view_col_res, - gint *view_row_res, - gdouble *x1_res, - gdouble *y1_res) -{ - const gint cols = eti->cols; - const gint rows = eti->rows; - gdouble x1, y1, x2, y2; - gint col, row; - - gint height_extra = eti->horizontal_draw_grid ? 1 : 0; - - /* FIXME: this routine is inneficient, fix later */ - - if (eti->grabbed_col >= 0 && eti->grabbed_row >= 0) { - *view_col_res = eti->grabbed_col; - *view_row_res = eti->grabbed_row; - *x1_res = x - e_table_header_col_diff (eti->header, 0, eti->grabbed_col); - *y1_res = y - e_table_item_row_diff (eti, 0, eti->grabbed_row); - return TRUE; - } - - if (cols == 0 || rows == 0) - return FALSE; - - 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; - } - - if (eti->uniform_row_height) { - if (y < height_extra) - return FALSE; - row = (y - height_extra) / (ETI_ROW_HEIGHT (eti, -1) + height_extra); - y1 = row * (ETI_ROW_HEIGHT (eti, -1) + height_extra) + height_extra; - if (row >= eti->rows) - return FALSE; - } else { - y1 = y2 = height_extra; - if (y < height_extra) - return FALSE; - for (row = 0; row < rows; row++, y1 = y2) { - y2 += ETI_ROW_HEIGHT (eti, row) + height_extra; - - if (y <= y2) - break; - } - - if (row == rows) - return FALSE; - } - *view_col_res = col; - if (x1_res) - *x1_res = x - x1; - *view_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) -{ - gint cursor_col, cursor_row; - g_object_get ( - 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) -{ - gint cursor_col, cursor_row; - g_object_get ( - 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 gint -eti_e_cell_event (ETableItem *item, - ECellView *ecell_view, - GdkEvent *event, - gint model_col, - gint view_col, - gint 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) { - GdkDevice *event_device; - guint32 event_time; - - d (g_print ("%s: eti_grab\n", __FUNCTION__)); - - event_device = gdk_event_get_device (event); - event_time = gdk_event_get_time (event); - eti_grab (item, event_device, event_time); - - item->grabbed_col = view_col; - item->grabbed_row = row; - } - - if (actions & E_CELL_UNGRAB) { - guint32 event_time; - - d (g_print ("%s: eti_ungrab\n", __FUNCTION__)); - - event_time = gdk_event_get_time (event); - eti_ungrab (item, event_time); - - item->grabbed_col = -1; - item->grabbed_row = -1; - } - - return ret_val; -} - -/* FIXME: cursor */ -static gint -eti_event (GnomeCanvasItem *item, - GdkEvent *event) -{ - ETableItem *eti = E_TABLE_ITEM (item); - ECellView *ecell_view; - GdkModifierType event_state = 0; - GdkEvent *event_copy; - guint event_button = 0; - guint event_keyval = 0; - gdouble event_x_item = 0; - gdouble event_y_item = 0; - gdouble event_x_win = 0; - gdouble event_y_win = 0; - guint32 event_time; - gboolean return_val = TRUE; -#if d(!)0 - gboolean leave = FALSE; -#endif - - if (!eti->header) - return FALSE; - - /* Don't fetch the device here. GnomeCanvas frequently emits - * synthesized events, and calling gdk_event_get_device() on them - * will trigger a runtime warning. Fetch the device where needed. */ - gdk_event_get_button (event, &event_button); - gdk_event_get_coords (event, &event_x_win, &event_y_win); - gdk_event_get_keyval (event, &event_keyval); - gdk_event_get_state (event, &event_state); - event_time = gdk_event_get_time (event); - - switch (event->type) { - case GDK_BUTTON_PRESS: { - gdouble x1, y1; - gint col, row; - gint cursor_row, cursor_col; - gint new_cursor_row, new_cursor_col; - ECellFlags flags = 0; - - d (g_print ("%s: GDK_BUTTON_PRESS received, button %d\n", __FUNCTION__, event_button)); - - switch (event_button) { - case 1: /* Fall through. */ - case 2: - e_canvas_item_grab_focus (GNOME_CANVAS_ITEM (eti), TRUE); - - event_x_item = event_x_win; - event_y_item = event_y_win; - - gnome_canvas_item_w2i ( - item, &event_x_item, &event_y_item); - - if (!find_cell (eti, event_x_item, event_y_item, &col, &row, &x1, &y1)) { - if (eti_editing (eti)) - e_table_item_leave_edit_(eti); - return TRUE; - } - - ecell_view = eti->cell_views[col]; - - /* Clone the event and alter its position. */ - event_copy = gdk_event_copy (event); - event_copy->button.x = x1; - event_copy->button.y = y1; - - g_object_get ( - eti->selection, - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (cursor_col == view_to_model_col (eti, col) && cursor_row == view_to_model_row (eti, row)) { - flags = E_CELL_CURSOR; - } else { - flags = 0; - } - - return_val = eti_e_cell_event ( - eti, ecell_view, event_copy, - view_to_model_col (eti, col), - col, row, flags); - if (return_val) { - gdk_event_free (event_copy); - return TRUE; - } - - g_signal_emit ( - eti, eti_signals[CLICK], 0, - row, view_to_model_col (eti, col), - event_copy, &return_val); - - gdk_event_free (event_copy); - - if (return_val) { - eti->click_count = 0; - return TRUE; - } - - g_object_get ( - eti->selection, - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - eti->maybe_did_something = - e_selection_model_maybe_do_something ( - E_SELECTION_MODEL (eti->selection), - view_to_model_row (eti, row), - view_to_model_col (eti, col), - event_state); - g_object_get ( - eti->selection, - "cursor_row", &new_cursor_row, - "cursor_col", &new_cursor_col, - NULL); - - if (cursor_row != new_cursor_row || cursor_col != new_cursor_col) { - eti->click_count = 1; - } else { - eti->click_count++; - eti->row_guess = row; - - if ((!eti_editing (eti)) && e_table_model_is_cell_editable (eti->table_model, cursor_col, row)) { - e_table_item_enter_edit (eti, col, row); - } - - /* - * Adjust the event positions - */ - - if (eti_editing (eti)) { - return_val = eti_e_cell_event ( - eti, ecell_view, event, - view_to_model_col (eti, col), - col, row, - E_CELL_EDITING | - E_CELL_CURSOR); - if (return_val) - return TRUE; - } - } - - if (event_button == 1) { - GdkDevice *event_device; - - return_val = TRUE; - - event_device = gdk_event_get_device (event); - - eti->maybe_in_drag = TRUE; - eti->drag_row = new_cursor_row; - eti->drag_col = new_cursor_col; - eti->drag_x = event_x_item; - eti->drag_y = event_y_item; - eti->drag_state = event_state; - eti->grabbed = TRUE; - d (g_print ("%s: eti_grab\n", __FUNCTION__)); - eti_grab (eti, event_device, event_time); - } - - break; - case 3: - e_canvas_item_grab_focus (GNOME_CANVAS_ITEM (eti), TRUE); - - event_x_item = event_x_win; - event_y_item = event_y_win; - - gnome_canvas_item_w2i ( - item, &event_x_item, &event_y_item); - - if (!find_cell (eti, event_x_item, event_y_item, &col, &row, &x1, &y1)) - return TRUE; - - e_selection_model_right_click_down ( - E_SELECTION_MODEL (eti->selection), - view_to_model_row (eti, row), - view_to_model_col (eti, col), 0); - - /* Clone the event and alter its position. */ - event_copy = gdk_event_copy (event); - event_copy->button.x = event_x_item; - event_copy->button.y = event_y_item; - - g_signal_emit ( - eti, eti_signals[RIGHT_CLICK], 0, - row, view_to_model_col (eti, col), - event, &return_val); - - gdk_event_free (event_copy); - - if (!return_val) - e_selection_model_right_click_up (E_SELECTION_MODEL (eti->selection)); - break; - case 4: - case 5: - return FALSE; - - } - break; - } - - case GDK_BUTTON_RELEASE: { - gdouble x1, y1; - gint col, row; - gint cursor_row, cursor_col; - - d (g_print ("%s: GDK_BUTTON_RELEASE received, button %d\n", __FUNCTION__, event_button)); - - if (eti->grabbed_count > 0) { - d (g_print ("%s: eti_ungrab\n", __FUNCTION__)); - eti_ungrab (eti, event_time); - } - - if (event_button == 1) { - if (eti->maybe_in_drag) { - eti->maybe_in_drag = FALSE; - if (!eti->maybe_did_something) - e_selection_model_do_something (E_SELECTION_MODEL (eti->selection), eti->drag_row, eti->drag_col, eti->drag_state); - } - if (eti->in_drag) { - eti->in_drag = FALSE; - } - } - - switch (event_button) { - case 1: /* Fall through. */ - case 2: - - event_x_item = event_x_win; - event_y_item = event_y_win; - - gnome_canvas_item_w2i ( - item, &event_x_item, &event_y_item); -#if d(!)0 - { - gboolean cell_found = find_cell ( - eti, event_x_item, event_y_item, - &col, &row, &x1, &y1); - g_print ( - "%s: find_cell(%f, %f) = %s(%d, %d, %f, %f)\n", - __FUNCTION__, event_x_item, event_y_item, - cell_found?"true":"false", col, row, x1, y1); - } -#endif - - if (!find_cell (eti, event_x_item, event_y_item, &col, &row, &x1, &y1)) - return TRUE; - - g_object_get ( - eti->selection, - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (eti_editing (eti) && cursor_row == view_to_model_row (eti, row) && cursor_col == view_to_model_col (eti, col)) { - - d (g_print ("%s: GDK_BUTTON_RELEASE received, button %d, line: %d\n", __FUNCTION__, event_button, __LINE__)) -; - - ecell_view = eti->cell_views[col]; - - /* Clone the event and alter its position. */ - event_copy = gdk_event_copy (event); - event_copy->button.x = x1; - event_copy->button.y = y1; - - return_val = eti_e_cell_event ( - eti, ecell_view, event_copy, - view_to_model_col (eti, col), - col, row, - E_CELL_EDITING | - E_CELL_CURSOR); - - gdk_event_free (event_copy); - } - break; - case 3: - e_selection_model_right_click_up (E_SELECTION_MODEL (eti->selection)); - return_val = TRUE; - break; - case 4: - case 5: - return FALSE; - - } - break; - } - - case GDK_2BUTTON_PRESS: { - gint model_col, model_row; -#if 0 - gdouble x1, y1; -#endif - - d (g_print ("%s: GDK_2BUTTON_PRESS received, button %d\n", __FUNCTION__, event_button)); - - /* - * click_count is so that if you click on two - * different rows we don't send a double click signal. - */ - - if (eti->click_count >= 2) { - - event_x_item = event_x_win; - event_y_item = event_y_win; - - gnome_canvas_item_w2i ( - item, &event_x_item, &event_y_item); - - g_object_get ( - eti->selection, - "cursor_row", &model_row, - "cursor_col", &model_col, - NULL); - - /* Clone the event and alter its position. */ - event_copy = gdk_event_copy (event); - event_copy->button.x = event_x_item - - e_table_header_col_diff ( - eti->header, 0, - model_to_view_col (eti, model_col)); - event_copy->button.y = event_y_item - - e_table_item_row_diff ( - eti, 0, - model_to_view_row (eti, model_row)); - - if (event_button == 1) { - if (eti->maybe_in_drag) { - eti->maybe_in_drag = FALSE; - if (!eti->maybe_did_something) - e_selection_model_do_something (E_SELECTION_MODEL (eti->selection), eti->drag_row, eti->drag_col, eti->drag_state); - } - if (eti->in_drag) { - eti->in_drag = FALSE; - } - if (eti_editing (eti)) - e_table_item_leave_edit_ (eti); - - } - - if (eti->grabbed_count > 0) { - d (g_print ("%s: eti_ungrab\n", __FUNCTION__)); - eti_ungrab (eti, event_time); - } - - if (model_row != -1 && model_col != -1) { - g_signal_emit ( - eti, eti_signals[DOUBLE_CLICK], 0, - model_row, model_col, event_copy); - } - - gdk_event_free (event_copy); - } - break; - } - case GDK_MOTION_NOTIFY: { - gint col, row, flags; - gdouble x1, y1; - gint cursor_col, cursor_row; - - event_x_item = event_x_win; - event_y_item = event_y_win; - - gnome_canvas_item_w2i (item, &event_x_item, &event_y_item); - - if (eti->maybe_in_drag) { - if (abs (event_x_item - eti->drag_x) >= 3 || - abs (event_y_item - eti->drag_y) >= 3) { - gboolean drag_handled; - - eti->maybe_in_drag = 0; - - /* Clone the event and - * alter its position. */ - event_copy = gdk_event_copy (event); - event_copy->motion.x = event_x_item; - event_copy->motion.y = event_y_item; - - g_signal_emit ( - eti, eti_signals[START_DRAG], 0, - eti->drag_row, eti->drag_col, - event_copy, &drag_handled); - - gdk_event_free (event_copy); - - if (drag_handled) - eti->in_drag = 1; - else - eti->in_drag = 0; - } - } - - if (!find_cell (eti, event_x_item, event_y_item, &col, &row, &x1, &y1)) - return TRUE; - - if (eti->motion_row != -1 && eti->motion_col != -1 && - (row != eti->motion_row || col != eti->motion_col)) { - GdkEvent *cross = gdk_event_new (GDK_LEAVE_NOTIFY); - cross->crossing.time = event_time; - return_val = eti_e_cell_event ( - eti, eti->cell_views[eti->motion_col], - cross, - view_to_model_col (eti, eti->motion_col), - eti->motion_col, eti->motion_row, 0); - } - - eti->motion_row = row; - eti->motion_col = col; - - g_object_get ( - eti->selection, - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - flags = 0; - if (cursor_row == view_to_model_row (eti, row) && cursor_col == view_to_model_col (eti, col)) { - flags = E_CELL_EDITING | E_CELL_CURSOR; - } - - ecell_view = eti->cell_views[col]; - - /* Clone the event and alter its position. */ - event_copy = gdk_event_copy (event); - event_copy->motion.x = x1; - event_copy->motion.y = y1; - - return_val = eti_e_cell_event ( - eti, ecell_view, event_copy, - view_to_model_col (eti, col), col, row, flags); - - gdk_event_free (event_copy); - - break; - } - - case GDK_KEY_PRESS: { - gint cursor_row, cursor_col; - gint handled = TRUE; - - d (g_print ("%s: GDK_KEY_PRESS received, keyval: %d\n", __FUNCTION__, (gint) e->key.keyval)); - - g_object_get ( - eti->selection, - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (cursor_row == -1 && cursor_col == -1) - return FALSE; - - eti->in_key_press = TRUE; - - switch (event_keyval) { - case GDK_KEY_Left: - case GDK_KEY_KP_Left: - if (eti_editing (eti)) { - handled = FALSE; - break; - } - - g_signal_emit ( - eti, eti_signals[KEY_PRESS], 0, - model_to_view_row (eti, cursor_row), - cursor_col, event, &return_val); - if ((!return_val) && - (atk_get_root () || eti->cursor_mode != E_CURSOR_LINE) && - cursor_col != view_to_model_col (eti, 0)) - eti_cursor_move_left (eti); - return_val = 1; - break; - - case GDK_KEY_Right: - case GDK_KEY_KP_Right: - if (eti_editing (eti)) { - handled = FALSE; - break; - } - - g_signal_emit ( - eti, eti_signals[KEY_PRESS], 0, - model_to_view_row (eti, cursor_row), - cursor_col, event, &return_val); - if ((!return_val) && - (atk_get_root () || eti->cursor_mode != E_CURSOR_LINE) && - cursor_col != view_to_model_col (eti, eti->cols - 1)) - eti_cursor_move_right (eti); - return_val = 1; - break; - - case GDK_KEY_Up: - case GDK_KEY_KP_Up: - case GDK_KEY_Down: - case GDK_KEY_KP_Down: - if ((event_state & GDK_MOD1_MASK) - && ((event_keyval == GDK_KEY_Down) || (event_keyval == GDK_KEY_KP_Down))) { - gint view_col = model_to_view_col (eti, cursor_col); - - if ((view_col >= 0) && (view_col < eti->cols)) - if (eti_e_cell_event (eti, eti->cell_views[view_col], event, cursor_col, view_col, model_to_view_row (eti, cursor_row), E_CELL_CURSOR)) - return TRUE; - } else - return_val = e_selection_model_key_press (E_SELECTION_MODEL (eti->selection), (GdkEventKey *) event); - break; - case GDK_KEY_Home: - case GDK_KEY_KP_Home: - if (eti_editing (eti)) { - handled = FALSE; - break; - } - - if (eti->cursor_mode != E_CURSOR_LINE) { - eti_cursor_move (eti, model_to_view_row (eti, cursor_row), 0); - return_val = TRUE; - } else - return_val = e_selection_model_key_press (E_SELECTION_MODEL (eti->selection), (GdkEventKey *) event); - break; - case GDK_KEY_End: - case GDK_KEY_KP_End: - if (eti_editing (eti)) { - handled = FALSE; - break; - } - - if (eti->cursor_mode != E_CURSOR_LINE) { - eti_cursor_move (eti, model_to_view_row (eti, cursor_row), eti->cols - 1); - return_val = TRUE; - } else - return_val = e_selection_model_key_press (E_SELECTION_MODEL (eti->selection), (GdkEventKey *) event); - break; - case GDK_KEY_Tab: - case GDK_KEY_KP_Tab: - case GDK_KEY_ISO_Left_Tab: - if ((event_state & GDK_CONTROL_MASK) != 0) { - return_val = FALSE; - break; - } - if (eti->cursor_mode == E_CURSOR_SPREADSHEET) { - if ((event_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; - } - g_object_get ( - 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->table_model, cursor_col, model_to_view_row (eti, 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_KEY_Return: - case GDK_KEY_KP_Enter: - case GDK_KEY_ISO_Enter: - case GDK_KEY_3270_Enter: - if (eti_editing (eti)) { - ecell_view = eti->cell_views[eti->editing_col]; - return_val = eti_e_cell_event ( - eti, ecell_view, event, - view_to_model_col (eti, eti->editing_col), - eti->editing_col, eti->editing_row, E_CELL_EDITING | E_CELL_CURSOR | E_CELL_PREEDIT); - if (!return_val) - break; - } - g_signal_emit ( - eti, eti_signals[KEY_PRESS], 0, - model_to_view_row (eti, cursor_row), - cursor_col, event, &return_val); - if (!return_val) - return_val = e_selection_model_key_press (E_SELECTION_MODEL (eti->selection), (GdkEventKey *) event); - break; - - default: - handled = FALSE; - break; - } - - if (!handled) { - switch (event_keyval) { - case GDK_KEY_Scroll_Lock: - case GDK_KEY_Sys_Req: - case GDK_KEY_Shift_L: - case GDK_KEY_Shift_R: - case GDK_KEY_Control_L: - case GDK_KEY_Control_R: - case GDK_KEY_Caps_Lock: - case GDK_KEY_Shift_Lock: - case GDK_KEY_Meta_L: - case GDK_KEY_Meta_R: - case GDK_KEY_Alt_L: - case GDK_KEY_Alt_R: - case GDK_KEY_Super_L: - case GDK_KEY_Super_R: - case GDK_KEY_Hyper_L: - case GDK_KEY_Hyper_R: - case GDK_KEY_ISO_Lock: - break; - - default: - 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->table_model, cursor_col, row)) { - e_table_item_enter_edit (eti, col, row); - } - } - if (!eti_editing (eti)) { - g_signal_emit ( - eti, eti_signals[KEY_PRESS], 0, - model_to_view_row (eti, cursor_row), - cursor_col, event, &return_val); - if (!return_val) - e_selection_model_key_press (E_SELECTION_MODEL (eti->selection), (GdkEventKey *) event); - } else { - ecell_view = eti->cell_views[eti->editing_col]; - return_val = eti_e_cell_event ( - eti, ecell_view, event, - view_to_model_col (eti, eti->editing_col), - eti->editing_col, eti->editing_row, E_CELL_EDITING | E_CELL_CURSOR); - if (!return_val) - e_selection_model_key_press (E_SELECTION_MODEL (eti->selection), (GdkEventKey *) event); - } - break; - } - } - eti->in_key_press = FALSE; - break; - } - - case GDK_KEY_RELEASE: { - gint cursor_row, cursor_col; - - d (g_print ("%s: GDK_KEY_RELEASE received, keyval: %d\n", __FUNCTION__, (gint) event_keyval)); - - g_object_get ( - 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, event, - view_to_model_col (eti, eti->editing_col), - eti->editing_col, eti->editing_row, E_CELL_EDITING | E_CELL_CURSOR); - } - break; - } - - case GDK_LEAVE_NOTIFY: - d (leave = TRUE); - case GDK_ENTER_NOTIFY: - d (g_print ("%s: %s received\n", __FUNCTION__, leave ? "GDK_LEAVE_NOTIFY" : "GDK_ENTER_NOTIFY")); - if (eti->motion_row != -1 && eti->motion_col != -1) - return_val = eti_e_cell_event ( - eti, eti->cell_views[eti->motion_col], - event, - view_to_model_col (eti, eti->motion_col), - eti->motion_col, eti->motion_row, 0); - eti->motion_row = -1; - eti->motion_col = -1; - - break; - - case GDK_FOCUS_CHANGE: - d (g_print ("%s: GDK_FOCUS_CHANGE received, %s\n", __FUNCTION__, e->focus_change.in ? "in": "out")); - if (event->focus_change.in) { - if (eti->save_row != -1 && - eti->save_col != -1 && - !eti_editing (eti) && - e_table_model_is_cell_editable (eti->table_model, view_to_model_col (eti, eti->save_col), eti->save_row)) { - e_table_item_enter_edit (eti, eti->save_col, eti->save_row); - e_cell_load_state ( - eti->cell_views[eti->editing_col], view_to_model_col (eti, eti->save_col), - eti->save_col, eti->save_row, eti->edit_ctx, eti->save_state); - eti_free_save_state (eti); - } - } else { - if (eti_editing (eti)) { - eti_free_save_state (eti); - - eti->save_row = eti->editing_row; - eti->save_col = eti->editing_col; - eti->save_state = e_cell_save_state ( - eti->cell_views[eti->editing_col], view_to_model_col (eti, eti->editing_col), - eti->editing_col, eti->editing_row, eti->edit_ctx); - e_table_item_leave_edit_(eti); - } - } - - default: - return_val = FALSE; - } - /* d(g_print("%s: returning: %s\n", __FUNCTION__, return_val?"true":"false"));*/ - - return return_val; -} - -static void -eti_style_set (ETableItem *eti, - GtkStyle *previous_style) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); - - if (!(item->flags & GNOME_CANVAS_ITEM_REALIZED)) - return; - - if (eti->cell_views_realized) { - gint i; - gint n_cells = eti->n_cells; - - for (i = 0; i < n_cells; i++) { - e_cell_style_set (eti->cell_views[i], previous_style); - } - } - - 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)); - - free_height_cache (eti); - - eti_idle_maybe_show_cursor (eti); -} - -static void -eti_class_init (ETableItemClass *class) -{ - GnomeCanvasItemClass *item_class = GNOME_CANVAS_ITEM_CLASS (class); - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->dispose = eti_dispose; - object_class->set_property = eti_set_property; - object_class->get_property = eti_get_property; - - 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; - - class->cursor_change = NULL; - class->cursor_activated = NULL; - class->double_click = NULL; - class->right_click = NULL; - class->click = NULL; - class->key_press = NULL; - class->start_drag = NULL; - class->style_set = eti_style_set; - class->selection_model_removed = NULL; - class->selection_model_added = NULL; - - g_object_class_install_property ( - object_class, - PROP_TABLE_HEADER, - g_param_spec_object ( - "ETableHeader", - "Table header", - "Table header", - E_TYPE_TABLE_HEADER, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_TABLE_MODEL, - g_param_spec_object ( - "ETableModel", - "Table model", - "Table model", - E_TYPE_TABLE_MODEL, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_SELECTION_MODEL, - g_param_spec_object ( - "selection_model", - "Selection model", - "Selection model", - E_TYPE_SELECTION_MODEL, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_TABLE_ALTERNATING_ROW_COLORS, - g_param_spec_boolean ( - "alternating_row_colors", - "Alternating Row Colors", - "Alternating Row Colors", - FALSE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_TABLE_HORIZONTAL_DRAW_GRID, - g_param_spec_boolean ( - "horizontal_draw_grid", - "Horizontal Draw Grid", - "Horizontal Draw Grid", - FALSE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_TABLE_VERTICAL_DRAW_GRID, - g_param_spec_boolean ( - "vertical_draw_grid", - "Vertical Draw Grid", - "Vertical Draw Grid", - FALSE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_TABLE_DRAW_FOCUS, - g_param_spec_boolean ( - "drawfocus", - "Draw focus", - "Draw focus", - FALSE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_CURSOR_MODE, - g_param_spec_int ( - "cursor_mode", - "Cursor mode", - "Cursor mode", - E_CURSOR_LINE, - E_CURSOR_SPREADSHEET, - E_CURSOR_LINE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_LENGTH_THRESHOLD, - g_param_spec_int ( - "length_threshold", - "Length Threshold", - "Length Threshold", - -1, G_MAXINT, 0, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_MINIMUM_WIDTH, - g_param_spec_double ( - "minimum_width", - "Minimum width", - "Minimum Width", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_WIDTH, - g_param_spec_double ( - "width", - "Width", - "Width", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_HEIGHT, - g_param_spec_double ( - "height", - "Height", - "Height", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READABLE)); - - g_object_class_install_property ( - object_class, - PROP_CURSOR_ROW, - g_param_spec_int ( - "cursor_row", - "Cursor row", - "Cursor row", - 0, G_MAXINT, 0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_UNIFORM_ROW_HEIGHT, - g_param_spec_boolean ( - "uniform_row_height", - "Uniform row height", - "Uniform row height", - FALSE, - G_PARAM_READWRITE)); - - eti_signals[CURSOR_CHANGE] = g_signal_new ( - "cursor_change", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableItemClass, cursor_change), - NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, - G_TYPE_INT); - - eti_signals[CURSOR_ACTIVATED] = g_signal_new ( - "cursor_activated", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableItemClass, cursor_activated), - NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, - G_TYPE_INT); - - eti_signals[DOUBLE_CLICK] = g_signal_new ( - "double_click", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableItemClass, double_click), - NULL, NULL, - e_marshal_NONE__INT_INT_BOXED, - G_TYPE_NONE, 3, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - eti_signals[START_DRAG] = g_signal_new ( - "start_drag", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableItemClass, start_drag), - g_signal_accumulator_true_handled, NULL, - e_marshal_BOOLEAN__INT_INT_BOXED, - G_TYPE_BOOLEAN, 3, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - eti_signals[RIGHT_CLICK] = g_signal_new ( - "right_click", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableItemClass, right_click), - g_signal_accumulator_true_handled, NULL, - e_marshal_BOOLEAN__INT_INT_BOXED, - G_TYPE_BOOLEAN, 3, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - eti_signals[CLICK] = g_signal_new ( - "click", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableItemClass, click), - g_signal_accumulator_true_handled, NULL, - e_marshal_BOOLEAN__INT_INT_BOXED, - G_TYPE_BOOLEAN, 3, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - eti_signals[KEY_PRESS] = g_signal_new ( - "key_press", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableItemClass, key_press), - g_signal_accumulator_true_handled, NULL, - e_marshal_BOOLEAN__INT_INT_BOXED, - G_TYPE_BOOLEAN, 3, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - eti_signals[STYLE_SET] = g_signal_new ( - "style_set", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableItemClass, style_set), - NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, - GTK_TYPE_STYLE); - - eti_signals[SELECTION_MODEL_REMOVED] = g_signal_new ( - "selection_model_removed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (ETableItemClass, selection_model_removed), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); - - eti_signals[SELECTION_MODEL_ADDED] = g_signal_new ( - "selection_model_added", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (ETableItemClass, selection_model_added), - NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); - - /* A11y Init */ - gal_a11y_e_table_item_init (); -} - -/** - * 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, - gint col, - gint row) -{ - e_table_item_focus (eti, col, view_to_model_row (eti, row), 0); -} - -static void -e_table_item_focus (ETableItem *eti, - gint col, - gint 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_selection_model_do_something ( - E_SELECTION_MODEL (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) -{ - gint cursor_col; - - g_return_val_if_fail (eti != NULL, -1); - g_return_val_if_fail (E_IS_TABLE_ITEM (eti), -1); - - g_object_get ( - eti->selection, - "cursor_col", &cursor_col, - NULL); - - return cursor_col; -} - -static void -eti_cursor_change (ESelectionModel *selection, - gint row, - gint col, - ETableItem *eti) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); - gint view_row; - - if (!(item->flags & GNOME_CANVAS_ITEM_REALIZED)) - return; - - view_row = model_to_view_row (eti, row); - - if (eti->old_cursor_row != -1 && view_row != eti->old_cursor_row) - e_table_item_redraw_row (eti, eti->old_cursor_row); - - if (view_row == -1) { - e_table_item_leave_edit_(eti); - eti->old_cursor_row = -1; - return; - } - - if (!e_table_model_has_change_pending (eti->table_model)) { - if (!eti->in_key_press) { - eti_maybe_show_cursor (eti, DOUBLE_CLICK_TIME + 10); - } else { - eti_maybe_show_cursor (eti, 0); - } - } - - e_canvas_item_grab_focus (GNOME_CANVAS_ITEM (eti), FALSE); - if (eti_editing (eti)) - e_table_item_leave_edit_(eti); - - g_signal_emit (eti, eti_signals[CURSOR_CHANGE], 0, view_row); - - e_table_item_redraw_row (eti, view_row); - - eti->old_cursor_row = view_row; -} - -static void -eti_cursor_activated (ESelectionModel *selection, - gint row, - gint col, - ETableItem *eti) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); - gint view_row; - gint view_col; - - if (!(item->flags & GNOME_CANVAS_ITEM_REALIZED)) - return; - - view_row = model_to_view_row (eti, row); - view_col = model_to_view_col (eti, col); - - if (view_row != -1 && view_col != -1) { - if (!e_table_model_has_change_pending (eti->table_model)) { - if (!eti->in_key_press) { - eti_show_cursor (eti, DOUBLE_CLICK_TIME + 10); - } else { - eti_show_cursor (eti, 0); - } - eti_check_cursor_bounds (eti); - } - } - - if (eti_editing (eti)) - e_table_item_leave_edit_(eti); - - if (view_row != -1) - g_signal_emit ( - eti, eti_signals[CURSOR_ACTIVATED], 0, view_row); -} - -static void -eti_selection_change (ESelectionModel *selection, - ETableItem *eti) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); - - if (!(item->flags & GNOME_CANVAS_ITEM_REALIZED)) - return; - - eti->needs_redraw = TRUE; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); -} - -static void -eti_selection_row_change (ESelectionModel *selection, - gint row, - ETableItem *eti) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); - - if (!(item->flags & GNOME_CANVAS_ITEM_REALIZED)) - return; - - if (!eti->needs_redraw) { - e_table_item_redraw_row (eti, model_to_view_row (eti, row)); - } -} - -/** - * 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, - gint col, - gint row) -{ - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - d (g_print ("%s: %d, %d, eti_editing() = %s\n", __FUNCTION__, col, row, eti_editing (eti)?"true":"false")); - - 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) -{ - gint col, row; - gpointer edit_ctx; - - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - d (g_print ("%s: eti_editing() = %s\n", __FUNCTION__, eti_editing (eti)?"true":"false")); - - 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, - gint *x, - gint *y, - gint *row, - gint *col) -{ - /* Save the grabbed row but make sure that we don't get flawed - * results because the cursor is grabbed. */ - gint grabbed_row = eti->grabbed_row; - eti->grabbed_row = -1; - - if (!find_cell (eti, *x, *y, col, row, NULL, NULL)) { - *y -= eti->height; - } - - eti->grabbed_row = grabbed_row; -} - -/** - * e_table_item_compute_mouse_over: - * Similar to e_table_item_compute_location, only here recalculating - * the position inside the item too. - **/ -void -e_table_item_compute_mouse_over (ETableItem *eti, - gint x, - gint y, - gint *row, - gint *col) -{ - gdouble realx, realy; - /* Save the grabbed row but make sure that we don't get flawed - * results because the cursor is grabbed. */ - gint grabbed_row = eti->grabbed_row; - eti->grabbed_row = -1; - - realx = x; - realy = y; - - gnome_canvas_item_w2i (GNOME_CANVAS_ITEM (eti), &realx, &realy); - - if (!find_cell (eti, (gint) realx, (gint) realy, col, row, NULL, NULL)) { - *row = -1; - *col = -1; - } - - eti->grabbed_row = grabbed_row; -} - -void -e_table_item_get_cell_geometry (ETableItem *eti, - gint *row, - gint *col, - gint *x, - gint *y, - gint *width, - gint *height) -{ - if (eti->rows > *row) { - if (x) - *x = e_table_header_col_diff (eti->header, 0, *col); - if (y) - *y = e_table_item_row_diff (eti, 0, *row); - if (width) - *width = e_table_header_col_diff (eti->header, *col, *col + 1); - if (height) - *height = ETI_ROW_HEIGHT (eti, *row); - *row = -1; - *col = -1; - } else { - *row -= eti->rows; - } -} - -typedef struct { - ETableItem *item; - gint rows_printed; -} ETableItemPrintContext; - -static gdouble * -e_table_item_calculate_print_widths (ETableHeader *eth, - gdouble width) -{ - gint i; - gdouble extra; - gdouble expansion; - gint last_resizable = -1; - gdouble scale = 1.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]->resizable && eth->columns[i]->expansion > 0) - last_resizable = i; - expansion += eth->columns[i]->resizable ? 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]->resizable ? eth->columns[i]->expansion : 0) / expansion; - } - - return widths; -} - -static gdouble -eti_printed_row_height (ETableItem *eti, - gdouble *widths, - GtkPrintContext *context, - gint row) -{ - gint col; - gint 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 (GtkPrintContext *context, - gdouble x, - gdouble y, - gdouble width, - gdouble height) -{ - cairo_t *cr; - cr = gtk_print_context_get_cairo_context (context); - cairo_save (cr); - cairo_rectangle (cr, x, y, width, height); - cairo_set_line_width (cr, 0.5); - cairo_stroke (cr); - cairo_restore (cr); - return 0; -} - -static void -e_table_item_print_page (EPrintable *ep, - GtkPrintContext *context, - gdouble width, - gdouble height, - gboolean quantize, - ETableItemPrintContext *itemcontext) -{ - ETableItem *eti = itemcontext->item; - const gint rows = eti->rows; - const gint cols = eti->cols; - gdouble max_height; - gint rows_printed = itemcontext->rows_printed; - gint row, col, next_page = 0; - gdouble yd = height; - cairo_t *cr; - gdouble *widths; - - cr = gtk_print_context_get_cairo_context (context); - max_height = gtk_print_context_get_height (context); - widths = e_table_item_calculate_print_widths (itemcontext->item->header, width); - - /* - * Draw cells - */ - - if (eti->horizontal_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 > max_height && row != rows_printed) { - next_page = 1; - break; - } - } else { - if (yd > max_height) { - next_page = 1; - break; - } - } - - for (col = 0; col < cols; col++) { - ECellView *ecell_view = eti->cell_views[col]; - - cairo_save (cr); - cairo_translate (cr, xd, yd); - cairo_rectangle (cr, 0, 0, widths[col] - 1, row_height); - cairo_clip (cr); - - e_cell_print ( - ecell_view, context, - view_to_model_col (eti, col), - col, - row, - widths[col] - 1, - row_height + 2); - - cairo_restore (cr); - - xd += widths[col]; - } - - yd += row_height; - if (eti->horizontal_draw_grid) { - gp_draw_rect (context, 0, yd, width, 1); - } - yd++; - } - - itemcontext->rows_printed = row; - if (eti->vertical_draw_grid) { - gdouble xd = 0; - for (col = 0; col < cols; col++) { - gp_draw_rect (context, xd, height, 1, yd - height); - xd += widths[col]; - } - gp_draw_rect (context, xd, height, 1, yd - height); - } - - if (next_page) - cairo_show_page (cr); - - g_free (widths); -} - -static gboolean -e_table_item_data_left (EPrintable *ep, - ETableItemPrintContext *itemcontext) -{ - ETableItem *item = itemcontext->item; - gint rows_printed = itemcontext->rows_printed; - - g_signal_stop_emission_by_name (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, - GtkPrintContext *context, - gdouble width, - gdouble max_height, - gboolean quantize, - ETableItemPrintContext *itemcontext) -{ - ETableItem *item = itemcontext->item; - const gint rows = item->rows; - gint rows_printed = itemcontext->rows_printed; - gdouble *widths; - gint 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; - - g_signal_stop_emission_by_name (ep, "height"); - return yd; -} - -static gboolean -e_table_item_will_fit (EPrintable *ep, - GtkPrintContext *context, - gdouble width, - gdouble max_height, - gboolean quantize, - ETableItemPrintContext *itemcontext) -{ - ETableItem *item = itemcontext->item; - const gint rows = item->rows; - gint rows_printed = itemcontext->rows_printed; - gdouble *widths; - gint 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); - - g_signal_stop_emission_by_name (ep, "will_fit"); - return ret_val; -} - -static void -e_table_item_printable_destroy (gpointer data, - GObject *where_object_was) -{ - ETableItemPrintContext *itemcontext = data; - - g_object_unref (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; - g_object_ref (item); - itemcontext->rows_printed = 0; - - g_signal_connect ( - printable, "print_page", - G_CALLBACK (e_table_item_print_page), itemcontext); - g_signal_connect ( - printable, "data_left", - G_CALLBACK (e_table_item_data_left), itemcontext); - g_signal_connect ( - printable, "reset", - G_CALLBACK (e_table_item_reset), itemcontext); - g_signal_connect ( - printable, "height", - G_CALLBACK (e_table_item_height), itemcontext); - g_signal_connect ( - printable, "will_fit", - G_CALLBACK (e_table_item_will_fit), itemcontext); - - g_object_weak_ref ( - G_OBJECT (printable), - 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 26a181dd64..0000000000 --- a/widgets/table/e-table-item.h +++ /dev/null @@ -1,256 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Miguel de Icaza <miguel@gnu.org> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_ITEM_H_ -#define _E_TABLE_ITEM_H_ - -#include <libgnomecanvas/libgnomecanvas.h> -#include <table/e-table-model.h> -#include <table/e-table-header.h> -#include <table/e-table-defines.h> -#include <misc/e-selection-model.h> -#include <misc/e-printable.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_ITEM \ - (e_table_item_get_type ()) -#define E_TABLE_ITEM(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_ITEM, ETableItem)) -#define E_TABLE_ITEM_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_ITEM, ETableItemClass)) -#define E_IS_TABLE_ITEM(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_ITEM)) -#define E_IS_TABLE_ITEM_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_ITEM)) -#define E_TABLE_ITEM_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_ITEM, ETableItemClass)) - -G_BEGIN_DECLS - -typedef struct _ETableItem ETableItem; -typedef struct _ETableItemClass ETableItemClass; - -struct _ETableItem { - GnomeCanvasItem parent; - ETableModel *table_model; - ETableHeader *header; - - ETableModel *source_model; - ESelectionModel *selection; - - gint minimum_width, width, height; - - gint cols, rows; - - gint click_count; - - /* - * Ids for the signals we connect to - */ - gint header_dim_change_id; - gint header_structure_change_id; - gint header_request_width_id; - gint table_model_pre_change_id; - gint table_model_no_change_id; - gint table_model_change_id; - gint table_model_row_change_id; - gint table_model_cell_change_id; - gint table_model_rows_inserted_id; - gint table_model_rows_deleted_id; - - gint selection_change_id; - gint selection_row_change_id; - gint cursor_change_id; - gint cursor_activated_id; - - guint cursor_idle_id; - - /* View row, -1 means unknown */ - gint old_cursor_row; - - guint alternating_row_colors : 1; - guint horizontal_draw_grid : 1; - guint vertical_draw_grid : 1; - guint draw_focus : 1; - guint uniform_row_height : 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; - - guint maybe_in_drag : 1; - guint in_drag : 1; - guint grabbed : 1; - - guint maybe_did_something : 1; - - guint cursor_on_screen : 1; - guint gtk_grabbed : 1; - - guint queue_show_cursor : 1; - guint grab_cancelled : 1; - - gint frozen_count; - - gint cursor_x1; - gint cursor_y1; - gint cursor_x2; - gint cursor_y2; - - gint drag_col; - gint drag_row; - gint drag_x; - gint drag_y; - guint drag_state; - - /* - * Realized views, per column - */ - ECellView **cell_views; - gint n_cells; - - gint *height_cache; - gint uniform_row_height_cache; - gint height_cache_idle_id; - gint height_cache_idle_count; - - /* - * Lengh Threshold: above this, we stop computing correctly - * the size - */ - gint length_threshold; - - gint row_guess; - ECursorMode cursor_mode; - - gint motion_col, motion_row; - - /* - * During editing - */ - gint editing_col, editing_row; - void *edit_ctx; - - gint save_col, save_row; - void *save_state; - - gint grabbed_col, grabbed_row; - gint grabbed_count; -}; - -struct _ETableItemClass { - GnomeCanvasItemClass parent_class; - - void (*cursor_change) (ETableItem *eti, - gint row); - void (*cursor_activated) (ETableItem *eti, - gint row); - void (*double_click) (ETableItem *eti, - gint row, - gint col, - GdkEvent *event); - gboolean (*right_click) (ETableItem *eti, - gint row, - gint col, - GdkEvent *event); - gboolean (*click) (ETableItem *eti, - gint row, - gint col, - GdkEvent *event); - gboolean (*key_press) (ETableItem *eti, - gint row, - gint col, - GdkEvent *event); - gboolean (*start_drag) (ETableItem *eti, - gint row, - gint col, - GdkEvent *event); - void (*style_set) (ETableItem *eti, - GtkStyle *previous_style); - void (*selection_model_removed) - (ETableItem *eti, - ESelectionModel *selection); - void (*selection_model_added) - (ETableItem *eti, - ESelectionModel *selection); -}; - -GType e_table_item_get_type (void) G_GNUC_CONST; - -/* - * Focus - */ -void e_table_item_set_cursor (ETableItem *eti, - gint col, - gint 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, - gint col, - gint row); - -void e_table_item_redraw_range (ETableItem *eti, - gint start_col, - gint start_row, - gint end_col, - gint end_row); - -EPrintable * e_table_item_get_printable (ETableItem *eti); -void e_table_item_compute_location (ETableItem *eti, - gint *x, - gint *y, - gint *row, - gint *col); -void e_table_item_compute_mouse_over (ETableItem *eti, - gint x, - gint y, - gint *row, - gint *col); -void e_table_item_get_cell_geometry (ETableItem *eti, - gint *row, - gint *col, - gint *x, - gint *y, - gint *width, - gint *height); - -gint e_table_item_row_diff (ETableItem *eti, - gint start_row, - gint end_row); - -G_END_DECLS - -#endif /* _E_TABLE_ITEM_H_ */ diff --git a/widgets/table/e-table-memory-callbacks.c b/widgets/table/e-table-memory-callbacks.c deleted file mode 100644 index 279d0a505e..0000000000 --- a/widgets/table/e-table-memory-callbacks.c +++ /dev/null @@ -1,236 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "e-util/e-util.h" - -#include "e-table-memory-callbacks.h" - -G_DEFINE_TYPE (ETableMemoryCallbacks, e_table_memory_callbacks, E_TYPE_TABLE_MEMORY) - -static gint -etmc_column_count (ETableModel *etm) -{ - ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm); - - if (etmc->col_count) - return etmc->col_count (etm, etmc->data); - else - return 0; -} - -static gpointer -etmc_value_at (ETableModel *etm, - gint col, - gint row) -{ - ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm); - - if (etmc->value_at) - return etmc->value_at (etm, col, row, etmc->data); - else - return NULL; -} - -static void -etmc_set_value_at (ETableModel *etm, - gint col, - gint row, - gconstpointer val) -{ - ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm); - - if (etmc->set_value_at) - etmc->set_value_at (etm, col, row, val, etmc->data); -} - -static gboolean -etmc_is_cell_editable (ETableModel *etm, - gint col, - gint row) -{ - ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm); - - if (etmc->is_cell_editable) - return etmc->is_cell_editable (etm, col, row, etmc->data); - else - return FALSE; -} - -/* The default for etmc_duplicate_value is to return the raw value. */ -static gpointer -etmc_duplicate_value (ETableModel *etm, - gint col, - gconstpointer value) -{ - ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm); - - if (etmc->duplicate_value) - return etmc->duplicate_value (etm, col, value, etmc->data); - else - return (gpointer) value; -} - -static void -etmc_free_value (ETableModel *etm, - gint col, - gpointer value) -{ - ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm); - - if (etmc->free_value) - etmc->free_value (etm, col, value, etmc->data); -} - -static gpointer -etmc_initialize_value (ETableModel *etm, - gint col) -{ - ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm); - - if (etmc->initialize_value) - return etmc->initialize_value (etm, col, etmc->data); - else - return NULL; -} - -static gboolean -etmc_value_is_empty (ETableModel *etm, - gint col, - gconstpointer value) -{ - ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm); - - if (etmc->value_is_empty) - return etmc->value_is_empty (etm, col, value, etmc->data); - else - return FALSE; -} - -static gchar * -etmc_value_to_string (ETableModel *etm, - gint col, - gconstpointer value) -{ - ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm); - - if (etmc->value_to_string) - return etmc->value_to_string (etm, col, value, etmc->data); - else - return g_strdup (""); -} - -static void -etmc_append_row (ETableModel *etm, - ETableModel *source, - gint row) -{ - ETableMemoryCallbacks *etmc = E_TABLE_MEMORY_CALLBACKS (etm); - - if (etmc->append_row) - etmc->append_row (etm, source, row, etmc->data); -} - -static void -e_table_memory_callbacks_class_init (ETableMemoryCallbacksClass *class) -{ - ETableModelClass *model_class = E_TABLE_MODEL_CLASS (class); - - model_class->column_count = etmc_column_count; - model_class->value_at = etmc_value_at; - model_class->set_value_at = etmc_set_value_at; - model_class->is_cell_editable = etmc_is_cell_editable; - model_class->duplicate_value = etmc_duplicate_value; - model_class->free_value = etmc_free_value; - model_class->initialize_value = etmc_initialize_value; - model_class->value_is_empty = etmc_value_is_empty; - model_class->value_to_string = etmc_value_to_string; - model_class->append_row = etmc_append_row; - -} - -static void -e_table_memory_callbacks_init (ETableMemoryCallbacks *etmc) -{ - /* nothing to do */ -} - -/** - * e_table_memory_callbacks_new: - * @col_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 ETableMemoryCallbacksModel object. - * ETableMemoryCallbacksModel is an implementaiton of the abstract class - * ETableModel. The ETableMemoryCallbacksModel is designed to allow people - * to easily create ETableModels without having to create a new GType - * derived from ETableModel every time they need one. - * - * Instead, ETableMemoryCallbacksModel 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 ETableMemoryCallbacksModel object (which is also an ETableModel - * object). - */ -ETableModel * -e_table_memory_callbacks_new (ETableMemoryCallbacksColumnCountFn col_count, - ETableMemoryCallbacksValueAtFn value_at, - ETableMemoryCallbacksSetValueAtFn set_value_at, - ETableMemoryCallbacksIsCellEditableFn is_cell_editable, - ETableMemoryCallbacksDuplicateValueFn duplicate_value, - ETableMemoryCallbacksFreeValueFn free_value, - ETableMemoryCallbacksInitializeValueFn initialize_value, - ETableMemoryCallbacksValueIsEmptyFn value_is_empty, - ETableMemoryCallbacksValueToStringFn value_to_string, - gpointer data) -{ - ETableMemoryCallbacks *et; - - et = g_object_new (E_TYPE_TABLE_MEMORY_CALLBACKS, NULL); - - et->col_count = col_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-memory-callbacks.h b/widgets/table/e-table-memory-callbacks.h deleted file mode 100644 index 8feb6e9884..0000000000 --- a/widgets/table/e-table-memory-callbacks.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_MEMORY_CALLBACKS_H_ -#define _E_TABLE_MEMORY_CALLBACKS_H_ - -#include <table/e-table-memory.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_MEMORY_CALLBACKS \ - (e_table_memory_callbacks_get_type ()) -#define E_TABLE_MEMORY_CALLBACKS(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_MEMORY_CALLBACKS, ETableMemoryCallbacks)) -#define E_TABLE_MEMORY_CALLBACKS_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_MEMORY_CALLBACKS, ETableMemoryCallbacksClass)) -#define E_IS_TABLE_MEMORY_CALLBACKS(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_MEMORY_CALLBACKS)) -#define E_IS_TABLE_MEMORY_CALLBACKS_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_MEMORY_CALLBACKS)) -#define E_TABLE_MEMORY_CALLBACKS_GET_CLASS(cls) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((cls), E_TYPE_TABLE_MEMORY_CALLBACKS, ETableMemoryCallbacksClass)) - -G_BEGIN_DECLS - -typedef struct _ETableMemoryCallbacks ETableMemoryCallbacks; -typedef struct _ETableMemoryCallbacksClass ETableMemoryCallbacksClass; - -typedef gint (*ETableMemoryCallbacksColumnCountFn) - (ETableModel *etm, - gpointer data); -typedef void (*ETableMemoryCallbacksAppendRowFn) - (ETableModel *etm, - ETableModel *model, - gint row, - gpointer data); - -typedef gpointer (*ETableMemoryCallbacksValueAtFn) - (ETableModel *etm, - gint col, - gint row, - gpointer data); -typedef void (*ETableMemoryCallbacksSetValueAtFn) - (ETableModel *etm, - gint col, - gint row, - gconstpointer val, - gpointer data); -typedef gboolean (*ETableMemoryCallbacksIsCellEditableFn) - (ETableModel *etm, - gint col, - gint row, - gpointer data); - -typedef gpointer (*ETableMemoryCallbacksDuplicateValueFn) - (ETableModel *etm, - gint col, - gconstpointer val, - gpointer data); -typedef void (*ETableMemoryCallbacksFreeValueFn) - (ETableModel *etm, - gint col, - gpointer val, - gpointer data); -typedef gpointer (*ETableMemoryCallbacksInitializeValueFn) - (ETableModel *etm, - gint col, - gpointer data); -typedef gboolean (*ETableMemoryCallbacksValueIsEmptyFn) - (ETableModel *etm, - gint col, - gconstpointer val, - gpointer data); -typedef gchar * (*ETableMemoryCallbacksValueToStringFn) - (ETableModel *etm, - gint col, - gconstpointer val, - gpointer data); - -struct _ETableMemoryCallbacks { - ETableMemory parent; - - ETableMemoryCallbacksColumnCountFn col_count; - ETableMemoryCallbacksAppendRowFn append_row; - - ETableMemoryCallbacksValueAtFn value_at; - ETableMemoryCallbacksSetValueAtFn set_value_at; - ETableMemoryCallbacksIsCellEditableFn is_cell_editable; - - ETableMemoryCallbacksDuplicateValueFn duplicate_value; - ETableMemoryCallbacksFreeValueFn free_value; - ETableMemoryCallbacksInitializeValueFn initialize_value; - ETableMemoryCallbacksValueIsEmptyFn value_is_empty; - ETableMemoryCallbacksValueToStringFn value_to_string; - gpointer data; -}; - -struct _ETableMemoryCallbacksClass { - ETableMemoryClass parent_class; -}; - -GType e_table_memory_callbacks_get_type - (void) G_GNUC_CONST; -ETableModel * e_table_memory_callbacks_new - (ETableMemoryCallbacksColumnCountFn col_count, - - ETableMemoryCallbacksValueAtFn value_at, - ETableMemoryCallbacksSetValueAtFn set_value_at, - ETableMemoryCallbacksIsCellEditableFn is_cell_editable, - - ETableMemoryCallbacksDuplicateValueFn duplicate_value, - ETableMemoryCallbacksFreeValueFn free_value, - ETableMemoryCallbacksInitializeValueFn initialize_value, - ETableMemoryCallbacksValueIsEmptyFn value_is_empty, - ETableMemoryCallbacksValueToStringFn value_to_string, - gpointer data); - -G_END_DECLS - -#endif /* _E_TABLE_MEMORY_CALLBACKS_H_ */ - diff --git a/widgets/table/e-table-memory-store.c b/widgets/table/e-table-memory-store.c deleted file mode 100644 index 950b58e31e..0000000000 --- a/widgets/table/e-table-memory-store.c +++ /dev/null @@ -1,639 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include "e-util/e-util.h" - -#include "e-table-memory-store.h" - -#define E_TABLE_MEMORY_STORE_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), E_TYPE_TABLE_MEMORY_STORE, ETableMemoryStorePrivate)) - -#define STORE_LOCATOR(etms, col, row) (*((etms)->priv->store + (row) * (etms)->priv->col_count + (col))) - -struct _ETableMemoryStorePrivate { - gint col_count; - ETableMemoryStoreColumnInfo *columns; - gpointer *store; -}; - -G_DEFINE_TYPE (ETableMemoryStore, e_table_memory_store, E_TYPE_TABLE_MEMORY) - -static gpointer -duplicate_value (ETableMemoryStore *etms, - gint col, - gconstpointer val) -{ - switch (etms->priv->columns[col].type) { - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_STRING: - return g_strdup (val); - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_PIXBUF: - if (val) - g_object_ref ((gpointer) val); - return (gpointer) val; - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_OBJECT: - if (val) - g_object_ref ((gpointer) val); - return (gpointer) val; - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_CUSTOM: - if (etms->priv->columns[col].custom.duplicate_value) - return etms->priv->columns[col].custom.duplicate_value (E_TABLE_MODEL (etms), col, val, NULL); - break; - default: - break; - } - return (gpointer) val; -} - -static void -free_value (ETableMemoryStore *etms, - gint col, - gpointer value) -{ - switch (etms->priv->columns[col].type) { - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_STRING: - g_free (value); - break; - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_PIXBUF: - if (value) - g_object_unref (value); - break; - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_OBJECT: - if (value) - g_object_unref (value); - break; - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_CUSTOM: - if (etms->priv->columns[col].custom.free_value) - etms->priv->columns[col].custom.free_value (E_TABLE_MODEL (etms), col, value, NULL); - break; - default: - break; - } -} - -static gint -etms_column_count (ETableModel *etm) -{ - ETableMemoryStore *etms = E_TABLE_MEMORY_STORE (etm); - - return etms->priv->col_count; -} - -static gpointer -etms_value_at (ETableModel *etm, - gint col, - gint row) -{ - ETableMemoryStore *etms = E_TABLE_MEMORY_STORE (etm); - - return STORE_LOCATOR (etms, col, row); -} - -static void -etms_set_value_at (ETableModel *etm, - gint col, - gint row, - gconstpointer val) -{ - ETableMemoryStore *etms = E_TABLE_MEMORY_STORE (etm); - - e_table_model_pre_change (etm); - - STORE_LOCATOR (etms, col, row) = duplicate_value (etms, col, val); - - e_table_model_cell_changed (etm, col, row); -} - -static gboolean -etms_is_cell_editable (ETableModel *etm, - gint col, - gint row) -{ - ETableMemoryStore *etms = E_TABLE_MEMORY_STORE (etm); - - return etms->priv->columns[col].editable; -} - -/* The default for etms_duplicate_value is to return the raw value. */ -static gpointer -etms_duplicate_value (ETableModel *etm, - gint col, - gconstpointer value) -{ - ETableMemoryStore *etms = E_TABLE_MEMORY_STORE (etm); - - return duplicate_value (etms, col, value); -} - -static void -etms_free_value (ETableModel *etm, - gint col, - gpointer value) -{ - ETableMemoryStore *etms = E_TABLE_MEMORY_STORE (etm); - - free_value (etms, col, value); -} - -static gpointer -etms_initialize_value (ETableModel *etm, - gint col) -{ - ETableMemoryStore *etms = E_TABLE_MEMORY_STORE (etm); - - switch (etms->priv->columns[col].type) { - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_STRING: - return g_strdup (""); - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_PIXBUF: - return NULL; - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_CUSTOM: - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_OBJECT: - if (etms->priv->columns[col].custom.initialize_value) - return etms->priv->columns[col].custom.initialize_value (E_TABLE_MODEL (etms), col, NULL); - break; - default: - break; - } - return NULL; -} - -static gboolean -etms_value_is_empty (ETableModel *etm, - gint col, - gconstpointer value) -{ - ETableMemoryStore *etms = E_TABLE_MEMORY_STORE (etm); - - switch (etms->priv->columns[col].type) { - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_STRING: - return !(value && *(gchar *) value); - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_PIXBUF: - return value == NULL; - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_CUSTOM: - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_OBJECT: - if (etms->priv->columns[col].custom.value_is_empty) - return etms->priv->columns[col].custom.value_is_empty (E_TABLE_MODEL (etms), col, value, NULL); - break; - default: - break; - } - return value == NULL; -} - -static gchar * -etms_value_to_string (ETableModel *etm, - gint col, - gconstpointer value) -{ - ETableMemoryStore *etms = E_TABLE_MEMORY_STORE (etm); - - switch (etms->priv->columns[col].type) { - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_STRING: - return g_strdup (value); - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_PIXBUF: - return g_strdup (""); - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_CUSTOM: - case E_TABLE_MEMORY_STORE_COLUMN_TYPE_OBJECT: - if (etms->priv->columns[col].custom.value_is_empty) - return etms->priv->columns[col].custom.value_to_string (E_TABLE_MODEL (etms), col, value, NULL); - break; - default: - break; - } - return g_strdup_printf ("%d", GPOINTER_TO_INT (value)); -} - -static void -etms_append_row (ETableModel *etm, - ETableModel *source, - gint row) -{ - ETableMemoryStore *etms = E_TABLE_MEMORY_STORE (etm); - gpointer *new_data; - gint i; - gint row_count; - - new_data = g_new (gpointer , etms->priv->col_count); - - for (i = 0; i < etms->priv->col_count; i++) { - new_data[i] = e_table_model_value_at (source, i, row); - } - - row_count = e_table_model_row_count (E_TABLE_MODEL (etms)); - - e_table_memory_store_insert_array (etms, row_count, new_data, NULL); -} - -static void -etms_finalize (GObject *object) -{ - ETableMemoryStorePrivate *priv; - - priv = E_TABLE_MEMORY_STORE_GET_PRIVATE (object); - - e_table_memory_store_clear (E_TABLE_MEMORY_STORE (object)); - - g_free (priv->columns); - g_free (priv->store); - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (e_table_memory_store_parent_class)->finalize (object); -} - -static void -e_table_memory_store_init (ETableMemoryStore *etms) -{ - etms->priv = E_TABLE_MEMORY_STORE_GET_PRIVATE (etms); -} - -static void -e_table_memory_store_class_init (ETableMemoryStoreClass *class) -{ - GObjectClass *object_class; - ETableModelClass *model_class; - - g_type_class_add_private (class, sizeof (ETableMemoryStorePrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->finalize = etms_finalize; - - model_class = E_TABLE_MODEL_CLASS (class); - model_class->column_count = etms_column_count; - model_class->value_at = etms_value_at; - model_class->set_value_at = etms_set_value_at; - model_class->is_cell_editable = etms_is_cell_editable; - model_class->duplicate_value = etms_duplicate_value; - model_class->free_value = etms_free_value; - model_class->initialize_value = etms_initialize_value; - model_class->value_is_empty = etms_value_is_empty; - model_class->value_to_string = etms_value_to_string; - model_class->append_row = etms_append_row; -} - -/** - * e_table_memory_store_new: - * @col_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 ETableMemoryStoreModel object. ETableMemoryStoreModel is - * an implementaiton of the abstract class ETableModel. The ETableMemoryStoreModel - * is designed to allow people to easily create ETableModels without having - * to create a new GType derived from ETableModel every time they need one. - * - * Instead, ETableMemoryStoreModel 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 ETableMemoryStoreModel object (which is also an ETableModel - * object). - */ -ETableModel * -e_table_memory_store_new (ETableMemoryStoreColumnInfo *columns) -{ - ETableMemoryStore *et = g_object_new (E_TYPE_TABLE_MEMORY_STORE, NULL); - - if (e_table_memory_store_construct (et, columns)) { - return (ETableModel *) et; - } else { - g_object_unref (et); - return NULL; - } -} - -ETableModel * -e_table_memory_store_construct (ETableMemoryStore *etms, - ETableMemoryStoreColumnInfo *columns) -{ - gint i; - for (i = 0; columns[i].type != E_TABLE_MEMORY_STORE_COLUMN_TYPE_TERMINATOR; i++) - /* Intentionally blank */; - etms->priv->col_count = i; - - etms->priv->columns = g_new (ETableMemoryStoreColumnInfo, etms->priv->col_count + 1); - - memcpy (etms->priv->columns, columns, (etms->priv->col_count + 1) * sizeof (ETableMemoryStoreColumnInfo)); - - return E_TABLE_MODEL (etms); -} - -void -e_table_memory_store_adopt_value_at (ETableMemoryStore *etms, - gint col, - gint row, - gpointer value) -{ - e_table_model_pre_change (E_TABLE_MODEL (etms)); - - STORE_LOCATOR (etms, col, row) = value; - - e_table_model_cell_changed (E_TABLE_MODEL (etms), col, row); -} - -/* The size of these arrays is the number of columns. */ -void -e_table_memory_store_insert_array (ETableMemoryStore *etms, - gint row, - gpointer *store, - gpointer data) -{ - gint row_count; - gint i; - - row_count = e_table_model_row_count (E_TABLE_MODEL (etms)) + 1; - if (row == -1) - row = row_count - 1; - etms->priv->store = g_realloc (etms->priv->store, etms->priv->col_count * row_count * sizeof (gpointer)); - memmove ( - etms->priv->store + etms->priv->col_count * (row + 1), - etms->priv->store + etms->priv->col_count * row, - etms->priv->col_count * (row_count - row - 1) * sizeof (gpointer)); - - for (i = 0; i < etms->priv->col_count; i++) { - STORE_LOCATOR (etms, i, row) = duplicate_value (etms, i, store[i]); - } - - e_table_memory_insert (E_TABLE_MEMORY (etms), row, data); -} - -void -e_table_memory_store_insert (ETableMemoryStore *etms, - gint row, - gpointer data, - ...) -{ - gpointer *store; - va_list args; - gint i; - - store = g_new (gpointer , etms->priv->col_count + 1); - - va_start (args, data); - for (i = 0; i < etms->priv->col_count; i++) { - store[i] = va_arg (args, gpointer); - } - va_end (args); - - e_table_memory_store_insert_array (etms, row, store, data); - - g_free (store); -} - -void -e_table_memory_store_insert_adopt_array (ETableMemoryStore *etms, - gint row, - gpointer *store, - gpointer data) -{ - gint row_count; - gint i; - - row_count = e_table_model_row_count (E_TABLE_MODEL (etms)) + 1; - if (row == -1) - row = row_count - 1; - etms->priv->store = g_realloc (etms->priv->store, etms->priv->col_count * row_count * sizeof (gpointer)); - memmove ( - etms->priv->store + etms->priv->col_count * (row + 1), - etms->priv->store + etms->priv->col_count * row, - etms->priv->col_count * (row_count - row - 1) * sizeof (gpointer)); - - for (i = 0; i < etms->priv->col_count; i++) { - STORE_LOCATOR (etms, i, row) = store[i]; - } - - e_table_memory_insert (E_TABLE_MEMORY (etms), row, data); -} - -void -e_table_memory_store_insert_adopt (ETableMemoryStore *etms, - gint row, - gpointer data, - ...) -{ - gpointer *store; - va_list args; - gint i; - - store = g_new (gpointer , etms->priv->col_count + 1); - - va_start (args, data); - for (i = 0; i < etms->priv->col_count; i++) { - store[i] = va_arg (args, gpointer); - } - va_end (args); - - e_table_memory_store_insert_adopt_array (etms, row, store, data); - - g_free (store); -} - -/** - * e_table_memory_store_change_array: - * @etms: the ETabelMemoryStore. - * @row: the row we're changing. - * @store: an array of new values to fill the row - * @data: the new closure to associate with this row. - * - * frees existing values associated with a row and replaces them with - * duplicates of the values in store. - * - */ -void -e_table_memory_store_change_array (ETableMemoryStore *etms, - gint row, - gpointer *store, - gpointer data) -{ - gint i; - - g_return_if_fail (row >= 0 && row < e_table_model_row_count (E_TABLE_MODEL (etms))); - - e_table_model_pre_change (E_TABLE_MODEL (etms)); - - for (i = 0; i < etms->priv->col_count; i++) { - free_value (etms, i, STORE_LOCATOR (etms, i, row)); - STORE_LOCATOR (etms, i, row) = duplicate_value (etms, i, store[i]); - } - - e_table_memory_set_data (E_TABLE_MEMORY (etms), row, data); - e_table_model_row_changed (E_TABLE_MODEL (etms), row); -} - -/** - * e_table_memory_store_change: - * @etms: the ETabelMemoryStore. - * @row: the row we're changing. - * @data: the new closure to associate with this row. - * - * a varargs version of e_table_memory_store_change_array. you must - * pass in etms->col_count args. - */ -void -e_table_memory_store_change (ETableMemoryStore *etms, - gint row, - gpointer data, - ...) -{ - gpointer *store; - va_list args; - gint i; - - g_return_if_fail (row >= 0 && row < e_table_model_row_count (E_TABLE_MODEL (etms))); - - store = g_new0 (gpointer , etms->priv->col_count + 1); - - va_start (args, data); - for (i = 0; i < etms->priv->col_count; i++) { - store[i] = va_arg (args, gpointer); - } - va_end (args); - - e_table_memory_store_change_array (etms, row, store, data); - - g_free (store); -} - -/** - * e_table_memory_store_change_adopt_array: - * @etms: the ETableMemoryStore - * @row: the row we're changing. - * @store: an array of new values to fill the row - * @data: the new closure to associate with this row. - * - * frees existing values for the row and stores the values from store - * into it. This function differs from - * e_table_memory_storage_change_adopt_array in that it does not - * duplicate the data. - */ -void -e_table_memory_store_change_adopt_array (ETableMemoryStore *etms, - gint row, - gpointer *store, - gpointer data) -{ - gint i; - - g_return_if_fail (row >= 0 && row < e_table_model_row_count (E_TABLE_MODEL (etms))); - - for (i = 0; i < etms->priv->col_count; i++) { - free_value (etms, i, STORE_LOCATOR (etms, i, row)); - STORE_LOCATOR (etms, i, row) = store[i]; - } - - e_table_memory_set_data (E_TABLE_MEMORY (etms), row, data); - e_table_model_row_changed (E_TABLE_MODEL (etms), row); -} - -/** - * e_table_memory_store_change_adopt - * @etms: the ETabelMemoryStore. - * @row: the row we're changing. - * @data: the new closure to associate with this row. - * - * a varargs version of e_table_memory_store_change_adopt_array. you - * must pass in etms->col_count args. - */ -void -e_table_memory_store_change_adopt (ETableMemoryStore *etms, - gint row, - gpointer data, - ...) -{ - gpointer *store; - va_list args; - gint i; - - g_return_if_fail (row >= 0 && row < e_table_model_row_count (E_TABLE_MODEL (etms))); - - store = g_new0 (gpointer , etms->priv->col_count + 1); - - va_start (args, data); - for (i = 0; i < etms->priv->col_count; i++) { - store[i] = va_arg (args, gpointer); - } - va_end (args); - - e_table_memory_store_change_adopt_array (etms, row, store, data); - - g_free (store); -} - -void -e_table_memory_store_remove (ETableMemoryStore *etms, - gint row) -{ - ETableModel *model; - gint column_count, row_count; - gint i; - - model = E_TABLE_MODEL (etms); - column_count = e_table_model_column_count (model); - - for (i = 0; i < column_count; i++) - e_table_model_free_value (model, i, e_table_model_value_at (model, i, row)); - - row_count = e_table_model_row_count (E_TABLE_MODEL (etms)) - 1; - memmove ( - etms->priv->store + etms->priv->col_count * row, - etms->priv->store + etms->priv->col_count * (row + 1), - etms->priv->col_count * (row_count - row) * sizeof (gpointer)); - etms->priv->store = g_realloc (etms->priv->store, etms->priv->col_count * row_count * sizeof (gpointer)); - - e_table_memory_remove (E_TABLE_MEMORY (etms), row); -} - -void -e_table_memory_store_clear (ETableMemoryStore *etms) -{ - ETableModel *model; - gint row_count, column_count; - gint i, j; - - model = E_TABLE_MODEL (etms); - row_count = e_table_model_row_count (model); - column_count = e_table_model_column_count (model); - - for (i = 0; i < row_count; i++) { - for (j = 0; j < column_count; j++) { - e_table_model_free_value (model, j, e_table_model_value_at (model, j, i)); - } - } - - e_table_memory_clear (E_TABLE_MEMORY (etms)); - - g_free (etms->priv->store); - etms->priv->store = NULL; -} diff --git a/widgets/table/e-table-memory-store.h b/widgets/table/e-table-memory-store.h deleted file mode 100644 index 9d3d638e18..0000000000 --- a/widgets/table/e-table-memory-store.h +++ /dev/null @@ -1,151 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_MEMORY_STORE_H_ -#define _E_TABLE_MEMORY_STORE_H_ - -#include <table/e-table-memory.h> -#include <table/e-table-memory-callbacks.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_MEMORY_STORE \ - (e_table_memory_store_get_type ()) -#define E_TABLE_MEMORY_STORE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_MEMORY_STORE, ETableMemoryStore)) -#define E_TABLE_MEMORY_STORE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_MEMORY_STORE, ETableMemoryStoreClass)) -#define E_IS_TABLE_MEMORY_STORE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_MEMORY_STORE)) -#define E_IS_TABLE_MEMORY_STORE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_MEMORY_STORE)) -#define E_TABLE_MEMORY_STORE_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_MEMORY_STORE, ETableMemoryStoreClass)) - -G_BEGIN_DECLS - -typedef enum { - E_TABLE_MEMORY_STORE_COLUMN_TYPE_TERMINATOR, - E_TABLE_MEMORY_STORE_COLUMN_TYPE_INTEGER, - E_TABLE_MEMORY_STORE_COLUMN_TYPE_STRING, - E_TABLE_MEMORY_STORE_COLUMN_TYPE_PIXBUF, - E_TABLE_MEMORY_STORE_COLUMN_TYPE_OBJECT, - E_TABLE_MEMORY_STORE_COLUMN_TYPE_CUSTOM -} ETableMemoryStoreColumnType; - -typedef struct { - ETableMemoryCallbacksDuplicateValueFn duplicate_value; - ETableMemoryCallbacksFreeValueFn free_value; - ETableMemoryCallbacksInitializeValueFn initialize_value; - ETableMemoryCallbacksValueIsEmptyFn value_is_empty; - ETableMemoryCallbacksValueToStringFn value_to_string; -} ETableMemoryStoreCustomColumn; - -typedef struct { - ETableMemoryStoreColumnType type; - ETableMemoryStoreCustomColumn custom; - guint editable : 1; -} ETableMemoryStoreColumnInfo; - -#define E_TABLE_MEMORY_STORE_TERMINATOR \ - { E_TABLE_MEMORY_STORE_COLUMN_TYPE_TERMINATOR, { NULL }, FALSE } -#define E_TABLE_MEMORY_STORE_INTEGER \ - { E_TABLE_MEMORY_STORE_COLUMN_TYPE_INTEGER, { NULL }, FALSE } -#define E_TABLE_MEMORY_STORE_STRING \ - { E_TABLE_MEMORY_STORE_COLUMN_TYPE_STRING, { NULL }, FALSE } - -typedef struct _ETableMemoryStore ETableMemoryStore; -typedef struct _ETableMemoryStoreClass ETableMemoryStoreClass; -typedef struct _ETableMemoryStorePrivate ETableMemoryStorePrivate; - -struct _ETableMemoryStore { - ETableMemory parent; - ETableMemoryStorePrivate *priv; -}; - -struct _ETableMemoryStoreClass { - ETableMemoryClass parent_class; -}; - -GType e_table_memory_store_get_type (void) G_GNUC_CONST; -ETableModel * e_table_memory_store_new (ETableMemoryStoreColumnInfo *columns); -ETableModel * e_table_memory_store_construct (ETableMemoryStore *store, - ETableMemoryStoreColumnInfo *columns); - -/* Adopt a value instead of copying it. */ -void e_table_memory_store_adopt_value_at - (ETableMemoryStore *etms, - gint col, - gint row, - gpointer value); - -/* The size of these arrays is the number of columns. */ -void e_table_memory_store_insert_array - (ETableMemoryStore *etms, - gint row, - gpointer *store, - gpointer data); -void e_table_memory_store_insert (ETableMemoryStore *etms, - gint row, - gpointer data, - ...); -void e_table_memory_store_insert_adopt - (ETableMemoryStore *etms, - gint row, - gpointer data, - ...); -void e_table_memory_store_insert_adopt_array - (ETableMemoryStore *etms, - gint row, - gpointer *store, - gpointer data); -void e_table_memory_store_change_array - (ETableMemoryStore *etms, - gint row, - gpointer *store, - gpointer data); -void e_table_memory_store_change (ETableMemoryStore *etms, - gint row, - gpointer data, - ...); -void e_table_memory_store_change_adopt - (ETableMemoryStore *etms, - gint row, - gpointer data, - ...); -void e_table_memory_store_change_adopt_array - (ETableMemoryStore *etms, - gint row, - gpointer *store, - gpointer data); -void e_table_memory_store_remove (ETableMemoryStore *etms, - gint row); -void e_table_memory_store_clear (ETableMemoryStore *etms); - -G_END_DECLS - -#endif /* _E_TABLE_MEMORY_STORE_H_ */ diff --git a/widgets/table/e-table-memory.c b/widgets/table/e-table-memory.c deleted file mode 100644 index 58c1f8415a..0000000000 --- a/widgets/table/e-table-memory.c +++ /dev/null @@ -1,273 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <errno.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <string.h> - -#include <libxml/parser.h> -#include <libxml/xmlmemory.h> - -#include "e-util/e-util.h" -#include "libevolution-utils/e-xml-utils.h" - -#include "e-table-memory.h" - -#define E_TABLE_MEMORY_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), E_TYPE_TABLE_MEMORY, ETableMemoryPrivate)) - -G_DEFINE_TYPE (ETableMemory, e_table_memory, E_TYPE_TABLE_MODEL) - -struct _ETableMemoryPrivate { - gpointer *data; - gint num_rows; - gint frozen; -}; - -static void -etmm_finalize (GObject *object) -{ - ETableMemoryPrivate *priv; - - priv = E_TABLE_MEMORY_GET_PRIVATE (object); - - g_free (priv->data); - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (e_table_memory_parent_class)->finalize (object); -} - -static gint -etmm_row_count (ETableModel *etm) -{ - ETableMemory *etmm = E_TABLE_MEMORY (etm); - - return etmm->priv->num_rows; -} - -static void -e_table_memory_class_init (ETableMemoryClass *class) -{ - GObjectClass *object_class; - ETableModelClass *table_model_class; - - g_type_class_add_private (class, sizeof (ETableMemoryPrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->finalize = etmm_finalize; - - table_model_class = E_TABLE_MODEL_CLASS (class); - table_model_class->row_count = etmm_row_count; -} - -static void -e_table_memory_init (ETableMemory *etmm) -{ - etmm->priv = E_TABLE_MEMORY_GET_PRIVATE (etmm); -} - -/** - * e_table_memory_new - * - * XXX docs here. - * - * return values: a newly constructed ETableMemory. - */ -ETableMemory * -e_table_memory_new (void) -{ - return g_object_new (E_TYPE_TABLE_MEMORY, NULL); -} - -/** - * e_table_memory_get_data: - * @etmm: - * @row: - * - * - * - * Return value: - **/ -gpointer -e_table_memory_get_data (ETableMemory *etmm, - gint row) -{ - g_return_val_if_fail (row >= 0, NULL); - g_return_val_if_fail (row < etmm->priv->num_rows, NULL); - - return etmm->priv->data[row]; -} - -/** - * e_table_memory_set_data: - * @etmm: - * @row: - * @data: - * - * - **/ -void -e_table_memory_set_data (ETableMemory *etmm, - gint row, - gpointer data) -{ - g_return_if_fail (row >= 0); - g_return_if_fail (row < etmm->priv->num_rows); - - etmm->priv->data[row] = data; -} - -/** - * e_table_memory_insert: - * @table_model: - * @parent_path: - * @position: - * @data: - * - * - * - * Return value: - **/ -void -e_table_memory_insert (ETableMemory *etmm, - gint row, - gpointer data) -{ - g_return_if_fail (row >= -1); - g_return_if_fail (row <= etmm->priv->num_rows); - - if (!etmm->priv->frozen) - e_table_model_pre_change (E_TABLE_MODEL (etmm)); - - if (row == -1) - row = etmm->priv->num_rows; - etmm->priv->data = g_renew (gpointer, etmm->priv->data, etmm->priv->num_rows + 1); - memmove ( - etmm->priv->data + row + 1, - etmm->priv->data + row, - (etmm->priv->num_rows - row) * sizeof (gpointer)); - etmm->priv->data[row] = data; - etmm->priv->num_rows++; - if (!etmm->priv->frozen) - e_table_model_row_inserted (E_TABLE_MODEL (etmm), row); -} - -/** - * e_table_memory_remove: - * @etable: - * @path: - * - * - * - * Return value: - **/ -gpointer -e_table_memory_remove (ETableMemory *etmm, - gint row) -{ - gpointer ret; - - g_return_val_if_fail (row >= 0, NULL); - g_return_val_if_fail (row < etmm->priv->num_rows, NULL); - - if (!etmm->priv->frozen) - e_table_model_pre_change (E_TABLE_MODEL (etmm)); - ret = etmm->priv->data[row]; - memmove ( - etmm->priv->data + row, - etmm->priv->data + row + 1, - (etmm->priv->num_rows - row - 1) * sizeof (gpointer)); - etmm->priv->num_rows--; - if (!etmm->priv->frozen) - e_table_model_row_deleted (E_TABLE_MODEL (etmm), row); - return ret; -} - -/** - * e_table_memory_clear: - * @etable: - * @path: - * - * - * - * Return value: - **/ -void -e_table_memory_clear (ETableMemory *etmm) -{ - if (!etmm->priv->frozen) - e_table_model_pre_change (E_TABLE_MODEL (etmm)); - g_free (etmm->priv->data); - etmm->priv->data = NULL; - etmm->priv->num_rows = 0; - if (!etmm->priv->frozen) - e_table_model_changed (E_TABLE_MODEL (etmm)); -} - -/** - * e_table_memory_freeze: - * @etmm: the ETableModel to freeze. - * - * This function prepares an ETableModel for a period of much change. - * All signals regarding changes to the table are deferred until we - * thaw the table. - * - **/ -void -e_table_memory_freeze (ETableMemory *etmm) -{ - ETableMemoryPrivate *priv = etmm->priv; - - if (priv->frozen == 0) - e_table_model_pre_change (E_TABLE_MODEL (etmm)); - - priv->frozen++; -} - -/** - * e_table_memory_thaw: - * @etmm: the ETableMemory to thaw. - * - * This function thaws an ETableMemory. All the defered signals can add - * up to a lot, we don't know - so we just emit a model_changed - * signal. - * - **/ -void -e_table_memory_thaw (ETableMemory *etmm) -{ - ETableMemoryPrivate *priv = etmm->priv; - - if (priv->frozen > 0) - priv->frozen--; - if (priv->frozen == 0) { - e_table_model_changed (E_TABLE_MODEL (etmm)); - } -} diff --git a/widgets/table/e-table-memory.h b/widgets/table/e-table-memory.h deleted file mode 100644 index 853f378c9e..0000000000 --- a/widgets/table/e-table-memory.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_MEMORY_H_ -#define _E_TABLE_MEMORY_H_ - -#include <gdk-pixbuf/gdk-pixbuf.h> -#include <table/e-table-model.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_MEMORY \ - (e_table_memory_get_type ()) -#define E_TABLE_MEMORY(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_MEMORY, ETableMemory)) -#define E_TABLE_MEMORY_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_MEMORY, ETableMemoryClass)) -#define E_IS_TABLE_MEMORY(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_MEMORY)) -#define E_IS_TABLE_MEMORY_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_MEMORY)) -#define E_TABLE_MEMORY_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_MEMORY, ETableMemoryClass)) - -G_BEGIN_DECLS - -typedef struct _ETableMemory ETableMemory; -typedef struct _ETableMemoryClass ETableMemoryClass; -typedef struct _ETableMemoryPrivate ETableMemoryPrivate; - -struct _ETableMemory { - ETableModel parent; - ETableMemoryPrivate *priv; -}; - -struct _ETableMemoryClass { - ETableModelClass parent_class; -}; - -GType e_table_memory_get_type (void) G_GNUC_CONST; -ETableMemory * e_table_memory_new (void); -void e_table_memory_construct (ETableMemory *etable); - -/* row operations */ -void e_table_memory_insert (ETableMemory *etable, - gint row, - gpointer data); -gpointer e_table_memory_remove (ETableMemory *etable, - gint row); -void e_table_memory_clear (ETableMemory *etable); - -/* Freeze and thaw */ -void e_table_memory_freeze (ETableMemory *etable); -void e_table_memory_thaw (ETableMemory *etable); -gpointer e_table_memory_get_data (ETableMemory *etm, - gint row); -void e_table_memory_set_data (ETableMemory *etm, - gint row, - gpointer data); - -G_END_DECLS - -#endif /* _E_TABLE_MEMORY_H */ diff --git a/widgets/table/e-table-model.c b/widgets/table/e-table-model.c deleted file mode 100644 index 99479f94ee..0000000000 --- a/widgets/table/e-table-model.c +++ /dev/null @@ -1,682 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "e-util/e-util.h" - -#include "e-table-model.h" - -#define ETM_FROZEN(e) \ - (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (e), "frozen")) != 0) - -#define d(x) - -d (static gint depth = 0;) - -G_DEFINE_TYPE (ETableModel, e_table_model, G_TYPE_OBJECT) - -enum { - MODEL_NO_CHANGE, - MODEL_CHANGED, - MODEL_PRE_CHANGE, - MODEL_ROW_CHANGED, - MODEL_CELL_CHANGED, - MODEL_ROWS_INSERTED, - MODEL_ROWS_DELETED, - ROW_SELECTION, - LAST_SIGNAL -}; - -static guint 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. - */ -gint -e_table_model_column_count (ETableModel *e_table_model) -{ - ETableModelClass *class; - - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), 0); - - class = E_TABLE_MODEL_GET_CLASS (e_table_model); - g_return_val_if_fail (class->column_count != NULL, 0); - - return class->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. - */ -gint -e_table_model_row_count (ETableModel *e_table_model) -{ - ETableModelClass *class; - - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), 0); - - class = E_TABLE_MODEL_GET_CLASS (e_table_model); - g_return_val_if_fail (class->row_count != NULL, 0); - - return class->row_count (e_table_model); -} - -/** - * 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, - gint row) -{ - ETableModelClass *class; - - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - class = E_TABLE_MODEL_GET_CLASS (e_table_model); - - if (class->append_row != NULL) - class->append_row (e_table_model, source, row); -} - -/** - * 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. - * - * The data returned must be valid until the model sends a signal that - * affect that piece of data. model_changed affects all data. - * row_changed affects the data in that row. cell_changed affects the - * data in that cell. rows_deleted affects all data in those rows. - * rows_inserted and no_change don't affect any data in this way. - **/ -gpointer -e_table_model_value_at (ETableModel *e_table_model, - gint col, - gint row) -{ - ETableModelClass *class; - - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - class = E_TABLE_MODEL_GET_CLASS (e_table_model); - g_return_val_if_fail (class->value_at != NULL, NULL); - - return class->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 gpointer . - */ -void -e_table_model_set_value_at (ETableModel *e_table_model, - gint col, - gint row, - gconstpointer value) -{ - ETableModelClass *class; - - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - class = E_TABLE_MODEL_GET_CLASS (e_table_model); - g_return_if_fail (class->set_value_at != NULL); - - class->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, - gint col, - gint row) -{ - ETableModelClass *class; - - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), FALSE); - - class = E_TABLE_MODEL_GET_CLASS (e_table_model); - g_return_val_if_fail (class->is_cell_editable != NULL, FALSE); - - return class->is_cell_editable (e_table_model, col, row); -} - -gpointer -e_table_model_duplicate_value (ETableModel *e_table_model, - gint col, - gconstpointer value) -{ - ETableModelClass *class; - - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - class = E_TABLE_MODEL_GET_CLASS (e_table_model); - - if (class->duplicate_value == NULL) - return NULL; - - return class->duplicate_value (e_table_model, col, value); -} - -void -e_table_model_free_value (ETableModel *e_table_model, - gint col, - gpointer value) -{ - ETableModelClass *class; - - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - class = E_TABLE_MODEL_GET_CLASS (e_table_model); - - if (class->free_value != NULL) - class->free_value (e_table_model, col, value); -} - -gboolean -e_table_model_has_save_id (ETableModel *e_table_model) -{ - ETableModelClass *class; - - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), FALSE); - - class = E_TABLE_MODEL_GET_CLASS (e_table_model); - - if (class->has_save_id == NULL) - return FALSE; - - return class->has_save_id (e_table_model); -} - -gchar * -e_table_model_get_save_id (ETableModel *e_table_model, - gint row) -{ - ETableModelClass *class; - - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - class = E_TABLE_MODEL_GET_CLASS (e_table_model); - - if (class->get_save_id == NULL) - return NULL; - - return class->get_save_id (e_table_model, row); -} - -gboolean -e_table_model_has_change_pending (ETableModel *e_table_model) -{ - ETableModelClass *class; - - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), FALSE); - - class = E_TABLE_MODEL_GET_CLASS (e_table_model); - - if (class->has_change_pending == NULL) - return FALSE; - - return class->has_change_pending (e_table_model); -} - -gpointer -e_table_model_initialize_value (ETableModel *e_table_model, - gint col) -{ - ETableModelClass *class; - - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - class = E_TABLE_MODEL_GET_CLASS (e_table_model); - - if (class->initialize_value == NULL) - return NULL; - - return class->initialize_value (e_table_model, col); -} - -gboolean -e_table_model_value_is_empty (ETableModel *e_table_model, - gint col, - gconstpointer value) -{ - ETableModelClass *class; - - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), FALSE); - - class = E_TABLE_MODEL_GET_CLASS (e_table_model); - - if (class->value_is_empty == NULL) - return FALSE; - - return class->value_is_empty (e_table_model, col, value); -} - -gchar * -e_table_model_value_to_string (ETableModel *e_table_model, - gint col, - gconstpointer value) -{ - ETableModelClass *class; - - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - class = E_TABLE_MODEL_GET_CLASS (e_table_model); - - if (class->value_to_string == NULL) - return g_strdup (""); - - return class->value_to_string (e_table_model, col, value); -} - -static void -e_table_model_class_init (ETableModelClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - signals[MODEL_NO_CHANGE] = g_signal_new ( - "model_no_change", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableModelClass, model_no_change), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[MODEL_CHANGED] = g_signal_new ( - "model_changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableModelClass, model_changed), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[MODEL_PRE_CHANGE] = g_signal_new ( - "model_pre_change", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableModelClass, model_pre_change), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[MODEL_ROW_CHANGED] = g_signal_new ( - "model_row_changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableModelClass, model_row_changed), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, - G_TYPE_INT); - - signals[MODEL_CELL_CHANGED] = g_signal_new ( - "model_cell_changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableModelClass, model_cell_changed), - (GSignalAccumulator) NULL, NULL, - e_marshal_VOID__INT_INT, - G_TYPE_NONE, 2, - G_TYPE_INT, - G_TYPE_INT); - - signals[MODEL_ROWS_INSERTED] = g_signal_new ( - "model_rows_inserted", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableModelClass, model_rows_inserted), - (GSignalAccumulator) NULL, NULL, - e_marshal_VOID__INT_INT, - G_TYPE_NONE, 2, - G_TYPE_INT, - G_TYPE_INT); - - signals[MODEL_ROWS_DELETED] = g_signal_new ( - "model_rows_deleted", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableModelClass, model_rows_deleted), - (GSignalAccumulator) NULL, NULL, - e_marshal_VOID__INT_INT, - G_TYPE_NONE, 2, - G_TYPE_INT, - G_TYPE_INT); - - class->column_count = NULL; - class->row_count = NULL; - class->append_row = NULL; - - class->value_at = NULL; - class->set_value_at = NULL; - class->is_cell_editable = NULL; - - class->has_save_id = NULL; - class->get_save_id = NULL; - - class->has_change_pending = NULL; - - class->duplicate_value = NULL; - class->free_value = NULL; - class->initialize_value = NULL; - class->value_is_empty = NULL; - class->value_to_string = NULL; - - class->model_no_change = NULL; - class->model_changed = NULL; - class->model_row_changed = NULL; - class->model_cell_changed = NULL; - class->model_rows_inserted = NULL; - class->model_rows_deleted = NULL; -} - -static void -e_table_model_init (ETableModel *e_table_model) -{ - /* nothing to do */ -} - -#if d(!)0 -static void -print_tabs (void) -{ - gint 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_IS_TABLE_MODEL (e_table_model)); - - if (ETM_FROZEN (e_table_model)) - return; - - d (print_tabs ()); - d (depth++); - g_signal_emit (e_table_model, signals[MODEL_PRE_CHANGE], 0); - d (depth--); -} - -/** - * e_table_model_no_change: - * @e_table_model: the table model to notify of the lack of a 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_no_change" 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_no_change (ETableModel *e_table_model) -{ - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - if (ETM_FROZEN (e_table_model)) - return; - - d (print_tabs ()); - d (depth++); - g_signal_emit (e_table_model, signals[MODEL_NO_CHANGE], 0); - 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_IS_TABLE_MODEL (e_table_model)); - - if (ETM_FROZEN (e_table_model)) - return; - - d (print_tabs ()); - d (depth++); - g_signal_emit (e_table_model, signals[MODEL_CHANGED], 0); - 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, - gint row) -{ - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - if (ETM_FROZEN (e_table_model)) - return; - - d (print_tabs ()); - d (depth++); - g_signal_emit (e_table_model, signals[MODEL_ROW_CHANGED], 0, 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, - gint col, - gint row) -{ - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - if (ETM_FROZEN (e_table_model)) - return; - - d (print_tabs ()); - d (depth++); - g_signal_emit ( - e_table_model, signals[MODEL_CELL_CHANGED], 0, col, row); - d (depth--); -} - -/** - * e_table_model_rows_inserted: - * @e_table_model: the table model to notify of the change - * @row: the row that was inserted into the model. - * @count: The number of rows that were inserted. - * - * Use this function to notify any views of the table model that - * @count rows at row @row have been inserted into the model. This - * function will emit the "model_rows_inserted" signal on the - * @e_table_model object - */ -void -e_table_model_rows_inserted (ETableModel *e_table_model, - gint row, - gint count) -{ - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - if (ETM_FROZEN (e_table_model)) - return; - - d (print_tabs ()); - d (depth++); - g_signal_emit ( - e_table_model, signals[MODEL_ROWS_INSERTED], 0, row, count); - 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_rows_inserted" signal on the @e_table_model object - */ -void -e_table_model_row_inserted (ETableModel *e_table_model, - gint row) -{ - e_table_model_rows_inserted (e_table_model, row, 1); -} - -/** - * e_table_model_row_deleted: - * @e_table_model: the table model to notify of the change - * @row: the row that was deleted - * @count: The number of rows deleted - * - * Use this function to notify any views of the table model that - * @count rows at row @row have been deleted from the model. This - * function will emit the "model_rows_deleted" signal on the - * @e_table_model object - */ -void -e_table_model_rows_deleted (ETableModel *e_table_model, - gint row, - gint count) -{ - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - if (ETM_FROZEN (e_table_model)) - return; - - d (print_tabs ()); - d (depth++); - g_signal_emit ( - e_table_model, signals[MODEL_ROWS_DELETED], 0, row, count); - 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_rows_deleted" signal on the @e_table_model object - */ -void -e_table_model_row_deleted (ETableModel *e_table_model, - gint row) -{ - e_table_model_rows_deleted (e_table_model, row, 1); -} - -void -e_table_model_freeze (ETableModel *e_table_model) -{ - e_table_model_pre_change (e_table_model); - - /* FIXME This expression is awesome! */ - g_object_set_data ( - G_OBJECT (e_table_model), "frozen", - GINT_TO_POINTER (GPOINTER_TO_INT ( - g_object_get_data (G_OBJECT (e_table_model), "frozen")) + 1)); -} - -void -e_table_model_thaw (ETableModel *e_table_model) -{ - /* FIXME This expression is awesome! */ - g_object_set_data ( - G_OBJECT (e_table_model), "frozen", - GINT_TO_POINTER (GPOINTER_TO_INT ( - g_object_get_data (G_OBJECT (e_table_model), "frozen")) - 1)); - - e_table_model_changed (e_table_model); -} - diff --git a/widgets/table/e-table-model.h b/widgets/table/e-table-model.h deleted file mode 100644 index 2ff4eacebd..0000000000 --- a/widgets/table/e-table-model.h +++ /dev/null @@ -1,213 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_MODEL_H_ -#define _E_TABLE_MODEL_H_ - -#include <glib-object.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_MODEL \ - (e_table_model_get_type ()) -#define E_TABLE_MODEL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_MODEL, ETableModel)) -#define E_TABLE_MODEL_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_MODEL, ETableModelClass)) -#define E_IS_TABLE_MODEL(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_MODEL)) -#define E_IS_TABLE_MODEL_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_MODEL)) -#define E_TABLE_MODEL_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_MODEL, ETableModelClass)) - -G_BEGIN_DECLS - -typedef struct _ETableModel ETableModel; -typedef struct _ETableModelClass ETableModelClass; - -struct _ETableModel { - GObject parent; -}; - -struct _ETableModelClass { - GObjectClass parent_class; - - /* - * Virtual methods - */ - gint (*column_count) (ETableModel *etm); - gint (*row_count) (ETableModel *etm); - void (*append_row) (ETableModel *etm, - ETableModel *source, - gint row); - - gpointer (*value_at) (ETableModel *etm, - gint col, - gint row); - void (*set_value_at) (ETableModel *etm, - gint col, - gint row, - gconstpointer value); - gboolean (*is_cell_editable) (ETableModel *etm, - gint col, - gint row); - - gboolean (*has_save_id) (ETableModel *etm); - gchar * (*get_save_id) (ETableModel *etm, - gint row); - - gboolean (*has_change_pending) (ETableModel *etm); - - /* Allocate a copy of the given value. */ - gpointer (*duplicate_value) (ETableModel *etm, - gint col, - gconstpointer value); - /* Free an allocated value. */ - void (*free_value) (ETableModel *etm, - gint col, - gpointer value); - /* Return an allocated empty value. */ - gpointer (*initialize_value) (ETableModel *etm, - gint col); - /* Return TRUE if value is equivalent to an empty cell. */ - gboolean (*value_is_empty) (ETableModel *etm, - gint col, - gconstpointer value); - /* Return an allocated string. */ - gchar * (*value_to_string) (ETableModel *etm, - gint col, - gconstpointer value); - - /* - * Signals - */ - - /* - * These all come after the change has been made. - * No changes, cancel pre_change: no_change - * 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_no_change) (ETableModel *etm); - void (*model_changed) (ETableModel *etm); - void (*model_row_changed) (ETableModel *etm, - gint row); - void (*model_cell_changed) (ETableModel *etm, - gint col, - gint row); - void (*model_rows_inserted) (ETableModel *etm, - gint row, - gint count); - void (*model_rows_deleted) (ETableModel *etm, - gint row, - gint count); -}; - -GType e_table_model_get_type (void) G_GNUC_CONST; - -/**/ -gint e_table_model_column_count (ETableModel *e_table_model); -const gchar * e_table_model_column_name (ETableModel *e_table_model, - gint col); -gint e_table_model_row_count (ETableModel *e_table_model); -void e_table_model_append_row (ETableModel *e_table_model, - ETableModel *source, - gint row); - -/**/ -gpointer e_table_model_value_at (ETableModel *e_table_model, - gint col, - gint row); -void e_table_model_set_value_at (ETableModel *e_table_model, - gint col, - gint row, - gconstpointer value); -gboolean e_table_model_is_cell_editable (ETableModel *e_table_model, - gint col, - gint row); - -/**/ -gboolean e_table_model_has_save_id (ETableModel *etm); -gchar * e_table_model_get_save_id (ETableModel *etm, - gint row); - -/**/ -gboolean e_table_model_has_change_pending - (ETableModel *etm); - -/**/ -gpointer e_table_model_duplicate_value (ETableModel *e_table_model, - gint col, - gconstpointer value); -void e_table_model_free_value (ETableModel *e_table_model, - gint col, - gpointer value); -gpointer e_table_model_initialize_value (ETableModel *e_table_model, - gint col); -gboolean e_table_model_value_is_empty (ETableModel *e_table_model, - gint col, - gconstpointer value); -gchar * e_table_model_value_to_string (ETableModel *e_table_model, - gint col, - gconstpointer value); - -/* - * Routines for emitting signals on the e_table - */ -void e_table_model_pre_change (ETableModel *e_table_model); -void e_table_model_no_change (ETableModel *e_table_model); -void e_table_model_changed (ETableModel *e_table_model); -void e_table_model_row_changed (ETableModel *e_table_model, - gint row); -void e_table_model_cell_changed (ETableModel *e_table_model, - gint col, - gint row); -void e_table_model_rows_inserted (ETableModel *e_table_model, - gint row, - gint count); -void e_table_model_rows_deleted (ETableModel *e_table_model, - gint row, - gint count); - -/**/ -void e_table_model_row_inserted (ETableModel *e_table_model, - gint row); -void e_table_model_row_deleted (ETableModel *e_table_model, - gint row); - -void e_table_model_freeze (ETableModel *e_table_model); -void e_table_model_thaw (ETableModel *e_table_model); - -G_END_DECLS - -#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 503b6a47a7..0000000000 --- a/widgets/table/e-table-one.c +++ /dev/null @@ -1,254 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "e-util/e-util.h" - -#include "e-table-one.h" - -G_DEFINE_TYPE (ETableOne, e_table_one, E_TYPE_TABLE_MODEL) - -static gint -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 gint -one_row_count (ETableModel *etm) -{ - return 1; -} - -static gpointer -one_value_at (ETableModel *etm, - gint col, - gint 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, - gint col, - gint row, - gconstpointer 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, - gint col, - gint row) -{ - ETableOne *one = E_TABLE_ONE (etm); - - if (one->source) - return e_table_model_is_cell_editable (one->source, col, -1); - else - return FALSE; -} - -/* The default for one_duplicate_value is to return the raw value. */ -static gpointer -one_duplicate_value (ETableModel *etm, - gint col, - gconstpointer value) -{ - ETableOne *one = E_TABLE_ONE (etm); - - if (one->source) - return e_table_model_duplicate_value (one->source, col, value); - else - return (gpointer) value; -} - -static void -one_free_value (ETableModel *etm, - gint col, - gpointer value) -{ - ETableOne *one = E_TABLE_ONE (etm); - - if (one->source) - e_table_model_free_value (one->source, col, value); -} - -static gpointer -one_initialize_value (ETableModel *etm, - gint 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, - gint col, - gconstpointer 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 gchar * -one_value_to_string (ETableModel *etm, - gint col, - gconstpointer 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_finalize (GObject *object) -{ - G_OBJECT_CLASS (e_table_one_parent_class)->finalize (object); -} - -static void -one_dispose (GObject *object) -{ - ETableOne *one = E_TABLE_ONE (object); - - if (one->data) { - gint i; - gint col_count; - - if (one->source) { - col_count = e_table_model_column_count (one->source); - - for (i = 0; i < col_count; i++) - e_table_model_free_value (one->source, i, one->data[i]); - } - - g_free (one->data); - } - one->data = NULL; - - if (one->source) - g_object_unref (one->source); - one->source = NULL; - - G_OBJECT_CLASS (e_table_one_parent_class)->dispose (object); -} - -static void -e_table_one_class_init (ETableOneClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - ETableModelClass *model_class = E_TABLE_MODEL_CLASS (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->dispose = one_dispose; - object_class->finalize = one_finalize; -} - -static void -e_table_one_init (ETableOne *one) -{ - one->source = NULL; - one->data = NULL; -} - -ETableModel * -e_table_one_new (ETableModel *source) -{ - ETableOne *eto; - gint col_count; - gint i; - - eto = g_object_new (E_TYPE_TABLE_ONE, NULL); - eto->source = source; - - col_count = e_table_model_column_count (source); - eto->data = g_new (gpointer , col_count); - for (i = 0; i < col_count; i++) { - eto->data[i] = e_table_model_initialize_value (source, i); - } - - if (source) - g_object_ref (source); - - return (ETableModel *) eto; -} - -void -e_table_one_commit (ETableOne *one) -{ - if (one->source) { - gint empty = TRUE; - gint col; - gint 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 a0d5c7bf88..0000000000 --- a/widgets/table/e-table-one.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_ONE_H_ -#define _E_TABLE_ONE_H_ - -#include <table/e-table-model.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_ONE \ - (e_table_one_get_type ()) -#define E_TABLE_ONE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_ONE, ETableOne)) -#define E_TABLE_ONE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_ONE, ETableOneClass)) -#define E_IS_TABLE_ONE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_ONE)) -#define E_IS_TABLE_ONE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_ONE)) -#define E_TABLE_ONE_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_ONE, ETableOneClass)) - -G_BEGIN_DECLS - -typedef struct _ETableOne ETableOne; -typedef struct _ETableOneClass ETableOneClass; - -struct _ETableOne { - ETableModel parent; - - ETableModel *source; - gpointer *data; -}; - -struct _ETableOneClass { - ETableModelClass parent_class; -}; - -GType e_table_one_get_type (void) G_GNUC_CONST; - -ETableModel * e_table_one_new (ETableModel *source); -void e_table_one_commit (ETableOne *one); - -G_END_DECLS - -#endif /* _E_TABLE_ONE_H_ */ - diff --git a/widgets/table/e-table-search.c b/widgets/table/e-table-search.c deleted file mode 100644 index e084bc9602..0000000000 --- a/widgets/table/e-table-search.c +++ /dev/null @@ -1,235 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include "e-util/e-util.h" - -#include "e-table-search.h" - -#define d(x) - -struct _ETableSearchPrivate { - guint timeout_id; - - gchar *search_string; - gunichar last_character; -}; - -G_DEFINE_TYPE (ETableSearch, e_table_search, G_TYPE_OBJECT) - -enum { - SEARCH_SEARCH, - SEARCH_ACCEPT, - LAST_SIGNAL -}; - -#define E_TABLE_SEARCH_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), E_TYPE_TABLE_SEARCH, ETableSearchPrivate)) - -d (static gint depth = 0) - -static guint e_table_search_signals[LAST_SIGNAL] = { 0, }; - -static gboolean -e_table_search_search (ETableSearch *e_table_search, - gchar *string, - ETableSearchFlags flags) -{ - gboolean ret_val; - g_return_val_if_fail (E_IS_TABLE_SEARCH (e_table_search), FALSE); - - g_signal_emit ( - e_table_search, - e_table_search_signals[SEARCH_SEARCH], 0, - string, flags, &ret_val); - - return ret_val; -} - -static void -e_table_search_accept (ETableSearch *e_table_search) -{ - g_return_if_fail (E_IS_TABLE_SEARCH (e_table_search)); - - g_signal_emit ( - e_table_search, - e_table_search_signals[SEARCH_ACCEPT], 0); -} - -static gboolean -ets_accept (gpointer data) -{ - ETableSearch *ets = data; - e_table_search_accept (ets); - g_free (ets->priv->search_string); - - ets->priv->timeout_id = 0; - ets->priv->search_string = g_strdup (""); - ets->priv->last_character = 0; - - return FALSE; -} - -static void -drop_timeout (ETableSearch *ets) -{ - if (ets->priv->timeout_id) { - g_source_remove (ets->priv->timeout_id); - } - ets->priv->timeout_id = 0; -} - -static void -add_timeout (ETableSearch *ets) -{ - drop_timeout (ets); - ets->priv->timeout_id = g_timeout_add_seconds (1, ets_accept, ets); -} - -static void -e_table_search_finalize (GObject *object) -{ - ETableSearchPrivate *priv; - - priv = E_TABLE_SEARCH_GET_PRIVATE (object); - - drop_timeout (E_TABLE_SEARCH (object)); - - g_free (priv->search_string); - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (e_table_search_parent_class)->finalize (object); -} - -static void -e_table_search_class_init (ETableSearchClass *class) -{ - GObjectClass *object_class; - - g_type_class_add_private (class, sizeof (ETableSearchPrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->finalize = e_table_search_finalize; - - e_table_search_signals[SEARCH_SEARCH] = g_signal_new ( - "search", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableSearchClass, search), - (GSignalAccumulator) NULL, NULL, - e_marshal_BOOLEAN__STRING_INT, - G_TYPE_BOOLEAN, 2, - G_TYPE_STRING, - G_TYPE_INT); - - e_table_search_signals[SEARCH_ACCEPT] = g_signal_new ( - "accept", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableSearchClass, accept), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - class->search = NULL; - class->accept = NULL; -} - -static void -e_table_search_init (ETableSearch *ets) -{ - ets->priv = E_TABLE_SEARCH_GET_PRIVATE (ets); - - ets->priv->search_string = g_strdup (""); -} - -ETableSearch * -e_table_search_new (void) -{ - return g_object_new (E_TYPE_TABLE_SEARCH, NULL); -} - -/** - * e_table_search_column_count: - * @e_table_search: The e-table-search to operate on - * - * Returns: the number of columns in the table search. - */ -void -e_table_search_input_character (ETableSearch *ets, - gunichar character) -{ - gchar character_utf8[7]; - gchar *temp_string; - - g_return_if_fail (ets != NULL); - g_return_if_fail (E_IS_TABLE_SEARCH (ets)); - - character_utf8[g_unichar_to_utf8 (character, character_utf8)] = 0; - - temp_string = g_strdup_printf ("%s%s", ets->priv->search_string, character_utf8); - if (e_table_search_search ( - ets, temp_string, - ets->priv->last_character != 0 ? - E_TABLE_SEARCH_FLAGS_CHECK_CURSOR_FIRST : 0)) { - g_free (ets->priv->search_string); - ets->priv->search_string = temp_string; - add_timeout (ets); - ets->priv->last_character = character; - return; - } else { - g_free (temp_string); - } - - if (character == ets->priv->last_character) { - if (ets->priv->search_string && - e_table_search_search (ets, ets->priv->search_string, 0)) { - add_timeout (ets); - } - } -} - -gboolean -e_table_search_backspace (ETableSearch *ets) -{ - gchar *end; - - g_return_val_if_fail (ets != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_SEARCH (ets), FALSE); - - if (!ets->priv->search_string || - !*ets->priv->search_string) - return FALSE; - - end = ets->priv->search_string + strlen (ets->priv->search_string); - end = g_utf8_prev_char (end); - *end = 0; - ets->priv->last_character = 0; - add_timeout (ets); - return TRUE; -} diff --git a/widgets/table/e-table-search.h b/widgets/table/e-table-search.h deleted file mode 100644 index ecd56a5d72..0000000000 --- a/widgets/table/e-table-search.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_SEARCH_H_ -#define _E_TABLE_SEARCH_H_ - -#include <glib-object.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_SEARCH \ - (e_table_search_get_type ()) -#define E_TABLE_SEARCH(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_SEARCH, ETableSearch)) -#define E_TABLE_SEARCH_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_SEARCH, ETableSearchClass)) -#define E_IS_TABLE_SEARCH(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_SEARCH)) -#define E_IS_TABLE_SEARCH_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_SEARCH)) -#define E_TABLE_SEARCH_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_SEARCH, ETableSearchClass)) - -G_BEGIN_DECLS - -typedef struct _ETableSearch ETableSearch; -typedef struct _ETableSearchClass ETableSearchClass; -typedef struct _ETableSearchPrivate ETableSearchPrivate; - -typedef enum { - E_TABLE_SEARCH_FLAGS_CHECK_CURSOR_FIRST = 1 << 0 -} ETableSearchFlags; - -struct _ETableSearch { - GObject parent; - ETableSearchPrivate *priv; -}; - -struct _ETableSearchClass { - GObjectClass parent_class; - - /* Signals */ - gboolean (*search) (ETableSearch *ets, - gchar *string /* utf8 */, - ETableSearchFlags flags); - void (*accept) (ETableSearch *ets); -}; - -GType e_table_search_get_type (void) G_GNUC_CONST; -ETableSearch * e_table_search_new (void); -void e_table_search_input_character (ETableSearch *e_table_search, - gunichar character); -gboolean e_table_search_backspace (ETableSearch *e_table_search); -void e_table_search_cancel (ETableSearch *e_table_search); - -G_END_DECLS - -#endif /* _E_TABLE_SEARCH_H_ */ diff --git a/widgets/table/e-table-selection-model.c b/widgets/table/e-table-selection-model.c deleted file mode 100644 index 2ee44a7ffe..0000000000 --- a/widgets/table/e-table-selection-model.c +++ /dev/null @@ -1,385 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include <gdk/gdkkeysyms.h> - -#include <glib/gi18n.h> -#include "e-util/e-util.h" - -#include "e-table-selection-model.h" - -G_DEFINE_TYPE (ETableSelectionModel, e_table_selection_model, E_SELECTION_MODEL_ARRAY_TYPE) - -static gint etsm_get_row_count (ESelectionModelArray *esm); - -enum { - PROP_0, - PROP_MODEL, - PROP_HEADER -}; - -static void -save_to_hash (gint model_row, - gpointer closure) -{ - ETableSelectionModel *etsm = closure; - const gchar *key = e_table_model_get_save_id (etsm->model, model_row); - - g_hash_table_insert (etsm->hash, (gpointer) key, (gpointer) key); -} - -static void -free_hash (ETableSelectionModel *etsm) -{ - if (etsm->hash) { - g_hash_table_destroy (etsm->hash); - etsm->hash = NULL; - } - if (etsm->cursor_id) - g_free (etsm->cursor_id); - etsm->cursor_id = NULL; -} - -static void -model_pre_change (ETableModel *etm, - ETableSelectionModel *etsm) -{ - free_hash (etsm); - - if (etsm->model && e_table_model_has_save_id (etsm->model)) { - gint cursor_row; - - etsm->hash = g_hash_table_new_full ( - g_str_hash, g_str_equal, - (GDestroyNotify) g_free, - (GDestroyNotify) NULL); - e_selection_model_foreach (E_SELECTION_MODEL (etsm), save_to_hash, etsm); - - g_object_get ( - etsm, - "cursor_row", &cursor_row, - NULL); - g_free (etsm->cursor_id); - if (cursor_row != -1) - etsm->cursor_id = e_table_model_get_save_id (etm, cursor_row); - else - etsm->cursor_id = NULL; - } -} - -static gint -model_changed_idle (ETableSelectionModel *etsm) -{ - ETableModel *etm = etsm->model; - - e_selection_model_clear (E_SELECTION_MODEL (etsm)); - - if (etsm->cursor_id && etm && e_table_model_has_save_id (etm)) { - gint row_count = e_table_model_row_count (etm); - gint cursor_row = -1; - gint cursor_col = -1; - gint i; - e_selection_model_array_confirm_row_count (E_SELECTION_MODEL_ARRAY (etsm)); - for (i = 0; i < row_count; i++) { - gchar *save_id = e_table_model_get_save_id (etm, i); - if (g_hash_table_lookup (etsm->hash, save_id)) - e_selection_model_change_one_row (E_SELECTION_MODEL (etsm), i, TRUE); - - if (etsm->cursor_id && !strcmp (etsm->cursor_id, save_id)) { - cursor_row = i; - cursor_col = e_selection_model_cursor_col (E_SELECTION_MODEL (etsm)); - if (cursor_col == -1) { - if (etsm->eth) { - cursor_col = e_table_header_prioritized_column (etsm->eth); - } else - cursor_col = 0; - } - e_selection_model_change_cursor (E_SELECTION_MODEL (etsm), cursor_row, cursor_col); - g_free (etsm->cursor_id); - etsm->cursor_id = NULL; - } - g_free (save_id); - } - free_hash (etsm); - e_selection_model_cursor_changed (E_SELECTION_MODEL (etsm), cursor_row, cursor_col); - e_selection_model_selection_changed (E_SELECTION_MODEL (etsm)); - } - etsm->model_changed_idle_id = 0; - return FALSE; -} - -static void -model_changed (ETableModel *etm, - ETableSelectionModel *etsm) -{ - e_selection_model_clear (E_SELECTION_MODEL (etsm)); - if (!etsm->model_changed_idle_id && etm && e_table_model_has_save_id (etm)) { - etsm->model_changed_idle_id = g_idle_add_full (G_PRIORITY_HIGH, (GSourceFunc) model_changed_idle, etsm, NULL); - } -} - -static void -model_row_changed (ETableModel *etm, - gint row, - ETableSelectionModel *etsm) -{ - free_hash (etsm); -} - -static void -model_cell_changed (ETableModel *etm, - gint col, - gint row, - ETableSelectionModel *etsm) -{ - free_hash (etsm); -} - -#if 1 -static void -model_rows_inserted (ETableModel *etm, - gint row, - gint count, - ETableSelectionModel *etsm) -{ - e_selection_model_array_insert_rows (E_SELECTION_MODEL_ARRAY (etsm), row, count); - free_hash (etsm); -} - -static void -model_rows_deleted (ETableModel *etm, - gint row, - gint count, - ETableSelectionModel *etsm) -{ - e_selection_model_array_delete_rows (E_SELECTION_MODEL_ARRAY (etsm), row, count); - free_hash (etsm); -} - -#else - -static void -model_rows_inserted (ETableModel *etm, - gint row, - gint count, - ETableSelectionModel *etsm) -{ - model_changed (etm, etsm); -} - -static void -model_rows_deleted (ETableModel *etm, - gint row, - gint count, - ETableSelectionModel *etsm) -{ - model_changed (etm, etsm); -} -#endif - -inline static void -add_model (ETableSelectionModel *etsm, - ETableModel *model) -{ - etsm->model = model; - if (model) { - g_object_ref (model); - etsm->model_pre_change_id = g_signal_connect ( - model, "model_pre_change", - G_CALLBACK (model_pre_change), etsm); - etsm->model_changed_id = g_signal_connect ( - model, "model_changed", - G_CALLBACK (model_changed), etsm); - etsm->model_row_changed_id = g_signal_connect ( - model, "model_row_changed", - G_CALLBACK (model_row_changed), etsm); - etsm->model_cell_changed_id = g_signal_connect ( - model, "model_cell_changed", - G_CALLBACK (model_cell_changed), etsm); - etsm->model_rows_inserted_id = g_signal_connect ( - model, "model_rows_inserted", - G_CALLBACK (model_rows_inserted), etsm); - etsm->model_rows_deleted_id = g_signal_connect ( - model, "model_rows_deleted", - G_CALLBACK (model_rows_deleted), etsm); - } - e_selection_model_array_confirm_row_count (E_SELECTION_MODEL_ARRAY (etsm)); -} - -inline static void -drop_model (ETableSelectionModel *etsm) -{ - if (etsm->model) { - g_signal_handler_disconnect ( - etsm->model, - etsm->model_pre_change_id); - g_signal_handler_disconnect ( - etsm->model, - etsm->model_changed_id); - g_signal_handler_disconnect ( - etsm->model, - etsm->model_row_changed_id); - g_signal_handler_disconnect ( - etsm->model, - etsm->model_cell_changed_id); - g_signal_handler_disconnect ( - etsm->model, - etsm->model_rows_inserted_id); - g_signal_handler_disconnect ( - etsm->model, - etsm->model_rows_deleted_id); - - g_object_unref (etsm->model); - } - etsm->model = NULL; -} - -static void -etsm_dispose (GObject *object) -{ - ETableSelectionModel *etsm; - - etsm = E_TABLE_SELECTION_MODEL (object); - - if (etsm->model_changed_idle_id) - g_source_remove (etsm->model_changed_idle_id); - etsm->model_changed_idle_id = 0; - - drop_model (etsm); - free_hash (etsm); - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (e_table_selection_model_parent_class)->dispose (object); -} - -static void -etsm_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ETableSelectionModel *etsm = E_TABLE_SELECTION_MODEL (object); - - switch (property_id) { - case PROP_MODEL: - g_value_set_object (value, etsm->model); - break; - case PROP_HEADER: - g_value_set_object (value, etsm->eth); - break; - } -} - -static void -etsm_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ETableSelectionModel *etsm = E_TABLE_SELECTION_MODEL (object); - - switch (property_id) { - case PROP_MODEL: - drop_model (etsm); - add_model (etsm, g_value_get_object (value) ? E_TABLE_MODEL (g_value_get_object (value)) : NULL); - break; - case PROP_HEADER: - etsm->eth = E_TABLE_HEADER (g_value_get_object (value)); - break; - } -} - -static void -e_table_selection_model_init (ETableSelectionModel *selection) -{ - selection->model = NULL; - selection->hash = NULL; - selection->cursor_id = NULL; - - selection->model_changed_idle_id = 0; -} - -static void -e_table_selection_model_class_init (ETableSelectionModelClass *class) -{ - GObjectClass *object_class; - ESelectionModelArrayClass *esma_class; - - object_class = G_OBJECT_CLASS (class); - esma_class = E_SELECTION_MODEL_ARRAY_CLASS (class); - - object_class->dispose = etsm_dispose; - object_class->get_property = etsm_get_property; - object_class->set_property = etsm_set_property; - - esma_class->get_row_count = etsm_get_row_count; - - g_object_class_install_property ( - object_class, - PROP_MODEL, - g_param_spec_object ( - "model", - "Model", - NULL, - E_TYPE_TABLE_MODEL, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_HEADER, - g_param_spec_object ( - "header", - "Header", - NULL, - E_TYPE_TABLE_HEADER, - G_PARAM_READWRITE)); -} - -/** - * e_table_selection_model_new - * - * This routine creates a new #ETableSelectionModel. - * - * Returns: The new #ETableSelectionModel. - */ -ETableSelectionModel * -e_table_selection_model_new (void) -{ - return g_object_new (E_TYPE_TABLE_SELECTION_MODEL, NULL); -} - -static gint -etsm_get_row_count (ESelectionModelArray *esma) -{ - ETableSelectionModel *etsm = E_TABLE_SELECTION_MODEL (esma); - - if (etsm->model) - return e_table_model_row_count (etsm->model); - else - return 0; -} diff --git a/widgets/table/e-table-selection-model.h b/widgets/table/e-table-selection-model.h deleted file mode 100644 index 02309c047a..0000000000 --- a/widgets/table/e-table-selection-model.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_SELECTION_MODEL_H_ -#define _E_TABLE_SELECTION_MODEL_H_ - -#include <misc/e-selection-model-array.h> -#include <table/e-table-model.h> -#include <table/e-table-header.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_SELECTION_MODEL \ - (e_table_selection_model_get_type ()) -#define E_TABLE_SELECTION_MODEL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_SELECTION_MODEL, ETableSelectionModel)) -#define E_TABLE_SELECTION_MODEL_CLASS(cls) \ - (G_TYPE - CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_SELECTION_MODEL, ETableSelectionModelClass)) -#define E_IS_TABLE_SELECTION_MODEL(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_SELECTION_MODEL)) -#define E_IS_TABLE_SELECTION_MODEL_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_SELECTION_MODEL)) -#define E_TABLE_SELECTION_MODEL_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_SELECTION_MODEL, ETableSelectionModelClass)) - -G_BEGIN_DECLS - -typedef struct _ETableSelectionModel ETableSelectionModel; -typedef struct _ETableSelectionModelClass ETableSelectionModelClass; - -struct _ETableSelectionModel { - ESelectionModelArray parent; - - ETableModel *model; - ETableHeader *eth; - - guint model_pre_change_id; - guint model_changed_id; - guint model_row_changed_id; - guint model_cell_changed_id; - guint model_rows_inserted_id; - guint model_rows_deleted_id; - - guint model_changed_idle_id; - - guint selection_model_changed : 1; - guint group_info_changed : 1; - - GHashTable *hash; - gchar *cursor_id; -}; - -struct _ETableSelectionModelClass { - ESelectionModelArrayClass parent_class; -}; - -GType e_table_selection_model_get_type (void) G_GNUC_CONST; -ETableSelectionModel * - e_table_selection_model_new (void); - -G_END_DECLS - -#endif /* _E_TABLE_SELECTION_MODEL_H_ */ diff --git a/widgets/table/e-table-sort-info.c b/widgets/table/e-table-sort-info.c deleted file mode 100644 index 7ce56d7c75..0000000000 --- a/widgets/table/e-table-sort-info.c +++ /dev/null @@ -1,483 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include "e-util/e-util.h" -#include "libevolution-utils/e-xml-utils.h" - -#include "e-table-sort-info.h" - -#define ETM_CLASS(e) (E_TABLE_SORT_INFO_GET_CLASS (e)) - -G_DEFINE_TYPE (ETableSortInfo , e_table_sort_info, G_TYPE_OBJECT) - -enum { - SORT_INFO_CHANGED, - GROUP_INFO_CHANGED, - LAST_SIGNAL -}; - -static guint e_table_sort_info_signals[LAST_SIGNAL] = { 0, }; - -static void -etsi_finalize (GObject *object) -{ - ETableSortInfo *etsi = E_TABLE_SORT_INFO (object); - - if (etsi->groupings) - g_free (etsi->groupings); - etsi->groupings = NULL; - - if (etsi->sortings) - g_free (etsi->sortings); - etsi->sortings = NULL; - - G_OBJECT_CLASS (e_table_sort_info_parent_class)->finalize (object); -} - -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; - info->can_group = 1; -} - -static void -e_table_sort_info_class_init (ETableSortInfoClass *class) -{ - GObjectClass * object_class = G_OBJECT_CLASS (class); - - object_class->finalize = etsi_finalize; - - e_table_sort_info_signals[SORT_INFO_CHANGED] = g_signal_new ( - "sort_info_changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableSortInfoClass, sort_info_changed), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - e_table_sort_info_signals[GROUP_INFO_CHANGED] = g_signal_new ( - "group_info_changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableSortInfoClass, group_info_changed), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - class->sort_info_changed = NULL; - class->group_info_changed = NULL; -} - -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 { - g_signal_emit (info, e_table_sort_info_signals[SORT_INFO_CHANGED], 0); - } -} - -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 { - g_signal_emit (info, e_table_sort_info_signals[GROUP_INFO_CHANGED], 0); - } -} - -/** - * 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) -{ - if (info->can_group) - return info->group_count; - else - return 0; -} - -static void -e_table_sort_info_grouping_real_truncate (ETableSortInfo *info, - gint 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, - gint 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, - gint n) -{ - if (info->can_group && 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, - gint 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, - gint 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, - gint 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, - gint 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, - gint 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 g_object_new (E_TYPE_TABLE_SORT_INFO, NULL); -} - -/** - * 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) -{ - gint i; - xmlNode *grouping; - - if (state_version <= 0.05) { - i = 0; - for (grouping = node->xmlChildrenNode; grouping && !strcmp ((gchar *) grouping->name, "group"); grouping = grouping->xmlChildrenNode) { - ETableSortColumn column; - column.column = e_xml_get_integer_prop_by_name (grouping, (const guchar *)"column"); - column.ascending = e_xml_get_bool_prop_by_name (grouping, (const guchar *)"ascending"); - e_table_sort_info_grouping_set_nth (info, i++, column); - } - i = 0; - for (; grouping && !strcmp ((gchar *) grouping->name, "leaf"); grouping = grouping->xmlChildrenNode) { - ETableSortColumn column; - column.column = e_xml_get_integer_prop_by_name (grouping, (const guchar *)"column"); - column.ascending = e_xml_get_bool_prop_by_name (grouping, (const guchar *)"ascending"); - e_table_sort_info_sorting_set_nth (info, i++, column); - } - } else { - gint gcnt = 0; - gint scnt = 0; - for (grouping = node->children; grouping; grouping = grouping->next) { - ETableSortColumn column; - - if (grouping->type != XML_ELEMENT_NODE) - continue; - - if (!strcmp ((gchar *) grouping->name, "group")) { - column.column = e_xml_get_integer_prop_by_name (grouping, (const guchar *)"column"); - column.ascending = e_xml_get_bool_prop_by_name (grouping, (const guchar *)"ascending"); - e_table_sort_info_grouping_set_nth (info, gcnt++, column); - } else if (!strcmp ((gchar *) grouping->name, "leaf")) { - column.column = e_xml_get_integer_prop_by_name (grouping, (const guchar *)"column"); - column.ascending = e_xml_get_bool_prop_by_name (grouping, (const guchar *)"ascending"); - e_table_sort_info_sorting_set_nth (info, scnt++, column); - } - } - } - g_signal_emit (info, e_table_sort_info_signals[SORT_INFO_CHANGED], 0); -} - -/** - * 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; - gint i; - const gint sort_count = e_table_sort_info_sorting_get_count (info); - const gint group_count = e_table_sort_info_grouping_get_count (info); - - grouping = xmlNewChild (parent, NULL, (const guchar *)"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, (const guchar *)"group", NULL); - - e_xml_set_integer_prop_by_name (new_node, (const guchar *)"column", column.column); - e_xml_set_bool_prop_by_name (new_node, (const guchar *)"ascending", column.ascending); - } - - for (i = 0; i < sort_count; i++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth (info, i); - xmlNode *new_node = xmlNewChild (grouping, NULL, (const guchar *)"leaf", NULL); - - e_xml_set_integer_prop_by_name (new_node, (const guchar *)"column", column.column); - e_xml_set_bool_prop_by_name (new_node, (const guchar *)"ascending", column.ascending); - } - - 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); - - new_info->can_group = info->can_group; - - return new_info; -} - -void -e_table_sort_info_set_can_group (ETableSortInfo *info, - gboolean can_group) -{ - info->can_group = can_group; -} - -gboolean -e_table_sort_info_get_can_group (ETableSortInfo *info) -{ - return info->can_group; -} - diff --git a/widgets/table/e-table-sort-info.h b/widgets/table/e-table-sort-info.h deleted file mode 100644 index a577481150..0000000000 --- a/widgets/table/e-table-sort-info.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_SORT_INFO_H_ -#define _E_TABLE_SORT_INFO_H_ - -#include <glib-object.h> -#include <libxml/tree.h> - -#define E_TYPE_TABLE_SORT_INFO \ - (e_table_sort_info_get_type ()) -#define E_TABLE_SORT_INFO(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_SORT_INFO, ETableSortInfo)) -#define E_TABLE_SORT_INFO_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_SORT_INFO, ETableSortInfoClass)) -#define E_IS_TABLE_SORT_INFO(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_SORT_INFO)) -#define E_IS_TABLE_SORT_INFO_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_SORT_INFO)) -#define E_TABLE_SORT_INFO_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_SORT_INFO, ETableSortInfoClass)) - -G_BEGIN_DECLS - -typedef struct _ETableSortColumn ETableSortColumn; - -typedef struct _ETableSortInfo ETableSortInfo; -typedef struct _ETableSortInfoClass ETableSortInfoClass; - -struct _ETableSortColumn { - guint column : 31; - guint ascending : 1; -}; - -struct _ETableSortInfo { - GObject parent; - - gint group_count; - ETableSortColumn *groupings; - gint sort_count; - ETableSortColumn *sortings; - - guint frozen : 1; - guint sort_info_changed : 1; - guint group_info_changed : 1; - - guint can_group : 1; -}; - -struct _ETableSortInfoClass { - GObjectClass parent_class; - - /* Signals */ - void (*sort_info_changed) (ETableSortInfo *info); - void (*group_info_changed) (ETableSortInfo *info); -}; - -GType e_table_sort_info_get_type (void) G_GNUC_CONST; - -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, - gint length); -ETableSortColumn - e_table_sort_info_grouping_get_nth - (ETableSortInfo *info, - gint n); -void e_table_sort_info_grouping_set_nth - (ETableSortInfo *info, - gint n, - ETableSortColumn column); - -guint e_table_sort_info_sorting_get_count - (ETableSortInfo *info); -void e_table_sort_info_sorting_truncate - (ETableSortInfo *info, - gint length); -ETableSortColumn - e_table_sort_info_sorting_get_nth - (ETableSortInfo *info, - gint n); -void e_table_sort_info_sorting_set_nth - (ETableSortInfo *info, - gint 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); -void e_table_sort_info_set_can_group (ETableSortInfo *info, - gboolean can_group); -gboolean e_table_sort_info_get_can_group (ETableSortInfo *info); - -G_END_DECLS - -#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 73a92c35ef..0000000000 --- a/widgets/table/e-table-sorted-variable.c +++ /dev/null @@ -1,237 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <string.h> - -#include "e-util/e-util.h" - -#include "e-table-sorted-variable.h" -#include "e-table-sorting-utils.h" - -#define d(x) - -#define INCREMENT_AMOUNT 100 - -/* maximum insertions between an idle event that we will do without scheduling an idle sort */ -#define ETSV_INSERT_MAX (4) - -/* workaround for avoiding API breakage */ -#define etsv_get_type e_table_sorted_variable_get_type -G_DEFINE_TYPE (ETableSortedVariable, etsv, E_TYPE_TABLE_SUBSET_VARIABLE) - -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_dispose (GObject *object) -{ - ETableSortedVariable *etsv = E_TABLE_SORTED_VARIABLE (object); - - if (etsv->sort_info_changed_id) - g_signal_handler_disconnect ( - etsv->sort_info, - etsv->sort_info_changed_id); - etsv->sort_info_changed_id = 0; - - if (etsv->sort_idle_id) { - g_source_remove (etsv->sort_idle_id); - etsv->sort_idle_id = 0; - } - if (etsv->insert_idle_id) { - g_source_remove (etsv->insert_idle_id); - etsv->insert_idle_id = 0; - } - - if (etsv->sort_info) - g_object_unref (etsv->sort_info); - etsv->sort_info = NULL; - - if (etsv->full_header) - g_object_unref (etsv->full_header); - etsv->full_header = NULL; - - G_OBJECT_CLASS (etsv_parent_class)->dispose (object); -} - -static void -etsv_class_init (ETableSortedVariableClass *class) -{ - ETableSubsetVariableClass *etssv_class = E_TABLE_SUBSET_VARIABLE_CLASS (class); - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->dispose = etsv_dispose; - - 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->sort_info_changed_id = 0; - - etsv->sort_idle_id = 0; - etsv->insert_count = 0; -} - -static gboolean -etsv_sort_idle (ETableSortedVariable *etsv) -{ - g_object_ref (etsv); - etsv_sort (etsv); - etsv->sort_idle_id = 0; - etsv->insert_count = 0; - g_object_unref (etsv); - return FALSE; -} - -static gboolean -etsv_insert_idle (ETableSortedVariable *etsv) -{ - etsv->insert_count = 0; - etsv->insert_idle_id = 0; - return FALSE; -} - -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); - gint i; - - e_table_model_pre_change (etm); - - 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 (gint)); - } - 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 = e_table_sorting_utils_insert (etss->source, etsv->sort_info, etsv->full_header, etss->map_table, etss->n_map, row); - memmove (etss->map_table + i + 1, etss->map_table + i, (etss->n_map - i) * sizeof (gint)); - } - } - 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); - gint rows; - gint 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 (gint)); - } - 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 = g_object_new (E_TYPE_TABLE_SORTED_VARIABLE, NULL); - ETableSubsetVariable *etssv = E_TABLE_SUBSET_VARIABLE (etsv); - - if (e_table_subset_variable_construct (etssv, source) == NULL) { - g_object_unref (etsv); - return NULL; - } - - etsv->sort_info = sort_info; - g_object_ref (etsv->sort_info); - etsv->full_header = full_header; - g_object_ref (etsv->full_header); - - etsv->sort_info_changed_id = g_signal_connect ( - sort_info, "sort_info_changed", - G_CALLBACK (etsv_sort_info_changed), etsv); - - return E_TABLE_MODEL (etsv); -} - -static void -etsv_sort_info_changed (ETableSortInfo *info, - ETableSortedVariable *etsv) -{ - etsv_sort (etsv); -} - -static void -etsv_sort (ETableSortedVariable *etsv) -{ - ETableSubset *etss = E_TABLE_SUBSET (etsv); - static gint reentering = 0; - if (reentering) - return; - reentering = 1; - - e_table_model_pre_change (E_TABLE_MODEL (etsv)); - - e_table_sorting_utils_sort (etss->source, etsv->sort_info, etsv->full_header, etss->map_table, etss->n_map); - - 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 917338ae4d..0000000000 --- a/widgets/table/e-table-sorted-variable.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_SORTED_VARIABLE_H_ -#define _E_TABLE_SORTED_VARIABLE_H_ - -#include <table/e-table-model.h> -#include <table/e-table-subset-variable.h> -#include <table/e-table-sort-info.h> -#include <table/e-table-header.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_SORTED_VARIABLE \ - (e_table_sorted_variable_get_type ()) -#define E_TABLE_SORTED_VARIABLE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_SORTED_VARIABLE, ETableSortedVariable)) -#define E_TABLE_SORTED_VARIABLE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_SORTED_VARIABLE, ETableSortedVariableClass)) -#define E_IS_TABLE_SORTED_VARIABLE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_SORTED_VARIABLE)) -#define E_IS_TABLE_SORTED_VARIABLE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_SORTED_VARIABLE)) -#define E_TABLE_SORTED_VARIABLE_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_SORTED_VARIABLE, ETableSortedVariableClass)) - -G_BEGIN_DECLS - -typedef struct _ETableSortedVariable ETableSortedVariable; -typedef struct _ETableSortedVariableClass ETableSortedVariableClass; - -struct _ETableSortedVariable { - ETableSubsetVariable parent; - - ETableSortInfo *sort_info; - - ETableHeader *full_header; - - gint sort_info_changed_id; - gint sort_idle_id; - gint insert_idle_id; - gint insert_count; -}; - -struct _ETableSortedVariableClass { - ETableSubsetVariableClass parent_class; -}; - -GType e_table_sorted_variable_get_type - (void) G_GNUC_CONST; -ETableModel * e_table_sorted_variable_new (ETableModel *etm, - ETableHeader *header, - ETableSortInfo *sort_info); - -G_END_DECLS - -#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 31f0fa60b4..0000000000 --- a/widgets/table/e-table-sorted.c +++ /dev/null @@ -1,330 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <string.h> - -#include "e-util/e-util.h" - -#include "e-table-sorted.h" -#include "e-table-sorting-utils.h" - -#define d(x) - -#define INCREMENT_AMOUNT 100 - -/* workaround for avoding API breakage */ -#define ets_get_type e_table_sorted_get_type -G_DEFINE_TYPE (ETableSorted, ets, E_TYPE_TABLE_SUBSET) - -/* maximum insertions between an idle event that we will do without scheduling an idle sort */ -#define ETS_INSERT_MAX (4) - -static void ets_sort_info_changed (ETableSortInfo *info, ETableSorted *ets); -static void ets_sort (ETableSorted *ets); -static void ets_proxy_model_changed (ETableSubset *etss, ETableModel *source); -static void ets_proxy_model_row_changed (ETableSubset *etss, ETableModel *source, gint row); -static void ets_proxy_model_cell_changed (ETableSubset *etss, ETableModel *source, gint col, gint row); -static void ets_proxy_model_rows_inserted (ETableSubset *etss, ETableModel *source, gint row, gint count); -static void ets_proxy_model_rows_deleted (ETableSubset *etss, ETableModel *source, gint row, gint count); - -static void -ets_dispose (GObject *object) -{ - ETableSorted *ets = E_TABLE_SORTED (object); - - if (ets->sort_idle_id) - g_source_remove (ets->sort_idle_id); - ets->sort_idle_id = 0; - - if (ets->insert_idle_id) - g_source_remove (ets->insert_idle_id); - ets->insert_idle_id = 0; - - if (ets->sort_info) { - g_signal_handler_disconnect ( - ets->sort_info, - ets->sort_info_changed_id); - g_object_unref (ets->sort_info); - ets->sort_info = NULL; - } - - if (ets->full_header) - g_object_unref (ets->full_header); - ets->full_header = NULL; - - G_OBJECT_CLASS (ets_parent_class)->dispose (object); -} - -static void -ets_class_init (ETableSortedClass *class) -{ - ETableSubsetClass *etss_class = E_TABLE_SUBSET_CLASS (class); - GObjectClass *object_class = G_OBJECT_CLASS (class); - - etss_class->proxy_model_changed = ets_proxy_model_changed; - etss_class->proxy_model_row_changed = ets_proxy_model_row_changed; - etss_class->proxy_model_cell_changed = ets_proxy_model_cell_changed; - etss_class->proxy_model_rows_inserted = ets_proxy_model_rows_inserted; - etss_class->proxy_model_rows_deleted = ets_proxy_model_rows_deleted; - - object_class->dispose = ets_dispose; -} - -static void -ets_init (ETableSorted *ets) -{ - ets->full_header = NULL; - ets->sort_info = NULL; - - ets->sort_info_changed_id = 0; - - ets->sort_idle_id = 0; - ets->insert_count = 0; -} - -static gboolean -ets_sort_idle (ETableSorted *ets) -{ - g_object_ref (ets); - ets_sort (ets); - ets->sort_idle_id = 0; - ets->insert_count = 0; - g_object_unref (ets); - return FALSE; -} - -static gboolean -ets_insert_idle (ETableSorted *ets) -{ - ets->insert_count = 0; - ets->insert_idle_id = 0; - return FALSE; -} - -ETableModel * -e_table_sorted_new (ETableModel *source, - ETableHeader *full_header, - ETableSortInfo *sort_info) -{ - ETableSorted *ets = g_object_new (E_TYPE_TABLE_SORTED, NULL); - ETableSubset *etss = E_TABLE_SUBSET (ets); - - if (E_TABLE_SUBSET_CLASS (ets_parent_class)->proxy_model_pre_change) - (E_TABLE_SUBSET_CLASS (ets_parent_class)->proxy_model_pre_change) (etss, source); - - if (e_table_subset_construct (etss, source, 0) == NULL) { - g_object_unref (ets); - return NULL; - } - - ets->sort_info = sort_info; - g_object_ref (ets->sort_info); - ets->full_header = full_header; - g_object_ref (ets->full_header); - - ets_proxy_model_changed (etss, source); - - ets->sort_info_changed_id = g_signal_connect ( - sort_info, "sort_info_changed", - G_CALLBACK (ets_sort_info_changed), ets); - - return E_TABLE_MODEL (ets); -} - -static void -ets_sort_info_changed (ETableSortInfo *info, - ETableSorted *ets) -{ - ets_sort (ets); -} - -static void -ets_proxy_model_changed (ETableSubset *subset, - ETableModel *source) -{ - gint rows, i; - - rows = e_table_model_row_count (source); - - g_free (subset->map_table); - subset->n_map = rows; - subset->map_table = g_new (int, rows); - - for (i = 0; i < rows; i++) { - subset->map_table[i] = i; - } - - if (!E_TABLE_SORTED (subset)->sort_idle_id) - E_TABLE_SORTED (subset)->sort_idle_id = g_idle_add_full (50, (GSourceFunc) ets_sort_idle, subset, NULL); - - e_table_model_changed (E_TABLE_MODEL (subset)); -} - -static void -ets_proxy_model_row_changed (ETableSubset *subset, - ETableModel *source, - gint row) -{ - if (!E_TABLE_SORTED (subset)->sort_idle_id) - E_TABLE_SORTED (subset)->sort_idle_id = g_idle_add_full (50, (GSourceFunc) ets_sort_idle, subset, NULL); - - if (E_TABLE_SUBSET_CLASS (ets_parent_class)->proxy_model_row_changed) - (E_TABLE_SUBSET_CLASS (ets_parent_class)->proxy_model_row_changed) (subset, source, row); -} - -static void -ets_proxy_model_cell_changed (ETableSubset *subset, - ETableModel *source, - gint col, - gint row) -{ - ETableSorted *ets = E_TABLE_SORTED (subset); - if (e_table_sorting_utils_affects_sort (ets->sort_info, ets->full_header, col)) - ets_proxy_model_row_changed (subset, source, row); - else if (E_TABLE_SUBSET_CLASS (ets_parent_class)->proxy_model_cell_changed) - (E_TABLE_SUBSET_CLASS (ets_parent_class)->proxy_model_cell_changed) (subset, source, col, row); -} - -static void -ets_proxy_model_rows_inserted (ETableSubset *etss, - ETableModel *source, - gint row, - gint count) -{ - ETableModel *etm = E_TABLE_MODEL (etss); - ETableSorted *ets = E_TABLE_SORTED (etss); - gint i; - gboolean full_change = FALSE; - - if (count == 0) { - e_table_model_no_change (etm); - return; - } - - if (row != etss->n_map) { - full_change = TRUE; - for (i = 0; i < etss->n_map; i++) { - if (etss->map_table[i] >= row) { - etss->map_table[i] += count; - } - } - } - - etss->map_table = g_realloc (etss->map_table, (etss->n_map + count) * sizeof (gint)); - - for (; count > 0; count--) { - if (!full_change) - e_table_model_pre_change (etm); - i = etss->n_map; - if (ets->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 */ - ets->insert_count++; - if (ets->insert_count > ETS_INSERT_MAX) { - /* schedule a sort, and append instead */ - ets->sort_idle_id = g_idle_add_full (50, (GSourceFunc) ets_sort_idle, ets, NULL); - } else { - /* make sure we have an idle handler to reset the count every now and then */ - if (ets->insert_idle_id == 0) { - ets->insert_idle_id = g_idle_add_full (40, (GSourceFunc) ets_insert_idle, ets, NULL); - } - i = e_table_sorting_utils_insert (etss->source, ets->sort_info, ets->full_header, etss->map_table, etss->n_map, row); - memmove (etss->map_table + i + 1, etss->map_table + i, (etss->n_map - i) * sizeof (gint)); - } - } - etss->map_table[i] = row; - etss->n_map++; - if (!full_change) { - e_table_model_row_inserted (etm, i); - } - - d (g_print ("inserted row %d", row)); - row++; - } - if (full_change) - e_table_model_changed (etm); - else - e_table_model_no_change (etm); - d (e_table_subset_print_debugging (etss)); -} - -static void -ets_proxy_model_rows_deleted (ETableSubset *etss, - ETableModel *source, - gint row, - gint count) -{ - ETableModel *etm = E_TABLE_MODEL (etss); - gint i; - gboolean shift; - gint j; - - shift = row == etss->n_map - count; - - for (j = 0; j < count; j++) { - for (i = 0; i < etss->n_map; i++) { - if (etss->map_table[i] == row + j) { - if (shift) - e_table_model_pre_change (etm); - memmove (etss->map_table + i, etss->map_table + i + 1, (etss->n_map - i - 1) * sizeof (gint)); - etss->n_map--; - if (shift) - e_table_model_row_deleted (etm, i); - } - } - } - if (!shift) { - for (i = 0; i < etss->n_map; i++) { - if (etss->map_table[i] >= row) - etss->map_table[i] -= count; - } - - e_table_model_changed (etm); - } else { - e_table_model_no_change (etm); - } - - d (g_print ("deleted row %d count %d", row, count)); - d (e_table_subset_print_debugging (etss)); -} - -static void -ets_sort (ETableSorted *ets) -{ - ETableSubset *etss = E_TABLE_SUBSET (ets); - static gint reentering = 0; - if (reentering) - return; - reentering = 1; - - e_table_model_pre_change (E_TABLE_MODEL (ets)); - - e_table_sorting_utils_sort (etss->source, ets->sort_info, ets->full_header, etss->map_table, etss->n_map); - - e_table_model_changed (E_TABLE_MODEL (ets)); - reentering = 0; -} diff --git a/widgets/table/e-table-sorted.h b/widgets/table/e-table-sorted.h deleted file mode 100644 index feff6e2ad5..0000000000 --- a/widgets/table/e-table-sorted.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_SORTED_H_ -#define _E_TABLE_SORTED_H_ - -#include <table/e-table-model.h> -#include <table/e-table-subset.h> -#include <table/e-table-sort-info.h> -#include <table/e-table-header.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_SORTED \ - (e_table_sorted_get_type ()) -#define E_TABLE_SORTED(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_SORTED, ETableSorted)) -#define E_TABLE_SORTED_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_SORTED, ETableSortedClass)) -#define E_IS_TABLE_SORTED(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_SORTED)) -#define E_IS_TABLE_SORTED_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_SORTED)) -#define E_TABLE_SORTED_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_SORTED, ETableSortedClass)) - -G_BEGIN_DECLS - -typedef struct _ETableSorted ETableSorted; -typedef struct _ETableSortedClass ETableSortedClass; - -struct _ETableSorted { - ETableSubset parent; - - ETableSortInfo *sort_info; - - ETableHeader *full_header; - - gint sort_info_changed_id; - gint sort_idle_id; - gint insert_idle_id; - gint insert_count; -}; - -struct _ETableSortedClass { - ETableSubsetClass parent_class; -}; - -GType e_table_sorted_get_type (void) G_GNUC_CONST; -ETableModel * e_table_sorted_new (ETableModel *etm, - ETableHeader *header, - ETableSortInfo *sort_info); - -G_END_DECLS - -#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 2815d13b1b..0000000000 --- a/widgets/table/e-table-sorter.c +++ /dev/null @@ -1,520 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <string.h> - -#include <glib/gi18n.h> -#include "e-util/e-util.h" - -#include "e-table-sorter.h" -#include "e-table-sorting-utils.h" - -#define d(x) - -enum { - PROP_0, - PROP_SORT_INFO -}; - -/* workaround for avoiding API breakage */ -#define ets_get_type e_table_sorter_get_type -G_DEFINE_TYPE (ETableSorter, ets, E_SORTER_TYPE) - -#define INCREMENT_AMOUNT 100 - -static void ets_model_changed (ETableModel *etm, ETableSorter *ets); -static void ets_model_row_changed (ETableModel *etm, gint row, ETableSorter *ets); -static void ets_model_cell_changed (ETableModel *etm, gint col, gint row, ETableSorter *ets); -static void ets_model_rows_inserted (ETableModel *etm, gint row, gint count, ETableSorter *ets); -static void ets_model_rows_deleted (ETableModel *etm, gint row, gint count, 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 gint ets_model_to_sorted (ESorter *sorter, gint row); -static gint ets_sorted_to_model (ESorter *sorter, gint row); -static void ets_get_model_to_sorted_array (ESorter *sorter, gint **array, gint *count); -static void ets_get_sorted_to_model_array (ESorter *sorter, gint **array, gint *count); -static gboolean ets_needs_sorting (ESorter *ets); - -static void -ets_dispose (GObject *object) -{ - ETableSorter *ets = E_TABLE_SORTER (object); - - if (ets->sort_info) { - if (ets->table_model_changed_id) - g_signal_handler_disconnect ( - ets->source, - ets->table_model_changed_id); - if (ets->table_model_row_changed_id) - g_signal_handler_disconnect ( - ets->source, - ets->table_model_row_changed_id); - if (ets->table_model_cell_changed_id) - g_signal_handler_disconnect ( - ets->source, - ets->table_model_cell_changed_id); - if (ets->table_model_rows_inserted_id) - g_signal_handler_disconnect ( - ets->source, - ets->table_model_rows_inserted_id); - if (ets->table_model_rows_deleted_id) - g_signal_handler_disconnect ( - ets->source, - ets->table_model_rows_deleted_id); - if (ets->sort_info_changed_id) - g_signal_handler_disconnect ( - ets->sort_info, - ets->sort_info_changed_id); - if (ets->group_info_changed_id) - g_signal_handler_disconnect ( - ets->sort_info, - ets->group_info_changed_id); - - ets->table_model_changed_id = 0; - ets->table_model_row_changed_id = 0; - ets->table_model_cell_changed_id = 0; - ets->table_model_rows_inserted_id = 0; - ets->table_model_rows_deleted_id = 0; - ets->sort_info_changed_id = 0; - ets->group_info_changed_id = 0; - - g_object_unref (ets->sort_info); - ets->sort_info = NULL; - } - - if (ets->full_header) - g_object_unref (ets->full_header); - ets->full_header = NULL; - - if (ets->source) - g_object_unref (ets->source); - ets->source = NULL; - - G_OBJECT_CLASS (ets_parent_class)->dispose (object); -} - -static void -ets_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ETableSorter *ets = E_TABLE_SORTER (object); - - switch (property_id) { - case PROP_SORT_INFO: - if (ets->sort_info) { - if (ets->sort_info_changed_id) - g_signal_handler_disconnect (ets->sort_info, ets->sort_info_changed_id); - if (ets->group_info_changed_id) - g_signal_handler_disconnect (ets->sort_info, ets->group_info_changed_id); - g_object_unref (ets->sort_info); - } - - ets->sort_info = E_TABLE_SORT_INFO (g_value_get_object (value)); - g_object_ref (ets->sort_info); - ets->sort_info_changed_id = g_signal_connect ( - ets->sort_info, "sort_info_changed", - G_CALLBACK (ets_sort_info_changed), ets); - ets->group_info_changed_id = g_signal_connect ( - ets->sort_info, "group_info_changed", - G_CALLBACK (ets_sort_info_changed), ets); - - ets_clean (ets); - break; - default: - break; - } -} - -static void -ets_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ETableSorter *ets = E_TABLE_SORTER (object); - switch (property_id) { - case PROP_SORT_INFO: - g_value_set_object (value, ets->sort_info); - break; - } -} - -static void -ets_class_init (ETableSorterClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - ESorterClass *sorter_class = E_SORTER_CLASS (class); - - object_class->dispose = ets_dispose; - object_class->set_property = ets_set_property; - object_class->get_property = ets_get_property; - - sorter_class->model_to_sorted = ets_model_to_sorted; - sorter_class->sorted_to_model = ets_sorted_to_model; - sorter_class->get_model_to_sorted_array = ets_get_model_to_sorted_array; - sorter_class->get_sorted_to_model_array = ets_get_sorted_to_model_array; - sorter_class->needs_sorting = ets_needs_sorting; - - g_object_class_install_property ( - object_class, - PROP_SORT_INFO, - g_param_spec_object ( - "sort_info", - "Sort Info", - NULL, - E_TYPE_TABLE_SORT_INFO, - G_PARAM_READWRITE)); -} - -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->table_model_rows_inserted_id = 0; - ets->table_model_rows_deleted_id = 0; - ets->sort_info_changed_id = 0; - ets->group_info_changed_id = 0; -} - -ETableSorter * -e_table_sorter_new (ETableModel *source, - ETableHeader *full_header, - ETableSortInfo *sort_info) -{ - ETableSorter *ets = g_object_new (E_TYPE_TABLE_SORTER, NULL); - - ets->sort_info = sort_info; - g_object_ref (ets->sort_info); - ets->full_header = full_header; - g_object_ref (ets->full_header); - ets->source = source; - g_object_ref (ets->source); - - ets->table_model_changed_id = g_signal_connect ( - source, "model_changed", - G_CALLBACK (ets_model_changed), ets); - - ets->table_model_row_changed_id = g_signal_connect ( - source, "model_row_changed", - G_CALLBACK (ets_model_row_changed), ets); - - ets->table_model_cell_changed_id = g_signal_connect ( - source, "model_cell_changed", - G_CALLBACK (ets_model_cell_changed), ets); - - ets->table_model_rows_inserted_id = g_signal_connect ( - source, "model_rows_inserted", - G_CALLBACK (ets_model_rows_inserted), ets); - - ets->table_model_rows_deleted_id = g_signal_connect ( - source, "model_rows_deleted", - G_CALLBACK (ets_model_rows_deleted), ets); - - ets->sort_info_changed_id = g_signal_connect ( - sort_info, "sort_info_changed", - G_CALLBACK (ets_sort_info_changed), ets); - - ets->group_info_changed_id = g_signal_connect ( - sort_info, "group_info_changed", - G_CALLBACK (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, - gint row, - ETableSorter *ets) -{ - ets_clean (ets); -} - -static void -ets_model_cell_changed (ETableModel *etm, - gint col, - gint row, - ETableSorter *ets) -{ - ets_clean (ets); -} - -static void -ets_model_rows_inserted (ETableModel *etm, - gint row, - gint count, - ETableSorter *ets) -{ - ets_clean (ets); -} - -static void -ets_model_rows_deleted (ETableModel *etm, - gint row, - gint count, - ETableSorter *ets) -{ - ets_clean (ets); -} - -static void -ets_sort_info_changed (ETableSortInfo *info, - ETableSorter *ets) -{ - d (g_print ("sort info changed\n")); - ets_clean (ets); -} - -struct qsort_data { - ETableSorter *ets; - gpointer *vals; - gint cols; - gint *ascending; - GCompareDataFunc *compare; - gpointer cmp_cache; -}; - -/* FIXME: Make it not cache the second and later columns (as if anyone cares.) */ - -static gint -qsort_callback (gconstpointer data1, - gconstpointer data2, - gpointer user_data) -{ - struct qsort_data *qd = (struct qsort_data *) user_data; - gint row1 = *(gint *) data1; - gint row2 = *(gint *) data2; - gint j; - gint sort_count = e_table_sort_info_sorting_get_count (qd->ets->sort_info) + e_table_sort_info_grouping_get_count (qd->ets->sort_info); - gint comp_val = 0; - gint ascending = 1; - for (j = 0; j < sort_count; j++) { - comp_val = (*(qd->compare[j]))(qd->vals[qd->cols * row1 + j], qd->vals[qd->cols * row2 + j], qd->cmp_cache); - ascending = qd->ascending[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; -} - -static void -ets_sort (ETableSorter *ets) -{ - gint rows; - gint i; - gint j; - gint cols; - gint group_cols; - struct qsort_data qd; - - 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; - - qd.cols = cols; - qd.ets = ets; - - qd.vals = g_new (gpointer , rows * cols); - qd.ascending = g_new (int, cols); - qd.compare = g_new (GCompareDataFunc, cols); - qd.cmp_cache = e_table_sorting_utils_create_cmp_cache (); - - 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++) { - qd.vals[i * cols + j] = e_table_model_value_at (ets->source, col->col_idx, i); - } - - qd.compare[j] = col->compare; - qd.ascending[j] = column.ascending; - } - - g_qsort_with_data (ets->sorted, rows, sizeof (gint), qsort_callback, &qd); - - g_free (qd.vals); - g_free (qd.ascending); - g_free (qd.compare); - e_table_sorting_utils_free_cmp_cache (qd.cmp_cache); -} - -static void -ets_backsort (ETableSorter *ets) -{ - gint 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; - } -} - -static gint -ets_model_to_sorted (ESorter *es, - gint row) -{ - ETableSorter *ets = E_TABLE_SORTER (es); - gint rows = e_table_model_row_count (ets->source); - - g_return_val_if_fail (row >= 0, -1); - g_return_val_if_fail (row < rows, -1); - - if (ets_needs_sorting (es)) - ets_backsort (ets); - - if (ets->backsorted) - return ets->backsorted[row]; - else - return row; -} - -static gint -ets_sorted_to_model (ESorter *es, - gint row) -{ - ETableSorter *ets = E_TABLE_SORTER (es); - gint rows = e_table_model_row_count (ets->source); - - g_return_val_if_fail (row >= 0, -1); - g_return_val_if_fail (row < rows, -1); - - if (ets_needs_sorting (es)) - ets_sort (ets); - - if (ets->sorted) - return ets->sorted[row]; - else - return row; -} - -static void -ets_get_model_to_sorted_array (ESorter *es, - gint **array, - gint *count) -{ - ETableSorter *ets = E_TABLE_SORTER (es); - if (array || count) { - ets_backsort (ets); - - if (array) - *array = ets->backsorted; - if (count) - *count = e_table_model_row_count(ets->source); - } -} - -static void -ets_get_sorted_to_model_array (ESorter *es, - gint **array, - gint *count) -{ - ETableSorter *ets = E_TABLE_SORTER (es); - if (array || count) { - ets_sort (ets); - - if (array) - *array = ets->sorted; - if (count) - *count = e_table_model_row_count(ets->source); - } -} - -static gboolean -ets_needs_sorting (ESorter *es) -{ - ETableSorter *ets = E_TABLE_SORTER (es); - 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; -} diff --git a/widgets/table/e-table-sorter.h b/widgets/table/e-table-sorter.h deleted file mode 100644 index 0f36f441f6..0000000000 --- a/widgets/table/e-table-sorter.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_SORTER_H_ -#define _E_TABLE_SORTER_H_ - -#include <e-util/e-sorter.h> -#include <table/e-table-model.h> -#include <table/e-table-subset-variable.h> -#include <table/e-table-sort-info.h> -#include <table/e-table-header.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_SORTER \ - (e_table_sorter_get_type ()) -#define E_TABLE_SORTER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_SORTER, ETableSorter)) -#define E_TABLE_SORTER_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_SORTER, ETableSorterClass)) -#define E_IS_TABLE_SORTER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_SORTER)) -#define E_IS_TABLE_SORTER_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_SORTER)) -#define E_TABLE_SORTER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_SORTER, ETableSorterClass)) - -G_BEGIN_DECLS - -typedef struct _ETableSorter ETableSorter; -typedef struct _ETableSorterClass ETableSorterClass; - -struct _ETableSorter { - ESorter parent; - - ETableModel *source; - ETableHeader *full_header; - ETableSortInfo *sort_info; - - /* If needs_sorting is 0, then model_to_sorted - * and sorted_to_model are no-ops. */ - gint needs_sorting; - - gint *sorted; - gint *backsorted; - - gint table_model_changed_id; - gint table_model_row_changed_id; - gint table_model_cell_changed_id; - gint table_model_rows_inserted_id; - gint table_model_rows_deleted_id; - gint sort_info_changed_id; - gint group_info_changed_id; -}; - -struct _ETableSorterClass { - ESorterClass parent_class; -}; - -GType e_table_sorter_get_type (void) G_GNUC_CONST; -ETableSorter * e_table_sorter_new (ETableModel *etm, - ETableHeader *full_header, - ETableSortInfo *sort_info); - -G_END_DECLS - -#endif /* _E_TABLE_SORTER_H_ */ diff --git a/widgets/table/e-table-sorting-utils.c b/widgets/table/e-table-sorting-utils.c deleted file mode 100644 index a94c45f7b0..0000000000 --- a/widgets/table/e-table-sorting-utils.c +++ /dev/null @@ -1,492 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> -#include <camel/camel.h> - -#include "e-util/e-util.h" - -#include "e-table-sorting-utils.h" - -#define d(x) - -/* This takes source rows. */ -static gint -etsu_compare (ETableModel *source, - ETableSortInfo *sort_info, - ETableHeader *full_header, - gint row1, - gint row2, - gpointer cmp_cache) -{ - gint j; - gint sort_count = e_table_sort_info_sorting_get_count (sort_info); - gint comp_val = 0; - gint ascending = 1; - - for (j = 0; j < sort_count; j++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth (sort_info, j); - ETableCol *col; - 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); - comp_val = (*col->compare)(e_table_model_value_at (source, col->compare_col, row1), - e_table_model_value_at (source, col->compare_col, row2), - cmp_cache); - 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; -} - -typedef struct { - gint cols; - gpointer *vals; - gint *ascending; - GCompareDataFunc *compare; - gpointer cmp_cache; -} ETableSortClosure; - -typedef struct { - ETreeModel *tree; - ETableSortInfo *sort_info; - ETableHeader *full_header; - gpointer cmp_cache; -} ETreeSortClosure; - -/* FIXME: Make it not cache the second and later columns (as if anyone cares.) */ - -static gint -e_sort_callback (gconstpointer data1, - gconstpointer data2, - gpointer user_data) -{ - gint row1 = *(gint *) data1; - gint row2 = *(gint *) data2; - ETableSortClosure *closure = user_data; - gint j; - gint sort_count = closure->cols; - gint comp_val = 0; - gint ascending = 1; - for (j = 0; j < sort_count; j++) { - comp_val = (*(closure->compare[j]))(closure->vals[closure->cols * row1 + j], closure->vals[closure->cols * row2 + j], closure->cmp_cache); - ascending = closure->ascending[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; -} - -void -e_table_sorting_utils_sort (ETableModel *source, - ETableSortInfo *sort_info, - ETableHeader *full_header, - gint *map_table, - gint rows) -{ - gint total_rows; - gint i; - gint j; - gint cols; - ETableSortClosure closure; - - g_return_if_fail (source != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (source)); - g_return_if_fail (sort_info != NULL); - g_return_if_fail (E_IS_TABLE_SORT_INFO (sort_info)); - g_return_if_fail (full_header != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (full_header)); - - total_rows = e_table_model_row_count (source); - cols = e_table_sort_info_sorting_get_count (sort_info); - closure.cols = cols; - - closure.vals = g_new (gpointer , total_rows * cols); - closure.ascending = g_new (int, cols); - closure.compare = g_new (GCompareDataFunc, cols); - closure.cmp_cache = e_table_sorting_utils_create_cmp_cache (); - - for (j = 0; j < cols; j++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth (sort_info, j); - ETableCol *col; - 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); - for (i = 0; i < rows; i++) { - closure.vals[map_table[i] * cols + j] = e_table_model_value_at (source, col->compare_col, map_table[i]); - } - closure.compare[j] = col->compare; - closure.ascending[j] = column.ascending; - } - - g_qsort_with_data ( - map_table, rows, sizeof (gint), e_sort_callback, &closure); - - g_free (closure.vals); - g_free (closure.ascending); - g_free (closure.compare); - e_table_sorting_utils_free_cmp_cache (closure.cmp_cache); -} - -gboolean -e_table_sorting_utils_affects_sort (ETableSortInfo *sort_info, - ETableHeader *full_header, - gint col) -{ - gint j; - gint cols; - - g_return_val_if_fail (sort_info != NULL, TRUE); - g_return_val_if_fail (E_IS_TABLE_SORT_INFO (sort_info), TRUE); - g_return_val_if_fail (full_header != NULL, TRUE); - g_return_val_if_fail (E_IS_TABLE_HEADER (full_header), TRUE); - - cols = e_table_sort_info_sorting_get_count (sort_info); - - for (j = 0; j < cols; j++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth (sort_info, j); - ETableCol *tablecol; - tablecol = e_table_header_get_column_by_col_idx (full_header, column.column); - if (tablecol == NULL) - tablecol = e_table_header_get_column (full_header, e_table_header_count (full_header) - 1); - if (col == tablecol->compare_col) - return TRUE; - } - return FALSE; -} - -/* FIXME: This could be done in time log n instead of time n with a binary search. */ -gint -e_table_sorting_utils_insert (ETableModel *source, - ETableSortInfo *sort_info, - ETableHeader *full_header, - gint *map_table, - gint rows, - gint row) -{ - gint i; - gpointer cmp_cache = e_table_sorting_utils_create_cmp_cache (); - - i = 0; - /* handle insertions when we have a 'sort group' */ - while (i < rows && etsu_compare (source, sort_info, full_header, map_table[i], row, cmp_cache) < 0) - i++; - - e_table_sorting_utils_free_cmp_cache (cmp_cache); - - return i; -} - -/* FIXME: This could be done in time log n instead of time n with a binary search. */ -gint -e_table_sorting_utils_check_position (ETableModel *source, - ETableSortInfo *sort_info, - ETableHeader *full_header, - gint *map_table, - gint rows, - gint view_row) -{ - gint i; - gint row; - gpointer cmp_cache; - - i = view_row; - row = map_table[i]; - cmp_cache = e_table_sorting_utils_create_cmp_cache (); - - i = view_row; - if (i < rows - 1 && etsu_compare (source, sort_info, full_header, map_table[i + 1], row, cmp_cache) < 0) { - i++; - while (i < rows - 1 && etsu_compare (source, sort_info, full_header, map_table[i], row, cmp_cache) < 0) - i++; - } else if (i > 0 && etsu_compare (source, sort_info, full_header, map_table[i - 1], row, cmp_cache) > 0) { - i--; - while (i > 0 && etsu_compare (source, sort_info, full_header, map_table[i], row, cmp_cache) > 0) - i--; - } - - e_table_sorting_utils_free_cmp_cache (cmp_cache); - - return i; -} - -/* This takes source rows. */ -static gint -etsu_tree_compare (ETreeModel *source, - ETableSortInfo *sort_info, - ETableHeader *full_header, - ETreePath path1, - ETreePath path2, - gpointer cmp_cache) -{ - gint j; - gint sort_count = e_table_sort_info_sorting_get_count (sort_info); - gint comp_val = 0; - gint ascending = 1; - - for (j = 0; j < sort_count; j++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth (sort_info, j); - ETableCol *col; - 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); - comp_val = (*col->compare)(e_tree_model_value_at (source, path1, col->compare_col), - e_tree_model_value_at (source, path2, col->compare_col), - cmp_cache); - ascending = column.ascending; - if (comp_val != 0) - break; - } - if (!ascending) - comp_val = -comp_val; - return comp_val; -} - -static gint -e_sort_tree_callback (gconstpointer data1, - gconstpointer data2, - gpointer user_data) -{ - ETreePath *path1 = *(ETreePath *) data1; - ETreePath *path2 = *(ETreePath *) data2; - ETreeSortClosure *closure = user_data; - - return etsu_tree_compare (closure->tree, closure->sort_info, closure->full_header, path1, path2, closure->cmp_cache); -} - -void -e_table_sorting_utils_tree_sort (ETreeModel *source, - ETableSortInfo *sort_info, - ETableHeader *full_header, - ETreePath *map_table, - gint count) -{ - ETableSortClosure closure; - gint cols; - gint i, j; - gint *map; - ETreePath *map_copy; - g_return_if_fail (source != NULL); - g_return_if_fail (E_IS_TREE_MODEL (source)); - g_return_if_fail (sort_info != NULL); - g_return_if_fail (E_IS_TABLE_SORT_INFO (sort_info)); - g_return_if_fail (full_header != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (full_header)); - - cols = e_table_sort_info_sorting_get_count (sort_info); - closure.cols = cols; - - closure.vals = g_new (gpointer , count * cols); - closure.ascending = g_new (int, cols); - closure.compare = g_new (GCompareDataFunc, cols); - closure.cmp_cache = e_table_sorting_utils_create_cmp_cache (); - - for (j = 0; j < cols; j++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth (sort_info, j); - ETableCol *col; - - 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); - - for (i = 0; i < count; i++) { - closure.vals[i * cols + j] = e_tree_model_sort_value_at (source, map_table[i], col->compare_col); - } - closure.ascending[j] = column.ascending; - closure.compare[j] = col->compare; - } - - map = g_new (int, count); - for (i = 0; i < count; i++) { - map[i] = i; - } - - g_qsort_with_data ( - map, count, sizeof (gint), e_sort_callback, &closure); - - map_copy = g_new (ETreePath, count); - for (i = 0; i < count; i++) { - map_copy[i] = map_table[i]; - } - for (i = 0; i < count; i++) { - map_table[i] = map_copy[map[i]]; - } - - g_free (map); - g_free (map_copy); - - g_free (closure.vals); - g_free (closure.ascending); - g_free (closure.compare); - e_table_sorting_utils_free_cmp_cache (closure.cmp_cache); -} - -/* FIXME: This could be done in time log n instead of time n with a binary search. */ -gint -e_table_sorting_utils_tree_check_position (ETreeModel *source, - ETableSortInfo *sort_info, - ETableHeader *full_header, - ETreePath *map_table, - gint count, - gint old_index) -{ - gint i; - ETreePath path; - gpointer cmp_cache = e_table_sorting_utils_create_cmp_cache (); - - i = old_index; - path = map_table[i]; - - if (i < count - 1 && etsu_tree_compare (source, sort_info, full_header, map_table[i + 1], path, cmp_cache) < 0) { - i++; - while (i < count - 1 && etsu_tree_compare (source, sort_info, full_header, map_table[i], path, cmp_cache) < 0) - i++; - } else if (i > 0 && etsu_tree_compare (source, sort_info, full_header, map_table[i - 1], path, cmp_cache) > 0) { - i--; - while (i > 0 && etsu_tree_compare (source, sort_info, full_header, map_table[i], path, cmp_cache) > 0) - i--; - } - - e_table_sorting_utils_free_cmp_cache (cmp_cache); - - return i; -} - -/* FIXME: This does not pay attention to making sure that it's a stable insert. This needs to be fixed. */ -gint -e_table_sorting_utils_tree_insert (ETreeModel *source, - ETableSortInfo *sort_info, - ETableHeader *full_header, - ETreePath *map_table, - gint count, - ETreePath path) -{ - gsize start; - gsize end; - ETreeSortClosure closure; - - closure.tree = source; - closure.sort_info = sort_info; - closure.full_header = full_header; - closure.cmp_cache = e_table_sorting_utils_create_cmp_cache (); - - e_bsearch (&path, map_table, count, sizeof (ETreePath), e_sort_tree_callback, &closure, &start, &end); - - e_table_sorting_utils_free_cmp_cache (closure.cmp_cache); - - return end; -} - -/** - * e_table_sorting_utils_create_cmp_cache: - * - * Creates a new compare cache, which is storing pairs of string keys and - * string values. This can be accessed by - * e_table_sorting_utils_lookup_cmp_cache() and - * e_table_sorting_utils_add_to_cmp_cache(). - * - * Returned pointer should be freed with - * e_table_sorting_utils_free_cmp_cache(). - **/ -gpointer -e_table_sorting_utils_create_cmp_cache (void) -{ - return g_hash_table_new_full (g_str_hash, g_str_equal, (GDestroyNotify) camel_pstring_free, g_free); -} - -/** - * e_table_sorting_utils_free_cmp_cache: - * @cmp_cache: a compare cache; cannot be %NULL - * - * Frees a compare cache previously created with - * e_table_sorting_utils_create_cmp_cache(). - **/ -void -e_table_sorting_utils_free_cmp_cache (gpointer cmp_cache) -{ - g_return_if_fail (cmp_cache != NULL); - - g_hash_table_destroy (cmp_cache); -} - -/** - * e_table_sorting_utils_add_to_cmp_cache: - * @cmp_cache: a compare cache; cannot be %NULL - * @key: unique key to a cache; cannot be %NULL - * @value: value to store for a key - * - * Adds a new value for a given key to a compare cache. If such key - * already exists in a cache then its value will be replaced. - * Note: Given @value will be stolen and later freed with g_free. - **/ -void -e_table_sorting_utils_add_to_cmp_cache (gpointer cmp_cache, - const gchar *key, - gchar *value) -{ - g_return_if_fail (cmp_cache != NULL); - g_return_if_fail (key != NULL); - - g_hash_table_insert (cmp_cache, (gchar *) camel_pstring_strdup (key), value); -} - -/** - * e_table_sorting_utils_lookup_cmp_cache: - * @cmp_cache: a compare cache - * @key: unique key to a cache - * - * Lookups for a key in a compare cache, which is passed in GCompareDataFunc as 'data'. - * Returns %NULL when not found or the cache wasn't provided, otherwise value stored - * with a key. - **/ -const gchar * -e_table_sorting_utils_lookup_cmp_cache (gpointer cmp_cache, - const gchar *key) -{ - g_return_val_if_fail (key != NULL, NULL); - - if (!cmp_cache) - return NULL; - - return g_hash_table_lookup (cmp_cache, key); -} diff --git a/widgets/table/e-table-sorting-utils.h b/widgets/table/e-table-sorting-utils.h deleted file mode 100644 index 5a0a3cd3d7..0000000000 --- a/widgets/table/e-table-sorting-utils.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_SORTING_UTILS_H_ -#define _E_TABLE_SORTING_UTILS_H_ - -G_BEGIN_DECLS - -#include <table/e-table-model.h> -#include <table/e-tree-model.h> -#include <table/e-table-sort-info.h> -#include <table/e-table-header.h> - -gboolean e_table_sorting_utils_affects_sort - (ETableSortInfo *sort_info, - ETableHeader *full_header, - gint col); - -void e_table_sorting_utils_sort (ETableModel *source, - ETableSortInfo *sort_info, - ETableHeader *full_header, - gint *map_table, - gint rows); -gint e_table_sorting_utils_insert (ETableModel *source, - ETableSortInfo *sort_info, - ETableHeader *full_header, - gint *map_table, - gint rows, - gint row); -gint e_table_sorting_utils_check_position - (ETableModel *source, - ETableSortInfo *sort_info, - ETableHeader *full_header, - gint *map_table, - gint rows, - gint view_row); - -void e_table_sorting_utils_tree_sort (ETreeModel *source, - ETableSortInfo *sort_info, - ETableHeader *full_header, - ETreePath *map_table, - gint count); -gint e_table_sorting_utils_tree_check_position - (ETreeModel *source, - ETableSortInfo *sort_info, - ETableHeader *full_header, - ETreePath *map_table, - gint count, - gint old_index); -gint e_table_sorting_utils_tree_insert - (ETreeModel *source, - ETableSortInfo *sort_info, - ETableHeader *full_header, - ETreePath *map_table, - gint count, - ETreePath path); - -gpointer e_table_sorting_utils_create_cmp_cache - (void); -void e_table_sorting_utils_free_cmp_cache - (gpointer cmp_cache); -void e_table_sorting_utils_add_to_cmp_cache - (gpointer cmp_cache, - const gchar *key, - gchar *value); -const gchar * e_table_sorting_utils_lookup_cmp_cache - (gpointer cmp_cache, - const gchar *key); - -G_END_DECLS - -#endif /* _E_TABLE_SORTING_UTILS_H_ */ diff --git a/widgets/table/e-table-specification.c b/widgets/table/e-table-specification.c deleted file mode 100644 index 9f301f6852..0000000000 --- a/widgets/table/e-table-specification.c +++ /dev/null @@ -1,436 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <string.h> - -#include <glib/gstdio.h> -#include <libxml/parser.h> -#include <libxml/xmlmemory.h> - -#include <libedataserver/libedataserver.h> - -#include "e-util/e-util.h" -#include "libevolution-utils/e-xml-utils.h" - -#include "e-table-specification.h" - -/* workaround for avoiding API breakage */ -#define etsp_get_type e_table_specification_get_type -G_DEFINE_TYPE (ETableSpecification, etsp, G_TYPE_OBJECT) - -static void -etsp_finalize (GObject *object) -{ - ETableSpecification *etsp = E_TABLE_SPECIFICATION (object); - gint i; - - if (etsp->columns) { - for (i = 0; etsp->columns[i]; i++) { - g_object_unref (etsp->columns[i]); - } - g_free (etsp->columns); - etsp->columns = NULL; - } - - if (etsp->state) - g_object_unref (etsp->state); - etsp->state = NULL; - - g_free (etsp->click_to_add_message); - etsp->click_to_add_message = NULL; - - g_free (etsp->domain); - etsp->domain = NULL; - - G_OBJECT_CLASS (etsp_parent_class)->finalize (object); -} - -static void -etsp_class_init (ETableSpecificationClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->finalize = etsp_finalize; -} - -static void -etsp_init (ETableSpecification *etsp) -{ - etsp->columns = NULL; - etsp->state = NULL; - - etsp->alternating_row_colors = TRUE; - etsp->no_headers = FALSE; - etsp->click_to_add = FALSE; - etsp->click_to_add_end = FALSE; - etsp->horizontal_draw_grid = FALSE; - etsp->vertical_draw_grid = FALSE; - etsp->draw_focus = TRUE; - etsp->horizontal_scrolling = FALSE; - etsp->horizontal_resize = FALSE; - etsp->allow_grouping = TRUE; - - etsp->cursor_mode = E_CURSOR_SIMPLE; - etsp->selection_mode = GTK_SELECTION_MULTIPLE; - - etsp->click_to_add_message = NULL; - etsp->domain = NULL; -} - -/** - * 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 = g_object_new (E_TYPE_TABLE_SPECIFICATION, NULL); - - 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 gchar *filename) -{ - xmlDoc *doc; - - doc = e_xml_parse_file (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 gchar *xml) -{ - xmlDoc *doc; - doc = xmlParseMemory ((gchar *) 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) -{ - gchar *temp; - xmlNode *children; - GList *list = NULL, *list2; - gint i; - - specification->no_headers = e_xml_get_bool_prop_by_name (node, (const guchar *)"no-headers"); - specification->click_to_add = e_xml_get_bool_prop_by_name (node, (const guchar *)"click-to-add"); - specification->click_to_add_end = e_xml_get_bool_prop_by_name (node, (const guchar *)"click-to-add-end") && specification->click_to_add; - specification->alternating_row_colors = e_xml_get_bool_prop_by_name_with_default (node, (const guchar *)"alternating-row-colors", TRUE); - specification->horizontal_draw_grid = e_xml_get_bool_prop_by_name (node, (const guchar *)"horizontal-draw-grid"); - specification->vertical_draw_grid = e_xml_get_bool_prop_by_name (node, (const guchar *)"vertical-draw-grid"); - if (e_xml_get_bool_prop_by_name_with_default (node, (const guchar *)"draw-grid", TRUE) == - e_xml_get_bool_prop_by_name_with_default (node, (const guchar *)"draw-grid", FALSE)) { - specification->horizontal_draw_grid = - specification->vertical_draw_grid = e_xml_get_bool_prop_by_name (node, (const guchar *)"draw-grid"); - } - specification->draw_focus = e_xml_get_bool_prop_by_name_with_default (node, (const guchar *)"draw-focus", TRUE); - specification->horizontal_scrolling = e_xml_get_bool_prop_by_name_with_default (node, (const guchar *)"horizontal-scrolling", FALSE); - specification->horizontal_resize = e_xml_get_bool_prop_by_name_with_default (node, (const guchar *)"horizontal-resize", FALSE); - specification->allow_grouping = e_xml_get_bool_prop_by_name_with_default (node, (const guchar *)"allow-grouping", TRUE); - - specification->selection_mode = GTK_SELECTION_MULTIPLE; - temp = e_xml_get_string_prop_by_name (node, (const guchar *)"selection-mode"); - if (temp && !g_ascii_strcasecmp (temp, "single")) { - specification->selection_mode = GTK_SELECTION_SINGLE; - } else if (temp && !g_ascii_strcasecmp (temp, "browse")) { - specification->selection_mode = GTK_SELECTION_BROWSE; - } else if (temp && !g_ascii_strcasecmp (temp, "extended")) { - specification->selection_mode = GTK_SELECTION_MULTIPLE; - } - g_free (temp); - - specification->cursor_mode = E_CURSOR_SIMPLE; - temp = e_xml_get_string_prop_by_name (node, (const guchar *)"cursor-mode"); - if (temp && !g_ascii_strcasecmp (temp, "line")) { - specification->cursor_mode = E_CURSOR_LINE; - } else if (temp && !g_ascii_strcasecmp (temp, "spreadsheet")) { - specification->cursor_mode = E_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, (const guchar *)"_click-to-add-message"); - - g_free (specification->domain); - specification->domain = - e_xml_get_string_prop_by_name ( - node, (const guchar *)"gettext-domain"); - if (specification->domain && !*specification->domain) { - g_free (specification->domain); - specification->domain = NULL; - } - - if (specification->state) - g_object_unref (specification->state); - specification->state = NULL; - if (specification->columns) { - for (i = 0; specification->columns[i]; i++) { - g_object_unref (specification->columns[i]); - } - g_free (specification->columns); - } - specification->columns = NULL; - - for (children = node->xmlChildrenNode; children; children = children->next) { - if (!strcmp ((gchar *) 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 ((gchar *) children->name, "ETableState")) { - specification->state = e_table_state_new (); - e_table_state_load_from_node (specification->state, children); - e_table_sort_info_set_can_group (specification->state->sort_info, specification->allow_grouping); - } - } - - if (specification->state == NULL) { - /* Make the default state. */ - specification->state = e_table_state_vanilla (g_list_length (list)); - } - - 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: 0 on success or -1 on error. - */ -gint -e_table_specification_save_to_file (ETableSpecification *specification, - const gchar *filename) -{ - xmlDoc *doc; - gint ret; - - 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); - - if ((doc = xmlNewDoc ((const guchar *)"1.0")) == NULL) - return -1; - - xmlDocSetRootElement (doc, e_table_specification_save_to_node (specification, doc)); - - ret = e_xml_save_file (filename, doc); - - xmlFreeDoc (doc); - - return ret; -} - -/** - * 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. - */ -gchar * -e_table_specification_save_to_string (ETableSpecification *specification) -{ - gchar *ret_val; - xmlChar *string; - gint length; - xmlDoc *doc; - - g_return_val_if_fail (specification != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (specification), NULL); - - doc = xmlNewDoc ((const guchar *)"1.0"); - xmlDocSetRootElement (doc, e_table_specification_save_to_node (specification, doc)); - xmlDocDumpMemory (doc, &string, &length); - - ret_val = g_strdup ((gchar *) 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; - const gchar *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, (const guchar *)"ETableSpecification"); - e_xml_set_bool_prop_by_name (node, (const guchar *)"no-headers", specification->no_headers); - e_xml_set_bool_prop_by_name (node, (const guchar *)"click-to-add", specification->click_to_add); - e_xml_set_bool_prop_by_name (node, (const guchar *)"click-to-add-end", specification->click_to_add_end && specification->click_to_add); - e_xml_set_bool_prop_by_name (node, (const guchar *)"alternating-row-colors", specification->alternating_row_colors); - e_xml_set_bool_prop_by_name (node, (const guchar *)"horizontal-draw-grid", specification->horizontal_draw_grid); - e_xml_set_bool_prop_by_name (node, (const guchar *)"vertical-draw-grid", specification->vertical_draw_grid); - e_xml_set_bool_prop_by_name (node, (const guchar *)"draw-focus", specification->draw_focus); - e_xml_set_bool_prop_by_name (node, (const guchar *)"horizontal-scrolling", specification->horizontal_scrolling); - e_xml_set_bool_prop_by_name (node, (const guchar *)"horizontal-resize", specification->horizontal_resize); - e_xml_set_bool_prop_by_name (node, (const guchar *)"allow-grouping", specification->allow_grouping); - - switch (specification->selection_mode) { - case GTK_SELECTION_SINGLE: - s = "single"; - break; - case GTK_SELECTION_BROWSE: - s = "browse"; - break; - default: - case GTK_SELECTION_MULTIPLE: - s = "extended"; - } - xmlSetProp (node, (const guchar *)"selection-mode", (guchar *) s); - if (specification->cursor_mode == E_CURSOR_LINE) - s = "line"; - else - s = "cell"; - xmlSetProp (node, (const guchar *)"cursor-mode", (guchar *) s); - - xmlSetProp (node, (const guchar *)"_click-to-add-message", (guchar *) specification->click_to_add_message); - xmlSetProp (node, (const guchar *)"gettext-domain", (guchar *) specification->domain); - - if (specification->columns) { - gint 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; - gchar *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); - if (!e_table_specification_load_from_string (new_spec, spec_str)) { - g_warning ("Unable to duplicate ETable specification"); - g_object_unref (new_spec); - new_spec = NULL; - } - 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 021c0524c5..0000000000 --- a/widgets/table/e-table-specification.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_SPECIFICATION_H_ -#define _E_TABLE_SPECIFICATION_H_ - -#include <libxml/tree.h> -#include <misc/e-selection-model.h> -#include <table/e-table-state.h> -#include <table/e-table-column-specification.h> -#include <table/e-table-defines.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_SPECIFICATION \ - (e_table_specification_get_type ()) -#define E_TABLE_SPECIFICATION(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_SPECIFICATION, ETableSpecification)) -#define E_TABLE_SPECIFICATION_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_SPECIFICATION, ETableSpecificationClass)) -#define E_IS_TABLE_SPECIFICATION(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_SPECIFICATION)) -#define E_IS_TABLE_SPECIFICATION_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_SPECIFICATION)) -#define E_TABLE_SPECIFICATION_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_SPECIFICATION, ETableSpecificationClass)) - -G_BEGIN_DECLS - -typedef struct _ETableSpecification ETableSpecification; -typedef struct _ETableSpecificationClass ETableSpecificationClass; - -struct _ETableSpecification { - GObject parent; - - ETableColumnSpecification **columns; - ETableState *state; - - guint alternating_row_colors : 1; - guint no_headers : 1; - guint click_to_add : 1; - guint click_to_add_end : 1; - guint horizontal_draw_grid : 1; - guint vertical_draw_grid : 1; - guint draw_focus : 1; - guint horizontal_scrolling : 1; - guint horizontal_resize : 1; - guint allow_grouping : 1; - GtkSelectionMode selection_mode; - ECursorMode cursor_mode; - - gchar *click_to_add_message; - gchar *domain; -}; - -struct _ETableSpecificationClass { - GObjectClass parent_class; -}; - -GType e_table_specification_get_type (void) G_GNUC_CONST; -ETableSpecification * - e_table_specification_new (void); - -gboolean e_table_specification_load_from_file - (ETableSpecification *specification, - const gchar *filename); -gboolean e_table_specification_load_from_string - (ETableSpecification *specification, - const gchar *xml); -void e_table_specification_load_from_node - (ETableSpecification *specification, - const xmlNode *node); - -gint e_table_specification_save_to_file - (ETableSpecification *specification, - const gchar *filename); -gchar * 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 *specification); - -G_END_DECLS - -#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 61c0e5ced5..0000000000 --- a/widgets/table/e-table-state.c +++ /dev/null @@ -1,321 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <string.h> - -#include <libxml/parser.h> -#include <libxml/xmlmemory.h> - -#include <libedataserver/libedataserver.h> - -#include "e-util/e-util.h" -#include "libevolution-utils/e-xml-utils.h" - -#include "e-table-state.h" - -#define STATE_VERSION 0.1 - -G_DEFINE_TYPE (ETableState, e_table_state, G_TYPE_OBJECT) - -static void -etst_dispose (GObject *object) -{ - ETableState *etst = E_TABLE_STATE (object); - - if (etst->sort_info) { - g_object_unref (etst->sort_info); - etst->sort_info = NULL; - } - - G_OBJECT_CLASS (e_table_state_parent_class)->dispose (object); -} - -static void -etst_finalize (GObject *object) -{ - ETableState *etst = E_TABLE_STATE (object); - - if (etst->columns) { - g_free (etst->columns); - etst->columns = NULL; - } - - if (etst->expansions) { - g_free (etst->expansions); - etst->expansions = NULL; - } - - G_OBJECT_CLASS (e_table_state_parent_class)->finalize (object); -} - -static void -e_table_state_class_init (ETableStateClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->dispose = etst_dispose; - object_class->finalize = etst_finalize; -} - -static void -e_table_state_init (ETableState *state) -{ - state->columns = NULL; - state->expansions = NULL; - state->sort_info = e_table_sort_info_new (); -} - -ETableState * -e_table_state_new (void) -{ - return g_object_new (E_TYPE_TABLE_STATE, NULL); -} - -ETableState * -e_table_state_vanilla (gint col_count) -{ - GString *str; - gint i; - ETableState *res; - - str = g_string_new ("<ETableState>\n"); - for (i = 0; i < col_count; i++) - g_string_append_printf (str, " <column source=\"%d\"/>\n", i); - g_string_append (str, " <grouping></grouping>\n"); - g_string_append (str, "</ETableState>\n"); - - res = e_table_state_new (); - e_table_state_load_from_string (res, str->str); - - g_string_free (str, TRUE); - return res; -} - -gboolean -e_table_state_load_from_file (ETableState *state, - const gchar *filename) -{ - xmlDoc *doc; - - g_return_val_if_fail (E_IS_TABLE_STATE (state), FALSE); - g_return_val_if_fail (filename != NULL, FALSE); - - doc = e_xml_parse_file (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 gchar *xml) -{ - xmlDoc *doc; - - g_return_if_fail (E_IS_TABLE_STATE (state)); - g_return_if_fail (xml != NULL); - - doc = xmlParseMemory ((gchar *) xml, strlen (xml)); - if (doc) { - xmlNode *node = xmlDocGetRootElement (doc); - e_table_state_load_from_node (state, node); - xmlFreeDoc (doc); - } -} - -typedef struct { - gint column; - gdouble 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; - gint i; - gboolean can_group = TRUE; - - g_return_if_fail (E_IS_TABLE_STATE (state)); - g_return_if_fail (node != NULL); - - state_version = e_xml_get_double_prop_by_name_with_default ( - node, (const guchar *)"state-version", STATE_VERSION); - - if (state->sort_info) { - can_group = e_table_sort_info_get_can_group (state->sort_info); - g_object_unref (state->sort_info); - } - - state->sort_info = NULL; - children = node->xmlChildrenNode; - for (; children; children = children->next) { - if (!strcmp ((gchar *) 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, (const guchar *)"source"); - column_info->expansion = - e_xml_get_double_prop_by_name_with_default ( - children, (const guchar *)"expansion", 1); - - list = g_list_append (list, column_info); - } else if (state->sort_info == NULL && - !strcmp ((gchar *) 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); - - if (!state->sort_info) - state->sort_info = e_table_sort_info_new (); - e_table_sort_info_set_can_group (state->sort_info, can_group); - - 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 gchar *filename) -{ - xmlDoc *doc; - - if ((doc = xmlNewDoc ((const guchar *)"1.0")) == NULL) - return; - - xmlDocSetRootElement (doc, e_table_state_save_to_node (state, NULL)); - - e_xml_save_file (filename, doc); - - xmlFreeDoc (doc); -} - -gchar * -e_table_state_save_to_string (ETableState *state) -{ - gchar *ret_val; - xmlChar *string; - gint length; - xmlDoc *doc; - - g_return_val_if_fail (E_IS_TABLE_STATE (state), NULL); - - doc = xmlNewDoc ((const guchar *)"1.0"); - xmlDocSetRootElement (doc, e_table_state_save_to_node (state, NULL)); - xmlDocDumpMemory (doc, &string, &length); - xmlFreeDoc (doc); - - ret_val = g_strdup ((gchar *) string); - xmlFree (string); - return ret_val; -} - -xmlNode * -e_table_state_save_to_node (ETableState *state, - xmlNode *parent) -{ - gint i; - xmlNode *node; - - g_return_val_if_fail (E_IS_TABLE_STATE (state), NULL); - - if (parent) - node = xmlNewChild ( - parent, NULL, (const guchar *) "ETableState", NULL); - else - node = xmlNewNode (NULL, (const guchar *) "ETableState"); - - e_xml_set_double_prop_by_name ( - node, (const guchar *)"state-version", STATE_VERSION); - - for (i = 0; i < state->col_count; i++) { - gint column = state->columns[i]; - gdouble expansion = state->expansions[i]; - xmlNode *new_node; - - new_node = xmlNewChild ( - node, NULL, (const guchar *) "column", NULL); - e_xml_set_integer_prop_by_name ( - new_node, (const guchar *) "source", column); - if (expansion >= -1) - e_xml_set_double_prop_by_name ( - new_node, (const guchar *) - "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; - gchar *copy; - - 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); - - e_table_sort_info_set_can_group - (new_state->sort_info, - e_table_sort_info_get_can_group (state->sort_info)); - - return new_state; -} diff --git a/widgets/table/e-table-state.h b/widgets/table/e-table-state.h deleted file mode 100644 index 23fc5b2fb2..0000000000 --- a/widgets/table/e-table-state.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_STATE_H_ -#define _E_TABLE_STATE_H_ - -#include <libxml/tree.h> -#include <table/e-table-sort-info.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_STATE \ - (e_table_state_get_type ()) -#define E_TABLE_STATE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_STATE, ETableState)) -#define E_TABLE_STATE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_STATE, ETableStateClass)) -#define E_IS_TABLE_STATE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_STATE)) -#define E_IS_TABLE_STATE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_STATE)) -#define E_TABLE_STATE_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_STATE, ETableStateClass)) - -G_BEGIN_DECLS - -typedef struct _ETableState ETableState; -typedef struct _ETableStateClass ETableStateClass; - -struct _ETableState { - GObject parent; - - ETableSortInfo *sort_info; - gint col_count; - gint *columns; - gdouble *expansions; -}; - -struct _ETableStateClass { - GObjectClass parent_class; -}; - -GType e_table_state_get_type (void) G_GNUC_CONST; -ETableState * e_table_state_new (void); -ETableState * e_table_state_vanilla (gint col_count); -gboolean e_table_state_load_from_file (ETableState *state, - const gchar *filename); -void e_table_state_load_from_string (ETableState *state, - const gchar *xml); -void e_table_state_load_from_node (ETableState *state, - const xmlNode *node); -void e_table_state_save_to_file (ETableState *state, - const gchar *filename); -gchar * 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); - -G_END_DECLS - -#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 a40859b492..0000000000 --- a/widgets/table/e-table-subset-variable.c +++ /dev/null @@ -1,269 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <string.h> - -#include "e-util/e-util.h" - -#include "e-table-subset-variable.h" - -#define ETSSV_CLASS(e) (E_TABLE_SUBSET_VARIABLE_GET_CLASS (e)) - -/* workaround for avoiding API breakage */ -#define etssv_get_type e_table_subset_variable_get_type -G_DEFINE_TYPE (ETableSubsetVariable, etssv, E_TYPE_TABLE_SUBSET) - -#define INCREMENT_AMOUNT 10 - -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) { - etssv->n_vals_allocated += INCREMENT_AMOUNT; - etss->map_table = g_realloc ( - etss->map_table, - etssv->n_vals_allocated * sizeof (gint)); - } - - etss->map_table[etss->n_map++] = row; - - e_table_model_row_inserted (etm, etss->n_map - 1); -} - -static void -etssv_add_array (ETableSubsetVariable *etssv, - const gint *array, - gint count) -{ - ETableModel *etm = E_TABLE_MODEL (etssv); - ETableSubset *etss = E_TABLE_SUBSET (etssv); - gint i; - - e_table_model_pre_change (etm); - - if (etss->n_map + count > etssv->n_vals_allocated) { - etssv->n_vals_allocated += MAX (INCREMENT_AMOUNT, count); - etss->map_table = g_realloc ( - etss->map_table, - etssv->n_vals_allocated * sizeof (gint)); - } - for (i = 0; i < count; i++) - etss->map_table[etss->n_map++] = array[i]; - - e_table_model_changed (etm); -} - -static void -etssv_add_all (ETableSubsetVariable *etssv) -{ - ETableModel *etm = E_TABLE_MODEL (etssv); - ETableSubset *etss = E_TABLE_SUBSET (etssv); - gint rows; - gint 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 (gint)); - } - 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); - gint 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 (gint)); - etss->n_map--; - - e_table_model_row_deleted (etm, i); - return TRUE; - } - } - return FALSE; -} - -static void -etssv_class_init (ETableSubsetVariableClass *class) -{ - class->add = etssv_add; - class->add_array = etssv_add_array; - class->add_all = etssv_add_all; - class->remove = etssv_remove; -} - -static void -etssv_init (ETableSubsetVariable *etssv) -{ - /* nothing to do */ -} - -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 = g_object_new (E_TYPE_TABLE_SUBSET_VARIABLE, NULL); - - if (e_table_subset_variable_construct (etssv, source) == NULL) { - g_object_unref (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_array (ETableSubsetVariable *etssv, - const gint *array, - gint count) -{ - g_return_if_fail (etssv != NULL); - g_return_if_fail (E_IS_TABLE_SUBSET_VARIABLE (etssv)); - - if (ETSSV_CLASS (etssv)->add_array) - ETSSV_CLASS (etssv)->add_array (etssv, array, count); -} - -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_clear (ETableSubsetVariable *etssv) -{ - ETableModel *etm = E_TABLE_MODEL (etssv); - ETableSubset *etss = E_TABLE_SUBSET (etssv); - - e_table_model_pre_change (etm); - etss->n_map = 0; - g_free (etss->map_table); - etss->map_table = (gint *) g_new (guint, 1); - etssv->n_vals_allocated = 1; - - e_table_model_changed (etm); -} - -void -e_table_subset_variable_increment (ETableSubsetVariable *etssv, - gint position, - gint amount) -{ - gint 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) -{ - gint 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 (gint)); - } -} diff --git a/widgets/table/e-table-subset-variable.h b/widgets/table/e-table-subset-variable.h deleted file mode 100644 index da8186a1df..0000000000 --- a/widgets/table/e-table-subset-variable.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_SUBSET_VARIABLE_H_ -#define _E_TABLE_SUBSET_VARIABLE_H_ - -#include <table/e-table-subset.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_SUBSET_VARIABLE \ - (e_table_subset_variable_get_type ()) -#define E_TABLE_SUBSET_VARIABLE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_SUBSET_VARIABLE, ETableSubsetVariable)) -#define E_TABLE_SUBSET_VARIABLE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_SUBSET_VARIABLE, ETableSubsetVariableClass)) -#define E_IS_TABLE_SUBSET_VARIABLE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_SUBSET_VARIABLE)) -#define E_IS_TABLE_SUBSET_VARIABLE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_SUBSET_VARIABLE)) -#define E_TABLE_SUBSET_VARIABLE_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_SUBSET_VARIABLE, ETableSubsetVariableClass)) - -G_BEGIN_DECLS - -typedef struct _ETableSubsetVariable ETableSubsetVariable; -typedef struct _ETableSubsetVariableClass ETableSubsetVariableClass; - -struct _ETableSubsetVariable { - ETableSubset parent; - gint n_vals_allocated; -}; - -struct _ETableSubsetVariableClass { - ETableSubsetClass parent_class; - - void (*add) (ETableSubsetVariable *ets, - gint row); - void (*add_array) (ETableSubsetVariable *ets, - const gint *array, - gint count); - void (*add_all) (ETableSubsetVariable *ets); - gboolean (*remove) (ETableSubsetVariable *ets, - gint row); -}; - -GType e_table_subset_variable_get_type - (void) G_GNUC_CONST; -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_array - (ETableSubsetVariable *ets, - const gint *array, - gint count); -void e_table_subset_variable_add_all (ETableSubsetVariable *ets); -gboolean e_table_subset_variable_remove (ETableSubsetVariable *ets, - gint row); -void e_table_subset_variable_clear (ETableSubsetVariable *ets); -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); - -G_END_DECLS - -#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 411102eac1..0000000000 --- a/widgets/table/e-table-subset.c +++ /dev/null @@ -1,569 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> - -#include "e-util/e-util.h" - -#include "e-table-subset.h" - -static void etss_proxy_model_pre_change_real - (ETableSubset *etss, - ETableModel *etm); -static void etss_proxy_model_no_change_real (ETableSubset *etss, - ETableModel *etm); -static void etss_proxy_model_changed_real (ETableSubset *etss, - ETableModel *etm); -static void etss_proxy_model_row_changed_real - (ETableSubset *etss, - ETableModel *etm, - gint row); -static void etss_proxy_model_cell_changed_real - (ETableSubset *etss, - ETableModel *etm, - gint col, - gint row); -static void etss_proxy_model_rows_inserted_real - (ETableSubset *etss, - ETableModel *etm, - gint row, - gint count); -static void etss_proxy_model_rows_deleted_real - (ETableSubset *etss, - ETableModel *etm, - gint row, - gint count); - -#define d(x) - -/* workaround for avoding API breakage */ -#define etss_get_type e_table_subset_get_type -G_DEFINE_TYPE (ETableSubset, etss, E_TYPE_TABLE_MODEL) - -#define ETSS_CLASS(object) (E_TABLE_SUBSET_GET_CLASS(object)) - -#define VALID_ROW(etss, row) (row >= -1 && row < etss->n_map) -#define MAP_ROW(etss, row) (row == -1 ? -1 : etss->map_table[row]) - -static gint -etss_get_view_row (ETableSubset *etss, - gint row) -{ - const gint n = etss->n_map; - const gint * const map_table = etss->map_table; - gint i; - - gint end = MIN (etss->n_map, etss->last_access + 10); - gint start = MAX (0, etss->last_access - 10); - gint initial = MAX (MIN (etss->last_access, end), start); - - for (i = initial; i < end; i++) { - if (map_table[i] == row) { - d (g_print ("a) Found %d from %d\n", i, etss->last_access)); - etss->last_access = i; - return i; - } - } - - for (i = initial - 1; i >= start; i--) { - if (map_table[i] == row) { - d (g_print ("b) Found %d from %d\n", i, etss->last_access)); - etss->last_access = i; - return i; - } - } - - for (i = 0; i < n; i++) { - if (map_table[i] == row) { - d (g_print ("c) Found %d from %d\n", i, etss->last_access)); - etss->last_access = i; - return i; - } - } - return -1; -} - -static void -etss_dispose (GObject *object) -{ - ETableSubset *etss = E_TABLE_SUBSET (object); - - if (etss->source) { - g_signal_handler_disconnect ( - etss->source, - etss->table_model_pre_change_id); - g_signal_handler_disconnect ( - etss->source, - etss->table_model_no_change_id); - g_signal_handler_disconnect ( - etss->source, - etss->table_model_changed_id); - g_signal_handler_disconnect ( - etss->source, - etss->table_model_row_changed_id); - g_signal_handler_disconnect ( - etss->source, - etss->table_model_cell_changed_id); - g_signal_handler_disconnect ( - etss->source, - etss->table_model_rows_inserted_id); - g_signal_handler_disconnect ( - etss->source, - etss->table_model_rows_deleted_id); - - g_object_unref (etss->source); - etss->source = NULL; - - etss->table_model_changed_id = 0; - etss->table_model_row_changed_id = 0; - etss->table_model_cell_changed_id = 0; - etss->table_model_rows_inserted_id = 0; - etss->table_model_rows_deleted_id = 0; - } - - G_OBJECT_CLASS (etss_parent_class)->dispose (object); -} - -static void -etss_finalize (GObject *object) -{ - ETableSubset *etss = E_TABLE_SUBSET (object); - - g_free (etss->map_table); - etss->map_table = NULL; - - G_OBJECT_CLASS (etss_parent_class)->finalize (object); -} - -static gint -etss_column_count (ETableModel *etm) -{ - ETableSubset *etss = (ETableSubset *) etm; - - return e_table_model_column_count (etss->source); -} - -static gint -etss_row_count (ETableModel *etm) -{ - ETableSubset *etss = (ETableSubset *) etm; - - return etss->n_map; -} - -static gpointer -etss_value_at (ETableModel *etm, - gint col, - gint row) -{ - ETableSubset *etss = (ETableSubset *) etm; - - g_return_val_if_fail (VALID_ROW (etss, row), NULL); - - etss->last_access = row; - d (g_print ("g) Setting last_access to %d\n", row)); - return e_table_model_value_at (etss->source, col, MAP_ROW (etss, row)); -} - -static void -etss_set_value_at (ETableModel *etm, - gint col, - gint row, - gconstpointer val) -{ - ETableSubset *etss = (ETableSubset *) etm; - - g_return_if_fail (VALID_ROW (etss, row)); - - etss->last_access = row; - d (g_print ("h) Setting last_access to %d\n", row)); - e_table_model_set_value_at (etss->source, col, MAP_ROW (etss, row), val); -} - -static gboolean -etss_is_cell_editable (ETableModel *etm, - gint col, - gint row) -{ - ETableSubset *etss = (ETableSubset *) etm; - - g_return_val_if_fail (VALID_ROW (etss, row), FALSE); - - return e_table_model_is_cell_editable (etss->source, col, MAP_ROW (etss, row)); -} - -static gboolean -etss_has_save_id (ETableModel *etm) -{ - return TRUE; -} - -static gchar * -etss_get_save_id (ETableModel *etm, - gint row) -{ - ETableSubset *etss = (ETableSubset *) etm; - - g_return_val_if_fail (VALID_ROW (etss, row), NULL); - - if (e_table_model_has_save_id (etss->source)) - return e_table_model_get_save_id (etss->source, MAP_ROW (etss, row)); - else - return g_strdup_printf ("%d", MAP_ROW (etss, row)); -} - -static void -etss_append_row (ETableModel *etm, - ETableModel *source, - gint row) -{ - ETableSubset *etss = (ETableSubset *) etm; - e_table_model_append_row (etss->source, source, row); -} - -static gpointer -etss_duplicate_value (ETableModel *etm, - gint col, - gconstpointer value) -{ - ETableSubset *etss = (ETableSubset *) etm; - - return e_table_model_duplicate_value (etss->source, col, value); -} - -static void -etss_free_value (ETableModel *etm, - gint col, - gpointer value) -{ - ETableSubset *etss = (ETableSubset *) etm; - - e_table_model_free_value (etss->source, col, value); -} - -static gpointer -etss_initialize_value (ETableModel *etm, - gint col) -{ - ETableSubset *etss = (ETableSubset *) etm; - - return e_table_model_initialize_value (etss->source, col); -} - -static gboolean -etss_value_is_empty (ETableModel *etm, - gint col, - gconstpointer value) -{ - ETableSubset *etss = (ETableSubset *) etm; - - return e_table_model_value_is_empty (etss->source, col, value); -} - -static gchar * -etss_value_to_string (ETableModel *etm, - gint col, - gconstpointer value) -{ - ETableSubset *etss = (ETableSubset *) etm; - - return e_table_model_value_to_string (etss->source, col, value); -} - -static void -etss_class_init (ETableSubsetClass *class) -{ - ETableModelClass *table_class = E_TABLE_MODEL_CLASS (class); - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->dispose = etss_dispose; - object_class->finalize = etss_finalize; - - table_class->column_count = etss_column_count; - table_class->row_count = etss_row_count; - table_class->append_row = etss_append_row; - - 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->has_save_id = etss_has_save_id; - table_class->get_save_id = etss_get_save_id; - - 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; - - class->proxy_model_pre_change = etss_proxy_model_pre_change_real; - class->proxy_model_no_change = etss_proxy_model_no_change_real; - class->proxy_model_changed = etss_proxy_model_changed_real; - class->proxy_model_row_changed = etss_proxy_model_row_changed_real; - class->proxy_model_cell_changed = etss_proxy_model_cell_changed_real; - class->proxy_model_rows_inserted = etss_proxy_model_rows_inserted_real; - class->proxy_model_rows_deleted = etss_proxy_model_rows_deleted_real; -} - -static void -etss_init (ETableSubset *etss) -{ - etss->last_access = 0; -} - -static void -etss_proxy_model_pre_change_real (ETableSubset *etss, - ETableModel *etm) -{ - e_table_model_pre_change (E_TABLE_MODEL (etss)); -} - -static void -etss_proxy_model_no_change_real (ETableSubset *etss, - ETableModel *etm) -{ - e_table_model_no_change (E_TABLE_MODEL (etss)); -} - -static void -etss_proxy_model_changed_real (ETableSubset *etss, - ETableModel *etm) -{ - e_table_model_changed (E_TABLE_MODEL (etss)); -} - -static void -etss_proxy_model_row_changed_real (ETableSubset *etss, - ETableModel *etm, - gint row) -{ - gint view_row = etss_get_view_row (etss, row); - if (view_row != -1) - e_table_model_row_changed (E_TABLE_MODEL (etss), view_row); - else - e_table_model_no_change (E_TABLE_MODEL (etss)); -} - -static void -etss_proxy_model_cell_changed_real (ETableSubset *etss, - ETableModel *etm, - gint col, - gint row) -{ - gint view_row = etss_get_view_row (etss, row); - if (view_row != -1) - e_table_model_cell_changed (E_TABLE_MODEL (etss), col, view_row); - else - e_table_model_no_change (E_TABLE_MODEL (etss)); -} - -static void -etss_proxy_model_rows_inserted_real (ETableSubset *etss, - ETableModel *etm, - gint row, - gint count) -{ - e_table_model_no_change (E_TABLE_MODEL (etss)); -} - -static void -etss_proxy_model_rows_deleted_real (ETableSubset *etss, - ETableModel *etm, - gint row, - gint count) -{ - e_table_model_no_change (E_TABLE_MODEL (etss)); -} - -static void -etss_proxy_model_pre_change (ETableModel *etm, - ETableSubset *etss) -{ - if (ETSS_CLASS (etss)->proxy_model_pre_change) - (ETSS_CLASS (etss)->proxy_model_pre_change) (etss, etm); -} - -static void -etss_proxy_model_no_change (ETableModel *etm, - ETableSubset *etss) -{ - if (ETSS_CLASS (etss)->proxy_model_no_change) - (ETSS_CLASS (etss)->proxy_model_no_change) (etss, etm); -} - -static void -etss_proxy_model_changed (ETableModel *etm, - ETableSubset *etss) -{ - if (ETSS_CLASS (etss)->proxy_model_changed) - (ETSS_CLASS (etss)->proxy_model_changed) (etss, etm); -} - -static void -etss_proxy_model_row_changed (ETableModel *etm, - gint row, - ETableSubset *etss) -{ - if (ETSS_CLASS (etss)->proxy_model_row_changed) - (ETSS_CLASS (etss)->proxy_model_row_changed) (etss, etm, row); -} - -static void -etss_proxy_model_cell_changed (ETableModel *etm, - gint col, - gint row, - ETableSubset *etss) -{ - if (ETSS_CLASS (etss)->proxy_model_cell_changed) - (ETSS_CLASS (etss)->proxy_model_cell_changed) (etss, etm, col, row); -} - -static void -etss_proxy_model_rows_inserted (ETableModel *etm, - gint row, - gint col, - ETableSubset *etss) -{ - if (ETSS_CLASS (etss)->proxy_model_rows_inserted) - (ETSS_CLASS (etss)->proxy_model_rows_inserted) (etss, etm, row, col); -} - -static void -etss_proxy_model_rows_deleted (ETableModel *etm, - gint row, - gint col, - ETableSubset *etss) -{ - if (ETSS_CLASS (etss)->proxy_model_rows_deleted) - (ETSS_CLASS (etss)->proxy_model_rows_deleted) (etss, etm, row, col); -} - -ETableModel * -e_table_subset_construct (ETableSubset *etss, - ETableModel *source, - gint nvals) -{ - guint *buffer; - gint i; - - if (nvals) { - buffer = (guint *) g_malloc (sizeof (guint) * nvals); - if (buffer == NULL) - return NULL; - } else - buffer = NULL; - etss->map_table = (gint *) buffer; - etss->n_map = nvals; - etss->source = source; - g_object_ref (source); - - /* Init */ - for (i = 0; i < nvals; i++) - etss->map_table[i] = i; - - etss->table_model_pre_change_id = g_signal_connect ( - source, "model_pre_change", - G_CALLBACK (etss_proxy_model_pre_change), etss); - etss->table_model_no_change_id = g_signal_connect ( - source, "model_no_change", - G_CALLBACK (etss_proxy_model_no_change), etss); - etss->table_model_changed_id = g_signal_connect ( - source, "model_changed", - G_CALLBACK (etss_proxy_model_changed), etss); - etss->table_model_row_changed_id = g_signal_connect ( - source, "model_row_changed", - G_CALLBACK (etss_proxy_model_row_changed), etss); - etss->table_model_cell_changed_id = g_signal_connect ( - source, "model_cell_changed", - G_CALLBACK (etss_proxy_model_cell_changed), etss); - etss->table_model_rows_inserted_id = g_signal_connect ( - source, "model_rows_inserted", - G_CALLBACK (etss_proxy_model_rows_inserted), etss); - etss->table_model_rows_deleted_id = g_signal_connect ( - source, "model_rows_deleted", - G_CALLBACK (etss_proxy_model_rows_deleted), etss); - - return E_TABLE_MODEL (etss); -} - -ETableModel * -e_table_subset_new (ETableModel *source, - const gint nvals) -{ - ETableSubset *etss = g_object_new (E_TYPE_TABLE_SUBSET, NULL); - - if (e_table_subset_construct (etss, source, nvals) == NULL) { - g_object_unref (etss); - return NULL; - } - - return (ETableModel *) etss; -} - -gint -e_table_subset_model_to_view_row (ETableSubset *ets, - gint model_row) -{ - gint i; - for (i = 0; i < ets->n_map; i++) { - if (ets->map_table[i] == model_row) - return i; - } - return -1; -} - -gint -e_table_subset_view_to_model_row (ETableSubset *ets, - gint view_row) -{ - if (view_row >= 0 && view_row < ets->n_map) - return ets->map_table[view_row]; - else - return -1; -} - -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; -} - -void -e_table_subset_print_debugging (ETableSubset *table_model) -{ - gint i; - for (i = 0; i < table_model->n_map; i++) { - g_print ("%8d\n", table_model->map_table[i]); - } -} diff --git a/widgets/table/e-table-subset.h b/widgets/table/e-table-subset.h deleted file mode 100644 index 9729bdd6b0..0000000000 --- a/widgets/table/e-table-subset.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_SUBSET_H_ -#define _E_TABLE_SUBSET_H_ - -#include <table/e-table-model.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_SUBSET \ - (e_table_subset_get_type ()) -#define E_TABLE_SUBSET(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_SUBSET, ETableSubset)) -#define E_TABLE_SUBSET_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_SUBSET, ETableSubsetClass)) -#define E_IS_TABLE_SUBSET(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_SUBSET)) -#define E_IS_TABLE_SUBSET_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_SUBSET)) -#define E_TABLE_SUBSET_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_SUBSET, ETableSubsetClass)) - -G_BEGIN_DECLS - -typedef struct _ETableSubset ETableSubset; -typedef struct _ETableSubsetClass ETableSubsetClass; - -struct _ETableSubset { - ETableModel parent; - - ETableModel *source; - gint n_map; - gint *map_table; - - gint last_access; - - gint table_model_pre_change_id; - gint table_model_no_change_id; - gint table_model_changed_id; - gint table_model_row_changed_id; - gint table_model_cell_changed_id; - gint table_model_rows_inserted_id; - gint table_model_rows_deleted_id; -}; - -struct _ETableSubsetClass { - ETableModelClass parent_class; - - void (*proxy_model_pre_change) (ETableSubset *etss, - ETableModel *etm); - void (*proxy_model_no_change) (ETableSubset *etss, - ETableModel *etm); - void (*proxy_model_changed) (ETableSubset *etss, - ETableModel *etm); - void (*proxy_model_row_changed) (ETableSubset *etss, - ETableModel *etm, - gint row); - void (*proxy_model_cell_changed) (ETableSubset *etss, - ETableModel *etm, - gint col, - gint row); - void (*proxy_model_rows_inserted) (ETableSubset *etss, - ETableModel *etm, - gint row, - gint count); - void (*proxy_model_rows_deleted) (ETableSubset *etss, - ETableModel *etm, - gint row, - gint count); -}; - -GType e_table_subset_get_type (void) G_GNUC_CONST; -ETableModel * e_table_subset_new (ETableModel *etm, - gint n_vals); -ETableModel * e_table_subset_construct (ETableSubset *ets, - ETableModel *source, - gint nvals); -gint e_table_subset_model_to_view_row - (ETableSubset *ets, - gint model_row); -gint e_table_subset_view_to_model_row - (ETableSubset *ets, - gint view_row); -ETableModel * e_table_subset_get_toplevel (ETableSubset *table_model); -void e_table_subset_print_debugging (ETableSubset *table_model); - -G_END_DECLS - -#endif /* _E_TABLE_SUBSET_H_ */ - diff --git a/widgets/table/e-table-utils.c b/widgets/table/e-table-utils.c deleted file mode 100644 index 2bdfddc949..0000000000 --- a/widgets/table/e-table-utils.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <libintl.h> /* This file uses dgettext() but no _() */ -#include <string.h> - -#include "e-util/e-util.h" -#include "e-util/e-unicode.h" - -#include "e-table-utils.h" -#include "e-table-header-utils.h" - -ETableHeader * -e_table_state_to_header (GtkWidget *widget, - ETableHeader *full_header, - ETableState *state) -{ - ETableHeader *nh; - const gint max_cols = e_table_header_count (full_header); - gint column; - GValue *val = g_new0 (GValue, 1); - - g_return_val_if_fail (widget, NULL); - g_return_val_if_fail (full_header, NULL); - g_return_val_if_fail (state, NULL); - - nh = e_table_header_new (); - g_value_init (val, G_TYPE_DOUBLE); - g_value_set_double (val, e_table_header_width_extras (widget)); - g_object_set_property (G_OBJECT (nh), "width_extras", val); - g_free (val); - - for (column = 0; column < state->col_count; column++) { - gint col; - gdouble 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; -} - -static ETableCol * -et_col_spec_to_col (ETableColumnSpecification *col_spec, - ETableExtras *ete, - const gchar *domain) -{ - ETableCol *col = NULL; - ECell *cell = NULL; - GCompareDataFunc compare = NULL; - ETableSearchFunc search = NULL; - - if (col_spec->cell) - cell = e_table_extras_get_cell (ete, col_spec->cell); - if (col_spec->compare) - compare = e_table_extras_get_compare (ete, col_spec->compare); - if (col_spec->search) - search = e_table_extras_get_search (ete, col_spec->search); - - if (cell && compare) { - gchar *title = dgettext (domain, col_spec->title); - - title = g_strdup (title); - - if (col_spec->pixbuf && *col_spec->pixbuf) { - const gchar *icon_name; - - icon_name = e_table_extras_get_icon_name ( - ete, col_spec->pixbuf); - if (icon_name != NULL) { - col = e_table_col_new ( - col_spec->model_col, - title, icon_name, - col_spec->expansion, - col_spec->minimum_width, - cell, compare, - col_spec->resizable, - col_spec->disabled, - col_spec->priority); - } - } - - if (col == NULL && col_spec->title && *col_spec->title) { - col = e_table_col_new ( - col_spec->model_col, title, NULL, - col_spec->expansion, - col_spec->minimum_width, - cell, compare, - col_spec->resizable, - col_spec->disabled, - col_spec->priority); - } - - if (col) { - col->search = search; - if (col_spec->sortable && !strcmp (col_spec->sortable, "false")) - col->sortable = FALSE; - else - col->sortable = TRUE; - } - g_free (title); - } - if (col && col_spec->compare_col != col_spec->model_col) - g_object_set ( - col, - "compare_col", col_spec->compare_col, - NULL); - return col; -} - -ETableHeader * -e_table_spec_to_full_header (ETableSpecification *spec, - ETableExtras *ete) -{ - ETableHeader *nh; - gint column; - - 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 ( - spec->columns[column], ete, spec->domain); - - if (col) { - e_table_header_add_column (nh, col, -1); - g_object_unref (col); - } - } - - return nh; -} - -static gboolean -check_col (ETableCol *col, - gpointer user_data) -{ - return col->search ? TRUE : FALSE; -} - -ETableCol * -e_table_util_calculate_current_search_col (ETableHeader *header, - ETableHeader *full_header, - ETableSortInfo *sort_info, - gboolean always_search) -{ - gint i; - gint count; - ETableCol *col = NULL; - - count = e_table_sort_info_grouping_get_count (sort_info); - - for (i = 0; i < count; i++) { - ETableSortColumn column; - - column = e_table_sort_info_grouping_get_nth (sort_info, i); - - col = e_table_header_get_column (full_header, column.column); - - if (col && col->search) - break; - - col = NULL; - } - - if (col == NULL) { - count = e_table_sort_info_sorting_get_count (sort_info); - for (i = 0; i < count; i++) { - ETableSortColumn column; - - column = e_table_sort_info_sorting_get_nth (sort_info, i); - - col = e_table_header_get_column (full_header, column.column); - - if (col && col->search) - break; - - col = NULL; - } - } - - if (col == NULL && always_search) { - col = e_table_header_prioritized_column_selected (header, check_col, NULL); - } - - return col; -} diff --git a/widgets/table/e-table-utils.h b/widgets/table/e-table-utils.h deleted file mode 100644 index a53e7e4060..0000000000 --- a/widgets/table/e-table-utils.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_UTILS_H_ -#define _E_TABLE_UTILS_H_ - -#include <table/e-table-header.h> -#include <table/e-table-state.h> -#include <table/e-table-specification.h> -#include <table/e-table-extras.h> - -G_BEGIN_DECLS - -ETableHeader * e_table_state_to_header (GtkWidget *widget, - ETableHeader *full_header, - ETableState *state); - -ETableHeader * e_table_spec_to_full_header (ETableSpecification *spec, - ETableExtras *ete); - -ETableCol * e_table_util_calculate_current_search_col - (ETableHeader *header, - ETableHeader *full_header, - ETableSortInfo *sort_info, - gboolean always_search); - -G_END_DECLS - -#endif /* _E_TABLE_UTILS_H_ */ - diff --git a/widgets/table/e-table-without.c b/widgets/table/e-table-without.c deleted file mode 100644 index 6fba6cbe12..0000000000 --- a/widgets/table/e-table-without.c +++ /dev/null @@ -1,414 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <string.h> - -#include "e-util/e-util.h" - -#include "e-table-without.h" - -#define E_TABLE_WITHOUT_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), E_TYPE_TABLE_WITHOUT, ETableWithoutPrivate)) - -/* workaround for avoiding API breakage */ -#define etw_get_type e_table_without_get_type -G_DEFINE_TYPE (ETableWithout, etw, E_TYPE_TABLE_SUBSET) - -#define INCREMENT_AMOUNT 10 - -struct _ETableWithoutPrivate { - GHashTable *hash; - - GHashFunc hash_func; - GCompareFunc compare_func; - - ETableWithoutGetKeyFunc get_key_func; - ETableWithoutDuplicateKeyFunc duplicate_key_func; - ETableWithoutFreeKeyFunc free_gotten_key_func; - ETableWithoutFreeKeyFunc free_duplicated_key_func; - - gpointer closure; -}; - -static gboolean -check (ETableWithout *etw, - gint model_row) -{ - gboolean ret_val; - gpointer key; - ETableSubset *etss = E_TABLE_SUBSET (etw); - - if (etw->priv->get_key_func) - key = etw->priv->get_key_func (etss->source, model_row, etw->priv->closure); - else - key = GINT_TO_POINTER (model_row); - ret_val = (g_hash_table_lookup (etw->priv->hash, key) != NULL); - if (etw->priv->free_gotten_key_func) - etw->priv->free_gotten_key_func (key, etw->priv->closure); - return ret_val; -} - -static gboolean -check_with_key (ETableWithout *etw, - gpointer key, - gint model_row) -{ - gboolean ret_val; - gpointer key2; - ETableSubset *etss = E_TABLE_SUBSET (etw); - - if (etw->priv->get_key_func) - key2 = etw->priv->get_key_func (etss->source, model_row, etw->priv->closure); - else - key2 = GINT_TO_POINTER (model_row); - if (etw->priv->compare_func) - ret_val = (etw->priv->compare_func (key, key2)); - else - ret_val = (key == key2); - if (etw->priv->free_gotten_key_func) - etw->priv->free_gotten_key_func (key2, etw->priv->closure); - return ret_val; -} - -static gint -etw_view_to_model_row (ETableWithout *etw, - gint view_row) -{ - ETableSubset *etss = E_TABLE_SUBSET (etw); - return etss->map_table[view_row]; -} - -static void -add_row (ETableWithout *etw, - gint model_row) -{ - ETableSubset *etss = E_TABLE_SUBSET (etw); - - e_table_model_pre_change (E_TABLE_MODEL (etw)); - - etss->map_table = g_renew (int, etss->map_table, etss->n_map + 1); - - etss->map_table[etss->n_map++] = model_row; - - e_table_model_row_inserted (E_TABLE_MODEL (etw), etss->n_map - 1); -} - -static void -remove_row (ETableWithout *etw, - gint view_row) -{ - ETableSubset *etss = E_TABLE_SUBSET (etw); - - e_table_model_pre_change (E_TABLE_MODEL (etw)); - memmove ( - etss->map_table + view_row, - etss->map_table + view_row + 1, - (etss->n_map - view_row - 1) * sizeof (gint)); - etss->n_map--; - e_table_model_row_deleted (E_TABLE_MODEL (etw), view_row); -} - -static void -delete_hash_element (gpointer key, - gpointer value, - gpointer closure) -{ - ETableWithout *etw = closure; - if (etw->priv->free_duplicated_key_func) - etw->priv->free_duplicated_key_func (key, etw->priv->closure); -} - -static void -etw_dispose (GObject *object) -{ - ETableWithoutPrivate *priv; - - priv = E_TABLE_WITHOUT_GET_PRIVATE (object); - - if (priv->hash != NULL) { - g_hash_table_foreach (priv->hash, delete_hash_element, object); - g_hash_table_destroy (priv->hash); - priv->hash = NULL; - } - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (etw_parent_class)->dispose (object); -} - -static void -etw_proxy_model_rows_inserted (ETableSubset *etss, - ETableModel *etm, - gint model_row, - gint count) -{ - gint i; - ETableWithout *etw = E_TABLE_WITHOUT (etss); - gboolean shift = FALSE; - - /* i is View row */ - if (model_row != etss->n_map) { - for (i = 0; i < etss->n_map; i++) { - if (etss->map_table[i] > model_row) - etss->map_table[i] += count; - } - shift = TRUE; - } - - /* i is Model row */ - for (i = model_row; i < model_row + count; i++) { - if (!check (etw, i)) { - add_row (etw, i); - } - } - if (shift) - e_table_model_changed (E_TABLE_MODEL (etw)); - else - e_table_model_no_change (E_TABLE_MODEL (etw)); -} - -static void -etw_proxy_model_rows_deleted (ETableSubset *etss, - ETableModel *etm, - gint model_row, - gint count) -{ - gint i; /* View row */ - ETableWithout *etw = E_TABLE_WITHOUT (etss); - gboolean shift = FALSE; - - for (i = 0; i < etss->n_map; i++) { - if (etss->map_table[i] >= model_row && - etss->map_table[i] < model_row + count) { - remove_row (etw, i); - i--; - } else if (etss->map_table[i] >= model_row + count) { - etss->map_table[i] -= count; - shift = TRUE; - } - } - if (shift) - e_table_model_changed (E_TABLE_MODEL (etw)); - else - e_table_model_no_change (E_TABLE_MODEL (etw)); -} - -static void -etw_proxy_model_changed (ETableSubset *etss, - ETableModel *etm) -{ - gint i; /* Model row */ - gint j; /* View row */ - gint row_count; - ETableWithout *etw = E_TABLE_WITHOUT (etss); - - g_free (etss->map_table); - row_count = e_table_model_row_count (etm); - etss->map_table = g_new (int, row_count); - - for (i = 0, j = 0; i < row_count; i++) { - if (!check (etw, i)) { - etss->map_table[j++] = i; - } - } - etss->n_map = j; - - if (E_TABLE_SUBSET_CLASS (etw_parent_class)->proxy_model_changed) - E_TABLE_SUBSET_CLASS (etw_parent_class)->proxy_model_changed (etss, etm); -} - -static void -etw_class_init (ETableWithoutClass *class) -{ - GObjectClass *object_class; - ETableSubsetClass *etss_class; - - g_type_class_add_private (class, sizeof (ETableWithoutPrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->dispose = etw_dispose; - - etss_class = E_TABLE_SUBSET_CLASS (class); - etss_class->proxy_model_rows_inserted = etw_proxy_model_rows_inserted; - etss_class->proxy_model_rows_deleted = etw_proxy_model_rows_deleted; - etss_class->proxy_model_changed = etw_proxy_model_changed; -} - -static void -etw_init (ETableWithout *etw) -{ - etw->priv = E_TABLE_WITHOUT_GET_PRIVATE (etw); -} - -ETableModel * -e_table_without_construct (ETableWithout *etw, - ETableModel *source, - GHashFunc hash_func, - GCompareFunc compare_func, - ETableWithoutGetKeyFunc get_key_func, - ETableWithoutDuplicateKeyFunc duplicate_key_func, - ETableWithoutFreeKeyFunc free_gotten_key_func, - ETableWithoutFreeKeyFunc free_duplicated_key_func, - gpointer closure) -{ - if (e_table_subset_construct (E_TABLE_SUBSET (etw), source, 1) == NULL) - return NULL; - E_TABLE_SUBSET (etw)->n_map = 0; - - etw->priv->hash_func = hash_func; - etw->priv->compare_func = compare_func; - etw->priv->get_key_func = get_key_func; - etw->priv->duplicate_key_func = duplicate_key_func; - etw->priv->free_gotten_key_func = free_gotten_key_func; - etw->priv->free_duplicated_key_func = free_duplicated_key_func; - etw->priv->closure = closure; - - etw->priv->hash = g_hash_table_new ( - etw->priv->hash_func, etw->priv->compare_func); - - return E_TABLE_MODEL (etw); -} - -ETableModel * -e_table_without_new (ETableModel *source, - GHashFunc hash_func, - GCompareFunc compare_func, - ETableWithoutGetKeyFunc get_key_func, - ETableWithoutDuplicateKeyFunc duplicate_key_func, - ETableWithoutFreeKeyFunc free_gotten_key_func, - ETableWithoutFreeKeyFunc free_duplicated_key_func, - gpointer closure) -{ - ETableWithout *etw = g_object_new (E_TYPE_TABLE_WITHOUT, NULL); - - if (e_table_without_construct (etw, - source, - hash_func, - compare_func, - get_key_func, - duplicate_key_func, - free_gotten_key_func, - free_duplicated_key_func, - closure) - == NULL) { - g_object_unref (etw); - return NULL; - } - - return (ETableModel *) etw; -} - -void -e_table_without_hide (ETableWithout *etw, - gpointer key) -{ - gint i; /* View row */ - ETableSubset *etss = E_TABLE_SUBSET (etw); - - if (etw->priv->duplicate_key_func) - key = etw->priv->duplicate_key_func (key, etw->priv->closure); - - g_hash_table_insert (etw->priv->hash, key, key); - for (i = 0; i < etss->n_map; i++) { - if (check_with_key (etw, key, etw_view_to_model_row (etw, i))) { - remove_row (etw, i); - i--; - } - } -} - -/* An adopted key will later be freed using the free_duplicated_key function. */ -void -e_table_without_hide_adopt (ETableWithout *etw, - gpointer key) -{ - gint i; /* View row */ - ETableSubset *etss = E_TABLE_SUBSET (etw); - - g_hash_table_insert (etw->priv->hash, key, key); - for (i = 0; i < etss->n_map; i++) { - if (check_with_key (etw, key, etw_view_to_model_row (etw, i))) { - remove_row (etw, i); - i--; - } - } -} - -void -e_table_without_show (ETableWithout *etw, - gpointer key) -{ - gint i; /* Model row */ - ETableSubset *etss = E_TABLE_SUBSET (etw); - gint count; - gpointer old_key; - - count = e_table_model_row_count (etss->source); - - for (i = 0; i < count; i++) { - if (check_with_key (etw, key, i)) { - add_row (etw, i); - } - } - if (g_hash_table_lookup_extended (etw->priv->hash, key, &old_key, NULL)) { -#if 0 - if (etw->priv->free_duplicated_key_func) - etw->priv->free_duplicated_key_func (key, etw->priv->closure); -#endif - g_hash_table_remove (etw->priv->hash, key); - } -} - -void -e_table_without_show_all (ETableWithout *etw) -{ - gint i; /* Model row */ - gint row_count; - ETableSubset *etss = E_TABLE_SUBSET (etw); - - e_table_model_pre_change (E_TABLE_MODEL (etw)); - - if (etw->priv->hash) { - g_hash_table_foreach (etw->priv->hash, delete_hash_element, etw); - g_hash_table_destroy (etw->priv->hash); - etw->priv->hash = NULL; - } - etw->priv->hash = g_hash_table_new ( - etw->priv->hash_func, etw->priv->compare_func); - - row_count = e_table_model_row_count (E_TABLE_MODEL (etss->source)); - g_free (etss->map_table); - etss->map_table = g_new (int, row_count); - - for (i = 0; i < row_count; i++) { - etss->map_table[i] = i; - } - etss->n_map = row_count; - - e_table_model_changed (E_TABLE_MODEL (etw)); -} diff --git a/widgets/table/e-table-without.h b/widgets/table/e-table-without.h deleted file mode 100644 index 03e1db6702..0000000000 --- a/widgets/table/e-table-without.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_WITHOUT_H_ -#define _E_TABLE_WITHOUT_H_ - -#include <table/e-table-subset.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE_WITHOUT \ - (e_table_without_get_type ()) -#define E_TABLE_WITHOUT(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE_WITHOUT, ETableWithout)) -#define E_TABLE_WITHOUT_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE_WITHOUT, ETableWithoutClass)) -#define E_IS_TABLE_WITHOUT(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE_WITHOUT)) -#define E_IS_TABLE_WITHOUT_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE_WITHOUT)) -#define E_TABLE_WITHOUT_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE_WITHOUT, ETableWithoutClass)) - -G_BEGIN_DECLS - -typedef struct _ETableWithout ETableWithout; -typedef struct _ETableWithoutClass ETableWithoutClass; -typedef struct _ETableWithoutPrivate ETableWithoutPrivate; - -typedef gpointer (*ETableWithoutGetKeyFunc) (ETableModel *source, - gint row, - gpointer closure); -typedef gpointer (*ETableWithoutDuplicateKeyFunc)(gconstpointer key, - gpointer closure); -typedef void (*ETableWithoutFreeKeyFunc) (gpointer key, - gpointer closure); - -struct _ETableWithout { - ETableSubset parent; - ETableWithoutPrivate *priv; -}; - -struct _ETableWithoutClass { - ETableSubsetClass parent_class; -}; - -GType e_table_without_get_type (void) G_GNUC_CONST; -ETableModel * e_table_without_new (ETableModel *source, - GHashFunc hash_func, - GCompareFunc compare_func, - ETableWithoutGetKeyFunc get_key_func, - ETableWithoutDuplicateKeyFunc duplicate_key_func, - ETableWithoutFreeKeyFunc free_gotten_key_func, - ETableWithoutFreeKeyFunc free_duplicated_key_func, - gpointer closure); -ETableModel * e_table_without_construct (ETableWithout *etw, - ETableModel *source, - GHashFunc hash_func, - GCompareFunc compare_func, - ETableWithoutGetKeyFunc get_key_func, - ETableWithoutDuplicateKeyFunc duplicate_key_func, - ETableWithoutFreeKeyFunc free_gotten_key_func, - ETableWithoutFreeKeyFunc free_duplicated_key_func, - gpointer closure); -void e_table_without_hide (ETableWithout *etw, - gpointer key); -void e_table_without_hide_adopt (ETableWithout *etw, - gpointer key); -void e_table_without_show (ETableWithout *etw, - gpointer key); -void e_table_without_show_all (ETableWithout *etw); - -G_END_DECLS - -#endif /* _E_TABLE_WITHOUT_H_ */ - diff --git a/widgets/table/e-table.c b/widgets/table/e-table.c deleted file mode 100644 index b73ae55ba6..0000000000 --- a/widgets/table/e-table.c +++ /dev/null @@ -1,3626 +0,0 @@ -/* - * e-table.c - A graphical view of a Table. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <string.h> -#include <stdio.h> - -#include <glib/gstdio.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> -#include <libgnomecanvas/libgnomecanvas.h> - -#include "gal-a11y-e-table.h" -#include <glib/gi18n.h> -#include "e-util/e-util.h" -#include "misc/e-canvas.h" -#include "misc/e-canvas-background.h" -#include "misc/e-canvas-vbox.h" -#include "e-util/e-unicode.h" - -#include "e-table.h" -#include "e-table-click-to-add.h" -#include "e-table-column-specification.h" -#include "e-table-group-leaf.h" -#include "e-table-header-item.h" -#include "e-table-header-utils.h" -#include "e-table-subset.h" -#include "e-table-utils.h" - -#define COLUMN_HEADER_HEIGHT 16 - -#define d(x) - -#if d(!)0 -#define e_table_item_leave_edit_(x) \ - (e_table_item_leave_edit ((x)), \ - g_print ("%s: e_table_item_leave_edit\n", __FUNCTION__)) -#else -#define e_table_item_leave_edit_(x) (e_table_item_leave_edit((x))) -#endif - -enum { - CURSOR_CHANGE, - CURSOR_ACTIVATED, - SELECTION_CHANGE, - DOUBLE_CLICK, - RIGHT_CLICK, - CLICK, - KEY_PRESS, - START_DRAG, - STATE_CHANGE, - WHITE_SPACE_EVENT, - - CUT_CLIPBOARD, - COPY_CLIPBOARD, - PASTE_CLIPBOARD, - SELECT_ALL, - - 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 { - PROP_0, - PROP_LENGTH_THRESHOLD, - PROP_MODEL, - PROP_UNIFORM_ROW_HEIGHT, - PROP_ALWAYS_SEARCH, - PROP_USE_CLICK_TO_ADD, - PROP_HADJUSTMENT, - PROP_VADJUSTMENT, - PROP_HSCROLL_POLICY, - PROP_VSCROLL_POLICY -}; - -enum { - ET_SCROLL_UP = 1 << 0, - ET_SCROLL_DOWN = 1 << 1, - ET_SCROLL_LEFT = 1 << 2, - ET_SCROLL_RIGHT = 1 << 3 -}; - -static guint 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 et_focus (GtkWidget *container, GtkDirectionType direction); - -static void scroll_off (ETable *et); -static void scroll_on (ETable *et, guint scroll_direction); - -G_DEFINE_TYPE_WITH_CODE (ETable, e_table, GTK_TYPE_TABLE, - G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL)) - -static void -et_disconnect_model (ETable *et) -{ - if (et->model == NULL) - return; - - if (et->table_model_change_id != 0) - g_signal_handler_disconnect ( - et->model, et->table_model_change_id); - if (et->table_row_change_id != 0) - g_signal_handler_disconnect ( - et->model, et->table_row_change_id); - if (et->table_cell_change_id != 0) - g_signal_handler_disconnect ( - et->model, et->table_cell_change_id); - if (et->table_rows_inserted_id != 0) - g_signal_handler_disconnect ( - et->model, et->table_rows_inserted_id); - if (et->table_rows_deleted_id != 0) - g_signal_handler_disconnect ( - et->model, et->table_rows_deleted_id); - - et->table_model_change_id = 0; - et->table_row_change_id = 0; - et->table_cell_change_id = 0; - et->table_rows_inserted_id = 0; - et->table_rows_deleted_id = 0; -} - -static void -e_table_state_change (ETable *et) -{ - if (et->state_change_freeze) - et->state_changed = TRUE; - else - g_signal_emit (et, et_signals[STATE_CHANGE], 0); -} - -#define CHECK_HORIZONTAL(et) \ - if ((et)->horizontal_scrolling || (et)->horizontal_resize) \ - e_table_header_update_horizontal (et->header); - -static void -clear_current_search_col (ETable *et) -{ - et->search_col_set = FALSE; -} - -static ETableCol * -current_search_col (ETable *et) -{ - if (!et->search_col_set) { - et->current_search_col = - e_table_util_calculate_current_search_col ( - et->header, - et->full_header, - et->sort_info, - et->always_search); - et->search_col_set = TRUE; - } - - return et->current_search_col; -} - -static void -et_get_preferred_width (GtkWidget *widget, - gint *minimum, - gint *natural) -{ - ETable *et = E_TABLE (widget); - - GTK_WIDGET_CLASS (e_table_parent_class)-> - get_preferred_width (widget, minimum, natural); - - if (et->horizontal_resize) { - *minimum = MAX (*minimum, et->header_width); - *natural = MAX (*natural, et->header_width); - } -} - -static void -et_get_preferred_height (GtkWidget *widget, - gint *minimum, - gint *natural) -{ - GTK_WIDGET_CLASS (e_table_parent_class)-> - get_preferred_height (widget, minimum, natural); -} - -static void -set_header_width (ETable *et) -{ - if (et->horizontal_resize) { - et->header_width = e_table_header_min_width (et->header); - gtk_widget_queue_resize (GTK_WIDGET (et)); - } -} - -static void -structure_changed (ETableHeader *header, - ETable *et) -{ - e_table_state_change (et); - set_header_width (et); - clear_current_search_col (et); -} - -static void -expansion_changed (ETableHeader *header, - ETable *et) -{ - e_table_state_change (et); - set_header_width (et); -} - -static void -dimension_changed (ETableHeader *header, - gint total_width, - ETable *et) -{ - set_header_width (et); -} - -static void -disconnect_header (ETable *e_table) -{ - if (e_table->header == NULL) - return; - - if (e_table->structure_change_id) - g_signal_handler_disconnect ( - e_table->header, e_table->structure_change_id); - if (e_table->expansion_change_id) - g_signal_handler_disconnect ( - e_table->header, e_table->expansion_change_id); - if (e_table->dimension_change_id) - g_signal_handler_disconnect ( - e_table->header, e_table->dimension_change_id); - - g_object_unref (e_table->header); - e_table->header = NULL; -} - -static void -connect_header (ETable *e_table, - ETableState *state) -{ - if (e_table->header != NULL) - disconnect_header (e_table); - - e_table->header = e_table_state_to_header ( - GTK_WIDGET (e_table), e_table->full_header, state); - - e_table->structure_change_id = g_signal_connect ( - e_table->header, "structure_change", - G_CALLBACK (structure_changed), e_table); - e_table->expansion_change_id = g_signal_connect ( - e_table->header, "expansion_change", - G_CALLBACK (expansion_changed), e_table); - e_table->dimension_change_id = g_signal_connect ( - e_table->header, "dimension_change", - G_CALLBACK (dimension_changed), e_table); -} - -static void -et_dispose (GObject *object) -{ - ETable *et = E_TABLE (object); - - et_disconnect_model (et); - - if (et->search) { - if (et->search_search_id) - g_signal_handler_disconnect ( - et->search, et->search_search_id); - if (et->search_accept_id) - g_signal_handler_disconnect ( - et->search, et->search_accept_id); - g_object_unref (et->search); - et->search = NULL; - } - - if (et->group_info_change_id) { - g_signal_handler_disconnect ( - et->sort_info, et->group_info_change_id); - et->group_info_change_id = 0; - } - - if (et->sort_info_change_id) { - g_signal_handler_disconnect ( - et->sort_info, et->sort_info_change_id); - et->sort_info_change_id = 0; - } - - if (et->reflow_idle_id) { - g_source_remove (et->reflow_idle_id); - et->reflow_idle_id = 0; - } - - scroll_off (et); - - disconnect_header (et); - - if (et->model) { - g_object_unref (et->model); - et->model = NULL; - } - - if (et->full_header) { - g_object_unref (et->full_header); - et->full_header = NULL; - } - - if (et->sort_info) { - g_object_unref (et->sort_info); - et->sort_info = NULL; - } - - if (et->sorter) { - g_object_unref (et->sorter); - et->sorter = NULL; - } - - if (et->selection) { - g_object_unref (et->selection); - et->selection = NULL; - } - - if (et->spec) { - g_object_unref (et->spec); - et->spec = NULL; - } - - if (et->header_canvas != NULL) { - gtk_widget_destroy (GTK_WIDGET (et->header_canvas)); - et->header_canvas = NULL; - } - - if (et->site != NULL) { - e_table_drag_source_unset (et); - et->site = NULL; - } - - if (et->table_canvas != NULL) { - gtk_widget_destroy (GTK_WIDGET (et->table_canvas)); - et->table_canvas = NULL; - } - - if (et->rebuild_idle_id != 0) { - g_source_remove (et->rebuild_idle_id); - et->rebuild_idle_id = 0; - } - - g_free (et->click_to_add_message); - et->click_to_add_message = NULL; - - g_free (et->domain); - et->domain = NULL; - - G_OBJECT_CLASS (e_table_parent_class)->dispose (object); -} - -static void -et_unrealize (GtkWidget *widget) -{ - scroll_off (E_TABLE (widget)); - - if (GTK_WIDGET_CLASS (e_table_parent_class)->unrealize) - GTK_WIDGET_CLASS (e_table_parent_class)->unrealize (widget); -} - -static gboolean -check_row (ETable *et, - gint model_row, - gint col, - ETableSearchFunc search, - gchar *string) -{ - gconstpointer value; - - value = e_table_model_value_at (et->model, col, model_row); - - return search (value, string); -} - -static gboolean -et_search_search (ETableSearch *search, - gchar *string, - ETableSearchFlags flags, - ETable *et) -{ - gint cursor; - gint rows; - gint i; - ETableCol *col = current_search_col (et); - - if (col == NULL) - return FALSE; - - rows = e_table_model_row_count (et->model); - - g_object_get ( - et->selection, - "cursor_row", &cursor, - NULL); - - if ((flags & E_TABLE_SEARCH_FLAGS_CHECK_CURSOR_FIRST) && - cursor < rows && cursor >= 0 && - check_row (et, cursor, col->col_idx, col->search, string)) - return TRUE; - - cursor = e_sorter_model_to_sorted (E_SORTER (et->sorter), cursor); - - for (i = cursor + 1; i < rows; i++) { - gint model_row = e_sorter_sorted_to_model (E_SORTER (et->sorter), i); - if (check_row (et, model_row, col->col_idx, col->search, string)) { - e_selection_model_select_as_key_press ( - E_SELECTION_MODEL (et->selection), - model_row, col->col_idx, GDK_CONTROL_MASK); - return TRUE; - } - } - - for (i = 0; i < cursor; i++) { - gint model_row = e_sorter_sorted_to_model (E_SORTER (et->sorter), i); - if (check_row (et, model_row, col->col_idx, col->search, string)) { - e_selection_model_select_as_key_press ( - E_SELECTION_MODEL (et->selection), - model_row, col->col_idx, GDK_CONTROL_MASK); - return TRUE; - } - } - - cursor = e_sorter_sorted_to_model (E_SORTER (et->sorter), cursor); - - /* Check if the cursor row is the only matching row. */ - return (!(flags & E_TABLE_SEARCH_FLAGS_CHECK_CURSOR_FIRST) && - cursor < rows && cursor >= 0 && - check_row (et, cursor, col->col_idx, col->search, string)); -} - -static void -et_search_accept (ETableSearch *search, - ETable *et) -{ - gint cursor; - ETableCol *col = current_search_col (et); - - if (col == NULL) - return; - - g_object_get (et->selection, "cursor_row", &cursor, NULL); - - e_selection_model_select_as_key_press ( - E_SELECTION_MODEL (et->selection), cursor, col->col_idx, 0); -} - -static void -init_search (ETable *e_table) -{ - if (e_table->search != NULL) - return; - - e_table->search = e_table_search_new (); - - e_table->search_search_id = g_signal_connect ( - e_table->search, "search", - G_CALLBACK (et_search_search), e_table); - e_table->search_accept_id = g_signal_connect ( - e_table->search, "accept", - G_CALLBACK (et_search_accept), e_table); -} - -static void -et_finalize (GObject *object) -{ - ETable *et = E_TABLE (object); - - g_free (et->click_to_add_message); - et->click_to_add_message = NULL; - - g_free (et->domain); - et->domain = NULL; - - G_OBJECT_CLASS (e_table_parent_class)->finalize (object); -} - -static void -e_table_init (ETable *e_table) -{ - gtk_widget_set_can_focus (GTK_WIDGET (e_table), TRUE); - - gtk_table_set_homogeneous (GTK_TABLE (e_table), FALSE); - - e_table->sort_info = NULL; - e_table->group_info_change_id = 0; - e_table->sort_info_change_id = 0; - e_table->structure_change_id = 0; - e_table->expansion_change_id = 0; - e_table->dimension_change_id = 0; - e_table->reflow_idle_id = 0; - e_table->scroll_idle_id = 0; - - e_table->alternating_row_colors = 1; - e_table->horizontal_draw_grid = 1; - e_table->vertical_draw_grid = 1; - e_table->draw_focus = 1; - e_table->cursor_mode = E_CURSOR_SIMPLE; - e_table->length_threshold = 200; - e_table->uniform_row_height = FALSE; - - e_table->need_rebuild = 0; - e_table->rebuild_idle_id = 0; - - e_table->horizontal_scrolling = FALSE; - e_table->horizontal_resize = FALSE; - - e_table->click_to_add_message = NULL; - e_table->domain = NULL; - - e_table->drop_row = -1; - e_table->drop_col = -1; - e_table->site = NULL; - - e_table->do_drag = 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; - - e_table->always_search = g_getenv ("GAL_ALWAYS_SEARCH") ? TRUE : FALSE; - - e_table->search = NULL; - e_table->search_search_id = 0; - e_table->search_accept_id = 0; - - e_table->current_search_col = NULL; - - e_table->header_width = 0; - - e_table->state_changed = FALSE; - e_table->state_change_freeze = 0; -} - -/* 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 (GtkWidget *container, - GtkDirectionType direction) -{ - ETable *e_table; - - e_table = E_TABLE (container); - - if (gtk_container_get_focus_child (GTK_CONTAINER (container))) { - gtk_container_set_focus_child (GTK_CONTAINER (container), NULL); - return FALSE; - } - - return gtk_widget_child_focus (GTK_WIDGET (e_table->table_canvas), direction); -} - -static void -set_header_canvas_width (ETable *e_table) -{ - gdouble oldwidth, oldheight, width; - - if (!(e_table->header_item && e_table->header_canvas && e_table->table_canvas)) - return; - - gnome_canvas_get_scroll_region ( - GNOME_CANVAS (e_table->table_canvas), - NULL, NULL, &width, NULL); - gnome_canvas_get_scroll_region ( - GNOME_CANVAS (e_table->header_canvas), - NULL, NULL, &oldwidth, &oldheight); - - if (oldwidth != width || - oldheight != E_TABLE_HEADER_ITEM (e_table->header_item)->height - 1) - gnome_canvas_set_scroll_region ( - GNOME_CANVAS (e_table->header_canvas), - 0, 0, width, /* COLUMN_HEADER_HEIGHT - 1 */ - E_TABLE_HEADER_ITEM (e_table->header_item)->height - 1); - -} - -static void -header_canvas_size_allocate (GtkWidget *widget, - GtkAllocation *alloc, - ETable *e_table) -{ - GtkAllocation allocation; - - set_header_canvas_width (e_table); - - gtk_widget_get_allocation ( - GTK_WIDGET (e_table->header_canvas), &allocation); - - /* 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 (allocation.height != E_TABLE_HEADER_ITEM (e_table->header_item)->height) - g_object_set ( - e_table->header_canvas, "height-request", - E_TABLE_HEADER_ITEM (e_table->header_item)->height, - NULL); -} - -static void -group_info_changed (ETableSortInfo *info, - ETable *et) -{ - gboolean will_be_grouped = e_table_sort_info_grouping_get_count (info) > 0; - clear_current_search_col (et); - if (et->is_grouped || will_be_grouped) { - et->need_rebuild = TRUE; - if (!et->rebuild_idle_id) { - g_object_run_dispose (G_OBJECT (et->group)); - et->group = NULL; - et->rebuild_idle_id = g_idle_add_full (20, changed_idle, et, NULL); - } - } - e_table_state_change (et); -} - -static void -sort_info_changed (ETableSortInfo *info, - ETable *et) -{ - clear_current_search_col (et); - e_table_state_change (et); -} - -static void -e_table_setup_header (ETable *e_table) -{ - gchar *pointer; - e_table->header_canvas = GNOME_CANVAS (e_canvas_new ()); - - gtk_widget_show (GTK_WIDGET (e_table->header_canvas)); - - pointer = g_strdup_printf ("%p", (gpointer) 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); - - g_signal_connect ( - e_table->header_canvas, "size_allocate", - G_CALLBACK (header_canvas_size_allocate), e_table); - - g_object_set ( - e_table->header_canvas, "height-request", - E_TABLE_HEADER_ITEM (e_table->header_item)->height, NULL); -} - -static gboolean -table_canvas_reflow_idle (ETable *e_table) -{ - gdouble height, width; - gdouble oldheight, oldwidth; - GtkAllocation allocation; - - gtk_widget_get_allocation ( - GTK_WIDGET (e_table->table_canvas), &allocation); - - g_object_get ( - e_table->canvas_vbox, - "height", &height, "width", &width, NULL); - height = MAX ((gint) height, allocation.height); - width = MAX ((gint) width, allocation.width); - /* I have no idea why this needs to be -1, but it works. */ - gnome_canvas_get_scroll_region ( - GNOME_CANVAS (e_table->table_canvas), - NULL, NULL, &oldwidth, &oldheight); - - if (oldwidth != width - 1 || - oldheight != height - 1) { - gnome_canvas_set_scroll_region ( - GNOME_CANVAS (e_table->table_canvas), - 0, 0, width - 1, height - 1); - set_header_canvas_width (e_table); - } - 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; - GValue *val = g_new0 (GValue, 1); - g_value_init (val, G_TYPE_DOUBLE); - - width = alloc->width; - g_value_set_double (val, width); - g_object_get ( - e_table->canvas_vbox, - "height", &height, - NULL); - height = MAX ((gint) height, alloc->height); - - g_object_set ( - e_table->canvas_vbox, - "width", width, - NULL); - g_object_set_property (G_OBJECT (e_table->header), "width", val); - g_free (val); - if (e_table->reflow_idle_id) - g_source_remove (e_table->reflow_idle_id); - table_canvas_reflow_idle (e_table); - - e_table->size_allocated = TRUE; - - if (e_table->need_rebuild && !e_table->rebuild_idle_id) - e_table->rebuild_idle_id = g_idle_add_full (20, changed_idle, e_table, NULL); -} - -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, - gint row, - gint col, - ETable *et) -{ - if (et->cursor_loc == E_TABLE_CURSOR_LOC_TABLE) { - e_selection_model_clear (E_SELECTION_MODEL (et->selection)); - } - et->cursor_loc = E_TABLE_CURSOR_LOC_ETCTA; -} - -static void -group_cursor_change (ETableGroup *etg, - gint row, - ETable *et) -{ - ETableCursorLoc old_cursor_loc; - - old_cursor_loc = et->cursor_loc; - - et->cursor_loc = E_TABLE_CURSOR_LOC_TABLE; - g_signal_emit (et, et_signals[CURSOR_CHANGE], 0, row); - - if (old_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)); -} - -static void -group_cursor_activated (ETableGroup *etg, - gint row, - ETable *et) -{ - g_signal_emit (et, et_signals[CURSOR_ACTIVATED], 0, row); -} - -static void -group_double_click (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event, - ETable *et) -{ - g_signal_emit (et, et_signals[DOUBLE_CLICK], 0, row, col, event); -} - -static gboolean -group_right_click (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event, - ETable *et) -{ - gboolean return_val = FALSE; - - g_signal_emit ( - et, et_signals[RIGHT_CLICK], 0, - row, col, event, &return_val); - - return return_val; -} - -static gboolean -group_click (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event, - ETable *et) -{ - gboolean return_val = 0; - - g_signal_emit ( - et, et_signals[CLICK], 0, - row, col, event, &return_val); - - return return_val; -} - -static gboolean -group_key_press (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event, - ETable *et) -{ - gboolean return_val = FALSE; - GdkEventKey *key = (GdkEventKey *) event; - gint y, row_local, col_local; - GtkAdjustment *adjustment; - GtkScrollable *scrollable; - gdouble page_size; - gdouble upper; - gdouble value; - - scrollable = GTK_SCROLLABLE (et->table_canvas); - adjustment = gtk_scrollable_get_vadjustment (scrollable); - - switch (key->keyval) { - case GDK_KEY_Page_Down: - case GDK_KEY_KP_Page_Down: - page_size = gtk_adjustment_get_page_size (adjustment); - upper = gtk_adjustment_get_value (adjustment); - value = gtk_adjustment_get_value (adjustment); - - y = CLAMP (value + (2 * page_size - 50), 0, upper); - y -= value; - e_table_get_cell_at (et, 30, y, &row_local, &col_local); - - if (row_local == -1) - row_local = e_table_model_row_count (et->model) - 1; - - row_local = e_table_view_to_model_row (et, row_local); - col_local = e_selection_model_cursor_col (E_SELECTION_MODEL (et->selection)); - e_selection_model_select_as_key_press ( - E_SELECTION_MODEL (et->selection), - row_local, col_local, key->state); - return_val = 1; - break; - case GDK_KEY_Page_Up: - case GDK_KEY_KP_Page_Up: - page_size = gtk_adjustment_get_page_size (adjustment); - upper = gtk_adjustment_get_upper (adjustment); - value = gtk_adjustment_get_value (adjustment); - - y = CLAMP (value - (page_size - 50), 0, upper); - y -= value; - e_table_get_cell_at (et, 30, y, &row_local, &col_local); - - if (row_local == -1) - row_local = 0; - - row_local = e_table_view_to_model_row (et, row_local); - col_local = e_selection_model_cursor_col (E_SELECTION_MODEL (et->selection)); - e_selection_model_select_as_key_press ( - E_SELECTION_MODEL (et->selection), - row_local, col_local, key->state); - return_val = 1; - break; - case GDK_KEY_BackSpace: - init_search (et); - if (e_table_search_backspace (et->search)) - return TRUE; - /* Fall through */ - default: - init_search (et); - if ((key->state & ~(GDK_SHIFT_MASK | GDK_LOCK_MASK | - GDK_MOD1_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK | - GDK_MOD4_MASK | GDK_MOD5_MASK)) == 0 - && ((key->keyval >= GDK_KEY_a && key->keyval <= GDK_KEY_z) || - (key->keyval >= GDK_KEY_A && key->keyval <= GDK_KEY_Z) || - (key->keyval >= GDK_KEY_0 && key->keyval <= GDK_KEY_9))) - e_table_search_input_character (et->search, key->keyval); - g_signal_emit ( - et, et_signals[KEY_PRESS], 0, - row, col, event, &return_val); - break; - } - return return_val; -} - -static gboolean -group_start_drag (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event, - ETable *et) -{ - gboolean return_val = TRUE; - - g_signal_emit ( - et, et_signals[START_DRAG], 0, - row, col, event, &return_val); - - return return_val; -} - -static void -et_table_model_changed (ETableModel *model, - ETable *et) -{ - et->need_rebuild = TRUE; - if (!et->rebuild_idle_id) { - g_object_run_dispose (G_OBJECT (et->group)); - et->group = NULL; - et->rebuild_idle_id = g_idle_add_full (20, changed_idle, et, NULL); - } -} - -static void -et_table_row_changed (ETableModel *table_model, - gint row, - ETable *et) -{ - if (!et->need_rebuild) { - if (e_table_group_remove (et->group, row)) - e_table_group_add (et->group, row); - CHECK_HORIZONTAL (et); - } -} - -static void -et_table_cell_changed (ETableModel *table_model, - gint view_col, - gint row, - ETable *et) -{ - et_table_row_changed (table_model, row, et); -} - -static void -et_table_rows_inserted (ETableModel *table_model, - gint row, - gint count, - ETable *et) -{ - /* This number has already been decremented. */ - gint row_count = e_table_model_row_count (table_model); - if (!et->need_rebuild) { - gint i; - if (row != row_count - count) - e_table_group_increment (et->group, row, count); - for (i = 0; i < count; i++) - e_table_group_add (et->group, row + i); - CHECK_HORIZONTAL (et); - } -} - -static void -et_table_rows_deleted (ETableModel *table_model, - gint row, - gint count, - ETable *et) -{ - gint row_count = e_table_model_row_count (table_model); - if (!et->need_rebuild) { - gint i; - for (i = 0; i < count; i++) - e_table_group_remove (et->group, row + i); - if (row != row_count) - e_table_group_decrement (et->group, row, count); - CHECK_HORIZONTAL (et); - } -} - -static void -et_build_groups (ETable *et) -{ - gboolean was_grouped = et->is_grouped; - - et->is_grouped = e_table_sort_info_grouping_get_count (et->sort_info) > 0; - - et->group = e_table_group_new ( - GNOME_CANVAS_GROUP (et->canvas_vbox), - et->full_header, - et->header, - et->model, - et->sort_info, - 0); - - if (et->use_click_to_add_end) - e_canvas_vbox_add_item_start ( - E_CANVAS_VBOX (et->canvas_vbox), - GNOME_CANVAS_ITEM (et->group)); - else - 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), - "alternating_row_colors", et->alternating_row_colors, - "horizontal_draw_grid", et->horizontal_draw_grid, - "vertical_draw_grid", et->vertical_draw_grid, - "drawfocus", et->draw_focus, - "cursor_mode", et->cursor_mode, - "length_threshold", et->length_threshold, - "uniform_row_height", et->uniform_row_height, - "selection_model", et->selection, - NULL); - - g_signal_connect ( - et->group, "cursor_change", - G_CALLBACK (group_cursor_change), et); - g_signal_connect ( - et->group, "cursor_activated", - G_CALLBACK (group_cursor_activated), et); - g_signal_connect ( - et->group, "double_click", - G_CALLBACK (group_double_click), et); - g_signal_connect ( - et->group, "right_click", - G_CALLBACK (group_right_click), et); - g_signal_connect ( - et->group, "click", - G_CALLBACK (group_click), et); - g_signal_connect ( - et->group, "key_press", - G_CALLBACK (group_key_press), et); - g_signal_connect ( - et->group, "start_drag", - G_CALLBACK (group_start_drag), et); - - if (!(et->is_grouped) && was_grouped) - et_disconnect_model (et); - - if (et->is_grouped && (!was_grouped)) { - et->table_model_change_id = g_signal_connect ( - et->model, "model_changed", - G_CALLBACK (et_table_model_changed), et); - - et->table_row_change_id = g_signal_connect ( - et->model, "model_row_changed", - G_CALLBACK (et_table_row_changed), et); - - et->table_cell_change_id = g_signal_connect ( - et->model, "model_cell_changed", - G_CALLBACK (et_table_cell_changed), et); - - et->table_rows_inserted_id = g_signal_connect ( - et->model, "model_rows_inserted", - G_CALLBACK (et_table_rows_inserted), et); - - et->table_rows_deleted_id = g_signal_connect ( - et->model, "model_rows_deleted", - G_CALLBACK (et_table_rows_deleted), et); - - } - - if (et->is_grouped) - e_table_fill_table (et, et->model); -} - -static gboolean -changed_idle (gpointer data) -{ - ETable *et = E_TABLE (data); - - /* Wait until we have a valid size allocation. */ - if (et->need_rebuild && et->size_allocated) { - GtkWidget *widget; - GtkAllocation allocation; - - if (et->group) - g_object_run_dispose (G_OBJECT (et->group)); - et_build_groups (et); - - widget = GTK_WIDGET (et->table_canvas); - gtk_widget_get_allocation (widget, &allocation); - - g_object_set ( - et->canvas_vbox, - "width", (gdouble) allocation.width, - NULL); - - table_canvas_size_allocate (widget, &allocation, et); - - et->need_rebuild = 0; - } - - et->rebuild_idle_id = 0; - - CHECK_HORIZONTAL (et); - - return FALSE; -} - -static void -et_canvas_realize (GtkWidget *canvas, - ETable *e_table) -{ - GtkWidget *widget; - GtkStyle *style; - - widget = GTK_WIDGET (e_table->table_canvas); - style = gtk_widget_get_style (widget); - - gnome_canvas_item_set ( - e_table->white_item, - "fill_color_gdk", &style->base[GTK_STATE_NORMAL], - NULL); - - CHECK_HORIZONTAL (e_table); - set_header_width (e_table); -} - -static gboolean -white_item_event (GnomeCanvasItem *white_item, - GdkEvent *event, - ETable *e_table) -{ - gboolean return_val = 0; - - g_signal_emit ( - e_table, et_signals[WHITE_SPACE_EVENT], 0, - event, &return_val); - - return return_val; -} - -static void -et_eti_leave_edit (ETable *et) -{ - GnomeCanvas *canvas = et->table_canvas; - - if (gtk_widget_has_focus (GTK_WIDGET (canvas))) { - GnomeCanvasItem *item = GNOME_CANVAS (canvas)->focused_item; - - if (E_IS_TABLE_ITEM (item)) { - e_table_item_leave_edit_(E_TABLE_ITEM (item)); - } - } -} - -static gint -et_canvas_root_event (GnomeCanvasItem *root, - GdkEvent *event, - ETable *e_table) -{ - switch (event->type) { - case GDK_BUTTON_PRESS: - case GDK_2BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - if (event->button.button != 4 && event->button.button != 5) { - et_eti_leave_edit (e_table); - return TRUE; - } - break; - default: - break; - } - - return FALSE; -} - -/* Finds the first descendant of the group that is an ETableItem and focuses it */ -static void -focus_first_etable_item (ETableGroup *group) -{ - GnomeCanvasGroup *cgroup; - GList *l; - - cgroup = GNOME_CANVAS_GROUP (group); - - for (l = cgroup->item_list; l; l = l->next) { - GnomeCanvasItem *i; - - i = GNOME_CANVAS_ITEM (l->data); - - if (E_IS_TABLE_GROUP (i)) - focus_first_etable_item (E_TABLE_GROUP (i)); - else if (E_IS_TABLE_ITEM (i)) { - e_table_item_set_cursor (E_TABLE_ITEM (i), 0, 0); - gnome_canvas_item_grab_focus (i); - } - } -} - -/* Handler for focus events in the table_canvas; we have to repaint ourselves - * always, and also give the focus to some ETableItem if we get focused. - */ -static gint -table_canvas_focus_event_cb (GtkWidget *widget, - GdkEventFocus *event, - gpointer data) -{ - GnomeCanvas *canvas; - ECanvas *ecanvas; - ETable *etable; - - gtk_widget_queue_draw (widget); - canvas = GNOME_CANVAS (widget); - ecanvas = E_CANVAS (widget); - - if (!event->in) { - gtk_im_context_focus_out (ecanvas->im_context); - return FALSE; - } else { - gtk_im_context_focus_in (ecanvas->im_context); - } - - etable = E_TABLE (data); - - if (e_table_model_row_count (etable->model) < 1 - && (etable->click_to_add) - && !(E_TABLE_CLICK_TO_ADD (etable->click_to_add)->row)) { - gnome_canvas_item_grab_focus (etable->canvas_vbox); - gnome_canvas_item_grab_focus (etable->click_to_add); - } else if (!canvas->focused_item && etable->group) { - focus_first_etable_item (etable->group); - } else if (canvas->focused_item) { - ESelectionModel *selection = (ESelectionModel *) etable->selection; - - /* check whether click_to_add already got the focus */ - if (etable->click_to_add) { - GnomeCanvasItem *row = E_TABLE_CLICK_TO_ADD (etable->click_to_add)->row; - if (canvas->focused_item == row) - return TRUE; - } - - if (e_selection_model_cursor_row (selection) == -1) - focus_first_etable_item (etable->group); - } - - return FALSE; -} - -static gboolean -canvas_vbox_event (ECanvasVbox *vbox, - GdkEventKey *key, - ETable *etable) -{ - if (key->type != GDK_KEY_PRESS && - key->type != GDK_KEY_RELEASE) { - return FALSE; - } - switch (key->keyval) { - case GDK_KEY_Tab: - case GDK_KEY_KP_Tab: - case GDK_KEY_ISO_Left_Tab: - if ((key->state & GDK_CONTROL_MASK) && etable->click_to_add) { - gnome_canvas_item_grab_focus (etable->click_to_add); - break; - } - default: - return FALSE; - } - - return TRUE; -} - -static gboolean -click_to_add_event (ETableClickToAdd *etcta, - GdkEventKey *key, - ETable *etable) -{ - if (key->type != GDK_KEY_PRESS && - key->type != GDK_KEY_RELEASE) { - return FALSE; - } - switch (key->keyval) { - case GDK_KEY_Tab: - case GDK_KEY_KP_Tab: - case GDK_KEY_ISO_Left_Tab: - if (key->state & GDK_CONTROL_MASK) { - if (etable->group) { - if (e_table_model_row_count (etable->model) > 0) - focus_first_etable_item (etable->group); - else - gtk_widget_child_focus ( - gtk_widget_get_toplevel ( - GTK_WIDGET (etable->table_canvas)), - GTK_DIR_TAB_FORWARD); - break; - } - } - default: - return FALSE; - } - - return FALSE; -} - -static void -e_table_setup_table (ETable *e_table, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model) -{ - GtkWidget *widget; - GtkStyle *style; - - e_table->table_canvas = GNOME_CANVAS (e_canvas_new ()); - g_signal_connect ( - e_table->table_canvas, "size_allocate", - G_CALLBACK (table_canvas_size_allocate), e_table); - g_signal_connect ( - e_table->table_canvas, "focus_in_event", - G_CALLBACK (table_canvas_focus_event_cb), e_table); - g_signal_connect ( - e_table->table_canvas, "focus_out_event", - G_CALLBACK (table_canvas_focus_event_cb), e_table); - - g_signal_connect ( - e_table, "drag_begin", - G_CALLBACK (et_drag_begin), e_table); - g_signal_connect ( - e_table, "drag_end", - G_CALLBACK (et_drag_end), e_table); - g_signal_connect ( - e_table, "drag_data_get", - G_CALLBACK (et_drag_data_get), e_table); - g_signal_connect ( - e_table, "drag_data_delete", - G_CALLBACK (et_drag_data_delete), e_table); - g_signal_connect ( - e_table, "drag_motion", - G_CALLBACK (et_drag_motion), e_table); - g_signal_connect ( - e_table, "drag_leave", - G_CALLBACK (et_drag_leave), e_table); - g_signal_connect ( - e_table, "drag_drop", - G_CALLBACK (et_drag_drop), e_table); - g_signal_connect ( - e_table, "drag_data_received", - G_CALLBACK (et_drag_data_received), e_table); - - g_signal_connect ( - e_table->table_canvas, "reflow", - G_CALLBACK (table_canvas_reflow), e_table); - - widget = GTK_WIDGET (e_table->table_canvas); - style = gtk_widget_get_style (widget); - - gtk_widget_show (widget); - - e_table->white_item = gnome_canvas_item_new ( - gnome_canvas_root (e_table->table_canvas), - e_canvas_background_get_type (), - "fill_color_gdk", &style->base[GTK_STATE_NORMAL], - NULL); - - g_signal_connect ( - e_table->white_item, "event", - G_CALLBACK (white_item_event), e_table); - - g_signal_connect ( - e_table->table_canvas, "realize", - G_CALLBACK (et_canvas_realize), e_table); - - g_signal_connect ( - gnome_canvas_root (e_table->table_canvas), "event", - G_CALLBACK (et_canvas_root_event), 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); - - g_signal_connect ( - e_table->canvas_vbox, "event", - G_CALLBACK (canvas_vbox_event), e_table); - - et_build_groups (e_table); - - 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); - - if (e_table->use_click_to_add_end) - e_canvas_vbox_add_item ( - E_CANVAS_VBOX (e_table->canvas_vbox), - e_table->click_to_add); - else - e_canvas_vbox_add_item_start ( - E_CANVAS_VBOX (e_table->canvas_vbox), - e_table->click_to_add); - - g_signal_connect ( - e_table->click_to_add, "event", - G_CALLBACK (click_to_add_event), e_table); - g_signal_connect ( - e_table->click_to_add, "cursor_change", - G_CALLBACK (click_to_add_cursor_change), e_table); - } -} - -static void -e_table_fill_table (ETable *e_table, - ETableModel *model) -{ - e_table_group_add_all (e_table->group); -} - -/** - * e_table_set_state_object: - * @e_table: The #ETable object to modify - * @state: The #ETableState to use - * - * This routine sets the state of the #ETable from the given - * #ETableState. - * - **/ -void -e_table_set_state_object (ETable *e_table, - ETableState *state) -{ - GValue *val; - GtkWidget *widget; - GtkAllocation allocation; - - val = g_new0 (GValue, 1); - g_value_init (val, G_TYPE_DOUBLE); - - connect_header (e_table, state); - - widget = GTK_WIDGET (e_table->table_canvas); - gtk_widget_get_allocation (widget, &allocation); - - g_value_set_double (val, (gdouble) allocation.width); - g_object_set_property (G_OBJECT (e_table->header), "width", val); - g_free (val); - - if (e_table->sort_info) { - if (e_table->group_info_change_id) - g_signal_handler_disconnect ( - e_table->sort_info, - e_table->group_info_change_id); - if (e_table->sort_info_change_id) - g_signal_handler_disconnect ( - e_table->sort_info, - e_table->sort_info_change_id); - g_object_unref (e_table->sort_info); - } - if (state->sort_info) { - e_table->sort_info = e_table_sort_info_duplicate (state->sort_info); - e_table_sort_info_set_can_group ( - e_table->sort_info, e_table->allow_grouping); - e_table->group_info_change_id = g_signal_connect ( - e_table->sort_info, "group_info_changed", - G_CALLBACK (group_info_changed), e_table); - - e_table->sort_info_change_id = g_signal_connect ( - e_table->sort_info, "sort_info_changed", - G_CALLBACK (sort_info_changed), e_table); - } - else - e_table->sort_info = NULL; - - if (e_table->sorter) - g_object_set ( - e_table->sorter, - "sort_info", e_table->sort_info, - NULL); - if (e_table->header_item) - g_object_set ( - e_table->header_item, - "ETableHeader", e_table->header, - "sort_info", e_table->sort_info, - NULL); - if (e_table->click_to_add) - g_object_set ( - 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_state_change (e_table); -} - -/** - * e_table_set_state: - * @e_table: The #ETable object to modify - * @state_str: a string representing an #ETableState - * - * This routine sets the state of the #ETable from a string. - * - **/ -void -e_table_set_state (ETable *e_table, - const gchar *state_str) -{ - ETableState *state; - - 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); - - g_object_unref (state); -} - -/** - * e_table_load_state: - * @e_table: The #ETable object to modify - * @filename: name of the file to use - * - * This routine sets the state of the #ETable from a file. - * - **/ -void -e_table_load_state (ETable *e_table, - const gchar *filename) -{ - ETableState *state; - - 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); - - g_object_unref (state); -} - -/** - * e_table_get_state_object: - * @e_table: #ETable object to act on - * - * Builds an #ETableState corresponding to the current state of the - * #ETable. - * - * Return value: - * The %ETableState object generated. - **/ -ETableState * -e_table_get_state_object (ETable *e_table) -{ - ETableState *state; - gint full_col_count; - gint i, j; - - state = e_table_state_new (); - if (state->sort_info) - g_object_unref (state->sort_info); - state->sort_info = e_table->sort_info; - g_object_ref (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; -} - -/** - * e_table_get_state: - * @e_table: The #ETable to act on. - * - * Builds a state object based on the current state and returns the - * string corresponding to that state. - * - * Return value: - * A string describing the current state of the #ETable. - **/ -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); - g_object_unref (state); - return string; -} - -/** - * e_table_save_state: - * @e_table: The #ETable to act on - * @filename: name of the file to save to - * - * 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); - g_object_unref (state); -} - -static void -et_selection_model_selection_changed (ETableGroup *etg, - ETable *et) -{ - g_signal_emit (et, et_signals[SELECTION_CHANGE], 0); -} - -static void -et_selection_model_selection_row_changed (ETableGroup *etg, - gint row, - ETable *et) -{ - g_signal_emit (et, et_signals[SELECTION_CHANGE], 0); -} - -static ETable * -et_real_construct (ETable *e_table, - ETableModel *etm, - ETableExtras *ete, - ETableSpecification *specification, - ETableState *state) -{ - gint row = 0; - gint col_count, i; - GValue *val; - GtkAdjustment *adjustment; - GtkScrollable *scrollable; - - val = g_new0 (GValue, 1); - g_value_init (val, G_TYPE_OBJECT); - - if (ete) - g_object_ref (ete); - else { - ete = e_table_extras_new (); - } - - e_table->domain = g_strdup (specification->domain); - - e_table->use_click_to_add = specification->click_to_add; - e_table->use_click_to_add_end = specification->click_to_add_end; - e_table->click_to_add_message = specification->click_to_add_message ? - g_strdup ( - dgettext (e_table->domain, - specification->click_to_add_message)) : NULL; - e_table->alternating_row_colors = specification->alternating_row_colors; - e_table->horizontal_draw_grid = specification->horizontal_draw_grid; - e_table->vertical_draw_grid = specification->vertical_draw_grid; - e_table->draw_focus = specification->draw_focus; - e_table->cursor_mode = specification->cursor_mode; - e_table->full_header = e_table_spec_to_full_header (specification, ete); - - col_count = e_table_header_count (e_table->full_header); - for (i = 0; i < col_count; i++) { - ETableCol *col = e_table_header_get_column (e_table->full_header, i); - if (col && col->search) { - e_table->current_search_col = col; - e_table->search_col_set = TRUE; - break; - } - } - - e_table->model = etm; - g_object_ref (etm); - - connect_header (e_table, state); - e_table->horizontal_scrolling = specification->horizontal_scrolling; - e_table->horizontal_resize = specification->horizontal_resize; - e_table->allow_grouping = specification->allow_grouping; - - e_table->sort_info = g_object_ref (state->sort_info); - - e_table_sort_info_set_can_group ( - e_table->sort_info, e_table->allow_grouping); - - e_table->group_info_change_id = g_signal_connect ( - e_table->sort_info, "group_info_changed", - G_CALLBACK (group_info_changed), e_table); - - e_table->sort_info_change_id = g_signal_connect ( - e_table->sort_info, "sort_info_changed", - G_CALLBACK (sort_info_changed), e_table); - - g_value_set_object (val, e_table->sort_info); - g_object_set_property (G_OBJECT (e_table->header), "sort_info", val); - g_free (val); - - e_table->sorter = e_table_sorter_new ( - etm, e_table->full_header, e_table->sort_info); - - g_object_set ( - e_table->selection, - "model", etm, - "selection_mode", specification->selection_mode, - "cursor_mode", specification->cursor_mode, - "sorter", e_table->sorter, - "header", e_table->header, - NULL); - - g_signal_connect ( - e_table->selection, "selection_changed", - G_CALLBACK (et_selection_model_selection_changed), e_table); - g_signal_connect ( - e_table->selection, "selection_row_changed", - G_CALLBACK (et_selection_model_selection_row_changed), 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); - - scrollable = GTK_SCROLLABLE (e_table->table_canvas); - - adjustment = gtk_scrollable_get_vadjustment (scrollable); - gtk_adjustment_set_step_increment (adjustment, 20); - - adjustment = gtk_scrollable_get_hadjustment (scrollable); - gtk_adjustment_set_step_increment (adjustment, 20); - - 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); - - g_object_unref (ete); - - return e_table; -} - -/** - * e_table_construct: - * @e_table: The newly created #ETable object. - * @etm: The model for this table. - * @ete: An optional #ETableExtras. (%NULL is valid.) - * @spec_str: The spec. - * @state_str: An optional state. (%NULL is valid.) - * - * This is the internal implementation of e_table_new() for use by - * subclasses or language bindings. See e_table_new() for details. - * - * Return value: - * The passed in value @e_table or %NULL if there's an error. - **/ -ETable * -e_table_construct (ETable *e_table, - ETableModel *etm, - ETableExtras *ete, - const gchar *spec_str, - const gchar *state_str) -{ - ETableSpecification *specification; - ETableState *state; - - g_return_val_if_fail (E_IS_TABLE (e_table), 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); - - g_object_ref (etm); - - specification = e_table_specification_new (); - g_object_ref (specification); - if (!e_table_specification_load_from_string (specification, spec_str)) { - g_object_unref (specification); - return NULL; - } - - if (state_str) { - state = e_table_state_new (); - g_object_ref (state); - e_table_state_load_from_string (state, state_str); - if (state->col_count <= 0) { - g_object_unref (state); - state = specification->state; - g_object_ref (state); - } - } else { - state = specification->state; - g_object_ref (state); - } - - e_table = et_real_construct (e_table, etm, ete, specification, state); - - e_table->spec = specification; - g_object_unref (state); - - return e_table; -} - -/** - * e_table_construct_from_spec_file: - * @e_table: The newly created #ETable object. - * @etm: The model for this table. - * @ete: An optional #ETableExtras. (%NULL is valid.) - * @spec_fn: The filename of the spec. - * @state_fn: An optional state file. (%NULL is valid.) - * - * This is the internal implementation of e_table_new_from_spec_file() - * for use by subclasses or language bindings. See - * e_table_new_from_spec_file() for details. - * - * Return value: - * The passed in value @e_table or %NULL if there's an error. - **/ -ETable * -e_table_construct_from_spec_file (ETable *e_table, - ETableModel *etm, - ETableExtras *ete, - const gchar *spec_fn, - const gchar *state_fn) -{ - ETableSpecification *specification; - ETableState *state; - - g_return_val_if_fail (E_IS_TABLE (e_table), 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)) { - g_object_unref (specification); - return NULL; - } - - if (state_fn) { - state = e_table_state_new (); - if (!e_table_state_load_from_file (state, state_fn)) { - g_object_unref (state); - state = specification->state; - g_object_ref (state); - } - if (state->col_count <= 0) { - g_object_unref (state); - state = specification->state; - g_object_ref (state); - } - } else { - state = specification->state; - g_object_ref (state); - } - - e_table = et_real_construct (e_table, etm, ete, specification, state); - - e_table->spec = specification; - g_object_unref (state); - - return e_table; -} - -/** - * e_table_new: - * @etm: The model for this table. - * @ete: An optional #ETableExtras. (%NULL is valid.) - * @spec: The spec. - * @state: An optional state. (%NULL is valid.) - * - * This function creates an #ETable from the given parameters. The - * #ETableModel is a table model to be represented. The #ETableExtras - * is an optional set of pixbufs, cells, and sorting functions to be - * used when interpreting the spec. If you pass in %NULL it uses the - * default #ETableExtras. (See e_table_extras_new()). - * - * @spec is the specification of the set of viewable columns and the - * default sorting state and such. @state is an optional string - * specifying the current sorting state and such. If @state is NULL, - * then the default state from the spec will be used. - * - * Return value: - * The newly created #ETable or %NULL if there's an error. - **/ -GtkWidget * -e_table_new (ETableModel *etm, - ETableExtras *ete, - const gchar *spec, - const gchar *state) -{ - ETable *e_table; - - 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 = g_object_new (E_TYPE_TABLE, NULL); - - e_table = e_table_construct (e_table, etm, ete, spec, state); - - return GTK_WIDGET (e_table); -} - -/** - * e_table_new_from_spec_file: - * @etm: The model for this table. - * @ete: An optional #ETableExtras. (%NULL is valid.) - * @spec_fn: The filename of the spec. - * @state_fn: An optional state file. (%NULL is valid.) - * - * This is very similar to e_table_new(), except instead of passing in - * strings you pass in the file names of the spec and state to load. - * - * @spec_fn is the filename of the spec to load. If this file doesn't - * exist, e_table_new_from_spec_file will return %NULL. - * - * @state_fn is the filename of the initial state to load. If this is - * %NULL or if the specified file doesn't exist, the default state - * from the spec file is used. - * - * Return value: - * The newly created #ETable or %NULL if there's an error. - **/ -GtkWidget * -e_table_new_from_spec_file (ETableModel *etm, - ETableExtras *ete, - const gchar *spec_fn, - const gchar *state_fn) -{ - ETable *e_table; - - 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 = g_object_new (E_TYPE_TABLE, NULL); - - e_table = e_table_construct_from_spec_file (e_table, etm, ete, spec_fn, state_fn); - - return GTK_WIDGET (e_table); -} - -/** - * e_table_set_cursor_row: - * @e_table: The #ETable to set the cursor row of - * @row: The row number - * - * Sets the cursor row and the selection to the given row number. - **/ -void -e_table_set_cursor_row (ETable *e_table, - gint row) -{ - g_return_if_fail (E_IS_TABLE (e_table)); - g_return_if_fail (row >= 0); - - g_object_set ( - e_table->selection, - "cursor_row", row, - NULL); -} - -/** - * e_table_get_cursor_row: - * @e_table: The #ETable to query - * - * Calculates the cursor row. -1 means that we don't have a cursor. - * - * Return value: - * Cursor row - **/ -gint -e_table_get_cursor_row (ETable *e_table) -{ - gint row; - g_return_val_if_fail (E_IS_TABLE (e_table), -1); - - g_object_get ( - e_table->selection, - "cursor_row", &row, - NULL); - return row; -} - -/** - * e_table_selected_row_foreach: - * @e_table: The #ETable to act on - * @callback: The callback function to call - * @closure: The value passed to the callback's closure argument - * - * Calls the given @callback function once for every selected row. - * - * If you change the selection or delete or add rows to the table - * during these callbacks, problems can occur. A standard thing to do - * is to create a list of rows or objects the function is called upon - * and then act upon that list. (In inverse order if it's rows.) - **/ -void -e_table_selected_row_foreach (ETable *e_table, - EForeachFunc callback, - gpointer closure) -{ - g_return_if_fail (E_IS_TABLE (e_table)); - - e_selection_model_foreach (E_SELECTION_MODEL (e_table->selection), - callback, - closure); -} - -/** - * e_table_selected_count: - * @e_table: The #ETable to query - * - * Counts the number of selected rows. - * - * Return value: - * The number of rows selected. - **/ -gint -e_table_selected_count (ETable *e_table) -{ - g_return_val_if_fail (E_IS_TABLE (e_table), -1); - - return e_selection_model_selected_count (E_SELECTION_MODEL (e_table->selection)); -} - -/** - * e_table_select_all: - * @table: The #ETable to modify - * - * Selects all the rows in @table. - **/ -void -e_table_select_all (ETable *table) -{ - g_return_if_fail (E_IS_TABLE (table)); - - e_selection_model_select_all (E_SELECTION_MODEL (table->selection)); -} - -/** - * e_table_invert_selection: - * @table: The #ETable to modify - * - * Inverts the selection in @table. - **/ -void -e_table_invert_selection (ETable *table) -{ - g_return_if_fail (E_IS_TABLE (table)); - - e_selection_model_invert_selection (E_SELECTION_MODEL (table->selection)); -} - -/** - * e_table_get_printable: - * @e_table: #ETable to query - * - * Used for printing your #ETable. - * - * Return value: - * The #EPrintable to print. - **/ -EPrintable * -e_table_get_printable (ETable *e_table) -{ - g_return_val_if_fail (E_IS_TABLE (e_table), NULL); - - return e_table_group_get_printable (e_table->group); -} - -/** - * e_table_right_click_up: - * @table: The #ETable to modify. - * - * Call this function when you're done handling the right click if you - * return TRUE from the "right_click" signal. - **/ -void -e_table_right_click_up (ETable *table) -{ - e_selection_model_right_click_up (E_SELECTION_MODEL (table->selection)); -} - -/** - * e_table_commit_click_to_add: - * @table: The #ETable to modify - * - * Commits the current values in the click to add to the table. - **/ -void -e_table_commit_click_to_add (ETable *table) -{ - et_eti_leave_edit (table); - if (table->click_to_add) - e_table_click_to_add_commit ( - E_TABLE_CLICK_TO_ADD (table->click_to_add)); -} - -static void -et_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ETable *etable = E_TABLE (object); - - switch (property_id) { - case PROP_MODEL: - g_value_set_object (value, etable->model); - break; - case PROP_UNIFORM_ROW_HEIGHT: - g_value_set_boolean (value, etable->uniform_row_height); - break; - case PROP_ALWAYS_SEARCH: - g_value_set_boolean (value, etable->always_search); - break; - case PROP_USE_CLICK_TO_ADD: - g_value_set_boolean (value, etable->use_click_to_add); - break; - case PROP_HADJUSTMENT: - if (etable->table_canvas) - g_object_get_property ( - G_OBJECT (etable->table_canvas), - "hadjustment", value); - else - g_value_set_object (value, NULL); - break; - case PROP_VADJUSTMENT: - if (etable->table_canvas) - g_object_get_property ( - G_OBJECT (etable->table_canvas), - "vadjustment", value); - else - g_value_set_object (value, NULL); - break; - case PROP_HSCROLL_POLICY: - if (etable->table_canvas) - g_object_get_property ( - G_OBJECT (etable->table_canvas), - "hscroll-policy", value); - else - g_value_set_enum (value, 0); - break; - case PROP_VSCROLL_POLICY: - if (etable->table_canvas) - g_object_get_property ( - G_OBJECT (etable->table_canvas), - "vscroll-policy", value); - else - g_value_set_enum (value, 0); - break; - default: - break; - } -} - -typedef struct { - gchar *arg; - gboolean setting; -} bool_closure; - -static void -et_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ETable *etable = E_TABLE (object); - - switch (property_id) { - case PROP_LENGTH_THRESHOLD: - etable->length_threshold = g_value_get_int (value); - if (etable->group) { - gnome_canvas_item_set ( - GNOME_CANVAS_ITEM (etable->group), - "length_threshold", - etable->length_threshold, - NULL); - } - break; - case PROP_UNIFORM_ROW_HEIGHT: - etable->uniform_row_height = g_value_get_boolean (value); - if (etable->group) { - gnome_canvas_item_set ( - GNOME_CANVAS_ITEM (etable->group), - "uniform_row_height", - etable->uniform_row_height, - NULL); - } - break; - case PROP_ALWAYS_SEARCH: - if (etable->always_search == g_value_get_boolean (value)) - return; - - etable->always_search = g_value_get_boolean (value); - clear_current_search_col (etable); - break; - case PROP_USE_CLICK_TO_ADD: - if (etable->use_click_to_add == g_value_get_boolean (value)) - return; - - etable->use_click_to_add = g_value_get_boolean (value); - clear_current_search_col (etable); - - if (etable->use_click_to_add) { - etable->click_to_add = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (etable->canvas_vbox), - e_table_click_to_add_get_type (), - "header", etable->header, - "model", etable->model, - "message", etable->click_to_add_message, - NULL); - - if (etable->use_click_to_add_end) - e_canvas_vbox_add_item ( - E_CANVAS_VBOX (etable->canvas_vbox), - etable->click_to_add); - else - e_canvas_vbox_add_item_start ( - E_CANVAS_VBOX (etable->canvas_vbox), - etable->click_to_add); - - g_signal_connect ( - etable->click_to_add, "cursor_change", - G_CALLBACK (click_to_add_cursor_change), - etable); - } else { - g_object_run_dispose (G_OBJECT (etable->click_to_add)); - etable->click_to_add = NULL; - } - break; - case PROP_HADJUSTMENT: - if (etable->table_canvas) - g_object_set_property ( - G_OBJECT (etable->table_canvas), - "hadjustment", value); - break; - case PROP_VADJUSTMENT: - if (etable->table_canvas) - g_object_set_property ( - G_OBJECT (etable->table_canvas), - "vadjustment", value); - break; - case PROP_HSCROLL_POLICY: - if (etable->table_canvas) - g_object_set_property ( - G_OBJECT (etable->table_canvas), - "hscroll-policy", value); - break; - case PROP_VSCROLL_POLICY: - if (etable->table_canvas) - g_object_set_property ( - G_OBJECT (etable->table_canvas), - "vscroll-policy", value); - break; - } -} - -/** - * e_table_get_next_row: - * @e_table: The #ETable to query - * @model_row: The model row to go from - * - * This function is used when your table is sorted, but you're using - * model row numbers. It returns the next row in sorted order as a model row. - * - * Return value: - * The model row number. - **/ -gint -e_table_get_next_row (ETable *e_table, - gint model_row) -{ - g_return_val_if_fail (E_IS_TABLE (e_table), -1); - - if (e_table->sorter) { - gint i; - i = e_sorter_model_to_sorted (E_SORTER (e_table->sorter), model_row); - i++; - if (i < e_table_model_row_count (e_table->model)) { - return e_sorter_sorted_to_model (E_SORTER (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; -} - -/** - * e_table_get_prev_row: - * @e_table: The #ETable to query - * @model_row: The model row to go from - * - * This function is used when your table is sorted, but you're using - * model row numbers. It returns the previous row in sorted order as - * a model row. - * - * Return value: - * The model row number. - **/ -gint -e_table_get_prev_row (ETable *e_table, - gint model_row) -{ - g_return_val_if_fail (E_IS_TABLE (e_table), -1); - - if (e_table->sorter) { - gint i; - i = e_sorter_model_to_sorted (E_SORTER (e_table->sorter), model_row); - i--; - if (i >= 0) - return e_sorter_sorted_to_model (E_SORTER (e_table->sorter), i); - else - return -1; - } else - return model_row - 1; -} - -/** - * e_table_model_to_view_row: - * @e_table: The #ETable to query - * @model_row: The model row number - * - * Turns a model row into a view row. - * - * Return value: - * The view row number. - **/ -gint -e_table_model_to_view_row (ETable *e_table, - gint model_row) -{ - g_return_val_if_fail (E_IS_TABLE (e_table), -1); - - if (e_table->sorter) - return e_sorter_model_to_sorted (E_SORTER (e_table->sorter), model_row); - else - return model_row; -} - -/** - * e_table_view_to_model_row: - * @e_table: The #ETable to query - * @view_row: The view row number - * - * Turns a view row into a model row. - * - * Return value: - * The model row number. - **/ -gint -e_table_view_to_model_row (ETable *e_table, - gint view_row) -{ - g_return_val_if_fail (E_IS_TABLE (e_table), -1); - - if (e_table->sorter) - return e_sorter_sorted_to_model (E_SORTER (e_table->sorter), view_row); - else - return view_row; -} - -/** - * e_table_get_cell_at: - * @table: An #ETable widget - * @x: X coordinate for the pixel - * @y: Y coordinate for the pixel - * @row_return: Pointer to return the row value - * @col_return: Pointer to return the column value - * - * Return the row and column for the cell in which the pixel at (@x, @y) is - * contained. - **/ -void -e_table_get_cell_at (ETable *table, - gint x, - gint y, - gint *row_return, - gint *col_return) -{ - GtkAdjustment *adjustment; - GtkScrollable *scrollable; - - g_return_if_fail (E_IS_TABLE (table)); - g_return_if_fail (row_return != NULL); - g_return_if_fail (col_return != NULL); - - /* FIXME it would be nice if it could handle a NULL row_return or - * col_return gracefully. */ - - scrollable = GTK_SCROLLABLE (table->table_canvas); - - adjustment = gtk_scrollable_get_hadjustment (scrollable); - x += gtk_adjustment_get_value (adjustment); - - adjustment = gtk_scrollable_get_vadjustment (scrollable); - y += gtk_adjustment_get_value (adjustment); - - e_table_group_compute_location ( - table->group, &x, &y, row_return, col_return); -} - -/** - * e_table_get_cell_geometry: - * @table: The #ETable. - * @row: The row to get the geometry of. - * @col: The col to get the geometry of. - * @x_return: Returns the x coordinate of the upper left hand corner - * of the cell with respect to the widget. - * @y_return: Returns the y coordinate of the upper left hand corner - * of the cell with respect to the widget. - * @width_return: Returns the width of the cell. - * @height_return: Returns the height of the cell. - * - * Returns the x, y, width, and height of the given cell. These can - * all be #NULL and they just won't be set. - **/ -void -e_table_get_cell_geometry (ETable *table, - gint row, - gint col, - gint *x_return, - gint *y_return, - gint *width_return, - gint *height_return) -{ - GtkAllocation allocation; - GtkAdjustment *adjustment; - GtkScrollable *scrollable; - - g_return_if_fail (E_IS_TABLE (table)); - - scrollable = GTK_SCROLLABLE (table->table_canvas); - - e_table_group_get_cell_geometry ( - table->group, &row, &col, x_return, y_return, - width_return, height_return); - - if (x_return && table->table_canvas) { - adjustment = gtk_scrollable_get_hadjustment (scrollable); - (*x_return) -= gtk_adjustment_get_value (adjustment); - } - - if (y_return) { - if (table->table_canvas) { - adjustment = gtk_scrollable_get_vadjustment (scrollable); - (*y_return) -= gtk_adjustment_get_value (adjustment); - } - - if (table->header_canvas) { - gtk_widget_get_allocation ( - GTK_WIDGET (table->header_canvas), - &allocation); - (*y_return) += allocation.height; - } - } -} - -/** - * e_table_get_mouse_over_cell: - * - * Similar to e_table_get_cell_at, only here we check - * based on the mouse motion information in the group. - **/ -void -e_table_get_mouse_over_cell (ETable *table, - gint *row, - gint *col) -{ - g_return_if_fail (E_IS_TABLE (table)); - - if (!table->group) - return; - - e_table_group_get_mouse_over (table->group, row, col); -} - -/** - * e_table_get_selection_model: - * @table: The #ETable to query - * - * Returns the table's #ESelectionModel in case you want to access it - * directly. - * - * Return value: - * The #ESelectionModel. - **/ -ESelectionModel * -e_table_get_selection_model (ETable *table) -{ - g_return_val_if_fail (E_IS_TABLE (table), NULL); - - return E_SELECTION_MODEL (table->selection); -} - -struct _ETableDragSourceSite -{ - GdkModifierType start_button_mask; - GtkTargetList *target_list; /* Targets for drag data */ - GdkDragAction actions; /* Possible actions */ - GdkPixbuf *pixbuf; /* Icon for drag data */ - - /* 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 */ - guint dropped : 1; /* Set after we receive a drop */ - guint32 proxy_drop_time; /* Timestamp for proxied drop */ - guint 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 */ - -/** - * e_table_drag_get_data: - * @table: - * @row: - * @col: - * @context: - * @target: - * @time: - * - * - **/ -void -e_table_drag_get_data (ETable *table, - gint row, - gint col, - GdkDragContext *context, - GdkAtom target, - guint32 time) -{ - g_return_if_fail (E_IS_TABLE (table)); - - gtk_drag_get_data ( - GTK_WIDGET (table), - context, - target, - time); -} - -/** - * e_table_drag_highlight: - * @table: The #ETable to highlight - * @row: The row number of the cell to highlight - * @col: The column number of the cell to highlight - * - * Set col to -1 to highlight the entire row. If row is -1, this is - * identical to e_table_drag_unhighlight(). - **/ -void -e_table_drag_highlight (ETable *table, - gint row, - gint col) -{ - GtkAllocation allocation; - GtkAdjustment *adjustment; - GtkScrollable *scrollable; - GtkStyle *style; - - g_return_if_fail (E_IS_TABLE (table)); - - scrollable = GTK_SCROLLABLE (table->table_canvas); - style = gtk_widget_get_style (GTK_WIDGET (table)); - gtk_widget_get_allocation (GTK_WIDGET (scrollable), &allocation); - - if (row != -1) { - gint x, y, width, height; - if (col == -1) { - e_table_get_cell_geometry (table, row, 0, &x, &y, &width, &height); - x = 0; - width = allocation.width; - } else { - e_table_get_cell_geometry (table, row, col, &x, &y, &width, &height); - adjustment = gtk_scrollable_get_hadjustment (scrollable); - x += gtk_adjustment_get_value (adjustment); - } - - adjustment = gtk_scrollable_get_vadjustment (scrollable); - y += gtk_adjustment_get_value (adjustment); - - if (table->drop_highlight == NULL) { - table->drop_highlight = gnome_canvas_item_new ( - gnome_canvas_root (table->table_canvas), - gnome_canvas_rect_get_type (), - "fill_color", NULL, - "outline_color_gdk", &style->fg[GTK_STATE_NORMAL], - NULL); - } - gnome_canvas_item_set ( - table->drop_highlight, - "x1", (gdouble) x, - "x2", (gdouble) x + width - 1, - "y1", (gdouble) y, - "y2", (gdouble) y + height - 1, - NULL); - } else { - if (table->drop_highlight) { - g_object_run_dispose (G_OBJECT (table->drop_highlight)); - table->drop_highlight = NULL; - } - } -} - -/** - * e_table_drag_unhighlight: - * @table: The #ETable to unhighlight - * - * Removes the highlight from an #ETable. - **/ -void -e_table_drag_unhighlight (ETable *table) -{ - g_return_if_fail (E_IS_TABLE (table)); - - if (table->drop_highlight) { - g_object_run_dispose (G_OBJECT (table->drop_highlight)); - table->drop_highlight = NULL; - } -} - -void -e_table_drag_dest_set (ETable *table, - GtkDestDefaults flags, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions) -{ - 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 (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 (E_IS_TABLE (widget)); - - gtk_drag_dest_unset (widget); -} - -/* Source side */ - -static gint -et_real_start_drag (ETable *table, - gint row, - gint col, - GdkEvent *event) -{ - GtkDragSourceInfo *info; - GdkDragContext *context; - ETableDragSourceSite *site; - - if (table->do_drag) { - site = table->site; - - site->state = 0; - context = e_table_drag_begin ( - table, row, col, - site->target_list, - site->actions, - 1, event); - - if (context) { - info = g_dataset_get_data (context, "gtk-info"); - - if (info && !info->icon_window) { - if (site->pixbuf) - gtk_drag_set_icon_pixbuf ( - context, - site->pixbuf, - -2, -2); - else - gtk_drag_set_icon_default (context); - } - } - return TRUE; - } - return FALSE; -} - -/** - * e_table_drag_source_set: - * @table: The #ETable to set up as a drag site - * @start_button_mask: Mask of allowed buttons to start drag - * @targets: Table of targets for this source - * @n_targets: Number of targets in @targets - * @actions: Actions allowed for this source - * - * Registers this table as a drag site, and possibly adds default behaviors. - **/ -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 (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 | GDK_STRUCTURE_MASK); - - table->do_drag = TRUE; - - if (site) { - if (site->target_list) - gtk_target_list_unref (site->target_list); - } else { - site = g_new0 (ETableDragSourceSite, 1); - 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; -} - -/** - * e_table_drag_source_unset: - * @table: The #ETable to un set up as a drag site - * - * Unregisters this #ETable as a drag site. - **/ -void -e_table_drag_source_unset (ETable *table) -{ - ETableDragSourceSite *site; - - g_return_if_fail (E_IS_TABLE (table)); - - site = table->site; - - if (site) { - if (site->target_list) - gtk_target_list_unref (site->target_list); - g_free (site); - table->site = NULL; - } - table->do_drag = FALSE; -} - -/* There probably should be functions for setting the targets - * as a GtkTargetList - */ - -/** - * e_table_drag_begin: - * @table: The #ETable to drag from - * @row: The row number of the cell - * @col: The col number of the cell - * @targets: The list of targets supported by the drag - * @actions: The available actions supported by the drag - * @button: The button held down for the drag - * @event: The event that initiated the drag - * - * Start a drag from this cell. - * - * Return value: - * The drag context. - **/ -GdkDragContext * -e_table_drag_begin (ETable *table, - gint row, - gint col, - GtkTargetList *targets, - GdkDragAction actions, - gint button, - GdkEvent *event) -{ - 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 -et_drag_begin (GtkWidget *widget, - GdkDragContext *context, - ETable *et) -{ - g_signal_emit ( - et, et_signals[TABLE_DRAG_BEGIN], 0, - et->drag_row, et->drag_col, context); -} - -static void -et_drag_end (GtkWidget *widget, - GdkDragContext *context, - ETable *et) -{ - g_signal_emit ( - et, et_signals[TABLE_DRAG_END], 0, - 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) -{ - g_signal_emit ( - et, et_signals[TABLE_DRAG_DATA_GET], 0, - et->drag_row, et->drag_col, context, selection_data, - info, time); -} - -static void -et_drag_data_delete (GtkWidget *widget, - GdkDragContext *context, - ETable *et) -{ - g_signal_emit ( - et, et_signals[TABLE_DRAG_DATA_DELETE], 0, - et->drag_row, et->drag_col, context); -} - -static gboolean -do_drag_motion (ETable *et, - GdkDragContext *context, - gint x, - gint y, - guint time) -{ - gboolean ret_val; - gint row = -1, col = -1; - - e_table_get_cell_at (et, x, y, &row, &col); - - if (row != et->drop_row && col != et->drop_row) { - g_signal_emit ( - et, et_signals[TABLE_DRAG_LEAVE], 0, - et->drop_row, et->drop_col, context, time); - } - - et->drop_row = row; - et->drop_col = col; - - g_signal_emit ( - et, et_signals[TABLE_DRAG_MOTION], 0, - et->drop_row, et->drop_col, context, x, y, time, &ret_val); - - return ret_val; -} - -static gboolean -scroll_timeout (gpointer data) -{ - ETable *et = data; - gint dx = 0, dy = 0; - GtkAdjustment *adjustment; - GtkScrollable *scrollable; - gdouble old_h_value; - gdouble new_h_value; - gdouble old_v_value; - gdouble new_v_value; - gdouble page_size; - gdouble lower; - gdouble upper; - - if (et->scroll_direction & ET_SCROLL_DOWN) - dy += 20; - if (et->scroll_direction & ET_SCROLL_UP) - dy -= 20; - - if (et->scroll_direction & ET_SCROLL_RIGHT) - dx += 20; - if (et->scroll_direction & ET_SCROLL_LEFT) - dx -= 20; - - scrollable = GTK_SCROLLABLE (et->table_canvas); - - adjustment = gtk_scrollable_get_hadjustment (scrollable); - - lower = gtk_adjustment_get_lower (adjustment); - upper = gtk_adjustment_get_upper (adjustment); - page_size = gtk_adjustment_get_page_size (adjustment); - - old_h_value = gtk_adjustment_get_value (adjustment); - new_h_value = CLAMP (old_h_value + dx, lower, upper - page_size); - - gtk_adjustment_set_value (adjustment, new_h_value); - - adjustment = gtk_scrollable_get_vadjustment (scrollable); - - lower = gtk_adjustment_get_lower (adjustment); - upper = gtk_adjustment_get_upper (adjustment); - page_size = gtk_adjustment_get_page_size (adjustment); - - old_v_value = gtk_adjustment_get_value (adjustment); - new_v_value = CLAMP (old_v_value + dy, lower, upper - page_size); - - gtk_adjustment_set_value (adjustment, new_v_value); - - if (new_h_value != old_h_value || new_v_value != old_v_value) - do_drag_motion ( - et, - et->last_drop_context, - et->last_drop_x, - et->last_drop_y, - et->last_drop_time); - - return TRUE; -} - -static void -scroll_on (ETable *et, - guint scroll_direction) -{ - if (et->scroll_idle_id == 0 || scroll_direction != et->scroll_direction) { - if (et->scroll_idle_id != 0) - g_source_remove (et->scroll_idle_id); - et->scroll_direction = scroll_direction; - et->scroll_idle_id = g_timeout_add (100, scroll_timeout, et); - } -} - -static void -scroll_off (ETable *et) -{ - if (et->scroll_idle_id) { - g_source_remove (et->scroll_idle_id); - et->scroll_idle_id = 0; - } -} - -static void -context_destroyed (gpointer data) -{ - ETable *et = data; - /* if (!G_OBJECT_DESTROYED (et)) */ -/* FIXME: */ - { - et->last_drop_x = 0; - et->last_drop_y = 0; - et->last_drop_time = 0; - et->last_drop_context = NULL; - scroll_off (et); - } - g_object_unref (et); -} - -static void -context_connect (ETable *et, - GdkDragContext *context) -{ - if (g_dataset_get_data (context, "e-table") == NULL) { - g_object_ref (et); - g_dataset_set_data_full (context, "e-table", et, context_destroyed); - } -} - -static void -et_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time, - ETable *et) -{ - g_signal_emit ( - et, et_signals[TABLE_DRAG_LEAVE], 0, - et->drop_row, et->drop_col, context, time); - - et->drop_row = -1; - et->drop_col = -1; - - scroll_off (et); -} - -static gboolean -et_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETable *et) -{ - GtkAllocation allocation; - gboolean ret_val; - guint direction = 0; - - gtk_widget_get_allocation (widget, &allocation); - - et->last_drop_x = x; - et->last_drop_y = y; - et->last_drop_time = time; - et->last_drop_context = context; - context_connect (et, context); - - ret_val = do_drag_motion (et, context, x, y, time); - - if (y < 20) - direction |= ET_SCROLL_UP; - if (y > allocation.height - 20) - direction |= ET_SCROLL_DOWN; - if (x < 20) - direction |= ET_SCROLL_LEFT; - if (x > allocation.width - 20) - direction |= ET_SCROLL_RIGHT; - - if (direction != 0) - scroll_on (et, direction); - else - scroll_off (et); - - return ret_val; -} - -static gboolean -et_drag_drop (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETable *et) -{ - gboolean ret_val; - gint row, col; - - e_table_get_cell_at (et, x, y, &row, &col); - - if (row != et->drop_row && col != et->drop_row) { - g_signal_emit ( - et, et_signals[TABLE_DRAG_LEAVE], 0, - et->drop_row, et->drop_col, context, time); - g_signal_emit ( - et, et_signals[TABLE_DRAG_MOTION], 0, - row, col, context, x, y, time, &ret_val); - } - et->drop_row = row; - et->drop_col = col; - g_signal_emit ( - et, et_signals[TABLE_DRAG_DROP], 0, - et->drop_row, et->drop_col, context, x, y, time, &ret_val); - et->drop_row = -1; - et->drop_col = -1; - - scroll_off (et); - - 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) -{ - gint row, col; - - e_table_get_cell_at (et, x, y, &row, &col); - - g_signal_emit ( - et, et_signals[TABLE_DRAG_DATA_RECEIVED], 0, - row, col, context, x, y, selection_data, info, time); -} - -static void -e_table_class_init (ETableClass *class) -{ - GObjectClass *object_class; - GtkWidgetClass *widget_class; - - object_class = (GObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - - object_class->dispose = et_dispose; - object_class->finalize = et_finalize; - object_class->set_property = et_set_property; - object_class->get_property = et_get_property; - - widget_class->grab_focus = et_grab_focus; - widget_class->unrealize = et_unrealize; - widget_class->get_preferred_width = et_get_preferred_width; - widget_class->get_preferred_height = et_get_preferred_height; - - widget_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->start_drag = et_real_start_drag; - class->state_change = NULL; - class->white_space_event = 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] = g_signal_new ( - "cursor_change", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClass, cursor_change), - NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, G_TYPE_INT); - - et_signals[CURSOR_ACTIVATED] = g_signal_new ( - "cursor_activated", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClass, cursor_activated), - NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, G_TYPE_INT); - - et_signals[SELECTION_CHANGE] = g_signal_new ( - "selection_change", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClass, selection_change), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - et_signals[DOUBLE_CLICK] = g_signal_new ( - "double_click", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClass, double_click), - NULL, NULL, - e_marshal_NONE__INT_INT_BOXED, - G_TYPE_NONE, 3, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - et_signals[RIGHT_CLICK] = g_signal_new ( - "right_click", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClass, right_click), - g_signal_accumulator_true_handled, NULL, - e_marshal_BOOLEAN__INT_INT_BOXED, - G_TYPE_BOOLEAN, 3, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - et_signals[CLICK] = g_signal_new ( - "click", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClass, click), - g_signal_accumulator_true_handled, NULL, - e_marshal_BOOLEAN__INT_INT_BOXED, - G_TYPE_BOOLEAN, 3, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - et_signals[KEY_PRESS] = g_signal_new ( - "key_press", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClass, key_press), - g_signal_accumulator_true_handled, NULL, - e_marshal_BOOLEAN__INT_INT_BOXED, - G_TYPE_BOOLEAN, 3, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - et_signals[START_DRAG] = g_signal_new ( - "start_drag", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClass, start_drag), - g_signal_accumulator_true_handled, NULL, - e_marshal_BOOLEAN__INT_INT_BOXED, - G_TYPE_BOOLEAN, 3, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - et_signals[STATE_CHANGE] = g_signal_new ( - "state_change", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClass, state_change), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - et_signals[WHITE_SPACE_EVENT] = g_signal_new ( - "white_space_event", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClass, white_space_event), - g_signal_accumulator_true_handled, NULL, - e_marshal_BOOLEAN__BOXED, - G_TYPE_BOOLEAN, 1, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - et_signals[TABLE_DRAG_BEGIN] = g_signal_new ( - "table_drag_begin", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClass, table_drag_begin), - NULL, NULL, - e_marshal_NONE__INT_INT_OBJECT, - G_TYPE_NONE, 3, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_DRAG_CONTEXT); - - et_signals[TABLE_DRAG_END] = g_signal_new ( - "table_drag_end", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClass, table_drag_end), - NULL, NULL, - e_marshal_NONE__INT_INT_OBJECT, - G_TYPE_NONE, 3, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_DRAG_CONTEXT); - - et_signals[TABLE_DRAG_DATA_GET] = g_signal_new ( - "table_drag_data_get", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClass, table_drag_data_get), - NULL, NULL, - e_marshal_NONE__INT_INT_OBJECT_BOXED_UINT_UINT, - G_TYPE_NONE, 6, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_DRAG_CONTEXT, - GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE, - G_TYPE_UINT, - G_TYPE_UINT); - - et_signals[TABLE_DRAG_DATA_DELETE] = g_signal_new ( - "table_drag_data_delete", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClass, table_drag_data_delete), - NULL, NULL, - e_marshal_NONE__INT_INT_OBJECT, - G_TYPE_NONE, 3, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_DRAG_CONTEXT); - - et_signals[TABLE_DRAG_LEAVE] = g_signal_new ( - "table_drag_leave", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClass, table_drag_leave), - NULL, NULL, - e_marshal_NONE__INT_INT_OBJECT_UINT, - G_TYPE_NONE, 4, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_DRAG_CONTEXT, - G_TYPE_UINT); - - et_signals[TABLE_DRAG_MOTION] = g_signal_new ( - "table_drag_motion", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClass, table_drag_motion), - NULL, NULL, - e_marshal_BOOLEAN__INT_INT_OBJECT_INT_INT_UINT, - G_TYPE_BOOLEAN, 6, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_DRAG_CONTEXT, - G_TYPE_INT, - G_TYPE_INT, - G_TYPE_UINT); - - et_signals[TABLE_DRAG_DROP] = g_signal_new ( - "table_drag_drop", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClass, table_drag_drop), - NULL, NULL, - e_marshal_BOOLEAN__INT_INT_OBJECT_INT_INT_UINT, - G_TYPE_BOOLEAN, 6, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_DRAG_CONTEXT, - G_TYPE_INT, - G_TYPE_INT, - G_TYPE_UINT); - - et_signals[TABLE_DRAG_DATA_RECEIVED] = g_signal_new ( - "table_drag_data_received", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETableClass, table_drag_data_received), - NULL, NULL, - e_marshal_NONE__INT_INT_OBJECT_INT_INT_BOXED_UINT_UINT, - G_TYPE_NONE, 8, - G_TYPE_INT, - G_TYPE_INT, - GDK_TYPE_DRAG_CONTEXT, - G_TYPE_INT, - G_TYPE_INT, - GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE, - G_TYPE_UINT, - G_TYPE_UINT); - - g_object_class_install_property ( - object_class, - PROP_LENGTH_THRESHOLD, - g_param_spec_int ( - "length_threshold", - "Length Threshold", - NULL, - 0, G_MAXINT, 0, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_UNIFORM_ROW_HEIGHT, - g_param_spec_boolean ( - "uniform_row_height", - "Uniform row height", - NULL, - FALSE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_ALWAYS_SEARCH, - g_param_spec_boolean ( - "always_search", - "Always search", - NULL, - FALSE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_USE_CLICK_TO_ADD, - g_param_spec_boolean ( - "use_click_to_add", - "Use click to add", - NULL, - FALSE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_MODEL, - g_param_spec_object ( - "model", - "Model", - NULL, - E_TYPE_TABLE_MODEL, - G_PARAM_READABLE)); - - gtk_widget_class_install_style_property ( - widget_class, - g_param_spec_int ( - "vertical-spacing", - "Vertical Row Spacing", - "Vertical space between rows. " - "It is added to top and to bottom of a row", - 0, G_MAXINT, 3, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - /* Scrollable interface */ - g_object_class_override_property ( - object_class, PROP_HADJUSTMENT, "hadjustment"); - g_object_class_override_property ( - object_class, PROP_VADJUSTMENT, "vadjustment"); - g_object_class_override_property ( - object_class, PROP_HSCROLL_POLICY, "hscroll-policy"); - g_object_class_override_property ( - object_class, PROP_VSCROLL_POLICY, "vscroll-policy"); - - gal_a11y_e_table_init (); -} - -void -e_table_freeze_state_change (ETable *table) -{ - g_return_if_fail (table != NULL); - - table->state_change_freeze++; - if (table->state_change_freeze == 1) - table->state_changed = FALSE; - - g_return_if_fail (table->state_change_freeze != 0); -} - -void -e_table_thaw_state_change (ETable *table) -{ - g_return_if_fail (table != NULL); - g_return_if_fail (table->state_change_freeze != 0); - - table->state_change_freeze--; - if (table->state_change_freeze == 0 && table->state_changed) { - table->state_changed = FALSE; - e_table_state_change (table); - } -} 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 6c2908811c..0000000000 --- a/widgets/table/e-table.h +++ /dev/null @@ -1,398 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Miguel de Icaza <miguel@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TABLE_H_ -#define _E_TABLE_H_ - -#include <libgnomecanvas/libgnomecanvas.h> -#include <gtk/gtk.h> -#include <libxml/tree.h> -#include <table/e-table-model.h> -#include <table/e-table-header.h> -#include <table/e-table-group.h> -#include <table/e-table-sort-info.h> -#include <table/e-table-item.h> -#include <table/e-table-selection-model.h> -#include <table/e-table-extras.h> -#include <table/e-table-specification.h> -#include <misc/e-printable.h> -#include <table/e-table-state.h> -#include <table/e-table-sorter.h> -#include <table/e-table-search.h> - -/* Standard GObject macros */ -#define E_TYPE_TABLE \ - (e_table_get_type ()) -#define E_TABLE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TABLE, ETable)) -#define E_TABLE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TABLE, ETableClass)) -#define E_IS_TABLE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TABLE)) -#define E_IS_TABLE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TABLE)) -#define E_TABLE_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TABLE, ETableClass)) - -G_BEGIN_DECLS - -typedef struct _ETable ETable; -typedef struct _ETableClass ETableClass; - -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; - -struct _ETable { - 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; - - ETableSearch *search; - - ETableCol *current_search_col; - - guint search_search_id; - guint search_accept_id; - - gint table_model_change_id; - gint table_row_change_id; - gint table_cell_change_id; - gint table_rows_inserted_id; - gint table_rows_deleted_id; - - gint group_info_change_id; - gint sort_info_change_id; - - gint structure_change_id; - gint expansion_change_id; - gint dimension_change_id; - - gint reflow_idle_id; - gint scroll_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; - guint size_allocated : 1; - - /* - * Configuration settings - */ - guint alternating_row_colors : 1; - guint horizontal_draw_grid : 1; - guint vertical_draw_grid : 1; - guint draw_focus : 1; - guint row_selection_active : 1; - - guint horizontal_scrolling : 1; - guint horizontal_resize : 1; - - guint is_grouped : 1; - - guint scroll_direction : 4; - - guint do_drag : 1; - - guint uniform_row_height : 1; - guint allow_grouping : 1; - - guint always_search : 1; - guint search_col_set : 1; - - gchar *click_to_add_message; - GnomeCanvasItem *click_to_add; - gboolean use_click_to_add; - gboolean use_click_to_add_end; - - ECursorMode cursor_mode; - - gint drop_row; - gint drop_col; - GnomeCanvasItem *drop_highlight; - gint last_drop_x; - gint last_drop_y; - gint last_drop_time; - GdkDragContext *last_drop_context; - - gint drag_row; - gint drag_col; - ETableDragSourceSite *site; - - gint header_width; - - gchar *domain; - - gboolean state_changed; - guint state_change_freeze; -}; - -struct _ETableClass { - GtkTableClass parent_class; - - void (*cursor_change) (ETable *et, - gint row); - void (*cursor_activated) (ETable *et, - gint row); - void (*selection_change) (ETable *et); - void (*double_click) (ETable *et, - gint row, - gint col, - GdkEvent *event); - gboolean (*right_click) (ETable *et, - gint row, - gint col, - GdkEvent *event); - gboolean (*click) (ETable *et, - gint row, - gint col, - GdkEvent *event); - gboolean (*key_press) (ETable *et, - gint row, - gint col, - GdkEvent *event); - gboolean (*start_drag) (ETable *et, - gint row, - gint col, - GdkEvent *event); - void (*state_change) (ETable *et); - gboolean (*white_space_event) (ETable *et, - GdkEvent *event); - - /* Source side drag signals */ - void (*table_drag_begin) (ETable *table, - gint row, - gint col, - GdkDragContext *context); - void (*table_drag_end) (ETable *table, - gint row, - gint col, - GdkDragContext *context); - void (*table_drag_data_get) (ETable *table, - gint row, - gint col, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time); - void (*table_drag_data_delete) - (ETable *table, - gint row, - gint col, - GdkDragContext *context); - - /* Target side drag signals */ - void (*table_drag_leave) (ETable *table, - gint row, - gint col, - GdkDragContext *context, - guint time); - gboolean (*table_drag_motion) (ETable *table, - gint row, - gint col, - GdkDragContext *context, - gint x, - gint y, - guint time); - gboolean (*table_drag_drop) (ETable *table, - gint row, - gint col, - GdkDragContext *context, - gint x, - gint y, - guint time); - void (*table_drag_data_received) - (ETable *table, - gint row, - gint col, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time); -}; - -GType e_table_get_type (void) G_GNUC_CONST; -ETable * e_table_construct (ETable *e_table, - ETableModel *etm, - ETableExtras *ete, - const gchar *spec, - const gchar *state); -GtkWidget * e_table_new (ETableModel *etm, - ETableExtras *ete, - const gchar *spec, - const gchar *state); - -/* Create an ETable using files. */ -ETable * e_table_construct_from_spec_file - (ETable *e_table, - ETableModel *etm, - ETableExtras *ete, - const gchar *spec_fn, - const gchar *state_fn); -GtkWidget * e_table_new_from_spec_file (ETableModel *etm, - ETableExtras *ete, - const gchar *spec_fn, - const gchar *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, - gint row); - -/* -1 means we don't have the cursor. This is in model rows. */ -gint e_table_get_cursor_row (ETable *e_table); -void e_table_selected_row_foreach (ETable *e_table, - EForeachFunc 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); -void e_table_get_cell_at (ETable *table, - gint x, - gint y, - gint *row_return, - gint *col_return); -void e_table_get_mouse_over_cell (ETable *table, - gint *row, - gint *col); -void e_table_get_cell_geometry (ETable *table, - gint row, - gint col, - gint *x_return, - gint *y_return, - gint *width_return, - gint *height_return); - -/* Useful accessor functions. */ -ESelectionModel *e_table_get_selection_model (ETable *table); - -/* Drag & drop stuff. */ -/* Target */ -void e_table_drag_get_data (ETable *table, - gint row, - gint col, - GdkDragContext *context, - GdkAtom target, - guint32 time); -void e_table_drag_highlight (ETable *table, - gint row, - gint 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, - gint row, - gint 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); - -/* This function is only needed in single_selection_mode. */ -void e_table_right_click_up (ETable *table); - -void e_table_commit_click_to_add (ETable *table); - -void e_table_freeze_state_change (ETable *table); -void e_table_thaw_state_change (ETable *table); - -G_END_DECLS - -#endif /* _E_TABLE_H_ */ - diff --git a/widgets/table/e-tree-memory-callbacks.c b/widgets/table/e-tree-memory-callbacks.c deleted file mode 100644 index 9f8d7d468a..0000000000 --- a/widgets/table/e-tree-memory-callbacks.c +++ /dev/null @@ -1,316 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtk.h> - -#include "e-util/e-util.h" - -#include "e-tree-memory-callbacks.h" - -G_DEFINE_TYPE (ETreeMemoryCallbacks, e_tree_memory_callbacks, E_TYPE_TREE_MEMORY) - -static GdkPixbuf * -etmc_icon_at (ETreeModel *etm, - ETreePath node) -{ - ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm); - - return etmc->icon_at (etm, node, etmc->model_data); -} - -static gint -etmc_column_count (ETreeModel *etm) -{ - ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm); - - if (etmc->column_count) - return etmc->column_count (etm, etmc->model_data); - else - return 0; -} - -static gboolean -etmc_has_save_id (ETreeModel *etm) -{ - ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm); - - if (etmc->has_save_id) - return etmc->has_save_id (etm, etmc->model_data); - else - return FALSE; -} - -static gchar * -etmc_get_save_id (ETreeModel *etm, - ETreePath node) -{ - ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm); - - if (etmc->get_save_id) - return etmc->get_save_id (etm, node, etmc->model_data); - else - return NULL; -} - -static gboolean -etmc_has_get_node_by_id (ETreeModel *etm) -{ - ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm); - - if (etmc->has_get_node_by_id) - return etmc->has_get_node_by_id (etm, etmc->model_data); - else - return FALSE; -} - -static ETreePath -etmc_get_node_by_id (ETreeModel *etm, - const gchar *save_id) -{ - ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm); - - if (etmc->get_node_by_id) - return etmc->get_node_by_id (etm, save_id, etmc->model_data); - else - return NULL; -} - -static gpointer -etmc_sort_value_at (ETreeModel *etm, - ETreePath node, - gint col) -{ - ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm); - - if (etmc->sort_value_at) - return etmc->sort_value_at (etm, node, col, etmc->model_data); - else - return etmc->value_at (etm, node, col, etmc->model_data); -} - -static gpointer -etmc_value_at (ETreeModel *etm, - ETreePath node, - gint col) -{ - ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm); - - return etmc->value_at (etm, node, col, etmc->model_data); -} - -static void -etmc_set_value_at (ETreeModel *etm, - ETreePath node, - gint col, - gconstpointer val) -{ - ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm); - - etmc->set_value_at (etm, node, col, val, etmc->model_data); -} - -static gboolean -etmc_is_editable (ETreeModel *etm, - ETreePath node, - gint col) -{ - ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm); - - return etmc->is_editable (etm, node, col, etmc->model_data); -} - -/* The default for etmc_duplicate_value is to return the raw value. */ -static gpointer -etmc_duplicate_value (ETreeModel *etm, - gint col, - gconstpointer value) -{ - ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm); - - if (etmc->duplicate_value) - return etmc->duplicate_value (etm, col, value, etmc->model_data); - else - return (gpointer) value; -} - -static void -etmc_free_value (ETreeModel *etm, - gint col, - gpointer value) -{ - ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm); - - if (etmc->free_value) - etmc->free_value (etm, col, value, etmc->model_data); -} - -static gpointer -etmc_initialize_value (ETreeModel *etm, - gint col) -{ - ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm); - - if (etmc->initialize_value) - return etmc->initialize_value (etm, col, etmc->model_data); - else - return NULL; -} - -static gboolean -etmc_value_is_empty (ETreeModel *etm, - gint col, - gconstpointer value) -{ - ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm); - - if (etmc->value_is_empty) - return etmc->value_is_empty (etm, col, value, etmc->model_data); - else - return FALSE; -} - -static gchar * -etmc_value_to_string (ETreeModel *etm, - gint col, - gconstpointer value) -{ - ETreeMemoryCallbacks *etmc = E_TREE_MEMORY_CALLBACKS (etm); - - if (etmc->value_to_string) - return etmc->value_to_string (etm, col, value, etmc->model_data); - else - return g_strdup (""); -} - -static void -e_tree_memory_callbacks_class_init (ETreeMemoryCallbacksClass *class) -{ - ETreeModelClass *model_class = E_TREE_MODEL_CLASS (class); - - model_class->icon_at = etmc_icon_at; - - model_class->column_count = etmc_column_count; - - model_class->has_save_id = etmc_has_save_id; - model_class->get_save_id = etmc_get_save_id; - - model_class->has_get_node_by_id = etmc_has_get_node_by_id; - model_class->get_node_by_id = etmc_get_node_by_id; - - model_class->sort_value_at = etmc_sort_value_at; - model_class->value_at = etmc_value_at; - model_class->set_value_at = etmc_set_value_at; - model_class->is_editable = etmc_is_editable; - - model_class->duplicate_value = etmc_duplicate_value; - model_class->free_value = etmc_free_value; - model_class->initialize_value = etmc_initialize_value; - model_class->value_is_empty = etmc_value_is_empty; - model_class->value_to_string = etmc_value_to_string; -} - -static void -e_tree_memory_callbacks_init (ETreeMemoryCallbacks *etmc) -{ - /* nothing to do */ -} - -/** - * e_tree_memory_callbacks_new: - * - * This initializes a new ETreeMemoryCallbacksModel object. - * ETreeMemoryCallbacksModel is an implementaiton of the somewhat - * abstract class ETreeMemory. The ETreeMemoryCallbacksModel is - * designed to allow people to easily create ETreeMemorys without - * having to create a new GType derived from ETreeMemory every time - * they need one. - * - * Instead, ETreeMemoryCallbacksModel 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. - * - * ETreeMemoryCallbacks is to ETreeMemory as ETableSimple is to ETableModel. - * - * Return value: An ETreeMemoryCallbacks object (which is also an - * ETreeMemory and thus an ETreeModel object). - * - */ -ETreeModel * -e_tree_memory_callbacks_new (ETreeMemoryCallbacksIconAtFn icon_at, - - ETreeMemoryCallbacksColumnCountFn column_count, - - ETreeMemoryCallbacksHasSaveIdFn has_save_id, - ETreeMemoryCallbacksGetSaveIdFn get_save_id, - - ETreeMemoryCallbacksHasGetNodeByIdFn has_get_node_by_id, - ETreeMemoryCallbacksGetNodeByIdFn get_node_by_id, - - ETreeMemoryCallbacksValueAtFn sort_value_at, - ETreeMemoryCallbacksValueAtFn value_at, - ETreeMemoryCallbacksSetValueAtFn set_value_at, - ETreeMemoryCallbacksIsEditableFn is_editable, - - ETreeMemoryCallbacksDuplicateValueFn duplicate_value, - ETreeMemoryCallbacksFreeValueFn free_value, - ETreeMemoryCallbacksInitializeValueFn initialize_value, - ETreeMemoryCallbacksValueIsEmptyFn value_is_empty, - ETreeMemoryCallbacksValueToStringFn value_to_string, - - gpointer model_data) -{ - ETreeMemoryCallbacks *etmc; - - etmc = g_object_new (E_TYPE_TREE_MEMORY_CALLBACKS, NULL); - - etmc->icon_at = icon_at; - - etmc->column_count = column_count; - - etmc->has_save_id = has_save_id; - etmc->get_save_id = get_save_id; - - etmc->has_get_node_by_id = has_get_node_by_id; - etmc->get_node_by_id = get_node_by_id; - - etmc->sort_value_at = sort_value_at; - etmc->value_at = value_at; - etmc->set_value_at = set_value_at; - etmc->is_editable = is_editable; - - etmc->duplicate_value = duplicate_value; - etmc->free_value = free_value; - etmc->initialize_value = initialize_value; - etmc->value_is_empty = value_is_empty; - etmc->value_to_string = value_to_string; - - etmc->model_data = model_data; - - return (ETreeModel *) etmc; -} - diff --git a/widgets/table/e-tree-memory-callbacks.h b/widgets/table/e-tree-memory-callbacks.h deleted file mode 100644 index f2e202bec3..0000000000 --- a/widgets/table/e-tree-memory-callbacks.h +++ /dev/null @@ -1,178 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TREE_MEMORY_CALLBACKS_H_ -#define _E_TREE_MEMORY_CALLBACKS_H_ - -#include <table/e-tree-memory.h> - -/* Standard GObject macros */ -#define E_TYPE_TREE_MEMORY_CALLBACKS \ - (e_tree_memory_callbacks_get_type ()) -#define E_TREE_MEMORY_CALLBACKS(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TREE_MEMORY_CALLBACKS, ETreeMemoryCallbacks)) -#define E_TREE_MEMORY_CALLBACKS_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TREE_MEMORY_CALLBACKS, ETreeMemoryCallbacksClass)) -#define E_IS_TREE_MEMORY_CALLBACKS(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TREE_MEMORY_CALLBACKS)) -#define E_IS_TREE_MEMORY_CALLBACKS_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TREE_MEMORY_CALLBACKS)) -#define E_TREE_MEMORY_CALLBACKS_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TREE_MEMORY_CALLBACKS, ETreeMemoryCallbacksClass)) - -G_BEGIN_DECLS - -typedef struct _ETreeMemoryCallbacks ETreeMemoryCallbacks; -typedef struct _ETreeMemoryCallbacksClass ETreeMemoryCallbacksClass; - -typedef GdkPixbuf * (*ETreeMemoryCallbacksIconAtFn) - (ETreeModel *etree, - ETreePath path, - gpointer model_data); - -typedef gint (*ETreeMemoryCallbacksColumnCountFn) - (ETreeModel *etree, - gpointer model_data); - -typedef gboolean (*ETreeMemoryCallbacksHasSaveIdFn) - (ETreeModel *etree, - gpointer model_data); -typedef gchar * (*ETreeMemoryCallbacksGetSaveIdFn) - (ETreeModel *etree, - ETreePath path, - gpointer model_data); - -typedef gboolean (*ETreeMemoryCallbacksHasGetNodeByIdFn) - (ETreeModel *etree, - gpointer model_data); -typedef ETreePath (*ETreeMemoryCallbacksGetNodeByIdFn) - (ETreeModel *etree, - const gchar *save_id, - gpointer model_data); - -typedef gpointer (*ETreeMemoryCallbacksValueAtFn) - (ETreeModel *etree, - ETreePath path, - gint col, - gpointer model_data); -typedef void (*ETreeMemoryCallbacksSetValueAtFn) - (ETreeModel *etree, - ETreePath path, - gint col, - gconstpointer val, - gpointer model_data); -typedef gboolean (*ETreeMemoryCallbacksIsEditableFn) - (ETreeModel *etree, - ETreePath path, - gint col, - gpointer model_data); - -typedef gpointer (*ETreeMemoryCallbacksDuplicateValueFn) - (ETreeModel *etm, - gint col, - gconstpointer val, - gpointer data); -typedef void (*ETreeMemoryCallbacksFreeValueFn) - (ETreeModel *etm, - gint col, - gpointer val, - gpointer data); -typedef gpointer (*ETreeMemoryCallbacksInitializeValueFn) - (ETreeModel *etm, - gint col, - gpointer data); -typedef gboolean (*ETreeMemoryCallbacksValueIsEmptyFn) - (ETreeModel *etm, - gint col, - gconstpointer val, - gpointer data); -typedef gchar * (*ETreeMemoryCallbacksValueToStringFn) - (ETreeModel *etm, - gint col, - gconstpointer val, - gpointer data); - -struct _ETreeMemoryCallbacks { - ETreeMemory parent; - - ETreeMemoryCallbacksIconAtFn icon_at; - - ETreeMemoryCallbacksColumnCountFn column_count; - - ETreeMemoryCallbacksHasSaveIdFn has_save_id; - ETreeMemoryCallbacksGetSaveIdFn get_save_id; - - ETreeMemoryCallbacksHasGetNodeByIdFn has_get_node_by_id; - ETreeMemoryCallbacksGetNodeByIdFn get_node_by_id; - - ETreeMemoryCallbacksValueAtFn sort_value_at; - ETreeMemoryCallbacksValueAtFn value_at; - ETreeMemoryCallbacksSetValueAtFn set_value_at; - ETreeMemoryCallbacksIsEditableFn is_editable; - - ETreeMemoryCallbacksDuplicateValueFn duplicate_value; - ETreeMemoryCallbacksFreeValueFn free_value; - ETreeMemoryCallbacksInitializeValueFn initialize_value; - ETreeMemoryCallbacksValueIsEmptyFn value_is_empty; - ETreeMemoryCallbacksValueToStringFn value_to_string; - - gpointer model_data; -}; - -struct _ETreeMemoryCallbacksClass { - ETreeMemoryClass parent_class; -}; - -GType e_tree_memory_callbacks_get_type - (void) G_GNUC_CONST; -ETreeModel * e_tree_memory_callbacks_new - (ETreeMemoryCallbacksIconAtFn icon_at, - - ETreeMemoryCallbacksColumnCountFn column_count, - - ETreeMemoryCallbacksHasSaveIdFn has_save_id, - ETreeMemoryCallbacksGetSaveIdFn get_save_id, - - ETreeMemoryCallbacksHasGetNodeByIdFn has_get_node_by_id, - ETreeMemoryCallbacksGetNodeByIdFn get_node_by_id, - - ETreeMemoryCallbacksValueAtFn sort_value_at, - ETreeMemoryCallbacksValueAtFn value_at, - ETreeMemoryCallbacksSetValueAtFn set_value_at, - ETreeMemoryCallbacksIsEditableFn is_editable, - - ETreeMemoryCallbacksDuplicateValueFn duplicate_value, - ETreeMemoryCallbacksFreeValueFn free_value, - ETreeMemoryCallbacksInitializeValueFn initialize_value, - ETreeMemoryCallbacksValueIsEmptyFn value_is_empty, - ETreeMemoryCallbacksValueToStringFn value_to_string, - - gpointer model_data); - -G_END_DECLS - -#endif /* _E_TREE_MEMORY_CALLBACKS_H_ */ diff --git a/widgets/table/e-tree-memory.c b/widgets/table/e-tree-memory.c deleted file mode 100644 index f779405d0e..0000000000 --- a/widgets/table/e-tree-memory.c +++ /dev/null @@ -1,744 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Chris Toshok <toshok@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <errno.h> -#include <unistd.h> -#include <fcntl.h> -#include <stdlib.h> - -#include <libxml/parser.h> -#include <libxml/xmlmemory.h> - -#include "e-util/e-util.h" -#include "libevolution-utils/e-xml-utils.h" - -#include "e-tree-memory.h" - -#define E_TREE_MEMORY_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), E_TYPE_TREE_MEMORY, ETreeMemoryPrivate)) - -G_DEFINE_TYPE (ETreeMemory, e_tree_memory, E_TYPE_TREE_MODEL) - -enum { - FILL_IN_CHILDREN, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0, }; - -typedef struct ETreeMemoryPath ETreeMemoryPath; - -struct ETreeMemoryPath { - gpointer node_data; - - guint children_computed : 1; - - /* parent/child/sibling pointers */ - ETreeMemoryPath *parent; - ETreeMemoryPath *next_sibling; - ETreeMemoryPath *prev_sibling; - ETreeMemoryPath *first_child; - ETreeMemoryPath *last_child; - - gint num_children; -}; - -struct _ETreeMemoryPrivate { - ETreeMemoryPath *root; - - /* whether nodes are created expanded - * or collapsed by default */ - gboolean expanded_default; - - gint frozen; - GFunc destroy_func; - gpointer destroy_user_data; -}; - -/* ETreeMemoryPath functions */ - -static inline void -check_children (ETreeMemory *memory, - ETreePath node) -{ - ETreeMemoryPath *path = node; - if (!path->children_computed) { - g_signal_emit (memory, signals[FILL_IN_CHILDREN], 0, node); - path->children_computed = TRUE; - } -} - -static gint -e_tree_memory_path_depth (ETreeMemoryPath *path) -{ - gint depth = 0; - - g_return_val_if_fail (path != NULL, -1); - - for (path = path->parent; path; path = path->parent) - depth++; - return depth; -} - -static void -e_tree_memory_path_insert (ETreeMemoryPath *parent, - gint position, - ETreeMemoryPath *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 { - ETreeMemoryPath *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 (ETreeMemoryPath *path) -{ - ETreeMemoryPath *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_memory_freeze: - * @etmm: 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_memory_freeze (ETreeMemory *etmm) -{ - ETreeMemoryPrivate *priv = etmm->priv; - - if (priv->frozen == 0) - e_tree_model_pre_change (E_TREE_MODEL (etmm)); - - priv->frozen++; -} - -/** - * e_tree_memory_thaw: - * @etmm: the ETreeMemory to thaw. - * - * This function thaws an ETreeMemory. 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_memory_thaw (ETreeMemory *etmm) -{ - ETreeMemoryPrivate *priv = etmm->priv; - - if (priv->frozen > 0) - priv->frozen--; - if (priv->frozen == 0) { - e_tree_model_node_changed (E_TREE_MODEL (etmm), priv->root); - } -} - -/* virtual methods */ - -static void -etmm_dispose (GObject *object) -{ - ETreeMemoryPrivate *priv; - - priv = E_TREE_MEMORY_GET_PRIVATE (object); - - if (priv->root) - e_tree_memory_node_remove ( - E_TREE_MEMORY (object), priv->root); - - G_OBJECT_CLASS (e_tree_memory_parent_class)->dispose (object); -} - -static ETreePath -etmm_get_root (ETreeModel *etm) -{ - ETreeMemoryPrivate *priv = E_TREE_MEMORY (etm)->priv; - return priv->root; -} - -static ETreePath -etmm_get_parent (ETreeModel *etm, - ETreePath node) -{ - ETreeMemoryPath *path = node; - return path->parent; -} - -static ETreePath -etmm_get_first_child (ETreeModel *etm, - ETreePath node) -{ - ETreeMemoryPath *path = node; - - check_children (E_TREE_MEMORY (etm), node); - return path->first_child; -} - -static ETreePath -etmm_get_last_child (ETreeModel *etm, - ETreePath node) -{ - ETreeMemoryPath *path = node; - - check_children (E_TREE_MEMORY (etm), node); - return path->last_child; -} - -static ETreePath -etmm_get_next (ETreeModel *etm, - ETreePath node) -{ - ETreeMemoryPath *path = node; - return path->next_sibling; -} - -static ETreePath -etmm_get_prev (ETreeModel *etm, - ETreePath node) -{ - ETreeMemoryPath *path = node; - return path->prev_sibling; -} - -static gboolean -etmm_is_root (ETreeModel *etm, - ETreePath node) -{ - ETreeMemoryPath *path = node; - return e_tree_memory_path_depth (path) == 0; -} - -static gboolean -etmm_is_expandable (ETreeModel *etm, - ETreePath node) -{ - ETreeMemoryPath *path = node; - - check_children (E_TREE_MEMORY (etm), node); - return path->first_child != NULL; -} - -static guint -etmm_get_children (ETreeModel *etm, - ETreePath node, - ETreePath **nodes) -{ - ETreeMemoryPath *path = node; - guint n_children; - - check_children (E_TREE_MEMORY (etm), node); - - n_children = path->num_children; - - if (nodes) { - ETreeMemoryPath *p; - gint i = 0; - - (*nodes) = g_new (ETreePath, n_children); - for (p = path->first_child; p; p = p->next_sibling) { - (*nodes)[i++] = p; - } - } - - return n_children; -} - -static guint -etmm_depth (ETreeModel *etm, - ETreePath path) -{ - return e_tree_memory_path_depth (path); -} - -static gboolean -etmm_get_expanded_default (ETreeModel *etm) -{ - ETreeMemory *etmm = E_TREE_MEMORY (etm); - ETreeMemoryPrivate *priv = etmm->priv; - - return priv->expanded_default; -} - -static void -etmm_clear_children_computed (ETreeMemoryPath *path) -{ - for (path = path->first_child; path; path = path->next_sibling) { - path->children_computed = FALSE; - etmm_clear_children_computed (path); - } -} - -static void -etmm_node_request_collapse (ETreeModel *etm, - ETreePath node) -{ - ETreeModelClass *parent_class; - - if (node) - etmm_clear_children_computed (node); - - parent_class = E_TREE_MODEL_CLASS (e_tree_memory_parent_class); - - if (parent_class->node_request_collapse != NULL) - parent_class->node_request_collapse (etm, node); -} - -static void -e_tree_memory_class_init (ETreeMemoryClass *class) -{ - GObjectClass *object_class; - ETreeModelClass *tree_model_class; - - g_type_class_add_private (class, sizeof (ETreeMemoryPrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->dispose = etmm_dispose; - - tree_model_class = E_TREE_MODEL_CLASS (class); - tree_model_class->get_root = etmm_get_root; - tree_model_class->get_prev = etmm_get_prev; - tree_model_class->get_next = etmm_get_next; - tree_model_class->get_first_child = etmm_get_first_child; - tree_model_class->get_last_child = etmm_get_last_child; - tree_model_class->get_parent = etmm_get_parent; - - tree_model_class->is_root = etmm_is_root; - tree_model_class->is_expandable = etmm_is_expandable; - tree_model_class->get_children = etmm_get_children; - tree_model_class->depth = etmm_depth; - tree_model_class->get_expanded_default = etmm_get_expanded_default; - - tree_model_class->node_request_collapse = etmm_node_request_collapse; - - class->fill_in_children = NULL; - - signals[FILL_IN_CHILDREN] = g_signal_new ( - "fill_in_children", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeMemoryClass, fill_in_children), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); -} - -static void -e_tree_memory_init (ETreeMemory *etmm) -{ - etmm->priv = E_TREE_MEMORY_GET_PRIVATE (etmm); -} - -/** - * e_tree_memory_construct: - * @etree: - * - * - **/ -void -e_tree_memory_construct (ETreeMemory *etmm) -{ -} - -/** - * e_tree_memory_new - * - * XXX docs here. - * - * return values: a newly constructed ETreeMemory. - */ -ETreeMemory * -e_tree_memory_new (void) -{ - return g_object_new (E_TYPE_TREE_MEMORY, NULL); -} - -/** - * e_tree_memory_set_expanded_default - * - * Sets the state of nodes to be append to a thread. - * They will either be expanded or collapsed, according to - * the value of @expanded. - */ -void -e_tree_memory_set_expanded_default (ETreeMemory *etree, - gboolean expanded) -{ - g_return_if_fail (etree != NULL); - - etree->priv->expanded_default = expanded; -} - -/** - * e_tree_memory_node_get_data: - * @etmm: - * @node: - * - * - * - * Return value: - **/ -gpointer -e_tree_memory_node_get_data (ETreeMemory *etmm, - ETreePath node) -{ - ETreeMemoryPath *path = node; - - g_return_val_if_fail (path, NULL); - - return path->node_data; -} - -/** - * e_tree_memory_node_set_data: - * @etmm: - * @node: - * @node_data: - * - * - **/ -void -e_tree_memory_node_set_data (ETreeMemory *etmm, - ETreePath node, - gpointer node_data) -{ - ETreeMemoryPath *path = node; - - g_return_if_fail (path); - - path->node_data = node_data; -} - -/** - * e_tree_memory_node_insert: - * @tree_model: - * @parent_path: - * @position: - * @node_data: - * - * - * - * Return value: - **/ -ETreePath -e_tree_memory_node_insert (ETreeMemory *tree_model, - ETreePath parent_node, - gint position, - gpointer node_data) -{ - ETreeMemoryPrivate *priv; - ETreeMemoryPath *new_path; - ETreeMemoryPath *parent_path = parent_node; - - g_return_val_if_fail (tree_model != NULL, NULL); - - priv = tree_model->priv; - - g_return_val_if_fail (parent_path != NULL || priv->root == NULL, NULL); - - priv = tree_model->priv; - - if (!tree_model->priv->frozen) - e_tree_model_pre_change (E_TREE_MODEL (tree_model)); - - new_path = g_slice_new0 (ETreeMemoryPath); - - new_path->node_data = node_data; - new_path->children_computed = FALSE; - - if (parent_path != NULL) { - e_tree_memory_path_insert (parent_path, position, new_path); - if (!tree_model->priv->frozen) - e_tree_model_node_inserted ( - E_TREE_MODEL (tree_model), - parent_path, new_path); - } else { - priv->root = new_path; - if (!tree_model->priv->frozen) - e_tree_model_node_changed ( - E_TREE_MODEL (tree_model), new_path); - } - - return new_path; -} - -ETreePath -e_tree_memory_node_insert_id (ETreeMemory *etree, - ETreePath parent, - gint position, - gpointer node_data, - gchar *id) -{ - return e_tree_memory_node_insert (etree, parent, position, node_data); -} - -/** - * e_tree_memory_node_insert_before: - * @etree: - * @parent: - * @sibling: - * @node_data: - * - * - * - * Return value: - **/ -ETreePath -e_tree_memory_node_insert_before (ETreeMemory *etree, - ETreePath parent, - ETreePath sibling, - gpointer node_data) -{ - ETreeMemoryPath *child; - ETreeMemoryPath *parent_path = parent; - ETreeMemoryPath *sibling_path = sibling; - gint position = 0; - - g_return_val_if_fail (etree != NULL, NULL); - - if (sibling != NULL) { - for (child = parent_path->first_child; child; child = child->next_sibling) { - if (child == sibling_path) - break; - position++; - } - } else - position = parent_path->num_children; - return e_tree_memory_node_insert (etree, parent, position, node_data); -} - -/* just blows away child data, doesn't take into account unlinking/etc */ -static void -child_free (ETreeMemory *etree, - ETreeMemoryPath *node) -{ - ETreeMemoryPath *child, *next; - - child = node->first_child; - while (child) { - next = child->next_sibling; - child_free (etree, child); - child = next; - } - - if (etree->priv->destroy_func) { - etree->priv->destroy_func (node->node_data, etree->priv->destroy_user_data); - } - - g_slice_free (ETreeMemoryPath, node); -} - -/** - * e_tree_memory_node_remove: - * @etree: - * @path: - * - * - * - * Return value: - **/ -gpointer -e_tree_memory_node_remove (ETreeMemory *etree, - ETreePath node) -{ - ETreeMemoryPath *path = node; - ETreeMemoryPath *parent = path->parent; - ETreeMemoryPath *sibling; - gpointer ret = path->node_data; - gint old_position = 0; - - g_return_val_if_fail (etree != NULL, NULL); - - if (!etree->priv->frozen) { - e_tree_model_pre_change (E_TREE_MODEL (etree)); - for (old_position = 0, sibling = path; - sibling; - old_position++, sibling = sibling->prev_sibling) - /* Empty intentionally*/; - old_position--; - } - - /* 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 (!etree->priv->frozen) - e_tree_model_node_removed (E_TREE_MODEL (etree), parent, path, old_position); - - child_free (etree, path); - - if (path == etree->priv->root) - etree->priv->root = NULL; - - if (!etree->priv->frozen) - e_tree_model_node_deleted (E_TREE_MODEL (etree), path); - - return ret; -} - -typedef struct { - ETreeMemory *memory; - gpointer closure; - ETreeMemorySortCallback callback; -} MemoryAndClosure; - -static gint -sort_callback (gconstpointer data1, - gconstpointer data2, - gpointer user_data) -{ - ETreePath path1 = *(ETreePath *) data1; - ETreePath path2 = *(ETreePath *) data2; - MemoryAndClosure *mac = user_data; - return (*mac->callback) (mac->memory, path1, path2, mac->closure); -} - -void -e_tree_memory_sort_node (ETreeMemory *etmm, - ETreePath node, - ETreeMemorySortCallback callback, - gpointer user_data) -{ - ETreeMemoryPath **children; - ETreeMemoryPath *child; - gint count; - gint i; - ETreeMemoryPath *path = node; - MemoryAndClosure mac; - ETreeMemoryPath *last; - - e_tree_model_pre_change (E_TREE_MODEL (etmm)); - - i = 0; - for (child = path->first_child; child; child = child->next_sibling) - i++; - - children = g_new (ETreeMemoryPath *, i); - - count = i; - - for (child = path->first_child, i = 0; - child; - child = child->next_sibling, i++) { - children[i] = child; - } - - mac.memory = etmm; - mac.closure = user_data; - mac.callback = callback; - - g_qsort_with_data ( - children, count, sizeof (ETreeMemoryPath *), - sort_callback, &mac); - - path->first_child = NULL; - last = NULL; - for (i = 0; - i < count; - i++) { - children[i]->prev_sibling = last; - if (last) - last->next_sibling = children[i]; - else - path->first_child = children[i]; - last = children[i]; - } - if (last) - last->next_sibling = NULL; - - path->last_child = last; - - g_free (children); - - e_tree_model_node_changed (E_TREE_MODEL (etmm), node); -} - -void -e_tree_memory_set_node_destroy_func (ETreeMemory *etmm, - GFunc destroy_func, - gpointer user_data) -{ - etmm->priv->destroy_func = destroy_func; - etmm->priv->destroy_user_data = user_data; -} diff --git a/widgets/table/e-tree-memory.h b/widgets/table/e-tree-memory.h deleted file mode 100644 index cff4811256..0000000000 --- a/widgets/table/e-tree-memory.h +++ /dev/null @@ -1,119 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Chris Toshok <toshok@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TREE_MEMORY_H_ -#define _E_TREE_MEMORY_H_ - -#include <gdk-pixbuf/gdk-pixbuf.h> -#include <table/e-tree-model.h> - -/* Standard GObject macros */ -#define E_TYPE_TREE_MEMORY \ - (e_tree_memory_get_type ()) -#define E_TREE_MEMORY(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TREE_MEMORY, ETreeMemory)) -#define E_TREE_MEMORY_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TREE_MEMORY, ETreeMemoryClass)) -#define E_IS_TREE_MEMORY(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TREE_MEMORY)) -#define E_IS_TREE_MEMORY_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TREE_MEMORY)) -#define E_TREE_MEMORY_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TREE_MEMORY, ETreeMemoryClass)) - -G_BEGIN_DECLS - -typedef struct _ETreeMemory ETreeMemory; -typedef struct _ETreeMemoryClass ETreeMemoryClass; -typedef struct _ETreeMemoryPrivate ETreeMemoryPrivate; - -typedef gint (*ETreeMemorySortCallback) (ETreeMemory *etmm, - ETreePath path1, - ETreePath path2, - gpointer closure); - -struct _ETreeMemory { - ETreeModel parent; - ETreeMemoryPrivate *priv; -}; - -struct _ETreeMemoryClass { - ETreeModelClass parent_class; - - /* Signals */ - void (*fill_in_children) (ETreeMemory *model, - ETreePath node); -}; - -GType e_tree_memory_get_type (void) G_GNUC_CONST; -void e_tree_memory_construct (ETreeMemory *etree); -ETreeMemory * e_tree_memory_new (void); - -/* node operations */ -ETreePath e_tree_memory_node_insert (ETreeMemory *etree, - ETreePath parent, - gint position, - gpointer node_data); -ETreePath e_tree_memory_node_insert_id (ETreeMemory *etree, - ETreePath parent, - gint position, - gpointer node_data, - gchar *id); -ETreePath e_tree_memory_node_insert_before - (ETreeMemory *etree, - ETreePath parent, - ETreePath sibling, - gpointer node_data); -gpointer e_tree_memory_node_remove (ETreeMemory *etree, - ETreePath path); - -/* Freeze and thaw */ -void e_tree_memory_freeze (ETreeMemory *etree); -void e_tree_memory_thaw (ETreeMemory *etree); -void e_tree_memory_set_expanded_default - (ETreeMemory *etree, - gboolean expanded); -gpointer e_tree_memory_node_get_data (ETreeMemory *etm, - ETreePath node); -void e_tree_memory_node_set_data (ETreeMemory *etm, - ETreePath node, - gpointer node_data); -void e_tree_memory_sort_node (ETreeMemory *etm, - ETreePath node, - ETreeMemorySortCallback callback, - gpointer user_data); -void e_tree_memory_set_node_destroy_func - (ETreeMemory *etmm, - GFunc destroy_func, - gpointer user_data); - -G_END_DECLS - -#endif /* _E_TREE_MEMORY_H */ - diff --git a/widgets/table/e-tree-model.c b/widgets/table/e-tree-model.c deleted file mode 100644 index 944572dfb4..0000000000 --- a/widgets/table/e-tree-model.c +++ /dev/null @@ -1,1177 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Chris Toshok <toshok@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> - -#include <gtk/gtk.h> -#include <libxml/parser.h> -#include <libxml/xmlmemory.h> - -#include "e-util/e-util.h" -#include "libevolution-utils/e-xml-utils.h" - -#include "e-tree-model.h" - -#define ETM_CLASS(e) (E_TREE_MODEL_GET_CLASS(e)) - -#define d(x) - -G_DEFINE_TYPE (ETreeModel, e_tree_model, G_TYPE_OBJECT) - -enum { - PRE_CHANGE, - NO_CHANGE, - NODE_CHANGED, - NODE_DATA_CHANGED, - NODE_COL_CHANGED, - NODE_INSERTED, - NODE_REMOVED, - NODE_DELETED, - NODE_REQUEST_COLLAPSE, - REBUILT, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = {0, }; - -static void -e_tree_model_class_init (ETreeModelClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - signals[PRE_CHANGE] = g_signal_new ( - "pre_change", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeModelClass, pre_change), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[NO_CHANGE] = g_signal_new ( - "no_change", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeModelClass, no_change), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[REBUILT] = g_signal_new ( - "rebuilt", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeModelClass, rebuilt), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[NODE_CHANGED] = g_signal_new ( - "node_changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeModelClass, node_changed), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); - - signals[NODE_DATA_CHANGED] = g_signal_new ( - "node_data_changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeModelClass, node_data_changed), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); - - signals[NODE_COL_CHANGED] = g_signal_new ( - "node_col_changed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeModelClass, node_col_changed), - (GSignalAccumulator) NULL, NULL, - e_marshal_VOID__POINTER_INT, - G_TYPE_NONE, 2, - G_TYPE_POINTER, - G_TYPE_INT); - - signals[NODE_INSERTED] = g_signal_new ( - "node_inserted", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeModelClass, node_inserted), - (GSignalAccumulator) NULL, NULL, - e_marshal_VOID__POINTER_POINTER, - G_TYPE_NONE, 2, - G_TYPE_POINTER, - G_TYPE_POINTER); - - signals[NODE_REMOVED] = g_signal_new ( - "node_removed", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeModelClass, node_removed), - (GSignalAccumulator) NULL, NULL, - e_marshal_VOID__POINTER_POINTER_INT, - G_TYPE_NONE, 3, - G_TYPE_POINTER, - G_TYPE_POINTER, - G_TYPE_INT); - - signals[NODE_DELETED] = g_signal_new ( - "node_deleted", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeModelClass, node_deleted), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); - - signals[NODE_REQUEST_COLLAPSE] = g_signal_new ( - "node_request_collapse", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeModelClass, node_request_collapse), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); - - class->get_root = NULL; - - class->get_parent = NULL; - class->get_first_child = NULL; - class->get_last_child = NULL; - class->get_next = NULL; - class->get_prev = NULL; - - class->is_root = NULL; - class->is_expandable = NULL; - class->get_children = NULL; - class->depth = NULL; - - class->icon_at = NULL; - - class->get_expanded_default = NULL; - class->column_count = NULL; - - class->has_save_id = NULL; - class->get_save_id = NULL; - class->has_get_node_by_id = NULL; - class->get_node_by_id = NULL; - - class->has_change_pending = NULL; - - class->sort_value_at = NULL; - class->value_at = NULL; - class->set_value_at = NULL; - class->is_editable = NULL; - - class->duplicate_value = NULL; - class->free_value = NULL; - class->initialize_value = NULL; - class->value_is_empty = NULL; - class->value_to_string = NULL; - - class->pre_change = NULL; - class->no_change = NULL; - class->rebuilt = NULL; - class->node_changed = NULL; - class->node_data_changed = NULL; - class->node_col_changed = NULL; - class->node_inserted = NULL; - class->node_removed = NULL; - class->node_deleted = NULL; - class->node_request_collapse = NULL; -} - -static void -e_tree_model_init (ETreeModel *tree_model) -{ - /* nothing to do */ -} - -/* signals */ - -/** - * e_tree_model_node_changed: - * @tree_model: - * @node: - * - * - * - * Return value: - **/ -void -e_tree_model_pre_change (ETreeModel *tree_model) -{ - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - g_signal_emit (tree_model, signals[PRE_CHANGE], 0); -} - -/** - * e_tree_model_node_changed: - * @tree_model: - * @node: - * - * - * - * Return value: - **/ -void -e_tree_model_no_change (ETreeModel *tree_model) -{ - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - g_signal_emit (tree_model, signals[NO_CHANGE], 0); -} - -/** - * e_tree_model_rebuilt: - * @tree_model: - * @node: - * - * - * - * Return value: - **/ -void -e_tree_model_rebuilt (ETreeModel *tree_model) -{ - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - g_signal_emit (tree_model, signals[REBUILT], 0); -} -/** - * e_tree_model_node_changed: - * @tree_model: - * @node: - * - * - * - * Return value: - **/ -void -e_tree_model_node_changed (ETreeModel *tree_model, - ETreePath node) -{ - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - g_signal_emit (tree_model, signals[NODE_CHANGED], 0, node); -} - -/** - * e_tree_model_node_data_changed: - * @tree_model: - * @node: - * - * - * - * Return value: - **/ -void -e_tree_model_node_data_changed (ETreeModel *tree_model, - ETreePath node) -{ - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - g_signal_emit (tree_model, signals[NODE_DATA_CHANGED], 0, node); -} - -/** - * e_tree_model_node_col_changed: - * @tree_model: - * @node: - * - * - * - * Return value: - **/ -void -e_tree_model_node_col_changed (ETreeModel *tree_model, - ETreePath node, - gint col) -{ - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - g_signal_emit (tree_model, signals[NODE_COL_CHANGED], 0, node, col); -} - -/** - * 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) -{ - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - g_signal_emit ( - tree_model, signals[NODE_INSERTED], 0, - 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, - gint old_position) -{ - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - g_signal_emit ( - tree_model, signals[NODE_REMOVED], 0, - parent_node, removed_node, old_position); -} - -/** - * e_tree_model_node_deleted: - * @tree_model: - * @deleted_node: - * - * - **/ -void -e_tree_model_node_deleted (ETreeModel *tree_model, - ETreePath deleted_node) -{ - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - g_signal_emit (tree_model, signals[NODE_DELETED], 0, deleted_node); -} - -/** - * e_tree_model_node_request_collapse: - * @tree_model: - * @collapsed_node: - * - * - **/ -void -e_tree_model_node_request_collapse (ETreeModel *tree_model, - ETreePath collapsed_node) -{ - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - g_signal_emit (tree_model, signals[NODE_REQUEST_COLLAPSE], 0, collapsed_node); -} - -/** - * e_tree_model_new - * - * XXX docs here. - * - * return values: a newly constructed ETreeModel. - */ -ETreeModel * -e_tree_model_new (void) -{ - return g_object_new (E_TYPE_TREE_MODEL, NULL); -} - -/** - * 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) -{ - g_return_val_if_fail (E_IS_TREE_MODEL (etree), NULL); - - if (ETM_CLASS (etree)->get_root) - return ETM_CLASS (etree)->get_root (etree); - else - return NULL; -} - -/** - * e_tree_model_node_get_parent: - * @etree: - * @path: - * - * - * - * Return value: - **/ -ETreePath -e_tree_model_node_get_parent (ETreeModel *etree, - ETreePath node) -{ - g_return_val_if_fail (E_IS_TREE_MODEL (etree), NULL); - - if (ETM_CLASS (etree)->get_parent) - return ETM_CLASS (etree)->get_parent (etree, node); - else - return NULL; -} - -/** - * e_tree_model_node_get_first_child: - * @etree: - * @node: - * - * - * - * Return value: - **/ -ETreePath -e_tree_model_node_get_first_child (ETreeModel *etree, - ETreePath node) -{ - g_return_val_if_fail (E_IS_TREE_MODEL (etree), NULL); - - if (ETM_CLASS (etree)->get_first_child) - return ETM_CLASS (etree)->get_first_child (etree, node); - else - return NULL; -} - -/** - * e_tree_model_node_get_last_child: - * @etree: - * @node: - * - * - * - * Return value: - **/ -ETreePath -e_tree_model_node_get_last_child (ETreeModel *etree, - ETreePath node) -{ - g_return_val_if_fail (E_IS_TREE_MODEL (etree), NULL); - - if (ETM_CLASS (etree)->get_last_child) - return ETM_CLASS (etree)->get_last_child (etree, node); - else - return NULL; -} - -/** - * e_tree_model_node_get_next: - * @etree: - * @node: - * - * - * - * Return value: - **/ -ETreePath -e_tree_model_node_get_next (ETreeModel *etree, - ETreePath node) -{ - g_return_val_if_fail (E_IS_TREE_MODEL (etree), NULL); - - if (ETM_CLASS (etree)->get_next) - return ETM_CLASS (etree)->get_next (etree, node); - else - return NULL; -} - -/** - * e_tree_model_node_get_prev: - * @etree: - * @node: - * - * - * - * Return value: - **/ -ETreePath -e_tree_model_node_get_prev (ETreeModel *etree, - ETreePath node) -{ - g_return_val_if_fail (E_IS_TREE_MODEL (etree), NULL); - - if (ETM_CLASS (etree)->get_prev) - return ETM_CLASS (etree)->get_prev (etree, node); - else - return NULL; -} - -/** - * e_tree_model_node_is_root: - * @etree: - * @path: - * - * - * - * Return value: - **/ -gboolean -e_tree_model_node_is_root (ETreeModel *etree, - ETreePath node) -{ - g_return_val_if_fail (etree != NULL, FALSE); - - if (ETM_CLASS (etree)->is_root) - return ETM_CLASS (etree)->is_root (etree, node); - else - return FALSE; -} - -/** - * e_tree_model_node_is_expandable: - * @etree: - * @path: - * - * - * - * Return value: - **/ -gboolean -e_tree_model_node_is_expandable (ETreeModel *etree, - ETreePath node) -{ - g_return_val_if_fail (etree != NULL, FALSE); - g_return_val_if_fail (node != NULL, FALSE); - - if (ETM_CLASS (etree)->is_expandable) - return ETM_CLASS (etree)->is_expandable (etree, node); - else - return FALSE; -} - -guint -e_tree_model_node_get_children (ETreeModel *etree, - ETreePath node, - ETreePath **nodes) -{ - g_return_val_if_fail (etree != NULL, 0); - if (ETM_CLASS (etree)->get_children) - return ETM_CLASS (etree)->get_children (etree, node, nodes); - else - return 0; -} - -/** - * e_tree_model_node_depth: - * @etree: - * @path: - * - * - * - * Return value: - **/ -guint -e_tree_model_node_depth (ETreeModel *etree, - ETreePath node) -{ - g_return_val_if_fail (E_IS_TREE_MODEL (etree), 0); - - if (ETM_CLASS (etree)->depth) - return ETM_CLASS (etree)->depth (etree, node); - else - return 0; -} - -/** - * e_tree_model_icon_at - * @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_at (ETreeModel *etree, - ETreePath node) -{ - g_return_val_if_fail (E_IS_TREE_MODEL (etree), NULL); - - if (ETM_CLASS (etree)->icon_at) - return ETM_CLASS (etree)->icon_at (etree, node); - else - return NULL; -} - -/** - * e_tree_model_get_expanded_default - * @etree: The ETreeModel. - * - * XXX docs here. - * - * return values: Whether nodes should be expanded by default. - */ -gboolean -e_tree_model_get_expanded_default (ETreeModel *etree) -{ - g_return_val_if_fail (E_IS_TREE_MODEL (etree), FALSE); - - if (ETM_CLASS (etree)->get_expanded_default) - return ETM_CLASS (etree)->get_expanded_default (etree); - else - return FALSE; -} - -/** - * e_tree_model_column_count - * @etree: The ETreeModel. - * - * XXX docs here. - * - * return values: The number of columns - */ -gint -e_tree_model_column_count (ETreeModel *etree) -{ - g_return_val_if_fail (E_IS_TREE_MODEL (etree), 0); - - if (ETM_CLASS (etree)->column_count) - return ETM_CLASS (etree)->column_count (etree); - else - return 0; -} - -/** - * e_tree_model_has_save_id - * @etree: The ETreeModel. - * - * XXX docs here. - * - * return values: Whether this tree has valid save id data. - */ -gboolean -e_tree_model_has_save_id (ETreeModel *etree) -{ - g_return_val_if_fail (E_IS_TREE_MODEL (etree), FALSE); - - if (ETM_CLASS (etree)->has_save_id) - return ETM_CLASS (etree)->has_save_id (etree); - else - return FALSE; -} - -/** - * e_tree_model_get_save_id - * @etree: The ETreeModel. - * @node: The ETreePath. - * - * XXX docs here. - * - * return values: The save id for this path. - */ -gchar * -e_tree_model_get_save_id (ETreeModel *etree, - ETreePath node) -{ - g_return_val_if_fail (E_IS_TREE_MODEL (etree), NULL); - - if (ETM_CLASS (etree)->get_save_id) - return ETM_CLASS (etree)->get_save_id (etree, node); - else - return NULL; -} - -/** - * e_tree_model_has_get_node_by_id - * @etree: The ETreeModel. - * - * XXX docs here. - * - * return values: Whether this tree can quickly get a node from its save id. - */ -gboolean -e_tree_model_has_get_node_by_id (ETreeModel *etree) -{ - g_return_val_if_fail (E_IS_TREE_MODEL (etree), FALSE); - - if (ETM_CLASS (etree)->has_get_node_by_id) - return ETM_CLASS (etree)->has_get_node_by_id (etree); - else - return FALSE; -} - -/** - * e_tree_model_get_node_by_id - * @etree: The ETreeModel. - * @node: The ETreePath. - * - * get_node_by_id(get_save_id(node)) should be the original node. - * Likewise if get_node_by_id is not NULL, then - * get_save_id(get_node_by_id(string)) should be a copy of the - * original string. - * - * return values: The path for this save id. - */ -ETreePath -e_tree_model_get_node_by_id (ETreeModel *etree, - const gchar *save_id) -{ - g_return_val_if_fail (E_IS_TREE_MODEL (etree), NULL); - - if (ETM_CLASS (etree)->get_node_by_id) - return ETM_CLASS (etree)->get_node_by_id (etree, save_id); - else - return NULL; -} - -/** - * e_tree_model_has_change_pending - * @etree: The ETreeModel. - * - * XXX docs here. - * - * return values: Whether this tree has valid save id data. - */ -gboolean -e_tree_model_has_change_pending (ETreeModel *etree) -{ - g_return_val_if_fail (E_IS_TREE_MODEL (etree), FALSE); - - if (ETM_CLASS (etree)->has_change_pending) - return ETM_CLASS (etree)->has_change_pending (etree); - else - return FALSE; -} - -/** - * e_tree_model_sort_value_at: - * @etree: The ETreeModel. - * @node: The ETreePath to the node we're getting the data from. - * @col: the column to retrieve data from - * - * Return value: This function returns the value that is stored by the - * @etree in column @col and node @node. 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 sort renderer if it wants - * to proxy the data of cell value_at at a better sorting order. - * - * The data returned must be valid until the model sends a signal that - * affect that piece of data. node_changed and node_deleted affect - * all data in tha t node and all nodes under that node. - * node_data_changed affects the data in that node. node_col_changed - * affects the data in that node for that column. node_inserted, - * node_removed, and no_change don't affect any data in this way. - **/ -gpointer -e_tree_model_sort_value_at (ETreeModel *etree, - ETreePath node, - gint col) -{ - g_return_val_if_fail (E_IS_TREE_MODEL (etree), NULL); - - if (ETM_CLASS (etree)->sort_value_at) - return ETM_CLASS (etree)->sort_value_at (etree, node, col); - else - return NULL; -} - -/** - * e_tree_model_value_at: - * @etree: The ETreeModel. - * @node: The ETreePath to the node we're getting the data from. - * @col: the column to retrieve data from - * - * Return value: This function returns the value that is stored by the - * @etree in column @col and node @node. 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. - * - * The data returned must be valid until the model sends a signal that - * affect that piece of data. node_changed and node_deleted affect - * all data in tha t node and all nodes under that node. - * node_data_changed affects the data in that node. node_col_changed - * affects the data in that node for that column. node_inserted, - * node_removed, and no_change don't affect any data in this way. - **/ -gpointer -e_tree_model_value_at (ETreeModel *etree, - ETreePath node, - gint col) -{ - g_return_val_if_fail (E_IS_TREE_MODEL (etree), NULL); - - if (ETM_CLASS (etree)->value_at) - return ETM_CLASS (etree)->value_at (etree, node, col); - else - return NULL; -} - -void -e_tree_model_set_value_at (ETreeModel *etree, - ETreePath node, - gint col, - gconstpointer val) -{ - g_return_if_fail (E_IS_TREE_MODEL (etree)); - - if (ETM_CLASS (etree)->set_value_at) - ETM_CLASS (etree)->set_value_at (etree, node, col, val); -} - -/** - * e_tree_model_node_is_editable: - * @etree: - * @path: - * - * - * - * Return value: - **/ -gboolean -e_tree_model_node_is_editable (ETreeModel *etree, - ETreePath node, - gint col) -{ - g_return_val_if_fail (etree != NULL, FALSE); - - if (ETM_CLASS (etree)->is_editable) - return ETM_CLASS (etree)->is_editable (etree, node, col); - else - return FALSE; -} - -/** - * e_tree_model_duplicate_value: - * @etree: - * @path: - * - * - * - * Return value: - **/ -gpointer -e_tree_model_duplicate_value (ETreeModel *etree, - gint col, - gconstpointer value) -{ - g_return_val_if_fail (etree != NULL, NULL); - - if (ETM_CLASS (etree)->duplicate_value) - return ETM_CLASS (etree)->duplicate_value (etree, col, value); - else - return NULL; -} - -/** - * e_tree_model_free_value: - * @etree: - * @path: - * - * - * - * Return value: - **/ -void -e_tree_model_free_value (ETreeModel *etree, - gint col, - gpointer value) -{ - g_return_if_fail (etree != NULL); - - if (ETM_CLASS (etree)->free_value) - ETM_CLASS (etree)->free_value (etree, col, value); -} - -/** - * e_tree_model_initialize_value: - * @etree: - * @path: - * - * - * - * Return value: - **/ -gpointer -e_tree_model_initialize_value (ETreeModel *etree, - gint col) -{ - g_return_val_if_fail (etree != NULL, NULL); - - if (ETM_CLASS (etree)->initialize_value) - return ETM_CLASS (etree)->initialize_value (etree, col); - else - return NULL; -} - -/** - * e_tree_model_value_is_empty: - * @etree: - * @path: - * - * - * - * Return value: - **/ -gboolean -e_tree_model_value_is_empty (ETreeModel *etree, - gint col, - gconstpointer value) -{ - g_return_val_if_fail (etree != NULL, TRUE); - - if (ETM_CLASS (etree)->value_is_empty) - return ETM_CLASS (etree)->value_is_empty (etree, col, value); - else - return TRUE; -} - -/** - * e_tree_model_value_to_string: - * @etree: - * @path: - * - * - * - * Return value: - **/ -gchar * -e_tree_model_value_to_string (ETreeModel *etree, - gint col, - gconstpointer value) -{ - g_return_val_if_fail (etree != NULL, g_strdup ("")); - - if (ETM_CLASS (etree)->value_to_string) - return ETM_CLASS (etree)->value_to_string (etree, col, value); - else - return g_strdup (""); -} - -/** - * 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 (E_IS_TREE_MODEL (model)); - g_return_if_fail (path != NULL); - - child = e_tree_model_node_get_first_child (model, path); - - while (child) { - ETreePath next_child; - - next_child = e_tree_model_node_get_next (model, child); - e_tree_model_node_traverse (model, child, func, data); - if (func (model, child, data)) - return; - - child = next_child; - } -} - -/** - * e_tree_model_node_traverse_preorder: - * @model: - * @path: - * @func: - * @data: - * - * - **/ -void -e_tree_model_node_traverse_preorder (ETreeModel *model, - ETreePath path, - ETreePathFunc func, - gpointer data) -{ - ETreePath child; - - g_return_if_fail (E_IS_TREE_MODEL (model)); - g_return_if_fail (path != NULL); - - child = e_tree_model_node_get_first_child (model, path); - - while (child) { - ETreePath next_child; - - if (func (model, child, data)) - return; - - next_child = e_tree_model_node_get_next (model, child); - e_tree_model_node_traverse_preorder (model, child, func, data); - - child = next_child; - } -} - -/** - * e_tree_model_node_traverse_preorder: - * @model: - * @path: - * @func: - * @data: - * - * - **/ -static ETreePath -e_tree_model_node_real_traverse (ETreeModel *model, - ETreePath path, - ETreePath end_path, - gboolean forward_direction, - ETreePathFunc func, - gpointer data) -{ - ETreePath child; - - g_return_val_if_fail (E_IS_TREE_MODEL (model), NULL); - g_return_val_if_fail (path != NULL, NULL); - - if (forward_direction) - child = e_tree_model_node_get_first_child (model, path); - else - child = e_tree_model_node_get_last_child (model, path); - - while (child) { - ETreePath result; - - if (forward_direction && (child == end_path || func (model, child, data))) - return child; - - if ((result = e_tree_model_node_real_traverse ( - model, child, end_path, - forward_direction, func, data))) - return result; - - if (!forward_direction && (child == end_path || func (model, child, data))) - return child; - - if (forward_direction) - child = e_tree_model_node_get_next (model, child); - else - child = e_tree_model_node_get_prev (model, child); - } - return NULL; -} - -/** - * e_tree_model_node_traverse_preorder: - * @model: - * @path: - * @func: - * @data: - * - * - **/ -ETreePath -e_tree_model_node_find (ETreeModel *model, - ETreePath path, - ETreePath end_path, - gboolean forward_direction, - ETreePathFunc func, - gpointer data) -{ - ETreePath result; - ETreePath next; - - g_return_val_if_fail (E_IS_TREE_MODEL (model), NULL); - - /* Just search the whole tree in this case. */ - if (path == NULL) { - ETreePath root; - root = e_tree_model_get_root (model); - - if (forward_direction && (end_path == root || func (model, root, data))) - return root; - - result = e_tree_model_node_real_traverse ( - model, root, end_path, forward_direction, func, data); - if (result) - return result; - - if (!forward_direction && (end_path == root || func (model, root, data))) - return root; - - return NULL; - } - - while (1) { - - if (forward_direction) { - if ((result = e_tree_model_node_real_traverse ( - model, path, end_path, - forward_direction, func, data))) - return result; - next = e_tree_model_node_get_next (model, path); - } else { - next = e_tree_model_node_get_prev (model, path); - if (next && (result = e_tree_model_node_real_traverse ( - model, next, end_path, - forward_direction, func, data))) - return result; - } - - while (next == NULL) { - path = e_tree_model_node_get_parent (model, path); - - if (path == NULL) - return NULL; - - if (forward_direction) - next = e_tree_model_node_get_next (model, path); - else - next = path; - } - - if (end_path == next || func (model, next, data)) - return next; - - path = next; - } -} - diff --git a/widgets/table/e-tree-model.h b/widgets/table/e-tree-model.h deleted file mode 100644 index f857e52a49..0000000000 --- a/widgets/table/e-tree-model.h +++ /dev/null @@ -1,294 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Chris Toshok <toshok@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TREE_MODEL_H_ -#define _E_TREE_MODEL_H_ - -#include <gdk-pixbuf/gdk-pixbuf.h> - -/* Standard GObject macros */ -#define E_TYPE_TREE_MODEL \ - (e_tree_model_get_type ()) -#define E_TREE_MODEL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TREE_MODEL, ETreeModel)) -#define E_TREE_MODEL_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TREE_MODEL, ETreeModelClass)) -#define E_IS_TREE_MODEL(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TREE_MODEL)) -#define E_IS_TREE_MODEL_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TREE_MODEL)) -#define E_TREE_MODEL_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TREE_MODEL, ETreeModelClass)) - -G_BEGIN_DECLS - -typedef gpointer ETreePath; - -typedef struct _ETreeModel ETreeModel; -typedef struct _ETreeModelClass ETreeModelClass; - -typedef gint (*ETreePathCompareFunc) (ETreeModel *model, - ETreePath path1, - ETreePath path2); -typedef gboolean (*ETreePathFunc) (ETreeModel *model, - ETreePath path, - gpointer data); - -struct _ETreeModel { - GObject parent; -}; - -struct _ETreeModelClass { - GObjectClass 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); - - gboolean (*is_root) (ETreeModel *etm, - ETreePath node); - gboolean (*is_expandable) (ETreeModel *etm, - ETreePath node); - guint (*get_children) (ETreeModel *etm, - ETreePath node, - ETreePath **paths); - guint (*depth) (ETreeModel *etm, - ETreePath node); - - GdkPixbuf * (*icon_at) (ETreeModel *etm, - ETreePath node); - - gboolean (*get_expanded_default) (ETreeModel *etm); - gint (*column_count) (ETreeModel *etm); - - gboolean (*has_save_id) (ETreeModel *etm); - gchar * (*get_save_id) (ETreeModel *etm, - ETreePath node); - - gboolean (*has_get_node_by_id) (ETreeModel *etm); - ETreePath (*get_node_by_id) (ETreeModel *etm, - const gchar *save_id); - - gboolean (*has_change_pending) (ETreeModel *etm); - - /* - * ETable analogs - */ - gpointer (*sort_value_at) (ETreeModel *etm, - ETreePath node, - gint col); - gpointer (*value_at) (ETreeModel *etm, - ETreePath node, - gint col); - void (*set_value_at) (ETreeModel *etm, - ETreePath node, - gint col, - gconstpointer val); - gboolean (*is_editable) (ETreeModel *etm, - ETreePath node, - gint col); - - gpointer (*duplicate_value) (ETreeModel *etm, - gint col, - gconstpointer value); - void (*free_value) (ETreeModel *etm, - gint col, - gpointer value); - gpointer (*initialize_value) (ETreeModel *etm, - gint col); - gboolean (*value_is_empty) (ETreeModel *etm, - gint col, - gconstpointer value); - gchar * (*value_to_string) (ETreeModel *etm, - gint col, - gconstpointer value); - - /* - * Signals - */ - - /* During node_remove, the ETreePath of the child is removed - * from the tree but is still a valid ETreePath. At - * node_deleted, the ETreePath is no longer valid. - */ - - void (*pre_change) (ETreeModel *etm); - void (*no_change) (ETreeModel *etm); - void (*node_changed) (ETreeModel *etm, - ETreePath node); - void (*node_data_changed) (ETreeModel *etm, - ETreePath node); - void (*node_col_changed) (ETreeModel *etm, - ETreePath node, - gint col); - void (*node_inserted) (ETreeModel *etm, - ETreePath parent, - ETreePath inserted_node); - void (*node_removed) (ETreeModel *etm, - ETreePath parent, - ETreePath removed_node, - gint old_position); - void (*node_deleted) (ETreeModel *etm, - ETreePath deleted_node); - void (*rebuilt) (ETreeModel *etm); - - /* This signal requests that any viewers of the tree that - * collapse and expand nodes collapse this node. - */ - void (*node_request_collapse) - (ETreeModel *etm, - ETreePath node); -}; - -GType e_tree_model_get_type (void) G_GNUC_CONST; -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 accessors */ -gboolean e_tree_model_node_is_root (ETreeModel *etree, - ETreePath path); -gboolean e_tree_model_node_is_expandable (ETreeModel *etree, - ETreePath path); -guint e_tree_model_node_get_children (ETreeModel *etree, - ETreePath path, - ETreePath **paths); -guint e_tree_model_node_depth (ETreeModel *etree, - ETreePath path); -GdkPixbuf * e_tree_model_icon_at (ETreeModel *etree, - ETreePath path); -gboolean e_tree_model_get_expanded_default - (ETreeModel *model); -gint e_tree_model_column_count (ETreeModel *model); -gboolean e_tree_model_has_save_id (ETreeModel *model); -gchar * e_tree_model_get_save_id (ETreeModel *model, - ETreePath node); -gboolean e_tree_model_has_get_node_by_id (ETreeModel *model); -ETreePath e_tree_model_get_node_by_id (ETreeModel *model, - const gchar *save_id); -gboolean e_tree_model_has_change_pending (ETreeModel *model); -void *e_tree_model_sort_value_at (ETreeModel *etree, - ETreePath node, - gint col); -void *e_tree_model_value_at (ETreeModel *etree, - ETreePath node, - gint col); -void e_tree_model_set_value_at (ETreeModel *etree, - ETreePath node, - gint col, - gconstpointer val); -gboolean e_tree_model_node_is_editable (ETreeModel *etree, - ETreePath node, - gint col); -void *e_tree_model_duplicate_value (ETreeModel *etree, - gint col, - gconstpointer value); -void e_tree_model_free_value (ETreeModel *etree, - gint col, - gpointer value); -void *e_tree_model_initialize_value (ETreeModel *etree, - gint col); -gboolean e_tree_model_value_is_empty (ETreeModel *etree, - gint col, - gconstpointer value); -gchar * e_tree_model_value_to_string (ETreeModel *etree, - gint col, - gconstpointer value); - -/* 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_node_traverse_preorder - (ETreeModel *model, - ETreePath path, - ETreePathFunc func, - gpointer data); -ETreePath e_tree_model_node_find (ETreeModel *model, - ETreePath path, - ETreePath end_path, - gboolean forward_direction, - ETreePathFunc func, - gpointer data); - -/* -** Routines for emitting signals on the ETreeModel -*/ -void e_tree_model_pre_change (ETreeModel *tree_model); -void e_tree_model_no_change (ETreeModel *tree_model); -void e_tree_model_rebuilt (ETreeModel *tree_model); -void e_tree_model_node_changed (ETreeModel *tree_model, - ETreePath node); -void e_tree_model_node_data_changed (ETreeModel *tree_model, - ETreePath node); -void e_tree_model_node_col_changed (ETreeModel *tree_model, - ETreePath node, - gint col); -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, - gint old_position); -void e_tree_model_node_deleted (ETreeModel *tree_model, - ETreePath deleted_node); -void e_tree_model_node_request_collapse - (ETreeModel *tree_model, - ETreePath deleted_node); - -G_END_DECLS - -#endif /* _E_TREE_MODEL_H */ diff --git a/widgets/table/e-tree-selection-model.c b/widgets/table/e-tree-selection-model.c deleted file mode 100644 index 33e4ab0780..0000000000 --- a/widgets/table/e-tree-selection-model.c +++ /dev/null @@ -1,939 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Mike Kestner <mkestner@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "table/e-tree-table-adapter.h" -#include <glib/gi18n.h> -#include "e-util/e-util.h" - -#include "e-tree-selection-model.h" - -#define E_TREE_SELECTION_MODEL_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), E_TYPE_TREE_SELECTION_MODEL, ETreeSelectionModelPrivate)) - -G_DEFINE_TYPE ( - ETreeSelectionModel, e_tree_selection_model, E_TYPE_SELECTION_MODEL) - -enum { - PROP_0, - PROP_CURSOR_ROW, - PROP_CURSOR_COL, - PROP_MODEL, - PROP_ETTA -}; - -struct _ETreeSelectionModelPrivate { - ETreeTableAdapter *etta; - ETreeModel *model; - - GHashTable *paths; - ETreePath cursor_path; - ETreePath start_path; - gint cursor_col; - gchar *cursor_save_id; - - gint tree_model_pre_change_id; - gint tree_model_no_change_id; - gint tree_model_node_changed_id; - gint tree_model_node_data_changed_id; - gint tree_model_node_col_changed_id; - gint tree_model_node_inserted_id; - gint tree_model_node_removed_id; - gint tree_model_node_deleted_id; -}; - -static gint -get_cursor_row (ETreeSelectionModel *etsm) -{ - if (etsm->priv->cursor_path) - return e_tree_table_adapter_row_of_node ( - etsm->priv->etta, etsm->priv->cursor_path); - - return -1; -} - -static void -clear_selection (ETreeSelectionModel *etsm) -{ - g_hash_table_destroy (etsm->priv->paths); - etsm->priv->paths = g_hash_table_new (NULL, NULL); -} - -static void -change_one_path (ETreeSelectionModel *etsm, - ETreePath path, - gboolean grow) -{ - if (!path) - return; - - if (grow) - g_hash_table_insert (etsm->priv->paths, path, path); - else if (g_hash_table_lookup (etsm->priv->paths, path)) - g_hash_table_remove (etsm->priv->paths, path); -} - -static void -select_single_path (ETreeSelectionModel *etsm, - ETreePath path) -{ - clear_selection (etsm); - change_one_path (etsm, path, TRUE); - etsm->priv->cursor_path = path; - etsm->priv->start_path = NULL; -} - -static void -select_range (ETreeSelectionModel *etsm, - gint start, - gint end) -{ - gint i; - - if (start > end) { - i = start; - start = end; - end = i; - } - - for (i = start; i <= end; i++) { - ETreePath path = e_tree_table_adapter_node_at_row (etsm->priv->etta, i); - if (path) - g_hash_table_insert (etsm->priv->paths, path, path); - } -} - -static void -free_id (ETreeSelectionModel *etsm) -{ - g_free (etsm->priv->cursor_save_id); - etsm->priv->cursor_save_id = NULL; -} - -static void -restore_cursor (ETreeSelectionModel *etsm, - ETreeModel *etm) -{ - clear_selection (etsm); - etsm->priv->cursor_path = NULL; - - if (etsm->priv->cursor_save_id) { - etsm->priv->cursor_path = e_tree_model_get_node_by_id ( - etm, etsm->priv->cursor_save_id); - if (etsm->priv->cursor_path != NULL && etsm->priv->cursor_col == -1) - etsm->priv->cursor_col = 0; - - select_single_path (etsm, etsm->priv->cursor_path); - } - - e_selection_model_selection_changed (E_SELECTION_MODEL (etsm)); - - if (etsm->priv->cursor_path) { - gint cursor_row = get_cursor_row (etsm); - e_selection_model_cursor_changed ( - E_SELECTION_MODEL (etsm), - cursor_row, etsm->priv->cursor_col); - } else { - e_selection_model_cursor_changed ( - E_SELECTION_MODEL (etsm), -1, -1); - e_selection_model_cursor_activated ( - E_SELECTION_MODEL (etsm), -1, -1); - - } - - free_id (etsm); -} - -static void -etsm_pre_change (ETreeModel *etm, - ETreeSelectionModel *etsm) -{ - g_free (etsm->priv->cursor_save_id); - etsm->priv->cursor_save_id = NULL; - - if (e_tree_model_has_get_node_by_id (etm) && - e_tree_model_has_save_id (etm) && - etsm->priv->cursor_path) { - etsm->priv->cursor_save_id = e_tree_model_get_save_id ( - etm, etsm->priv->cursor_path); - } -} - -static void -etsm_no_change (ETreeModel *etm, - ETreeSelectionModel *etsm) -{ - free_id (etsm); -} - -static void -etsm_node_changed (ETreeModel *etm, - ETreePath node, - ETreeSelectionModel *etsm) -{ - restore_cursor (etsm, etm); -} - -static void -etsm_node_data_changed (ETreeModel *etm, - ETreePath node, - ETreeSelectionModel *etsm) -{ - free_id (etsm); -} - -static void -etsm_node_col_changed (ETreeModel *etm, - ETreePath node, - gint col, - ETreeSelectionModel *etsm) -{ - free_id (etsm); -} - -static void -etsm_node_inserted (ETreeModel *etm, - ETreePath parent, - ETreePath child, - ETreeSelectionModel *etsm) -{ - restore_cursor (etsm, etm); -} - -static void -etsm_node_removed (ETreeModel *etm, - ETreePath parent, - ETreePath child, - gint old_position, - ETreeSelectionModel *etsm) -{ - restore_cursor (etsm, etm); -} - -static void -etsm_node_deleted (ETreeModel *etm, - ETreePath child, - ETreeSelectionModel *etsm) -{ - restore_cursor (etsm, etm); -} - -static void -add_model (ETreeSelectionModel *etsm, - ETreeModel *model) -{ - ETreeSelectionModelPrivate *priv = etsm->priv; - - priv->model = model; - - if (!priv->model) - return; - - g_object_ref (priv->model); - - priv->tree_model_pre_change_id = g_signal_connect_after ( - priv->model, "pre_change", - G_CALLBACK (etsm_pre_change), etsm); - - priv->tree_model_no_change_id = g_signal_connect_after ( - priv->model, "no_change", - G_CALLBACK (etsm_no_change), etsm); - - priv->tree_model_node_changed_id = g_signal_connect_after ( - priv->model, "node_changed", - G_CALLBACK (etsm_node_changed), etsm); - - priv->tree_model_node_data_changed_id = g_signal_connect_after ( - priv->model, "node_data_changed", - G_CALLBACK (etsm_node_data_changed), etsm); - - priv->tree_model_node_col_changed_id = g_signal_connect_after ( - priv->model, "node_col_changed", - G_CALLBACK (etsm_node_col_changed), etsm); - - priv->tree_model_node_inserted_id = g_signal_connect_after ( - priv->model, "node_inserted", - G_CALLBACK (etsm_node_inserted), etsm); - - priv->tree_model_node_removed_id = g_signal_connect_after ( - priv->model, "node_removed", - G_CALLBACK (etsm_node_removed), etsm); - - priv->tree_model_node_deleted_id = g_signal_connect_after ( - priv->model, "node_deleted", - G_CALLBACK (etsm_node_deleted), etsm); -} - -static void -drop_model (ETreeSelectionModel *etsm) -{ - ETreeSelectionModelPrivate *priv = etsm->priv; - - if (!priv->model) - return; - - g_signal_handler_disconnect ( - priv->model, priv->tree_model_pre_change_id); - g_signal_handler_disconnect ( - priv->model, priv->tree_model_no_change_id); - g_signal_handler_disconnect ( - priv->model, priv->tree_model_node_changed_id); - g_signal_handler_disconnect ( - priv->model, priv->tree_model_node_data_changed_id); - g_signal_handler_disconnect ( - priv->model, priv->tree_model_node_col_changed_id); - g_signal_handler_disconnect ( - priv->model, priv->tree_model_node_inserted_id); - g_signal_handler_disconnect ( - priv->model, priv->tree_model_node_removed_id); - g_signal_handler_disconnect ( - priv->model, priv->tree_model_node_deleted_id); - - g_object_unref (priv->model); - priv->model = NULL; - - priv->tree_model_pre_change_id = 0; - priv->tree_model_no_change_id = 0; - priv->tree_model_node_changed_id = 0; - priv->tree_model_node_data_changed_id = 0; - priv->tree_model_node_col_changed_id = 0; - priv->tree_model_node_inserted_id = 0; - priv->tree_model_node_removed_id = 0; - priv->tree_model_node_deleted_id = 0; -} - -static void -etsm_dispose (GObject *object) -{ - ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (object); - - drop_model (etsm); - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (e_tree_selection_model_parent_class)->dispose (object); -} - -static void -etsm_finalize (GObject *object) -{ - ETreeSelectionModelPrivate *priv; - - priv = E_TREE_SELECTION_MODEL_GET_PRIVATE (object); - - clear_selection (E_TREE_SELECTION_MODEL (object)); - g_hash_table_destroy (priv->paths); - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (e_tree_selection_model_parent_class)->finalize (object); -} - -static void -etsm_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (object); - - switch (property_id) { - case PROP_CURSOR_ROW: - g_value_set_int (value, get_cursor_row (etsm)); - break; - - case PROP_CURSOR_COL: - g_value_set_int (value, etsm->priv->cursor_col); - break; - - case PROP_MODEL: - g_value_set_object (value, etsm->priv->model); - break; - - case PROP_ETTA: - g_value_set_object (value, etsm->priv->etta); - break; - } -} - -static void -etsm_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ESelectionModel *esm = E_SELECTION_MODEL (object); - ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (object); - - switch (property_id) { - case PROP_CURSOR_ROW: - e_selection_model_do_something ( - esm, g_value_get_int (value), - etsm->priv->cursor_col, 0); - break; - - case PROP_CURSOR_COL: - e_selection_model_do_something ( - esm, get_cursor_row (etsm), - g_value_get_int (value), 0); - break; - - case PROP_MODEL: - drop_model (etsm); - add_model (etsm, E_TREE_MODEL (g_value_get_object (value))); - break; - - case PROP_ETTA: - etsm->priv->etta = - E_TREE_TABLE_ADAPTER (g_value_get_object (value)); - break; - } -} - -static gboolean -etsm_is_path_selected (ETreeSelectionModel *etsm, - ETreePath path) -{ - if (path && g_hash_table_lookup (etsm->priv->paths, path)) - return TRUE; - - return FALSE; -} - -/** - * e_selection_model_is_row_selected - * @selection: #ESelectionModel to check - * @n: The row to check - * - * This routine calculates whether the given row is selected. - * - * Returns: %TRUE if the given row is selected - */ -static gboolean -etsm_is_row_selected (ESelectionModel *selection, - gint row) -{ - ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection); - ETreePath path; - - g_return_val_if_fail ( - row < e_table_model_row_count ( - E_TABLE_MODEL (etsm->priv->etta)), FALSE); - g_return_val_if_fail (row >= 0, FALSE); - g_return_val_if_fail (etsm != NULL, FALSE); - - path = e_tree_table_adapter_node_at_row (etsm->priv->etta, row); - return etsm_is_path_selected (etsm, path); -} - -typedef struct { - ETreeSelectionModel *etsm; - EForeachFunc callback; - gpointer closure; -} ModelAndCallback; - -static void -etsm_row_foreach_cb (gpointer key, - gpointer value, - gpointer user_data) -{ - ETreePath path = key; - ModelAndCallback *mac = user_data; - gint row = e_tree_table_adapter_row_of_node ( - mac->etsm->priv->etta, path); - if (row >= 0) - mac->callback (row, mac->closure); -} - -/** - * e_selection_model_foreach - * @selection: #ESelectionModel 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. - */ -static void -etsm_foreach (ESelectionModel *selection, - EForeachFunc callback, - gpointer closure) -{ - ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection); - ModelAndCallback mac; - - mac.etsm = etsm; - mac.callback = callback; - mac.closure = closure; - - g_hash_table_foreach (etsm->priv->paths, etsm_row_foreach_cb, &mac); -} - -/** - * e_selection_model_clear - * @selection: #ESelectionModel to clear - * - * This routine clears the selection to no rows selected. - */ -static void -etsm_clear (ESelectionModel *selection) -{ - ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection); - - clear_selection (etsm); - - etsm->priv->cursor_path = NULL; - e_selection_model_selection_changed (E_SELECTION_MODEL (etsm)); - e_selection_model_cursor_changed (E_SELECTION_MODEL (etsm), -1, -1); -} - -/** - * e_selection_model_selected_count - * @selection: #ESelectionModel to count - * - * This routine calculates the number of rows selected. - * - * Returns: The number of rows selected in the given model. - */ -static gint -etsm_selected_count (ESelectionModel *selection) -{ - ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection); - - return g_hash_table_size (etsm->priv->paths); -} - -static gint -etsm_row_count (ESelectionModel *selection) -{ - ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection); - return e_table_model_row_count (E_TABLE_MODEL (etsm->priv->etta)); -} - -/** - * e_selection_model_select_all - * @selection: #ESelectionModel to select all - * - * This routine selects all the rows in the given - * #ESelectionModel. - */ -static void -etsm_select_all (ESelectionModel *selection) -{ - ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection); - ETreePath root; - - root = e_tree_model_get_root (etsm->priv->model); - if (root == NULL) - return; - - clear_selection (etsm); - select_range (etsm, 0, etsm_row_count (selection) - 1); - - if (etsm->priv->cursor_path == NULL) - etsm->priv->cursor_path = e_tree_table_adapter_node_at_row ( - etsm->priv->etta, 0); - - e_selection_model_selection_changed (E_SELECTION_MODEL (etsm)); - - e_selection_model_cursor_changed ( - E_SELECTION_MODEL (etsm), - get_cursor_row (etsm), etsm->priv->cursor_col); -} - -/** - * e_selection_model_invert_selection - * @selection: #ESelectionModel to invert - * - * This routine inverts all the rows in the given - * #ESelectionModel. - */ -static void -etsm_invert_selection (ESelectionModel *selection) -{ - ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection); - gint count = etsm_row_count (selection); - gint i; - - for (i = 0; i < count; i++) { - ETreePath path; - - path = e_tree_table_adapter_node_at_row (etsm->priv->etta, i); - if (!path) - continue; - if (g_hash_table_lookup (etsm->priv->paths, path)) - g_hash_table_remove (etsm->priv->paths, path); - else - g_hash_table_insert (etsm->priv->paths, path, path); - } - - etsm->priv->cursor_col = -1; - etsm->priv->cursor_path = NULL; - etsm->priv->start_path = NULL; - e_selection_model_selection_changed (E_SELECTION_MODEL (etsm)); - e_selection_model_cursor_changed (E_SELECTION_MODEL (etsm), -1, -1); -} - -static void -etsm_change_one_row (ESelectionModel *selection, - gint row, - gboolean grow) -{ - ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection); - ETreePath path; - - g_return_if_fail ( - row < e_table_model_row_count ( - E_TABLE_MODEL (etsm->priv->etta))); - g_return_if_fail (row >= 0); - g_return_if_fail (selection != NULL); - - path = e_tree_table_adapter_node_at_row (etsm->priv->etta, row); - - if (!path) - return; - - change_one_path (etsm, path, grow); -} - -static void -etsm_change_cursor (ESelectionModel *selection, - gint row, - gint col) -{ - ETreeSelectionModel *etsm; - - g_return_if_fail (selection != NULL); - g_return_if_fail (E_IS_SELECTION_MODEL (selection)); - - etsm = E_TREE_SELECTION_MODEL (selection); - - if (row == -1) { - etsm->priv->cursor_path = NULL; - } else { - etsm->priv->cursor_path = - e_tree_table_adapter_node_at_row ( - etsm->priv->etta, row); - } - etsm->priv->cursor_col = col; -} - -static gint -etsm_cursor_row (ESelectionModel *selection) -{ - return get_cursor_row (E_TREE_SELECTION_MODEL (selection)); -} - -static gint -etsm_cursor_col (ESelectionModel *selection) -{ - ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection); - return etsm->priv->cursor_col; -} - -static void -etsm_get_rows (gint row, - gpointer d) -{ - gint **rowp = d; - - **rowp = row; - (*rowp)++; -} - -static void -etsm_select_single_row (ESelectionModel *selection, - gint row) -{ - ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection); - ETreePath path; - gint rows[5], *rowp = NULL, size; - - path = e_tree_table_adapter_node_at_row (etsm->priv->etta, row); - g_return_if_fail (path != NULL); - - /* we really only care about the size=1 case (cursor changed), - * but this doesn't cost much */ - size = g_hash_table_size (etsm->priv->paths); - if (size > 0 && size <= 5) { - rowp = rows; - etsm_foreach (selection, etsm_get_rows, &rowp); - } - - select_single_path (etsm, path); - - if (size > 5) { - e_selection_model_selection_changed (E_SELECTION_MODEL (etsm)); - } else { - if (rowp) { - gint *p = rows; - - while (p < rowp) - e_selection_model_selection_row_changed ( - (ESelectionModel *) etsm, *p++); - } - e_selection_model_selection_row_changed ( - (ESelectionModel *) etsm, row); - } -} - -static void -etsm_toggle_single_row (ESelectionModel *selection, - gint row) -{ - ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection); - ETreePath path; - - path = e_tree_table_adapter_node_at_row (etsm->priv->etta, row); - g_return_if_fail (path); - - if (g_hash_table_lookup (etsm->priv->paths, path)) - g_hash_table_remove (etsm->priv->paths, path); - else - g_hash_table_insert (etsm->priv->paths, path, path); - - etsm->priv->start_path = NULL; - - e_selection_model_selection_row_changed ((ESelectionModel *) etsm, row); -} - -static void -etsm_real_move_selection_end (ETreeSelectionModel *etsm, - gint row) -{ - ETreePath end_path; - gint start; - - end_path = e_tree_table_adapter_node_at_row (etsm->priv->etta, row); - g_return_if_fail (end_path); - - start = e_tree_table_adapter_row_of_node ( - etsm->priv->etta, etsm->priv->start_path); - clear_selection (etsm); - select_range (etsm, start, row); -} - -static void -etsm_move_selection_end (ESelectionModel *selection, - gint row) -{ - ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection); - - g_return_if_fail (etsm->priv->cursor_path); - - etsm_real_move_selection_end (etsm, row); - e_selection_model_selection_changed (E_SELECTION_MODEL (selection)); -} - -static void -etsm_set_selection_end (ESelectionModel *selection, - gint row) -{ - ETreeSelectionModel *etsm = E_TREE_SELECTION_MODEL (selection); - - g_return_if_fail (etsm->priv->cursor_path); - - if (!etsm->priv->start_path) - etsm->priv->start_path = etsm->priv->cursor_path; - etsm_real_move_selection_end (etsm, row); - e_selection_model_selection_changed (E_SELECTION_MODEL (etsm)); -} - -struct foreach_path_t { - ETreeForeachFunc callback; - gpointer closure; -}; - -static void -foreach_path (gpointer key, - gpointer value, - gpointer data) -{ - ETreePath path = key; - struct foreach_path_t *c = data; - c->callback (path, c->closure); -} - -void -e_tree_selection_model_foreach (ETreeSelectionModel *etsm, - ETreeForeachFunc callback, - gpointer closure) -{ - if (etsm->priv->paths) { - struct foreach_path_t c; - c.callback = callback; - c.closure = closure; - g_hash_table_foreach (etsm->priv->paths, foreach_path, &c); - return; - } -} - -void -e_tree_selection_model_select_single_path (ETreeSelectionModel *etsm, - ETreePath path) -{ - select_single_path (etsm, path); - - e_selection_model_selection_changed (E_SELECTION_MODEL (etsm)); -} - -void -e_tree_selection_model_select_paths (ETreeSelectionModel *etsm, - GPtrArray *paths) -{ - ETreePath path; - gint i; - - for (i = 0; i < paths->len; i++) { - path = paths->pdata[i]; - change_one_path (etsm, path, TRUE); - } - - e_selection_model_selection_changed (E_SELECTION_MODEL (etsm)); -} - -void -e_tree_selection_model_add_to_selection (ETreeSelectionModel *etsm, - ETreePath path) -{ - change_one_path (etsm, path, TRUE); - - e_selection_model_selection_changed (E_SELECTION_MODEL (etsm)); -} - -void -e_tree_selection_model_change_cursor (ETreeSelectionModel *etsm, - ETreePath path) -{ - gint row; - - etsm->priv->cursor_path = path; - - row = get_cursor_row (etsm); - - E_SELECTION_MODEL (etsm)->old_selection = -1; - - e_selection_model_cursor_changed ( - E_SELECTION_MODEL (etsm), row, etsm->priv->cursor_col); - e_selection_model_cursor_activated ( - E_SELECTION_MODEL (etsm), row, etsm->priv->cursor_col); -} - -ETreePath -e_tree_selection_model_get_cursor (ETreeSelectionModel *etsm) -{ - return etsm->priv->cursor_path; -} - -static void -e_tree_selection_model_init (ETreeSelectionModel *etsm) -{ - etsm->priv = E_TREE_SELECTION_MODEL_GET_PRIVATE (etsm); - - etsm->priv->paths = g_hash_table_new (NULL, NULL); - etsm->priv->cursor_col = -1; -} - -static void -e_tree_selection_model_class_init (ETreeSelectionModelClass *class) -{ - GObjectClass *object_class; - ESelectionModelClass *esm_class; - - g_type_class_add_private (class, sizeof (ETreeSelectionModelPrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->dispose = etsm_dispose; - object_class->finalize = etsm_finalize; - object_class->get_property = etsm_get_property; - object_class->set_property = etsm_set_property; - - esm_class = E_SELECTION_MODEL_CLASS (class); - esm_class->is_row_selected = etsm_is_row_selected; - esm_class->foreach = etsm_foreach; - esm_class->clear = etsm_clear; - esm_class->selected_count = etsm_selected_count; - esm_class->select_all = etsm_select_all; - esm_class->invert_selection = etsm_invert_selection; - esm_class->row_count = etsm_row_count; - - esm_class->change_one_row = etsm_change_one_row; - esm_class->change_cursor = etsm_change_cursor; - esm_class->cursor_row = etsm_cursor_row; - esm_class->cursor_col = etsm_cursor_col; - - esm_class->select_single_row = etsm_select_single_row; - esm_class->toggle_single_row = etsm_toggle_single_row; - esm_class->move_selection_end = etsm_move_selection_end; - esm_class->set_selection_end = etsm_set_selection_end; - - g_object_class_install_property ( - object_class, - PROP_CURSOR_ROW, - g_param_spec_int ( - "cursor_row", - "Cursor Row", - NULL, - 0, G_MAXINT, 0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_CURSOR_COL, - g_param_spec_int ( - "cursor_col", - "Cursor Column", - NULL, - 0, G_MAXINT, 0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_MODEL, - g_param_spec_object ( - "model", - "Model", - NULL, - E_TYPE_TREE_MODEL, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_ETTA, - g_param_spec_object ( - "etta", - "ETTA", - NULL, - E_TYPE_TREE_TABLE_ADAPTER, - G_PARAM_READWRITE)); - -} - -ESelectionModel * -e_tree_selection_model_new (void) -{ - return g_object_new (E_TYPE_TREE_SELECTION_MODEL, NULL); -} - diff --git a/widgets/table/e-tree-selection-model.h b/widgets/table/e-tree-selection-model.h deleted file mode 100644 index 1541fcb95a..0000000000 --- a/widgets/table/e-tree-selection-model.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TREE_SELECTION_MODEL_H_ -#define _E_TREE_SELECTION_MODEL_H_ - -#include <e-util/e-sorter.h> -#include <misc/e-selection-model.h> -#include <table/e-tree-model.h> - -/* Standard GObject macros */ -#define E_TYPE_TREE_SELECTION_MODEL \ - (e_tree_selection_model_get_type ()) -#define E_TREE_SELECTION_MODEL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TREE_SELECTION_MODEL, ETreeSelectionModel)) -#define E_TREE_SELECTION_MODEL_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TREE_SELECTION_MODEL, ETreeSelectionModelClass)) -#define E_IS_TREE_SELECTION_MODEL(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TREE_SELECTION_MODEL)) -#define E_IS_TREE_SELECTION_MODEL_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TREE_SELECTION_MODEL)) -#define E_TREE_SELECTION_MODEL_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TREE_SELECTION_MODEL, ETreeSelectionModelClass)) - -G_BEGIN_DECLS - -typedef void (*ETreeForeachFunc) (ETreePath path, - gpointer closure); - -typedef struct _ETreeSelectionModel ETreeSelectionModel; -typedef struct _ETreeSelectionModelClass ETreeSelectionModelClass; -typedef struct _ETreeSelectionModelPrivate ETreeSelectionModelPrivate; - -struct _ETreeSelectionModel { - ESelectionModel parent; - ETreeSelectionModelPrivate *priv; -}; - -struct _ETreeSelectionModelClass { - ESelectionModelClass parent_class; -}; - -GType e_tree_selection_model_get_type (void) G_GNUC_CONST; -ESelectionModel * - e_tree_selection_model_new (void); -void e_tree_selection_model_foreach (ETreeSelectionModel *etsm, - ETreeForeachFunc callback, - gpointer closure); -void e_tree_selection_model_select_single_path - (ETreeSelectionModel *etsm, - ETreePath path); -void e_tree_selection_model_select_paths - (ETreeSelectionModel *etsm, - GPtrArray *paths); - -void e_tree_selection_model_add_to_selection - (ETreeSelectionModel *etsm, - ETreePath path); -void e_tree_selection_model_change_cursor - (ETreeSelectionModel *etsm, - ETreePath path); -ETreePath e_tree_selection_model_get_cursor - (ETreeSelectionModel *etsm); - -G_END_DECLS - -#endif /* _E_TREE_SELECTION_MODEL_H_ */ diff --git a/widgets/table/e-tree-sorted.c b/widgets/table/e-tree-sorted.c deleted file mode 100644 index 0b8f1c4447..0000000000 --- a/widgets/table/e-tree-sorted.c +++ /dev/null @@ -1,1434 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Chris Toshok <toshok@ximian.com> - * - * Adapted from the gtree code and ETableModel. - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -/* FIXME: Overall e-tree-sorted.c needs to be made more efficient. */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdio.h> -#include <errno.h> -#include <stdlib.h> -#include <unistd.h> -#include <fcntl.h> -#include <string.h> - -#include <libxml/parser.h> -#include <libxml/xmlmemory.h> - -#include "e-util/e-util.h" -#include "libevolution-utils/e-xml-utils.h" - -#include "e-table-sorting-utils.h" -#include "e-tree-sorted.h" - -/* maximum insertions between an idle event that we will do without scheduling an idle sort */ -#define ETS_INSERT_MAX (4) - -#define d(x) - -#define E_TREE_SORTED_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), E_TYPE_TREE_SORTED, ETreeSortedPrivate)) - -G_DEFINE_TYPE (ETreeSorted, e_tree_sorted, E_TYPE_TREE_MODEL) - -enum { - NODE_RESORTED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = {0, }; - -typedef struct ETreeSortedPath ETreeSortedPath; - -struct ETreeSortedPath { - ETreePath corresponding; - - /* parent/child/sibling pointers */ - ETreeSortedPath *parent; - gint num_children; - ETreeSortedPath **children; - gint position; - gint orig_position; - - guint needs_resort : 1; - guint child_needs_resort : 1; - guint resort_all_children : 1; - guint needs_regen_to_sort : 1; -}; - -struct _ETreeSortedPrivate { - ETreeModel *source; - ETreeSortedPath *root; - - ETableSortInfo *sort_info; - ETableHeader *full_header; - - ETreeSortedPath *last_access; - - gint tree_model_pre_change_id; - gint tree_model_no_change_id; - gint tree_model_node_changed_id; - gint tree_model_node_data_changed_id; - gint tree_model_node_col_changed_id; - gint tree_model_node_inserted_id; - gint tree_model_node_removed_id; - gint tree_model_node_deleted_id; - gint tree_model_node_request_collapse_id; - - gint sort_info_changed_id; - gint sort_idle_id; - gint insert_idle_id; - gint insert_count; - - guint in_resort_idle : 1; - guint nested_resort_idle : 1; -}; - -enum { - ARG_0, - - ARG_SORT_INFO -}; - -static void ets_sort_info_changed (ETableSortInfo *sort_info, ETreeSorted *ets); -static void resort_node (ETreeSorted *ets, ETreeSortedPath *path, gboolean resort_all_children, gboolean needs_regen, gboolean send_signals); -static void mark_path_needs_resort (ETreeSorted *ets, ETreeSortedPath *path, gboolean needs_rebuild, gboolean resort_all_children); -static void schedule_resort (ETreeSorted *ets, ETreeSortedPath *path, gboolean needs_regen, gboolean resort_all_children); -static void free_path (ETreeSortedPath *path); -static void generate_children (ETreeSorted *ets, ETreeSortedPath *path); -static void regenerate_children (ETreeSorted *ets, ETreeSortedPath *path); - -/* idle callbacks */ - -static gboolean -ets_sort_idle (gpointer user_data) -{ - ETreeSorted *ets = user_data; - if (ets->priv->in_resort_idle) { - ets->priv->nested_resort_idle = TRUE; - return FALSE; - } - ets->priv->in_resort_idle = TRUE; - if (ets->priv->root) { - do { - ets->priv->nested_resort_idle = FALSE; - resort_node (ets, ets->priv->root, FALSE, FALSE, TRUE); - } while (ets->priv->nested_resort_idle); - } - ets->priv->in_resort_idle = FALSE; - ets->priv->sort_idle_id = 0; - return FALSE; -} - -#define ETS_SORT_IDLE_ACTIVATED(ets) ((ets)->priv->sort_idle_id != 0) - -inline static void -ets_stop_sort_idle (ETreeSorted *ets) -{ - if (ets->priv->sort_idle_id) { - g_source_remove (ets->priv->sort_idle_id); - ets->priv->sort_idle_id = 0; - } -} - -static gboolean -ets_insert_idle (ETreeSorted *ets) -{ - ets->priv->insert_count = 0; - ets->priv->insert_idle_id = 0; - return FALSE; -} - -/* Helper functions */ - -#define CHECK_AROUND_LAST_ACCESS - -static inline ETreeSortedPath * -check_last_access (ETreeSorted *ets, - ETreePath corresponding) -{ -#ifdef CHECK_AROUND_LAST_ACCESS - ETreeSortedPath *parent; -#endif - - if (ets->priv->last_access == NULL) - return NULL; - - if (ets->priv->last_access == corresponding) { - d (g_print ("Found last access %p at %p.", ets->priv->last_access, ets->priv->last_access)); - return ets->priv->last_access; - } - -#ifdef CHECK_AROUND_LAST_ACCESS - parent = ets->priv->last_access->parent; - if (parent && parent->children) { - gint position = ets->priv->last_access->position; - gint end = MIN (parent->num_children, position + 10); - gint start = MAX (0, position - 10); - gint initial = MAX (MIN (position, end), start); - gint i; - - for (i = initial; i < end; i++) { - if (parent->children[i] && parent->children[i]->corresponding == corresponding) { - d (g_print ("Found last access %p at %p.", ets->priv->last_access, parent->children[i])); - return parent->children[i]; - } - } - - for (i = initial - 1; i >= start; i--) { - if (parent->children[i] && parent->children[i]->corresponding == corresponding) { - d (g_print ("Found last access %p at %p.", ets->priv->last_access, parent->children[i])); - return parent->children[i]; - } - } - } -#endif - return NULL; -} - -static ETreeSortedPath * -find_path (ETreeSorted *ets, - ETreePath corresponding) -{ - gint depth; - ETreePath *sequence; - gint i; - ETreeSortedPath *path; - ETreeSortedPath *check_last; - - if (corresponding == NULL) - return NULL; - - check_last = check_last_access (ets, corresponding); - if (check_last) { - d (g_print (" (find_path)\n")); - return check_last; - } - - depth = e_tree_model_node_depth (ets->priv->source, corresponding); - - sequence = g_new (ETreePath, depth + 1); - - sequence[0] = corresponding; - - for (i = 0; i < depth; i++) - sequence[i + 1] = e_tree_model_node_get_parent (ets->priv->source, sequence[i]); - - path = ets->priv->root; - - for (i = depth - 1; i >= 0 && path != NULL; i--) { - gint j; - - if (path->num_children == -1) { - path = NULL; - break; - } - - for (j = 0; j < path->num_children; j++) { - if (path->children[j]->corresponding == sequence[i]) { - break; - } - } - - if (j < path->num_children) { - path = path->children[j]; - } else { - path = NULL; - } - } - g_free (sequence); - - d (g_print ("Didn't find last access %p. Setting to %p. (find_path)\n", ets->priv->last_access, path)); - ets->priv->last_access = path; - - return path; -} - -static ETreeSortedPath * -find_child_path (ETreeSorted *ets, - ETreeSortedPath *parent, - ETreePath corresponding) -{ - gint i; - - if (corresponding == NULL) - return NULL; - - if (parent->num_children == -1) { - return NULL; - } - - for (i = 0; i < parent->num_children; i++) - if (parent->children[i]->corresponding == corresponding) - return parent->children[i]; - - return NULL; -} - -static ETreeSortedPath * -find_or_create_path (ETreeSorted *ets, - ETreePath corresponding) -{ - gint depth; - ETreePath *sequence; - gint i; - ETreeSortedPath *path; - ETreeSortedPath *check_last; - - if (corresponding == NULL) - return NULL; - - check_last = check_last_access (ets, corresponding); - if (check_last) { - d (g_print (" (find_or_create_path)\n")); - return check_last; - } - - depth = e_tree_model_node_depth (ets->priv->source, corresponding); - - sequence = g_new (ETreePath, depth + 1); - - sequence[0] = corresponding; - - for (i = 0; i < depth; i++) - sequence[i + 1] = e_tree_model_node_get_parent (ets->priv->source, sequence[i]); - - path = ets->priv->root; - - for (i = depth - 1; i >= 0 && path != NULL; i--) { - gint j; - - if (path->num_children == -1) { - generate_children (ets, path); - } - - for (j = 0; j < path->num_children; j++) { - if (path->children[j]->corresponding == sequence[i]) { - break; - } - } - - if (j < path->num_children) { - path = path->children[j]; - } else { - path = NULL; - } - } - g_free (sequence); - - d (g_print ("Didn't find last access %p. Setting to %p. (find_or_create_path)\n", ets->priv->last_access, path)); - ets->priv->last_access = path; - - return path; -} - -static void -free_children (ETreeSortedPath *path) -{ - gint i; - - if (path == NULL) - return; - - for (i = 0; i < path->num_children; i++) { - free_path (path->children[i]); - } - - g_free (path->children); - path->children = NULL; - path->num_children = -1; -} - -static void -free_path (ETreeSortedPath *path) -{ - free_children (path); - g_slice_free (ETreeSortedPath, path); -} - -static ETreeSortedPath * -new_path (ETreeSortedPath *parent, - ETreePath corresponding) -{ - ETreeSortedPath *path; - - path = g_slice_new0 (ETreeSortedPath); - - path->corresponding = corresponding; - path->parent = parent; - path->num_children = -1; - path->children = NULL; - path->position = -1; - path->orig_position = -1; - path->child_needs_resort = 0; - path->resort_all_children = 0; - path->needs_resort = 0; - path->needs_regen_to_sort = 0; - - return path; -} - -static gboolean -reposition_path (ETreeSorted *ets, - ETreeSortedPath *path) -{ - gint new_index; - gint old_index = path->position; - ETreeSortedPath *parent = path->parent; - gboolean changed = FALSE; - if (parent) { - if (ets->priv->sort_idle_id == 0) { - if (ets->priv->insert_count > ETS_INSERT_MAX) { - /* schedule a sort, and append instead */ - schedule_resort (ets, parent, TRUE, FALSE); - } else { - /* make sure we have an idle handler to reset the count every now and then */ - if (ets->priv->insert_idle_id == 0) { - ets->priv->insert_idle_id = g_idle_add_full (40, (GSourceFunc) ets_insert_idle, ets, NULL); - } - - new_index = e_table_sorting_utils_tree_check_position - (E_TREE_MODEL (ets), - ets->priv->sort_info, - ets->priv->full_header, - (ETreePath *) parent->children, - parent->num_children, - old_index); - - if (new_index > old_index) { - gint i; - ets->priv->insert_count++; - memmove (parent->children + old_index, parent->children + old_index + 1, sizeof (ETreePath) * (new_index - old_index)); - parent->children[new_index] = path; - for (i = old_index; i <= new_index; i++) - parent->children[i]->position = i; - changed = TRUE; - e_tree_model_node_changed (E_TREE_MODEL (ets), parent); - e_tree_sorted_node_resorted (ets, parent); - } else if (new_index < old_index) { - gint i; - ets->priv->insert_count++; - memmove (parent->children + new_index + 1, parent->children + new_index, sizeof (ETreePath) * (old_index - new_index)); - parent->children[new_index] = path; - for (i = new_index; i <= old_index; i++) - parent->children[i]->position = i; - changed = TRUE; - e_tree_model_node_changed (E_TREE_MODEL (ets), parent); - e_tree_sorted_node_resorted (ets, parent); - } - } - } else - mark_path_needs_resort (ets, parent, TRUE, FALSE); - } - return changed; -} - -static void -regenerate_children (ETreeSorted *ets, - ETreeSortedPath *path) -{ - ETreeSortedPath **children; - gint i; - - children = g_new (ETreeSortedPath *, path->num_children); - for (i = 0; i < path->num_children; i++) - children[path->children[i]->orig_position] = path->children[i]; - g_free (path->children); - path->children = children; -} - -static void -generate_children (ETreeSorted *ets, - ETreeSortedPath *path) -{ - ETreePath child; - gint i; - gint count; - - free_children (path); - - count = 0; - for (child = e_tree_model_node_get_first_child (ets->priv->source, path->corresponding); - child; - child = e_tree_model_node_get_next (ets->priv->source, child)) { - count++; - } - - path->num_children = count; - path->children = g_new (ETreeSortedPath *, count); - for (child = e_tree_model_node_get_first_child (ets->priv->source, path->corresponding), i = 0; - child; - child = e_tree_model_node_get_next (ets->priv->source, child), i++) { - path->children[i] = new_path (path, child); - path->children[i]->position = i; - path->children[i]->orig_position = i; - } - if (path->num_children > 0) - schedule_resort (ets, path, FALSE, TRUE); -} - -static void -resort_node (ETreeSorted *ets, - ETreeSortedPath *path, - gboolean resort_all_children, - gboolean needs_regen, - gboolean send_signals) -{ - gboolean needs_resort; - if (path) { - needs_resort = path->needs_resort || resort_all_children; - needs_regen = path->needs_regen_to_sort || needs_regen; - if (path->num_children > 0) { - if (needs_resort && send_signals) - e_tree_model_pre_change (E_TREE_MODEL (ets)); - if (needs_resort) { - gint i; - d (g_print ("Start sort of node %p\n", path)); - if (needs_regen) - regenerate_children (ets, path); - d (g_print ("Regened sort of node %p\n", path)); - e_table_sorting_utils_tree_sort ( - E_TREE_MODEL (ets), - ets->priv->sort_info, - ets->priv->full_header, - (ETreePath *) path->children, - path->num_children); - d (g_print ("Renumbering sort of node %p\n", path)); - for (i = 0; i < path->num_children; i++) { - path->children[i]->position = i; - } - d (g_print ("End sort of node %p\n", path)); - } - if (path->resort_all_children) - resort_all_children = TRUE; - if ((resort_all_children || path->child_needs_resort) && path->num_children >= 0) { - gint i; - for (i = 0; i < path->num_children; i++) { - resort_node (ets, path->children[i], resort_all_children, needs_regen, send_signals && !needs_resort); - } - path->child_needs_resort = 0; - } - } - path->needs_resort = 0; - path->child_needs_resort = 0; - path->needs_regen_to_sort = 0; - path->resort_all_children = 0; - if (needs_resort && send_signals && path->num_children > 0) { - e_tree_model_node_changed (E_TREE_MODEL (ets), path); - e_tree_sorted_node_resorted (ets, path); - } - } -} - -static void -mark_path_child_needs_resort (ETreeSorted *ets, - ETreeSortedPath *path) -{ - if (path == NULL) - return; - if (!path->child_needs_resort) { - path->child_needs_resort = 1; - mark_path_child_needs_resort (ets, path->parent); - } -} - -static void -mark_path_needs_resort (ETreeSorted *ets, - ETreeSortedPath *path, - gboolean needs_regen, - gboolean resort_all_children) -{ - if (path == NULL) - return; - if (path->num_children == 0) - return; - path->needs_resort = 1; - path->needs_regen_to_sort = needs_regen; - path->resort_all_children = resort_all_children; - mark_path_child_needs_resort (ets, path->parent); -} - -static void -schedule_resort (ETreeSorted *ets, - ETreeSortedPath *path, - gboolean needs_regen, - gboolean resort_all_children) -{ - ets->priv->insert_count = 0; - if (ets->priv->insert_idle_id != 0) { - g_source_remove (ets->priv->insert_idle_id); - ets->priv->insert_idle_id = 0; - } - - if (path == NULL) - return; - if (path->num_children == 0) - return; - - mark_path_needs_resort (ets, path, needs_regen, resort_all_children); - if (ets->priv->sort_idle_id == 0) { - ets->priv->sort_idle_id = g_idle_add_full (50, (GSourceFunc) ets_sort_idle, ets, NULL); - } else if (ets->priv->in_resort_idle) { - ets->priv->nested_resort_idle = TRUE; - } -} - -/* virtual methods */ - -static void -ets_dispose (GObject *object) -{ - ETreeSortedPrivate *priv; - - priv = E_TREE_SORTED_GET_PRIVATE (object); - - if (priv->source) { - g_signal_handler_disconnect ( - priv->source, priv->tree_model_pre_change_id); - g_signal_handler_disconnect ( - priv->source, priv->tree_model_no_change_id); - g_signal_handler_disconnect ( - priv->source, priv->tree_model_node_changed_id); - g_signal_handler_disconnect ( - priv->source, priv->tree_model_node_data_changed_id); - g_signal_handler_disconnect ( - priv->source, priv->tree_model_node_col_changed_id); - g_signal_handler_disconnect ( - priv->source, priv->tree_model_node_inserted_id); - g_signal_handler_disconnect ( - priv->source, priv->tree_model_node_removed_id); - g_signal_handler_disconnect ( - priv->source, priv->tree_model_node_deleted_id); - g_signal_handler_disconnect ( - priv->source, priv->tree_model_node_request_collapse_id); - - g_object_unref (priv->source); - priv->source = NULL; - - priv->tree_model_pre_change_id = 0; - priv->tree_model_no_change_id = 0; - priv->tree_model_node_changed_id = 0; - priv->tree_model_node_data_changed_id = 0; - priv->tree_model_node_col_changed_id = 0; - priv->tree_model_node_inserted_id = 0; - priv->tree_model_node_removed_id = 0; - priv->tree_model_node_deleted_id = 0; - priv->tree_model_node_request_collapse_id = 0; - } - - if (priv->sort_info) { - g_signal_handler_disconnect ( - priv->sort_info, priv->sort_info_changed_id); - priv->sort_info_changed_id = 0; - - g_object_unref (priv->sort_info); - priv->sort_info = NULL; - } - - ets_stop_sort_idle (E_TREE_SORTED (object)); - - if (priv->insert_idle_id) { - g_source_remove (priv->insert_idle_id); - priv->insert_idle_id = 0; - } - - if (priv->full_header) { - g_object_unref (priv->full_header); - priv->full_header = NULL; - } - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (e_tree_sorted_parent_class)->dispose (object); -} - -static void -ets_finalize (GObject *object) -{ - ETreeSortedPrivate *priv; - - priv = E_TREE_SORTED_GET_PRIVATE (object); - - if (priv->root) - free_path (priv->root); - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (e_tree_sorted_parent_class)->finalize (object); -} - -static ETreePath -ets_get_root (ETreeModel *etm) -{ - ETreeSortedPrivate *priv = E_TREE_SORTED (etm)->priv; - if (priv->root == NULL) { - ETreeSorted *ets = E_TREE_SORTED (etm); - ETreePath corresponding = e_tree_model_get_root (ets->priv->source); - - if (corresponding) { - priv->root = new_path (NULL, corresponding); - } - } - if (priv->root && priv->root->num_children == -1) { - generate_children (E_TREE_SORTED (etm), priv->root); - } - - return priv->root; -} - -static ETreePath -ets_get_parent (ETreeModel *etm, - ETreePath node) -{ - ETreeSortedPath *path = node; - return path->parent; -} - -static ETreePath -ets_get_first_child (ETreeModel *etm, - ETreePath node) -{ - ETreeSortedPath *path = node; - ETreeSorted *ets = E_TREE_SORTED (etm); - - if (path->num_children == -1) - generate_children (ets, path); - - if (path->num_children > 0) - return path->children[0]; - else - return NULL; -} - -static ETreePath -ets_get_last_child (ETreeModel *etm, - ETreePath node) -{ - ETreeSortedPath *path = node; - ETreeSorted *ets = E_TREE_SORTED (etm); - - if (path->num_children == -1) - generate_children (ets, path); - - if (path->num_children > 0) - return path->children[path->num_children - 1]; - else - return NULL; -} - -static ETreePath -ets_get_next (ETreeModel *etm, - ETreePath node) -{ - ETreeSortedPath *path = node; - ETreeSortedPath *parent = path->parent; - if (parent) { - if (parent->num_children > path->position + 1) - return parent->children[path->position + 1]; - else - return NULL; - } else - return NULL; -} - -static ETreePath -ets_get_prev (ETreeModel *etm, - ETreePath node) -{ - ETreeSortedPath *path = node; - ETreeSortedPath *parent = path->parent; - if (parent) { - if (path->position - 1 >= 0) - return parent->children[path->position - 1]; - else - return NULL; - } else - return NULL; -} - -static gboolean -ets_is_root (ETreeModel *etm, - ETreePath node) -{ - ETreeSortedPath *path = node; - ETreeSorted *ets = E_TREE_SORTED (etm); - - return e_tree_model_node_is_root (ets->priv->source, path->corresponding); -} - -static gboolean -ets_is_expandable (ETreeModel *etm, - ETreePath node) -{ - ETreeSortedPath *path = node; - ETreeSorted *ets = E_TREE_SORTED (etm); - gboolean expandable = e_tree_model_node_is_expandable (ets->priv->source, path->corresponding); - - if (path->num_children == -1) { - generate_children (ets, node); - } - - return expandable; -} - -static guint -ets_get_children (ETreeModel *etm, - ETreePath node, - ETreePath **nodes) -{ - ETreeSortedPath *path = node; - guint n_children; - - if (path->num_children == -1) { - generate_children (E_TREE_SORTED (etm), node); - } - - n_children = path->num_children; - - if (nodes) { - gint i; - - (*nodes) = g_malloc (sizeof (ETreePath) * n_children); - for (i = 0; i < n_children; i++) { - (*nodes)[i] = path->children[i]; - } - } - - return n_children; -} - -static guint -ets_depth (ETreeModel *etm, - ETreePath node) -{ - ETreeSortedPath *path = node; - ETreeSorted *ets = E_TREE_SORTED (etm); - - return e_tree_model_node_depth (ets->priv->source, path->corresponding); -} - -static GdkPixbuf * -ets_icon_at (ETreeModel *etm, - ETreePath node) -{ - ETreeSortedPath *path = node; - ETreeSorted *ets = E_TREE_SORTED (etm); - - return e_tree_model_icon_at (ets->priv->source, path->corresponding); -} - -static gboolean -ets_get_expanded_default (ETreeModel *etm) -{ - ETreeSorted *ets = E_TREE_SORTED (etm); - - return e_tree_model_get_expanded_default (ets->priv->source); -} - -static gint -ets_column_count (ETreeModel *etm) -{ - ETreeSorted *ets = E_TREE_SORTED (etm); - - return e_tree_model_column_count (ets->priv->source); -} - -static gboolean -ets_has_save_id (ETreeModel *etm) -{ - return TRUE; -} - -static gchar * -ets_get_save_id (ETreeModel *etm, - ETreePath node) -{ - ETreeSorted *ets = E_TREE_SORTED (etm); - ETreeSortedPath *path = node; - - if (e_tree_model_has_save_id (ets->priv->source)) - return e_tree_model_get_save_id (ets->priv->source, path->corresponding); - else - return g_strdup_printf ("%p", path->corresponding); -} - -static gboolean -ets_has_get_node_by_id (ETreeModel *etm) -{ - ETreeSorted *ets = E_TREE_SORTED (etm); - return e_tree_model_has_get_node_by_id (ets->priv->source); -} - -static ETreePath -ets_get_node_by_id (ETreeModel *etm, - const gchar *save_id) -{ - ETreeSorted *ets = E_TREE_SORTED (etm); - ETreePath node; - - node = e_tree_model_get_node_by_id (ets->priv->source, save_id); - - return find_path (ets, node); -} - -static gboolean -ets_has_change_pending (ETreeModel *etm) -{ - ETreeSorted *ets = E_TREE_SORTED (etm); - - return ets->priv->sort_idle_id != 0; -} - -static gpointer -ets_value_at (ETreeModel *etm, - ETreePath node, - gint col) -{ - ETreeSorted *ets = E_TREE_SORTED (etm); - ETreeSortedPath *path = node; - - return e_tree_model_value_at (ets->priv->source, path->corresponding, col); -} - -static void -ets_set_value_at (ETreeModel *etm, - ETreePath node, - gint col, - gconstpointer val) -{ - ETreeSorted *ets = E_TREE_SORTED (etm); - ETreeSortedPath *path = node; - - e_tree_model_set_value_at (ets->priv->source, path->corresponding, col, val); -} - -static gboolean -ets_is_editable (ETreeModel *etm, - ETreePath node, - gint col) -{ - ETreeSorted *ets = E_TREE_SORTED (etm); - ETreeSortedPath *path = node; - - return e_tree_model_node_is_editable (ets->priv->source, path->corresponding, col); -} - -/* The default for ets_duplicate_value is to return the raw value. */ -static gpointer -ets_duplicate_value (ETreeModel *etm, - gint col, - gconstpointer value) -{ - ETreeSorted *ets = E_TREE_SORTED (etm); - - return e_tree_model_duplicate_value (ets->priv->source, col, value); -} - -static void -ets_free_value (ETreeModel *etm, - gint col, - gpointer value) -{ - ETreeSorted *ets = E_TREE_SORTED (etm); - - e_tree_model_free_value (ets->priv->source, col, value); -} - -static gpointer -ets_initialize_value (ETreeModel *etm, - gint col) -{ - ETreeSorted *ets = E_TREE_SORTED (etm); - - return e_tree_model_initialize_value (ets->priv->source, col); -} - -static gboolean -ets_value_is_empty (ETreeModel *etm, - gint col, - gconstpointer value) -{ - ETreeSorted *ets = E_TREE_SORTED (etm); - - return e_tree_model_value_is_empty (ets->priv->source, col, value); -} - -static gchar * -ets_value_to_string (ETreeModel *etm, - gint col, - gconstpointer value) -{ - ETreeSorted *ets = E_TREE_SORTED (etm); - - return e_tree_model_value_to_string (ets->priv->source, col, value); -} - -/* Proxy functions */ - -static void -ets_proxy_pre_change (ETreeModel *etm, - ETreeSorted *ets) -{ - e_tree_model_pre_change (E_TREE_MODEL (ets)); -} - -static void -ets_proxy_no_change (ETreeModel *etm, - ETreeSorted *ets) -{ - e_tree_model_no_change (E_TREE_MODEL (ets)); -} - -static void -ets_proxy_node_changed (ETreeModel *etm, - ETreePath node, - ETreeSorted *ets) -{ - ets->priv->last_access = NULL; - d (g_print ("Setting last access %p. (ets_proxy_node_changed)\n", ets->priv->last_access)); - - if (e_tree_model_node_is_root (ets->priv->source, node)) { - ets_stop_sort_idle (ets); - - if (ets->priv->root) { - free_path (ets->priv->root); - } - ets->priv->root = new_path (NULL, node); - e_tree_model_node_changed (E_TREE_MODEL (ets), ets->priv->root); - return; - } else { - ETreeSortedPath *path = find_path (ets, node); - - if (path) { - free_children (path); - if (!reposition_path (ets, path)) { - e_tree_model_node_changed (E_TREE_MODEL (ets), path); - } else { - e_tree_model_no_change (E_TREE_MODEL (ets)); - } - } else { - e_tree_model_no_change (E_TREE_MODEL (ets)); - } - } -} - -static void -ets_proxy_node_data_changed (ETreeModel *etm, - ETreePath node, - ETreeSorted *ets) -{ - ETreeSortedPath *path = find_path (ets, node); - - if (path) { - if (!reposition_path (ets, path)) - e_tree_model_node_data_changed (E_TREE_MODEL (ets), path); - else - e_tree_model_no_change (E_TREE_MODEL (ets)); - } else - e_tree_model_no_change (E_TREE_MODEL (ets)); -} - -static void -ets_proxy_node_col_changed (ETreeModel *etm, - ETreePath node, - gint col, - ETreeSorted *ets) -{ - ETreeSortedPath *path = find_path (ets, node); - - if (path) { - gboolean changed = FALSE; - if (e_table_sorting_utils_affects_sort (ets->priv->sort_info, ets->priv->full_header, col)) - changed = reposition_path (ets, path); - if (!changed) - e_tree_model_node_col_changed (E_TREE_MODEL (ets), path, col); - else - e_tree_model_no_change (E_TREE_MODEL (ets)); - } else - e_tree_model_no_change (E_TREE_MODEL (ets)); -} - -static void -ets_proxy_node_inserted (ETreeModel *etm, - ETreePath parent, - ETreePath child, - ETreeSorted *ets) -{ - ETreeSortedPath *parent_path = find_path (ets, parent); - - if (parent_path && parent_path->num_children != -1) { - gint i; - gint j; - ETreeSortedPath *path; - gint position = parent_path->num_children; - ETreePath counter; - - for (counter = e_tree_model_node_get_next (etm, child); - counter; - counter = e_tree_model_node_get_next (etm, counter)) - position--; - - if (position != parent_path->num_children) { - for (i = 0; i < parent_path->num_children; i++) { - if (parent_path->children[i]->orig_position >= position) - parent_path->children[i]->orig_position++; - } - } - - i = parent_path->num_children; - path = new_path (parent_path, child); - path->orig_position = position; - if (!ETS_SORT_IDLE_ACTIVATED (ets)) { - ets->priv->insert_count++; - if (ets->priv->insert_count > ETS_INSERT_MAX) { - /* schedule a sort, and append instead */ - schedule_resort (ets, parent_path, TRUE, FALSE); - } else { - /* make sure we have an idle handler to reset the count every now and then */ - if (ets->priv->insert_idle_id == 0) { - ets->priv->insert_idle_id = g_idle_add_full (40, (GSourceFunc) ets_insert_idle, ets, NULL); - } - i = e_table_sorting_utils_tree_insert - (ets->priv->source, - ets->priv->sort_info, - ets->priv->full_header, - (ETreePath *) parent_path->children, - parent_path->num_children, - path); - } - } else { - mark_path_needs_resort (ets, parent_path, TRUE, FALSE); - } - parent_path->num_children++; - parent_path->children = g_renew (ETreeSortedPath *, parent_path->children, parent_path->num_children); - memmove (parent_path->children + i + 1, parent_path->children + i, (parent_path->num_children - 1 - i) * sizeof (gint)); - parent_path->children[i] = path; - for (j = i; j < parent_path->num_children; j++) { - parent_path->children[j]->position = j; - } - e_tree_model_node_inserted (E_TREE_MODEL (ets), parent_path, parent_path->children[i]); - } else if (ets->priv->root == NULL && parent == NULL) { - if (child) { - ets->priv->root = new_path (NULL, child); - e_tree_model_node_inserted (E_TREE_MODEL (ets), NULL, ets->priv->root); - } else { - e_tree_model_no_change (E_TREE_MODEL (ets)); - } - } else { - e_tree_model_no_change (E_TREE_MODEL (ets)); - } -} - -static void -ets_proxy_node_removed (ETreeModel *etm, - ETreePath parent, - ETreePath child, - gint old_position, - ETreeSorted *ets) -{ - ETreeSortedPath *parent_path = find_path (ets, parent); - ETreeSortedPath *path; - - if (parent_path) - path = find_child_path (ets, parent_path, child); - else - path = find_path (ets, child); - - d (g_print ("Setting last access %p. (ets_proxy_node_removed)\n ", ets->priv->last_access)); - ets->priv->last_access = NULL; - - if (path && parent_path && parent_path->num_children != -1) { - gint i; - for (i = 0; i < parent_path->num_children; i++) { - if (parent_path->children[i]->orig_position > old_position) - parent_path->children[i]->orig_position--; - } - - i = path->position; - - parent_path->num_children--; - memmove (parent_path->children + i, parent_path->children + i + 1, sizeof (ETreeSortedPath *) * (parent_path->num_children - i)); - for (; i < parent_path->num_children; i++) { - parent_path->children[i]->position = i; - } - e_tree_model_node_removed (E_TREE_MODEL (ets), parent_path, path, path->position); - free_path (path); - } else if (path && path == ets->priv->root) { - ets->priv->root = NULL; - e_tree_model_node_removed (E_TREE_MODEL (ets), NULL, path, -1); - free_path (path); - } -} - -static void -ets_proxy_node_deleted (ETreeModel *etm, - ETreePath child, - ETreeSorted *ets) -{ - e_tree_model_node_deleted (E_TREE_MODEL (ets), NULL); -} - -static void -ets_proxy_node_request_collapse (ETreeModel *etm, - ETreePath node, - ETreeSorted *ets) -{ - ETreeSortedPath *path = find_path (ets, node); - if (path) { - e_tree_model_node_request_collapse (E_TREE_MODEL (ets), path); - } -} - -static void -ets_sort_info_changed (ETableSortInfo *sort_info, - ETreeSorted *ets) -{ - schedule_resort (ets, ets->priv->root, TRUE, TRUE); -} - -/* Initialization and creation */ - -static void -e_tree_sorted_class_init (ETreeSortedClass *class) -{ - GObjectClass *object_class; - ETreeModelClass *tree_model_class; - - g_type_class_add_private (class, sizeof (ETreeSortedPrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->dispose = ets_dispose; - object_class->finalize = ets_finalize; - - tree_model_class = E_TREE_MODEL_CLASS (class); - tree_model_class->get_root = ets_get_root; - tree_model_class->get_parent = ets_get_parent; - tree_model_class->get_first_child = ets_get_first_child; - tree_model_class->get_last_child = ets_get_last_child; - tree_model_class->get_prev = ets_get_prev; - tree_model_class->get_next = ets_get_next; - - tree_model_class->is_root = ets_is_root; - tree_model_class->is_expandable = ets_is_expandable; - tree_model_class->get_children = ets_get_children; - tree_model_class->depth = ets_depth; - - tree_model_class->icon_at = ets_icon_at; - - tree_model_class->get_expanded_default = ets_get_expanded_default; - tree_model_class->column_count = ets_column_count; - - tree_model_class->has_save_id = ets_has_save_id; - tree_model_class->get_save_id = ets_get_save_id; - - tree_model_class->has_get_node_by_id = ets_has_get_node_by_id; - tree_model_class->get_node_by_id = ets_get_node_by_id; - - tree_model_class->has_change_pending = ets_has_change_pending; - - tree_model_class->value_at = ets_value_at; - tree_model_class->set_value_at = ets_set_value_at; - tree_model_class->is_editable = ets_is_editable; - - tree_model_class->duplicate_value = ets_duplicate_value; - tree_model_class->free_value = ets_free_value; - tree_model_class->initialize_value = ets_initialize_value; - tree_model_class->value_is_empty = ets_value_is_empty; - tree_model_class->value_to_string = ets_value_to_string; - - signals[NODE_RESORTED] = g_signal_new ( - "node_resorted", - G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeSortedClass, node_resorted), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, 1, - G_TYPE_POINTER); -} - -static void -e_tree_sorted_init (ETreeSorted *ets) -{ - ets->priv = E_TREE_SORTED_GET_PRIVATE (ets); -} - -/** - * e_tree_sorted_construct: - * @etree: - * - * - **/ -void -e_tree_sorted_construct (ETreeSorted *ets, - ETreeModel *source, - ETableHeader *full_header, - ETableSortInfo *sort_info) -{ - ets->priv->source = source; - if (source) - g_object_ref (source); - - ets->priv->full_header = full_header; - if (full_header) - g_object_ref (full_header); - - e_tree_sorted_set_sort_info (ets, sort_info); - - ets->priv->tree_model_pre_change_id = g_signal_connect ( - source, "pre_change", - G_CALLBACK (ets_proxy_pre_change), ets); - ets->priv->tree_model_no_change_id = g_signal_connect ( - source, "no_change", - G_CALLBACK (ets_proxy_no_change), ets); - ets->priv->tree_model_node_changed_id = g_signal_connect ( - source, "node_changed", - G_CALLBACK (ets_proxy_node_changed), ets); - ets->priv->tree_model_node_data_changed_id = g_signal_connect ( - source, "node_data_changed", - G_CALLBACK (ets_proxy_node_data_changed), ets); - ets->priv->tree_model_node_col_changed_id = g_signal_connect ( - source, "node_col_changed", - G_CALLBACK (ets_proxy_node_col_changed), ets); - ets->priv->tree_model_node_inserted_id = g_signal_connect ( - source, "node_inserted", - G_CALLBACK (ets_proxy_node_inserted), ets); - ets->priv->tree_model_node_removed_id = g_signal_connect ( - source, "node_removed", - G_CALLBACK (ets_proxy_node_removed), ets); - ets->priv->tree_model_node_deleted_id = g_signal_connect ( - source, "node_deleted", - G_CALLBACK (ets_proxy_node_deleted), ets); - ets->priv->tree_model_node_request_collapse_id = g_signal_connect ( - source, "node_request_collapse", - G_CALLBACK (ets_proxy_node_request_collapse), ets); - -} - -/** - * e_tree_sorted_new - * - * FIXME docs here. - * - * return values: a newly constructed ETreeSorted. - */ -ETreeSorted * -e_tree_sorted_new (ETreeModel *source, - ETableHeader *full_header, - ETableSortInfo *sort_info) -{ - ETreeSorted *ets = g_object_new (E_TYPE_TREE_SORTED, NULL); - - e_tree_sorted_construct (ets, source, full_header, sort_info); - - return ets; -} - -ETreePath -e_tree_sorted_view_to_model_path (ETreeSorted *ets, - ETreePath view_path) -{ - ETreeSortedPath *path = view_path; - if (path) { - ets->priv->last_access = path; - d (g_print ("Setting last access %p. (e_tree_sorted_view_to_model_path)\n", ets->priv->last_access)); - return path->corresponding; - } else - return NULL; -} - -ETreePath -e_tree_sorted_model_to_view_path (ETreeSorted *ets, - ETreePath model_path) -{ - return find_or_create_path (ets, model_path); -} - -gint -e_tree_sorted_orig_position (ETreeSorted *ets, - ETreePath path) -{ - ETreeSortedPath *sorted_path = path; - return sorted_path->orig_position; -} - -gint -e_tree_sorted_node_num_children (ETreeSorted *ets, - ETreePath path) -{ - ETreeSortedPath *sorted_path = path; - - if (sorted_path->num_children == -1) { - generate_children (ets, sorted_path); - } - - return sorted_path->num_children; -} - -void -e_tree_sorted_node_resorted (ETreeSorted *sorted, - ETreePath node) -{ - g_return_if_fail (sorted != NULL); - g_return_if_fail (E_IS_TREE_SORTED (sorted)); - - g_signal_emit (sorted, signals[NODE_RESORTED], 0, node); -} - -void -e_tree_sorted_set_sort_info (ETreeSorted *ets, - ETableSortInfo *sort_info) -{ - - g_return_if_fail (ets != NULL); - - if (ets->priv->sort_info) { - if (ets->priv->sort_info_changed_id != 0) - g_signal_handler_disconnect ( - ets->priv->sort_info, - ets->priv->sort_info_changed_id); - ets->priv->sort_info_changed_id = 0; - g_object_unref (ets->priv->sort_info); - } - - ets->priv->sort_info = sort_info; - if (sort_info) { - g_object_ref (sort_info); - ets->priv->sort_info_changed_id = g_signal_connect ( - ets->priv->sort_info, "sort_info_changed", - G_CALLBACK (ets_sort_info_changed), ets); - } - - if (ets->priv->root) - schedule_resort (ets, ets->priv->root, TRUE, TRUE); -} - -ETableSortInfo * -e_tree_sorted_get_sort_info (ETreeSorted *ets) -{ - return ets->priv->sort_info; -} - diff --git a/widgets/table/e-tree-sorted.h b/widgets/table/e-tree-sorted.h deleted file mode 100644 index 456ee15d14..0000000000 --- a/widgets/table/e-tree-sorted.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TREE_SORTED_H_ -#define _E_TREE_SORTED_H_ - -#include <gdk-pixbuf/gdk-pixbuf.h> -#include <table/e-tree-model.h> -#include <table/e-table-sort-info.h> -#include <table/e-table-header.h> - -/* Standard GObject macros */ -#define E_TYPE_TREE_SORTED \ - (e_tree_sorted_get_type ()) -#define E_TREE_SORTED(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TREE_SORTED, ETreeSorted)) -#define E_TREE_SORTED_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TREE_SORTED, ETreeSortedClass)) -#define E_IS_TREE_SORTED(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TREE_SORTED)) -#define E_IS_TREE_SORTED_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TREE_SORTED)) -#define E_TREE_SORTED_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TREE_SORTED, ETreeSortedClass)) - -G_BEGIN_DECLS - -typedef struct _ETreeSorted ETreeSorted; -typedef struct _ETreeSortedClass ETreeSortedClass; -typedef struct _ETreeSortedPrivate ETreeSortedPrivate; - -struct _ETreeSorted { - ETreeModel parent; - ETreeSortedPrivate *priv; -}; - -struct _ETreeSortedClass { - ETreeModelClass parent_class; - - /* Signals */ - void (*node_resorted) (ETreeSorted *etm, - ETreePath node); -}; - -GType e_tree_sorted_get_type (void) G_GNUC_CONST; -void e_tree_sorted_construct (ETreeSorted *etree, - ETreeModel *source, - ETableHeader *full_header, - ETableSortInfo *sort_info); -ETreeSorted * e_tree_sorted_new (ETreeModel *source, - ETableHeader *full_header, - ETableSortInfo *sort_info); - -ETreePath e_tree_sorted_view_to_model_path - (ETreeSorted *ets, - ETreePath view_path); -ETreePath e_tree_sorted_model_to_view_path - (ETreeSorted *ets, - ETreePath model_path); -gint e_tree_sorted_orig_position (ETreeSorted *ets, - ETreePath path); -gint e_tree_sorted_node_num_children (ETreeSorted *ets, - ETreePath path); - -void e_tree_sorted_node_resorted (ETreeSorted *tree_model, - ETreePath node); - -ETableSortInfo *e_tree_sorted_get_sort_info (ETreeSorted *tree_model); -void e_tree_sorted_set_sort_info (ETreeSorted *tree_model, - ETableSortInfo *sort_info); - -G_END_DECLS - -#endif /* _E_TREE_SORTED_H */ diff --git a/widgets/table/e-tree-table-adapter.c b/widgets/table/e-tree-table-adapter.c deleted file mode 100644 index c610039c83..0000000000 --- a/widgets/table/e-tree-table-adapter.c +++ /dev/null @@ -1,1413 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Chris Toshok <toshok@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <string.h> - -#include <glib/gstdio.h> -#include <libxml/tree.h> -#include <libxml/parser.h> - -#include <libedataserver/libedataserver.h> - -#include "e-util/e-util.h" -#include "libevolution-utils/e-xml-utils.h" - -#include "e-table-sorting-utils.h" -#include "e-tree-table-adapter.h" - -#define E_TREE_TABLE_ADAPTER_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), E_TYPE_TREE_TABLE_ADAPTER, ETreeTableAdapterPrivate)) - -/* workaround for avoiding API breakage */ -#define etta_get_type e_tree_table_adapter_get_type -G_DEFINE_TYPE (ETreeTableAdapter, etta, E_TYPE_TABLE_MODEL) -#define d(x) - -#define INCREMENT_AMOUNT 100 - -enum { - SORTING_CHANGED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0, }; - -typedef struct { - ETreePath path; - guint32 num_visible_children; - guint32 index; - - guint expanded : 1; - guint expandable : 1; - guint expandable_set : 1; -} node_t; - -struct _ETreeTableAdapterPrivate { - ETreeModel *source; - ETableSortInfo *sort_info; - ETableHeader *header; - - gint n_map; - gint n_vals_allocated; - node_t **map_table; - GHashTable *nodes; - GNode *root; - - guint root_visible : 1; - guint remap_needed : 1; - - gint last_access; - - gint pre_change_id; - gint no_change_id; - gint rebuilt_id; - gint node_changed_id; - gint node_data_changed_id; - gint node_col_changed_id; - gint node_inserted_id; - gint node_removed_id; - gint node_request_collapse_id; - gint sort_info_changed_id; - - guint resort_idle_id; - - gint force_expanded_state; /* use this instead of model's default if not 0; <0 ... collapse, >0 ... expand */ -}; - -static void etta_sort_info_changed (ETableSortInfo *sort_info, ETreeTableAdapter *etta); - -static GNode * -lookup_gnode (ETreeTableAdapter *etta, - ETreePath path) -{ - GNode *gnode; - - if (!path) - return NULL; - - gnode = g_hash_table_lookup (etta->priv->nodes, path); - - return gnode; -} - -static void -resize_map (ETreeTableAdapter *etta, - gint size) -{ - if (size > etta->priv->n_vals_allocated) { - etta->priv->n_vals_allocated = MAX (etta->priv->n_vals_allocated + INCREMENT_AMOUNT, size); - etta->priv->map_table = g_renew (node_t *, etta->priv->map_table, etta->priv->n_vals_allocated); - } - - etta->priv->n_map = size; -} - -static void -move_map_elements (ETreeTableAdapter *etta, - gint to, - gint from, - gint count) -{ - if (count <= 0 || from >= etta->priv->n_map) - return; - memmove (etta->priv->map_table + to, etta->priv->map_table + from, count * sizeof (node_t *)); - etta->priv->remap_needed = TRUE; -} - -static gint -fill_map (ETreeTableAdapter *etta, - gint index, - GNode *gnode) -{ - GNode *p; - - if ((gnode != etta->priv->root) || etta->priv->root_visible) - etta->priv->map_table[index++] = gnode->data; - - for (p = gnode->children; p; p = p->next) - index = fill_map (etta, index, p); - - etta->priv->remap_needed = TRUE; - return index; -} - -static void -remap_indices (ETreeTableAdapter *etta) -{ - gint i; - for (i = 0; i < etta->priv->n_map; i++) - etta->priv->map_table[i]->index = i; - etta->priv->remap_needed = FALSE; -} - -static node_t * -get_node (ETreeTableAdapter *etta, - ETreePath path) -{ - GNode *gnode = lookup_gnode (etta, path); - - if (!gnode) - return NULL; - - return (node_t *) gnode->data; -} - -static void -resort_node (ETreeTableAdapter *etta, - GNode *gnode, - gboolean recurse) -{ - node_t *node = (node_t *) gnode->data; - ETreePath *paths, path; - GNode *prev, *curr; - gint i, count; - gboolean sort_needed; - - if (node->num_visible_children == 0) - return; - - sort_needed = etta->priv->sort_info && e_table_sort_info_sorting_get_count (etta->priv->sort_info) > 0; - - for (i = 0, path = e_tree_model_node_get_first_child (etta->priv->source, node->path); path; - path = e_tree_model_node_get_next (etta->priv->source, path), i++); - - count = i; - if (count <= 1) - return; - - paths = g_new0 (ETreePath, count); - - for (i = 0, path = e_tree_model_node_get_first_child (etta->priv->source, node->path); path; - path = e_tree_model_node_get_next (etta->priv->source, path), i++) - paths[i] = path; - - if (count > 1 && sort_needed) - e_table_sorting_utils_tree_sort (etta->priv->source, etta->priv->sort_info, etta->priv->header, paths, count); - - prev = NULL; - for (i = 0; i < count; i++) { - curr = lookup_gnode (etta, paths[i]); - if (!curr) - continue; - - if (prev) - prev->next = curr; - else - gnode->children = curr; - - curr->prev = prev; - curr->next = NULL; - prev = curr; - if (recurse) - resort_node (etta, curr, recurse); - } - - g_free (paths); -} - -static gint -get_row (ETreeTableAdapter *etta, - ETreePath path) -{ - node_t *node = get_node (etta, path); - if (!node) - return -1; - - if (etta->priv->remap_needed) - remap_indices (etta); - - return node->index; -} - -static ETreePath -get_path (ETreeTableAdapter *etta, - gint row) -{ - if (row == -1 && etta->priv->n_map > 0) - row = etta->priv->n_map - 1; - else if (row < 0 || row >= etta->priv->n_map) - return NULL; - - return etta->priv->map_table[row]->path; -} - -static void -kill_gnode (GNode *node, - ETreeTableAdapter *etta) -{ - g_hash_table_remove (etta->priv->nodes, ((node_t *) node->data)->path); - - while (node->children) { - GNode *next = node->children->next; - kill_gnode (node->children, etta); - node->children = next; - } - - g_free (node->data); - if (node == etta->priv->root) - etta->priv->root = NULL; - g_node_destroy (node); -} - -static void -update_child_counts (GNode *gnode, - gint delta) -{ - while (gnode) { - node_t *node = (node_t *) gnode->data; - node->num_visible_children += delta; - gnode = gnode->parent; - } -} - -static gint -delete_children (ETreeTableAdapter *etta, - GNode *gnode) -{ - node_t *node = (node_t *) gnode->data; - gint to_remove = node ? node->num_visible_children : 0; - - if (to_remove == 0) - return 0; - - while (gnode->children) { - GNode *next = gnode->children->next; - kill_gnode (gnode->children, etta); - gnode->children = next; - } - - return to_remove; -} - -static void -delete_node (ETreeTableAdapter *etta, - ETreePath parent, - ETreePath path) -{ - gint to_remove = 1; - gint parent_row = get_row (etta, parent); - gint row = get_row (etta, path); - GNode *gnode = lookup_gnode (etta, path); - GNode *parent_gnode = lookup_gnode (etta, parent); - - e_table_model_pre_change (E_TABLE_MODEL (etta)); - - if (row == -1) { - e_table_model_no_change (E_TABLE_MODEL (etta)); - return; - } - - to_remove += delete_children (etta, gnode); - kill_gnode (gnode, etta); - - move_map_elements (etta, row, row + to_remove, etta->priv->n_map - row - to_remove); - resize_map (etta, etta->priv->n_map - to_remove); - - if (parent_gnode != NULL) { - node_t *parent_node = parent_gnode->data; - gboolean expandable = e_tree_model_node_is_expandable (etta->priv->source, parent); - - update_child_counts (parent_gnode, - to_remove); - if (parent_node->expandable != expandable) { - e_table_model_pre_change (E_TABLE_MODEL (etta)); - parent_node->expandable = expandable; - e_table_model_row_changed (E_TABLE_MODEL (etta), parent_row); - } - - resort_node (etta, parent_gnode, FALSE); - } - - e_table_model_rows_deleted (E_TABLE_MODEL (etta), row, to_remove); -} - -static GNode * -create_gnode (ETreeTableAdapter *etta, - ETreePath path) -{ - GNode *gnode; - node_t *node; - - node = g_new0 (node_t, 1); - node->path = path; - node->index = -1; - node->expanded = etta->priv->force_expanded_state == 0 ? e_tree_model_get_expanded_default (etta->priv->source) : etta->priv->force_expanded_state > 0; - node->expandable = e_tree_model_node_is_expandable (etta->priv->source, path); - node->expandable_set = 1; - node->num_visible_children = 0; - gnode = g_node_new (node); - g_hash_table_insert (etta->priv->nodes, path, gnode); - return gnode; -} - -static gint -insert_children (ETreeTableAdapter *etta, - GNode *gnode) -{ - ETreePath path, tmp; - gint count = 0; - gint pos = 0; - - path = ((node_t *) gnode->data)->path; - for (tmp = e_tree_model_node_get_first_child (etta->priv->source, path); - tmp; - tmp = e_tree_model_node_get_next (etta->priv->source, tmp), pos++) { - GNode *child = create_gnode (etta, tmp); - node_t *node = (node_t *) child->data; - if (node->expanded) - node->num_visible_children = insert_children (etta, child); - g_node_prepend (gnode, child); - count += node->num_visible_children + 1; - } - g_node_reverse_children (gnode); - return count; -} - -static void -generate_tree (ETreeTableAdapter *etta, - ETreePath path) -{ - GNode *gnode; - node_t *node; - gint size; - - e_table_model_pre_change (E_TABLE_MODEL (etta)); - - g_return_if_fail (e_tree_model_node_is_root (etta->priv->source, path)); - - if (etta->priv->root) - kill_gnode (etta->priv->root, etta); - resize_map (etta, 0); - - gnode = create_gnode (etta, path); - node = (node_t *) gnode->data; - node->expanded = TRUE; - node->num_visible_children = insert_children (etta, gnode); - if (etta->priv->sort_info && e_table_sort_info_sorting_get_count (etta->priv->sort_info) > 0) - resort_node (etta, gnode, TRUE); - - etta->priv->root = gnode; - size = etta->priv->root_visible ? node->num_visible_children + 1 : node->num_visible_children; - resize_map (etta, size); - fill_map (etta, 0, gnode); - e_table_model_changed (E_TABLE_MODEL (etta)); -} - -static void -insert_node (ETreeTableAdapter *etta, - ETreePath parent, - ETreePath path) -{ - GNode *gnode, *parent_gnode; - node_t *node, *parent_node; - gboolean expandable; - gint size, row; - - e_table_model_pre_change (E_TABLE_MODEL (etta)); - - if (get_node (etta, path)) { - e_table_model_no_change (E_TABLE_MODEL (etta)); - return; - } - - parent_gnode = lookup_gnode (etta, parent); - if (!parent_gnode) { - ETreePath grandparent = e_tree_model_node_get_parent (etta->priv->source, parent); - if (e_tree_model_node_is_root (etta->priv->source, parent)) - generate_tree (etta, parent); - else - insert_node (etta, grandparent, parent); - e_table_model_changed (E_TABLE_MODEL (etta)); - return; - } - - parent_node = (node_t *) parent_gnode->data; - - if (parent_gnode != etta->priv->root) { - expandable = e_tree_model_node_is_expandable (etta->priv->source, parent); - if (parent_node->expandable != expandable) { - e_table_model_pre_change (E_TABLE_MODEL (etta)); - parent_node->expandable = expandable; - parent_node->expandable_set = 1; - e_table_model_row_changed (E_TABLE_MODEL (etta), parent_node->index); - } - } - - if (!e_tree_table_adapter_node_is_expanded (etta, parent)) { - e_table_model_no_change (E_TABLE_MODEL (etta)); - return; - } - - gnode = create_gnode (etta, path); - node = (node_t *) gnode->data; - - if (node->expanded) - node->num_visible_children = insert_children (etta, gnode); - - g_node_append (parent_gnode, gnode); - update_child_counts (parent_gnode, node->num_visible_children + 1); - resort_node (etta, parent_gnode, FALSE); - resort_node (etta, gnode, TRUE); - - size = node->num_visible_children + 1; - resize_map (etta, etta->priv->n_map + size); - if (parent_gnode == etta->priv->root) - row = 0; - else { - gint new_size = parent_node->num_visible_children + 1; - gint old_size = new_size - size; - row = parent_node->index; - move_map_elements (etta, row + new_size, row + old_size, etta->priv->n_map - row - new_size); - } - fill_map (etta, row, parent_gnode); - e_table_model_rows_inserted (E_TABLE_MODEL (etta), get_row (etta, path), size); -} - -typedef struct { - GSList *paths; - gboolean expanded; -} check_expanded_closure; - -static gboolean -check_expanded (GNode *gnode, - gpointer data) -{ - check_expanded_closure *closure = (check_expanded_closure *) data; - node_t *node = (node_t *) gnode->data; - - if (node->expanded != closure->expanded) - closure->paths = g_slist_prepend (closure->paths, node->path); - - return FALSE; -} - -static void -update_node (ETreeTableAdapter *etta, - ETreePath path) -{ - check_expanded_closure closure; - ETreePath parent = e_tree_model_node_get_parent (etta->priv->source, path); - GNode *gnode = lookup_gnode (etta, path); - GSList *l; - - closure.expanded = e_tree_model_get_expanded_default (etta->priv->source); - closure.paths = NULL; - - if (gnode) - g_node_traverse (gnode, G_POST_ORDER, G_TRAVERSE_ALL, -1, check_expanded, &closure); - - if (e_tree_model_node_is_root (etta->priv->source, path)) - generate_tree (etta, path); - else { - delete_node (etta, parent, path); - insert_node (etta, parent, path); - } - - for (l = closure.paths; l; l = l->next) - if (lookup_gnode (etta, l->data)) - e_tree_table_adapter_node_set_expanded (etta, l->data, !closure.expanded); - - g_slist_free (closure.paths); -} - -static void -etta_finalize (GObject *object) -{ - ETreeTableAdapterPrivate *priv; - - priv = E_TREE_TABLE_ADAPTER_GET_PRIVATE (object); - - if (priv->resort_idle_id) { - g_source_remove (priv->resort_idle_id); - priv->resort_idle_id = 0; - } - - if (priv->root) { - kill_gnode (priv->root, E_TREE_TABLE_ADAPTER (object)); - priv->root = NULL; - } - - g_hash_table_destroy (priv->nodes); - - g_free (priv->map_table); - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (etta_parent_class)->finalize (object); -} - -static void -etta_dispose (GObject *object) -{ - ETreeTableAdapterPrivate *priv; - - priv = E_TREE_TABLE_ADAPTER_GET_PRIVATE (object); - - if (priv->sort_info) { - g_signal_handler_disconnect ( - priv->sort_info, priv->sort_info_changed_id); - g_object_unref (priv->sort_info); - priv->sort_info = NULL; - } - - if (priv->header) { - g_object_unref (priv->header); - priv->header = NULL; - } - - if (priv->source) { - g_signal_handler_disconnect ( - priv->source, priv->pre_change_id); - g_signal_handler_disconnect ( - priv->source, priv->no_change_id); - g_signal_handler_disconnect ( - priv->source, priv->rebuilt_id); - g_signal_handler_disconnect ( - priv->source, priv->node_changed_id); - g_signal_handler_disconnect ( - priv->source, priv->node_data_changed_id); - g_signal_handler_disconnect ( - priv->source, priv->node_col_changed_id); - g_signal_handler_disconnect ( - priv->source, priv->node_inserted_id); - g_signal_handler_disconnect ( - priv->source, priv->node_removed_id); - g_signal_handler_disconnect ( - priv->source, priv->node_request_collapse_id); - - g_object_unref (priv->source); - priv->source = NULL; - } - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (etta_parent_class)->dispose (object); -} - -static gint -etta_column_count (ETableModel *etm) -{ - ETreeTableAdapter *etta = (ETreeTableAdapter *) etm; - - return e_tree_model_column_count (etta->priv->source); -} - -static gboolean -etta_has_save_id (ETableModel *etm) -{ - ETreeTableAdapter *etta = (ETreeTableAdapter *) etm; - - return e_tree_model_has_save_id (etta->priv->source); -} - -static gchar * -etta_get_save_id (ETableModel *etm, - gint row) -{ - ETreeTableAdapter *etta = (ETreeTableAdapter *) etm; - - return e_tree_model_get_save_id (etta->priv->source, get_path (etta, row)); -} - -static gboolean -etta_has_change_pending (ETableModel *etm) -{ - ETreeTableAdapter *etta = (ETreeTableAdapter *) etm; - - return e_tree_model_has_change_pending (etta->priv->source); -} - -static gint -etta_row_count (ETableModel *etm) -{ - ETreeTableAdapter *etta = (ETreeTableAdapter *) etm; - - return etta->priv->n_map; -} - -static gpointer -etta_value_at (ETableModel *etm, - gint col, - gint row) -{ - ETreeTableAdapter *etta = (ETreeTableAdapter *) etm; - - switch (col) { - case -1: - if (row == -1) - return NULL; - return get_path (etta, row); - case -2: - return etta->priv->source; - case -3: - return etta; - default: - return e_tree_model_value_at (etta->priv->source, get_path (etta, row), col); - } -} - -static void -etta_set_value_at (ETableModel *etm, - gint col, - gint row, - gconstpointer val) -{ - ETreeTableAdapter *etta = (ETreeTableAdapter *) etm; - - e_tree_model_set_value_at (etta->priv->source, get_path (etta, row), col, val); -} - -static gboolean -etta_is_cell_editable (ETableModel *etm, - gint col, - gint row) -{ - ETreeTableAdapter *etta = (ETreeTableAdapter *) etm; - - return e_tree_model_node_is_editable (etta->priv->source, get_path (etta, row), col); -} - -static void -etta_append_row (ETableModel *etm, - ETableModel *source, - gint row) -{ -} - -static gpointer -etta_duplicate_value (ETableModel *etm, - gint col, - gconstpointer value) -{ - ETreeTableAdapter *etta = (ETreeTableAdapter *) etm; - - return e_tree_model_duplicate_value (etta->priv->source, col, value); -} - -static void -etta_free_value (ETableModel *etm, - gint col, - gpointer value) -{ - ETreeTableAdapter *etta = (ETreeTableAdapter *) etm; - - e_tree_model_free_value (etta->priv->source, col, value); -} - -static gpointer -etta_initialize_value (ETableModel *etm, - gint col) -{ - ETreeTableAdapter *etta = (ETreeTableAdapter *) etm; - - return e_tree_model_initialize_value (etta->priv->source, col); -} - -static gboolean -etta_value_is_empty (ETableModel *etm, - gint col, - gconstpointer value) -{ - ETreeTableAdapter *etta = (ETreeTableAdapter *) etm; - - return e_tree_model_value_is_empty (etta->priv->source, col, value); -} - -static gchar * -etta_value_to_string (ETableModel *etm, - gint col, - gconstpointer value) -{ - ETreeTableAdapter *etta = (ETreeTableAdapter *) etm; - - return e_tree_model_value_to_string (etta->priv->source, col, value); -} - -static void -etta_class_init (ETreeTableAdapterClass *class) -{ - GObjectClass *object_class; - ETableModelClass *table_model_class; - - g_type_class_add_private (class, sizeof (ETreeTableAdapterPrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->dispose = etta_dispose; - object_class->finalize = etta_finalize; - - table_model_class = E_TABLE_MODEL_CLASS (class); - table_model_class->column_count = etta_column_count; - table_model_class->row_count = etta_row_count; - table_model_class->append_row = etta_append_row; - - table_model_class->value_at = etta_value_at; - table_model_class->set_value_at = etta_set_value_at; - table_model_class->is_cell_editable = etta_is_cell_editable; - - table_model_class->has_save_id = etta_has_save_id; - table_model_class->get_save_id = etta_get_save_id; - - table_model_class->has_change_pending = etta_has_change_pending; - table_model_class->duplicate_value = etta_duplicate_value; - table_model_class->free_value = etta_free_value; - table_model_class->initialize_value = etta_initialize_value; - table_model_class->value_is_empty = etta_value_is_empty; - table_model_class->value_to_string = etta_value_to_string; - - class->sorting_changed = NULL; - - signals[SORTING_CHANGED] = g_signal_new ( - "sorting_changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeTableAdapterClass, sorting_changed), - NULL, NULL, - e_marshal_BOOLEAN__NONE, - G_TYPE_BOOLEAN, 0, - G_TYPE_NONE); -} - -static void -etta_init (ETreeTableAdapter *etta) -{ - etta->priv = E_TREE_TABLE_ADAPTER_GET_PRIVATE (etta); - - etta->priv->root_visible = TRUE; - etta->priv->remap_needed = TRUE; -} - -static void -etta_proxy_pre_change (ETreeModel *etm, - ETreeTableAdapter *etta) -{ - e_table_model_pre_change (E_TABLE_MODEL (etta)); -} - -static void -etta_proxy_no_change (ETreeModel *etm, - ETreeTableAdapter *etta) -{ - e_table_model_no_change (E_TABLE_MODEL (etta)); -} - -static void -etta_proxy_rebuilt (ETreeModel *etm, - ETreeTableAdapter *etta) -{ - if (!etta->priv->root) - return; - kill_gnode (etta->priv->root, etta); - etta->priv->root = NULL; - g_hash_table_destroy (etta->priv->nodes); - etta->priv->nodes = g_hash_table_new (NULL, NULL); -} - -static gboolean -resort_model (ETreeTableAdapter *etta) -{ - etta_sort_info_changed (NULL, etta); - etta->priv->resort_idle_id = 0; - return FALSE; -} - -static void -etta_proxy_node_changed (ETreeModel *etm, - ETreePath path, - ETreeTableAdapter *etta) -{ - update_node (etta, path); - e_table_model_changed (E_TABLE_MODEL (etta)); - - /* FIXME: Really it shouldnt be required. But a lot of thread - * which were supposed to be present in the list is way below - */ - if (!etta->priv->resort_idle_id) - etta->priv->resort_idle_id = g_idle_add ((GSourceFunc) resort_model, etta); -} - -static void -etta_proxy_node_data_changed (ETreeModel *etm, - ETreePath path, - ETreeTableAdapter *etta) -{ - gint row = get_row (etta, path); - - if (row == -1) { - e_table_model_no_change (E_TABLE_MODEL (etta)); - return; - } - - e_table_model_row_changed (E_TABLE_MODEL (etta), row); -} - -static void -etta_proxy_node_col_changed (ETreeModel *etm, - ETreePath path, - gint col, - ETreeTableAdapter *etta) -{ - gint row = get_row (etta, path); - - if (row == -1) { - e_table_model_no_change (E_TABLE_MODEL (etta)); - return; - } - - e_table_model_cell_changed (E_TABLE_MODEL (etta), col, row); -} - -static void -etta_proxy_node_inserted (ETreeModel *etm, - ETreePath parent, - ETreePath child, - ETreeTableAdapter *etta) -{ - if (e_tree_model_node_is_root (etm, child)) - generate_tree (etta, child); - else - insert_node (etta, parent, child); - - e_table_model_changed (E_TABLE_MODEL (etta)); -} - -static void -etta_proxy_node_removed (ETreeModel *etm, - ETreePath parent, - ETreePath child, - gint old_position, - ETreeTableAdapter *etta) -{ - delete_node (etta, parent, child); - e_table_model_changed (E_TABLE_MODEL (etta)); -} - -static void -etta_proxy_node_request_collapse (ETreeModel *etm, - ETreePath node, - ETreeTableAdapter *etta) -{ - e_tree_table_adapter_node_set_expanded (etta, node, FALSE); -} - -static void -etta_sort_info_changed (ETableSortInfo *sort_info, - ETreeTableAdapter *etta) -{ - if (!etta->priv->root) - return; - - /* the function is called also internally, with sort_info = NULL, - * thus skip those in signal emit */ - if (sort_info) { - gboolean handled = FALSE; - - g_signal_emit (etta, signals[SORTING_CHANGED], 0, &handled); - - if (handled) - return; - } - - e_table_model_pre_change (E_TABLE_MODEL (etta)); - resort_node (etta, etta->priv->root, TRUE); - fill_map (etta, 0, etta->priv->root); - e_table_model_changed (E_TABLE_MODEL (etta)); -} - -ETableModel * -e_tree_table_adapter_construct (ETreeTableAdapter *etta, - ETreeModel *source, - ETableSortInfo *sort_info, - ETableHeader *header) -{ - ETreePath root; - - etta->priv->source = source; - g_object_ref (source); - - etta->priv->sort_info = sort_info; - if (sort_info) { - g_object_ref (sort_info); - etta->priv->sort_info_changed_id = g_signal_connect ( - sort_info, "sort_info_changed", - G_CALLBACK (etta_sort_info_changed), etta); - } - - etta->priv->header = header; - if (header) - g_object_ref (header); - - etta->priv->nodes = g_hash_table_new (NULL, NULL); - - root = e_tree_model_get_root (source); - - if (root) - generate_tree (etta, root); - - etta->priv->pre_change_id = g_signal_connect ( - source, "pre_change", - G_CALLBACK (etta_proxy_pre_change), etta); - etta->priv->no_change_id = g_signal_connect ( - source, "no_change", - G_CALLBACK (etta_proxy_no_change), etta); - etta->priv->rebuilt_id = g_signal_connect ( - source, "rebuilt", - G_CALLBACK (etta_proxy_rebuilt), etta); - etta->priv->node_changed_id = g_signal_connect ( - source, "node_changed", - G_CALLBACK (etta_proxy_node_changed), etta); - etta->priv->node_data_changed_id = g_signal_connect ( - source, "node_data_changed", - G_CALLBACK (etta_proxy_node_data_changed), etta); - etta->priv->node_col_changed_id = g_signal_connect ( - source, "node_col_changed", - G_CALLBACK (etta_proxy_node_col_changed), etta); - etta->priv->node_inserted_id = g_signal_connect ( - source, "node_inserted", - G_CALLBACK (etta_proxy_node_inserted), etta); - etta->priv->node_removed_id = g_signal_connect ( - source, "node_removed", - G_CALLBACK (etta_proxy_node_removed), etta); - etta->priv->node_request_collapse_id = g_signal_connect ( - source, "node_request_collapse", - G_CALLBACK (etta_proxy_node_request_collapse), etta); - - return E_TABLE_MODEL (etta); -} - -ETableModel * -e_tree_table_adapter_new (ETreeModel *source, - ETableSortInfo *sort_info, - ETableHeader *header) -{ - ETreeTableAdapter *etta = g_object_new (E_TYPE_TREE_TABLE_ADAPTER, NULL); - - e_tree_table_adapter_construct (etta, source, sort_info, header); - - return (ETableModel *) etta; -} - -typedef struct { - xmlNode *root; - gboolean expanded_default; - ETreeModel *model; -} TreeAndRoot; - -static void -save_expanded_state_func (gpointer keyp, - gpointer value, - gpointer data) -{ - ETreePath path = keyp; - node_t *node = ((GNode *) value)->data; - TreeAndRoot *tar = data; - xmlNode *xmlnode; - - if (node->expanded != tar->expanded_default) { - gchar *save_id = e_tree_model_get_save_id (tar->model, path); - xmlnode = xmlNewChild (tar->root, NULL, (const guchar *)"node", NULL); - e_xml_set_string_prop_by_name (xmlnode, (const guchar *)"id", save_id); - g_free (save_id); - } -} - -xmlDoc * -e_tree_table_adapter_save_expanded_state_xml (ETreeTableAdapter *etta) -{ - TreeAndRoot tar; - xmlDocPtr doc; - xmlNode *root; - - g_return_val_if_fail (etta != NULL, NULL); - - doc = xmlNewDoc ((const guchar *)"1.0"); - root = xmlNewDocNode (doc, NULL, (const guchar *)"expanded_state", NULL); - xmlDocSetRootElement (doc, root); - - tar.model = etta->priv->source; - tar.root = root; - tar.expanded_default = e_tree_model_get_expanded_default (etta->priv->source); - - e_xml_set_integer_prop_by_name (root, (const guchar *)"vers", 2); - e_xml_set_bool_prop_by_name (root, (const guchar *)"default", tar.expanded_default); - - g_hash_table_foreach (etta->priv->nodes, save_expanded_state_func, &tar); - - return doc; -} - -void -e_tree_table_adapter_save_expanded_state (ETreeTableAdapter *etta, - const gchar *filename) -{ - xmlDoc *doc; - - g_return_if_fail (etta != NULL); - - doc = e_tree_table_adapter_save_expanded_state_xml (etta); - if (doc) { - e_xml_save_file (filename, doc); - xmlFreeDoc (doc); - } -} - -static xmlDoc * -open_file (ETreeTableAdapter *etta, - const gchar *filename) -{ - xmlDoc *doc; - xmlNode *root; - gint vers; - gboolean model_default, saved_default; - - if (!g_file_test (filename, G_FILE_TEST_EXISTS)) - return NULL; - -#ifdef G_OS_WIN32 - { - gchar *locale_filename = g_win32_locale_filename_from_utf8 (filename); - doc = xmlParseFile (locale_filename); - g_free (locale_filename); - } -#else - doc = xmlParseFile (filename); -#endif - - if (!doc) - return NULL; - - root = xmlDocGetRootElement (doc); - if (root == NULL || strcmp ((gchar *) root->name, "expanded_state")) { - xmlFreeDoc (doc); - return NULL; - } - - vers = e_xml_get_integer_prop_by_name_with_default (root, (const guchar *)"vers", 0); - if (vers > 2) { - xmlFreeDoc (doc); - return NULL; - } - model_default = e_tree_model_get_expanded_default (etta->priv->source); - saved_default = e_xml_get_bool_prop_by_name_with_default (root, (const guchar *)"default", !model_default); - if (saved_default != model_default) { - xmlFreeDoc (doc); - return NULL; - } - - return doc; -} - -/* state: <0 ... collapse; 0 ... use default; >0 ... expand */ -void -e_tree_table_adapter_force_expanded_state (ETreeTableAdapter *etta, - gint state) -{ - g_return_if_fail (etta != NULL); - - etta->priv->force_expanded_state = state; -} - -void -e_tree_table_adapter_load_expanded_state_xml (ETreeTableAdapter *etta, - xmlDoc *doc) -{ - xmlNode *root, *child; - gboolean model_default; - gboolean file_default = FALSE; - - g_return_if_fail (etta != NULL); - g_return_if_fail (doc != NULL); - - root = xmlDocGetRootElement (doc); - - e_table_model_pre_change (E_TABLE_MODEL (etta)); - - model_default = e_tree_model_get_expanded_default (etta->priv->source); - - if (!strcmp ((gchar *) root->name, "expanded_state")) { - gchar *state; - - state = e_xml_get_string_prop_by_name_with_default (root, (const guchar *)"default", ""); - - if (state[0] == 't') - file_default = TRUE; - else - file_default = FALSE; /* Even unspecified we'll consider as false */ - - g_free (state); - } - - /* Incase the default is changed, lets forget the changes and stick to default */ - - if (file_default != model_default) { - xmlFreeDoc (doc); - return; - } - - for (child = root->xmlChildrenNode; child; child = child->next) { - gchar *id; - ETreePath path; - - if (strcmp ((gchar *) child->name, "node")) { - d (g_warning ("unknown node '%s' in %s", child->name, filename)); - continue; - } - - id = e_xml_get_string_prop_by_name_with_default (child, (const guchar *)"id", ""); - - if (!strcmp (id, "")) { - g_free (id); - continue; - } - - path = e_tree_model_get_node_by_id (etta->priv->source, id); - if (path) - e_tree_table_adapter_node_set_expanded (etta, path, !model_default); - - g_free (id); - } - - e_table_model_changed (E_TABLE_MODEL (etta)); -} - -void -e_tree_table_adapter_load_expanded_state (ETreeTableAdapter *etta, - const gchar *filename) -{ - xmlDoc *doc; - - g_return_if_fail (etta != NULL); - - doc = open_file (etta, filename); - if (!doc) - return; - - e_tree_table_adapter_load_expanded_state_xml (etta, doc); - - xmlFreeDoc (doc); -} - -void -e_tree_table_adapter_root_node_set_visible (ETreeTableAdapter *etta, - gboolean visible) -{ - gint size; - - g_return_if_fail (etta != NULL); - - if (etta->priv->root_visible == visible) - return; - - e_table_model_pre_change (E_TABLE_MODEL (etta)); - - etta->priv->root_visible = visible; - if (!visible) { - ETreePath root = e_tree_model_get_root (etta->priv->source); - if (root) - e_tree_table_adapter_node_set_expanded (etta, root, TRUE); - } - size = (visible ? 1 : 0) + (etta->priv->root ? ((node_t *) etta->priv->root->data)->num_visible_children : 0); - resize_map (etta, size); - if (etta->priv->root) - fill_map (etta, 0, etta->priv->root); - e_table_model_changed (E_TABLE_MODEL (etta)); -} - -void -e_tree_table_adapter_node_set_expanded (ETreeTableAdapter *etta, - ETreePath path, - gboolean expanded) -{ - GNode *gnode = lookup_gnode (etta, path); - node_t *node; - gint row; - - if (!expanded && (!gnode || (e_tree_model_node_is_root (etta->priv->source, path) && !etta->priv->root_visible))) - return; - - if (!gnode && expanded) { - ETreePath parent = e_tree_model_node_get_parent (etta->priv->source, path); - g_return_if_fail (parent != NULL); - e_tree_table_adapter_node_set_expanded (etta, parent, expanded); - gnode = lookup_gnode (etta, path); - } - g_return_if_fail (gnode != NULL); - - node = (node_t *) gnode->data; - - if (expanded == node->expanded) - return; - - node->expanded = expanded; - - row = get_row (etta, path); - if (row == -1) - return; - - e_table_model_pre_change (E_TABLE_MODEL (etta)); - e_table_model_pre_change (E_TABLE_MODEL (etta)); - e_table_model_row_changed (E_TABLE_MODEL (etta), row); - - if (expanded) { - gint num_children = insert_children (etta, gnode); - update_child_counts (gnode, num_children); - if (etta->priv->sort_info && e_table_sort_info_sorting_get_count (etta->priv->sort_info) > 0) - resort_node (etta, gnode, TRUE); - resize_map (etta, etta->priv->n_map + num_children); - move_map_elements (etta, row + 1 + num_children, row + 1, etta->priv->n_map - row - 1 - num_children); - fill_map (etta, row, gnode); - if (num_children != 0) { - e_table_model_rows_inserted (E_TABLE_MODEL (etta), row + 1, num_children); - } else - e_table_model_no_change (E_TABLE_MODEL (etta)); - } else { - gint num_children = delete_children (etta, gnode); - if (num_children == 0) { - e_table_model_no_change (E_TABLE_MODEL (etta)); - return; - } - move_map_elements (etta, row + 1, row + 1 + num_children, etta->priv->n_map - row - 1 - num_children); - update_child_counts (gnode, - num_children); - resize_map (etta, etta->priv->n_map - num_children); - e_table_model_rows_deleted (E_TABLE_MODEL (etta), row + 1, num_children); - } -} - -void -e_tree_table_adapter_node_set_expanded_recurse (ETreeTableAdapter *etta, - ETreePath path, - gboolean expanded) -{ - ETreePath children; - - e_tree_table_adapter_node_set_expanded (etta, path, expanded); - - for (children = e_tree_model_node_get_first_child (etta->priv->source, path); - children; - children = e_tree_model_node_get_next (etta->priv->source, children)) { - e_tree_table_adapter_node_set_expanded_recurse (etta, children, expanded); - } -} - -ETreePath -e_tree_table_adapter_node_at_row (ETreeTableAdapter *etta, - gint row) -{ - return get_path (etta, row); -} - -gint -e_tree_table_adapter_row_of_node (ETreeTableAdapter *etta, - ETreePath path) -{ - return get_row (etta, path); -} - -gboolean -e_tree_table_adapter_root_node_is_visible (ETreeTableAdapter *etta) -{ - return etta->priv->root_visible; -} - -void -e_tree_table_adapter_show_node (ETreeTableAdapter *etta, - ETreePath path) -{ - ETreePath parent; - - parent = e_tree_model_node_get_parent (etta->priv->source, path); - - while (parent) { - e_tree_table_adapter_node_set_expanded (etta, parent, TRUE); - parent = e_tree_model_node_get_parent (etta->priv->source, parent); - } -} - -gboolean -e_tree_table_adapter_node_is_expanded (ETreeTableAdapter *etta, - ETreePath path) -{ - node_t *node = get_node (etta, path); - if (!e_tree_model_node_is_expandable (etta->priv->source, path) || !node) - return FALSE; - - return node->expanded; -} - -void -e_tree_table_adapter_set_sort_info (ETreeTableAdapter *etta, - ETableSortInfo *sort_info) -{ - if (etta->priv->sort_info) { - g_signal_handler_disconnect ( - etta->priv->sort_info, - etta->priv->sort_info_changed_id); - g_object_unref (etta->priv->sort_info); - } - - etta->priv->sort_info = sort_info; - if (sort_info) { - g_object_ref (sort_info); - etta->priv->sort_info_changed_id = g_signal_connect ( - sort_info, "sort_info_changed", - G_CALLBACK (etta_sort_info_changed), etta); - } - - if (!etta->priv->root) - return; - - e_table_model_pre_change (E_TABLE_MODEL (etta)); - resort_node (etta, etta->priv->root, TRUE); - fill_map (etta, 0, etta->priv->root); - e_table_model_changed (E_TABLE_MODEL (etta)); -} - -ETableSortInfo * -e_tree_table_adapter_get_sort_info (ETreeTableAdapter *etta) -{ - g_return_val_if_fail (etta != NULL, NULL); - - return etta->priv->sort_info; -} - -ETableHeader * -e_tree_table_adapter_get_header (ETreeTableAdapter *etta) -{ - g_return_val_if_fail (etta != NULL, NULL); - - return etta->priv->header; -} - -ETreePath -e_tree_table_adapter_node_get_next (ETreeTableAdapter *etta, - ETreePath path) -{ - GNode *node = lookup_gnode (etta, path); - - if (node && node->next) - return ((node_t *) node->next->data)->path; - - return NULL; -} diff --git a/widgets/table/e-tree-table-adapter.h b/widgets/table/e-tree-table-adapter.h deleted file mode 100644 index ea7b86b21d..0000000000 --- a/widgets/table/e-tree-table-adapter.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * Chris Toshok <toshok@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TREE_TABLE_ADAPTER_H_ -#define _E_TREE_TABLE_ADAPTER_H_ - -#include <table/e-table-model.h> -#include <table/e-tree-model.h> -#include <table/e-table-sort-info.h> -#include <table/e-table-header.h> -#include <libxml/tree.h> - -/* Standard GObject macros */ -#define E_TYPE_TREE_TABLE_ADAPTER \ - (e_tree_table_adapter_get_type ()) -#define E_TREE_TABLE_ADAPTER(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TREE_TABLE_ADAPTER, ETreeTableAdapter)) -#define E_TREE_TABLE_ADAPTER_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TREE_TABLE_ADAPTER, ETreeTableAdapterClass)) -#define E_IS_TREE_TABLE_ADAPTER(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TREE_TABLE_ADAPTER)) -#define E_IS_TREE_TABLE_ADAPTER_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TREE_TABLE_ADAPTER)) -#define E_TREE_TABLE_ADAPTER_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TREE_TABLE_ADAPTER, ETreeTableAdapterClass)) - -G_BEGIN_DECLS - -typedef struct _ETreeTableAdapter ETreeTableAdapter; -typedef struct _ETreeTableAdapterClass ETreeTableAdapterClass; -typedef struct _ETreeTableAdapterPrivate ETreeTableAdapterPrivate; - -struct _ETreeTableAdapter { - ETableModel parent; - ETreeTableAdapterPrivate *priv; -}; - -struct _ETreeTableAdapterClass { - ETableModelClass parent_class; - - /* Signals */ - gboolean (*sorting_changed) (ETreeTableAdapter *etta); -}; - -GType e_tree_table_adapter_get_type (void) G_GNUC_CONST; -ETableModel * e_tree_table_adapter_new (ETreeModel *source, - ETableSortInfo *sort_info, - ETableHeader *header); -ETableModel * e_tree_table_adapter_construct (ETreeTableAdapter *ets, - ETreeModel *source, - ETableSortInfo *sort_info, - ETableHeader *header); - -ETreePath e_tree_table_adapter_node_get_next - (ETreeTableAdapter *etta, - ETreePath path); -gboolean e_tree_table_adapter_node_is_expanded - (ETreeTableAdapter *etta, - ETreePath path); -void e_tree_table_adapter_node_set_expanded - (ETreeTableAdapter *etta, - ETreePath path, - gboolean expanded); -void e_tree_table_adapter_node_set_expanded_recurse - (ETreeTableAdapter *etta, - ETreePath path, - gboolean expanded); -void e_tree_table_adapter_force_expanded_state - (ETreeTableAdapter *etta, - gint state); -void e_tree_table_adapter_root_node_set_visible - (ETreeTableAdapter *etta, - gboolean visible); -ETreePath e_tree_table_adapter_node_at_row - (ETreeTableAdapter *etta, - gint row); -gint e_tree_table_adapter_row_of_node - (ETreeTableAdapter *etta, - ETreePath path); -gboolean e_tree_table_adapter_root_node_is_visible - (ETreeTableAdapter *etta); - -void e_tree_table_adapter_show_node (ETreeTableAdapter *etta, - ETreePath path); - -void e_tree_table_adapter_save_expanded_state - (ETreeTableAdapter *etta, - const gchar *filename); -void e_tree_table_adapter_load_expanded_state - (ETreeTableAdapter *etta, - const gchar *filename); - -xmlDoc * e_tree_table_adapter_save_expanded_state_xml - (ETreeTableAdapter *etta); -void e_tree_table_adapter_load_expanded_state_xml - (ETreeTableAdapter *etta, - xmlDoc *doc); - -void e_tree_table_adapter_set_sort_info - (ETreeTableAdapter *etta, - ETableSortInfo *sort_info); -ETableSortInfo *e_tree_table_adapter_get_sort_info - (ETreeTableAdapter *etta); -ETableHeader * e_tree_table_adapter_get_header (ETreeTableAdapter *etta); - -G_END_DECLS - -#endif /* _E_TREE_TABLE_ADAPTER_H_ */ diff --git a/widgets/table/e-tree.c b/widgets/table/e-tree.c deleted file mode 100644 index 78eef72746..0000000000 --- a/widgets/table/e-tree.c +++ /dev/null @@ -1,3956 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> -#include <libgnomecanvas/libgnomecanvas.h> - -#include "gal-a11y-e-tree.h" -#include <glib/gi18n.h> -#include "e-util/e-util.h" -#include "misc/e-canvas.h" -#include "misc/e-canvas-utils.h" -#include "misc/e-canvas-background.h" -#include "text/e-text.h" - -#include "e-table-column-specification.h" -#include "e-table-header-item.h" -#include "e-table-header.h" -#include "e-table-item.h" -#include "e-table-sort-info.h" -#include "e-table-utils.h" -#ifdef E_TREE_USE_TREE_SELECTION -#include "e-tree-selection-model.h" -#else -#include "e-table-selection-model.h" -#endif -#include "e-tree.h" -#include "e-tree-table-adapter.h" - -#define COLUMN_HEADER_HEIGHT 16 - -#define d(x) - -#define E_TREE_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), E_TYPE_TREE, ETreePrivate)) - -enum { - CURSOR_CHANGE, - CURSOR_ACTIVATED, - SELECTION_CHANGE, - DOUBLE_CLICK, - RIGHT_CLICK, - CLICK, - KEY_PRESS, - START_DRAG, - STATE_CHANGE, - WHITE_SPACE_EVENT, - - CUT_CLIPBOARD, - COPY_CLIPBOARD, - PASTE_CLIPBOARD, - SELECT_ALL, - - TREE_DRAG_BEGIN, - TREE_DRAG_END, - TREE_DRAG_DATA_GET, - TREE_DRAG_DATA_DELETE, - - TREE_DRAG_LEAVE, - TREE_DRAG_MOTION, - TREE_DRAG_DROP, - TREE_DRAG_DATA_RECEIVED, - - LAST_SIGNAL -}; - -enum { - PROP_0, - PROP_LENGTH_THRESHOLD, - PROP_HORIZONTAL_DRAW_GRID, - PROP_VERTICAL_DRAW_GRID, - PROP_DRAW_FOCUS, - PROP_ETTA, - PROP_UNIFORM_ROW_HEIGHT, - PROP_ALWAYS_SEARCH, - PROP_HADJUSTMENT, - PROP_VADJUSTMENT, - PROP_HSCROLL_POLICY, - PROP_VSCROLL_POLICY -}; - -enum { - ET_SCROLL_UP = 1 << 0, - ET_SCROLL_DOWN = 1 << 1, - ET_SCROLL_LEFT = 1 << 2, - ET_SCROLL_RIGHT = 1 << 3 -}; - -struct _ETreePrivate { - ETreeModel *model; - ETreeTableAdapter *etta; - - ETableHeader *full_header, *header; - - guint structure_change_id, expansion_change_id; - - ETableSortInfo *sort_info; - ESorter *sorter; - - guint sort_info_change_id, group_info_change_id; - - ESelectionModel *selection; - ETableSpecification *spec; - - ETableSearch *search; - - ETableCol *current_search_col; - - guint search_search_id; - guint search_accept_id; - - gint reflow_idle_id; - gint scroll_idle_id; - gint hover_idle_id; - - gboolean show_cursor_after_reflow; - - gint table_model_change_id; - gint table_row_change_id; - gint table_cell_change_id; - gint table_rows_delete_id; - - GnomeCanvasItem *info_text; - guint info_text_resize_id; - - GnomeCanvas *header_canvas, *table_canvas; - - GnomeCanvasItem *header_item, *root; - - GnomeCanvasItem *white_item; - GnomeCanvasItem *item; - - gint length_threshold; - - /* - * Configuration settings - */ - guint alternating_row_colors : 1; - guint horizontal_draw_grid : 1; - guint vertical_draw_grid : 1; - guint draw_focus : 1; - guint row_selection_active : 1; - - guint horizontal_scrolling : 1; - - guint scroll_direction : 4; - - guint do_drag : 1; - - guint uniform_row_height : 1; - - guint search_col_set : 1; - guint always_search : 1; - - ECursorMode cursor_mode; - - gint drop_row; - ETreePath drop_path; - gint drop_col; - - GnomeCanvasItem *drop_highlight; - gint last_drop_x; - gint last_drop_y; - gint last_drop_time; - GdkDragContext *last_drop_context; - - gint hover_x; - gint hover_y; - - gint drag_row; - ETreePath drag_path; - gint drag_col; - ETreeDragSourceSite *site; - - GList *expanded_list; - - gboolean state_changed; - guint state_change_freeze; - - gboolean is_dragging; -}; - -static guint et_signals[LAST_SIGNAL] = { 0, }; - -static void et_grab_focus (GtkWidget *widget); - -static void et_drag_begin (GtkWidget *widget, - GdkDragContext *context, - ETree *et); -static void et_drag_end (GtkWidget *widget, - GdkDragContext *context, - ETree *et); -static void et_drag_data_get (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - ETree *et); -static void et_drag_data_delete (GtkWidget *widget, - GdkDragContext *context, - ETree *et); - -static void et_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time, - ETree *et); -static gboolean et_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETree *et); -static gboolean et_drag_drop (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETree *et); -static void et_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time, - ETree *et); - -static void scroll_off (ETree *et); -static void scroll_on (ETree *et, guint scroll_direction); -static void hover_off (ETree *et); -static void hover_on (ETree *et, gint x, gint y); -static void context_destroyed (gpointer data, GObject *ctx); - -G_DEFINE_TYPE_WITH_CODE (ETree, e_tree, GTK_TYPE_TABLE, - G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL)) - -static void -et_disconnect_from_etta (ETree *et) -{ - if (et->priv->table_model_change_id != 0) - g_signal_handler_disconnect ( - et->priv->etta, - et->priv->table_model_change_id); - if (et->priv->table_row_change_id != 0) - g_signal_handler_disconnect ( - et->priv->etta, - et->priv->table_row_change_id); - if (et->priv->table_cell_change_id != 0) - g_signal_handler_disconnect ( - et->priv->etta, - et->priv->table_cell_change_id); - if (et->priv->table_rows_delete_id != 0) - g_signal_handler_disconnect ( - et->priv->etta, - et->priv->table_rows_delete_id); - - et->priv->table_model_change_id = 0; - et->priv->table_row_change_id = 0; - et->priv->table_cell_change_id = 0; - et->priv->table_rows_delete_id = 0; -} - -static void -clear_current_search_col (ETree *et) -{ - et->priv->search_col_set = FALSE; -} - -static ETableCol * -current_search_col (ETree *et) -{ - if (!et->priv->search_col_set) { - et->priv->current_search_col = - e_table_util_calculate_current_search_col ( - et->priv->header, - et->priv->full_header, - et->priv->sort_info, - et->priv->always_search); - et->priv->search_col_set = TRUE; - } - - return et->priv->current_search_col; -} - -static void -e_tree_state_change (ETree *et) -{ - if (et->priv->state_change_freeze) - et->priv->state_changed = TRUE; - else - g_signal_emit (et, et_signals[STATE_CHANGE], 0); -} - -static void -change_trigger (GObject *object, - ETree *et) -{ - e_tree_state_change (et); -} - -static void -search_col_change_trigger (GObject *object, - ETree *et) -{ - clear_current_search_col (et); - e_tree_state_change (et); -} - -static void -disconnect_header (ETree *e_tree) -{ - if (e_tree->priv->header == NULL) - return; - - if (e_tree->priv->structure_change_id) - g_signal_handler_disconnect ( - e_tree->priv->header, - e_tree->priv->structure_change_id); - if (e_tree->priv->expansion_change_id) - g_signal_handler_disconnect ( - e_tree->priv->header, - e_tree->priv->expansion_change_id); - if (e_tree->priv->sort_info) { - if (e_tree->priv->sort_info_change_id) - g_signal_handler_disconnect ( - e_tree->priv->sort_info, - e_tree->priv->sort_info_change_id); - if (e_tree->priv->group_info_change_id) - g_signal_handler_disconnect ( - e_tree->priv->sort_info, - e_tree->priv->group_info_change_id); - - g_object_unref (e_tree->priv->sort_info); - } - g_object_unref (e_tree->priv->header); - e_tree->priv->header = NULL; - e_tree->priv->sort_info = NULL; -} - -static void -connect_header (ETree *e_tree, - ETableState *state) -{ - GValue *val = g_new0 (GValue, 1); - - if (e_tree->priv->header != NULL) - disconnect_header (e_tree); - - e_tree->priv->header = e_table_state_to_header ( - GTK_WIDGET (e_tree), e_tree->priv->full_header, state); - - e_tree->priv->structure_change_id = g_signal_connect ( - e_tree->priv->header, "structure_change", - G_CALLBACK (search_col_change_trigger), e_tree); - - e_tree->priv->expansion_change_id = g_signal_connect ( - e_tree->priv->header, "expansion_change", - G_CALLBACK (change_trigger), e_tree); - - if (state->sort_info) { - e_tree->priv->sort_info = e_table_sort_info_duplicate (state->sort_info); - e_table_sort_info_set_can_group (e_tree->priv->sort_info, FALSE); - e_tree->priv->sort_info_change_id = g_signal_connect ( - e_tree->priv->sort_info, "sort_info_changed", - G_CALLBACK (search_col_change_trigger), e_tree); - - e_tree->priv->group_info_change_id = g_signal_connect ( - e_tree->priv->sort_info, "group_info_changed", - G_CALLBACK (search_col_change_trigger), e_tree); - } else - e_tree->priv->sort_info = NULL; - - g_value_init (val, G_TYPE_OBJECT); - g_value_set_object (val, e_tree->priv->sort_info); - g_object_set_property (G_OBJECT (e_tree->priv->header), "sort_info", val); - g_free (val); -} - -static void -et_dispose (GObject *object) -{ - ETreePrivate *priv; - - priv = E_TREE_GET_PRIVATE (object); - - if (priv->search != NULL) { - g_signal_handler_disconnect ( - priv->search, priv->search_search_id); - g_signal_handler_disconnect ( - priv->search, priv->search_accept_id); - g_object_unref (priv->search); - priv->search = NULL; - } - - if (priv->reflow_idle_id > 0) { - g_source_remove (priv->reflow_idle_id); - priv->reflow_idle_id = 0; - } - - scroll_off (E_TREE (object)); - hover_off (E_TREE (object)); - g_list_foreach ( - priv->expanded_list, - (GFunc) g_free, NULL); - g_list_free (priv->expanded_list); - priv->expanded_list = NULL; - - et_disconnect_from_etta (E_TREE (object)); - - if (priv->etta != NULL) { - g_object_unref (priv->etta); - priv->etta = NULL; - } - - if (priv->model != NULL) { - g_object_unref (priv->model); - priv->model = NULL; - } - - if (priv->full_header != NULL) { - g_object_unref (priv->full_header); - priv->full_header = NULL; - } - - disconnect_header (E_TREE (object)); - - if (priv->selection != NULL) { - g_object_unref (priv->selection); - priv->selection = NULL; - } - - if (priv->spec != NULL) { - g_object_unref (priv->spec); - priv->spec = NULL; - } - - if (priv->sorter != NULL) { - g_object_unref (priv->sorter); - priv->sorter = NULL; - } - - if (priv->header_canvas != NULL) { - gtk_widget_destroy (GTK_WIDGET (priv->header_canvas)); - priv->header_canvas = NULL; - } - - if (priv->site) - e_tree_drag_source_unset (E_TREE (object)); - - if (priv->last_drop_context != NULL) { - g_object_weak_unref ( - G_OBJECT (priv->last_drop_context), - context_destroyed, object); - priv->last_drop_context = NULL; - } - - if (priv->info_text != NULL) { - g_object_run_dispose (G_OBJECT (priv->info_text)); - priv->info_text = NULL; - } - priv->info_text_resize_id = 0; - - if (priv->table_canvas != NULL) { - gtk_widget_destroy (GTK_WIDGET (priv->table_canvas)); - priv->table_canvas = NULL; - } - - /* do not unref it, it was owned by priv->table_canvas */ - priv->item = NULL; - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (e_tree_parent_class)->dispose (object); -} - -static void -et_unrealize (GtkWidget *widget) -{ - scroll_off (E_TREE (widget)); - hover_off (E_TREE (widget)); - - if (GTK_WIDGET_CLASS (e_tree_parent_class)->unrealize) - GTK_WIDGET_CLASS (e_tree_parent_class)->unrealize (widget); -} - -typedef struct { - ETree *et; - gchar *string; -} SearchSearchStruct; - -static gboolean -search_search_callback (ETreeModel *model, - ETreePath path, - gpointer data) -{ - SearchSearchStruct *cb_data = data; - gconstpointer value; - ETableCol *col = current_search_col (cb_data->et); - - value = e_tree_model_value_at ( - model, path, cb_data->et->priv->current_search_col->col_idx); - - return col->search (value, cb_data->string); -} - -static gboolean -et_search_search (ETableSearch *search, - gchar *string, - ETableSearchFlags flags, - ETree *et) -{ - ETreePath cursor; - ETreePath found; - SearchSearchStruct cb_data; - ETableCol *col = current_search_col (et); - - if (col == NULL) - return FALSE; - - cb_data.et = et; - cb_data.string = string; - - cursor = e_tree_get_cursor (et); - - if (cursor && (flags & E_TABLE_SEARCH_FLAGS_CHECK_CURSOR_FIRST)) { - gconstpointer value; - - value = e_tree_model_value_at (et->priv->model, cursor, col->col_idx); - - if (col->search (value, string)) { - return TRUE; - } - } - - found = e_tree_model_node_find ( - et->priv->model, cursor, NULL, - E_TREE_FIND_NEXT_FORWARD, - search_search_callback, &cb_data); - if (found == NULL) - found = e_tree_model_node_find ( - et->priv->model, NULL, cursor, - E_TREE_FIND_NEXT_FORWARD, - search_search_callback, &cb_data); - - if (found && found != cursor) { - gint model_row; - - e_tree_table_adapter_show_node (et->priv->etta, found); - model_row = e_tree_table_adapter_row_of_node (et->priv->etta, found); - - e_selection_model_select_as_key_press ( - E_SELECTION_MODEL (et->priv->selection), - model_row, col->col_idx, GDK_CONTROL_MASK); - return TRUE; - } else if (cursor && !(flags & E_TABLE_SEARCH_FLAGS_CHECK_CURSOR_FIRST)) { - gconstpointer value; - - value = e_tree_model_value_at (et->priv->model, cursor, col->col_idx); - - return col->search (value, string); - } else - return FALSE; -} - -static void -et_search_accept (ETableSearch *search, - ETree *et) -{ - ETableCol *col = current_search_col (et); - gint cursor; - - if (col == NULL) - return; - - g_object_get (et->priv->selection, "cursor_row", &cursor, NULL); - - e_selection_model_select_as_key_press ( - E_SELECTION_MODEL (et->priv->selection), - cursor, col->col_idx, 0); -} - -static void -e_tree_init (ETree *e_tree) -{ - gtk_widget_set_can_focus (GTK_WIDGET (e_tree), TRUE); - - gtk_table_set_homogeneous (GTK_TABLE (e_tree), FALSE); - - e_tree->priv = E_TREE_GET_PRIVATE (e_tree); - - e_tree->priv->alternating_row_colors = 1; - e_tree->priv->horizontal_draw_grid = 1; - e_tree->priv->vertical_draw_grid = 1; - e_tree->priv->draw_focus = 1; - e_tree->priv->cursor_mode = E_CURSOR_SIMPLE; - e_tree->priv->length_threshold = 200; - - e_tree->priv->drop_row = -1; - e_tree->priv->drop_col = -1; - - e_tree->priv->drag_row = -1; - e_tree->priv->drag_col = -1; - -#ifdef E_TREE_USE_TREE_SELECTION - e_tree->priv->selection = - E_SELECTION_MODEL (e_tree_selection_model_new ()); -#else - e_tree->priv->selection = - E_SELECTION_MODEL (e_table_selection_model_new ()); -#endif - - e_tree->priv->search = e_table_search_new (); - - e_tree->priv->search_search_id = g_signal_connect ( - e_tree->priv->search, "search", - G_CALLBACK (et_search_search), e_tree); - - e_tree->priv->search_accept_id = g_signal_connect ( - e_tree->priv->search, "accept", - G_CALLBACK (et_search_accept), e_tree); - - e_tree->priv->always_search = g_getenv ("GAL_ALWAYS_SEARCH") ? TRUE : FALSE; - - e_tree->priv->state_changed = FALSE; - e_tree->priv->state_change_freeze = 0; - - e_tree->priv->is_dragging = FALSE; -} - -/* Grab_focus handler for the ETree */ -static void -et_grab_focus (GtkWidget *widget) -{ - ETree *e_tree; - - e_tree = E_TREE (widget); - - gtk_widget_grab_focus (GTK_WIDGET (e_tree->priv->table_canvas)); -} - -/* Focus handler for the ETree */ -static gint -et_focus (GtkWidget *container, - GtkDirectionType direction) -{ - ETree *e_tree; - - e_tree = E_TREE (container); - - if (gtk_container_get_focus_child (GTK_CONTAINER (container))) { - gtk_container_set_focus_child (GTK_CONTAINER (container), NULL); - return FALSE; - } - - return gtk_widget_child_focus ( - GTK_WIDGET (e_tree->priv->table_canvas), direction); -} - -static void -set_header_canvas_width (ETree *e_tree) -{ - gdouble oldwidth, oldheight, width; - - if (!(e_tree->priv->header_item && - e_tree->priv->header_canvas && e_tree->priv->table_canvas)) - return; - - gnome_canvas_get_scroll_region ( - GNOME_CANVAS (e_tree->priv->table_canvas), - NULL, NULL, &width, NULL); - gnome_canvas_get_scroll_region ( - GNOME_CANVAS (e_tree->priv->header_canvas), - NULL, NULL, &oldwidth, &oldheight); - - if (oldwidth != width || - oldheight != E_TABLE_HEADER_ITEM (e_tree->priv->header_item)->height - 1) - gnome_canvas_set_scroll_region ( - GNOME_CANVAS (e_tree->priv->header_canvas), - 0, 0, width, /* COLUMN_HEADER_HEIGHT - 1 */ - E_TABLE_HEADER_ITEM (e_tree->priv->header_item)->height - 1); - -} - -static void -header_canvas_size_allocate (GtkWidget *widget, - GtkAllocation *alloc, - ETree *e_tree) -{ - GtkAllocation allocation; - - set_header_canvas_width (e_tree); - - widget = GTK_WIDGET (e_tree->priv->header_canvas); - gtk_widget_get_allocation (widget, &allocation); - - /* 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 (allocation.height != E_TABLE_HEADER_ITEM (e_tree->priv->header_item)->height) - gtk_widget_set_size_request ( - widget, -1, - E_TABLE_HEADER_ITEM (e_tree->priv->header_item)->height); -} - -static void -e_tree_setup_header (ETree *e_tree) -{ - GtkWidget *widget; - gchar *pointer; - - widget = e_canvas_new (); - gtk_widget_set_can_focus (widget, FALSE); - e_tree->priv->header_canvas = GNOME_CANVAS (widget); - gtk_widget_show (widget); - - pointer = g_strdup_printf ("%p", (gpointer) e_tree); - - e_tree->priv->header_item = gnome_canvas_item_new ( - gnome_canvas_root (e_tree->priv->header_canvas), - e_table_header_item_get_type (), - "ETableHeader", e_tree->priv->header, - "full_header", e_tree->priv->full_header, - "sort_info", e_tree->priv->sort_info, - "dnd_code", pointer, - "tree", e_tree, - NULL); - - g_free (pointer); - - g_signal_connect ( - e_tree->priv->header_canvas, "size_allocate", - G_CALLBACK (header_canvas_size_allocate), e_tree); - - gtk_widget_set_size_request ( - GTK_WIDGET (e_tree->priv->header_canvas), -1, - E_TABLE_HEADER_ITEM (e_tree->priv->header_item)->height); -} - -static void -scroll_to_cursor (ETree *e_tree) -{ - ETreePath path; - GtkAdjustment *adjustment; - GtkScrollable *scrollable; - gint x, y, w, h; - gdouble page_size; - gdouble lower; - gdouble upper; - gdouble value; - - path = e_tree_get_cursor (e_tree); - x = y = w = h = 0; - - if (path) { - gint row = e_tree_row_of_node (e_tree, path); - gint col = 0; - - if (row >= 0) - e_table_item_get_cell_geometry ( - E_TABLE_ITEM (e_tree->priv->item), - &row, &col, &x, &y, &w, &h); - } - - scrollable = GTK_SCROLLABLE (e_tree->priv->table_canvas); - adjustment = gtk_scrollable_get_vadjustment (scrollable); - - page_size = gtk_adjustment_get_page_size (adjustment); - lower = gtk_adjustment_get_lower (adjustment); - upper = gtk_adjustment_get_upper (adjustment); - value = gtk_adjustment_get_value (adjustment); - - if (y < value || y + h > value + page_size) { - value = CLAMP (y - page_size / 2, lower, upper - page_size); - gtk_adjustment_set_value (adjustment, value); - } -} - -static gboolean -tree_canvas_reflow_idle (ETree *e_tree) -{ - gdouble height, width; - gdouble oldheight, oldwidth; - GtkAllocation allocation; - GtkWidget *widget; - - widget = GTK_WIDGET (e_tree->priv->table_canvas); - gtk_widget_get_allocation (widget, &allocation); - - g_object_get ( - e_tree->priv->item, - "height", &height, "width", &width, NULL); - - height = MAX ((gint) height, allocation.height); - width = MAX ((gint) width, allocation.width); - - /* I have no idea why this needs to be -1, but it works. */ - gnome_canvas_get_scroll_region ( - GNOME_CANVAS (e_tree->priv->table_canvas), - NULL, NULL, &oldwidth, &oldheight); - - if (oldwidth != width - 1 || - oldheight != height - 1) { - gnome_canvas_set_scroll_region ( - GNOME_CANVAS (e_tree->priv->table_canvas), - 0, 0, width - 1, height - 1); - set_header_canvas_width (e_tree); - } - - e_tree->priv->reflow_idle_id = 0; - - if (e_tree->priv->show_cursor_after_reflow) { - e_tree->priv->show_cursor_after_reflow = FALSE; - scroll_to_cursor (e_tree); - } - - return FALSE; -} - -static void -tree_canvas_size_allocate (GtkWidget *widget, - GtkAllocation *alloc, - ETree *e_tree) -{ - gdouble width; - gdouble height; - GValue *val = g_new0 (GValue, 1); - g_value_init (val, G_TYPE_DOUBLE); - - width = alloc->width; - g_value_set_double (val, width); - g_object_get ( - e_tree->priv->item, - "height", &height, - NULL); - height = MAX ((gint) height, alloc->height); - - g_object_set ( - e_tree->priv->item, - "width", width, - NULL); - g_object_set_property (G_OBJECT (e_tree->priv->header), "width", val); - g_free (val); - - if (e_tree->priv->reflow_idle_id) - g_source_remove (e_tree->priv->reflow_idle_id); - tree_canvas_reflow_idle (e_tree); -} - -static void -tree_canvas_reflow (GnomeCanvas *canvas, - ETree *e_tree) -{ - if (!e_tree->priv->reflow_idle_id) - e_tree->priv->reflow_idle_id = g_idle_add_full ( - 400, (GSourceFunc) tree_canvas_reflow_idle, - e_tree, NULL); -} - -static void -item_cursor_change (ETableItem *eti, - gint row, - ETree *et) -{ - ETreePath path = e_tree_table_adapter_node_at_row (et->priv->etta, row); - - g_signal_emit (et, et_signals[CURSOR_CHANGE], 0, row, path); -} - -static void -item_cursor_activated (ETableItem *eti, - gint row, - ETree *et) -{ - ETreePath path = e_tree_table_adapter_node_at_row (et->priv->etta, row); - - g_signal_emit (et, et_signals[CURSOR_ACTIVATED], 0, row, path); -} - -static void -item_double_click (ETableItem *eti, - gint row, - gint col, - GdkEvent *event, - ETree *et) -{ - ETreePath path = e_tree_table_adapter_node_at_row (et->priv->etta, row); - - g_signal_emit (et, et_signals[DOUBLE_CLICK], 0, row, path, col, event); -} - -static gboolean -item_right_click (ETableItem *eti, - gint row, - gint col, - GdkEvent *event, - ETree *et) -{ - ETreePath path = e_tree_table_adapter_node_at_row (et->priv->etta, row); - gboolean return_val = 0; - - g_signal_emit ( - et, et_signals[RIGHT_CLICK], 0, - row, path, col, event, &return_val); - - return return_val; -} - -static gboolean -item_click (ETableItem *eti, - gint row, - gint col, - GdkEvent *event, - ETree *et) -{ - gboolean return_val = 0; - ETreePath path = e_tree_table_adapter_node_at_row (et->priv->etta, row); - - g_signal_emit ( - et, et_signals[CLICK], 0, row, path, col, event, &return_val); - - return return_val; -} - -static gint -item_key_press (ETableItem *eti, - gint row, - gint col, - GdkEvent *event, - ETree *et) -{ - gint return_val = 0; - GdkEventKey *key = (GdkEventKey *) event; - ETreePath path; - gint y, row_local, col_local; - GtkAdjustment *adjustment; - GtkScrollable *scrollable; - gdouble page_size; - gdouble upper; - gdouble value; - - scrollable = GTK_SCROLLABLE (et->priv->table_canvas); - adjustment = gtk_scrollable_get_vadjustment (scrollable); - - page_size = gtk_adjustment_get_page_size (adjustment); - upper = gtk_adjustment_get_upper (adjustment); - value = gtk_adjustment_get_value (adjustment); - - switch (key->keyval) { - case GDK_KEY_Page_Down: - case GDK_KEY_KP_Page_Down: - y = CLAMP (value + (2 * page_size - 50), 0, upper); - y -= value; - e_tree_get_cell_at (et, 30, y, &row_local, &col_local); - - if (row_local == -1) - row_local = e_table_model_row_count ( - E_TABLE_MODEL (et->priv->etta)) - 1; - - row_local = e_tree_view_to_model_row (et, row_local); - col_local = e_selection_model_cursor_col ( - E_SELECTION_MODEL (et->priv->selection)); - e_selection_model_select_as_key_press ( - E_SELECTION_MODEL (et->priv->selection), - row_local, col_local, key->state); - - return_val = 1; - break; - case GDK_KEY_Page_Up: - case GDK_KEY_KP_Page_Up: - y = CLAMP (value - (page_size - 50), 0, upper); - y -= value; - e_tree_get_cell_at (et, 30, y, &row_local, &col_local); - - if (row_local == -1) - row_local = e_table_model_row_count ( - E_TABLE_MODEL (et->priv->etta)) - 1; - - row_local = e_tree_view_to_model_row (et, row_local); - col_local = e_selection_model_cursor_col ( - E_SELECTION_MODEL (et->priv->selection)); - e_selection_model_select_as_key_press ( - E_SELECTION_MODEL (et->priv->selection), - row_local, col_local, key->state); - - return_val = 1; - break; - case GDK_KEY_plus: - case GDK_KEY_KP_Add: - case GDK_KEY_Right: - case GDK_KEY_KP_Right: - /* Only allow if the Shift modifier is used. - * eg. Ctrl-Equal shouldn't be handled. */ - if ((key->state & (GDK_SHIFT_MASK | GDK_LOCK_MASK | - GDK_MOD1_MASK)) != GDK_SHIFT_MASK) - break; - if (row != -1) { - path = e_tree_table_adapter_node_at_row ( - et->priv->etta, row); - if (path) - e_tree_table_adapter_node_set_expanded ( - et->priv->etta, path, TRUE); - } - return_val = 1; - break; - case GDK_KEY_underscore: - case GDK_KEY_KP_Subtract: - case GDK_KEY_Left: - case GDK_KEY_KP_Left: - /* Only allow if the Shift modifier is used. - * eg. Ctrl-Minus shouldn't be handled. */ - if ((key->state & (GDK_SHIFT_MASK | GDK_LOCK_MASK | - GDK_MOD1_MASK)) != GDK_SHIFT_MASK) - break; - if (row != -1) { - path = e_tree_table_adapter_node_at_row ( - et->priv->etta, row); - if (path) - e_tree_table_adapter_node_set_expanded ( - et->priv->etta, path, FALSE); - } - return_val = 1; - break; - case GDK_KEY_BackSpace: - if (e_table_search_backspace (et->priv->search)) - return TRUE; - /* Fallthrough */ - default: - if ((key->state & ~(GDK_SHIFT_MASK | GDK_LOCK_MASK | - GDK_MOD1_MASK | GDK_MOD2_MASK | GDK_MOD3_MASK | - GDK_MOD4_MASK | GDK_MOD5_MASK)) == 0 - && ((key->keyval >= GDK_KEY_a && key->keyval <= GDK_KEY_z) || - (key->keyval >= GDK_KEY_A && key->keyval <= GDK_KEY_Z) || - (key->keyval >= GDK_KEY_0 && key->keyval <= GDK_KEY_9))) { - e_table_search_input_character (et->priv->search, key->keyval); - } - path = e_tree_table_adapter_node_at_row (et->priv->etta, row); - g_signal_emit ( - et, - et_signals[KEY_PRESS], 0, - row, path, col, event, &return_val); - break; - } - return return_val; -} - -static gint -item_start_drag (ETableItem *eti, - gint row, - gint col, - GdkEvent *event, - ETree *et) -{ - ETreePath path; - gint return_val = 0; - - path = e_tree_table_adapter_node_at_row (et->priv->etta, row); - - g_signal_emit ( - et, et_signals[START_DRAG], 0, - row, path, col, event, &return_val); - - return return_val; -} - -static void -et_selection_model_selection_changed (ETableSelectionModel *etsm, - ETree *et) -{ - g_signal_emit (et, et_signals[SELECTION_CHANGE], 0); -} - -static void -et_selection_model_selection_row_changed (ETableSelectionModel *etsm, - gint row, - ETree *et) -{ - g_signal_emit (et, et_signals[SELECTION_CHANGE], 0); -} - -static void -et_build_item (ETree *et) -{ - et->priv->item = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP ( - gnome_canvas_root (et->priv->table_canvas)), - e_table_item_get_type (), - "ETableHeader", et->priv->header, - "ETableModel", et->priv->etta, - "selection_model", et->priv->selection, - "alternating_row_colors", et->priv->alternating_row_colors, - "horizontal_draw_grid", et->priv->horizontal_draw_grid, - "vertical_draw_grid", et->priv->vertical_draw_grid, - "drawfocus", et->priv->draw_focus, - "cursor_mode", et->priv->cursor_mode, - "length_threshold", et->priv->length_threshold, - "uniform_row_height", et->priv->uniform_row_height, - NULL); - - g_signal_connect ( - et->priv->item, "cursor_change", - G_CALLBACK (item_cursor_change), et); - g_signal_connect ( - et->priv->item, "cursor_activated", - G_CALLBACK (item_cursor_activated), et); - g_signal_connect ( - et->priv->item, "double_click", - G_CALLBACK (item_double_click), et); - g_signal_connect ( - et->priv->item, "right_click", - G_CALLBACK (item_right_click), et); - g_signal_connect ( - et->priv->item, "click", - G_CALLBACK (item_click), et); - g_signal_connect ( - et->priv->item, "key_press", - G_CALLBACK (item_key_press), et); - g_signal_connect ( - et->priv->item, "start_drag", - G_CALLBACK (item_start_drag), et); -} - -static void -et_canvas_style_set (GtkWidget *widget, - GtkStyle *prev_style) -{ - GtkStyle *style; - - style = gtk_widget_get_style (widget); - - gnome_canvas_item_set ( - E_TREE (widget)->priv->white_item, - "fill_color_gdk", &style->base[GTK_STATE_NORMAL], - NULL); -} - -static gboolean -white_item_event (GnomeCanvasItem *white_item, - GdkEvent *event, - ETree *e_tree) -{ - gboolean return_val = 0; - g_signal_emit ( - e_tree, - et_signals[WHITE_SPACE_EVENT], 0, - event, &return_val); - return return_val; -} - -static gint -et_canvas_root_event (GnomeCanvasItem *root, - GdkEvent *event, - ETree *e_tree) -{ - switch (event->type) { - case GDK_BUTTON_PRESS: - case GDK_2BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - if (event->button.button != 4 && event->button.button != 5) { - if (gtk_widget_has_focus (GTK_WIDGET (root->canvas))) { - GnomeCanvasItem *item = GNOME_CANVAS (root->canvas)->focused_item; - - if (E_IS_TABLE_ITEM (item)) { - e_table_item_leave_edit (E_TABLE_ITEM (item)); - return TRUE; - } - } - } - break; - default: - break; - } - - return FALSE; -} - -/* Handler for focus events in the table_canvas; we have to repaint ourselves - * and give the focus to some ETableItem. - */ -static gboolean -table_canvas_focus_event_cb (GtkWidget *widget, - GdkEventFocus *event, - gpointer data) -{ - GnomeCanvas *canvas; - ETree *tree; - - gtk_widget_queue_draw (widget); - - if (!event->in) - return TRUE; - - canvas = GNOME_CANVAS (widget); - tree = E_TREE (data); - - if (!canvas->focused_item || - (e_selection_model_cursor_row (tree->priv->selection) == -1)) { - e_table_item_set_cursor (E_TABLE_ITEM (tree->priv->item), 0, 0); - gnome_canvas_item_grab_focus (tree->priv->item); - } - - return TRUE; -} - -static void -e_tree_setup_table (ETree *e_tree) -{ - GtkWidget *widget; - GtkStyle *style; - - e_tree->priv->table_canvas = GNOME_CANVAS (e_canvas_new ()); - g_signal_connect ( - e_tree->priv->table_canvas, "size_allocate", - G_CALLBACK (tree_canvas_size_allocate), e_tree); - g_signal_connect ( - e_tree->priv->table_canvas, "focus_in_event", - G_CALLBACK (table_canvas_focus_event_cb), e_tree); - g_signal_connect ( - e_tree->priv->table_canvas, "focus_out_event", - G_CALLBACK (table_canvas_focus_event_cb), e_tree); - - g_signal_connect ( - e_tree->priv->table_canvas, "drag_begin", - G_CALLBACK (et_drag_begin), e_tree); - g_signal_connect ( - e_tree->priv->table_canvas, "drag_end", - G_CALLBACK (et_drag_end), e_tree); - g_signal_connect ( - e_tree->priv->table_canvas, "drag_data_get", - G_CALLBACK (et_drag_data_get), e_tree); - g_signal_connect ( - e_tree->priv->table_canvas, "drag_data_delete", - G_CALLBACK (et_drag_data_delete), e_tree); - g_signal_connect ( - e_tree, "drag_motion", - G_CALLBACK (et_drag_motion), e_tree); - g_signal_connect ( - e_tree, "drag_leave", - G_CALLBACK (et_drag_leave), e_tree); - g_signal_connect ( - e_tree, "drag_drop", - G_CALLBACK (et_drag_drop), e_tree); - g_signal_connect ( - e_tree, "drag_data_received", - G_CALLBACK (et_drag_data_received), e_tree); - - g_signal_connect ( - e_tree->priv->table_canvas, "reflow", - G_CALLBACK (tree_canvas_reflow), e_tree); - - widget = GTK_WIDGET (e_tree->priv->table_canvas); - style = gtk_widget_get_style (widget); - - gtk_widget_show (widget); - - e_tree->priv->white_item = gnome_canvas_item_new ( - gnome_canvas_root (e_tree->priv->table_canvas), - e_canvas_background_get_type (), - "fill_color_gdk", &style->base[GTK_STATE_NORMAL], - NULL); - - g_signal_connect ( - e_tree->priv->white_item, "event", - G_CALLBACK (white_item_event), e_tree); - g_signal_connect ( - gnome_canvas_root (e_tree->priv->table_canvas), "event", - G_CALLBACK (et_canvas_root_event), e_tree); - - et_build_item (e_tree); -} - -/** - * e_tree_set_search_column: - * @e_tree: #ETree object that will be modified - * @col: Column index to use for searches - * - * This routine sets the current search column to be used for keypress - * searches of the #ETree. If -1 is passed in for column, the current - * search column is cleared. - */ -void -e_tree_set_search_column (ETree *e_tree, - gint col) -{ - if (col == -1) { - clear_current_search_col (e_tree); - return; - } - - e_tree->priv->search_col_set = TRUE; - e_tree->priv->current_search_col = e_table_header_get_column ( - e_tree->priv->full_header, col); -} - -void -e_tree_set_state_object (ETree *e_tree, - ETableState *state) -{ - GValue *val; - GtkAllocation allocation; - GtkWidget *widget; - - val = g_new0 (GValue, 1); - g_value_init (val, G_TYPE_DOUBLE); - - connect_header (e_tree, state); - - widget = GTK_WIDGET (e_tree->priv->table_canvas); - gtk_widget_get_allocation (widget, &allocation); - - g_value_set_double (val, (gdouble) allocation.width); - g_object_set_property (G_OBJECT (e_tree->priv->header), "width", val); - g_free (val); - - if (e_tree->priv->header_item) - g_object_set ( - e_tree->priv->header_item, - "ETableHeader", e_tree->priv->header, - "sort_info", e_tree->priv->sort_info, - NULL); - - if (e_tree->priv->item) - g_object_set ( - e_tree->priv->item, - "ETableHeader", e_tree->priv->header, - NULL); - - if (e_tree->priv->etta) - e_tree_table_adapter_set_sort_info ( - e_tree->priv->etta, e_tree->priv->sort_info); - - e_tree_state_change (e_tree); -} - -/** - * e_tree_set_state: - * @e_tree: #ETree 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 - * #ETree object. - */ -void -e_tree_set_state (ETree *e_tree, - const gchar *state_str) -{ - ETableState *state; - - g_return_if_fail (e_tree != NULL); - g_return_if_fail (E_IS_TREE (e_tree)); - 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_tree_set_state_object (e_tree, state); - - g_object_unref (state); -} - -/** - * e_tree_load_state: - * @e_tree: #ETree object that will be modified - * @filename: name of the file containing the state to be loaded into the #ETree - * - * An #ETableState will be loaded form the file pointed by @filename into the - * @e_tree object. - */ -void -e_tree_load_state (ETree *e_tree, - const gchar *filename) -{ - ETableState *state; - - g_return_if_fail (e_tree != NULL); - g_return_if_fail (E_IS_TREE (e_tree)); - 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_tree_set_state_object (e_tree, state); - - g_object_unref (state); -} - -/** - * e_tree_get_state_object: - * @e_tree: #ETree object to act on - * - * Builds an #ETableState corresponding to the current state of the - * #ETree. - * - * Return value: - * The %ETableState object generated. - **/ -ETableState * -e_tree_get_state_object (ETree *e_tree) -{ - ETableState *state; - gint full_col_count; - gint i, j; - - state = e_table_state_new (); - state->sort_info = e_tree->priv->sort_info; - if (state->sort_info) - g_object_ref (state->sort_info); - - state->col_count = e_table_header_count (e_tree->priv->header); - full_col_count = e_table_header_count (e_tree->priv->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_tree->priv->header, i); - state->columns[i] = -1; - for (j = 0; j < full_col_count; j++) { - if (col->col_idx == e_table_header_index (e_tree->priv->full_header, j)) { - state->columns[i] = j; - break; - } - } - state->expansions[i] = col->expansion; - } - - return state; -} - -/** - * e_tree_get_state: - * @e_tree: The #ETree to act on - * - * Builds a state object based on the current state and returns the - * string corresponding to that state. - * - * Return value: - * A string describing the current state of the #ETree. - **/ -gchar * -e_tree_get_state (ETree *e_tree) -{ - ETableState *state; - gchar *string; - - state = e_tree_get_state_object (e_tree); - string = e_table_state_save_to_string (state); - g_object_unref (state); - return string; -} - -/** - * e_tree_save_state: - * @e_tree: The #ETree to act on - * @filename: name of the file to save to - * - * Saves the state of the @e_tree object into the file pointed by - * @filename. - **/ -void -e_tree_save_state (ETree *e_tree, - const gchar *filename) -{ - ETableState *state; - - state = e_tree_get_state_object (e_tree); - e_table_state_save_to_file (state, filename); - g_object_unref (state); -} - -/** - * e_tree_get_spec: - * @e_tree: The #ETree to query - * - * Returns the specification object. - * - * Return value: - **/ -ETableSpecification * -e_tree_get_spec (ETree *e_tree) -{ - return e_tree->priv->spec; -} - -static void -et_table_model_changed (ETableModel *model, - ETree *et) -{ - if (et->priv->horizontal_scrolling) - e_table_header_update_horizontal (et->priv->header); -} - -static void -et_table_row_changed (ETableModel *table_model, - gint row, - ETree *et) -{ - et_table_model_changed (table_model, et); -} - -static void -et_table_cell_changed (ETableModel *table_model, - gint view_col, - gint row, - ETree *et) -{ - et_table_model_changed (table_model, et); -} - -static void -et_table_rows_deleted (ETableModel *table_model, - gint row, - gint count, - ETree *et) -{ - ETreePath * node, * prev_node; - - /* If the cursor is still valid after this deletion, we're done */ - if (e_selection_model_cursor_row (et->priv->selection) >= 0 - || row == 0) - return; - - prev_node = e_tree_node_at_row (et, row - 1); - node = e_tree_get_cursor (et); - - /* Check if the cursor is a child of the node directly before the - * deleted region (implying that an expander was collapsed with - * the cursor inside it) */ - while (node) { - node = e_tree_model_node_get_parent (et->priv->model, node); - if (node == prev_node) { - /* Set the cursor to the still-visible parent */ - e_tree_set_cursor (et, prev_node); - return; - } - } -} - -static void -et_connect_to_etta (ETree *et) -{ - et->priv->table_model_change_id = g_signal_connect ( - et->priv->etta, "model_changed", - G_CALLBACK (et_table_model_changed), et); - - et->priv->table_row_change_id = g_signal_connect ( - et->priv->etta, "model_row_changed", - G_CALLBACK (et_table_row_changed), et); - - et->priv->table_cell_change_id = g_signal_connect ( - et->priv->etta, "model_cell_changed", - G_CALLBACK (et_table_cell_changed), et); - - et->priv->table_rows_delete_id = g_signal_connect ( - et->priv->etta, "model_rows_deleted", - G_CALLBACK (et_table_rows_deleted), et); - -} - -static gboolean -et_real_construct (ETree *e_tree, - ETreeModel *etm, - ETableExtras *ete, - ETableSpecification *specification, - ETableState *state) -{ - GtkAdjustment *adjustment; - GtkScrollable *scrollable; - gint row = 0; - - if (ete) - g_object_ref (ete); - else - ete = e_table_extras_new (); - - e_tree->priv->alternating_row_colors = specification->alternating_row_colors; - e_tree->priv->horizontal_draw_grid = specification->horizontal_draw_grid; - e_tree->priv->vertical_draw_grid = specification->vertical_draw_grid; - e_tree->priv->draw_focus = specification->draw_focus; - e_tree->priv->cursor_mode = specification->cursor_mode; - e_tree->priv->full_header = e_table_spec_to_full_header (specification, ete); - - connect_header (e_tree, state); - - e_tree->priv->horizontal_scrolling = specification->horizontal_scrolling; - - e_tree->priv->model = etm; - g_object_ref (etm); - - e_tree->priv->etta = E_TREE_TABLE_ADAPTER ( - e_tree_table_adapter_new (e_tree->priv->model, - e_tree->priv->sort_info, e_tree->priv->full_header)); - - et_connect_to_etta (e_tree); - - e_tree->priv->sorter = e_sorter_new (); - - g_object_set ( - e_tree->priv->selection, - "sorter", e_tree->priv->sorter, -#ifdef E_TREE_USE_TREE_SELECTION - "model", e_tree->priv->model, - "etta", e_tree->priv->etta, -#else - "model", e_tree->priv->etta, -#endif - "selection_mode", specification->selection_mode, - "cursor_mode", specification->cursor_mode, - NULL); - - g_signal_connect ( - e_tree->priv->selection, "selection_changed", - G_CALLBACK (et_selection_model_selection_changed), e_tree); - g_signal_connect ( - e_tree->priv->selection, "selection_row_changed", - G_CALLBACK (et_selection_model_selection_row_changed), e_tree); - - if (!specification->no_headers) { - e_tree_setup_header (e_tree); - } - e_tree_setup_table (e_tree); - - scrollable = GTK_SCROLLABLE (e_tree->priv->table_canvas); - - adjustment = gtk_scrollable_get_vadjustment (scrollable); - gtk_adjustment_set_step_increment (adjustment, 20); - - adjustment = gtk_scrollable_get_hadjustment (scrollable); - gtk_adjustment_set_step_increment (adjustment, 20); - - if (!specification->no_headers) { - /* - * The header - */ - gtk_table_attach ( - GTK_TABLE (e_tree), - GTK_WIDGET (e_tree->priv->header_canvas), - 0, 1, 0 + row, 1 + row, - GTK_FILL | GTK_EXPAND, - GTK_FILL, 0, 0); - row++; - } - - gtk_table_attach ( - GTK_TABLE (e_tree), - GTK_WIDGET (e_tree->priv->table_canvas), - 0, 1, 0 + row, 1 + row, - GTK_FILL | GTK_EXPAND, - GTK_FILL | GTK_EXPAND, - 0, 0); - - g_object_unref (ete); - - return TRUE; -} - -/** - * e_tree_construct: - * @e_tree: The newly created #ETree object. - * @etm: The model for this table. - * @ete: An optional #ETableExtras. (%NULL is valid.) - * @spec_str: The spec. - * @state_str: An optional state. (%NULL is valid.) - * - * This is the internal implementation of e_tree_new() for use by - * subclasses or language bindings. See e_tree_new() for details. - * - * Return value: %TRUE on success, %FALSE if an error occurred - **/ -gboolean -e_tree_construct (ETree *e_tree, - ETreeModel *etm, - ETableExtras *ete, - const gchar *spec_str, - const gchar *state_str) -{ - ETableSpecification *specification; - ETableState *state; - - g_return_val_if_fail (e_tree != NULL, FALSE); - g_return_val_if_fail (E_IS_TREE (e_tree), FALSE); - g_return_val_if_fail (etm != NULL, FALSE); - g_return_val_if_fail (E_IS_TREE_MODEL (etm), FALSE); - g_return_val_if_fail (ete == NULL || E_IS_TABLE_EXTRAS (ete), FALSE); - g_return_val_if_fail (spec_str != NULL, FALSE); - - specification = e_table_specification_new (); - if (!e_table_specification_load_from_string (specification, spec_str)) { - g_object_unref (specification); - return FALSE; - } - if (state_str) { - state = e_table_state_new (); - e_table_state_load_from_string (state, state_str); - if (state->col_count <= 0) { - g_object_unref (state); - state = specification->state; - g_object_ref (state); - } - } else { - state = specification->state; - g_object_ref (state); - } - - if (!et_real_construct (e_tree, etm, ete, specification, state)) { - g_object_unref (specification); - g_object_unref (state); - return FALSE; - } - - e_tree->priv->spec = specification; - e_tree->priv->spec->allow_grouping = FALSE; - - g_object_unref (state); - - return TRUE; -} - -/** - * e_tree_construct_from_spec_file: - * @e_tree: The newly created #ETree object. - * @etm: The model for this tree - * @ete: An optional #ETableExtras (%NULL is valid.) - * @spec_fn: The filename of the spec - * @state_fn: An optional state file (%NULL is valid.) - * - * This is the internal implementation of e_tree_new_from_spec_file() - * for use by subclasses or language bindings. See - * e_tree_new_from_spec_file() for details. - * - * Return value: %TRUE on success, %FALSE if an error occurred - **/ -gboolean -e_tree_construct_from_spec_file (ETree *e_tree, - ETreeModel *etm, - ETableExtras *ete, - const gchar *spec_fn, - const gchar *state_fn) -{ - ETableSpecification *specification; - ETableState *state; - - g_return_val_if_fail (e_tree != NULL, FALSE); - g_return_val_if_fail (E_IS_TREE (e_tree), FALSE); - g_return_val_if_fail (etm != NULL, FALSE); - g_return_val_if_fail (E_IS_TREE_MODEL (etm), FALSE); - g_return_val_if_fail (ete == NULL || E_IS_TABLE_EXTRAS (ete), FALSE); - g_return_val_if_fail (spec_fn != NULL, FALSE); - - specification = e_table_specification_new (); - if (!e_table_specification_load_from_file (specification, spec_fn)) { - g_object_unref (specification); - return FALSE; - } - if (state_fn) { - state = e_table_state_new (); - if (!e_table_state_load_from_file (state, state_fn)) { - g_object_unref (state); - state = specification->state; - g_object_ref (state); - } - if (state->col_count <= 0) { - g_object_unref (state); - state = specification->state; - g_object_ref (state); - } - } else { - state = specification->state; - g_object_ref (state); - } - - if (!et_real_construct (e_tree, etm, ete, specification, state)) { - g_object_unref (specification); - g_object_unref (state); - return FALSE; - } - - e_tree->priv->spec = specification; - e_tree->priv->spec->allow_grouping = FALSE; - - g_object_unref (state); - - return TRUE; -} - -/** - * e_tree_new: - * @etm: The model for this tree - * @ete: An optional #ETableExtras (%NULL is valid.) - * @spec: The spec - * @state: An optional state (%NULL is valid.) - * - * This function creates an #ETree from the given parameters. The - * #ETreeModel is a tree model to be represented. The #ETableExtras - * is an optional set of pixbufs, cells, and sorting functions to be - * used when interpreting the spec. If you pass in %NULL it uses the - * default #ETableExtras. (See e_table_extras_new()). - * - * @spec is the specification of the set of viewable columns and the - * default sorting state and such. @state is an optional string - * specifying the current sorting state and such. If @state is NULL, - * then the default state from the spec will be used. - * - * Return value: - * The newly created #ETree or %NULL if there's an error. - **/ -GtkWidget * -e_tree_new (ETreeModel *etm, - ETableExtras *ete, - const gchar *spec, - const gchar *state) -{ - ETree *e_tree; - - g_return_val_if_fail (etm != NULL, NULL); - g_return_val_if_fail (E_IS_TREE_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_tree = g_object_new (E_TYPE_TREE, NULL); - - if (!e_tree_construct (e_tree, etm, ete, spec, state)) { - g_object_unref (e_tree); - return NULL; - } - - return (GtkWidget *) e_tree; -} - -/** - * e_tree_new_from_spec_file: - * @etm: The model for this tree. - * @ete: An optional #ETableExtras. (%NULL is valid.) - * @spec_fn: The filename of the spec. - * @state_fn: An optional state file. (%NULL is valid.) - * - * This is very similar to e_tree_new(), except instead of passing in - * strings you pass in the file names of the spec and state to load. - * - * @spec_fn is the filename of the spec to load. If this file doesn't - * exist, e_tree_new_from_spec_file will return %NULL. - * - * @state_fn is the filename of the initial state to load. If this is - * %NULL or if the specified file doesn't exist, the default state - * from the spec file is used. - * - * Return value: - * The newly created #ETree or %NULL if there's an error. - **/ -GtkWidget * -e_tree_new_from_spec_file (ETreeModel *etm, - ETableExtras *ete, - const gchar *spec_fn, - const gchar *state_fn) -{ - ETree *e_tree; - - g_return_val_if_fail (etm != NULL, NULL); - g_return_val_if_fail (E_IS_TREE_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_tree = g_object_new (E_TYPE_TREE, NULL); - - if (!e_tree_construct_from_spec_file (e_tree, etm, ete, spec_fn, state_fn)) { - g_object_unref (e_tree); - return NULL; - } - - return (GtkWidget *) e_tree; -} - -void -e_tree_show_cursor_after_reflow (ETree *e_tree) -{ - g_return_if_fail (e_tree != NULL); - g_return_if_fail (E_IS_TREE (e_tree)); - - e_tree->priv->show_cursor_after_reflow = TRUE; -} - -void -e_tree_set_cursor (ETree *e_tree, - ETreePath path) -{ -#ifndef E_TREE_USE_TREE_SELECTION - gint row; -#endif - g_return_if_fail (e_tree != NULL); - g_return_if_fail (E_IS_TREE (e_tree)); - g_return_if_fail (path != NULL); - -#ifdef E_TREE_USE_TREE_SELECTION - e_tree_selection_model_select_single_path ( - E_TREE_SELECTION_MODEL (e_tree->priv->selection), path); - e_tree_selection_model_change_cursor ( - E_TREE_SELECTION_MODEL (e_tree->priv->selection), path); -#else - row = e_tree_table_adapter_row_of_node ( - E_TREE_TABLE_ADAPTER (e_tree->priv->etta), path); - - if (row == -1) - return; - - g_object_set ( - e_tree->priv->selection, - "cursor_row", row, - NULL); -#endif -} - -ETreePath -e_tree_get_cursor (ETree *e_tree) -{ -#ifdef E_TREE_USE_TREE_SELECTION - return e_tree_selection_model_get_cursor ( - E_TREE_SELECTION_MODEL (e_tree->priv->selection)); -#else - gint row; - g_return_val_if_fail (e_tree != NULL, NULL); - g_return_val_if_fail (E_IS_TREE (e_tree), NULL); - - g_object_get ( - e_tree->priv->selection, - "cursor_row", &row, - NULL); - if (row == -1) - return NULL; - - return e_tree_table_adapter_node_at_row ( - E_TREE_TABLE_ADAPTER (e_tree->priv->etta), row); -#endif -} - -void -e_tree_selected_row_foreach (ETree *e_tree, - EForeachFunc callback, - gpointer closure) -{ - g_return_if_fail (e_tree != NULL); - g_return_if_fail (E_IS_TREE (e_tree)); - - e_selection_model_foreach (e_tree->priv->selection, - callback, - closure); -} - -#ifdef E_TREE_USE_TREE_SELECTION -void -e_tree_selected_path_foreach (ETree *e_tree, - ETreeForeachFunc callback, - gpointer closure) -{ - g_return_if_fail (e_tree != NULL); - g_return_if_fail (E_IS_TREE (e_tree)); - - e_tree_selection_model_foreach ( - E_TREE_SELECTION_MODEL (e_tree->priv->selection), - callback, closure); -} - -/* Standard functions */ -static void -et_foreach_recurse (ETreeModel *model, - ETreePath path, - ETreeForeachFunc callback, - gpointer closure) -{ - ETreePath child; - - callback (path, closure); - - child = e_tree_model_node_get_first_child (E_TREE_MODEL (model), path); - for (; child; child = e_tree_model_node_get_next (E_TREE_MODEL (model), child)) - if (child) - et_foreach_recurse (model, child, callback, closure); -} - -void -e_tree_path_foreach (ETree *e_tree, - ETreeForeachFunc callback, - gpointer closure) -{ - ETreePath root; - - g_return_if_fail (e_tree != NULL); - g_return_if_fail (E_IS_TREE (e_tree)); - - root = e_tree_model_get_root (e_tree->priv->model); - - if (root) - et_foreach_recurse (e_tree->priv->model, - root, - callback, - closure); -} -#endif - -EPrintable * -e_tree_get_printable (ETree *e_tree) -{ - g_return_val_if_fail (e_tree != NULL, NULL); - g_return_val_if_fail (E_IS_TREE (e_tree), NULL); - - return e_table_item_get_printable (E_TABLE_ITEM (e_tree->priv->item)); -} - -static void -et_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - ETree *etree = E_TREE (object); - - switch (property_id) { - case PROP_ETTA: - g_value_set_object (value, etree->priv->etta); - break; - - case PROP_UNIFORM_ROW_HEIGHT: - g_value_set_boolean (value, etree->priv->uniform_row_height); - break; - - case PROP_ALWAYS_SEARCH: - g_value_set_boolean (value, etree->priv->always_search); - break; - - case PROP_HADJUSTMENT: - if (etree->priv->table_canvas) - g_object_get_property ( - G_OBJECT (etree->priv->table_canvas), - "hadjustment", value); - else - g_value_set_object (value, NULL); - break; - - case PROP_VADJUSTMENT: - if (etree->priv->table_canvas) - g_object_get_property ( - G_OBJECT (etree->priv->table_canvas), - "vadjustment", value); - else - g_value_set_object (value, NULL); - break; - - case PROP_HSCROLL_POLICY: - if (etree->priv->table_canvas) - g_object_get_property ( - G_OBJECT (etree->priv->table_canvas), - "hscroll-policy", value); - else - g_value_set_enum (value, 0); - break; - - case PROP_VSCROLL_POLICY: - if (etree->priv->table_canvas) - g_object_get_property ( - G_OBJECT (etree->priv->table_canvas), - "vscroll-policy", value); - else - g_value_set_enum (value, 0); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -typedef struct { - gchar *arg; - gboolean setting; -} bool_closure; - -static void -et_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - ETree *etree = E_TREE (object); - - switch (property_id) { - case PROP_LENGTH_THRESHOLD: - etree->priv->length_threshold = g_value_get_int (value); - if (etree->priv->item) { - gnome_canvas_item_set ( - GNOME_CANVAS_ITEM (etree->priv->item), - "length_threshold", - etree->priv->length_threshold, - NULL); - } - break; - - case PROP_HORIZONTAL_DRAW_GRID: - etree->priv->horizontal_draw_grid = g_value_get_boolean (value); - if (etree->priv->item) { - gnome_canvas_item_set ( - GNOME_CANVAS_ITEM (etree->priv->item), - "horizontal_draw_grid", - etree->priv->horizontal_draw_grid, - NULL); - } - break; - - case PROP_VERTICAL_DRAW_GRID: - etree->priv->vertical_draw_grid = g_value_get_boolean (value); - if (etree->priv->item) { - gnome_canvas_item_set ( - GNOME_CANVAS_ITEM (etree->priv->item), - "vertical_draw_grid", - etree->priv->vertical_draw_grid, - NULL); - } - break; - - case PROP_DRAW_FOCUS: - etree->priv->draw_focus = g_value_get_boolean (value); - if (etree->priv->item) { - gnome_canvas_item_set ( - GNOME_CANVAS_ITEM (etree->priv->item), - "drawfocus", - etree->priv->draw_focus, - NULL); - } - break; - - case PROP_UNIFORM_ROW_HEIGHT: - etree->priv->uniform_row_height = g_value_get_boolean (value); - if (etree->priv->item) { - gnome_canvas_item_set ( - GNOME_CANVAS_ITEM (etree->priv->item), - "uniform_row_height", - etree->priv->uniform_row_height, - NULL); - } - break; - - case PROP_ALWAYS_SEARCH: - if (etree->priv->always_search == g_value_get_boolean (value)) - return; - etree->priv->always_search = g_value_get_boolean (value); - clear_current_search_col (etree); - break; - - case PROP_HADJUSTMENT: - if (etree->priv->table_canvas) - g_object_set_property ( - G_OBJECT (etree->priv->table_canvas), - "hadjustment", value); - break; - - case PROP_VADJUSTMENT: - if (etree->priv->table_canvas) - g_object_set_property ( - G_OBJECT (etree->priv->table_canvas), - "vadjustment", value); - break; - - case PROP_HSCROLL_POLICY: - if (etree->priv->table_canvas) - g_object_set_property ( - G_OBJECT (etree->priv->table_canvas), - "hscroll-policy", value); - break; - - case PROP_VSCROLL_POLICY: - if (etree->priv->table_canvas) - g_object_set_property ( - G_OBJECT (etree->priv->table_canvas), - "vscroll-policy", value); - break; - } -} - -gint -e_tree_get_next_row (ETree *e_tree, - gint model_row) -{ - g_return_val_if_fail (e_tree != NULL, -1); - g_return_val_if_fail (E_IS_TREE (e_tree), -1); - - if (e_tree->priv->sorter) { - gint i; - i = e_sorter_model_to_sorted (E_SORTER (e_tree->priv->sorter), model_row); - i++; - if (i < e_table_model_row_count (E_TABLE_MODEL (e_tree->priv->etta))) { - return e_sorter_sorted_to_model (E_SORTER (e_tree->priv->sorter), i); - } else - return -1; - } else { - gint row_count; - - row_count = e_table_model_row_count ( - E_TABLE_MODEL (e_tree->priv->etta)); - - if (model_row < row_count - 1) - return model_row + 1; - else - return -1; - } -} - -gint -e_tree_get_prev_row (ETree *e_tree, - gint model_row) -{ - g_return_val_if_fail (e_tree != NULL, -1); - g_return_val_if_fail (E_IS_TREE (e_tree), -1); - - if (e_tree->priv->sorter) { - gint i; - i = e_sorter_model_to_sorted (E_SORTER (e_tree->priv->sorter), model_row); - i--; - if (i >= 0) - return e_sorter_sorted_to_model (E_SORTER (e_tree->priv->sorter), i); - else - return -1; - } else - return model_row - 1; -} - -gint -e_tree_model_to_view_row (ETree *e_tree, - gint model_row) -{ - g_return_val_if_fail (e_tree != NULL, -1); - g_return_val_if_fail (E_IS_TREE (e_tree), -1); - - if (e_tree->priv->sorter) - return e_sorter_model_to_sorted (E_SORTER (e_tree->priv->sorter), model_row); - else - return model_row; -} - -gint -e_tree_view_to_model_row (ETree *e_tree, - gint view_row) -{ - g_return_val_if_fail (e_tree != NULL, -1); - g_return_val_if_fail (E_IS_TREE (e_tree), -1); - - if (e_tree->priv->sorter) - return e_sorter_sorted_to_model (E_SORTER (e_tree->priv->sorter), view_row); - else - return view_row; -} - -gboolean -e_tree_node_is_expanded (ETree *et, - ETreePath path) -{ - g_return_val_if_fail (path, FALSE); - - return e_tree_table_adapter_node_is_expanded (et->priv->etta, path); -} - -void -e_tree_node_set_expanded (ETree *et, - ETreePath path, - gboolean expanded) -{ - g_return_if_fail (et != NULL); - g_return_if_fail (E_IS_TREE (et)); - - e_tree_table_adapter_node_set_expanded (et->priv->etta, path, expanded); -} - -void -e_tree_node_set_expanded_recurse (ETree *et, - ETreePath path, - gboolean expanded) -{ - g_return_if_fail (et != NULL); - g_return_if_fail (E_IS_TREE (et)); - - e_tree_table_adapter_node_set_expanded_recurse (et->priv->etta, path, expanded); -} - -void -e_tree_root_node_set_visible (ETree *et, - gboolean visible) -{ - g_return_if_fail (et != NULL); - g_return_if_fail (E_IS_TREE (et)); - - e_tree_table_adapter_root_node_set_visible (et->priv->etta, visible); -} - -ETreePath -e_tree_node_at_row (ETree *et, - gint row) -{ - ETreePath path = { 0 }; - - g_return_val_if_fail (et != NULL, path); - - path = e_tree_table_adapter_node_at_row (et->priv->etta, row); - - return path; -} - -gint -e_tree_row_of_node (ETree *et, - ETreePath path) -{ - g_return_val_if_fail (et != NULL, -1); - - return e_tree_table_adapter_row_of_node (et->priv->etta, path); -} - -gboolean -e_tree_root_node_is_visible (ETree *et) -{ - g_return_val_if_fail (et != NULL, FALSE); - - return e_tree_table_adapter_root_node_is_visible (et->priv->etta); -} - -void -e_tree_show_node (ETree *et, - ETreePath path) -{ - g_return_if_fail (et != NULL); - g_return_if_fail (E_IS_TREE (et)); - - e_tree_table_adapter_show_node (et->priv->etta, path); -} - -void -e_tree_save_expanded_state (ETree *et, - gchar *filename) -{ - g_return_if_fail (et != NULL); - g_return_if_fail (E_IS_TREE (et)); - - e_tree_table_adapter_save_expanded_state (et->priv->etta, filename); -} - -void -e_tree_load_expanded_state (ETree *et, - gchar *filename) -{ - g_return_if_fail (et != NULL); - - e_tree_table_adapter_load_expanded_state (et->priv->etta, filename); -} - -xmlDoc * -e_tree_save_expanded_state_xml (ETree *et) -{ - g_return_val_if_fail (et != NULL, NULL); - g_return_val_if_fail (E_IS_TREE (et), NULL); - - return e_tree_table_adapter_save_expanded_state_xml (et->priv->etta); -} - -void -e_tree_load_expanded_state_xml (ETree *et, - xmlDoc *doc) -{ - g_return_if_fail (et != NULL); - g_return_if_fail (E_IS_TREE (et)); - g_return_if_fail (doc != NULL); - - e_tree_table_adapter_load_expanded_state_xml (et->priv->etta, doc); -} - -/* state: <0 ... collapse; 0 ... no force - use default; >0 ... expand; - * when using this, be sure to reset to 0 once no forcing is required - * anymore, aka the build of the tree is done */ -void -e_tree_force_expanded_state (ETree *et, - gint state) -{ - g_return_if_fail (et != NULL); - - e_tree_table_adapter_force_expanded_state (et->priv->etta, state); -} - -gint -e_tree_row_count (ETree *et) -{ - g_return_val_if_fail (et != NULL, -1); - - return e_table_model_row_count (E_TABLE_MODEL (et->priv->etta)); -} - -GtkWidget * -e_tree_get_tooltip (ETree *et) -{ - g_return_val_if_fail (et != NULL, NULL); - - return E_CANVAS (et->priv->table_canvas)->tooltip_window; -} - -static ETreePath -find_next_in_range (ETree *et, - gint start, - gint end, - ETreePathFunc func, - gpointer data) -{ - ETreePath path; - gint row; - - for (row = start; row <= end; row++) { - path = e_tree_table_adapter_node_at_row (et->priv->etta, row); - if (path && func (et->priv->model, path, data)) - return path; - } - - return NULL; -} - -static ETreePath -find_prev_in_range (ETree *et, - gint start, - gint end, - ETreePathFunc func, - gpointer data) -{ - ETreePath path; - gint row; - - for (row = start; row >= end; row--) { - path = e_tree_table_adapter_node_at_row (et->priv->etta, row); - if (path && func (et->priv->model, path, data)) - return path; - } - - return NULL; -} - -gboolean -e_tree_find_next (ETree *et, - ETreeFindNextParams params, - ETreePathFunc func, - gpointer data) -{ - ETreePath cursor, found; - gint row, row_count; - - cursor = e_tree_get_cursor (et); - row = e_tree_table_adapter_row_of_node (et->priv->etta, cursor); - row_count = e_table_model_row_count (E_TABLE_MODEL (et->priv->etta)); - - if (params & E_TREE_FIND_NEXT_FORWARD) - found = find_next_in_range (et, row + 1, row_count - 1, func, data); - else - found = find_prev_in_range (et, row == -1 ? -1 : row - 1, 0, func, data); - - if (found) { - e_tree_table_adapter_show_node (et->priv->etta, found); - e_tree_set_cursor (et, found); - return TRUE; - } - - if (params & E_TREE_FIND_NEXT_WRAP) { - if (params & E_TREE_FIND_NEXT_FORWARD) - found = find_next_in_range (et, 0, row, func, data); - else - found = find_prev_in_range (et, row_count - 1, row, func, data); - - if (found && found != cursor) { - e_tree_table_adapter_show_node (et->priv->etta, found); - e_tree_set_cursor (et, found); - return TRUE; - } - } - - return FALSE; -} - -void -e_tree_right_click_up (ETree *et) -{ - e_selection_model_right_click_up (et->priv->selection); -} - -/** - * e_tree_get_model: - * @et: the ETree - * - * Returns the model upon which this ETree is based. - * - * Returns: the model - **/ -ETreeModel * -e_tree_get_model (ETree *et) -{ - g_return_val_if_fail (et != NULL, NULL); - g_return_val_if_fail (E_IS_TREE (et), NULL); - - return et->priv->model; -} - -/** - * e_tree_get_selection_model: - * @et: the ETree - * - * Returns the selection model of this ETree. - * - * Returns: the selection model - **/ -ESelectionModel * -e_tree_get_selection_model (ETree *et) -{ - g_return_val_if_fail (et != NULL, NULL); - g_return_val_if_fail (E_IS_TREE (et), NULL); - - return et->priv->selection; -} - -/** - * e_tree_get_table_adapter: - * @et: the ETree - * - * Returns the table adapter this ETree uses. - * - * Returns: the model - **/ -ETreeTableAdapter * -e_tree_get_table_adapter (ETree *et) -{ - g_return_val_if_fail (et != NULL, NULL); - g_return_val_if_fail (E_IS_TREE (et), NULL); - - return et->priv->etta; -} - -ETableItem * -e_tree_get_item (ETree *et) -{ - g_return_val_if_fail (et != NULL, NULL); - g_return_val_if_fail (E_IS_TREE (et), NULL); - - return E_TABLE_ITEM (et->priv->item); -} - -GnomeCanvasItem * -e_tree_get_header_item (ETree *et) -{ - g_return_val_if_fail (et != NULL, NULL); - g_return_val_if_fail (E_IS_TREE (et), NULL); - - return et->priv->header_item; -} - -struct _ETreeDragSourceSite -{ - GdkModifierType start_button_mask; - GtkTargetList *target_list; /* Targets for drag data */ - GdkDragAction actions; /* Possible actions */ - GdkPixbuf *pixbuf; /* Icon for drag data */ - - /* 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 */ - guint dropped : 1; /* Set after we receive a drop */ - guint32 proxy_drop_time; /* Timestamp for proxied drop */ - guint 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_tree_drag_get_data (ETree *tree, - gint row, - gint col, - GdkDragContext *context, - GdkAtom target, - guint32 time) -{ - g_return_if_fail (tree != NULL); - g_return_if_fail (E_IS_TREE (tree)); - - gtk_drag_get_data ( - GTK_WIDGET (tree), - context, - target, - time); - -} - -/** - * e_tree_drag_highlight: - * @tree: - * @row: - * @col: - * - * Set col to -1 to highlight the entire row. - * Set row to -1 to turn off the highlight. - */ -void -e_tree_drag_highlight (ETree *tree, - gint row, - gint col) -{ - GtkAllocation allocation; - GtkAdjustment *adjustment; - GtkScrollable *scrollable; - GtkStyle *style; - - g_return_if_fail (E_IS_TREE (tree)); - - scrollable = GTK_SCROLLABLE (tree->priv->table_canvas); - style = gtk_widget_get_style (GTK_WIDGET (tree)); - gtk_widget_get_allocation (GTK_WIDGET (scrollable), &allocation); - - if (row != -1) { - gint x, y, width, height; - if (col == -1) { - e_tree_get_cell_geometry (tree, row, 0, &x, &y, &width, &height); - x = 0; - width = allocation.width; - } else { - e_tree_get_cell_geometry (tree, row, col, &x, &y, &width, &height); - adjustment = gtk_scrollable_get_hadjustment (scrollable); - x += gtk_adjustment_get_value (adjustment); - } - - adjustment = gtk_scrollable_get_vadjustment (scrollable); - y += gtk_adjustment_get_value (adjustment); - - if (tree->priv->drop_highlight == NULL) { - tree->priv->drop_highlight = gnome_canvas_item_new ( - gnome_canvas_root (tree->priv->table_canvas), - gnome_canvas_rect_get_type (), - "fill_color", NULL, - "outline_color_gdk", &style->fg[GTK_STATE_NORMAL], - NULL); - } - - gnome_canvas_item_set ( - tree->priv->drop_highlight, - "x1", (gdouble) x, - "x2", (gdouble) x + width - 1, - "y1", (gdouble) y, - "y2", (gdouble) y + height - 1, - NULL); - } else { - g_object_run_dispose (G_OBJECT (tree->priv->drop_highlight)); - tree->priv->drop_highlight = NULL; - } -} - -void -e_tree_drag_unhighlight (ETree *tree) -{ - g_return_if_fail (tree != NULL); - g_return_if_fail (E_IS_TREE (tree)); - - if (tree->priv->drop_highlight) { - g_object_run_dispose (G_OBJECT (tree->priv->drop_highlight)); - tree->priv->drop_highlight = NULL; - } -} - -void e_tree_drag_dest_set (ETree *tree, - GtkDestDefaults flags, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions) -{ - g_return_if_fail (tree != NULL); - g_return_if_fail (E_IS_TREE (tree)); - - gtk_drag_dest_set ( - GTK_WIDGET (tree), - flags, - targets, - n_targets, - actions); -} - -void e_tree_drag_dest_set_proxy (ETree *tree, - GdkWindow *proxy_window, - GdkDragProtocol protocol, - gboolean use_coordinates) -{ - g_return_if_fail (tree != NULL); - g_return_if_fail (E_IS_TREE (tree)); - - gtk_drag_dest_set_proxy ( - GTK_WIDGET (tree), - proxy_window, - protocol, - use_coordinates); -} - -/* - * There probably should be functions for setting the targets - * as a GtkTargetList - */ - -void -e_tree_drag_dest_unset (GtkWidget *widget) -{ - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_TREE (widget)); - - gtk_drag_dest_unset (widget); -} - -/* Source side */ - -static gint -et_real_start_drag (ETree *tree, - gint row, - ETreePath path, - gint col, - GdkEvent *event) -{ - GtkDragSourceInfo *info; - GdkDragContext *context; - ETreeDragSourceSite *site; - - if (tree->priv->do_drag) { - site = tree->priv->site; - - site->state = 0; - context = e_tree_drag_begin ( - tree, row, col, - site->target_list, - site->actions, - 1, event); - - if (context) { - info = g_dataset_get_data (context, "gtk-info"); - - if (info && !info->icon_window) { - if (site->pixbuf) - gtk_drag_set_icon_pixbuf ( - context, - site->pixbuf, - -2, -2); - else - gtk_drag_set_icon_default (context); - } - } - return TRUE; - } - return FALSE; -} - -void -e_tree_drag_source_set (ETree *tree, - GdkModifierType start_button_mask, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions) -{ - ETreeDragSourceSite *site; - GtkWidget *canvas; - - g_return_if_fail (tree != NULL); - g_return_if_fail (E_IS_TREE (tree)); - - canvas = GTK_WIDGET (tree->priv->table_canvas); - site = tree->priv->site; - - tree->priv->do_drag = TRUE; - - gtk_widget_add_events ( - canvas, - gtk_widget_get_events (canvas) | - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | - GDK_BUTTON_MOTION_MASK | GDK_STRUCTURE_MASK); - - if (site) { - if (site->target_list) - gtk_target_list_unref (site->target_list); - } else { - site = g_new0 (ETreeDragSourceSite, 1); - tree->priv->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_tree_drag_source_unset (ETree *tree) -{ - ETreeDragSourceSite *site; - - g_return_if_fail (tree != NULL); - g_return_if_fail (E_IS_TREE (tree)); - - site = tree->priv->site; - - if (site) { - if (site->target_list) - gtk_target_list_unref (site->target_list); - g_free (site); - tree->priv->site = NULL; - } -} - -/* There probably should be functions for setting the targets - * as a GtkTargetList - */ - -GdkDragContext * -e_tree_drag_begin (ETree *tree, - gint row, - gint col, - GtkTargetList *targets, - GdkDragAction actions, - gint button, - GdkEvent *event) -{ - ETreePath path; - g_return_val_if_fail (tree != NULL, NULL); - g_return_val_if_fail (E_IS_TREE (tree), NULL); - - path = e_tree_table_adapter_node_at_row (tree->priv->etta, row); - - tree->priv->drag_row = row; - tree->priv->drag_path = path; - tree->priv->drag_col = col; - - return gtk_drag_begin ( - GTK_WIDGET (tree->priv->table_canvas), - targets, - actions, - button, - event); -} - -/** - * e_tree_is_dragging: - * @tree: An #ETree widget - * - * Returns whether is @tree in a drag&drop operation. - **/ -gboolean -e_tree_is_dragging (ETree *tree) -{ - g_return_val_if_fail (tree != NULL, FALSE); - g_return_val_if_fail (tree->priv != NULL, FALSE); - - return tree->priv->is_dragging; -} - -/** - * e_tree_get_cell_at: - * @tree: An ETree widget - * @x: X coordinate for the pixel - * @y: Y coordinate for the pixel - * @row_return: Pointer to return the row value - * @col_return: Pointer to return the column value - * - * Return the row and column for the cell in which the pixel at (@x, @y) is - * contained. - **/ -void -e_tree_get_cell_at (ETree *tree, - gint x, - gint y, - gint *row_return, - gint *col_return) -{ - GtkAdjustment *adjustment; - GtkScrollable *scrollable; - - g_return_if_fail (E_IS_TREE (tree)); - g_return_if_fail (row_return != NULL); - g_return_if_fail (col_return != NULL); - - /* FIXME it would be nice if it could handle a NULL row_return or - * col_return gracefully. */ - - if (row_return) - *row_return = -1; - if (col_return) - *col_return = -1; - - scrollable = GTK_SCROLLABLE (tree->priv->table_canvas); - - adjustment = gtk_scrollable_get_hadjustment (scrollable); - x += gtk_adjustment_get_value (adjustment); - - adjustment = gtk_scrollable_get_vadjustment (scrollable); - y += gtk_adjustment_get_value (adjustment); - - e_table_item_compute_location ( - E_TABLE_ITEM (tree->priv->item), - &x, &y, row_return, col_return); -} - -/** - * e_tree_get_cell_geometry: - * @tree: The tree. - * @row: The row to get the geometry of. - * @col: The col to get the geometry of. - * @x_return: Returns the x coordinate of the upper right hand corner - * of the cell with respect to the widget. - * @y_return: Returns the y coordinate of the upper right hand corner - * of the cell with respect to the widget. - * @width_return: Returns the width of the cell. - * @height_return: Returns the height of the cell. - * - * Computes the data about this cell. - **/ -void -e_tree_get_cell_geometry (ETree *tree, - gint row, - gint col, - gint *x_return, - gint *y_return, - gint *width_return, - gint *height_return) -{ - GtkAdjustment *adjustment; - GtkScrollable *scrollable; - - g_return_if_fail (E_IS_TREE (tree)); - g_return_if_fail (row >= 0); - g_return_if_fail (col >= 0); - - /* FIXME it would be nice if it could handle a NULL row_return or - * col_return gracefully. */ - - e_table_item_get_cell_geometry ( - E_TABLE_ITEM (tree->priv->item), - &row, &col, x_return, y_return, - width_return, height_return); - - scrollable = GTK_SCROLLABLE (tree->priv->table_canvas); - - if (x_return) { - adjustment = gtk_scrollable_get_hadjustment (scrollable); - (*x_return) -= gtk_adjustment_get_value (adjustment); - } - - if (y_return) { - adjustment = gtk_scrollable_get_vadjustment (scrollable); - (*y_return) -= gtk_adjustment_get_value (adjustment); - } -} - -static void -et_drag_begin (GtkWidget *widget, - GdkDragContext *context, - ETree *et) -{ - et->priv->is_dragging = TRUE; - - g_signal_emit ( - et, - et_signals[TREE_DRAG_BEGIN], 0, - et->priv->drag_row, - et->priv->drag_path, - et->priv->drag_col, - context); -} - -static void -et_drag_end (GtkWidget *widget, - GdkDragContext *context, - ETree *et) -{ - et->priv->is_dragging = FALSE; - - g_signal_emit ( - et, - et_signals[TREE_DRAG_END], 0, - et->priv->drag_row, - et->priv->drag_path, - et->priv->drag_col, - context); -} - -static void -et_drag_data_get (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - ETree *et) -{ - g_signal_emit ( - et, - et_signals[TREE_DRAG_DATA_GET], 0, - et->priv->drag_row, - et->priv->drag_path, - et->priv->drag_col, - context, - selection_data, - info, - time); -} - -static void -et_drag_data_delete (GtkWidget *widget, - GdkDragContext *context, - ETree *et) -{ - g_signal_emit ( - et, - et_signals[TREE_DRAG_DATA_DELETE], 0, - et->priv->drag_row, - et->priv->drag_path, - et->priv->drag_col, - context); -} - -static gboolean -do_drag_motion (ETree *et, - GdkDragContext *context, - gint x, - gint y, - guint time) -{ - gboolean ret_val = FALSE; - gint row, col; - ETreePath path; - - e_tree_get_cell_at (et, x, y, &row, &col); - - if (row != et->priv->drop_row && col != et->priv->drop_col) { - g_signal_emit ( - et, et_signals[TREE_DRAG_LEAVE], 0, - et->priv->drop_row, - et->priv->drop_path, - et->priv->drop_col, - context, - time); - } - - path = e_tree_table_adapter_node_at_row (et->priv->etta, row); - - et->priv->drop_row = row; - et->priv->drop_path = path; - et->priv->drop_col = col; - g_signal_emit ( - et, et_signals[TREE_DRAG_MOTION], 0, - et->priv->drop_row, - et->priv->drop_path, - et->priv->drop_col, - context, - x, y, - time, - &ret_val); - - return ret_val; -} - -static gboolean -scroll_timeout (gpointer data) -{ - ETree *et = data; - gint dx = 0, dy = 0; - GtkAdjustment *adjustment; - GtkScrollable *scrollable; - gdouble old_h_value; - gdouble new_h_value; - gdouble old_v_value; - gdouble new_v_value; - gdouble page_size; - gdouble lower; - gdouble upper; - - if (et->priv->scroll_direction & ET_SCROLL_DOWN) - dy += 20; - if (et->priv->scroll_direction & ET_SCROLL_UP) - dy -= 20; - - if (et->priv->scroll_direction & ET_SCROLL_RIGHT) - dx += 20; - if (et->priv->scroll_direction & ET_SCROLL_LEFT) - dx -= 20; - - scrollable = GTK_SCROLLABLE (et->priv->table_canvas); - - adjustment = gtk_scrollable_get_hadjustment (scrollable); - - page_size = gtk_adjustment_get_page_size (adjustment); - lower = gtk_adjustment_get_lower (adjustment); - upper = gtk_adjustment_get_upper (adjustment); - - old_h_value = gtk_adjustment_get_value (adjustment); - new_h_value = CLAMP (old_h_value + dx, lower, upper - page_size); - - gtk_adjustment_set_value (adjustment, new_h_value); - - adjustment = gtk_scrollable_get_vadjustment (scrollable); - - page_size = gtk_adjustment_get_page_size (adjustment); - lower = gtk_adjustment_get_lower (adjustment); - upper = gtk_adjustment_get_upper (adjustment); - - old_v_value = gtk_adjustment_get_value (adjustment); - new_v_value = CLAMP (old_v_value + dy, lower, upper - page_size); - - gtk_adjustment_set_value (adjustment, new_v_value); - - if (new_h_value != old_h_value || new_v_value != old_v_value) - do_drag_motion ( - et, - et->priv->last_drop_context, - et->priv->last_drop_x, - et->priv->last_drop_y, - et->priv->last_drop_time); - - return TRUE; -} - -static void -scroll_on (ETree *et, - guint scroll_direction) -{ - if (et->priv->scroll_idle_id == 0 || - scroll_direction != et->priv->scroll_direction) { - if (et->priv->scroll_idle_id != 0) - g_source_remove (et->priv->scroll_idle_id); - et->priv->scroll_direction = scroll_direction; - et->priv->scroll_idle_id = g_timeout_add (100, scroll_timeout, et); - } -} - -static void -scroll_off (ETree *et) -{ - if (et->priv->scroll_idle_id) { - g_source_remove (et->priv->scroll_idle_id); - et->priv->scroll_idle_id = 0; - } -} - -static gboolean -hover_timeout (gpointer data) -{ - ETree *et = data; - gint x = et->priv->hover_x; - gint y = et->priv->hover_y; - gint row, col; - ETreePath path; - - e_tree_get_cell_at (et, x, y, &row, &col); - - path = e_tree_table_adapter_node_at_row (et->priv->etta, row); - if (path && e_tree_model_node_is_expandable (et->priv->model, path)) { - if (!e_tree_table_adapter_node_is_expanded (et->priv->etta, path)) { - if (e_tree_model_has_save_id (et->priv->model) && - e_tree_model_has_get_node_by_id (et->priv->model)) - et->priv->expanded_list = g_list_prepend ( - et->priv->expanded_list, - e_tree_model_get_save_id ( - et->priv->model, path)); - - e_tree_table_adapter_node_set_expanded ( - et->priv->etta, path, TRUE); - } - } - - return TRUE; -} - -static void -hover_on (ETree *et, - gint x, - gint y) -{ - et->priv->hover_x = x; - et->priv->hover_y = y; - if (et->priv->hover_idle_id != 0) - g_source_remove (et->priv->hover_idle_id); - et->priv->hover_idle_id = g_timeout_add (500, hover_timeout, et); -} - -static void -hover_off (ETree *et) -{ - if (et->priv->hover_idle_id) { - g_source_remove (et->priv->hover_idle_id); - et->priv->hover_idle_id = 0; - } -} - -static void -collapse_drag (ETree *et, - ETreePath drop) -{ - GList *list; - - /* We only want to leave open parents of the node dropped in. - * Not the node itself. */ - if (drop) { - drop = e_tree_model_node_get_parent (et->priv->model, drop); - } - - for (list = et->priv->expanded_list; list; list = list->next) { - gchar *save_id = list->data; - ETreePath path; - - path = e_tree_model_get_node_by_id (et->priv->model, save_id); - if (path) { - ETreePath search; - gboolean found = FALSE; - - for (search = drop; search; - search = e_tree_model_node_get_parent ( - et->priv->model, search)) { - if (path == search) { - found = TRUE; - break; - } - } - - if (!found) - e_tree_table_adapter_node_set_expanded ( - et->priv->etta, path, FALSE); - } - g_free (save_id); - } - g_list_free (et->priv->expanded_list); - et->priv->expanded_list = NULL; -} - -static void -context_destroyed (gpointer data, - GObject *ctx) -{ - ETree *et = data; - if (et->priv) { - et->priv->last_drop_x = 0; - et->priv->last_drop_y = 0; - et->priv->last_drop_time = 0; - et->priv->last_drop_context = NULL; - collapse_drag (et, NULL); - scroll_off (et); - hover_off (et); - } - g_object_unref (et); -} - -static void -context_connect (ETree *et, - GdkDragContext *context) -{ - if (context == et->priv->last_drop_context) - return; - - if (et->priv->last_drop_context) - g_object_weak_unref ( - G_OBJECT (et->priv->last_drop_context), - context_destroyed, et); - else - g_object_ref (et); - - g_object_weak_ref (G_OBJECT (context), context_destroyed, et); -} - -static void -et_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time, - ETree *et) -{ - g_signal_emit ( - et, - et_signals[TREE_DRAG_LEAVE], 0, - et->priv->drop_row, - et->priv->drop_path, - et->priv->drop_col, - context, - time); - et->priv->drop_row = -1; - et->priv->drop_col = -1; - - scroll_off (et); - hover_off (et); -} - -static gboolean -et_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETree *et) -{ - GtkAllocation allocation; - gint ret_val; - guint direction = 0; - - et->priv->last_drop_x = x; - et->priv->last_drop_y = y; - et->priv->last_drop_time = time; - context_connect (et, context); - et->priv->last_drop_context = context; - - if (et->priv->hover_idle_id != 0) { - if (abs (et->priv->hover_x - x) > 3 || - abs (et->priv->hover_y - y) > 3) { - hover_on (et, x, y); - } - } else { - hover_on (et, x, y); - } - - ret_val = do_drag_motion (et, context, x, y, time); - - gtk_widget_get_allocation (widget, &allocation); - - if (y < 20) - direction |= ET_SCROLL_UP; - if (y > allocation.height - 20) - direction |= ET_SCROLL_DOWN; - if (x < 20) - direction |= ET_SCROLL_LEFT; - if (x > allocation.width - 20) - direction |= ET_SCROLL_RIGHT; - - if (direction != 0) - scroll_on (et, direction); - else - scroll_off (et); - - return ret_val; -} - -static gboolean -et_drag_drop (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETree *et) -{ - gboolean ret_val = FALSE; - gint row, col; - ETreePath path; - - e_tree_get_cell_at (et, x, y, &row, &col); - - path = e_tree_table_adapter_node_at_row (et->priv->etta, row); - - if (row != et->priv->drop_row && col != et->priv->drop_row) { - g_signal_emit ( - et, et_signals[TREE_DRAG_LEAVE], 0, - et->priv->drop_row, - et->priv->drop_path, - et->priv->drop_col, - context, - time); - g_signal_emit ( - et, et_signals[TREE_DRAG_MOTION], 0, - row, - path, - col, - context, - x, - y, - time, - &ret_val); - } - et->priv->drop_row = row; - et->priv->drop_path = path; - et->priv->drop_col = col; - - g_signal_emit ( - et, et_signals[TREE_DRAG_DROP], 0, - et->priv->drop_row, - et->priv->drop_path, - et->priv->drop_col, - context, - x, - y, - time, - &ret_val); - - et->priv->drop_row = -1; - et->priv->drop_path = NULL; - et->priv->drop_col = -1; - - collapse_drag (et, path); - - scroll_off (et); - return ret_val; -} - -static void -et_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time, - ETree *et) -{ - gint row, col; - ETreePath path; - - e_tree_get_cell_at (et, x, y, &row, &col); - - path = e_tree_table_adapter_node_at_row (et->priv->etta, row); - g_signal_emit ( - et, et_signals[TREE_DRAG_DATA_RECEIVED], 0, - row, - path, - col, - context, - x, - y, - selection_data, - info, - time); -} - -static void -e_tree_class_init (ETreeClass *class) -{ - GObjectClass *object_class; - GtkWidgetClass *widget_class; - - g_type_class_add_private (class, sizeof (ETreePrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->dispose = et_dispose; - object_class->set_property = et_set_property; - object_class->get_property = et_get_property; - - widget_class = GTK_WIDGET_CLASS (class); - widget_class->grab_focus = et_grab_focus; - widget_class->unrealize = et_unrealize; - widget_class->style_set = et_canvas_style_set; - widget_class->focus = et_focus; - - class->start_drag = et_real_start_drag; - - et_signals[CURSOR_CHANGE] = g_signal_new ( - "cursor_change", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeClass, cursor_change), - NULL, NULL, - e_marshal_NONE__INT_POINTER, - G_TYPE_NONE, 2, - G_TYPE_INT, - G_TYPE_POINTER); - - et_signals[CURSOR_ACTIVATED] = g_signal_new ( - "cursor_activated", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeClass, cursor_activated), - NULL, NULL, - e_marshal_NONE__INT_POINTER, - G_TYPE_NONE, 2, - G_TYPE_INT, - G_TYPE_POINTER); - - et_signals[SELECTION_CHANGE] = g_signal_new ( - "selection_change", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeClass, selection_change), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - et_signals[DOUBLE_CLICK] = g_signal_new ( - "double_click", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeClass, double_click), - NULL, NULL, - e_marshal_NONE__INT_POINTER_INT_BOXED, - G_TYPE_NONE, 4, - G_TYPE_INT, - G_TYPE_POINTER, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - et_signals[RIGHT_CLICK] = g_signal_new ( - "right_click", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeClass, right_click), - g_signal_accumulator_true_handled, NULL, - e_marshal_BOOLEAN__INT_POINTER_INT_BOXED, - G_TYPE_BOOLEAN, 4, - G_TYPE_INT, - G_TYPE_POINTER, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - et_signals[CLICK] = g_signal_new ( - "click", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeClass, click), - g_signal_accumulator_true_handled, NULL, - e_marshal_BOOLEAN__INT_POINTER_INT_BOXED, - G_TYPE_BOOLEAN, 4, - G_TYPE_INT, - G_TYPE_POINTER, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - et_signals[KEY_PRESS] = g_signal_new ( - "key_press", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeClass, key_press), - g_signal_accumulator_true_handled, NULL, - e_marshal_BOOLEAN__INT_POINTER_INT_BOXED, - G_TYPE_BOOLEAN, 4, - G_TYPE_INT, - G_TYPE_POINTER, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - et_signals[START_DRAG] = g_signal_new ( - "start_drag", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeClass, start_drag), - NULL, NULL, - e_marshal_NONE__INT_POINTER_INT_BOXED, - G_TYPE_NONE, 4, - G_TYPE_INT, - G_TYPE_POINTER, - G_TYPE_INT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - et_signals[STATE_CHANGE] = g_signal_new ( - "state_change", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeClass, state_change), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - et_signals[WHITE_SPACE_EVENT] = g_signal_new ( - "white_space_event", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeClass, white_space_event), - g_signal_accumulator_true_handled, NULL, - e_marshal_BOOLEAN__POINTER, - G_TYPE_BOOLEAN, 1, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - et_signals[TREE_DRAG_BEGIN] = g_signal_new ( - "tree_drag_begin", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeClass, tree_drag_begin), - NULL, NULL, - e_marshal_NONE__INT_POINTER_INT_BOXED, - G_TYPE_NONE, 4, - G_TYPE_INT, - G_TYPE_POINTER, - G_TYPE_INT, - GDK_TYPE_DRAG_CONTEXT); - - et_signals[TREE_DRAG_END] = g_signal_new ( - "tree_drag_end", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeClass, tree_drag_end), - NULL, NULL, - e_marshal_NONE__INT_POINTER_INT_BOXED, - G_TYPE_NONE, 4, - G_TYPE_INT, - G_TYPE_POINTER, - G_TYPE_INT, - GDK_TYPE_DRAG_CONTEXT); - - et_signals[TREE_DRAG_DATA_GET] = g_signal_new ( - "tree_drag_data_get", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeClass, tree_drag_data_get), - NULL, NULL, - e_marshal_NONE__INT_POINTER_INT_OBJECT_BOXED_UINT_UINT, - G_TYPE_NONE, 7, - G_TYPE_INT, - G_TYPE_POINTER, - G_TYPE_INT, - GDK_TYPE_DRAG_CONTEXT, - GTK_TYPE_SELECTION_DATA | G_SIGNAL_TYPE_STATIC_SCOPE, - G_TYPE_UINT, - G_TYPE_UINT); - - et_signals[TREE_DRAG_DATA_DELETE] = g_signal_new ( - "tree_drag_data_delete", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeClass, tree_drag_data_delete), - NULL, NULL, - e_marshal_NONE__INT_POINTER_INT_OBJECT, - G_TYPE_NONE, 4, - G_TYPE_INT, - G_TYPE_POINTER, - G_TYPE_INT, - GDK_TYPE_DRAG_CONTEXT); - - et_signals[TREE_DRAG_LEAVE] = g_signal_new ( - "tree_drag_leave", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeClass, tree_drag_leave), - NULL, NULL, - e_marshal_NONE__INT_POINTER_INT_OBJECT_UINT, - G_TYPE_NONE, 5, - G_TYPE_INT, - G_TYPE_POINTER, - G_TYPE_INT, - GDK_TYPE_DRAG_CONTEXT, - G_TYPE_UINT); - - et_signals[TREE_DRAG_MOTION] = g_signal_new ( - "tree_drag_motion", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeClass, tree_drag_motion), - NULL, NULL, - e_marshal_BOOLEAN__INT_POINTER_INT_OBJECT_INT_INT_UINT, - G_TYPE_BOOLEAN, 7, - G_TYPE_INT, - G_TYPE_POINTER, - G_TYPE_INT, - GDK_TYPE_DRAG_CONTEXT, - G_TYPE_INT, - G_TYPE_INT, - G_TYPE_UINT); - - et_signals[TREE_DRAG_DROP] = g_signal_new ( - "tree_drag_drop", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeClass, tree_drag_drop), - NULL, NULL, - e_marshal_BOOLEAN__INT_POINTER_INT_OBJECT_INT_INT_UINT, - G_TYPE_BOOLEAN, 7, - G_TYPE_INT, - G_TYPE_POINTER, - G_TYPE_INT, - GDK_TYPE_DRAG_CONTEXT, - G_TYPE_INT, - G_TYPE_INT, - G_TYPE_UINT); - - et_signals[TREE_DRAG_DATA_RECEIVED] = g_signal_new ( - "tree_drag_data_received", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETreeClass, tree_drag_data_received), - NULL, NULL, - e_marshal_NONE__INT_POINTER_INT_OBJECT_INT_INT_BOXED_UINT_UINT, - G_TYPE_NONE, 9, - G_TYPE_INT, - G_TYPE_POINTER, - G_TYPE_INT, - GDK_TYPE_DRAG_CONTEXT, - G_TYPE_INT, - G_TYPE_INT, - GTK_TYPE_SELECTION_DATA, - G_TYPE_UINT, - G_TYPE_UINT); - - g_object_class_install_property ( - object_class, - PROP_LENGTH_THRESHOLD, - g_param_spec_int ( - "length_threshold", - "Length Threshold", - "Length Threshold", - 0, G_MAXINT, 0, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_HORIZONTAL_DRAW_GRID, - g_param_spec_boolean ( - "horizontal_draw_grid", - "Horizontal Draw Grid", - "Horizontal Draw Grid", - FALSE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_VERTICAL_DRAW_GRID, - g_param_spec_boolean ( - "vertical_draw_grid", - "Vertical Draw Grid", - "Vertical Draw Grid", - FALSE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_DRAW_FOCUS, - g_param_spec_boolean ( - "drawfocus", - "Draw focus", - "Draw focus", - FALSE, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - object_class, - PROP_ETTA, - g_param_spec_object ( - "ETreeTableAdapter", - "ETree table adapter", - "ETree table adapter", - E_TYPE_TREE_TABLE_ADAPTER, - G_PARAM_READABLE)); - - g_object_class_install_property ( - object_class, - PROP_UNIFORM_ROW_HEIGHT, - g_param_spec_boolean ( - "uniform_row_height", - "Uniform row height", - "Uniform row height", - FALSE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_ALWAYS_SEARCH, - g_param_spec_boolean ( - "always_search", - "Always search", - "Always search", - FALSE, - G_PARAM_READWRITE)); - - gtk_widget_class_install_style_property ( - widget_class, - g_param_spec_int ( - "expander_size", - "Expander Size", - "Size of the expander arrow", - 0, G_MAXINT, 10, - G_PARAM_READABLE)); - - gtk_widget_class_install_style_property ( - widget_class, - g_param_spec_int ( - "vertical-spacing", - "Vertical Row Spacing", - "Vertical space between rows. " - "It is added to top and to bottom of a row", - 0, G_MAXINT, 3, - G_PARAM_READABLE | - G_PARAM_STATIC_STRINGS)); - - /* Scrollable interface */ - g_object_class_override_property ( - object_class, PROP_HADJUSTMENT, "hadjustment"); - g_object_class_override_property ( - object_class, PROP_VADJUSTMENT, "vadjustment"); - g_object_class_override_property ( - object_class, PROP_HSCROLL_POLICY, "hscroll-policy"); - g_object_class_override_property ( - object_class, PROP_VSCROLL_POLICY, "vscroll-policy"); - - gal_a11y_e_tree_init (); -} - -static void -tree_size_allocate (GtkWidget *widget, - GtkAllocation *alloc, - ETree *tree) -{ - gdouble width; - - g_return_if_fail (tree != NULL); - g_return_if_fail (tree->priv != NULL); - g_return_if_fail (tree->priv->info_text != NULL); - - gnome_canvas_get_scroll_region ( - GNOME_CANVAS (tree->priv->table_canvas), - NULL, NULL, &width, NULL); - - width -= 60.0; - - g_object_set ( - tree->priv->info_text, "width", width, - "clip_width", width, NULL); -} - -/** - * e_tree_set_info_message: - * @tree: #ETree instance - * @info_message: Message to set. Can be NULL. - * - * Creates an info message in table area, or removes old. - **/ -void -e_tree_set_info_message (ETree *tree, - const gchar *info_message) -{ - GtkAllocation allocation; - GtkWidget *widget; - - g_return_if_fail (tree != NULL); - g_return_if_fail (tree->priv != NULL); - - if (!tree->priv->info_text && (!info_message || !*info_message)) - return; - - if (!info_message || !*info_message) { - g_signal_handler_disconnect (tree, tree->priv->info_text_resize_id); - g_object_run_dispose (G_OBJECT (tree->priv->info_text)); - tree->priv->info_text = NULL; - return; - } - - widget = GTK_WIDGET (tree->priv->table_canvas); - gtk_widget_get_allocation (widget, &allocation); - - if (!tree->priv->info_text) { - if (allocation.width > 60) { - tree->priv->info_text = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (gnome_canvas_root (tree->priv->table_canvas)), - e_text_get_type (), - "line_wrap", TRUE, - "clip", TRUE, - "justification", GTK_JUSTIFY_LEFT, - "text", info_message, - "width", (gdouble) allocation.width - 60.0, - "clip_width", (gdouble) allocation.width - 60.0, - NULL); - - e_canvas_item_move_absolute (tree->priv->info_text, 30, 30); - - tree->priv->info_text_resize_id = g_signal_connect ( - tree, "size_allocate", - G_CALLBACK (tree_size_allocate), tree); - } - } else - gnome_canvas_item_set (tree->priv->info_text, "text", info_message, NULL); -} - -void -e_tree_freeze_state_change (ETree *tree) -{ - g_return_if_fail (tree != NULL); - - tree->priv->state_change_freeze++; - if (tree->priv->state_change_freeze == 1) - tree->priv->state_changed = FALSE; - - g_return_if_fail (tree->priv->state_change_freeze != 0); -} - -void -e_tree_thaw_state_change (ETree *tree) -{ - g_return_if_fail (tree != NULL); - g_return_if_fail (tree->priv->state_change_freeze != 0); - - tree->priv->state_change_freeze--; - if (tree->priv->state_change_freeze == 0 && tree->priv->state_changed) { - tree->priv->state_changed = FALSE; - e_tree_state_change (tree); - } -} diff --git a/widgets/table/e-tree.h b/widgets/table/e-tree.h deleted file mode 100644 index f3d1f9f6a7..0000000000 --- a/widgets/table/e-tree.h +++ /dev/null @@ -1,372 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_TREE_H_ -#define _E_TREE_H_ - -#include <gtk/gtk.h> -#include <libxml/tree.h> -#include <libgnomecanvas/libgnomecanvas.h> -#include <misc/e-printable.h> - -#include <table/e-table-extras.h> -#include <table/e-table-specification.h> -#include <table/e-table-state.h> -#include <table/e-tree-model.h> -#include <table/e-tree-table-adapter.h> -#include <table/e-table-item.h> - -#define E_TREE_USE_TREE_SELECTION - -#ifdef E_TREE_USE_TREE_SELECTION -#include <table/e-tree-selection-model.h> -#endif - -/* Standard GObject macros */ -#define E_TYPE_TREE \ - (e_tree_get_type ()) -#define E_TREE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_TREE, ETree)) -#define E_TREE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_TREE, ETreeClass)) -#define E_IS_TREE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_TREE)) -#define E_IS_TREE_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_TREE)) -#define E_TREE_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_TREE)) - -G_BEGIN_DECLS - -typedef struct _ETreeDragSourceSite ETreeDragSourceSite; - -typedef struct _ETree ETree; -typedef struct _ETreeClass ETreeClass; -typedef struct _ETreePrivate ETreePrivate; - -struct _ETree { - GtkTable parent; - ETreePrivate *priv; -}; - -struct _ETreeClass { - GtkTableClass parent_class; - - void (*cursor_change) (ETree *et, - gint row, - ETreePath path); - void (*cursor_activated) (ETree *et, - gint row, - ETreePath path); - void (*selection_change) (ETree *et); - void (*double_click) (ETree *et, - gint row, - ETreePath path, - gint col, - GdkEvent *event); - gboolean (*right_click) (ETree *et, - gint row, - ETreePath path, - gint col, - GdkEvent *event); - gboolean (*click) (ETree *et, - gint row, - ETreePath path, - gint col, - GdkEvent *event); - gboolean (*key_press) (ETree *et, - gint row, - ETreePath path, - gint col, - GdkEvent *event); - gboolean (*start_drag) (ETree *et, - gint row, - ETreePath path, - gint col, - GdkEvent *event); - void (*state_change) (ETree *et); - gboolean (*white_space_event) (ETree *et, - GdkEvent *event); - - /* Source side drag signals */ - void (*tree_drag_begin) (ETree *tree, - gint row, - ETreePath path, - gint col, - GdkDragContext *context); - void (*tree_drag_end) (ETree *tree, - gint row, - ETreePath path, - gint col, - GdkDragContext *context); - void (*tree_drag_data_get) (ETree *tree, - gint row, - ETreePath path, - gint col, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time); - void (*tree_drag_data_delete) - (ETree *tree, - gint row, - ETreePath path, - gint col, - GdkDragContext *context); - - /* Target side drag signals */ - void (*tree_drag_leave) (ETree *tree, - gint row, - ETreePath path, - gint col, - GdkDragContext *context, - guint time); - gboolean (*tree_drag_motion) (ETree *tree, - gint row, - ETreePath path, - gint col, - GdkDragContext *context, - gint x, - gint y, - guint time); - gboolean (*tree_drag_drop) (ETree *tree, - gint row, - ETreePath path, - gint col, - GdkDragContext *context, - gint x, - gint y, - guint time); - void (*tree_drag_data_received) - (ETree *tree, - gint row, - ETreePath path, - gint col, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time); -}; - -GType e_tree_get_type (void) G_GNUC_CONST; -gboolean e_tree_construct (ETree *e_tree, - ETreeModel *etm, - ETableExtras *ete, - const gchar *spec, - const gchar *state); -GtkWidget * e_tree_new (ETreeModel *etm, - ETableExtras *ete, - const gchar *spec, - const gchar *state); - -/* Create an ETree using files. */ -gboolean e_tree_construct_from_spec_file (ETree *e_tree, - ETreeModel *etm, - ETableExtras *ete, - const gchar *spec_fn, - const gchar *state_fn); -GtkWidget * e_tree_new_from_spec_file (ETreeModel *etm, - ETableExtras *ete, - const gchar *spec_fn, - const gchar *state_fn); - -/* To save the state */ -gchar * e_tree_get_state (ETree *e_tree); -void e_tree_save_state (ETree *e_tree, - const gchar *filename); -ETableState * e_tree_get_state_object (ETree *e_tree); -ETableSpecification * - e_tree_get_spec (ETree *e_tree); - -/* note that it is more efficient to provide the state at creation time */ -void e_tree_set_search_column (ETree *e_tree, - gint col); -void e_tree_set_state (ETree *e_tree, - const gchar *state); -void e_tree_set_state_object (ETree *e_tree, - ETableState *state); -void e_tree_load_state (ETree *e_tree, - const gchar *filename); -void e_tree_show_cursor_after_reflow (ETree *e_tree); - -void e_tree_set_cursor (ETree *e_tree, - ETreePath path); - -/* NULL means we don't have the cursor. */ -ETreePath e_tree_get_cursor (ETree *e_tree); -void e_tree_selected_row_foreach (ETree *e_tree, - EForeachFunc callback, - gpointer closure); -#ifdef E_TREE_USE_TREE_SELECTION -void e_tree_selected_path_foreach (ETree *e_tree, - ETreeForeachFunc callback, - gpointer closure); -void e_tree_path_foreach (ETree *e_tree, - ETreeForeachFunc callback, - gpointer closure); -#endif -EPrintable *e_tree_get_printable (ETree *e_tree); -gint e_tree_get_next_row (ETree *e_tree, - gint model_row); -gint e_tree_get_prev_row (ETree *e_tree, - gint model_row); -gint e_tree_model_to_view_row (ETree *e_tree, - gint model_row); -gint e_tree_view_to_model_row (ETree *e_tree, - gint view_row); -void e_tree_get_cell_at (ETree *tree, - gint x, - gint y, - gint *row_return, - gint *col_return); -void e_tree_get_cell_geometry (ETree *tree, - gint row, - gint col, - gint *x_return, - gint *y_return, - gint *width_return, - gint *height_return); - -/* Useful accessors */ -ETreeModel * e_tree_get_model (ETree *et); -ESelectionModel * - e_tree_get_selection_model (ETree *et); -ETreeTableAdapter * - e_tree_get_table_adapter (ETree *et); - -/* Drag & drop stuff. */ -/* Target */ -void e_tree_drag_get_data (ETree *tree, - gint row, - gint col, - GdkDragContext *context, - GdkAtom target, - guint32 time); -void e_tree_drag_highlight (ETree *tree, - gint row, - gint col); /* col == -1 to highlight entire row. */ -void e_tree_drag_unhighlight (ETree *tree); -void e_tree_drag_dest_set (ETree *tree, - GtkDestDefaults flags, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions); -void e_tree_drag_dest_set_proxy (ETree *tree, - GdkWindow *proxy_window, - GdkDragProtocol protocol, - gboolean use_coordinates); - -/* There probably should be functions for setting the targets - * as a GtkTargetList - */ -void e_tree_drag_dest_unset (GtkWidget *widget); - -/* Source side */ -void e_tree_drag_source_set (ETree *tree, - GdkModifierType start_button_mask, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions); -void e_tree_drag_source_unset (ETree *tree); - -/* There probably should be functions for setting the targets - * as a GtkTargetList - */ -GdkDragContext *e_tree_drag_begin (ETree *tree, - gint row, - gint col, - GtkTargetList *targets, - GdkDragAction actions, - gint button, - GdkEvent *event); - -gboolean e_tree_is_dragging (ETree *tree); - -/* Adapter functions */ -gboolean e_tree_node_is_expanded (ETree *et, - ETreePath path); -void e_tree_node_set_expanded (ETree *et, - ETreePath path, - gboolean expanded); -void e_tree_node_set_expanded_recurse - (ETree *et, - ETreePath path, - gboolean expanded); -void e_tree_root_node_set_visible (ETree *et, - gboolean visible); -ETreePath e_tree_node_at_row (ETree *et, - gint row); -gint e_tree_row_of_node (ETree *et, - ETreePath path); -gboolean e_tree_root_node_is_visible (ETree *et); -void e_tree_show_node (ETree *et, - ETreePath path); -void e_tree_save_expanded_state (ETree *et, - gchar *filename); -void e_tree_load_expanded_state (ETree *et, - gchar *filename); - -xmlDoc * e_tree_save_expanded_state_xml (ETree *et); -void e_tree_load_expanded_state_xml (ETree *et, - xmlDoc *doc); - -gint e_tree_row_count (ETree *et); -GtkWidget * e_tree_get_tooltip (ETree *et); -void e_tree_force_expanded_state (ETree *et, - gint state); - -typedef enum { - E_TREE_FIND_NEXT_BACKWARD = 0, - E_TREE_FIND_NEXT_FORWARD = 1 << 0, - E_TREE_FIND_NEXT_WRAP = 1 << 1 -} ETreeFindNextParams; - -gboolean e_tree_find_next (ETree *et, - ETreeFindNextParams params, - ETreePathFunc func, - gpointer data); - -/* This function is only needed in single_selection_mode. */ -void e_tree_right_click_up (ETree *et); - -ETableItem * e_tree_get_item (ETree *et); - -GnomeCanvasItem * - e_tree_get_header_item (ETree *et); - -void e_tree_set_info_message (ETree *tree, - const gchar *info_message); - -void e_tree_freeze_state_change (ETree *table); -void e_tree_thaw_state_change (ETree *table); - -G_END_DECLS - -#endif /* _E_TREE_H_ */ - diff --git a/widgets/table/gal-a11y-e-cell-popup.c b/widgets/table/gal-a11y-e-cell-popup.c deleted file mode 100644 index 1c97ee3198..0000000000 --- a/widgets/table/gal-a11y-e-cell-popup.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Yang Wu <yang.wu@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gdk/gdkkeysyms.h> -#include <gtk/gtk.h> - -#include "a11y/gal-a11y-util.h" -#include "table/e-cell-popup.h" -#include <glib/gi18n.h> - -#include "gal-a11y-e-cell-popup.h" -#include "gal-a11y-e-cell-registry.h" - -static AtkObjectClass *parent_class = NULL; -#define PARENT_TYPE (gal_a11y_e_cell_get_type ()) - -static void gal_a11y_e_cell_popup_class_init (GalA11yECellPopupClass *class); -static void popup_cell_action (GalA11yECell *cell); - -/** - * gal_a11y_e_cell_popup_get_type: - * @void: - * - * Registers the &GalA11yECellPopup class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &GalA11yECellPopup class. - **/ -GType -gal_a11y_e_cell_popup_get_type (void) -{ - static GType type = 0; - - if (!type) { - GTypeInfo info = { - sizeof (GalA11yECellPopupClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) gal_a11y_e_cell_popup_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GalA11yECellPopup), - 0, - (GInstanceInitFunc) NULL, - NULL /* value_cell_popup */ - }; - - type = g_type_register_static (PARENT_TYPE, "GalA11yECellPopup", &info, 0); - gal_a11y_e_cell_type_add_action_interface (type); - } - - return type; -} - -static void -gal_a11y_e_cell_popup_class_init (GalA11yECellPopupClass *class) -{ - parent_class = g_type_class_ref (PARENT_TYPE); -} - -AtkObject * -gal_a11y_e_cell_popup_new (ETableItem *item, - ECellView *cell_view, - AtkObject *parent, - gint model_col, - gint view_col, - gint row) -{ - AtkObject *a11y; - GalA11yECell *cell; - ECellPopup *popupcell; - ECellView * child_view = NULL; - - popupcell= E_CELL_POPUP (cell_view->ecell); - - if (popupcell && popupcell->popup_cell_view) - child_view = popupcell->popup_cell_view->child_view; - - if (child_view && child_view->ecell) { - a11y = gal_a11y_e_cell_registry_get_object ( - NULL, - item, - child_view, - parent, - model_col, - view_col, - row); - } else { - a11y = g_object_new (GAL_A11Y_TYPE_E_CELL_POPUP, NULL); - gal_a11y_e_cell_construct ( - a11y, - item, - cell_view, - parent, - model_col, - view_col, - row); - } - g_return_val_if_fail (a11y != NULL, NULL); - cell = GAL_A11Y_E_CELL (a11y); - gal_a11y_e_cell_add_action ( - cell, - "popup", - /* Translators: description of a "popup" action */ - _("popup a child"), - "<Alt>Down", /* action keybinding */ - popup_cell_action); - - a11y->role = ATK_ROLE_TABLE_CELL; - return a11y; -} - -static void -popup_cell_action (GalA11yECell *cell) -{ - gint finished; - GdkEvent event; - GtkLayout *layout; - - layout = GTK_LAYOUT (GNOME_CANVAS_ITEM (cell->item)->canvas); - - event.key.type = GDK_KEY_PRESS; - event.key.window = gtk_layout_get_bin_window (layout); - event.key.send_event = TRUE; - event.key.time = GDK_CURRENT_TIME; - event.key.state = GDK_MOD1_MASK; - event.key.keyval = GDK_KEY_Down; - - g_signal_emit_by_name (cell->item, "event", &event, &finished); -} diff --git a/widgets/table/gal-a11y-e-cell-popup.h b/widgets/table/gal-a11y-e-cell-popup.h deleted file mode 100644 index fdf20802a1..0000000000 --- a/widgets/table/gal-a11y-e-cell-popup.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Yang Wu <yang.wu@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __GAL_A11Y_E_CELL_POPUP_H__ -#define __GAL_A11Y_E_CELL_POPUP_H__ - -#include <table/e-table-item.h> -#include <table/gal-a11y-e-cell.h> -#include <atk/atkgobjectaccessible.h> - -#define GAL_A11Y_TYPE_E_CELL_POPUP (gal_a11y_e_cell_popup_get_type ()) -#define GAL_A11Y_E_CELL_POPUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAL_A11Y_TYPE_E_CELL_POPUP, GalA11yECellPopup)) -#define GAL_A11Y_E_CELL_POPUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAL_A11Y_TYPE_E_CELL_POPUP, GalA11yECellPopupClass)) -#define GAL_A11Y_IS_E_CELL_POPUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAL_A11Y_TYPE_E_CELL_POPUP)) -#define GAL_A11Y_IS_E_CELL_POPUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAL_A11Y_TYPE_E_CELL_POPUP)) - -typedef struct _GalA11yECellPopup GalA11yECellPopup; -typedef struct _GalA11yECellPopupClass GalA11yECellPopupClass; - -/* This struct should actually be larger as this isn't what we derive from. - * The GalA11yECellPopupPrivate comes right after the parent class structure. - **/ -struct _GalA11yECellPopup { - GalA11yECell object; -}; - -struct _GalA11yECellPopupClass { - GalA11yECellClass parent_class; -}; - -/* Standard Glib function */ -GType gal_a11y_e_cell_popup_get_type (void); -AtkObject *gal_a11y_e_cell_popup_new (ETableItem *item, - ECellView *cell_view, - AtkObject *parent, - gint model_col, - gint view_col, - gint row); - -#endif /* __GAL_A11Y_E_CELL_POPUP_H__ */ diff --git a/widgets/table/gal-a11y-e-cell-registry.c b/widgets/table/gal-a11y-e-cell-registry.c deleted file mode 100644 index db05ac05c1..0000000000 --- a/widgets/table/gal-a11y-e-cell-registry.c +++ /dev/null @@ -1,151 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Christopher James Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "gal-a11y-e-cell.h" -#include "gal-a11y-e-cell-registry.h" - -static GObjectClass *parent_class; -static GalA11yECellRegistry *default_registry; -#define PARENT_TYPE (G_TYPE_OBJECT) - -struct _GalA11yECellRegistryPrivate { - GHashTable *table; -}; - -/* Static functions */ - -static void -gal_a11y_e_cell_registry_finalize (GObject *obj) -{ - GalA11yECellRegistry *registry = GAL_A11Y_E_CELL_REGISTRY (obj); - - g_hash_table_destroy (registry->priv->table); - g_free (registry->priv); - - G_OBJECT_CLASS (parent_class)->finalize (obj); -} - -static void -gal_a11y_e_cell_registry_class_init (GalA11yECellRegistryClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - parent_class = g_type_class_ref (PARENT_TYPE); - - object_class->finalize = gal_a11y_e_cell_registry_finalize; -} - -static void -gal_a11y_e_cell_registry_init (GalA11yECellRegistry *registry) -{ - registry->priv = g_new (GalA11yECellRegistryPrivate, 1); - registry->priv->table = g_hash_table_new (NULL, NULL); -} - -/** - * gal_a11y_e_cell_registry_get_type: - * @void: - * - * Registers the &GalA11yECellRegistry class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &GalA11yECellRegistry class. - **/ -GType -gal_a11y_e_cell_registry_get_type (void) -{ - static GType type = 0; - - if (!type) { - GTypeInfo info = { - sizeof (GalA11yECellRegistryClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) gal_a11y_e_cell_registry_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GalA11yECellRegistry), - 0, - (GInstanceInitFunc) gal_a11y_e_cell_registry_init, - NULL /* value_cell */ - }; - - type = g_type_register_static ( - PARENT_TYPE, "GalA11yECellRegistry", &info, 0); - } - - return type; -} - -static void -init_default_registry (void) -{ - if (default_registry == NULL) { - default_registry = g_object_new (gal_a11y_e_cell_registry_get_type (), NULL); - } -} - -AtkObject * -gal_a11y_e_cell_registry_get_object (GalA11yECellRegistry *registry, - ETableItem *item, - ECellView *cell_view, - AtkObject *parent, - gint model_col, - gint view_col, - gint row) -{ - GalA11yECellRegistryFunc func = NULL; - GType type; - - if (registry == NULL) { - init_default_registry (); - registry = default_registry; - } - - type = G_OBJECT_TYPE (cell_view->ecell); - while (func == NULL && type != 0) { - func = g_hash_table_lookup (registry->priv->table, GINT_TO_POINTER (type)); - type = g_type_parent (type); - } - - if (func == NULL) - func = gal_a11y_e_cell_new; - - return func (item, cell_view, parent, model_col, view_col, row); -} - -void -gal_a11y_e_cell_registry_add_cell_type (GalA11yECellRegistry *registry, - GType type, - GalA11yECellRegistryFunc func) -{ - if (registry == NULL) { - init_default_registry (); - registry = default_registry; - } - - g_hash_table_insert (registry->priv->table, GINT_TO_POINTER (type), func); -} diff --git a/widgets/table/gal-a11y-e-cell-registry.h b/widgets/table/gal-a11y-e-cell-registry.h deleted file mode 100644 index de8b21b701..0000000000 --- a/widgets/table/gal-a11y-e-cell-registry.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Christopher James Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __GAL_A11Y_E_CELL_REGISTRY_H__ -#define __GAL_A11Y_E_CELL_REGISTRY_H__ - -#include <atk/atkobject.h> -#include <table/e-table-item.h> -#include <table/e-cell.h> - -#define GAL_A11Y_TYPE_E_CELL_REGISTRY (gal_a11y_e_cell_registry_get_type ()) -#define GAL_A11Y_E_CELL_REGISTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAL_A11Y_TYPE_E_CELL_REGISTRY, GalA11yECellRegistry)) -#define GAL_A11Y_E_CELL_REGISTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAL_A11Y_TYPE_E_CELL_REGISTRY, GalA11yECellRegistryClass)) -#define GAL_A11Y_IS_E_CELL_REGISTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAL_A11Y_TYPE_E_CELL_REGISTRY)) -#define GAL_A11Y_IS_E_CELL_REGISTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAL_A11Y_TYPE_E_CELL_REGISTRY)) - -typedef struct _GalA11yECellRegistry GalA11yECellRegistry; -typedef struct _GalA11yECellRegistryClass GalA11yECellRegistryClass; -typedef struct _GalA11yECellRegistryPrivate GalA11yECellRegistryPrivate; - -typedef AtkObject *(*GalA11yECellRegistryFunc) (ETableItem *item, - ECellView *cell_view, - AtkObject *parent, - gint model_col, - gint view_col, - gint row); - -struct _GalA11yECellRegistry { - GObject object; - - GalA11yECellRegistryPrivate *priv; -}; - -struct _GalA11yECellRegistryClass { - GObjectClass parent_class; -}; - -/* Standard Glib function */ -GType gal_a11y_e_cell_registry_get_type (void); -AtkObject *gal_a11y_e_cell_registry_get_object (GalA11yECellRegistry *registry, - ETableItem *item, - ECellView *cell_view, - AtkObject *parent, - gint model_col, - gint view_col, - gint row); -void gal_a11y_e_cell_registry_add_cell_type (GalA11yECellRegistry *registry, - GType type, - GalA11yECellRegistryFunc func); - -#endif /* __GAL_A11Y_E_CELL_REGISTRY_H__ */ diff --git a/widgets/table/gal-a11y-e-cell-toggle.c b/widgets/table/gal-a11y-e-cell-toggle.c deleted file mode 100644 index 33d9e4fd32..0000000000 --- a/widgets/table/gal-a11y-e-cell-toggle.c +++ /dev/null @@ -1,198 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtk.h> - -#include "table/e-cell-toggle.h" -#include "table/e-table-model.h" -#include <glib/gi18n.h> - -#include "gal-a11y-e-cell-toggle.h" - -#define PARENT_TYPE (gal_a11y_e_cell_get_type ()) -static GObjectClass *parent_class; - -static void gal_a11y_e_cell_toggle_class_init (GalA11yECellToggleClass *class); - -static void -gal_a11y_e_cell_toggle_dispose (GObject *object) -{ - GalA11yECellToggle *a11y = GAL_A11Y_E_CELL_TOGGLE (object); - - ETableModel *e_table_model = GAL_A11Y_E_CELL (a11y)->item->table_model; - - if (e_table_model && a11y->model_id > 0) { - g_signal_handler_disconnect (e_table_model, a11y->model_id); - a11y->model_id = 0; - } - - if (parent_class->dispose) - parent_class->dispose (object); -} - -GType -gal_a11y_e_cell_toggle_get_type (void) -{ - static GType type = 0; - - if (!type) - { - static const GTypeInfo tinfo = - { - sizeof (GalA11yECellToggleClass), - (GBaseInitFunc) NULL, /* base init */ - (GBaseFinalizeFunc) NULL, /* base finalize */ - (GClassInitFunc) gal_a11y_e_cell_toggle_class_init, /* class init */ - (GClassFinalizeFunc) NULL, /* class finalize */ - NULL, /* class data */ - sizeof (GalA11yECellToggle), /* instance size */ - 0, /* nb preallocs */ - NULL, /* instance init */ - NULL /* value table */ - }; - - type = g_type_register_static (GAL_A11Y_TYPE_E_CELL, - "GalA11yECellToggle", &tinfo, 0); - gal_a11y_e_cell_type_add_action_interface (type); - - } - return type; -} - -static void -gal_a11y_e_cell_toggle_class_init (GalA11yECellToggleClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - object_class->dispose = gal_a11y_e_cell_toggle_dispose; - parent_class = g_type_class_ref (PARENT_TYPE); -} - -static void -toggle_cell_action (GalA11yECell *cell) -{ - gint finished; - GtkLayout *layout; - GdkEventButton event; - gint x, y, width, height; - gint row, col; - - row = cell->row; - col = cell->view_col; - - layout = GTK_LAYOUT (GNOME_CANVAS_ITEM (cell->item)->canvas); - - e_table_item_get_cell_geometry ( - cell->item, &row, &col, &x, &y, &width, &height); - - event.x = x + width / 2 + (gint)(GNOME_CANVAS_ITEM (cell->item)->x1); - event.y = y + height / 2 + (gint)(GNOME_CANVAS_ITEM (cell->item)->y1); - - event.type = GDK_BUTTON_PRESS; - event.window = gtk_layout_get_bin_window (layout); - event.button = 1; - event.send_event = TRUE; - event.time = GDK_CURRENT_TIME; - event.axes = NULL; - - g_signal_emit_by_name (cell->item, "event", &event, &finished); -} - -static void -model_change_cb (ETableModel *etm, - gint col, - gint row, - GalA11yECell *cell) -{ - gint value; - - if (col == cell->model_col && row == cell->row) { - - value = GPOINTER_TO_INT ( - e_table_model_value_at (cell->cell_view->e_table_model, - cell->model_col, cell->row)); - /* Cheat gnopernicus, or it will ignore the state change signal */ - atk_focus_tracker_notify (ATK_OBJECT (cell)); - - if (value) - gal_a11y_e_cell_add_state (cell, ATK_STATE_CHECKED, TRUE); - else - gal_a11y_e_cell_remove_state (cell, ATK_STATE_CHECKED, TRUE); - } -} - -AtkObject * -gal_a11y_e_cell_toggle_new (ETableItem *item, - ECellView *cell_view, - AtkObject *parent, - gint model_col, - gint view_col, - gint row) -{ - AtkObject *a11y; - GalA11yECell *cell; - GalA11yECellToggle *toggle_cell; - gint value; - - a11y = ATK_OBJECT (g_object_new (GAL_A11Y_TYPE_E_CELL_TOGGLE, NULL)); - - g_return_val_if_fail (a11y != NULL, NULL); - - cell = GAL_A11Y_E_CELL (a11y); - toggle_cell = GAL_A11Y_E_CELL_TOGGLE (a11y); - a11y->role = ATK_ROLE_TABLE_CELL; - - gal_a11y_e_cell_construct ( - a11y, - item, - cell_view, - parent, - model_col, - view_col, - row); - - gal_a11y_e_cell_add_action ( - cell, - "toggle", - /* Translators: description of a "toggle" action */ - _("toggle the cell"), - NULL, /* action keybinding */ - toggle_cell_action); - - toggle_cell->model_id = g_signal_connect ( - item->table_model, "model_cell_changed", - (GCallback) model_change_cb, a11y); - - value = GPOINTER_TO_INT ( - e_table_model_value_at ( - cell->cell_view->e_table_model, - cell->model_col, cell->row)); - if (value) - gal_a11y_e_cell_add_state (cell, ATK_STATE_CHECKED, FALSE); - else - gal_a11y_e_cell_remove_state (cell, ATK_STATE_CHECKED, FALSE); - - return a11y; -} diff --git a/widgets/table/gal-a11y-e-cell-toggle.h b/widgets/table/gal-a11y-e-cell-toggle.h deleted file mode 100644 index 3c29d777e3..0000000000 --- a/widgets/table/gal-a11y-e-cell-toggle.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __GAL_A11Y_E_CELL_TOGGLE_H__ -#define __GAL_A11Y_E_CELL_TOGGLE_H__ - -#include <atk/atk.h> -#include "gal-a11y-e-cell.h" -#include "gal-a11y-e-cell-toggle.h" - -G_BEGIN_DECLS - -#define GAL_A11Y_TYPE_E_CELL_TOGGLE (gal_a11y_e_cell_toggle_get_type ()) -#define GAL_A11Y_E_CELL_TOGGLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAL_A11Y_TYPE_E_CELL_TOGGLE, GalA11yECellToggle)) -#define GAL_A11Y_E_CELL_TOGGLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAL_A11Y_E_CELL_TOGGLE, GalA11yECellToggleClass)) -#define GAL_A11Y_IS_E_CELL_TOGGLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAL_A11Y_TYPE_E_CELL_TOGGLE)) -#define GAL_A11Y_IS_E_CELL_TOGGLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAL_A11Y_TYPE_E_CELL_TOGGLE)) -#define GAL_A11Y_E_CELL_TOGGLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAL_A11Y_TYPE_E_CELL_TOGGLE, GalA11yECellToggleClass)) - -typedef struct _GalA11yECellToggle GalA11yECellToggle; -typedef struct _GalA11yECellToggleClass GalA11yECellToggleClass; - -struct _GalA11yECellToggle -{ - GalA11yECell parent; - gint model_id; -}; - -GType gal_a11y_e_cell_toggle_get_type (void); - -struct _GalA11yECellToggleClass -{ - GalA11yECellClass parent_class; -}; - -AtkObject *gal_a11y_e_cell_toggle_new (ETableItem *item, - ECellView *cell_view, - AtkObject *parent, - gint model_col, - gint view_col, - gint row); - -G_END_DECLS - -#endif /* __GAL_A11Y_E_CELL_TOGGLE_H__ */ diff --git a/widgets/table/gal-a11y-e-cell-tree.c b/widgets/table/gal-a11y-e-cell-tree.c deleted file mode 100644 index 599b660ca5..0000000000 --- a/widgets/table/gal-a11y-e-cell-tree.c +++ /dev/null @@ -1,266 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Tim Wo <tim.wo@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <atk/atk.h> - -#include "a11y/gal-a11y-util.h" -#include "table/e-cell-tree.h" -#include "table/e-table.h" -#include "table/e-tree-table-adapter.h" -#include <glib/gi18n.h> - -#include "gal-a11y-e-cell-tree.h" -#include "gal-a11y-e-cell-registry.h" - -#define CS_CLASS(a11y) (G_TYPE_INSTANCE_GET_CLASS ((a11y), C_TYPE_STREAM, GalA11yECellTreeClass)) -static AtkObjectClass *a11y_parent_class; -#define A11Y_PARENT_TYPE (gal_a11y_e_cell_get_type ()) - -#define d(x) - -static void -ectr_model_row_changed_cb (ETableModel *etm, - gint row, - GalA11yECell *a11y) -{ - ETreePath node; - ETreeModel *tree_model; - ETreeTableAdapter *tree_table_adapter; - - g_return_if_fail (a11y); - if (a11y->row != row) - return; - - node = e_table_model_value_at (etm, -1, a11y->row); - tree_model = e_table_model_value_at (etm, -2, a11y->row); - tree_table_adapter = e_table_model_value_at (etm, -3, a11y->row); - - if (e_tree_model_node_is_expandable (tree_model, node)) { - gboolean is_exp = e_tree_table_adapter_node_is_expanded (tree_table_adapter, node); - if (is_exp) - gal_a11y_e_cell_add_state (a11y, ATK_STATE_EXPANDED, TRUE); - else - gal_a11y_e_cell_remove_state (a11y, ATK_STATE_EXPANDED, TRUE); - } -} - -static void -kill_view_cb (ECellView *subcell_view, - gpointer psubcell_a11ies) -{ - GList *node; - GList *subcell_a11ies = (GList *) psubcell_a11ies; - GalA11yECell *subcell; - - for (node = subcell_a11ies; node != NULL; node = g_list_next (node)) - { - subcell = GAL_A11Y_E_CELL (node->data); - if (subcell && subcell->cell_view == subcell_view) - { - d (fprintf (stderr, "subcell_view %p deleted before the a11y object %p\n", subcell_view, subcell)); - subcell->cell_view = NULL; - } - } -} - -static void -ectr_subcell_weak_ref (GalA11yECellTree *a11y, - GalA11yECell *subcell_a11y) -{ - ECellView *subcell_view = subcell_a11y ? subcell_a11y->cell_view : NULL; - if (subcell_a11y && subcell_view && subcell_view->kill_view_cb_data) - subcell_view->kill_view_cb_data = g_list_remove (subcell_view->kill_view_cb_data, subcell_a11y); - - g_signal_handler_disconnect ( - GAL_A11Y_E_CELL (a11y)->item->table_model, - a11y->model_row_changed_id); - g_object_unref (a11y); -} - -static void -ectr_do_action_expand (AtkAction *action) -{ - GalA11yECell *a11y; - ETableModel *table_model; - ETreePath node; - ETreeModel *tree_model; - ETreeTableAdapter *tree_table_adapter; - - a11y = GAL_A11Y_E_CELL (action); - table_model = a11y->item->table_model; - node = e_table_model_value_at (table_model, -1, a11y->row); - tree_model = e_table_model_value_at (table_model, -2, a11y->row); - tree_table_adapter = e_table_model_value_at (table_model, -3, a11y->row); - - if (e_tree_model_node_is_expandable (tree_model, node)) { - e_tree_table_adapter_node_set_expanded ( - tree_table_adapter, node, TRUE); - gal_a11y_e_cell_add_state (a11y, ATK_STATE_EXPANDED, TRUE); - } -} - -static void -ectr_do_action_collapse (AtkAction *action) -{ - GalA11yECell *a11y; - ETableModel *table_model; - ETreePath node; - ETreeModel *tree_model; - ETreeTableAdapter *tree_table_adapter; - - a11y = GAL_A11Y_E_CELL (action); - table_model = a11y->item->table_model; - node = e_table_model_value_at (table_model, -1, a11y->row); - tree_model = e_table_model_value_at (table_model, -2, a11y->row); - tree_table_adapter = e_table_model_value_at (table_model, -3, a11y->row); - - if (e_tree_model_node_is_expandable (tree_model, node)) { - e_tree_table_adapter_node_set_expanded ( - tree_table_adapter, node, FALSE); - gal_a11y_e_cell_remove_state (a11y, ATK_STATE_EXPANDED, TRUE); - } -} - -static void -ectr_class_init (GalA11yECellTreeClass *class) -{ - a11y_parent_class = g_type_class_ref (A11Y_PARENT_TYPE); -} - -static void -ectr_init (GalA11yECellTree *a11y) -{ -} - -GType -gal_a11y_e_cell_tree_get_type (void) -{ - static GType type = 0; - - if (!type) { - GTypeInfo info = { - sizeof (GalA11yECellTreeClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) ectr_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GalA11yECellTree), - 0, - (GInstanceInitFunc) ectr_init, - NULL /* value_cell_text */ - }; - - type = g_type_register_static (A11Y_PARENT_TYPE, "GalA11yECellTree", &info, 0); - gal_a11y_e_cell_type_add_action_interface (type); - } - - return type; -} - -AtkObject * -gal_a11y_e_cell_tree_new (ETableItem *item, - ECellView *cell_view, - AtkObject *parent, - gint model_col, - gint view_col, - gint row) -{ - AtkObject *subcell_a11y; - GalA11yECellTree *a11y; - - ETreePath node; - ETreeModel *tree_model; - ETreeTableAdapter *tree_table_adapter; - - ECellView *subcell_view; - subcell_view = e_cell_tree_view_get_subcell_view (cell_view); - - if (subcell_view->ecell) { - subcell_a11y = gal_a11y_e_cell_registry_get_object ( - NULL, - item, - subcell_view, - parent, - model_col, - view_col, - row); - gal_a11y_e_cell_add_action ( - GAL_A11Y_E_CELL (subcell_a11y), - "expand", - /* Translators: description of an "expand" action */ - _("expands the row in the ETree containing this cell"), - NULL, - (ACTION_FUNC) ectr_do_action_expand); - - gal_a11y_e_cell_add_action ( - GAL_A11Y_E_CELL (subcell_a11y), - "collapse", - /* Translators: description of a "collapse" action */ - _("collapses the row in the ETree containing this cell"), - NULL, - (ACTION_FUNC) ectr_do_action_collapse); - - /* init AtkStates for the cell's a11y object */ - node = e_table_model_value_at (item->table_model, -1, row); - tree_model = e_table_model_value_at (item->table_model, -2, row); - tree_table_adapter = e_table_model_value_at (item->table_model, -3, row); - if (e_tree_model_node_is_expandable (tree_model, node)) { - gal_a11y_e_cell_add_state (GAL_A11Y_E_CELL (subcell_a11y), ATK_STATE_EXPANDABLE, FALSE); - if (e_tree_table_adapter_node_is_expanded (tree_table_adapter, node)) - gal_a11y_e_cell_add_state (GAL_A11Y_E_CELL (subcell_a11y), ATK_STATE_EXPANDED, FALSE); - } - } - else - subcell_a11y = NULL; - - /* create a companion a11y object, this object has type GalA11yECellTree - * and it connects to some signals to determine whether a tree cell is - * expanded or collapsed */ - a11y = g_object_new (gal_a11y_e_cell_tree_get_type (), NULL); - gal_a11y_e_cell_construct ( - ATK_OBJECT (a11y), - item, - cell_view, - parent, - model_col, - view_col, - row); - a11y->model_row_changed_id = g_signal_connect ( - item->table_model, "model_row_changed", - G_CALLBACK (ectr_model_row_changed_cb), subcell_a11y); - - if (subcell_a11y && subcell_view) - { - subcell_view->kill_view_cb = kill_view_cb; - if (!g_list_find (subcell_view->kill_view_cb_data, subcell_a11y)) - subcell_view->kill_view_cb_data = g_list_append (subcell_view->kill_view_cb_data, subcell_a11y); - } - - g_object_weak_ref (G_OBJECT (subcell_a11y), (GWeakNotify) ectr_subcell_weak_ref, a11y); - - return subcell_a11y; -} diff --git a/widgets/table/gal-a11y-e-cell-tree.h b/widgets/table/gal-a11y-e-cell-tree.h deleted file mode 100644 index 18ccf9c7bc..0000000000 --- a/widgets/table/gal-a11y-e-cell-tree.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Tim Wo <tim.wo@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __GAL_A11Y_E_CELL_TREE_H__ -#define __GAL_A11Y_E_CELL_TREE_H__ - -#include <table/e-table-item.h> -#include <table/e-cell-tree.h> -#include "gal-a11y-e-cell.h" - -#define GAL_A11Y_TYPE_E_CELL_TREE (gal_a11y_e_cell_tree_get_type ()) -#define GAL_A11Y_E_CELL_TREE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAL_A11Y_TYPE_E_CELL_TREE, GalA11yECellTree)) -#define GAL_A11Y_E_CELL_TREE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAL_A11Y_TYPE_E_CELL_TREE, GalA11yECellTreeClass)) -#define GAL_A11Y_IS_E_CELL_TREE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAL_A11Y_TYPE_E_CELL_TREE)) -#define GAL_A11Y_IS_E_CELL_TREE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAL_A11Y_TYPE_E_CELL_TREE)) - -typedef struct _GalA11yECellTree GalA11yECellTree; -typedef struct _GalA11yECellTreeClass GalA11yECellTreeClass; -typedef struct _GalA11yECellTreePrivate GalA11yECellTreePrivate; - -/* This struct should actually be larger as this isn't what we derive from. - * The GalA11yECellTreePrivate comes right after the parent class structure. - **/ -struct _GalA11yECellTree { - GalA11yECell object; - - gint model_row_changed_id; -}; - -struct _GalA11yECellTreeClass { - GalA11yECellClass parent_class; -}; - -/* Standard Glib function */ -GType gal_a11y_e_cell_tree_get_type (void); -AtkObject *gal_a11y_e_cell_tree_new (ETableItem *item, - ECellView *cell_view, - AtkObject *parent, - gint model_col, - gint view_col, - gint row); - -#endif /* __GAL_A11Y_E_CELL_TREE_H__ */ diff --git a/widgets/table/gal-a11y-e-cell-vbox.c b/widgets/table/gal-a11y-e-cell-vbox.c deleted file mode 100644 index d00547c877..0000000000 --- a/widgets/table/gal-a11y-e-cell-vbox.c +++ /dev/null @@ -1,235 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Eric Zhao <eric.zhao@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * Copyright (C) 2004 Sun Microsystem, Inc. - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <atk/atk.h> - -#include "table/e-cell-vbox.h" - -#include "gal-a11y-e-cell-registry.h" -#include "gal-a11y-e-cell-vbox.h" - -static GObjectClass *parent_class; -static AtkComponentIface *component_parent_iface; -#define PARENT_TYPE (gal_a11y_e_cell_get_type ()) - -static gint -ecv_get_n_children (AtkObject *a11y) -{ - g_return_val_if_fail (GAL_A11Y_IS_E_CELL_VBOX (a11y), 0); - - return GAL_A11Y_E_CELL_VBOX (a11y)->a11y_subcell_count; -} - -static void -subcell_destroyed (gpointer data) -{ - GalA11yECell *cell; - AtkObject *parent; - GalA11yECellVbox *gaev; - - g_return_if_fail (GAL_A11Y_IS_E_CELL (data)); - cell = GAL_A11Y_E_CELL (data); - - parent = atk_object_get_parent (ATK_OBJECT (cell)); - g_return_if_fail (GAL_A11Y_IS_E_CELL_VBOX (parent)); - gaev = GAL_A11Y_E_CELL_VBOX (parent); - - if (cell->view_col < gaev->a11y_subcell_count) - gaev->a11y_subcells[cell->view_col] = NULL; -} - -static AtkObject * -ecv_ref_child (AtkObject *a11y, - gint i) -{ - GalA11yECellVbox *gaev = GAL_A11Y_E_CELL_VBOX (a11y); - GalA11yECell *gaec = GAL_A11Y_E_CELL (a11y); - ECellVboxView *ecvv = (ECellVboxView *) (gaec->cell_view); - AtkObject *ret; - if (i < gaev->a11y_subcell_count) { - if (gaev->a11y_subcells[i] == NULL) { - ECellView *subcell_view; - gint model_col, row; - row = gaec->row; - model_col = ecvv->model_cols[i]; - subcell_view = ecvv->subcell_views[i]; - /* FIXME Should the view column use a fake - * one or the same as its parent? */ - ret = gal_a11y_e_cell_registry_get_object ( - NULL, - gaec->item, - subcell_view, - a11y, - model_col, - gaec->view_col, - row); - gaev->a11y_subcells[i] = ret; - g_object_ref (ret); - g_object_weak_ref ( - G_OBJECT (ret), - (GWeakNotify) subcell_destroyed, - ret); - } else { - ret = (AtkObject *) gaev->a11y_subcells[i]; - if (ATK_IS_OBJECT (ret)) - g_object_ref (ret); - else - ret = NULL; - } - } else { - ret = NULL; - } - - return ret; -} - -static void -ecv_dispose (GObject *object) -{ - GalA11yECellVbox *gaev = GAL_A11Y_E_CELL_VBOX (object); - if (gaev->a11y_subcells) - g_free (gaev->a11y_subcells); - - if (parent_class->dispose) - parent_class->dispose (object); -} - -/* AtkComponet interface */ -static AtkObject * -ecv_ref_accessible_at_point (AtkComponent *component, - gint x, - gint y, - AtkCoordType coord_type) -{ - gint x0, y0, width, height; - gint subcell_height, i; - - GalA11yECell *gaec = GAL_A11Y_E_CELL (component); - ECellVboxView *ecvv = (ECellVboxView *) (gaec->cell_view); - - atk_component_get_extents (component, &x0, &y0, &width, &height, coord_type); - x -= x0; - y -= y0; - if (x < 0 || x > width || y < 0 || y > height) - return NULL; - - for (i = 0; i < ecvv->subcell_view_count; i++) { - subcell_height = e_cell_height ( - ecvv->subcell_views[i], ecvv->model_cols[i], - gaec->view_col, gaec->row); - if (0 <= y && y <= subcell_height) { - return ecv_ref_child ((AtkObject *) component, i); - } else - y -= subcell_height; - } - - return NULL; -} - -static void -ecv_class_init (GalA11yECellVboxClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - AtkObjectClass *a11y_class = ATK_OBJECT_CLASS (class); - parent_class = g_type_class_ref (PARENT_TYPE); - - object_class->dispose = ecv_dispose; - - a11y_class->get_n_children = ecv_get_n_children; - a11y_class->ref_child = ecv_ref_child; -} - -static void -ecv_init (GalA11yECellVbox *a11y) -{ -} - -static void -ecv_atk_component_iface_init (AtkComponentIface *iface) -{ - component_parent_iface = g_type_interface_peek_parent (iface); - - iface->ref_accessible_at_point = ecv_ref_accessible_at_point; -} - -GType -gal_a11y_e_cell_vbox_get_type (void) -{ - static GType type = 0; - if (!type) { - GTypeInfo info = { - sizeof (GalA11yECellVboxClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) ecv_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GalA11yECellVbox), - 0, - (GInstanceInitFunc) ecv_init, - NULL /* value_cell */ - }; - - static const GInterfaceInfo atk_component_info = { - (GInterfaceInitFunc) ecv_atk_component_iface_init, - (GInterfaceFinalizeFunc) NULL, - NULL - }; - - type = g_type_register_static (PARENT_TYPE, "GalA11yECellVbox", &info, 0); - gal_a11y_e_cell_type_add_action_interface (type); - g_type_add_interface_static (type, ATK_TYPE_COMPONENT, &atk_component_info); - } - - return type; -} - -AtkObject *gal_a11y_e_cell_vbox_new (ETableItem *item, - ECellView *cell_view, - AtkObject *parent, - gint model_col, - gint view_col, - gint row) -{ - AtkObject *a11y; - GalA11yECell *gaec; - GalA11yECellVbox *gaev; - ECellVboxView *ecvv; - - a11y = g_object_new (gal_a11y_e_cell_vbox_get_type (), NULL); - - gal_a11y_e_cell_construct ( - a11y, item, cell_view, parent, model_col, view_col, row); - - gaec = GAL_A11Y_E_CELL (a11y); - gaev = GAL_A11Y_E_CELL_VBOX (a11y); - ecvv = (ECellVboxView *) (gaec->cell_view); - gaev->a11y_subcell_count = ecvv->subcell_view_count; - gaev->a11y_subcells = g_malloc0 (sizeof (AtkObject *) * gaev->a11y_subcell_count); - return a11y; -} diff --git a/widgets/table/gal-a11y-e-cell-vbox.h b/widgets/table/gal-a11y-e-cell-vbox.h deleted file mode 100644 index 657cb5d9a5..0000000000 --- a/widgets/table/gal-a11y-e-cell-vbox.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Eric Zhao <eric.zhao@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * Copyright (C) 2004 Sun Microsystem, Inc. - * - */ - -#ifndef __GAL_A11Y_E_CELL_VBOX_H__ -#define __GAL_A11Y_E_CELL_VBOX_H__ - -#include "gal-a11y-e-cell.h" - -G_BEGIN_DECLS - -#define GAL_A11Y_TYPE_E_CELL_VBOX (gal_a11y_e_cell_vbox_get_type ()) -#define GAL_A11Y_E_CELL_VBOX(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAL_A11Y_TYPE_E_CELL_VBOX, GalA11yECellVbox)) -#define GAL_A11Y_E_CELL_VBOX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAL_A11Y_E_CELL_VBOX, GalA11yECellVboxClass)) -#define GAL_A11Y_IS_E_CELL_VBOX(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAL_A11Y_TYPE_E_CELL_VBOX)) -#define GAL_A11Y_IS_E_CELL_VBOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAL_A11Y_TYPE_E_CELL_VBOX)) -#define GAL_A11Y_E_CELL_VBOX_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAL_A11Y_TYPE_E_CELL_VBOX, GalA11yECellVboxClass)) - -typedef struct _GalA11yECellVbox GalA11yECellVbox; -typedef struct _GalA11yECellVboxClass GalA11yECellVboxClass; - -struct _GalA11yECellVbox -{ - GalA11yECell object; - gint a11y_subcell_count; - gpointer *a11y_subcells; -}; - -struct _GalA11yECellVboxClass -{ - GalA11yECellClass parent_class; -}; - -GType gal_a11y_e_cell_vbox_get_type (void); -AtkObject *gal_a11y_e_cell_vbox_new (ETableItem *item, - ECellView *cell_view, - AtkObject *parent, - gint model_col, - gint view_col, - gint row); - -G_END_DECLS -#endif /* __GAL_A11Y_E_CELL_VBOX_H__ */ diff --git a/widgets/table/gal-a11y-e-cell.c b/widgets/table/gal-a11y-e-cell.c deleted file mode 100644 index 3972c2de16..0000000000 --- a/widgets/table/gal-a11y-e-cell.c +++ /dev/null @@ -1,648 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Christopher James Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include <gtk/gtk.h> - -#include "a11y/gal-a11y-util.h" -#include "table/e-table.h" -#include "table/e-tree.h" -#include <glib/gi18n.h> - -#include "gal-a11y-e-cell.h" -#include "gal-a11y-e-cell-vbox.h" -#include "gal-a11y-e-table-item.h" - -static GObjectClass *parent_class; -#define PARENT_TYPE (atk_object_get_type ()) - -#if 0 -static void -unref_item (gpointer user_data, - GObject *obj_loc) -{ - GalA11yECell *a11y = GAL_A11Y_E_CELL (user_data); - a11y->item = NULL; - g_object_unref (a11y); -} - -static void -unref_cell (gpointer user_data, - GObject *obj_loc) -{ - GalA11yECell *a11y = GAL_A11Y_E_CELL (user_data); - a11y->cell_view = NULL; - g_object_unref (a11y); -} -#endif - -static gboolean -is_valid (AtkObject *cell) -{ - GalA11yECell *a11y = GAL_A11Y_E_CELL (cell); - GalA11yETableItem *a11yItem = GAL_A11Y_E_TABLE_ITEM (a11y->parent); - AtkStateSet *item_ss; - gboolean ret = TRUE; - - item_ss = atk_object_ref_state_set (ATK_OBJECT (a11yItem)); - if (atk_state_set_contains_state (item_ss, ATK_STATE_DEFUNCT)) - ret = FALSE; - - g_object_unref (item_ss); - - if (ret && atk_state_set_contains_state (a11y->state_set, ATK_STATE_DEFUNCT)) - ret = FALSE; - - return ret; -} - -static void -gal_a11y_e_cell_dispose (GObject *object) -{ - GalA11yECell *a11y = GAL_A11Y_E_CELL (object); - -#if 0 - if (a11y->item) - g_object_unref (a11y->item); /*, unref_item, a11y); */ - if (a11y->cell_view) - g_object_unref (a11y->cell_view); /*, unref_cell, a11y); */ - if (a11y->parent) - g_object_unref (a11y->parent); -#endif - - if (a11y->state_set) { - g_object_unref (a11y->state_set); - a11y->state_set = NULL; - } - - if (parent_class->dispose) - parent_class->dispose (object); - -} - -/* Static functions */ -static const gchar * -gal_a11y_e_cell_get_name (AtkObject *a11y) -{ - GalA11yECell *cell = GAL_A11Y_E_CELL (a11y); - ETableCol *ecol; - - if (a11y->name != NULL && strcmp (a11y->name, "")) - return a11y->name; - - if (cell->item != NULL) { - ecol = e_table_header_get_column (cell->item->header, cell->view_col); - if (ecol != NULL) - return ecol->text; - } - - return _("Table Cell"); -} - -static AtkStateSet * -gal_a11y_e_cell_ref_state_set (AtkObject *accessible) -{ - GalA11yECell *cell = GAL_A11Y_E_CELL (accessible); - - g_return_val_if_fail (cell->state_set, NULL); - - g_object_ref (cell->state_set); - - return cell->state_set; -} - -static AtkObject * -gal_a11y_e_cell_get_parent (AtkObject *accessible) -{ - GalA11yECell *a11y = GAL_A11Y_E_CELL (accessible); - return a11y->parent; -} - -static gint -gal_a11y_e_cell_get_index_in_parent (AtkObject *accessible) -{ - GalA11yECell *a11y = GAL_A11Y_E_CELL (accessible); - - if (!is_valid (accessible)) - return -1; - - return (a11y->row + 1) * a11y->item->cols + a11y->view_col; -} - -/* Component IFace */ -static void -gal_a11y_e_cell_get_extents (AtkComponent *component, - gint *x, - gint *y, - gint *width, - gint *height, - AtkCoordType coord_type) -{ - GalA11yECell *a11y = GAL_A11Y_E_CELL (component); - GtkWidget *tableOrTree; - gint row; - gint col; - gint xval; - gint yval; - - row = a11y->row; - col = a11y->view_col; - - tableOrTree = gtk_widget_get_parent (GTK_WIDGET (a11y->item->parent.canvas)); - if (E_IS_TREE (tableOrTree)) { - e_tree_get_cell_geometry ( - E_TREE (tableOrTree), - row, col, &xval, &yval, - width, height); - } else { - e_table_get_cell_geometry ( - E_TABLE (tableOrTree), - row, col, &xval, &yval, - width, height); - } - - atk_component_get_position ( - ATK_COMPONENT (a11y->parent), - x, y, coord_type); - if (x && *x != G_MININT) - *x += xval; - if (y && *y != G_MININT) - *y += yval; -} - -static gboolean -gal_a11y_e_cell_grab_focus (AtkComponent *component) -{ - GalA11yECell *a11y; - gint index; - GtkWidget *toplevel; - GalA11yETableItem *a11yTableItem; - - a11y = GAL_A11Y_E_CELL (component); - - /* for e_cell_vbox's children, we just grab the e_cell_vbox */ - if (GAL_A11Y_IS_E_CELL_VBOX (a11y->parent)) { - return atk_component_grab_focus (ATK_COMPONENT (a11y->parent)); - } - - a11yTableItem = GAL_A11Y_E_TABLE_ITEM (a11y->parent); - index = atk_object_get_index_in_parent (ATK_OBJECT (a11y)); - - atk_selection_clear_selection (ATK_SELECTION (a11yTableItem)); - atk_selection_add_selection (ATK_SELECTION (a11yTableItem), index); - - gtk_widget_grab_focus ( - GTK_WIDGET (GNOME_CANVAS_ITEM (a11y->item)->canvas)); - toplevel = gtk_widget_get_toplevel ( - GTK_WIDGET (GNOME_CANVAS_ITEM (a11y->item)->canvas)); - if (toplevel && gtk_widget_is_toplevel (toplevel)) - gtk_window_present (GTK_WINDOW (toplevel)); - - return TRUE; -} - -/* Table IFace */ - -static void -gal_a11y_e_cell_atk_component_iface_init (AtkComponentIface *iface) -{ - iface->get_extents = gal_a11y_e_cell_get_extents; - iface->grab_focus = gal_a11y_e_cell_grab_focus; -} - -static void -gal_a11y_e_cell_class_init (GalA11yECellClass *class) -{ - AtkObjectClass *atk_object_class = ATK_OBJECT_CLASS (class); - GObjectClass *object_class = G_OBJECT_CLASS (class); - - parent_class = g_type_class_ref (PARENT_TYPE); - - object_class->dispose = gal_a11y_e_cell_dispose; - - atk_object_class->get_parent = gal_a11y_e_cell_get_parent; - atk_object_class->get_index_in_parent = gal_a11y_e_cell_get_index_in_parent; - atk_object_class->ref_state_set = gal_a11y_e_cell_ref_state_set; - atk_object_class->get_name = gal_a11y_e_cell_get_name; -} - -static void -gal_a11y_e_cell_init (GalA11yECell *a11y) -{ - a11y->item = NULL; - a11y->cell_view = NULL; - a11y->parent = NULL; - a11y->model_col = -1; - a11y->view_col = -1; - a11y->row = -1; - - a11y->state_set = atk_state_set_new (); - atk_state_set_add_state (a11y->state_set, ATK_STATE_TRANSIENT); - atk_state_set_add_state (a11y->state_set, ATK_STATE_ENABLED); - atk_state_set_add_state (a11y->state_set, ATK_STATE_SENSITIVE); - atk_state_set_add_state (a11y->state_set, ATK_STATE_SELECTABLE); - atk_state_set_add_state (a11y->state_set, ATK_STATE_SHOWING); - atk_state_set_add_state (a11y->state_set, ATK_STATE_FOCUSABLE); - atk_state_set_add_state (a11y->state_set, ATK_STATE_VISIBLE); -} - -static ActionInfo * -_gal_a11y_e_cell_get_action_info (GalA11yECell *cell, - gint index) -{ - GList *list_node; - - g_return_val_if_fail (GAL_A11Y_IS_E_CELL (cell), NULL); - if (cell->action_list == NULL) - return NULL; - list_node = g_list_nth (cell->action_list, index); - if (!list_node) - return NULL; - return (ActionInfo *) (list_node->data); -} - -static void -_gal_a11y_e_cell_destroy_action_info (gpointer action_info, - gpointer user_data) -{ - ActionInfo *info = (ActionInfo *) action_info; - - g_return_if_fail (info != NULL); - g_free (info->name); - g_free (info->description); - g_free (info->keybinding); - g_free (info); -} - -gboolean -gal_a11y_e_cell_add_action (GalA11yECell *cell, - const gchar *action_name, - const gchar *action_description, - const gchar *action_keybinding, - ACTION_FUNC action_func) -{ - ActionInfo *info; - g_return_val_if_fail (GAL_A11Y_IS_E_CELL (cell), FALSE); - info = g_new (ActionInfo, 1); - - if (action_name != NULL) - info->name = g_strdup (action_name); - else - info->name = NULL; - - if (action_description != NULL) - info->description = g_strdup (action_description); - else - info->description = NULL; - if (action_keybinding != NULL) - info->keybinding = g_strdup (action_keybinding); - else - info->keybinding = NULL; - info->do_action_func = action_func; - - cell->action_list = g_list_append (cell->action_list, (gpointer) info); - return TRUE; -} - -gboolean -gal_a11y_e_cell_remove_action (GalA11yECell *cell, - gint action_index) -{ - GList *list_node; - - g_return_val_if_fail (GAL_A11Y_IS_E_CELL (cell), FALSE); - list_node = g_list_nth (cell->action_list, action_index); - if (!list_node) - return FALSE; - g_return_val_if_fail (list_node->data != NULL, FALSE); - _gal_a11y_e_cell_destroy_action_info (list_node->data, NULL); - cell->action_list = g_list_remove_link (cell->action_list, list_node); - - return TRUE; -} - -gboolean -gal_a11y_e_cell_remove_action_by_name (GalA11yECell *cell, - const gchar *action_name) -{ - GList *list_node; - - g_return_val_if_fail (GAL_A11Y_IS_E_CELL (cell), FALSE); - - for (list_node = cell->action_list; list_node; list_node = list_node->next) { - if (!g_ascii_strcasecmp (((ActionInfo *)(list_node->data))->name, action_name)) { - break; - } - } - - g_return_val_if_fail (list_node != NULL, FALSE); - - _gal_a11y_e_cell_destroy_action_info (list_node->data, NULL); - cell->action_list = g_list_remove_link (cell->action_list, list_node); - - return TRUE; -} - -static gint -gal_a11y_e_cell_action_get_n_actions (AtkAction *action) -{ - GalA11yECell *cell = GAL_A11Y_E_CELL (action); - if (cell->action_list != NULL) - return g_list_length (cell->action_list); - else - return 0; -} - -static const gchar * -gal_a11y_e_cell_action_get_name (AtkAction *action, - gint index) -{ - GalA11yECell *cell = GAL_A11Y_E_CELL (action); - ActionInfo *info = _gal_a11y_e_cell_get_action_info (cell, index); - - if (info == NULL) - return NULL; - return info->name; -} - -static const gchar * -gal_a11y_e_cell_action_get_description (AtkAction *action, - gint index) -{ - GalA11yECell *cell = GAL_A11Y_E_CELL (action); - ActionInfo *info = _gal_a11y_e_cell_get_action_info (cell, index); - - if (info == NULL) - return NULL; - return info->description; -} - -static gboolean -gal_a11y_e_cell_action_set_description (AtkAction *action, - gint index, - const gchar *desc) -{ - GalA11yECell *cell = GAL_A11Y_E_CELL (action); - ActionInfo *info = _gal_a11y_e_cell_get_action_info (cell, index); - - if (info == NULL) - return FALSE; - g_free (info->description); - info->description = g_strdup (desc); - return TRUE; -} - -static const gchar * -gal_a11y_e_cell_action_get_keybinding (AtkAction *action, - gint index) -{ - GalA11yECell *cell = GAL_A11Y_E_CELL (action); - ActionInfo *info = _gal_a11y_e_cell_get_action_info (cell, index); - if (info == NULL) - return NULL; - - return info->keybinding; -} - -static gboolean -idle_do_action (gpointer data) -{ - GalA11yECell *cell; - - cell = GAL_A11Y_E_CELL (data); - - if (!is_valid (ATK_OBJECT (cell))) - return FALSE; - - cell->action_idle_handler = 0; - cell->action_func (cell); - g_object_unref (cell); - - return FALSE; -} - -static gboolean -gal_a11y_e_cell_action_do_action (AtkAction *action, - gint index) -{ - GalA11yECell *cell = GAL_A11Y_E_CELL (action); - ActionInfo *info = _gal_a11y_e_cell_get_action_info (cell, index); - - if (!is_valid (ATK_OBJECT (action))) - return FALSE; - - if (info == NULL) - return FALSE; - g_return_val_if_fail (info->do_action_func, FALSE); - if (cell->action_idle_handler) - return FALSE; - cell->action_func = info->do_action_func; - g_object_ref (cell); - cell->action_idle_handler = g_idle_add (idle_do_action, cell); - - return TRUE; -} - -static void -gal_a11y_e_cell_atk_action_interface_init (AtkActionIface *iface) -{ - g_return_if_fail (iface != NULL); - - iface->get_n_actions = gal_a11y_e_cell_action_get_n_actions; - iface->do_action = gal_a11y_e_cell_action_do_action; - iface->get_name = gal_a11y_e_cell_action_get_name; - iface->get_description = gal_a11y_e_cell_action_get_description; - iface->set_description = gal_a11y_e_cell_action_set_description; - iface->get_keybinding = gal_a11y_e_cell_action_get_keybinding; -} - -void -gal_a11y_e_cell_type_add_action_interface (GType type) -{ - static const GInterfaceInfo atk_action_info = - { - (GInterfaceInitFunc) gal_a11y_e_cell_atk_action_interface_init, - (GInterfaceFinalizeFunc) NULL, - NULL - }; - - g_type_add_interface_static ( - type, ATK_TYPE_ACTION, - &atk_action_info); -} - -gboolean -gal_a11y_e_cell_add_state (GalA11yECell *cell, - AtkStateType state_type, - gboolean emit_signal) -{ - if (!atk_state_set_contains_state (cell->state_set, state_type)) { - gboolean rc; - - rc = atk_state_set_add_state (cell->state_set, state_type); - /* - * The signal should only be generated if the value changed, - * not when the cell is set up. So states that are set - * initially should pass FALSE as the emit_signal argument. - */ - - if (emit_signal) { - atk_object_notify_state_change (ATK_OBJECT (cell), state_type, TRUE); - /* If state_type is ATK_STATE_VISIBLE, additional - * notification */ - if (state_type == ATK_STATE_VISIBLE) - g_signal_emit_by_name (cell, "visible_data_changed"); - } - - return rc; - } - else - return FALSE; -} - -gboolean -gal_a11y_e_cell_remove_state (GalA11yECell *cell, - AtkStateType state_type, - gboolean emit_signal) -{ - if (atk_state_set_contains_state (cell->state_set, state_type)) { - gboolean rc; - - rc = atk_state_set_remove_state (cell->state_set, state_type); - /* - * The signal should only be generated if the value changed, - * not when the cell is set up. So states that are set - * initially should pass FALSE as the emit_signal argument. - */ - - if (emit_signal) { - atk_object_notify_state_change (ATK_OBJECT (cell), state_type, FALSE); - /* If state_type is ATK_STATE_VISIBLE, additional notification */ - if (state_type == ATK_STATE_VISIBLE) - g_signal_emit_by_name (cell, "visible_data_changed"); - } - - return rc; - } - else - return FALSE; -} - -/** - * gal_a11y_e_cell_get_type: - * @void: - * - * Registers the &GalA11yECell class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &GalA11yECell class. - **/ -GType -gal_a11y_e_cell_get_type (void) -{ - static GType type = 0; - - if (!type) { - GTypeInfo info = { - sizeof (GalA11yECellClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) gal_a11y_e_cell_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GalA11yECell), - 0, - (GInstanceInitFunc) gal_a11y_e_cell_init, - NULL /* value_cell */ - }; - - static const GInterfaceInfo atk_component_info = { - (GInterfaceInitFunc) gal_a11y_e_cell_atk_component_iface_init, - (GInterfaceFinalizeFunc) NULL, - NULL - }; - - type = g_type_register_static (PARENT_TYPE, "GalA11yECell", &info, 0); - g_type_add_interface_static (type, ATK_TYPE_COMPONENT, &atk_component_info); - } - - return type; -} - -AtkObject * -gal_a11y_e_cell_new (ETableItem *item, - ECellView *cell_view, - AtkObject *parent, - gint model_col, - gint view_col, - gint row) -{ - AtkObject *a11y; - - a11y = g_object_new (gal_a11y_e_cell_get_type (), NULL); - - gal_a11y_e_cell_construct ( - a11y, - item, - cell_view, - parent, - model_col, - view_col, - row); - return a11y; -} - -void -gal_a11y_e_cell_construct (AtkObject *object, - ETableItem *item, - ECellView *cell_view, - AtkObject *parent, - gint model_col, - gint view_col, - gint row) -{ - GalA11yECell *a11y = GAL_A11Y_E_CELL (object); - a11y->item = item; - a11y->cell_view = cell_view; - a11y->parent = parent; - a11y->model_col = model_col; - a11y->view_col = view_col; - a11y->row = row; - ATK_OBJECT (a11y) ->role = ATK_ROLE_TABLE_CELL; - - if (item) - g_object_ref (item); - -#if 0 - if (parent) - g_object_ref (parent); - - if (cell_view) - g_object_ref (cell_view); - -#endif -} diff --git a/widgets/table/gal-a11y-e-cell.h b/widgets/table/gal-a11y-e-cell.h deleted file mode 100644 index 48c7d2bec8..0000000000 --- a/widgets/table/gal-a11y-e-cell.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Christopher James Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __GAL_A11Y_E_CELL_H__ -#define __GAL_A11Y_E_CELL_H__ - -#include <table/e-table-item.h> -#include <table/e-cell.h> - -#define GAL_A11Y_TYPE_E_CELL (gal_a11y_e_cell_get_type ()) -#define GAL_A11Y_E_CELL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAL_A11Y_TYPE_E_CELL, GalA11yECell)) -#define GAL_A11Y_E_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAL_A11Y_TYPE_E_CELL, GalA11yECellClass)) -#define GAL_A11Y_IS_E_CELL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAL_A11Y_TYPE_E_CELL)) -#define GAL_A11Y_IS_E_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAL_A11Y_TYPE_E_CELL)) - -typedef struct _GalA11yECell GalA11yECell; -typedef struct _GalA11yECellClass GalA11yECellClass; -typedef struct _GalA11yECellPrivate GalA11yECellPrivate; -typedef struct _ActionInfo ActionInfo; -typedef void (*ACTION_FUNC) (GalA11yECell *cell); - -/* This struct should actually be larger as this isn't what we derive from. - * The GalA11yECellPrivate comes right after the parent class structure. - **/ -struct _GalA11yECell { - AtkObject object; - - ETableItem *item; - ECellView *cell_view; - AtkObject *parent; - gint model_col; - gint view_col; - gint row; - AtkStateSet *state_set; - GList *action_list; - gint action_idle_handler; - ACTION_FUNC action_func; -}; - -struct _GalA11yECellClass { - AtkObjectClass parent_class; -}; - -struct _ActionInfo { - gchar *name; - gchar *description; - gchar *keybinding; - ACTION_FUNC do_action_func; -}; - -/* Standard Glib function */ -GType gal_a11y_e_cell_get_type (void); -AtkObject *gal_a11y_e_cell_new (ETableItem *item, - ECellView *cell_view, - AtkObject *parent, - gint model_col, - gint view_col, - gint row); -void gal_a11y_e_cell_construct (AtkObject *object, - ETableItem *item, - ECellView *cell_view, - AtkObject *parent, - gint model_col, - gint view_col, - gint row); - -void gal_a11y_e_cell_type_add_action_interface (GType type); - -gboolean gal_a11y_e_cell_add_action (GalA11yECell *cell, - const gchar *action_name, - const gchar *action_description, - const gchar *action_keybinding, - ACTION_FUNC action_func); - -gboolean gal_a11y_e_cell_remove_action (GalA11yECell *cell, - gint action_id); - -gboolean gal_a11y_e_cell_remove_action_by_name (GalA11yECell *cell, - const gchar *action_name); - -gboolean gal_a11y_e_cell_add_state (GalA11yECell *cell, - AtkStateType state_type, - gboolean emit_signal); - -gboolean gal_a11y_e_cell_remove_state (GalA11yECell *cell, - AtkStateType state_type, - gboolean emit_signal); - -#endif /* __GAL_A11Y_E_CELL_H__ */ diff --git a/widgets/table/gal-a11y-e-table-click-to-add-factory.c b/widgets/table/gal-a11y-e-table-click-to-add-factory.c deleted file mode 100644 index 1a4b418adf..0000000000 --- a/widgets/table/gal-a11y-e-table-click-to-add-factory.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Yuedong Du <yuedong.du@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <atk/atk.h> - -#include "table/e-table.h" -#include "table/e-table-click-to-add.h" - -#include "gal-a11y-e-table.h" -#include "gal-a11y-e-table-click-to-add.h" -#include "gal-a11y-e-table-click-to-add-factory.h" - -#define CS_CLASS(factory) (G_TYPE_INSTANCE_GET_CLASS ((factory), C_TYPE_STREAM, GalA11yETableClickToAddFactoryClass)) -static AtkObjectFactoryClass *parent_class; -#define PARENT_TYPE (ATK_TYPE_OBJECT_FACTORY) - -/* Static functions */ - -static GType -gal_a11y_e_table_click_to_add_factory_get_accessible_type (void) -{ - return GAL_A11Y_TYPE_E_TABLE_CLICK_TO_ADD; -} - -static AtkObject * -gal_a11y_e_table_click_to_add_factory_create_accessible (GObject *obj) -{ - AtkObject * atk_object; - - g_return_val_if_fail (E_IS_TABLE_CLICK_TO_ADD (obj), NULL); - - atk_object = gal_a11y_e_table_click_to_add_new (obj); - - return atk_object; -} - -static void -gal_a11y_e_table_click_to_add_factory_class_init (GalA11yETableClickToAddFactoryClass *class) -{ - AtkObjectFactoryClass *factory_class = ATK_OBJECT_FACTORY_CLASS (class); - - parent_class = g_type_class_ref (PARENT_TYPE); - - factory_class->create_accessible = gal_a11y_e_table_click_to_add_factory_create_accessible; - factory_class->get_accessible_type = gal_a11y_e_table_click_to_add_factory_get_accessible_type; -} - -static void -gal_a11y_e_table_click_to_add_factory_init (GalA11yETableClickToAddFactory *factory) -{ -} - -/** - * gal_a11y_e_table_factory_get_type: - * @void: - * - * Registers the &GalA11yETableFactory class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &GalA11yETableFactory class. - **/ -GType -gal_a11y_e_table_click_to_add_factory_get_type (void) -{ - static GType type = 0; - - if (!type) { - GTypeInfo info = { - sizeof (GalA11yETableClickToAddFactoryClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) gal_a11y_e_table_click_to_add_factory_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GalA11yETableClickToAddFactory), - 0, - (GInstanceInitFunc) gal_a11y_e_table_click_to_add_factory_init, - NULL /* value_table */ - }; - - type = g_type_register_static (PARENT_TYPE, "GalA11yETableClickToAddFactory", &info, 0); - } - - return type; -} diff --git a/widgets/table/gal-a11y-e-table-click-to-add-factory.h b/widgets/table/gal-a11y-e-table-click-to-add-factory.h deleted file mode 100644 index c7b2cf8e6a..0000000000 --- a/widgets/table/gal-a11y-e-table-click-to-add-factory.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Yuedong Du <yuedong.du@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __GAL_A11Y_E_TABLE_CLICK_TO_ADD_FACTORY_H__ -#define __GAL_A11Y_E_TABLE_CLICK_TO_ADD_FACTORY_H__ - -#include <atk/atkobjectfactory.h> - -#define GAL_A11Y_TYPE_E_TABLE_CLICK_TO_ADD_FACTORY (gal_a11y_e_table_item_click_to_add_factory_get_type ()) -#define GAL_A11Y_E_TABLE_CLICK_TO_ADD_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAL_A11Y_TYPE_E_TABLE_CLICK_TO_ADD_FACTORY, GalA11yETableClickToAddFactory)) -#define GAL_A11Y_E_TABLE_CLICK_TO_ADD_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAL_A11Y_TYPE_E_TABLE_CLICK_TO_ADD_FACTORY, GalA11yETableClickToAddFactoryClass)) -#define GAL_A11Y_IS_E_TABLE_CLICK_TO_ADD_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAL_A11Y_TYPE_E_TABLE_CLICK_TO_ADD_FACTORY)) -#define GAL_A11Y_IS_E_TABLE_CLICK_TO_ADD_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAL_A11Y_TYPE_E_TABLE_CLICK_TO_ADD_FACTORY)) - -typedef struct _GalA11yETableClickToAddFactory GalA11yETableClickToAddFactory; -typedef struct _GalA11yETableClickToAddFactoryClass GalA11yETableClickToAddFactoryClass; - -struct _GalA11yETableClickToAddFactory { - AtkObject object; -}; - -struct _GalA11yETableClickToAddFactoryClass { - AtkObjectClass parent_class; -}; - -/* Standard Glib function */ -GType gal_a11y_e_table_click_to_add_factory_get_type (void); - -#endif diff --git a/widgets/table/gal-a11y-e-table-click-to-add.c b/widgets/table/gal-a11y-e-table-click-to-add.c deleted file mode 100644 index 52466cd7cb..0000000000 --- a/widgets/table/gal-a11y-e-table-click-to-add.c +++ /dev/null @@ -1,358 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Yuedong Du <yuedong.du@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <atk/atk.h> - -#include "a11y/gal-a11y-util.h" -#include "table/e-table-click-to-add.h" -#include "table/e-table-group.h" -#include "table/e-table-group-leaf.h" -#include <glib/gi18n.h> - -#include "gal-a11y-e-table-click-to-add.h" -#include "gal-a11y-e-table-click-to-add-factory.h" - -static AtkObjectClass *parent_class; -static GType parent_type; -static gint priv_offset; -#define GET_PRIVATE(object) \ - ((GalA11yETableClickToAddPrivate *) \ - (((gchar *) object) + priv_offset)) -#define PARENT_TYPE (parent_type) - -struct _GalA11yETableClickToAddPrivate { - gpointer rect; - gpointer row; -}; - -static gint -etcta_get_n_actions (AtkAction *action) -{ - return 1; -} - -static const gchar * -etcta_get_description (AtkAction *action, - gint i) -{ - if (i == 0) - return _("click to add"); - - return NULL; -} - -static const gchar * -etcta_action_get_name (AtkAction *action, - gint i) -{ - if (i == 0) - return _("click"); - - return NULL; -} - -static gboolean -idle_do_action (gpointer data) -{ - GtkLayout *layout; - GdkEventButton event; - ETableClickToAdd * etcta; - gint finished; - - g_return_val_if_fail (data!= NULL, FALSE); - - etcta = E_TABLE_CLICK_TO_ADD ( - atk_gobject_accessible_get_object ( - ATK_GOBJECT_ACCESSIBLE (data))); - g_return_val_if_fail (etcta, FALSE); - - layout = GTK_LAYOUT (GNOME_CANVAS_ITEM (etcta)->canvas); - - event.x = 0; - event.y = 0; - event.type = GDK_BUTTON_PRESS; - event.window = gtk_layout_get_bin_window (layout); - event.button = 1; - event.send_event = TRUE; - event.time = GDK_CURRENT_TIME; - event.axes = NULL; - - g_signal_emit_by_name (etcta, "event", &event, &finished); - - return FALSE; -} - -static gboolean -etcta_do_action (AtkAction *action, - gint i) -{ - g_return_val_if_fail (i == 0, FALSE); - - g_idle_add (idle_do_action, action); - - return TRUE; -} - -static void -atk_action_interface_init (AtkActionIface *iface) -{ - g_return_if_fail (iface != NULL); - - iface->do_action = etcta_do_action; - iface->get_n_actions = etcta_get_n_actions; - iface->get_description = etcta_get_description; - iface->get_name = etcta_action_get_name; -} - -static const gchar * -etcta_get_name (AtkObject *obj) -{ - ETableClickToAdd * etcta; - - g_return_val_if_fail (GAL_A11Y_IS_E_TABLE_CLICK_TO_ADD (obj), NULL); - - etcta = E_TABLE_CLICK_TO_ADD ( - atk_gobject_accessible_get_object ( - ATK_GOBJECT_ACCESSIBLE (obj))); - if (etcta && etcta->message != NULL) - return etcta->message; - - return _("click to add"); -} - -static gint -etcta_get_n_children (AtkObject *accessible) -{ - return 1; -} - -static AtkObject * -etcta_ref_child (AtkObject *accessible, - gint i) -{ - AtkObject * atk_obj = NULL; - ETableClickToAdd * etcta; - - if (i != 0) - return NULL; - - etcta = E_TABLE_CLICK_TO_ADD ( - atk_gobject_accessible_get_object ( - ATK_GOBJECT_ACCESSIBLE (accessible))); - - g_return_val_if_fail (etcta, NULL); - - if (etcta->rect) { - atk_obj = atk_gobject_accessible_for_object ( - G_OBJECT (etcta->rect)); - } else if (etcta->row) { - atk_obj = atk_gobject_accessible_for_object ( - G_OBJECT (etcta->row)); - } - - g_object_ref (atk_obj); - - return atk_obj; -} - -static AtkStateSet * -etcta_ref_state_set (AtkObject *accessible) -{ - AtkStateSet * state_set = NULL; - - state_set = ATK_OBJECT_CLASS (parent_class)->ref_state_set (accessible); - if (state_set != NULL) { - atk_state_set_add_state (state_set, ATK_STATE_SENSITIVE); - atk_state_set_add_state (state_set, ATK_STATE_SHOWING); - } - - return state_set; -} - -static void -etcta_class_init (GalA11yETableClickToAddClass *class) -{ - AtkObjectClass *atk_object_class = ATK_OBJECT_CLASS (class); - - parent_class = g_type_class_ref (PARENT_TYPE); - - atk_object_class->get_name = etcta_get_name; - atk_object_class->get_n_children = etcta_get_n_children; - atk_object_class->ref_child = etcta_ref_child; - atk_object_class->ref_state_set = etcta_ref_state_set; -} - -static void -etcta_init (GalA11yETableClickToAdd *a11y) -{ -} - -GType -gal_a11y_e_table_click_to_add_get_type (void) -{ - static GType type = 0; - - if (!type) { - AtkObjectFactory *factory; - - GTypeInfo info = { - sizeof (GalA11yETableClickToAddClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) etcta_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GalA11yETableClickToAdd), - 0, - (GInstanceInitFunc) etcta_init, - NULL /* value_table */ - }; - - static const GInterfaceInfo atk_action_info = { - (GInterfaceInitFunc) atk_action_interface_init, - (GInterfaceFinalizeFunc) NULL, - NULL - }; - - factory = atk_registry_get_factory ( - atk_get_default_registry (), - GNOME_TYPE_CANVAS_ITEM); - - parent_type = atk_object_factory_get_accessible_type (factory); - type = gal_a11y_type_register_static_with_private ( - PARENT_TYPE, "GalA11yETableClickToAdd", &info, 0, - sizeof (GalA11yETableClickToAddPrivate), &priv_offset); - - g_type_add_interface_static (type, ATK_TYPE_ACTION, &atk_action_info); - - } - - return type; -} - -static gboolean -etcta_event (GnomeCanvasItem *item, - GdkEvent *e, - gpointer data) -{ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item); - GalA11yETableClickToAdd *a11y; - GalA11yETableClickToAddPrivate *priv; - - g_return_val_if_fail (item, TRUE); - - g_return_val_if_fail (GAL_A11Y_IS_E_TABLE_CLICK_TO_ADD (data), FALSE); - a11y = GAL_A11Y_E_TABLE_CLICK_TO_ADD (data); - - priv = GET_PRIVATE (a11y); - - /* rect replaced by row. */ - if (etcta->rect == NULL && priv->rect != NULL) { - g_signal_emit_by_name (a11y, "children_changed::remove", 0, NULL, NULL); - - } - /* row inserted, and/or replaced by a new row. */ - if (etcta->row != NULL && priv->row == NULL) { - g_signal_emit_by_name (a11y, "children_changed::add", 0, NULL, NULL); - } else if (etcta->row != NULL && priv->row != NULL && etcta->row != priv->row) { - g_signal_emit_by_name (a11y, "children_changed::remove", 0, NULL, NULL); - g_signal_emit_by_name (a11y, "children_changed::add", 0, NULL, NULL); - } - - priv->rect = etcta->rect; - priv->row = etcta->row; - - return FALSE; -} - -static void -etcta_selection_cursor_changed (ESelectionModel *esm, - gint row, - gint col, - GalA11yETableClickToAdd *a11y) -{ - ETableClickToAdd *etcta; - AtkObject *row_a11y; - - etcta = E_TABLE_CLICK_TO_ADD ( - atk_gobject_accessible_get_object ( - ATK_GOBJECT_ACCESSIBLE (a11y))); - - if (etcta == NULL || etcta->row == NULL) - return; - - row_a11y = atk_gobject_accessible_for_object (G_OBJECT (etcta->row)); - if (row_a11y) { - AtkObject *cell_a11y; - - cell_a11y = g_object_get_data ( - G_OBJECT (row_a11y), "gail-focus-object"); - if (cell_a11y) { - atk_focus_tracker_notify (cell_a11y); - } - } -} - -AtkObject * -gal_a11y_e_table_click_to_add_new (GObject *widget) -{ - GalA11yETableClickToAdd *a11y; - ETableClickToAdd * etcta; - GalA11yETableClickToAddPrivate *priv; - - g_return_val_if_fail (widget != NULL, NULL); - - a11y = g_object_new (gal_a11y_e_table_click_to_add_get_type (), NULL); - priv = GET_PRIVATE (a11y); - - etcta = E_TABLE_CLICK_TO_ADD (widget); - - atk_object_initialize (ATK_OBJECT (a11y), etcta); - - priv->rect = etcta->rect; - priv->row = etcta->row; - - g_signal_connect_after ( - widget, "event", - G_CALLBACK (etcta_event), a11y); - - g_signal_connect ( - etcta->selection, "cursor_changed", - G_CALLBACK (etcta_selection_cursor_changed), a11y); - - return ATK_OBJECT (a11y); -} - -void -gal_a11y_e_table_click_to_add_init (void) -{ - if (atk_get_root ()) - atk_registry_set_factory_type ( - atk_get_default_registry (), - E_TYPE_TABLE_CLICK_TO_ADD, - gal_a11y_e_table_click_to_add_factory_get_type ()); -} - diff --git a/widgets/table/gal-a11y-e-table-click-to-add.h b/widgets/table/gal-a11y-e-table-click-to-add.h deleted file mode 100644 index 8d95a00baa..0000000000 --- a/widgets/table/gal-a11y-e-table-click-to-add.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __GAL_A11Y_E_TABLE_CLICK_TO_ADD_H__ -#define __GAL_A11Y_E_TABLE_CLICK_TO_ADD_H__ - -#include <table/e-table-item.h> -#include <atk/atkgobjectaccessible.h> - -#define GAL_A11Y_TYPE_E_TABLE_CLICK_TO_ADD (gal_a11y_e_table_click_to_add_get_type ()) -#define GAL_A11Y_E_TABLE_CLICK_TO_ADD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAL_A11Y_TYPE_E_TABLE_CLICK_TO_ADD, GalA11yETableClickToAdd)) -#define GAL_A11Y_E_TABLE_CLICK_TO_ADD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAL_A11Y_TYPE_E_TABLE_CLICK_TO_ADD, GalA11yETableClickToAddClass)) -#define GAL_A11Y_IS_E_TABLE_CLICK_TO_ADD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAL_A11Y_TYPE_E_TABLE_CLICK_TO_ADD)) -#define GAL_A11Y_IS_E_TABLE_CLICK_TO_ADD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAL_A11Y_TYPE_E_TABLE_CLICK_TO_ADD)) - -typedef struct _GalA11yETableClickToAdd GalA11yETableClickToAdd; -typedef struct _GalA11yETableClickToAddClass GalA11yETableClickToAddClass; -typedef struct _GalA11yETableClickToAddPrivate GalA11yETableClickToAddPrivate; - -/* This struct should actually be larger as this isn't what we derive from. - * The GalA11yETableClickToAddPrivate comes right after the parent class structure. - **/ -struct _GalA11yETableClickToAdd { - AtkGObjectAccessible parent; -}; - -struct _GalA11yETableClickToAddClass { - AtkGObjectAccessibleClass parent_class; -}; - -/* Standard Glib function */ -GType gal_a11y_e_table_click_to_add_get_type (void); -AtkObject *gal_a11y_e_table_click_to_add_new (GObject *widget); - -void gal_a11y_e_table_click_to_add_init (void); -#endif /* __GAL_A11Y_E_TABLE_CLICK_TO_ADD_H__ */ diff --git a/widgets/table/gal-a11y-e-table-column-header.c b/widgets/table/gal-a11y-e-table-column-header.c deleted file mode 100644 index 05a99e381b..0000000000 --- a/widgets/table/gal-a11y-e-table-column-header.c +++ /dev/null @@ -1,241 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Li Yuan <li.yuan@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib/gi18n.h> -#include <atk/atkobject.h> -#include <atk/atkregistry.h> -#include "table/e-table-header-item.h" -#include "a11y/gal-a11y-util.h" -#include "gal-a11y-e-table-column-header.h" - -static GObjectClass *parent_class; -static gint priv_offset; - -#define GET_PRIVATE(object) \ - ((GalA11yETableColumnHeaderPrivate *) \ - (((gchar *) object) + priv_offset)) -#define PARENT_TYPE (atk_gobject_accessible_get_type ()) - -struct _GalA11yETableColumnHeaderPrivate { - ETableItem *item; - AtkObject *parent; - AtkStateSet *state_set; -}; - -static void -etch_init (GalA11yETableColumnHeader *a11y) -{ - GET_PRIVATE (a11y)->item = NULL; - GET_PRIVATE (a11y)->parent = NULL; - GET_PRIVATE (a11y)->state_set = NULL; -} - -static AtkStateSet * -gal_a11y_e_table_column_header_ref_state_set (AtkObject *accessible) -{ - GalA11yETableColumnHeaderPrivate *priv = GET_PRIVATE (accessible); - - g_return_val_if_fail (priv->state_set, NULL); - - g_object_ref (priv->state_set); - - return priv->state_set; -} - -static void -gal_a11y_e_table_column_header_real_initialize (AtkObject *obj, - gpointer data) -{ - ATK_OBJECT_CLASS (parent_class)->initialize (obj, data); -} - -static void -gal_a11y_e_table_column_header_dispose (GObject *object) -{ - GalA11yETableColumnHeader *a11y = GAL_A11Y_E_TABLE_COLUMN_HEADER (object); - GalA11yETableColumnHeaderPrivate *priv = GET_PRIVATE (a11y); - - if (priv->state_set) { - g_object_unref (priv->state_set); - priv->state_set = NULL; - } - - if (parent_class->dispose) - parent_class->dispose (object); - -} - -static void -etch_class_init (GalA11yETableColumnHeaderClass *class) -{ - AtkObjectClass *atk_object_class = ATK_OBJECT_CLASS (class); - GObjectClass *object_class = G_OBJECT_CLASS (class); - - parent_class = g_type_class_ref (PARENT_TYPE); - - object_class->dispose = gal_a11y_e_table_column_header_dispose; - - atk_object_class->ref_state_set = gal_a11y_e_table_column_header_ref_state_set; - atk_object_class->initialize = gal_a11y_e_table_column_header_real_initialize; -} - -inline static GObject * -etch_a11y_get_gobject (AtkGObjectAccessible *accessible) -{ - return atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible)); -} - -static gboolean -gal_a11y_e_table_column_header_do_action (AtkAction *action, - gint i) -{ - gboolean return_value = TRUE; - GtkWidget *widget; - GalA11yETableColumnHeader *a11y; - ETableHeaderItem *ethi; - ETableItem *item; - ETableCol *col; - - switch (i) { - case 0: - a11y = GAL_A11Y_E_TABLE_COLUMN_HEADER (action); - col = E_TABLE_COL (etch_a11y_get_gobject ( - ATK_GOBJECT_ACCESSIBLE (a11y))); - item = GET_PRIVATE (a11y)->item; - widget = gtk_widget_get_parent (GTK_WIDGET (item->parent.canvas)); - if (E_IS_TREE (widget)) { - ethi = E_TABLE_HEADER_ITEM ( - e_tree_get_header_item (E_TREE (widget))); - } - else if (E_IS_TABLE (widget)) - ethi = E_TABLE_HEADER_ITEM ( - E_TABLE (widget)->header_item); - else - break; - ethi_change_sort_state (ethi, col); - default: - return_value = FALSE; - break; - } - return return_value; -} - -static gint -gal_a11y_e_table_column_header_get_n_actions (AtkAction *action) -{ - return 1; -} - -static const gchar * -gal_a11y_e_table_column_header_action_get_name (AtkAction *action, - gint i) -{ - const gchar *return_value; - - switch (i) { - case 0: - return_value = _("sort"); - break; - default: - return_value = NULL; - break; - } - return return_value; -} - -static void -atk_action_interface_init (AtkActionIface *iface) -{ - g_return_if_fail (iface != NULL); - - iface->do_action = gal_a11y_e_table_column_header_do_action; - iface->get_n_actions = gal_a11y_e_table_column_header_get_n_actions; - iface->get_name = gal_a11y_e_table_column_header_action_get_name; -} - -GType -gal_a11y_e_table_column_header_get_type (void) -{ - static GType type = 0; - - if (!type) { - GTypeInfo info = { - sizeof (GalA11yETableColumnHeaderClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) etch_class_init, - (GClassFinalizeFunc) NULL, - NULL, - sizeof (GalA11yETableColumnHeader), - 0, - (GInstanceInitFunc) etch_init, - NULL - }; - static const GInterfaceInfo atk_action_info = { - (GInterfaceInitFunc) atk_action_interface_init, - (GInterfaceFinalizeFunc) NULL, - NULL - }; - - type = gal_a11y_type_register_static_with_private ( - PARENT_TYPE, "GalA11yETableColumnHeader", &info, 0, - sizeof (GalA11yETableColumnHeaderPrivate), &priv_offset); - - g_type_add_interface_static ( - type, ATK_TYPE_ACTION, &atk_action_info); - } - - return type; -} - -AtkObject * -gal_a11y_e_table_column_header_new (ETableCol *ecol, - ETableItem *item) -{ - GalA11yETableColumnHeader *a11y; - AtkObject *accessible; - - g_return_val_if_fail (E_IS_TABLE_COL (ecol), NULL); - - a11y = g_object_new (gal_a11y_e_table_column_header_get_type (), NULL); - accessible = ATK_OBJECT (a11y); - atk_object_initialize (accessible, ecol); - - GET_PRIVATE (a11y)->item = item; - GET_PRIVATE (a11y)->state_set = atk_state_set_new (); - - atk_state_set_add_state (GET_PRIVATE (a11y)->state_set, ATK_STATE_VISIBLE); - atk_state_set_add_state (GET_PRIVATE (a11y)->state_set, ATK_STATE_SHOWING); - atk_state_set_add_state (GET_PRIVATE (a11y)->state_set, ATK_STATE_SENSITIVE); - atk_state_set_add_state (GET_PRIVATE (a11y)->state_set, ATK_STATE_ENABLED); - - if (ecol->text) - atk_object_set_name (accessible, ecol->text); - atk_object_set_role (accessible, ATK_ROLE_TABLE_COLUMN_HEADER); - - return ATK_OBJECT (a11y); -} diff --git a/widgets/table/gal-a11y-e-table-column-header.h b/widgets/table/gal-a11y-e-table-column-header.h deleted file mode 100644 index 20d41004f2..0000000000 --- a/widgets/table/gal-a11y-e-table-column-header.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Li Yuan <li.yuan@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __GAL_A11Y_E_TABLE_COLUMN_HEADER_H__ -#define __GAL_A11Y_E_TABLE_COLUMN_HEADER_H__ - -#include <atk/atkgobjectaccessible.h> - -#define GAL_A11Y_TYPE_E_TABLE_COLUMN_HEADER (gal_a11y_e_table_column_header_get_type ()) -#define GAL_A11Y_E_TABLE_COLUMN_HEADER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAL_A11Y_TYPE_E_TABLE_COLUMN_HEADER, GalA11yETableColumnHeader)) -#define GAL_A11Y_E_TABLE_COLUMN_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAL_A11Y_TYPE_E_TABLE_COLUMN_HEADER, GalA11yETableColumnHeaderClass)) -#define GAL_A11Y_IS_E_TABLE_COLUMN_HEADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAL_A11Y_TYPE_E_TABLE_COLUMN_HEADER)) -#define GAL_A11Y_IS_E_TABLE_COLUMN_HEADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAL_A11Y_TYPE_E_TABLE_COLUMN_HEADER)) - -typedef struct _GalA11yETableColumnHeader GalA11yETableColumnHeader; -typedef struct _GalA11yETableColumnHeaderClass GalA11yETableColumnHeaderClass; -typedef struct _GalA11yETableColumnHeaderPrivate GalA11yETableColumnHeaderPrivate; - -struct _GalA11yETableColumnHeader { - AtkGObjectAccessible parent; -}; - -struct _GalA11yETableColumnHeaderClass { - AtkGObjectAccessibleClass parent_class; -}; - -/* Standard Glib function */ -GType gal_a11y_e_table_column_header_get_type (void); -AtkObject *gal_a11y_e_table_column_header_new (ETableCol *etc, ETableItem *item); -void gal_a11y_e_table_column_header_init (void); - -#endif /* __GAL_A11Y_E_TABLE_COLUMN_HEADER_H__ */ diff --git a/widgets/table/gal-a11y-e-table-factory.c b/widgets/table/gal-a11y-e-table-factory.c deleted file mode 100644 index a3905ab393..0000000000 --- a/widgets/table/gal-a11y-e-table-factory.c +++ /dev/null @@ -1,101 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Christopher James Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "gal-a11y-e-table.h" -#include "gal-a11y-e-table-factory.h" - -static AtkObjectFactoryClass *parent_class; -#define PARENT_TYPE (ATK_TYPE_OBJECT_FACTORY) - -/* Static functions */ - -static GType -gal_a11y_e_table_factory_get_accessible_type (void) -{ - return GAL_A11Y_TYPE_E_TABLE; -} - -static AtkObject * -gal_a11y_e_table_factory_create_accessible (GObject *obj) -{ - AtkObject *accessible; - - accessible = gal_a11y_e_table_new (obj); - - return accessible; -} - -static void -gal_a11y_e_table_factory_class_init (GalA11yETableFactoryClass *class) -{ - AtkObjectFactoryClass *factory_class = ATK_OBJECT_FACTORY_CLASS (class); - - parent_class = g_type_class_ref (PARENT_TYPE); - - factory_class->create_accessible = gal_a11y_e_table_factory_create_accessible; - factory_class->get_accessible_type = gal_a11y_e_table_factory_get_accessible_type; -} - -static void -gal_a11y_e_table_factory_init (GalA11yETableFactory *factory) -{ -} - -/** - * gal_a11y_e_table_factory_get_type: - * @void: - * - * Registers the &GalA11yETableFactory class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &GalA11yETableFactory class. - **/ -GType -gal_a11y_e_table_factory_get_type (void) -{ - static GType type = 0; - - if (!type) { - GTypeInfo info = { - sizeof (GalA11yETableFactoryClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) gal_a11y_e_table_factory_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GalA11yETableFactory), - 0, - (GInstanceInitFunc) gal_a11y_e_table_factory_init, - NULL /* value_table */ - }; - - type = g_type_register_static ( - PARENT_TYPE, "GalA11yETableFactory", &info, 0); - } - - return type; -} diff --git a/widgets/table/gal-a11y-e-table-factory.h b/widgets/table/gal-a11y-e-table-factory.h deleted file mode 100644 index 6f66e6b82a..0000000000 --- a/widgets/table/gal-a11y-e-table-factory.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Christopher James Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __GAL_A11Y_E_TABLE_FACTORY_H__ -#define __GAL_A11Y_E_TABLE_FACTORY_H__ - -#include <atk/atkobjectfactory.h> - -#define GAL_A11Y_TYPE_E_TABLE_FACTORY (gal_a11y_e_table_factory_get_type ()) -#define GAL_A11Y_E_TABLE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAL_A11Y_TYPE_E_TABLE_FACTORY, GalA11yETableFactory)) -#define GAL_A11Y_E_TABLE_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAL_A11Y_TYPE_E_TABLE_FACTORY, GalA11yETableFactoryClass)) -#define GAL_A11Y_IS_E_TABLE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAL_A11Y_TYPE_E_TABLE_FACTORY)) -#define GAL_A11Y_IS_E_TABLE_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAL_A11Y_TYPE_E_TABLE_FACTORY)) - -typedef struct _GalA11yETableFactory GalA11yETableFactory; -typedef struct _GalA11yETableFactoryClass GalA11yETableFactoryClass; - -struct _GalA11yETableFactory { - AtkObject object; -}; - -struct _GalA11yETableFactoryClass { - AtkObjectClass parent_class; -}; - -/* Standard Glib function */ -GType gal_a11y_e_table_factory_get_type (void); - -#endif /* __GAL_A11Y_E_TABLE_FACTORY_H__ */ diff --git a/widgets/table/gal-a11y-e-table-item-factory.c b/widgets/table/gal-a11y-e-table-item-factory.c deleted file mode 100644 index a38269bd81..0000000000 --- a/widgets/table/gal-a11y-e-table-item-factory.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Yuedong Du <yuedong.du@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <atk/atk.h> - -#include "table/e-table.h" -#include "table/e-tree.h" - -#include "gal-a11y-e-table.h" -#include "gal-a11y-e-table-item.h" -#include "gal-a11y-e-table-item-factory.h" - -#define CS_CLASS(factory) (G_TYPE_INSTANCE_GET_CLASS ((factory), C_TYPE_STREAM, GalA11yETableItemFactoryClass)) -static AtkObjectFactoryClass *parent_class; -#define PARENT_TYPE (ATK_TYPE_OBJECT_FACTORY) - -/* Static functions */ - -static GType -gal_a11y_e_table_item_factory_get_accessible_type (void) -{ - return GAL_A11Y_TYPE_E_TABLE_ITEM; -} - -static AtkObject * -gal_a11y_e_table_item_factory_create_accessible (GObject *obj) -{ - AtkObject *accessible; - - g_return_val_if_fail (E_IS_TABLE_ITEM (obj), NULL); - accessible = gal_a11y_e_table_item_new (E_TABLE_ITEM (obj)); - - return accessible; -} - -static void -gal_a11y_e_table_item_factory_class_init (GalA11yETableItemFactoryClass *class) -{ - AtkObjectFactoryClass *factory_class = ATK_OBJECT_FACTORY_CLASS (class); - - parent_class = g_type_class_ref (PARENT_TYPE); - - factory_class->create_accessible = gal_a11y_e_table_item_factory_create_accessible; - factory_class->get_accessible_type = gal_a11y_e_table_item_factory_get_accessible_type; -} - -static void -gal_a11y_e_table_item_factory_init (GalA11yETableItemFactory *factory) -{ -} - -/** - * gal_a11y_e_table_factory_get_type: - * @void: - * - * Registers the &GalA11yETableFactory class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &GalA11yETableFactory class. - **/ -GType -gal_a11y_e_table_item_factory_get_type (void) -{ - static GType type = 0; - - if (!type) { - GTypeInfo info = { - sizeof (GalA11yETableItemFactoryClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) gal_a11y_e_table_item_factory_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GalA11yETableItemFactory), - 0, - (GInstanceInitFunc) gal_a11y_e_table_item_factory_init, - NULL /* value_table */ - }; - - type = g_type_register_static (PARENT_TYPE, "GalA11yETableItemFactory", &info, 0); - } - - return type; -} diff --git a/widgets/table/gal-a11y-e-table-item-factory.h b/widgets/table/gal-a11y-e-table-item-factory.h deleted file mode 100644 index c2995eaaf0..0000000000 --- a/widgets/table/gal-a11y-e-table-item-factory.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Yuedong Du <yuedong.du@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __GAL_A11Y_E_TABLE_ITEM_FACTORY_H__ -#define __GAL_A11Y_E_TABLE_ITEM_FACTORY_H__ - -#include <atk/atkobjectfactory.h> - -#define GAL_A11Y_TYPE_E_TABLE_ITEM_FACTORY (gal_a11y_e_table_item_factory_get_type ()) -#define GAL_A11Y_E_TABLE_ITEM_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAL_A11Y_TYPE_E_TABLE_ITEM_FACTORY, GalA11yETableItemFactory)) -#define GAL_A11Y_E_TABLE_ITEM_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAL_A11Y_TYPE_E_TABLE_ITEM_FACTORY, GalA11yETableItemFactoryClass)) -#define GAL_A11Y_IS_E_TABLE_ITEM_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAL_A11Y_TYPE_E_TABLE_ITEM_FACTORY)) -#define GAL_A11Y_IS_E_TABLE_ITEM_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAL_A11Y_TYPE_E_TABLE_ITEM_FACTORY)) - -typedef struct _GalA11yETableItemFactory GalA11yETableItemFactory; -typedef struct _GalA11yETableItemFactoryClass GalA11yETableItemFactoryClass; - -struct _GalA11yETableItemFactory { - AtkObject object; -}; - -struct _GalA11yETableItemFactoryClass { - AtkObjectClass parent_class; -}; - -/* Standard Glib function */ -GType gal_a11y_e_table_item_factory_get_type (void); - -#endif /* __GAL_A11Y_E_TABLE_FACTORY_H__ */ diff --git a/widgets/table/gal-a11y-e-table-item.c b/widgets/table/gal-a11y-e-table-item.c deleted file mode 100644 index d5a0edefdc..0000000000 --- a/widgets/table/gal-a11y-e-table-item.c +++ /dev/null @@ -1,1437 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Christopher James Lahey <clahey@ximian.com> - * Bolian Yin <bolian.yin@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <string.h> - -#include <atk/atk.h> - -#include "a11y/gal-a11y-util.h" -#include "table/e-table-click-to-add.h" -#include "table/e-table-subset.h" -#include "table/e-table.h" -#include "table/e-tree.h" -#include "misc/e-canvas.h" -#include "misc/e-selection-model.h" - -#include "gal-a11y-e-table-item.h" -#include "gal-a11y-e-table-item-factory.h" -#include "gal-a11y-e-table-click-to-add.h" -#include "gal-a11y-e-cell-registry.h" -#include "gal-a11y-e-cell.h" -#include "gal-a11y-e-table-column-header.h" - -static GObjectClass *parent_class; -static AtkComponentIface *component_parent_iface; -static GType parent_type; -static gint priv_offset; -static GQuark quark_accessible_object = 0; -#define GET_PRIVATE(object) \ - ((GalA11yETableItemPrivate *) (((gchar *) object) + priv_offset)) -#define PARENT_TYPE (parent_type) - -struct _GalA11yETableItemPrivate { - ETableItem *item; - gint cols; - gint rows; - gint selection_change_id; - gint cursor_change_id; - ETableCol ** columns; - ESelectionModel *selection; - AtkStateSet *state_set; - GtkWidget *widget; -}; - -static gboolean gal_a11y_e_table_item_ref_selection (GalA11yETableItem *a11y, - ESelectionModel *selection); -static gboolean gal_a11y_e_table_item_unref_selection (GalA11yETableItem *a11y); - -static AtkObject * eti_ref_at (AtkTable *table, gint row, gint column); - -static void -free_columns (ETableCol **columns) -{ - gint ii; - - if (!columns) - return; - - for (ii = 0; columns[ii]; ii++) { - g_object_unref (columns[ii]); - } - - g_free (columns); -} - -static void -item_finalized (gpointer user_data, - GObject *gone_item) -{ - GalA11yETableItem *a11y; - GalA11yETableItemPrivate *priv; - - a11y = GAL_A11Y_E_TABLE_ITEM (user_data); - priv = GET_PRIVATE (a11y); - - priv->item = NULL; - - atk_state_set_add_state (priv->state_set, ATK_STATE_DEFUNCT); - atk_object_notify_state_change (ATK_OBJECT (a11y), ATK_STATE_DEFUNCT, TRUE); - - if (priv->selection) - gal_a11y_e_table_item_unref_selection (a11y); - - g_object_unref (a11y); -} - -static AtkStateSet * -eti_ref_state_set (AtkObject *accessible) -{ - GalA11yETableItemPrivate *priv = GET_PRIVATE (accessible); - - g_object_ref (priv->state_set); - - return priv->state_set; -} - -inline static gint -view_to_model_row (ETableItem *eti, - gint row) -{ - if (eti->uses_source_model) { - ETableSubset *etss = E_TABLE_SUBSET (eti->table_model); - if (row >= 0 && row < etss->n_map) { - eti->row_guess = row; - return etss->map_table[row]; - } else - return -1; - } else - return row; -} - -inline static gint -view_to_model_col (ETableItem *eti, - gint col) -{ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - return ecol ? ecol->col_idx : -1; -} - -inline static gint -model_to_view_row (ETableItem *eti, - gint row) -{ - gint i; - if (row == -1) - return -1; - 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 -model_to_view_col (ETableItem *eti, - gint col) -{ - gint i; - if (col == -1) - return -1; - 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 GObject * -eti_a11y_get_gobject (AtkObject *accessible) -{ - return atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible)); -} - -static void -eti_a11y_reset_focus_object (GalA11yETableItem *a11y, - ETableItem *item, - gboolean notify) -{ - ESelectionModel * esm; - gint cursor_row, cursor_col, view_row, view_col; - AtkObject *cell, *old_cell; - - esm = item->selection; - g_return_if_fail (esm); - - cursor_row = e_selection_model_cursor_row (esm); - cursor_col = e_selection_model_cursor_col (esm); - - view_row = model_to_view_row (item, cursor_row); - view_col = model_to_view_col (item, cursor_col); - - if (view_row == -1) - view_row = 0; - if (view_col == -1) - view_col = 0; - - old_cell = (AtkObject *) g_object_get_data (G_OBJECT (a11y), "gail-focus-object"); - if (old_cell && GAL_A11Y_IS_E_CELL (old_cell)) - gal_a11y_e_cell_remove_state ( - GAL_A11Y_E_CELL (old_cell), ATK_STATE_FOCUSED, FALSE); - if (old_cell) - g_object_unref (old_cell); - - cell = eti_ref_at (ATK_TABLE (a11y), view_row, view_col); - - if (cell != NULL) { - g_object_set_data (G_OBJECT (a11y), "gail-focus-object", cell); - gal_a11y_e_cell_add_state ( - GAL_A11Y_E_CELL (cell), ATK_STATE_FOCUSED, FALSE); - } else - g_object_set_data (G_OBJECT (a11y), "gail-focus-object", NULL); - - if (notify && cell) - atk_focus_tracker_notify (cell); -} - -static void -eti_dispose (GObject *object) -{ - GalA11yETableItem *a11y = GAL_A11Y_E_TABLE_ITEM (object); - GalA11yETableItemPrivate *priv = GET_PRIVATE (a11y); - - if (priv->columns) { - free_columns (priv->columns); - priv->columns = NULL; - } - - if (priv->item) { - g_object_weak_unref (G_OBJECT (priv->item), item_finalized, a11y); - priv->item = NULL; - } - - if (parent_class->dispose) - parent_class->dispose (object); -} - -/* Static functions */ -static gint -eti_get_n_children (AtkObject *accessible) -{ - g_return_val_if_fail (GAL_A11Y_IS_E_TABLE_ITEM (accessible), 0); - if (!eti_a11y_get_gobject (accessible)) - return 0; - - return atk_table_get_n_columns (ATK_TABLE (accessible)) * - (atk_table_get_n_rows (ATK_TABLE (accessible)) + 1); -} - -static AtkObject * -eti_ref_child (AtkObject *accessible, - gint index) -{ - ETableItem *item; - gint col, row; - - g_return_val_if_fail (GAL_A11Y_IS_E_TABLE_ITEM (accessible), NULL); - item = E_TABLE_ITEM (eti_a11y_get_gobject (accessible)); - if (!item) - return NULL; - - if (index < item->cols) { - ETableCol *ecol; - AtkObject *child; - - ecol = e_table_header_get_column (item->header, index); - child = gal_a11y_e_table_column_header_new (ecol, item); - return child; - } - index -= item->cols; - - col = index % item->cols; - row = index / item->cols; - - return eti_ref_at (ATK_TABLE (accessible), row, col); -} - -static void -eti_get_extents (AtkComponent *component, - gint *x, - gint *y, - gint *width, - gint *height, - AtkCoordType coord_type) -{ - ETableItem *item; - AtkObject *parent; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (component))); - if (!item) - return; - - parent = ATK_OBJECT (component)->accessible_parent; - if (parent && ATK_IS_COMPONENT (parent)) - atk_component_get_extents ( - ATK_COMPONENT (parent), - x, y, - width, height, - coord_type); - - if (parent && GAL_A11Y_IS_E_TABLE_CLICK_TO_ADD (parent)) { - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD ( - atk_gobject_accessible_get_object ( - ATK_GOBJECT_ACCESSIBLE (parent))); - if (etcta) { - *width = etcta->width; - *height = etcta->height; - } - } -} - -static AtkObject * -eti_ref_accessible_at_point (AtkComponent *component, - gint x, - gint y, - AtkCoordType coord_type) -{ - gint row = -1; - gint col = -1; - gint x_origin, y_origin; - ETableItem *item; - GtkWidget *tableOrTree; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (component))); - if (!item) - return NULL; - - atk_component_get_position ( - component, - &x_origin, - &y_origin, - coord_type); - x -= x_origin; - y -= y_origin; - - tableOrTree = gtk_widget_get_parent (GTK_WIDGET (item->parent.canvas)); - - if (E_IS_TREE (tableOrTree)) - e_tree_get_cell_at (E_TREE (tableOrTree), x, y, &row, &col); - else - e_table_get_cell_at (E_TABLE (tableOrTree), x, y, &row, &col); - - if (row != -1 && col != -1) { - return eti_ref_at (ATK_TABLE (component), row, col); - } else { - return NULL; - } -} - -static void -cell_destroyed (gpointer data) -{ - GalA11yECell * cell; - - g_return_if_fail (GAL_A11Y_IS_E_CELL (data)); - cell = GAL_A11Y_E_CELL (data); - - g_return_if_fail (cell->item && G_IS_OBJECT (cell->item)); - - if (cell->item) { - g_object_unref (cell->item); - cell->item = NULL; - } - -} - -/* atk table */ -static AtkObject * -eti_ref_at (AtkTable *table, - gint row, - gint column) -{ - ETableItem *item; - AtkObject * ret; - GalA11yETableItemPrivate *priv = GET_PRIVATE (table); - - if (atk_state_set_contains_state (priv->state_set, ATK_STATE_DEFUNCT)) - return NULL; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); - if (!item) - return NULL; - - if (column >= 0 && - column < item->cols && - row >= 0 && - row < item->rows && - item->cell_views_realized) { - ECellView *cell_view = item->cell_views[column]; - ETableCol *ecol = e_table_header_get_column (item->header, column); - ret = gal_a11y_e_cell_registry_get_object ( - NULL, - item, - cell_view, - ATK_OBJECT (table), - ecol->col_idx, - column, - row); - if (ATK_IS_OBJECT (ret)) { - g_object_weak_ref ( - G_OBJECT (ret), - (GWeakNotify) cell_destroyed, - ret); - /* if current cell is focused, add FOCUSED state */ - if (e_selection_model_cursor_row (item->selection) == - GAL_A11Y_E_CELL (ret)->row && - e_selection_model_cursor_col (item->selection) == - GAL_A11Y_E_CELL (ret)->model_col) - gal_a11y_e_cell_add_state ( - GAL_A11Y_E_CELL (ret), - ATK_STATE_FOCUSED, FALSE); - } else - ret = NULL; - - return ret; - } - - return NULL; -} - -static gint -eti_get_index_at (AtkTable *table, - gint row, - gint column) -{ - ETableItem *item; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); - if (!item) - return -1; - - return column + (row + 1) * item->cols; -} - -static gint -eti_get_column_at_index (AtkTable *table, - gint index) -{ - ETableItem *item; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); - if (!item) - return -1; - - return index % item->cols; -} - -static gint -eti_get_row_at_index (AtkTable *table, - gint index) -{ - ETableItem *item; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); - if (!item) - return -1; - - return index / item->cols - 1; -} - -static gint -eti_get_n_columns (AtkTable *table) -{ - ETableItem *item; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); - if (!item) - return -1; - - return item->cols; -} - -static gint -eti_get_n_rows (AtkTable *table) -{ - ETableItem *item; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); - if (!item) - return -1; - - return item->rows; -} - -static gint -eti_get_column_extent_at (AtkTable *table, - gint row, - gint column) -{ - ETableItem *item; - gint width; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); - if (!item) - return -1; - - e_table_item_get_cell_geometry ( - item, - &row, - &column, - NULL, - NULL, - &width, - NULL); - - return width; -} - -static gint -eti_get_row_extent_at (AtkTable *table, - gint row, - gint column) -{ - ETableItem *item; - gint height; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); - if (!item) - return -1; - - e_table_item_get_cell_geometry ( - item, - &row, - &column, - NULL, - NULL, - NULL, - &height); - - return height; -} - -static AtkObject * -eti_get_caption (AtkTable *table) -{ - /* Unimplemented */ - return NULL; -} - -static const gchar * -eti_get_column_description (AtkTable *table, - gint column) -{ - ETableItem *item; - ETableCol *ecol; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); - if (!item) - return NULL; - - ecol = e_table_header_get_column (item->header, column); - - return ecol->text; -} - -static AtkObject * -eti_get_column_header (AtkTable *table, - gint column) -{ - ETableItem *item; - ETableCol *ecol; - AtkObject *atk_obj = NULL; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); - if (!item) - return NULL; - - ecol = e_table_header_get_column (item->header, column); - if (ecol) { - atk_obj = gal_a11y_e_table_column_header_new (ecol, item); - } - - return atk_obj; -} - -static const gchar * -eti_get_row_description (AtkTable *table, - gint row) -{ - /* Unimplemented */ - return NULL; -} - -static AtkObject * -eti_get_row_header (AtkTable *table, - gint row) -{ - /* Unimplemented */ - return NULL; -} - -static AtkObject * -eti_get_summary (AtkTable *table) -{ - /* Unimplemented */ - return NULL; -} - -static gboolean -table_is_row_selected (AtkTable *table, - gint row) -{ - ETableItem *item; - GalA11yETableItemPrivate *priv = GET_PRIVATE (table); - - if (row < 0) - return FALSE; - - if (atk_state_set_contains_state (priv->state_set, ATK_STATE_DEFUNCT)) - return FALSE; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); - if (!item) - return FALSE; - - return e_selection_model_is_row_selected ( - item->selection, view_to_model_row (item, row)); -} - -static gboolean -table_is_selected (AtkTable *table, - gint row, - gint column) -{ - return table_is_row_selected (table, row); -} - -static gint -table_get_selected_rows (AtkTable *table, - gint **rows_selected) -{ - ETableItem *item; - gint n_selected, row, index_selected; - GalA11yETableItemPrivate *priv = GET_PRIVATE (table); - - if (atk_state_set_contains_state (priv->state_set, ATK_STATE_DEFUNCT)) - return 0; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); - if (!item) - return 0; - - n_selected = e_selection_model_selected_count (item->selection); - if (rows_selected) { - *rows_selected = (gint *) g_malloc (n_selected * sizeof (gint)); - - index_selected = 0; - for (row = 0; row < item->rows && index_selected < n_selected; ++row) { - if (atk_table_is_row_selected (table, row)) { - (*rows_selected)[index_selected] = row; - ++index_selected; - } - } - } - return n_selected; -} - -static gboolean -table_add_row_selection (AtkTable *table, - gint row) -{ - ETableItem *item; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); - if (!item) - return FALSE; - - if (table_is_row_selected (table, row)) - return TRUE; - e_selection_model_toggle_single_row ( - item->selection, - view_to_model_row (item, row)); - - return TRUE; -} - -static gboolean -table_remove_row_selection (AtkTable *table, - gint row) -{ - ETableItem *item; - GalA11yETableItemPrivate *priv = GET_PRIVATE (table); - - if (atk_state_set_contains_state (priv->state_set, ATK_STATE_DEFUNCT)) - return FALSE; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (table))); - if (!item) - return FALSE; - - if (!atk_table_is_row_selected (table, row)) - return TRUE; - - e_selection_model_toggle_single_row ( - item->selection, view_to_model_row (item, row)); - - return TRUE; -} - -static void -eti_atk_table_iface_init (AtkTableIface *iface) -{ - iface->ref_at = eti_ref_at; - iface->get_index_at = eti_get_index_at; - iface->get_column_at_index = eti_get_column_at_index; - iface->get_row_at_index = eti_get_row_at_index; - iface->get_n_columns = eti_get_n_columns; - iface->get_n_rows = eti_get_n_rows; - iface->get_column_extent_at = eti_get_column_extent_at; - iface->get_row_extent_at = eti_get_row_extent_at; - iface->get_caption = eti_get_caption; - iface->get_column_description = eti_get_column_description; - iface->get_column_header = eti_get_column_header; - iface->get_row_description = eti_get_row_description; - iface->get_row_header = eti_get_row_header; - iface->get_summary = eti_get_summary; - - iface->is_row_selected = table_is_row_selected; - iface->is_selected = table_is_selected; - iface->get_selected_rows = table_get_selected_rows; - iface->add_row_selection = table_add_row_selection; - iface->remove_row_selection = table_remove_row_selection; -} - -static void -eti_atk_component_iface_init (AtkComponentIface *iface) -{ - component_parent_iface = g_type_interface_peek_parent (iface); - - iface->ref_accessible_at_point = eti_ref_accessible_at_point; - iface->get_extents = eti_get_extents; -} - -static void -eti_rows_inserted (ETableModel *model, - gint row, - gint count, - AtkObject *table_item) -{ - gint n_cols,n_rows,i,j; - GalA11yETableItem * item_a11y; - gint old_nrows; - - g_return_if_fail (table_item); - item_a11y = GAL_A11Y_E_TABLE_ITEM (table_item); - - n_cols = atk_table_get_n_columns (ATK_TABLE (table_item)); - n_rows = atk_table_get_n_rows (ATK_TABLE (table_item)); - - old_nrows = GET_PRIVATE (item_a11y)->rows; - - g_return_if_fail (n_cols > 0 && n_rows > 0); - g_return_if_fail (old_nrows == n_rows - count); - - GET_PRIVATE (table_item)->rows = n_rows; - - g_signal_emit_by_name ( - table_item, "row-inserted", row, - count, NULL); - - for (i = row; i < (row + count); i++) { - for (j = 0; j < n_cols; j++) { - g_signal_emit_by_name ( - table_item, - "children_changed::add", - (((i + 1) * n_cols) + j), NULL, NULL); - } - } - - g_signal_emit_by_name (table_item, "visible-data-changed"); -} - -static void -eti_rows_deleted (ETableModel *model, - gint row, - gint count, - AtkObject *table_item) -{ - gint i,j, n_rows, n_cols, old_nrows; - ETableItem *item = E_TABLE_ITEM ( - atk_gobject_accessible_get_object ( - ATK_GOBJECT_ACCESSIBLE (table_item))); - - n_rows = atk_table_get_n_rows (ATK_TABLE (table_item)); - n_cols = atk_table_get_n_columns (ATK_TABLE (table_item)); - - old_nrows = GET_PRIVATE (table_item)->rows; - - g_return_if_fail (row + count <= old_nrows); - g_return_if_fail (old_nrows == n_rows + count); - GET_PRIVATE (table_item)->rows = n_rows; - - g_signal_emit_by_name ( - table_item, "row-deleted", row, - count, NULL); - - for (i = row; i < (row + count); i++) { - for (j = 0; j < n_cols; j++) { - g_signal_emit_by_name ( - table_item, - "children_changed::remove", - (((i + 1) * n_cols) + j), NULL, NULL); - } - } - g_signal_emit_by_name (table_item, "visible-data-changed"); - eti_a11y_reset_focus_object ((GalA11yETableItem *) table_item, item, TRUE); -} - -static void -eti_tree_model_node_changed_cb (ETreeModel *model, - ETreePath node, - ETableItem *eti) -{ - AtkObject *atk_obj; - GalA11yETableItem *a11y; - - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - atk_obj = atk_gobject_accessible_for_object (G_OBJECT (eti)); - a11y = GAL_A11Y_E_TABLE_ITEM (atk_obj); - - /* we can't figure out which rows are changed, so just send out a signal ... */ - if (GET_PRIVATE (a11y)->rows > 0) - g_signal_emit_by_name (a11y, "visible-data-changed"); -} - -enum { - ETI_HEADER_UNCHANGED = 0, - ETI_HEADER_REORDERED, - ETI_HEADER_NEW_ADDED, - ETI_HEADER_REMOVED -}; - -/* - * 1. Check what actually happened: column reorder, remove or add - * 2. Update cache - * 3. Emit signals - */ -static void -eti_header_structure_changed (ETableHeader *eth, - AtkObject *a11y) -{ - - gboolean reorder_found = FALSE, added_found = FALSE, removed_found = FALSE; - GalA11yETableItem * a11y_item; - ETableCol ** cols, **prev_cols; - GalA11yETableItemPrivate *priv; - gint *state = NULL, *prev_state = NULL, *reorder = NULL; - gint i,j,n_rows,n_cols, prev_n_cols; - - a11y_item = GAL_A11Y_E_TABLE_ITEM (a11y); - priv = GET_PRIVATE (a11y_item); - - /* Assume rows do not changed. */ - n_rows = priv->rows; - - prev_n_cols = priv->cols; - prev_cols = priv->columns; - - cols = e_table_header_get_columns (eth); - n_cols = eth->col_count; - - g_return_if_fail (cols && prev_cols && n_cols > 0); - - /* Init to ETI_HEADER_UNCHANGED. */ - state = g_malloc0 (sizeof (gint) * n_cols); - prev_state = g_malloc0 (sizeof (gint) * prev_n_cols); - reorder = g_malloc0 (sizeof (gint) * n_cols); - - /* Compare with previously saved column headers. */ - for (i = 0; i < n_cols && cols[i]; i++) { - for (j = 0; j < prev_n_cols && prev_cols[j]; j++) { - if (prev_cols[j] == cols[i] && i != j) { - - reorder_found = TRUE; - state[i] = ETI_HEADER_REORDERED; - reorder[i] = j; - - break; - } else if (prev_cols[j] == cols[i]) { - /* OK, this column is not changed. */ - break; - } - } - - /* cols[i] is new added column. */ - if (j == prev_n_cols) { - added_found = TRUE; - state[i] = ETI_HEADER_NEW_ADDED; - } - } - - /* Now try to find if there are removed columns. */ - for (i = 0; i < prev_n_cols && prev_cols[i]; i++) { - for (j = 0; j < n_cols && cols[j]; j++) - if (prev_cols[j] == cols[i]) - break; - - /* Removed columns found. */ - if (j == n_cols) { - removed_found = TRUE; - prev_state[j] = ETI_HEADER_REMOVED; - } - } - - /* If nothing interesting just return. */ - if (!reorder_found && !added_found && !removed_found) - return; - - /* Emit signals */ - if (reorder_found) - g_signal_emit_by_name (a11y_item, "column_reordered"); - - if (removed_found) { - for (i = 0; i < prev_n_cols; i++) { - if (prev_state[i] == ETI_HEADER_REMOVED) { - g_signal_emit_by_name ( - a11y_item, "column-deleted", i, 1); - for (j = 0; j < n_rows; j++) - g_signal_emit_by_name ( - a11y_item, - "children_changed::remove", - ((j + 1) * prev_n_cols + i), - NULL, NULL); - } - } - } - - if (added_found) { - for (i = 0; i < n_cols; i++) { - if (state[i] == ETI_HEADER_NEW_ADDED) { - g_signal_emit_by_name ( - a11y_item, "column-inserted", i, 1); - for (j = 0; j < n_rows; j++) - g_signal_emit_by_name ( - a11y_item, - "children_changed::add", - ((j + 1) * n_cols + i), - NULL, NULL); - } - } - } - - priv->cols = n_cols; - - g_free (state); - g_free (reorder); - g_free (prev_state); - - free_columns (priv->columns); - priv->columns = cols; -} - -static void -eti_real_initialize (AtkObject *obj, - gpointer data) -{ - ETableItem * eti; - ETableModel * model; - - ATK_OBJECT_CLASS (parent_class)->initialize (obj, data); - eti = E_TABLE_ITEM (data); - - model = eti->table_model; - - g_signal_connect ( - model, "model-rows-inserted", - G_CALLBACK (eti_rows_inserted), obj); - g_signal_connect ( - model, "model-rows-deleted", - G_CALLBACK (eti_rows_deleted), obj); - g_signal_connect ( - eti->header, "structure_change", - G_CALLBACK (eti_header_structure_changed), obj); - -} - -static void -eti_class_init (GalA11yETableItemClass *class) -{ - AtkObjectClass *atk_object_class = ATK_OBJECT_CLASS (class); - GObjectClass *object_class = G_OBJECT_CLASS (class); - - quark_accessible_object = - g_quark_from_static_string ("gtk-accessible-object"); - - parent_class = g_type_class_ref (PARENT_TYPE); - - object_class->dispose = eti_dispose; - - atk_object_class->get_n_children = eti_get_n_children; - atk_object_class->ref_child = eti_ref_child; - atk_object_class->initialize = eti_real_initialize; - atk_object_class->ref_state_set = eti_ref_state_set; -} - -static void -eti_init (GalA11yETableItem *a11y) -{ - GalA11yETableItemPrivate *priv; - - priv = GET_PRIVATE (a11y); - - priv->selection_change_id = 0; - priv->cursor_change_id = 0; - priv->selection = NULL; -} - -/* atk selection */ - -static void atk_selection_interface_init (AtkSelectionIface *iface); -static gboolean selection_add_selection (AtkSelection *selection, - gint i); -static gboolean selection_clear_selection (AtkSelection *selection); -static AtkObject * - selection_ref_selection (AtkSelection *selection, - gint i); -static gint selection_get_selection_count (AtkSelection *selection); -static gboolean selection_is_child_selected (AtkSelection *selection, - gint i); - -/* callbacks */ -static void eti_a11y_selection_model_removed_cb (ETableItem *eti, - ESelectionModel *selection, - gpointer data); -static void eti_a11y_selection_model_added_cb (ETableItem *eti, - ESelectionModel *selection, - gpointer data); -static void eti_a11y_selection_changed_cb (ESelectionModel *selection, - GalA11yETableItem *a11y); -static void eti_a11y_cursor_changed_cb (ESelectionModel *selection, - gint row, gint col, - GalA11yETableItem *a11y); - -/** - * gal_a11y_e_table_item_get_type: - * @void: - * - * Registers the &GalA11yETableItem class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &GalA11yETableItem class. - **/ -GType -gal_a11y_e_table_item_get_type (void) -{ - static GType type = 0; - - if (!type) { - AtkObjectFactory *factory; - - GTypeInfo info = { - sizeof (GalA11yETableItemClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) eti_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GalA11yETableItem), - 0, - (GInstanceInitFunc) eti_init, - NULL /* value_table_item */ - }; - - static const GInterfaceInfo atk_component_info = { - (GInterfaceInitFunc) eti_atk_component_iface_init, - (GInterfaceFinalizeFunc) NULL, - NULL - }; - static const GInterfaceInfo atk_table_info = { - (GInterfaceInitFunc) eti_atk_table_iface_init, - (GInterfaceFinalizeFunc) NULL, - NULL - }; - - static const GInterfaceInfo atk_selection_info = { - (GInterfaceInitFunc) atk_selection_interface_init, - (GInterfaceFinalizeFunc) NULL, - NULL - }; - - factory = atk_registry_get_factory ( - atk_get_default_registry (), GNOME_TYPE_CANVAS_ITEM); - parent_type = atk_object_factory_get_accessible_type (factory); - - type = gal_a11y_type_register_static_with_private ( - PARENT_TYPE, "GalA11yETableItem", &info, 0, - sizeof (GalA11yETableItemPrivate), &priv_offset); - - g_type_add_interface_static (type, ATK_TYPE_COMPONENT, &atk_component_info); - g_type_add_interface_static (type, ATK_TYPE_TABLE, &atk_table_info); - g_type_add_interface_static (type, ATK_TYPE_SELECTION, &atk_selection_info); - } - - return type; -} - -AtkObject * -gal_a11y_e_table_item_new (ETableItem *item) -{ - GalA11yETableItem *a11y; - AtkObject *accessible; - ESelectionModel * esm; - AtkObject *parent; - const gchar *name; - - g_return_val_if_fail (item && item->cols >= 0 && item->rows >= 0, NULL); - a11y = g_object_new (gal_a11y_e_table_item_get_type (), NULL); - - atk_object_initialize (ATK_OBJECT (a11y), item); - - GET_PRIVATE (a11y)->state_set = atk_state_set_new (); - - atk_state_set_add_state (GET_PRIVATE (a11y)->state_set, ATK_STATE_TRANSIENT); - atk_state_set_add_state (GET_PRIVATE (a11y)->state_set, ATK_STATE_ENABLED); - atk_state_set_add_state (GET_PRIVATE (a11y)->state_set, ATK_STATE_SENSITIVE); - atk_state_set_add_state (GET_PRIVATE (a11y)->state_set, ATK_STATE_SHOWING); - atk_state_set_add_state (GET_PRIVATE (a11y)->state_set, ATK_STATE_VISIBLE); - - accessible = ATK_OBJECT (a11y); - - GET_PRIVATE (a11y)->item = item; - /* Initialize cell data. */ - GET_PRIVATE (a11y)->cols = item->cols; - GET_PRIVATE (a11y)->rows = item->rows; - - GET_PRIVATE (a11y)->columns = e_table_header_get_columns (item->header); - if (GET_PRIVATE (a11y)->columns == NULL) - return NULL; - - if (item) { - g_signal_connect ( - item, "selection_model_removed", - G_CALLBACK (eti_a11y_selection_model_removed_cb), NULL); - g_signal_connect ( - item, "selection_model_added", - G_CALLBACK (eti_a11y_selection_model_added_cb), NULL); - if (item->selection) - gal_a11y_e_table_item_ref_selection ( - a11y, - item->selection); - - /* find the TableItem's parent: table or tree */ - GET_PRIVATE (a11y)->widget = gtk_widget_get_parent ( - GTK_WIDGET (item->parent.canvas)); - parent = gtk_widget_get_accessible (GET_PRIVATE (a11y)->widget); - name = atk_object_get_name (parent); - if (name) - atk_object_set_name (accessible, name); - atk_object_set_parent (accessible, parent); - - if (E_IS_TREE (GET_PRIVATE (a11y)->widget)) { - ETreeModel *model; - model = e_tree_get_model (E_TREE (GET_PRIVATE (a11y)->widget)); - g_signal_connect ( - model, "node_changed", - G_CALLBACK (eti_tree_model_node_changed_cb), item); - accessible->role = ATK_ROLE_TREE_TABLE; - } else if (E_IS_TABLE (GET_PRIVATE (a11y)->widget)) { - accessible->role = ATK_ROLE_TABLE; - } - } - - if (item) - g_object_weak_ref (G_OBJECT (item), item_finalized, g_object_ref (a11y)); - - esm = item->selection; - - if (esm != NULL) { - eti_a11y_reset_focus_object (a11y, item, FALSE); - } - - return ATK_OBJECT (a11y); -} - -static gboolean -gal_a11y_e_table_item_ref_selection (GalA11yETableItem *a11y, - ESelectionModel *selection) -{ - GalA11yETableItemPrivate *priv; - - g_return_val_if_fail (a11y && selection, FALSE); - - priv = GET_PRIVATE (a11y); - priv->selection_change_id = g_signal_connect ( - selection, "selection_changed", - G_CALLBACK (eti_a11y_selection_changed_cb), a11y); - priv->cursor_change_id = g_signal_connect ( - selection, "cursor_changed", - G_CALLBACK (eti_a11y_cursor_changed_cb), a11y); - - priv->selection = selection; - g_object_ref (selection); - - return TRUE; -} - -static gboolean -gal_a11y_e_table_item_unref_selection (GalA11yETableItem *a11y) -{ - GalA11yETableItemPrivate *priv; - - g_return_val_if_fail (a11y, FALSE); - - priv = GET_PRIVATE (a11y); - - g_return_val_if_fail (priv->selection_change_id != 0, FALSE); - g_return_val_if_fail (priv->cursor_change_id != 0, FALSE); - - g_signal_handler_disconnect ( - priv->selection, - priv->selection_change_id); - g_signal_handler_disconnect ( - priv->selection, - priv->cursor_change_id); - priv->cursor_change_id = 0; - priv->selection_change_id = 0; - - g_object_unref (priv->selection); - priv->selection = NULL; - - return TRUE; -} - -/* callbacks */ - -static void -eti_a11y_selection_model_removed_cb (ETableItem *eti, - ESelectionModel *selection, - gpointer data) -{ - AtkObject *atk_obj; - GalA11yETableItem *a11y; - - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - g_return_if_fail (E_IS_SELECTION_MODEL (selection)); - - atk_obj = atk_gobject_accessible_for_object (G_OBJECT (eti)); - a11y = GAL_A11Y_E_TABLE_ITEM (atk_obj); - - if (selection == GET_PRIVATE (a11y)->selection) - gal_a11y_e_table_item_unref_selection (a11y); -} - -static void -eti_a11y_selection_model_added_cb (ETableItem *eti, - ESelectionModel *selection, - gpointer data) -{ - AtkObject *atk_obj; - GalA11yETableItem *a11y; - - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - g_return_if_fail (E_IS_SELECTION_MODEL (selection)); - - atk_obj = atk_gobject_accessible_for_object (G_OBJECT (eti)); - a11y = GAL_A11Y_E_TABLE_ITEM (atk_obj); - - if (GET_PRIVATE (a11y)->selection) - gal_a11y_e_table_item_unref_selection (a11y); - gal_a11y_e_table_item_ref_selection (a11y, selection); -} - -static void -eti_a11y_selection_changed_cb (ESelectionModel *selection, - GalA11yETableItem *a11y) -{ - GalA11yETableItemPrivate *priv = GET_PRIVATE (a11y); - - if (atk_state_set_contains_state (priv->state_set, ATK_STATE_DEFUNCT)) - return; - - g_return_if_fail (GAL_A11Y_IS_E_TABLE_ITEM (a11y)); - - g_signal_emit_by_name (a11y, "selection_changed"); -} - -static void -eti_a11y_cursor_changed_cb (ESelectionModel *selection, - gint row, - gint col, - GalA11yETableItem *a11y) -{ - ETableItem *item; - GalA11yETableItemPrivate *priv = GET_PRIVATE (a11y); - - g_return_if_fail (GAL_A11Y_IS_E_TABLE_ITEM (a11y)); - - if (atk_state_set_contains_state (priv->state_set, ATK_STATE_DEFUNCT)) - return; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (a11y))); - - g_return_if_fail (item); - - if (row == -1 && col == -1) - return; - eti_a11y_reset_focus_object (a11y, item, TRUE); -} - -/* atk selection */ - -static void atk_selection_interface_init (AtkSelectionIface *iface) -{ - g_return_if_fail (iface != NULL); - iface->add_selection = selection_add_selection; - iface->clear_selection = selection_clear_selection; - iface->ref_selection = selection_ref_selection; - iface->get_selection_count = selection_get_selection_count; - iface->is_child_selected = selection_is_child_selected; -} - -static gboolean -selection_add_selection (AtkSelection *selection, - gint index) -{ - AtkTable *table; - gint row, col, cursor_row, cursor_col, model_row, model_col; - ETableItem *item; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (selection))); - if (!item) - return FALSE; - - table = ATK_TABLE (selection); - - row = atk_table_get_row_at_index (table, index); - col = atk_table_get_column_at_index (table, index); - - model_row = view_to_model_row (item, row); - model_col = view_to_model_col (item, col); - - cursor_row = e_selection_model_cursor_row (item->selection); - cursor_col = e_selection_model_cursor_col (item->selection); - - /* check whether is selected already */ - if (model_row == cursor_row && model_col == cursor_col) - return TRUE; - - if (model_row != cursor_row) { - /* we need to make the item get focus */ - e_canvas_item_grab_focus (GNOME_CANVAS_ITEM (item), TRUE); - - /* FIXME, currently we only support single row selection */ - atk_selection_clear_selection (selection); - atk_table_add_row_selection (table, row); - } - - e_selection_model_change_cursor ( - item->selection, - model_row, - model_col); - e_selection_model_cursor_changed ( - item->selection, - model_row, - model_col); - e_selection_model_cursor_activated ( - item->selection, - model_row, - model_col); - return TRUE; -} - -static gboolean -selection_clear_selection (AtkSelection *selection) -{ - ETableItem *item; - - item = E_TABLE_ITEM (eti_a11y_get_gobject (ATK_OBJECT (selection))); - if (!item) - return FALSE; - - e_selection_model_clear (item->selection); - return TRUE; -} - -static AtkObject * -selection_ref_selection (AtkSelection *selection, - gint index) -{ - AtkTable *table; - gint row, col; - - table = ATK_TABLE (selection); - row = atk_table_get_row_at_index (table, index); - col = atk_table_get_column_at_index (table, index); - if (!atk_table_is_row_selected (table, row)) - return NULL; - - return eti_ref_at (table, row, col); -} - -static gint -selection_get_selection_count (AtkSelection *selection) -{ - AtkTable *table; - gint n_selected; - - table = ATK_TABLE (selection); - n_selected = atk_table_get_selected_rows (table, NULL); - if (n_selected > 0) - n_selected *= atk_table_get_n_columns (table); - return n_selected; -} - -static gboolean -selection_is_child_selected (AtkSelection *selection, - gint i) -{ - gint row; - - row = atk_table_get_row_at_index (ATK_TABLE (selection), i); - return atk_table_is_row_selected (ATK_TABLE (selection), row); -} - -void -gal_a11y_e_table_item_init (void) -{ - if (atk_get_root ()) - atk_registry_set_factory_type ( - atk_get_default_registry (), - E_TYPE_TABLE_ITEM, - gal_a11y_e_table_item_factory_get_type ()); -} - diff --git a/widgets/table/gal-a11y-e-table-item.h b/widgets/table/gal-a11y-e-table-item.h deleted file mode 100644 index b77c5c3e93..0000000000 --- a/widgets/table/gal-a11y-e-table-item.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Christopher James Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __GAL_A11Y_E_TABLE_ITEM_H__ -#define __GAL_A11Y_E_TABLE_ITEM_H__ - -#include <table/e-table-item.h> -#include <atk/atkgobjectaccessible.h> - -#define GAL_A11Y_TYPE_E_TABLE_ITEM (gal_a11y_e_table_item_get_type ()) -#define GAL_A11Y_E_TABLE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAL_A11Y_TYPE_E_TABLE_ITEM, GalA11yETableItem)) -#define GAL_A11Y_E_TABLE_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAL_A11Y_TYPE_E_TABLE_ITEM, GalA11yETableItemClass)) -#define GAL_A11Y_IS_E_TABLE_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAL_A11Y_TYPE_E_TABLE_ITEM)) -#define GAL_A11Y_IS_E_TABLE_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAL_A11Y_TYPE_E_TABLE_ITEM)) - -typedef struct _GalA11yETableItem GalA11yETableItem; -typedef struct _GalA11yETableItemClass GalA11yETableItemClass; -typedef struct _GalA11yETableItemPrivate GalA11yETableItemPrivate; - -/* This struct should actually be larger as this isn't what we derive from. - * The GalA11yETableItemPrivate comes right after the parent class structure. - **/ -struct _GalA11yETableItem { - AtkGObjectAccessible parent; -}; - -struct _GalA11yETableItemClass { - AtkGObjectAccessibleClass parent_class; -}; - -/* Standard Glib function */ -GType gal_a11y_e_table_item_get_type (void); -AtkObject *gal_a11y_e_table_item_new (ETableItem *item); - -void gal_a11y_e_table_item_init (void); - -#endif /* __GAL_A11Y_E_TABLE_ITEM_H__ */ diff --git a/widgets/table/gal-a11y-e-table.c b/widgets/table/gal-a11y-e-table.c deleted file mode 100644 index ec0025c6b8..0000000000 --- a/widgets/table/gal-a11y-e-table.c +++ /dev/null @@ -1,315 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Christopher James Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "a11y/gal-a11y-util.h" -#include "table/e-table.h" -#include "table/e-table-click-to-add.h" -#include "table/e-table-group.h" -#include "table/e-table-group-container.h" -#include "table/e-table-group-leaf.h" - -#include "gal-a11y-e-table.h" -#include "gal-a11y-e-table-factory.h" -#include "gal-a11y-e-table-item.h" - -#define CS_CLASS(a11y) (G_TYPE_INSTANCE_GET_CLASS ((a11y), C_TYPE_STREAM, GalA11yETableClass)) -static AtkObjectClass *parent_class; -static GType parent_type; -static gint priv_offset; -#define GET_PRIVATE(object) ((GalA11yETablePrivate *) (((gchar *) object) + priv_offset)) -#define PARENT_TYPE (parent_type) - -struct _GalA11yETablePrivate { - AtkObject *child_item; -}; - -/* Static functions */ -static ETableItem * -find_first_table_item (ETableGroup *group) -{ - GnomeCanvasGroup *cgroup; - GList *l; - - cgroup = GNOME_CANVAS_GROUP (group); - - for (l = cgroup->item_list; l; l = l->next) { - GnomeCanvasItem *i; - - i = GNOME_CANVAS_ITEM (l->data); - - if (E_IS_TABLE_GROUP (i)) - return find_first_table_item (E_TABLE_GROUP (i)); - else if (E_IS_TABLE_ITEM (i)) { - return E_TABLE_ITEM (i); - } - } - - return NULL; -} - -static AtkObject * -eti_get_accessible (ETableItem *eti, - AtkObject *parent) -{ - AtkObject *a11y = NULL; - - g_return_val_if_fail (eti, NULL); - - a11y = atk_gobject_accessible_for_object (G_OBJECT (eti)); - g_return_val_if_fail (a11y, NULL); - - return a11y; -} - -static gboolean -init_child_item (GalA11yETable *a11y) -{ - ETable *table; - - if (!a11y || !GTK_IS_ACCESSIBLE (a11y)) - return FALSE; - - table = E_TABLE (gtk_accessible_get_widget (GTK_ACCESSIBLE (a11y))); - if (table && gtk_widget_get_mapped (GTK_WIDGET (table)) && table->group && E_IS_TABLE_GROUP_CONTAINER (table->group)) { - ETableGroupContainer *etgc = (ETableGroupContainer *) table->group; - GList *list; - - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = list->data; - ETableGroup *child = child_node->child; - ETableItem *eti = find_first_table_item (child); - - eti_get_accessible (eti, ATK_OBJECT (a11y)); - } - } - g_object_unref (a11y); - g_object_unref (table); - - return FALSE; -} - -static AtkObject * -et_ref_accessible_at_point (AtkComponent *component, - gint x, - gint y, - AtkCoordType coord_type) -{ - GalA11yETable *a11y = GAL_A11Y_E_TABLE (component); - if (GET_PRIVATE (a11y)->child_item) - g_object_ref (GET_PRIVATE (a11y)->child_item); - return GET_PRIVATE (a11y)->child_item; -} - -static gint -et_get_n_children (AtkObject *accessible) -{ - GalA11yETable *a11y = GAL_A11Y_E_TABLE (accessible); - ETable * et; - gint n = 0; - - et = E_TABLE (gtk_accessible_get_widget (GTK_ACCESSIBLE (a11y))); - - if (et && et->group) { - if (E_IS_TABLE_GROUP_LEAF (et->group)) - n = 1; - else if (E_IS_TABLE_GROUP_CONTAINER (et->group)) { - ETableGroupContainer *etgc = (ETableGroupContainer *) et->group; - n = g_list_length (etgc->children); - } - } - - if (et && et->use_click_to_add && et->click_to_add) { - n++; - } - return n; -} - -static AtkObject * -et_ref_child (AtkObject *accessible, - gint i) -{ - GalA11yETable *a11y = GAL_A11Y_E_TABLE (accessible); - ETable * et; - gint child_no; - - et = E_TABLE (gtk_accessible_get_widget (GTK_ACCESSIBLE (a11y))); - if (!et) - return NULL; - - child_no = et_get_n_children (accessible); - if (i == 0 || i < child_no - 1) { - if (E_IS_TABLE_GROUP_LEAF (et->group)) { - ETableItem *eti = find_first_table_item (et->group); - AtkObject *aeti = eti_get_accessible (eti, accessible); - if (aeti) - g_object_ref (aeti); - return aeti; - - } else if (E_IS_TABLE_GROUP_CONTAINER (et->group)) { - ETableGroupContainer *etgc = (ETableGroupContainer *) et->group; - ETableGroupContainerChildNode *child_node = g_list_nth_data (etgc->children, i); - if (child_node) { - ETableGroup *child = child_node->child; - ETableItem * eti = find_first_table_item (child); - AtkObject *aeti = eti_get_accessible (eti, accessible); - if (aeti) - g_object_ref (aeti); - return aeti; - } - } - } else if (i == child_no -1) { - ETableClickToAdd * etcta; - - if (et && et->use_click_to_add && et->click_to_add) { - etcta = E_TABLE_CLICK_TO_ADD (et->click_to_add); - accessible = atk_gobject_accessible_for_object (G_OBJECT (etcta)); - if (accessible) - g_object_ref (accessible); - return accessible; - } - } - - return NULL; -} - -static AtkLayer -et_get_layer (AtkComponent *component) -{ - return ATK_LAYER_WIDGET; -} - -static void -et_class_init (GalA11yETableClass *class) -{ - AtkObjectClass *atk_object_class = ATK_OBJECT_CLASS (class); - - parent_class = g_type_class_ref (PARENT_TYPE); - - atk_object_class->get_n_children = et_get_n_children; - atk_object_class->ref_child = et_ref_child; -} - -static void -et_atk_component_iface_init (AtkComponentIface *iface) -{ - iface->ref_accessible_at_point = et_ref_accessible_at_point; - iface->get_layer = et_get_layer; -} - -static void -et_init (GalA11yETable *a11y) -{ - GalA11yETablePrivate *priv; - - priv = GET_PRIVATE (a11y); - - priv->child_item = NULL; -} - -/** - * gal_a11y_e_table_get_type: - * @void: - * - * Registers the &GalA11yETable class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &GalA11yETable class. - **/ -GType -gal_a11y_e_table_get_type (void) -{ - static GType type = 0; - - if (!type) { - AtkObjectFactory *factory; - - GTypeInfo info = { - sizeof (GalA11yETableClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) et_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GalA11yETable), - 0, - (GInstanceInitFunc) et_init, - NULL /* value_table */ - }; - - static const GInterfaceInfo atk_component_info = { - (GInterfaceInitFunc) et_atk_component_iface_init, - (GInterfaceFinalizeFunc) NULL, - NULL - }; - - factory = atk_registry_get_factory (atk_get_default_registry (), GTK_TYPE_WIDGET); - parent_type = atk_object_factory_get_accessible_type (factory); - - type = gal_a11y_type_register_static_with_private ( - PARENT_TYPE, "GalA11yETable", &info, 0, - sizeof (GalA11yETablePrivate), &priv_offset); - g_type_add_interface_static (type, ATK_TYPE_COMPONENT, &atk_component_info); - } - - return type; -} - -AtkObject * -gal_a11y_e_table_new (GObject *widget) -{ - GalA11yETable *a11y; - ETable *table; - - table = E_TABLE (widget); - - a11y = g_object_new (gal_a11y_e_table_get_type (), NULL); - - gtk_accessible_set_widget (GTK_ACCESSIBLE (a11y), GTK_WIDGET (widget)); - - /* we need to init all the children for multiple table items */ - if (table && gtk_widget_get_mapped (GTK_WIDGET (table)) && table->group && E_IS_TABLE_GROUP_CONTAINER (table->group)) { - /* Ref it here so that it is still valid in the idle function */ - /* It will be unrefed in the idle function */ - g_object_ref (a11y); - g_object_ref (widget); - - g_idle_add ((GSourceFunc) init_child_item, a11y); - } - - return ATK_OBJECT (a11y); -} - -void -gal_a11y_e_table_init (void) -{ - if (atk_get_root ()) - atk_registry_set_factory_type ( - atk_get_default_registry (), - E_TYPE_TABLE, - gal_a11y_e_table_factory_get_type ()); - -} - diff --git a/widgets/table/gal-a11y-e-table.h b/widgets/table/gal-a11y-e-table.h deleted file mode 100644 index f5dba40c7e..0000000000 --- a/widgets/table/gal-a11y-e-table.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Christopher James Lahey <clahey@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __GAL_A11Y_E_TABLE_H__ -#define __GAL_A11Y_E_TABLE_H__ - -#include <gtk/gtk.h> -#include <atk/atkobject.h> -#include <atk/atkcomponent.h> - -#define GAL_A11Y_TYPE_E_TABLE (gal_a11y_e_table_get_type ()) -#define GAL_A11Y_E_TABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAL_A11Y_TYPE_E_TABLE, GalA11yETable)) -#define GAL_A11Y_E_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAL_A11Y_TYPE_E_TABLE, GalA11yETableClass)) -#define GAL_A11Y_IS_E_TABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAL_A11Y_TYPE_E_TABLE)) -#define GAL_A11Y_IS_E_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAL_A11Y_TYPE_E_TABLE)) - -typedef struct _GalA11yETable GalA11yETable; -typedef struct _GalA11yETableClass GalA11yETableClass; -typedef struct _GalA11yETablePrivate GalA11yETablePrivate; - -/* This struct should actually be larger as this isn't what we derive from. - * The GalA11yETablePrivate comes right after the parent class structure. - **/ -struct _GalA11yETable { - GtkAccessible object; -}; - -struct _GalA11yETableClass { - GtkAccessibleClass parent_class; -}; - -/* Standard Glib function */ -GType gal_a11y_e_table_get_type (void); -AtkObject *gal_a11y_e_table_new (GObject *table); - -void gal_a11y_e_table_init (void); - -#endif /* __GAL_A11Y_E_TABLE_H__ */ diff --git a/widgets/table/gal-a11y-e-tree-factory.c b/widgets/table/gal-a11y-e-tree-factory.c deleted file mode 100644 index 00ce55c8c0..0000000000 --- a/widgets/table/gal-a11y-e-tree-factory.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Yuedong Du <yuedong.du@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "gal-a11y-e-tree.h" -#include "gal-a11y-e-tree-factory.h" - -static AtkObjectFactoryClass *parent_class; -#define PARENT_TYPE (ATK_TYPE_OBJECT_FACTORY) - -/* Static functions */ - -static GType -gal_a11y_e_tree_factory_get_accessible_type (void) -{ - return GAL_A11Y_TYPE_E_TREE; -} - -static AtkObject * -gal_a11y_e_tree_factory_create_accessible (GObject *obj) -{ - AtkObject *accessible; - - accessible = gal_a11y_e_tree_new (obj); - - return accessible; -} - -static void -gal_a11y_e_tree_factory_class_init (GalA11yETreeFactoryClass *class) -{ - AtkObjectFactoryClass *factory_class = ATK_OBJECT_FACTORY_CLASS (class); - - parent_class = g_type_class_ref (PARENT_TYPE); - - factory_class->create_accessible = gal_a11y_e_tree_factory_create_accessible; - factory_class->get_accessible_type = gal_a11y_e_tree_factory_get_accessible_type; -} - -static void -gal_a11y_e_tree_factory_init (GalA11yETreeFactory *factory) -{ -} - -/** - * gal_a11y_e_tree_factory_get_type: - * @void: - * - * Registers the &GalA11yETreeFactory class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &GalA11yETreeFactory class. - **/ -GType -gal_a11y_e_tree_factory_get_type (void) -{ - static GType type = 0; - - if (!type) { - GTypeInfo info = { - sizeof (GalA11yETreeFactoryClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) gal_a11y_e_tree_factory_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GalA11yETreeFactory), - 0, - (GInstanceInitFunc) gal_a11y_e_tree_factory_init, - NULL /* value_tree */ - }; - - type = g_type_register_static (PARENT_TYPE, "GalA11yETreeFactory", &info, 0); - } - - return type; -} diff --git a/widgets/table/gal-a11y-e-tree-factory.h b/widgets/table/gal-a11y-e-tree-factory.h deleted file mode 100644 index a2e44445a0..0000000000 --- a/widgets/table/gal-a11y-e-tree-factory.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Yuedong Du <yuedong.du@ximian.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __GAL_A11Y_E_TREE_FACTORY_H__ -#define __GAL_A11Y_E_TREE_FACTORY_H__ - -#include <atk/atkobjectfactory.h> - -#define GAL_A11Y_TYPE_E_TREE_FACTORY (gal_a11y_e_table_factory_get_type ()) -#define GAL_A11Y_E_TREE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAL_A11Y_TYPE_E_TREE_FACTORY, GalA11yETreeFactory)) -#define GAL_A11Y_E_TREE_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAL_A11Y_TYPE_E_TREE_FACTORY, GalA11yETreeFactoryClass)) -#define GAL_A11Y_IS_E_TREE_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAL_A11Y_TYPE_E_TREE_FACTORY)) -#define GAL_A11Y_IS_E_TREE_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAL_A11Y_TYPE_E_TREE_FACTORY)) - -typedef struct _GalA11yETreeFactory GalA11yETreeFactory; -typedef struct _GalA11yETreeFactoryClass GalA11yETreeFactoryClass; - -struct _GalA11yETreeFactory { - AtkObject object; -}; - -struct _GalA11yETreeFactoryClass { - AtkObjectClass parent_class; -}; - -/* Standard Glib function */ -GType gal_a11y_e_tree_factory_get_type (void); - -#endif /* __GAL_A11Y_E_TREE_FACTORY_H__ */ diff --git a/widgets/table/gal-a11y-e-tree.c b/widgets/table/gal-a11y-e-tree.c deleted file mode 100644 index 26d2f24e7b..0000000000 --- a/widgets/table/gal-a11y-e-tree.c +++ /dev/null @@ -1,196 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Yuedong Du <yuedong.du@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "a11y/gal-a11y-util.h" -#include "table/e-table-item.h" -#include "table/e-tree.h" - -#include "gal-a11y-e-table-item.h" -#include "gal-a11y-e-tree.h" -#include "gal-a11y-e-tree-factory.h" - -#define CS_CLASS(a11y) (G_TYPE_INSTANCE_GET_CLASS ((a11y), C_TYPE_STREAM, GalA11yETreeClass)) -static AtkObjectClass *parent_class; -static GType parent_type; -static gint priv_offset; -#define GET_PRIVATE(object) ((GalA11yETreePrivate *) (((gchar *) object) + priv_offset)) -#define PARENT_TYPE (parent_type) - -struct _GalA11yETreePrivate { - AtkObject *child_item; -}; - -/* Static functions */ - -static void -init_child_item (GalA11yETree *a11y) -{ - GalA11yETreePrivate *priv = GET_PRIVATE (a11y); - ETree *tree; - ETableItem * eti; - - tree = E_TREE (gtk_accessible_get_widget (GTK_ACCESSIBLE (a11y))); - g_return_if_fail (tree); - - eti = e_tree_get_item (tree); - if (priv->child_item == NULL) { - priv->child_item = atk_gobject_accessible_for_object (G_OBJECT (eti)); - } -} - -static AtkObject * -et_ref_accessible_at_point (AtkComponent *component, - gint x, - gint y, - AtkCoordType coord_type) -{ - GalA11yETree *a11y = GAL_A11Y_E_TREE (component); - init_child_item (a11y); - return GET_PRIVATE (a11y)->child_item; -} - -static gint -et_get_n_children (AtkObject *accessible) -{ - return 1; -} - -static AtkObject * -et_ref_child (AtkObject *accessible, - gint i) -{ - GalA11yETree *a11y = GAL_A11Y_E_TREE (accessible); - if (i != 0) - return NULL; - init_child_item (a11y); - g_object_ref (GET_PRIVATE (a11y)->child_item); - return GET_PRIVATE (a11y)->child_item; -} - -static AtkLayer -et_get_layer (AtkComponent *component) -{ - return ATK_LAYER_WIDGET; -} - -static void -et_class_init (GalA11yETreeClass *class) -{ - AtkObjectClass *atk_object_class = ATK_OBJECT_CLASS (class); - - parent_class = g_type_class_ref (PARENT_TYPE); - - atk_object_class->get_n_children = et_get_n_children; - atk_object_class->ref_child = et_ref_child; -} - -static void -et_atk_component_iface_init (AtkComponentIface *iface) -{ - iface->ref_accessible_at_point = et_ref_accessible_at_point; - iface->get_layer = et_get_layer; -} - -static void -et_init (GalA11yETree *a11y) -{ - GalA11yETreePrivate *priv; - - priv = GET_PRIVATE (a11y); - - priv->child_item = NULL; -} - -/** - * gal_a11y_e_tree_get_type: - * @void: - * - * Registers the &GalA11yETree class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &GalA11yETree class. - **/ -GType -gal_a11y_e_tree_get_type (void) -{ - static GType type = 0; - - if (!type) { - AtkObjectFactory *factory; - - GTypeInfo info = { - sizeof (GalA11yETreeClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) et_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GalA11yETree), - 0, - (GInstanceInitFunc) et_init, - NULL /* value_tree */ - }; - - static const GInterfaceInfo atk_component_info = { - (GInterfaceInitFunc) et_atk_component_iface_init, - (GInterfaceFinalizeFunc) NULL, - NULL - }; - - factory = atk_registry_get_factory (atk_get_default_registry (), GTK_TYPE_WIDGET); - parent_type = atk_object_factory_get_accessible_type (factory); - - type = gal_a11y_type_register_static_with_private ( - PARENT_TYPE, "GalA11yETree", &info, 0, - sizeof (GalA11yETreePrivate), &priv_offset); - g_type_add_interface_static (type, ATK_TYPE_COMPONENT, &atk_component_info); - } - - return type; -} - -AtkObject * -gal_a11y_e_tree_new (GObject *widget) -{ - GalA11yETree *a11y; - - a11y = g_object_new (gal_a11y_e_tree_get_type (), NULL); - - gtk_accessible_set_widget (GTK_ACCESSIBLE (a11y), GTK_WIDGET (widget)); - - return ATK_OBJECT (a11y); -} - -void -gal_a11y_e_tree_init (void) -{ - if (atk_get_root ()) - atk_registry_set_factory_type ( - atk_get_default_registry (), - E_TYPE_TREE, - gal_a11y_e_tree_factory_get_type ()); -} - diff --git a/widgets/table/gal-a11y-e-tree.h b/widgets/table/gal-a11y-e-tree.h deleted file mode 100644 index 61799e1b93..0000000000 --- a/widgets/table/gal-a11y-e-tree.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see <http://www.gnu.org/licenses/> - * - * - * Authors: - * Yuedong Du <yuedong.du@sun.com> - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __GAL_A11Y_E_TREE_H__ -#define __GAL_A11Y_E_TREE_H__ - -#include <gtk/gtk.h> -#include <atk/atkobject.h> -#include <atk/atkcomponent.h> - -#define GAL_A11Y_TYPE_E_TREE (gal_a11y_e_tree_get_type ()) -#define GAL_A11Y_E_TREE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAL_A11Y_TYPE_E_TREE, GalA11yETree)) -#define GAL_A11Y_E_TREE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAL_A11Y_TYPE_E_TREE, GalA11yETreeClass)) -#define GAL_A11Y_IS_E_TREE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAL_A11Y_TYPE_E_TREE)) -#define GAL_A11Y_IS_E_TREE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAL_A11Y_TYPE_E_TREE)) - -typedef struct _GalA11yETree GalA11yETree; -typedef struct _GalA11yETreeClass GalA11yETreeClass; -typedef struct _GalA11yETreePrivate GalA11yETreePrivate; - -/* This struct should actually be larger as this isn't what we derive from. - * The GalA11yETablePrivate comes right after the parent class structure. - **/ -struct _GalA11yETree { - GtkAccessible object; -}; - -struct _GalA11yETreeClass { - GtkAccessibleClass parent_class; -}; - -/* Standard Glib function */ -GType gal_a11y_e_tree_get_type (void); -AtkObject *gal_a11y_e_tree_new (GObject *tree); - -void gal_a11y_e_tree_init (void); - -#endif /* __GAL_A11Y_E_TREE_H__ */ diff --git a/widgets/table/sample.table b/widgets/table/sample.table deleted file mode 100644 index e1909a2bf7..0000000000 --- a/widgets/table/sample.table +++ /dev/null @@ -1,45 +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 -aaa1 bbb ccc ddd eee -aaa2 bbb ccc ddd eee -aaa3 bbb ccc ddd eee -aaa4 bbb ccc ddd eee -aaa5 bbb ccc ddd eee -aaa6 bbb ccc ddd eee -aaa7 bbb ccc ddd eee -aaa8 bbb ccc ddd eee -aaa9 bbb ccc ddd eee -aaa10 bbb ccc ddd eee -aaa11 bbb ccc ddd eee -aaa12 bbb ccc ddd eee -aaa13 bbb ccc ddd eee -aaa14 bbb ccc ddd eee -aaa15 bbb ccc ddd eee -aaa16 bbb ccc ddd eee -aaa17 bbb ccc ddd eee -aaa18 bbb ccc ddd eee -aaa19 bbb ccc ddd eee -aaa20 bbb ccc ddd eee -aaa21 bbb ccc ddd eee -aaa22 bbb ccc ddd eee -aaa23 bbb ccc ddd eee -aaa24 bbb ccc ddd eee -aaa25 bbb ccc ddd eee -aaa26 bbb ccc ddd eee -aaa27 bbb ccc ddd eee -aaa28 bbb ccc ddd eee -aaa29 bbb ccc ddd eee -aaa30 bbb ccc ddd eee -aaa31 bbb ccc ddd eee -aaa32 bbb ccc ddd eee -aaa33 bbb ccc ddd eee -aaa34 bbb ccc ddd eee -aaa35 bbb ccc ddd eee -aaa36 bbb ccc ddd eee 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/tree-expanded.xpm b/widgets/table/tree-expanded.xpm deleted file mode 100644 index 94d162d40b..0000000000 --- a/widgets/table/tree-expanded.xpm +++ /dev/null @@ -1,23 +0,0 @@ -/* XPM */ -static const gchar *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 d20ec5aa33..0000000000 --- a/widgets/table/tree-unexpanded.xpm +++ /dev/null @@ -1,23 +0,0 @@ -/* XPM */ -static const gchar *tree_unexpanded_xpm[] = { -"16 16 4 1", -" c None", -". c #FFFFFF", -"* c #000000", -"+ c #666666", -" ", -" ", -" ", -" ", -" +++++++++ ", -" +.......+ ", -" +...*...+ ", -" +...*...+ ", -" +.*****.+ ", -" +...*...+ ", -" +...*...+ ", -" +.......+ ", -" +++++++++ ", -" ", -" ", -" "}; |