diff options
author | nobody <nobody@localhost> | 2000-08-22 20:05:30 +0800 |
---|---|---|
committer | nobody <nobody@localhost> | 2000-08-22 20:05:30 +0800 |
commit | a662f8dc5458e376f173a7caeae927b0e617423d (patch) | |
tree | 3b4824784cd30983db4a6ae1f38db287d5815941 /widgets | |
parent | 44ae37c371e25fe05e8aee145f1d9af7130a201d (diff) | |
download | gsoc2013-evolution-a662f8dc5458e376f173a7caeae927b0e617423d.tar gsoc2013-evolution-a662f8dc5458e376f173a7caeae927b0e617423d.tar.gz gsoc2013-evolution-a662f8dc5458e376f173a7caeae927b0e617423d.tar.bz2 gsoc2013-evolution-a662f8dc5458e376f173a7caeae927b0e617423d.tar.lz gsoc2013-evolution-a662f8dc5458e376f173a7caeae927b0e617423d.tar.xz gsoc2013-evolution-a662f8dc5458e376f173a7caeae927b0e617423d.tar.zst gsoc2013-evolution-a662f8dc5458e376f173a7caeae927b0e617423d.zip |
This commit was manufactured by cvs2svn to create tag 'BONOBO_0_26'.BONOBO_0_26
svn path=/tags/BONOBO_0_26/; revision=4926
Diffstat (limited to 'widgets')
317 files changed, 0 insertions, 84535 deletions
diff --git a/widgets/.cvsignore b/widgets/.cvsignore deleted file mode 100644 index d5b3a2ad62..0000000000 --- a/widgets/.cvsignore +++ /dev/null @@ -1,9 +0,0 @@ -.deps -.libs -Makefile -Makefile.in -*.lo -*.la -minicard-test -minicard-label-test -reflow-test diff --git a/widgets/LICENSE b/widgets/LICENSE deleted file mode 100644 index b1f6ae08a4..0000000000 --- a/widgets/LICENSE +++ /dev/null @@ -1 +0,0 @@ -This code is released under the terms of the GNU GPL. diff --git a/widgets/Makefile.am b/widgets/Makefile.am deleted file mode 100644 index a2c421ee7d..0000000000 --- a/widgets/Makefile.am +++ /dev/null @@ -1,8 +0,0 @@ - -SUBDIRS = \ - misc \ - e-paned \ - e-text \ - e-table \ - meeting-time-sel \ - shortcut-bar diff --git a/widgets/e-paned/.cvsignore b/widgets/e-paned/.cvsignore deleted file mode 100644 index 955fc0b6d0..0000000000 --- a/widgets/e-paned/.cvsignore +++ /dev/null @@ -1,8 +0,0 @@ -.deps -.libs -.pure -Makefile -Makefile.in -*.lo -*.la -libepaned.a diff --git a/widgets/e-paned/Makefile.am b/widgets/e-paned/Makefile.am deleted file mode 100644 index 51ab38c80d..0000000000 --- a/widgets/e-paned/Makefile.am +++ /dev/null @@ -1,15 +0,0 @@ -INCLUDES = \ - -I$(top_srcdir) \ - $(GNOME_INCLUDEDIR) \ - -DG_LOG_DOMAIN=\"e-paned\" - -noinst_LIBRARIES = \ - libepaned.a - -libepaned_a_SOURCES = \ - e-hpaned.c \ - e-hpaned.h \ - e-paned.c \ - e-paned.h \ - e-vpaned.c \ - e-vpaned.h diff --git a/widgets/e-paned/e-hpaned.c b/widgets/e-paned/e-hpaned.c deleted file mode 100644 index 933fc1c057..0000000000 --- a/widgets/e-paned/e-hpaned.c +++ /dev/null @@ -1,439 +0,0 @@ -/* EPaned - A slightly more advanced paned widget. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Christopher James Lahey <clahey@helixcode.com> - * - * based on GtkPaned from Gtk+. Gtk+ Copyright notice follows. - */ - -/* GTK - The GIMP Toolkit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#include "e-hpaned.h" - -static void e_hpaned_class_init (EHPanedClass *klass); -static void e_hpaned_init (EHPaned *hpaned); -static void e_hpaned_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void e_hpaned_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void e_hpaned_draw (GtkWidget *widget, - GdkRectangle *area); -static void e_hpaned_xor_line (EPaned *paned); -static gboolean e_hpaned_button_press (GtkWidget *widget, - GdkEventButton *event); -static gboolean e_hpaned_button_release (GtkWidget *widget, - GdkEventButton *event); -static gboolean e_hpaned_motion (GtkWidget *widget, - GdkEventMotion *event); -static gboolean e_hpaned_handle_shown (EPaned *paned); - -GtkType -e_hpaned_get_type (void) -{ - static GtkType hpaned_type = 0; - - if (!hpaned_type) - { - static const GtkTypeInfo hpaned_info = - { - "EHPaned", - sizeof (EHPaned), - sizeof (EHPanedClass), - (GtkClassInitFunc) e_hpaned_class_init, - (GtkObjectInitFunc) e_hpaned_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - hpaned_type = gtk_type_unique (E_TYPE_PANED, &hpaned_info); - } - - return hpaned_type; -} - -static void -e_hpaned_class_init (EHPanedClass *klass) -{ - GtkWidgetClass *widget_class; - EPanedClass *paned_class; - - widget_class = (GtkWidgetClass *) klass; - paned_class = E_PANED_CLASS (klass); - - widget_class->size_request = e_hpaned_size_request; - widget_class->size_allocate = e_hpaned_size_allocate; - widget_class->draw = e_hpaned_draw; - widget_class->button_press_event = e_hpaned_button_press; - widget_class->button_release_event = e_hpaned_button_release; - widget_class->motion_notify_event = e_hpaned_motion; - - paned_class->handle_shown = e_hpaned_handle_shown; -} - -static void -e_hpaned_init (EHPaned *hpaned) -{ - EPaned *paned; - - g_return_if_fail (hpaned != NULL); - g_return_if_fail (E_IS_PANED (hpaned)); - - paned = E_PANED (hpaned); - - paned->cursor_type = GDK_SB_H_DOUBLE_ARROW; -} - -GtkWidget * -e_hpaned_new (void) -{ - EHPaned *hpaned; - - hpaned = gtk_type_new (E_TYPE_HPANED); - - return GTK_WIDGET (hpaned); -} - -static void -e_hpaned_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - EPaned *paned; - GtkRequisition child_requisition; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_HPANED (widget)); - g_return_if_fail (requisition != NULL); - - paned = E_PANED (widget); - requisition->width = 0; - requisition->height = 0; - - if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1)) - { - gtk_widget_size_request (paned->child1, &child_requisition); - - requisition->height = child_requisition.height; - requisition->width = child_requisition.width; - } - - if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2)) - { - gtk_widget_size_request (paned->child2, &child_requisition); - - requisition->height = MAX(requisition->height, child_requisition.height); - requisition->width += child_requisition.width; - } - - - requisition->width += GTK_CONTAINER (paned)->border_width * 2; - requisition->height += GTK_CONTAINER (paned)->border_width * 2; - if (e_paned_handle_shown(paned)) - requisition->width += paned->handle_size; -} - -static void -e_hpaned_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - EPaned *paned; - GtkRequisition child1_requisition; - GtkRequisition child2_requisition; - GtkAllocation child1_allocation; - GtkAllocation child2_allocation; - gint border_width; - gboolean handle_shown; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_HPANED (widget)); - g_return_if_fail (allocation != NULL); - - widget->allocation = *allocation; - paned = E_PANED (widget); - border_width = GTK_CONTAINER (paned)->border_width; - - if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1)) - gtk_widget_get_child_requisition (paned->child1, &child1_requisition); - else - child1_requisition.width = 0; - - if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2)) - gtk_widget_get_child_requisition (paned->child2, &child2_requisition); - else - child2_requisition.width = 0; - - e_paned_compute_position (paned, - MAX (1, (gint) widget->allocation.width - - 2 * border_width), - child1_requisition.width, - child2_requisition.width); - - /* Move the handle before the children so we don't get extra expose events */ - - if (GTK_WIDGET_REALIZED (widget)) - gdk_window_move_resize (widget->window, - allocation->x, allocation->y, - allocation->width, - allocation->height); - - handle_shown = e_paned_handle_shown(paned); - if (handle_shown) - { - paned->handle_xpos = paned->child1_real_size + border_width; - paned->handle_ypos = border_width; - paned->handle_width = paned->handle_size; - paned->handle_height = MAX (1, (gint) widget->allocation.height - 2 * border_width); - - if (GTK_WIDGET_REALIZED (widget)) - { - gdk_window_move_resize (paned->handle, - paned->handle_xpos, - paned->handle_ypos, - paned->handle_size, - paned->handle_height); - if (paned->handle) - gdk_window_show(paned->handle); - } - } - else - { - if (paned->handle && GTK_WIDGET_REALIZED (widget)) - gdk_window_hide(paned->handle); - } - - child1_allocation.height = child2_allocation.height = MAX (1, (gint) allocation->height - border_width * 2); - child1_allocation.width = paned->child1_real_size; - child1_allocation.x = border_width; - child1_allocation.y = child2_allocation.y = border_width; - - if (handle_shown) - child2_allocation.x = child1_allocation.x + child1_allocation.width + paned->handle_width; - else - child2_allocation.x = child1_allocation.x + child1_allocation.width; - child2_allocation.width = MAX (1, (gint) allocation->width - child2_allocation.x - border_width); - - /* Now allocate the childen, making sure, when resizing not to - * overlap the windows */ - if (GTK_WIDGET_MAPPED (widget) && - paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) && - paned->child1->allocation.width < child1_allocation.width) - { - if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2)) - gtk_widget_size_allocate (paned->child2, &child2_allocation); - gtk_widget_size_allocate (paned->child1, &child1_allocation); - } - else - { - if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1)) - gtk_widget_size_allocate (paned->child1, &child1_allocation); - if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2)) - gtk_widget_size_allocate (paned->child2, &child2_allocation); - } -} - -static void -e_hpaned_draw (GtkWidget *widget, - GdkRectangle *area) -{ - EPaned *paned; - GdkRectangle handle_area, child_area; - guint16 border_width; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_PANED (widget)); - - if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget)) - { - paned = E_PANED (widget); - border_width = GTK_CONTAINER (paned)->border_width; - - gdk_window_clear_area (widget->window, - area->x, area->y, area->width, - area->height); - - if (e_paned_handle_shown(paned)) - { - handle_area.x = paned->handle_xpos; - handle_area.y = paned->handle_ypos; - handle_area.width = paned->handle_size; - handle_area.height = paned->handle_height; - - if (gdk_rectangle_intersect (&handle_area, area, &child_area)) - { - child_area.x -= paned->handle_xpos; - child_area.y -= paned->handle_ypos; - - gtk_paint_handle (widget->style, - paned->handle, - GTK_STATE_NORMAL, - GTK_SHADOW_NONE, - &child_area, - widget, - "paned", - 0, 0, -1, -1, - GTK_ORIENTATION_VERTICAL); - - } - } - /* Redraw the children - */ - if (paned->child1 && gtk_widget_intersect (paned->child1, area, &child_area)) - gtk_widget_draw(paned->child1, &child_area); - if (paned->child2 && gtk_widget_intersect(paned->child2, area, &child_area)) - gtk_widget_draw(paned->child2, &child_area); - } -} - -static void -e_hpaned_xor_line (EPaned *paned) -{ - GtkWidget *widget; - GdkGCValues values; - guint16 xpos; - - widget = GTK_WIDGET(paned); - - if (!paned->xor_gc) - { - values.function = GDK_INVERT; - values.subwindow_mode = GDK_INCLUDE_INFERIORS; - paned->xor_gc = gdk_gc_new_with_values (widget->window, - &values, - GDK_GC_FUNCTION | GDK_GC_SUBWINDOW); - } - - gdk_gc_set_line_attributes (paned->xor_gc, 2, GDK_LINE_SOLID, - GDK_CAP_NOT_LAST, GDK_JOIN_BEVEL); - - xpos = paned->child1_real_size - + GTK_CONTAINER (paned)->border_width + paned->handle_size / 2; - - gdk_draw_line (widget->window, paned->xor_gc, - xpos, - 0, - xpos, - widget->allocation.height - 1); -} - -static gboolean -e_hpaned_button_press (GtkWidget *widget, - GdkEventButton *event) -{ - EPaned *paned; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_PANED (widget), FALSE); - - paned = E_PANED (widget); - - if (!paned->in_drag && - event->window == paned->handle && event->button == 1) - { - paned->old_child1_size = paned->child1_size; - paned->in_drag = TRUE; - /* We need a server grab here, not gtk_grab_add(), since - * we don't want to pass events on to the widget's children */ - gdk_pointer_grab(paned->handle, FALSE, - GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON1_MOTION_MASK - | GDK_BUTTON_RELEASE_MASK, - NULL, NULL, event->time); - paned->child1_size = e_paned_quantized_size(paned, paned->child1_size + event->x - paned->handle_size / 2); - paned->child1_size = CLAMP (paned->child1_size, 0, - widget->allocation.width - - paned->handle_size - - 2 * GTK_CONTAINER (paned)->border_width); - paned->child1_real_size = paned->child1_size; - e_hpaned_xor_line (paned); - - return TRUE; - } - - return FALSE; -} - -static gboolean -e_hpaned_button_release (GtkWidget *widget, - GdkEventButton *event) -{ - EPaned *paned; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_PANED (widget), FALSE); - - paned = E_PANED (widget); - - if (paned->in_drag && (event->button == 1)) - { - e_hpaned_xor_line (paned); - paned->in_drag = FALSE; - paned->position_set = TRUE; - gdk_pointer_ungrab (event->time); - gtk_widget_queue_resize (GTK_WIDGET (paned)); - - return TRUE; - } - - return FALSE; -} - -static gboolean -e_hpaned_motion (GtkWidget *widget, - GdkEventMotion *event) -{ - EPaned *paned; - gint x; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_PANED (widget), FALSE); - - paned = E_PANED (widget); - - if (event->is_hint || event->window != widget->window) - gtk_widget_get_pointer(widget, &x, NULL); - else - x = event->x; - - if (paned->in_drag) - { - gint size = x - GTK_CONTAINER (paned)->border_width - paned->handle_size / 2; - - e_hpaned_xor_line (paned); - paned->child1_size = CLAMP (e_paned_quantized_size(paned, size), paned->min_position, paned->max_position); - paned->child1_real_size = paned->child1_size; - e_hpaned_xor_line (paned); - } - - return TRUE; -} - -static gboolean -e_hpaned_handle_shown (EPaned *paned) -{ - return ((paned->child1 && paned->child2) && - (GTK_WIDGET_VISIBLE (paned->child1) && GTK_WIDGET_VISIBLE (paned->child2))); -} diff --git a/widgets/e-paned/e-hpaned.h b/widgets/e-paned/e-hpaned.h deleted file mode 100644 index 63c09198b1..0000000000 --- a/widgets/e-paned/e-hpaned.h +++ /dev/null @@ -1,72 +0,0 @@ -/* EPaned - A slightly more advanced paned widget. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Christopher James Lahey <clahey@helixcode.com> - * - * based on GtkPaned from Gtk+. Gtk+ Copyright notice follows. - */ - -/* GTK - The GIMP Toolkit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#ifndef __E_HPANED_H__ -#define __E_HPANED_H__ - -#include <widgets/e-paned/e-paned.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define E_TYPE_HPANED (e_hpaned_get_type ()) -#define E_HPANED(obj) (GTK_CHECK_CAST ((obj), E_TYPE_HPANED, EHPaned)) -#define E_HPANED_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_HPANED, EHPanedClass)) -#define E_IS_HPANED(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_HPANED)) -#define E_IS_HPANED_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_HPANED)) -#define E_HPANED_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), E_TYPE_HPANED, EHPanedClass)) - - -typedef struct _EHPaned EHPaned; -typedef struct _EHPanedClass EHPanedClass; - -struct _EHPaned -{ - EPaned paned; -}; - -struct _EHPanedClass -{ - EPanedClass parent_class; -}; - -GtkType e_hpaned_get_type (void); -GtkWidget *e_hpaned_new (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __E_HPANED_H__ */ diff --git a/widgets/e-paned/e-paned.c b/widgets/e-paned/e-paned.c deleted file mode 100644 index f02d4389a0..0000000000 --- a/widgets/e-paned/e-paned.c +++ /dev/null @@ -1,635 +0,0 @@ -/* EPaned - A slightly more advanced paned widget. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Christopher James Lahey <clahey@helixcode.com> - * - * based on GtkPaned from Gtk+. Gtk+ Copyright notice follows. - */ - -/* GTK - The GIMP Toolkit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#include "e-paned.h" - -enum { - ARG_0, - ARG_HANDLE_SIZE, - ARG_QUANTUM, -}; - -static void e_paned_class_init (EPanedClass *klass); -static void e_paned_init (EPaned *paned); -static void e_paned_set_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); -static void e_paned_get_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); -static void e_paned_realize (GtkWidget *widget); -static void e_paned_map (GtkWidget *widget); -static void e_paned_unmap (GtkWidget *widget); -static void e_paned_unrealize (GtkWidget *widget); -static gint e_paned_expose (GtkWidget *widget, - GdkEventExpose *event); -static void e_paned_add (GtkContainer *container, - GtkWidget *widget); -static void e_paned_remove (GtkContainer *container, - GtkWidget *widget); -static void e_paned_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); -static GtkType e_paned_child_type (GtkContainer *container); - -static GtkContainerClass *parent_class = NULL; - - -GtkType -e_paned_get_type (void) -{ - static GtkType paned_type = 0; - - if (!paned_type) - { - static const GtkTypeInfo paned_info = - { - "EPaned", - sizeof (EPaned), - sizeof (EPanedClass), - (GtkClassInitFunc) e_paned_class_init, - (GtkObjectInitFunc) e_paned_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - paned_type = gtk_type_unique (GTK_TYPE_CONTAINER, &paned_info); - } - - return paned_type; -} - -static void -e_paned_class_init (EPanedClass *klass) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - GtkContainerClass *container_class; - - object_class = (GtkObjectClass *) klass; - widget_class = (GtkWidgetClass *) klass; - container_class = (GtkContainerClass *) klass; - - parent_class = gtk_type_class (GTK_TYPE_CONTAINER); - - object_class->set_arg = e_paned_set_arg; - object_class->get_arg = e_paned_get_arg; - - widget_class->realize = e_paned_realize; - widget_class->map = e_paned_map; - widget_class->unmap = e_paned_unmap; - widget_class->unrealize = e_paned_unrealize; - widget_class->expose_event = e_paned_expose; - - container_class->add = e_paned_add; - container_class->remove = e_paned_remove; - container_class->forall = e_paned_forall; - container_class->child_type = e_paned_child_type; - - klass->handle_shown = NULL; - - gtk_object_add_arg_type("EPaned::handle_size", GTK_TYPE_UINT, - GTK_ARG_READWRITE, ARG_HANDLE_SIZE); - gtk_object_add_arg_type("EPaned::quantum", GTK_TYPE_UINT, - GTK_ARG_READWRITE, ARG_QUANTUM); -} - -static GtkType -e_paned_child_type (GtkContainer *container) -{ - if (!E_PANED (container)->child1 || !E_PANED (container)->child2) - return GTK_TYPE_WIDGET; - else - return GTK_TYPE_NONE; -} - -static void -e_paned_init (EPaned *paned) -{ - GTK_WIDGET_UNSET_FLAGS (paned, GTK_NO_WINDOW); - - paned->child1 = NULL; - paned->child2 = NULL; - paned->handle = NULL; - paned->xor_gc = NULL; - paned->cursor_type = GDK_CROSS; - - paned->handle_width = 5; - paned->handle_height = 5; - paned->handle_size = 5; - paned->position_set = FALSE; - paned->last_allocation = -1; - paned->in_drag = FALSE; - - paned->handle_xpos = -1; - paned->handle_ypos = -1; - - paned->old_child1_size = 0; - paned->child1_size = 0; - paned->quantum = 1; -} - -static void -e_paned_set_arg (GtkObject *object, - GtkArg *arg, - guint arg_id) -{ - EPaned *paned = E_PANED (object); - - switch (arg_id) - { - case ARG_HANDLE_SIZE: - e_paned_set_handle_size (paned, GTK_VALUE_UINT (*arg)); - break; - case ARG_QUANTUM: - paned->quantum = GTK_VALUE_UINT (*arg); - if (paned->quantum == 0) - paned->quantum = 1; - break; - default: - break; - } -} - -static void -e_paned_get_arg (GtkObject *object, - GtkArg *arg, - guint arg_id) -{ - EPaned *paned = E_PANED (object); - - switch (arg_id) - { - case ARG_HANDLE_SIZE: - GTK_VALUE_UINT (*arg) = paned->handle_size; - break; - case ARG_QUANTUM: - GTK_VALUE_UINT (*arg) = paned->quantum; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -e_paned_realize (GtkWidget *widget) -{ - EPaned *paned; - GdkWindowAttr attributes; - gint attributes_mask; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_PANED (widget)); - - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); - paned = E_PANED (widget); - - attributes.x = widget->allocation.x; - attributes.y = widget->allocation.y; - attributes.width = widget->allocation.width; - attributes.height = widget->allocation.height; - attributes.window_type = GDK_WINDOW_CHILD; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK; - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - - widget->window = gdk_window_new (gtk_widget_get_parent_window(widget), - &attributes, attributes_mask); - gdk_window_set_user_data (widget->window, paned); - - attributes.x = paned->handle_xpos; - attributes.y = paned->handle_ypos; - attributes.width = paned->handle_width; - attributes.height = paned->handle_height; - attributes.cursor = gdk_cursor_new (paned->cursor_type); - attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_POINTER_MOTION_MASK | - GDK_POINTER_MOTION_HINT_MASK); - attributes_mask |= GDK_WA_CURSOR; - - paned->handle = gdk_window_new (widget->window, - &attributes, attributes_mask); - gdk_window_set_user_data (paned->handle, paned); - gdk_cursor_destroy (attributes.cursor); - - widget->style = gtk_style_attach (widget->style, widget->window); - - gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); - gtk_style_set_background (widget->style, paned->handle, GTK_STATE_NORMAL); - - gdk_window_set_back_pixmap (widget->window, NULL, TRUE); - - if (e_paned_handle_shown(paned)) - gdk_window_show (paned->handle); -} - -static void -e_paned_map (GtkWidget *widget) -{ - EPaned *paned; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_PANED (widget)); - - GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); - paned = E_PANED (widget); - - if (paned->child1 && - GTK_WIDGET_VISIBLE (paned->child1) && - !GTK_WIDGET_MAPPED (paned->child1)) - gtk_widget_map (paned->child1); - if (paned->child2 && - GTK_WIDGET_VISIBLE (paned->child2) && - !GTK_WIDGET_MAPPED (paned->child2)) - gtk_widget_map (paned->child2); - - gdk_window_show (widget->window); -} - -static void -e_paned_unmap (GtkWidget *widget) -{ - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_PANED (widget)); - - GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); - - gdk_window_hide (widget->window); -} - -static void -e_paned_unrealize (GtkWidget *widget) -{ - EPaned *paned; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_PANED (widget)); - - paned = E_PANED (widget); - - if (paned->xor_gc) - { - gdk_gc_destroy (paned->xor_gc); - paned->xor_gc = NULL; - } - - if (paned->handle) - { - gdk_window_set_user_data (paned->handle, NULL); - gdk_window_destroy (paned->handle); - paned->handle = NULL; - } - - if (GTK_WIDGET_CLASS (parent_class)->unrealize) - (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); -} - -static gint -e_paned_expose (GtkWidget *widget, - GdkEventExpose *event) -{ - EPaned *paned; - GdkEventExpose child_event; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_PANED (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - if (GTK_WIDGET_DRAWABLE (widget)) - { - paned = E_PANED (widget); - - if (paned->handle && event->window == paned->handle) - { - if (e_paned_handle_shown(paned)) - { - child_event = *event; - event->area.x += paned->handle_xpos; - event->area.y += paned->handle_ypos; - gtk_widget_draw (widget, &event->area); - } - } - else - { - child_event = *event; - if (paned->child1 && - GTK_WIDGET_NO_WINDOW (paned->child1) && - gtk_widget_intersect (paned->child1, &event->area, &child_event.area)) - gtk_widget_event (paned->child1, (GdkEvent *) &child_event); - - if (paned->child2 && - GTK_WIDGET_NO_WINDOW (paned->child2) && - gtk_widget_intersect (paned->child2, &event->area, &child_event.area)) - gtk_widget_event (paned->child2, (GdkEvent *) &child_event); - } - } - - return FALSE; -} - -void -e_paned_add1 (EPaned *paned, - GtkWidget *widget) -{ - e_paned_pack1 (paned, widget, FALSE, TRUE); -} - -void -e_paned_add2 (EPaned *paned, - GtkWidget *widget) -{ - e_paned_pack2 (paned, widget, TRUE, TRUE); -} - -void -e_paned_pack1 (EPaned *paned, - GtkWidget *child, - gboolean resize, - gboolean shrink) -{ - g_return_if_fail (paned != NULL); - g_return_if_fail (E_IS_PANED (paned)); - g_return_if_fail (GTK_IS_WIDGET (child)); - - if (!paned->child1) - { - paned->child1 = child; - paned->child1_resize = resize; - paned->child1_shrink = shrink; - - gtk_widget_set_parent (child, GTK_WIDGET (paned)); - - if (GTK_WIDGET_REALIZED (child->parent)) - gtk_widget_realize (child); - - if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child)) - { - if (GTK_WIDGET_MAPPED (child->parent)) - gtk_widget_map (child); - - gtk_widget_queue_resize (child); - } - } -} - -void -e_paned_pack2 (EPaned *paned, - GtkWidget *child, - gboolean resize, - gboolean shrink) -{ - g_return_if_fail (paned != NULL); - g_return_if_fail (E_IS_PANED (paned)); - g_return_if_fail (GTK_IS_WIDGET (child)); - - if (!paned->child2) - { - paned->child2 = child; - paned->child2_resize = resize; - paned->child2_shrink = shrink; - - gtk_widget_set_parent (child, GTK_WIDGET (paned)); - - if (GTK_WIDGET_REALIZED (child->parent)) - gtk_widget_realize (child); - - if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child)) - { - if (GTK_WIDGET_MAPPED (child->parent)) - gtk_widget_map (child); - - gtk_widget_queue_resize (child); - } - } -} - - -static void -e_paned_add (GtkContainer *container, - GtkWidget *widget) -{ - EPaned *paned; - - g_return_if_fail (container != NULL); - g_return_if_fail (E_IS_PANED (container)); - g_return_if_fail (widget != NULL); - - paned = E_PANED (container); - - if (!paned->child1) - e_paned_add1 (E_PANED (container), widget); - else if (!paned->child2) - e_paned_add2 (E_PANED (container), widget); -} - -static void -e_paned_remove (GtkContainer *container, - GtkWidget *widget) -{ - EPaned *paned; - gboolean was_visible; - - g_return_if_fail (container != NULL); - g_return_if_fail (E_IS_PANED (container)); - g_return_if_fail (widget != NULL); - - paned = E_PANED (container); - was_visible = GTK_WIDGET_VISIBLE (widget); - - if (paned->child1 == widget) - { - gtk_widget_unparent (widget); - - paned->child1 = NULL; - - if (was_visible && GTK_WIDGET_VISIBLE (container)) - gtk_widget_queue_resize (GTK_WIDGET (container)); - } - else if (paned->child2 == widget) - { - gtk_widget_unparent (widget); - - paned->child2 = NULL; - - if (was_visible && GTK_WIDGET_VISIBLE (container)) - gtk_widget_queue_resize (GTK_WIDGET (container)); - } -} - -static void -e_paned_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data) -{ - EPaned *paned; - - g_return_if_fail (container != NULL); - g_return_if_fail (E_IS_PANED (container)); - g_return_if_fail (callback != NULL); - - paned = E_PANED (container); - - if (paned->child1) - (*callback) (paned->child1, callback_data); - if (paned->child2) - (*callback) (paned->child2, callback_data); -} - -gint -e_paned_get_position (EPaned *paned) -{ - g_return_val_if_fail (paned != NULL, 0); - g_return_val_if_fail (E_IS_PANED (paned), 0); - - return paned->child1_real_size; -} - -void -e_paned_set_position (EPaned *paned, - gint position) -{ - g_return_if_fail (paned != NULL); - g_return_if_fail (E_IS_PANED (paned)); - - if (position >= 0) - { - /* We don't clamp here - the assumption is that - * if the total allocation changes at the same time - * as the position, the position set is with reference - * to the new total size. If only the position changes, - * then clamping will occur in e_paned_compute_position() - */ - paned->child1_size = position; - paned->position_set = TRUE; - } - else - { - paned->position_set = FALSE; - } - - gtk_widget_queue_resize (GTK_WIDGET (paned)); -} - -void -e_paned_set_handle_size (EPaned *paned, - guint16 size) -{ - g_return_if_fail (paned != NULL); - g_return_if_fail (E_IS_PANED (paned)); - - gtk_widget_queue_resize (GTK_WIDGET (paned)); - - paned->handle_size = size; -} - -void -e_paned_compute_position(EPaned *paned, - gint allocation, - gint child1_req, - gint child2_req) -{ - g_return_if_fail (paned != NULL); - g_return_if_fail (E_IS_PANED (paned)); - - if (e_paned_handle_shown(paned)) - allocation -= (gint) paned->handle_size; - - paned->min_position = paned->child1_shrink ? 0 : child1_req; - - paned->max_position = allocation; - if (!paned->child2_shrink) - paned->max_position = MAX (1, paned->max_position - child2_req); - - if (!paned->position_set) - { - if (paned->child1_resize && !paned->child2_resize) - paned->child1_size = MAX (1, allocation - child2_req); - else if (!paned->child1_resize && paned->child2_resize) - paned->child1_size = child1_req; - else if (child1_req + child2_req != 0) - paned->child1_size = allocation * ((gdouble)child1_req / (child1_req + child2_req)); - else - paned->child1_size = allocation * 0.5; - } - else - { - /* If the position was set before the initial allocation. - * (paned->last_allocation <= 0) just clamp it and leave it. - */ - if (paned->last_allocation > 0) - { - if (paned->child1_resize && !paned->child2_resize) - paned->child1_size += allocation - paned->last_allocation; - else if (paned->child1_resize && paned->child2_resize) - paned->child1_size = allocation * ((gdouble) paned->child1_size / (paned->last_allocation)); - } - } - - paned->child1_real_size = CLAMP (paned->child1_size, - paned->min_position, - paned->max_position); - - paned->last_allocation = allocation; -} - -gboolean -e_paned_handle_shown(EPaned *paned) -{ - EPanedClass *klass = E_PANED_CLASS(GTK_OBJECT(paned)->klass); - if (klass->handle_shown) - return (*klass->handle_shown)(paned); - else - return TRUE; -} - -gint -e_paned_quantized_size(EPaned *paned, - gint size) -{ - gint quantization = size - paned->old_child1_size; - if (quantization > 0) - quantization += paned->quantum / 2; - else - quantization -= paned->quantum / 2; - quantization /= paned->quantum; - quantization *= paned->quantum; - return paned->old_child1_size + quantization; -} diff --git a/widgets/e-paned/e-paned.h b/widgets/e-paned/e-paned.h deleted file mode 100644 index b211d32bda..0000000000 --- a/widgets/e-paned/e-paned.h +++ /dev/null @@ -1,135 +0,0 @@ -/* EPaned - A slightly more advanced paned widget. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Christopher James Lahey <clahey@helixcode.com> - * - * based on GtkPaned from Gtk+. Gtk+ Copyright notice follows. - */ - -/* GTK - The GIMP Toolkit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#ifndef __E_PANED_H__ -#define __E_PANED_H__ - -#include <gtk/gtkcontainer.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define E_TYPE_PANED (e_paned_get_type ()) -#define E_PANED(obj) (GTK_CHECK_CAST ((obj), E_TYPE_PANED, EPaned)) -#define E_PANED_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_PANED, EPanedClass)) -#define E_IS_PANED(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_PANED)) -#define E_IS_PANED_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_PANED)) -#define E_PANED_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), E_TYPE_PANED, EPanedClass)) - - -typedef struct _EPaned EPaned; -typedef struct _EPanedClass EPanedClass; - -struct _EPaned -{ - GtkContainer container; - - GtkWidget *child1; - GtkWidget *child2; - - GdkWindow *handle; - GdkGC *xor_gc; - GdkCursorType cursor_type; - - /*< public >*/ - guint16 handle_size; - - /*< private >*/ - guint16 handle_width; - guint16 handle_height; - - gint child1_real_size; - gint child1_size; - gint last_allocation; - gint min_position; - gint max_position; - - gint old_child1_size; - gint quantum; - - guint position_set : 1; - guint in_drag : 1; - guint child1_shrink : 1; - guint child1_resize : 1; - guint child2_shrink : 1; - guint child2_resize : 1; - - gint16 handle_xpos; - gint16 handle_ypos; -}; - -struct _EPanedClass -{ - GtkContainerClass parent_class; - - /* Protected virtual method. */ - gboolean (*handle_shown) (EPaned *paned); -}; - - -GtkType e_paned_get_type (void); -void e_paned_add1 (EPaned *paned, - GtkWidget *child); -void e_paned_add2 (EPaned *paned, - GtkWidget *child); -void e_paned_pack1 (EPaned *paned, - GtkWidget *child, - gboolean resize, - gboolean shrink); -void e_paned_pack2 (EPaned *paned, - GtkWidget *child, - gboolean resize, - gboolean shrink); -gint e_paned_get_position (EPaned *paned); -void e_paned_set_position (EPaned *paned, - gint position); -void e_paned_set_handle_size (EPaned *paned, - guint16 size); - -/* Internal function */ -void e_paned_compute_position (EPaned *paned, - gint allocation, - gint child1_req, - gint child2_req); - -gboolean e_paned_handle_shown (EPaned *paned); -gint e_paned_quantized_size (EPaned *paned, - int size); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __E_PANED_H__ */ diff --git a/widgets/e-paned/e-vpaned.c b/widgets/e-paned/e-vpaned.c deleted file mode 100644 index 705a36f331..0000000000 --- a/widgets/e-paned/e-vpaned.c +++ /dev/null @@ -1,438 +0,0 @@ -/* EPaned - A slightly more advanced paned widget. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Christopher James Lahey <clahey@helixcode.com> - * - * based on GtkPaned from Gtk+. Gtk+ Copyright notice follows. - */ - -/* GTK - The GIMP Toolkit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#include "e-vpaned.h" - -static void e_vpaned_class_init (EVPanedClass *klass); -static void e_vpaned_init (EVPaned *vpaned); -static void e_vpaned_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void e_vpaned_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void e_vpaned_draw (GtkWidget *widget, - GdkRectangle *area); -static void e_vpaned_xor_line (EPaned *paned); -static gboolean e_vpaned_button_press (GtkWidget *widget, - GdkEventButton *event); -static gboolean e_vpaned_button_release (GtkWidget *widget, - GdkEventButton *event); -static gboolean e_vpaned_motion (GtkWidget *widget, - GdkEventMotion *event); -static gboolean e_vpaned_handle_shown (EPaned *paned); - -GtkType -e_vpaned_get_type (void) -{ - static GtkType vpaned_type = 0; - - if (!vpaned_type) - { - static const GtkTypeInfo vpaned_info = - { - "EVPaned", - sizeof (EVPaned), - sizeof (EVPanedClass), - (GtkClassInitFunc) e_vpaned_class_init, - (GtkObjectInitFunc) e_vpaned_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - vpaned_type = gtk_type_unique (E_TYPE_PANED, &vpaned_info); - } - - return vpaned_type; -} - -static void -e_vpaned_class_init (EVPanedClass *klass) -{ - GtkWidgetClass *widget_class; - EPanedClass *paned_class; - - widget_class = (GtkWidgetClass *) klass; - paned_class = E_PANED_CLASS (klass); - - widget_class->size_request = e_vpaned_size_request; - widget_class->size_allocate = e_vpaned_size_allocate; - widget_class->draw = e_vpaned_draw; - widget_class->button_press_event = e_vpaned_button_press; - widget_class->button_release_event = e_vpaned_button_release; - widget_class->motion_notify_event = e_vpaned_motion; - - paned_class->handle_shown = e_vpaned_handle_shown; -} - -static void -e_vpaned_init (EVPaned *vpaned) -{ - EPaned *paned; - - g_return_if_fail (vpaned != NULL); - g_return_if_fail (E_IS_PANED (vpaned)); - - paned = E_PANED (vpaned); - - paned->cursor_type = GDK_SB_V_DOUBLE_ARROW; -} - -GtkWidget * -e_vpaned_new (void) -{ - EVPaned *vpaned; - - vpaned = gtk_type_new (E_TYPE_VPANED); - - return GTK_WIDGET (vpaned); -} - -static void -e_vpaned_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - EPaned *paned; - GtkRequisition child_requisition; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_VPANED (widget)); - g_return_if_fail (requisition != NULL); - - paned = E_PANED (widget); - requisition->width = 0; - requisition->height = 0; - - if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1)) - { - gtk_widget_size_request (paned->child1, &child_requisition); - - requisition->height = child_requisition.height; - requisition->width = child_requisition.width; - } - - if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2)) - { - gtk_widget_size_request (paned->child2, &child_requisition); - - requisition->width = MAX (requisition->width, child_requisition.width); - requisition->height += child_requisition.height; - } - - requisition->height += GTK_CONTAINER (paned)->border_width * 2; - requisition->width += GTK_CONTAINER (paned)->border_width * 2; - if (e_paned_handle_shown(paned)) - requisition->height += paned->handle_size; -} - -static void -e_vpaned_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - EPaned *paned; - GtkRequisition child1_requisition; - GtkRequisition child2_requisition; - GtkAllocation child1_allocation; - GtkAllocation child2_allocation; - gint border_width; - gboolean handle_shown; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_VPANED (widget)); - g_return_if_fail (allocation != NULL); - - widget->allocation = *allocation; - paned = E_PANED (widget); - border_width = GTK_CONTAINER (widget)->border_width; - - if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1)) - gtk_widget_get_child_requisition (paned->child1, &child1_requisition); - else - child1_requisition.height = 0; - - if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2)) - gtk_widget_get_child_requisition (paned->child2, &child2_requisition); - else - child2_requisition.height = 0; - - e_paned_compute_position (paned, - MAX (1, (gint) widget->allocation.height - - 2 * border_width), - child1_requisition.height, - child2_requisition.height); - - /* Move the handle before the children so we don't get extra expose events */ - - if (GTK_WIDGET_REALIZED (widget)) - gdk_window_move_resize (widget->window, - allocation->x, allocation->y, - allocation->width, - allocation->height); - - handle_shown = e_paned_handle_shown(paned); - if (handle_shown) - { - paned->handle_xpos = border_width; - paned->handle_ypos = paned->child1_real_size + border_width; - paned->handle_width = MAX (1, (gint) widget->allocation.width - 2 * border_width); - paned->handle_height = paned->handle_size; - - if (GTK_WIDGET_REALIZED (widget)) - { - gdk_window_move_resize (paned->handle, - paned->handle_xpos, - paned->handle_ypos, - paned->handle_width, - paned->handle_size); - if (paned->handle) - gdk_window_show(paned->handle); - } - } - else - { - if (paned->handle && GTK_WIDGET_REALIZED (widget)) - gdk_window_hide(paned->handle); - } - - child1_allocation.width = child2_allocation.width = MAX (1, (gint) allocation->width - border_width * 2); - child1_allocation.height = paned->child1_real_size; - child1_allocation.x = child2_allocation.x = border_width; - child1_allocation.y = border_width; - - if (handle_shown) - child2_allocation.y = child1_allocation.y + child1_allocation.height + paned->handle_height; - else - child2_allocation.y = child1_allocation.y + child1_allocation.height; - child2_allocation.height = MAX(1, (gint) allocation->height - child2_allocation.y - border_width); - - /* Now allocate the childen, making sure, when resizing not to - * overlap the windows */ - if (GTK_WIDGET_MAPPED (widget) && - paned->child1 && GTK_WIDGET_VISIBLE (paned->child1) && - paned->child1->allocation.height < child1_allocation.height) - { - if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2)) - gtk_widget_size_allocate(paned->child2, &child2_allocation); - gtk_widget_size_allocate(paned->child1, &child1_allocation); - } - else - { - if (paned->child1 && GTK_WIDGET_VISIBLE (paned->child1)) - gtk_widget_size_allocate(paned->child1, &child1_allocation); - if (paned->child2 && GTK_WIDGET_VISIBLE (paned->child2)) - gtk_widget_size_allocate(paned->child2, &child2_allocation); - } -} - -static void -e_vpaned_draw (GtkWidget *widget, - GdkRectangle *area) -{ - EPaned *paned; - GdkRectangle handle_area, child_area; - guint16 border_width; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_PANED (widget)); - - if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget)) - { - paned = E_PANED (widget); - border_width = GTK_CONTAINER (paned)->border_width; - - gdk_window_clear_area (widget->window, - area->x, area->y, area->width, - area->height); - - if (e_paned_handle_shown(paned)) - { - handle_area.x = paned->handle_xpos; - handle_area.y = paned->handle_ypos; - handle_area.width = paned->handle_width; - handle_area.height = paned->handle_size; - - if (gdk_rectangle_intersect (&handle_area, area, &child_area)) - { - child_area.x -= paned->handle_xpos; - child_area.y -= paned->handle_ypos; - - gtk_paint_handle (widget->style, - paned->handle, - GTK_STATE_NORMAL, - GTK_SHADOW_NONE, - &child_area, - widget, - "paned", - 0, 0, -1, -1, - GTK_ORIENTATION_HORIZONTAL); - - } - } - /* Redraw the children - */ - if (paned->child1 && gtk_widget_intersect (paned->child1, area, &child_area)) - gtk_widget_draw (paned->child1, &child_area); - if (paned->child2 && gtk_widget_intersect (paned->child2, area, &child_area)) - gtk_widget_draw (paned->child2, &child_area); - } -} - -static void -e_vpaned_xor_line (EPaned *paned) -{ - GtkWidget *widget; - GdkGCValues values; - guint16 ypos; - - widget = GTK_WIDGET (paned); - - if (!paned->xor_gc) - { - values.function = GDK_INVERT; - values.subwindow_mode = GDK_INCLUDE_INFERIORS; - paned->xor_gc = gdk_gc_new_with_values (widget->window, - &values, - GDK_GC_FUNCTION | GDK_GC_SUBWINDOW); - } - - gdk_gc_set_line_attributes (paned->xor_gc, 2, GDK_LINE_SOLID, - GDK_CAP_NOT_LAST, GDK_JOIN_BEVEL); - - ypos = paned->child1_real_size - + GTK_CONTAINER (paned)->border_width + paned->handle_size / 2; - - gdk_draw_line (widget->window, paned->xor_gc, - 0, - ypos, - widget->allocation.width - 1, - ypos); -} - -static gboolean -e_vpaned_button_press (GtkWidget *widget, - GdkEventButton *event) -{ - EPaned *paned; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_PANED (widget), FALSE); - - paned = E_PANED (widget); - - if (!paned->in_drag && - (event->window == paned->handle) && (event->button == 1)) - { - paned->old_child1_size = paned->child1_size; - paned->in_drag = TRUE; - /* We need a server grab here, not gtk_grab_add(), since - * we don't want to pass events on to the widget's children */ - gdk_pointer_grab (paned->handle, FALSE, - GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON1_MOTION_MASK - | GDK_BUTTON_RELEASE_MASK, NULL, NULL, - event->time); - paned->child1_size = e_paned_quantized_size(paned, paned->child1_size + event->y - paned->handle_size / 2); - paned->child1_size = CLAMP (paned->child1_size, 0, - widget->allocation.height - - paned->handle_size - - 2 * GTK_CONTAINER (paned)->border_width); - paned->child1_real_size = paned->child1_size; - e_vpaned_xor_line(paned); - - return TRUE; - } - - return FALSE; -} - -static gboolean -e_vpaned_button_release (GtkWidget *widget, - GdkEventButton *event) -{ - EPaned *paned; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_PANED (widget), FALSE); - - paned = E_PANED (widget); - - if (paned->in_drag && (event->button == 1)) - { - e_vpaned_xor_line (paned); - paned->in_drag = FALSE; - paned->position_set = TRUE; - gdk_pointer_ungrab (event->time); - gtk_widget_queue_resize (GTK_WIDGET (paned)); - - return TRUE; - } - - return FALSE; -} - -static gboolean -e_vpaned_motion (GtkWidget *widget, - GdkEventMotion *event) -{ - EPaned *paned; - gint y; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_PANED (widget), FALSE); - - if (event->is_hint || event->window != widget->window) - gtk_widget_get_pointer (widget, NULL, &y); - else - y = event->y; - - paned = E_PANED (widget); - - if (paned->in_drag) - { - gint size = y - GTK_CONTAINER(paned)->border_width - paned->handle_size / 2; - - e_vpaned_xor_line (paned); - paned->child1_size = CLAMP (e_paned_quantized_size(paned, size), paned->min_position, paned->max_position); - paned->child1_real_size = paned->child1_size; - e_vpaned_xor_line(paned); - } - - return TRUE; -} - -static gboolean -e_vpaned_handle_shown (EPaned *paned) -{ - return ((paned->child1 && paned->child2) && - (GTK_WIDGET_VISIBLE (paned->child1) && GTK_WIDGET_VISIBLE (paned->child2))); -} diff --git a/widgets/e-paned/e-vpaned.h b/widgets/e-paned/e-vpaned.h deleted file mode 100644 index 1c247472fd..0000000000 --- a/widgets/e-paned/e-vpaned.h +++ /dev/null @@ -1,72 +0,0 @@ -/* EPaned - A slightly more advanced paned widget. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Christopher James Lahey <clahey@helixcode.com> - * - * based on GtkPaned from Gtk+. Gtk+ Copyright notice follows. - */ - -/* GTK - The GIMP Toolkit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#ifndef __E_VPANED_H__ -#define __E_VPANED_H__ - -#include <widgets/e-paned/e-paned.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define E_TYPE_VPANED (e_vpaned_get_type ()) -#define E_VPANED(obj) (GTK_CHECK_CAST ((obj), E_TYPE_VPANED, EVPaned)) -#define E_VPANED_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_VPANED, EVPanedClass)) -#define E_IS_VPANED(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_VPANED)) -#define E_IS_VPANED_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_VPANED)) -#define E_VPANED_GET_CLASS(obj) (GTK_CHECK_GET_CLASS ((obj), E_TYPE_VPANED, EVPanedClass)) - - -typedef struct _EVPaned EVPaned; -typedef struct _EVPanedClass EVPanedClass; - -struct _EVPaned -{ - EPaned paned; -}; - -struct _EVPanedClass -{ - EPanedClass parent_class; -}; - -GtkType e_vpaned_get_type (void); -GtkWidget *e_vpaned_new (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __E_VPANED_H__ */ diff --git a/widgets/e-reflow/e-reflow-sorted.c b/widgets/e-reflow/e-reflow-sorted.c deleted file mode 100644 index 2d2dcee787..0000000000 --- a/widgets/e-reflow/e-reflow-sorted.c +++ /dev/null @@ -1,272 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-reflow-sorted.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <config.h> -#include <math.h> -#include <gnome.h> -#include "e-reflow-sorted.h" -#include <e-util/e-canvas-utils.h> -#include <e-util/e-canvas.h> -#include <e-util/e-util.h> - -static void e_reflow_sorted_init (EReflowSorted *card); -static void e_reflow_sorted_class_init (EReflowSortedClass *klass); -static void e_reflow_sorted_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); -static void e_reflow_sorted_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_reflow_sorted_add_item(EReflow *e_reflow, GnomeCanvasItem *item); - -#define E_REFLOW_DIVIDER_WIDTH 2 -#define E_REFLOW_BORDER_WIDTH 7 -#define E_REFLOW_FULL_GUTTER (E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH * 2) - -static EReflowClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0, - ARG_COMPARE_FUNC, - ARG_STRING_FUNC -}; - -GtkType -e_reflow_sorted_get_type (void) -{ - static GtkType reflow_type = 0; - - if (!reflow_type) - { - static const GtkTypeInfo reflow_info = - { - "EReflowSorted", - sizeof (EReflowSorted), - sizeof (EReflowSortedClass), - (GtkClassInitFunc) e_reflow_sorted_class_init, - (GtkObjectInitFunc) e_reflow_sorted_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - reflow_type = gtk_type_unique (e_reflow_get_type (), &reflow_info); - } - - return reflow_type; -} - -static void -e_reflow_sorted_class_init (EReflowSortedClass *klass) -{ - GtkObjectClass *object_class; - EReflowClass *reflow_class; - - object_class = (GtkObjectClass*) klass; - reflow_class = E_REFLOW_CLASS (klass); - - parent_class = gtk_type_class (e_reflow_get_type ()); - - gtk_object_add_arg_type ("EReflowSorted::compare_func", GTK_TYPE_POINTER, - GTK_ARG_READWRITE, ARG_COMPARE_FUNC); - gtk_object_add_arg_type ("EReflowSorted::string_func", GTK_TYPE_POINTER, - GTK_ARG_READWRITE, ARG_STRING_FUNC); - - reflow_class->add_item = e_reflow_sorted_add_item; - - object_class->set_arg = e_reflow_sorted_set_arg; - object_class->get_arg = e_reflow_sorted_get_arg; -} - -static void -e_reflow_sorted_init (EReflowSorted *reflow) -{ - reflow->compare_func = NULL; - reflow->string_func = NULL; -} - -static void -e_reflow_sorted_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EReflowSorted *e_reflow_sorted; - - item = GNOME_CANVAS_ITEM (o); - e_reflow_sorted = E_REFLOW_SORTED (o); - - switch (arg_id){ - case ARG_COMPARE_FUNC: - e_reflow_sorted->compare_func = GTK_VALUE_POINTER (*arg); - break; - case ARG_STRING_FUNC: - e_reflow_sorted->string_func = GTK_VALUE_POINTER (*arg); - break; - } -} - -static void -e_reflow_sorted_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - EReflowSorted *e_reflow_sorted; - - e_reflow_sorted = E_REFLOW_SORTED (object); - - switch (arg_id) { - case ARG_COMPARE_FUNC: - GTK_VALUE_POINTER (*arg) = e_reflow_sorted->compare_func; - break; - case ARG_STRING_FUNC: - GTK_VALUE_POINTER (*arg) = e_reflow_sorted->string_func; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static GList * -e_reflow_sorted_get_list(EReflowSorted *e_reflow_sorted, const gchar *id) -{ - if (e_reflow_sorted->string_func) { - EReflow *reflow = E_REFLOW(e_reflow_sorted); - GList *list; - for (list = reflow->items; list; list = g_list_next(list)) { - GnomeCanvasItem *item = list->data; - char *string = e_reflow_sorted->string_func (item); - if (string && !strcmp(string, id)) { - return list; - } - } - } - return NULL; -} - -void -e_reflow_sorted_remove_item(EReflowSorted *e_reflow_sorted, const gchar *id) -{ - GList *list; - GnomeCanvasItem *item = NULL; - - list = e_reflow_sorted_get_list(e_reflow_sorted, id); - if (list) - item = list->data; - - if (item) { - EReflow *reflow = E_REFLOW(e_reflow_sorted); - reflow->items = g_list_remove_link(reflow->items, list); - g_list_free_1(list); - gtk_object_unref(GTK_OBJECT(item)); - gtk_object_destroy(GTK_OBJECT(item)); - if ( GTK_OBJECT_FLAGS( e_reflow_sorted ) & GNOME_CANVAS_ITEM_REALIZED ) { - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(e_reflow_sorted)); - e_reflow_post_add_item(E_REFLOW(e_reflow_sorted), NULL); - } - } -} - -void -e_reflow_sorted_replace_item(EReflowSorted *e_reflow_sorted, GnomeCanvasItem *item) -{ - if (e_reflow_sorted->string_func) { - char *string = e_reflow_sorted->string_func (item); - e_reflow_sorted_remove_item(e_reflow_sorted, string); - e_reflow_sorted_add_item(E_REFLOW(e_reflow_sorted), item); - } -} - -GnomeCanvasItem * -e_reflow_sorted_get_item(EReflowSorted *e_reflow_sorted, const gchar *id) -{ - GList *list; - list = e_reflow_sorted_get_list(e_reflow_sorted, id); - if (list) - return list->data; - else - return NULL; -} - -void -e_reflow_sorted_reorder_item(EReflowSorted *e_reflow_sorted, const gchar *id) -{ - GList *list; - GnomeCanvasItem *item = NULL; - - list = e_reflow_sorted_get_list(e_reflow_sorted, id); - if (list) - item = list->data; - if (item) { - EReflow *reflow = E_REFLOW(e_reflow_sorted); - reflow->items = g_list_remove_link(reflow->items, list); - gtk_object_unref(GTK_OBJECT(item)); - g_list_free_1(list); - e_reflow_sorted_add_item(reflow, item); - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(e_reflow_sorted)); - } -} - -static void -e_reflow_sorted_add_item(EReflow *reflow, GnomeCanvasItem *item) -{ - EReflowSorted *e_reflow_sorted = E_REFLOW_SORTED(reflow); - if ( e_reflow_sorted->compare_func ) { - reflow->items = g_list_insert_sorted(reflow->items, item, e_reflow_sorted->compare_func); - gtk_object_ref(GTK_OBJECT(item)); - - if ( GTK_OBJECT_FLAGS( e_reflow_sorted ) & GNOME_CANVAS_ITEM_REALIZED ) { - gnome_canvas_item_set(item, - "width", (double) reflow->column_width, - NULL); - - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(e_reflow_sorted)); - } - } - e_reflow_post_add_item(reflow, item); -} - -void e_reflow_sorted_jump (EReflowSorted *sorted, - GCompareFunc compare_func, - void *value) -{ - int columns = 0; - EReflow *reflow = E_REFLOW(sorted); - GList *list; - GtkAdjustment *adjustment; - - for (list = reflow->columns; list; list = g_list_next(list)) { - if (compare_func(((GList *)list->data)->data, value) >= 0) { - GList *last = list->prev; - if (last) { - GList *walk; - for (walk = last->data; walk != list->data; walk = g_list_next(walk)) { - if (compare_func(walk->data, value) >= 0) { - columns --; - break; - } - } - } - adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(GNOME_CANVAS_ITEM(sorted)->canvas)); - gtk_adjustment_set_value(adjustment, (reflow->column_width + E_REFLOW_FULL_GUTTER) * columns); - return; - } - columns ++; - } - columns --; - adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(GNOME_CANVAS_ITEM(sorted)->canvas)); - gtk_adjustment_set_value(adjustment, (reflow->column_width + E_REFLOW_FULL_GUTTER) * columns); -} diff --git a/widgets/e-reflow/e-reflow-sorted.h b/widgets/e-reflow/e-reflow-sorted.h deleted file mode 100644 index 1be4971fb2..0000000000 --- a/widgets/e-reflow/e-reflow-sorted.h +++ /dev/null @@ -1,90 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-reflow-sorted.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef __E_REFLOW_SORTED_H__ -#define __E_REFLOW_SORTED_H__ - -#include <addressbook/gui/minicard/e-reflow.h> - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* EReflowSorted - A canvas item container. - * - * The following arguments are available: - * - * name type read/write description - * -------------------------------------------------------------------------------- - * compare_func GCompareFunc RW compare function - * string_func EReflowStringFunc RW string function - * - * From EReflow: - * minimum_width double RW minimum width of the reflow. width >= minimum_width - * width double R width of the reflow - * height double RW height of the reflow - */ - -#define E_REFLOW_SORTED_TYPE (e_reflow_sorted_get_type ()) -#define E_REFLOW_SORTED(obj) (GTK_CHECK_CAST ((obj), E_REFLOW_SORTED_TYPE, EReflowSorted)) -#define E_REFLOW_SORTED_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_REFLOW_SORTED_TYPE, EReflowSortedClass)) -#define E_IS_REFLOW_SORTED(obj) (GTK_CHECK_TYPE ((obj), E_REFLOW_SORTED_TYPE)) -#define E_IS_REFLOW_SORTED_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_REFLOW_SORTED_TYPE)) - -typedef char * (* EReflowStringFunc) (GnomeCanvasItem *); - -typedef struct _EReflowSorted EReflowSorted; -typedef struct _EReflowSortedClass EReflowSortedClass; - -/* FIXME: Try reimplementing this as a hash table with key as string - and change EReflow to use a GTree. */ -struct _EReflowSorted -{ - EReflow parent; - - /* item specific fields */ - GCompareFunc compare_func; - EReflowStringFunc string_func; -}; - -struct _EReflowSortedClass -{ - EReflowClass parent_class; -}; - -/* - * To be added to a reflow, an item must have the argument "width" as - * a Read/Write argument and "height" as a Read Only argument. It - * should also do an ECanvas parent reflow request if its size - * changes. - */ -void e_reflow_sorted_remove_item (EReflowSorted *sorted, const char *id); -void e_reflow_sorted_replace_item (EReflowSorted *sorted, GnomeCanvasItem *item); -void e_reflow_sorted_reorder_item (EReflowSorted *e_reflow_sorted, const gchar *id); -GnomeCanvasItem *e_reflow_sorted_get_item (EReflowSorted *e_reflow_sorted, const gchar *id); -GtkType e_reflow_sorted_get_type (void); -void e_reflow_sorted_jump (EReflowSorted *sorted, GCompareFunc compare_func, void *value); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __E_REFLOW_SORTED_H__ */ diff --git a/widgets/e-reflow/e-reflow.c b/widgets/e-reflow/e-reflow.c deleted file mode 100644 index 0e9c8b92b1..0000000000 --- a/widgets/e-reflow/e-reflow.c +++ /dev/null @@ -1,859 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-reflow.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <config.h> -#include <gnome.h> -#include <math.h> -#include "e-reflow.h" -#include "e-text.h" -#include <e-util/e-canvas-utils.h> -#include <e-util/e-canvas.h> -#include <e-util/e-util.h> - -static void e_reflow_init (EReflow *reflow); -static void e_reflow_class_init (EReflowClass *klass); -static void e_reflow_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); -static void e_reflow_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_reflow_destroy (GtkObject *object); -static gboolean e_reflow_event (GnomeCanvasItem *item, GdkEvent *event); -static void e_reflow_realize (GnomeCanvasItem *item); -static void e_reflow_unrealize (GnomeCanvasItem *item); -static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable, - int x, int y, int width, int height); -static void e_reflow_update (GnomeCanvasItem *item, double affine[6], ArtSVP *clip_path, gint flags); -static double e_reflow_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item); -static void e_reflow_reflow (GnomeCanvasItem *item, int flags); -static void e_reflow_real_add_item(EReflow *e_reflow, GnomeCanvasItem *item); -static void set_empty(EReflow *e_reflow); - -static void e_reflow_resize_children (GnomeCanvasItem *item); - -#define E_REFLOW_DIVIDER_WIDTH 2 -#define E_REFLOW_BORDER_WIDTH 7 -#define E_REFLOW_FULL_GUTTER (E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH * 2) - -static GnomeCanvasGroupClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0, - ARG_MINIMUM_WIDTH, - ARG_WIDTH, - ARG_HEIGHT, - ARG_EMPTY_MESSAGE, -}; - -GtkType -e_reflow_get_type (void) -{ - static GtkType reflow_type = 0; - - if (!reflow_type) - { - static const GtkTypeInfo reflow_info = - { - "EReflow", - sizeof (EReflow), - sizeof (EReflowClass), - (GtkClassInitFunc) e_reflow_class_init, - (GtkObjectInitFunc) e_reflow_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - reflow_type = gtk_type_unique (gnome_canvas_group_get_type (), &reflow_info); - } - - return reflow_type; -} - -static void -e_reflow_class_init (EReflowClass *klass) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - object_class = (GtkObjectClass*) klass; - item_class = (GnomeCanvasItemClass *) klass; - - parent_class = gtk_type_class (gnome_canvas_group_get_type ()); - - gtk_object_add_arg_type ("EReflow::minimum_width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_MINIMUM_WIDTH); - gtk_object_add_arg_type ("EReflow::width", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_WIDTH); - gtk_object_add_arg_type ("EReflow::height", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_HEIGHT); - gtk_object_add_arg_type ("EReflow::empty_message", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_EMPTY_MESSAGE); - - klass->add_item = e_reflow_real_add_item; - - object_class->set_arg = e_reflow_set_arg; - object_class->get_arg = e_reflow_get_arg; - object_class->destroy = e_reflow_destroy; - - /* GnomeCanvasItem method overrides */ - item_class->event = e_reflow_event; - item_class->realize = e_reflow_realize; - item_class->unrealize = e_reflow_unrealize; - item_class->draw = e_reflow_draw; - item_class->update = e_reflow_update; - item_class->point = e_reflow_point; -} - -static void -e_reflow_init (EReflow *reflow) -{ - reflow->items = NULL; - reflow->columns = NULL; - reflow->column_width = 150; - - reflow->minimum_width = 10; - reflow->width = 10; - reflow->height = 10; - reflow->idle = 0; - - reflow->empty_message = NULL; - reflow->empty_text = NULL; - - reflow->column_drag = FALSE; - - reflow->need_height_update = FALSE; - reflow->need_column_resize = FALSE; - - reflow->default_cursor_shown = TRUE; - reflow->arrow_cursor = NULL; - reflow->default_cursor = NULL; - - e_canvas_item_set_reflow_callback(GNOME_CANVAS_ITEM(reflow), e_reflow_reflow); -} - -static void -e_reflow_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EReflow *e_reflow; - - item = GNOME_CANVAS_ITEM (o); - e_reflow = E_REFLOW (o); - - switch (arg_id){ - case ARG_HEIGHT: - e_reflow->height = GTK_VALUE_DOUBLE (*arg); - e_canvas_item_request_reflow(item); - break; - case ARG_MINIMUM_WIDTH: - e_reflow->minimum_width = GTK_VALUE_DOUBLE (*arg); - if (GNOME_CANVAS_ITEM_REALIZED & GTK_OBJECT_FLAGS(o)) - set_empty(e_reflow); - e_canvas_item_request_reflow(item); - break; - case ARG_EMPTY_MESSAGE: - g_free(e_reflow->empty_message); - e_reflow->empty_message = g_strdup(GTK_VALUE_STRING (*arg)); - if (GNOME_CANVAS_ITEM_REALIZED & GTK_OBJECT_FLAGS(o)) - set_empty(e_reflow); - } -} - -static void -e_reflow_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - EReflow *e_reflow; - - e_reflow = E_REFLOW (object); - - switch (arg_id) { - case ARG_MINIMUM_WIDTH: - GTK_VALUE_DOUBLE (*arg) = e_reflow->minimum_width; - break; - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = e_reflow->width; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = e_reflow->height; - break; - case ARG_EMPTY_MESSAGE: - GTK_VALUE_STRING (*arg) = g_strdup(e_reflow->empty_message); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -e_reflow_destroy (GtkObject *object) -{ - EReflow *reflow = E_REFLOW(object); - - g_list_foreach(reflow->items, (GFunc) gtk_object_unref, NULL); - g_list_free(reflow->items); - reflow->items = NULL; - - g_free(reflow->empty_message); - - GTK_OBJECT_CLASS(parent_class)->destroy (object); -} - -static void -e_reflow_realize (GnomeCanvasItem *item) -{ - EReflow *e_reflow; - GnomeCanvasGroup *group; - GList *list; - GtkAdjustment *adjustment; - - e_reflow = E_REFLOW (item); - group = GNOME_CANVAS_GROUP( item ); - - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) - (* GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) (item); - - e_reflow->arrow_cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW); - e_reflow->default_cursor = gdk_cursor_new (GDK_LEFT_PTR); - - for(list = e_reflow->items; list; list = g_list_next(list)) { - GnomeCanvasItem *item = GNOME_CANVAS_ITEM(list->data); - gnome_canvas_item_set(item, - "width", (double) e_reflow->column_width, - NULL); - } - - set_empty(e_reflow); - - e_canvas_item_request_reflow(item); - - adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas)); - adjustment->step_increment = (e_reflow->column_width + E_REFLOW_FULL_GUTTER) / 2; - adjustment->page_increment = adjustment->page_size - adjustment->step_increment; - gtk_adjustment_changed(adjustment); - - if (!item->canvas->aa) { - } -} - -static void -e_reflow_unrealize (GnomeCanvasItem *item) -{ - EReflow *e_reflow; - - e_reflow = E_REFLOW (item); - - if (!item->canvas->aa) - { - } - - gdk_cursor_destroy (e_reflow->arrow_cursor); - gdk_cursor_destroy (e_reflow->default_cursor); - e_reflow->arrow_cursor = NULL; - e_reflow->default_cursor = NULL; - - g_list_free (e_reflow->columns); - e_reflow->columns = NULL; - - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) - (* GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) (item); -} - -static gint -e_reflow_pick_line (EReflow *e_reflow, double x) -{ - x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH; - x /= e_reflow->column_width + E_REFLOW_FULL_GUTTER; - return x; -} - -static gboolean -e_reflow_event (GnomeCanvasItem *item, GdkEvent *event) -{ - EReflow *e_reflow; - - e_reflow = E_REFLOW (item); - - switch( event->type ) - { - case GDK_KEY_PRESS: - if (event->key.keyval == GDK_Tab || - event->key.keyval == GDK_KP_Tab || - event->key.keyval == GDK_ISO_Left_Tab) { - GList *list; - for (list = e_reflow->items; list; list = list->next) { - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data); - EFocus has_focus; - gtk_object_get(GTK_OBJECT(item), - "has_focus", &has_focus, - NULL); - if (has_focus) { - if (event->key.state & GDK_SHIFT_MASK) - list = list->prev; - else - list = list->next; - if (list) { - item = GNOME_CANVAS_ITEM(list->data); - gnome_canvas_item_set(item, - "has_focus", (event->key.state & GDK_SHIFT_MASK) ? E_FOCUS_END : E_FOCUS_START, - NULL); - return 1; - } else { - return 0; - } - } - } - } - break; - case GDK_BUTTON_PRESS: - switch(event->button.button) - { - case 1: - { - GdkEventButton *button = (GdkEventButton *) event; - double n_x, max_x; - n_x = button->x; - n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH; - n_x = fmod(n_x,(e_reflow->column_width + E_REFLOW_FULL_GUTTER)); - - max_x = E_REFLOW_BORDER_WIDTH; - max_x += (e_reflow->column_width + E_REFLOW_FULL_GUTTER) * e_reflow->column_count; - if ( button->y >= E_REFLOW_BORDER_WIDTH && button->y <= e_reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER && max_x > button->x ) { - e_reflow->which_column_dragged = e_reflow_pick_line(e_reflow, button->x); - e_reflow->start_x = e_reflow->which_column_dragged * (e_reflow->column_width + E_REFLOW_FULL_GUTTER) - E_REFLOW_DIVIDER_WIDTH / 2; - e_reflow->temp_column_width = e_reflow->column_width; - e_reflow->column_drag = TRUE; - - gnome_canvas_item_grab (item, - GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, - e_reflow->arrow_cursor, - button->time); - - e_reflow->previous_temp_column_width = -1; - e_reflow->need_column_resize = TRUE; - gnome_canvas_item_request_update(item); - return TRUE; - } - } - break; - case 4: - { - GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas)); - gdouble new_value = adjustment->value; - new_value -= adjustment->step_increment; - gtk_adjustment_set_value(adjustment, new_value); - } - break; - case 5: - { - GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas)); - gdouble new_value = adjustment->value; - new_value += adjustment->step_increment; - if ( new_value > adjustment->upper - adjustment->page_size ) - new_value = adjustment->upper - adjustment->page_size; - gtk_adjustment_set_value(adjustment, new_value); - } - break; - } - break; - case GDK_BUTTON_RELEASE: - if (e_reflow->column_drag) { - gdouble old_width = e_reflow->column_width; - GdkEventButton *button = (GdkEventButton *) event; - GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas)); - e_reflow->temp_column_width = e_reflow->column_width + - (button->x - e_reflow->start_x)/(e_reflow->which_column_dragged - e_reflow_pick_line(e_reflow, adjustment->value)); - if ( e_reflow->temp_column_width < 50 ) - e_reflow->temp_column_width = 50; - e_reflow->column_drag = FALSE; - if ( old_width != e_reflow->temp_column_width ) { - gtk_adjustment_set_value(adjustment, adjustment->value + e_reflow_pick_line(e_reflow, adjustment->value) * (e_reflow->temp_column_width - e_reflow->column_width)); - e_reflow->column_width = e_reflow->temp_column_width; - adjustment->step_increment = (e_reflow->column_width + E_REFLOW_FULL_GUTTER) / 2; - adjustment->page_increment = adjustment->page_size - adjustment->step_increment; - gtk_adjustment_changed(adjustment); - e_reflow_resize_children(item); - e_canvas_item_request_reflow(item); - } - e_reflow->need_column_resize = TRUE; - gnome_canvas_item_request_update(item); - gnome_canvas_item_ungrab (item, button->time); - return TRUE; - } - break; - case GDK_MOTION_NOTIFY: - if (e_reflow->column_drag) { - double old_width = e_reflow->temp_column_width; - GdkEventMotion *motion = (GdkEventMotion *) event; - GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas)); - e_reflow->temp_column_width = e_reflow->column_width + - (motion->x - e_reflow->start_x)/(e_reflow->which_column_dragged - e_reflow_pick_line(e_reflow, adjustment->value)); - if (e_reflow->temp_column_width < 50) - e_reflow->temp_column_width = 50; - if (old_width != e_reflow->temp_column_width) { - e_reflow->need_column_resize = TRUE; - gnome_canvas_item_request_update(item); - } - return TRUE; - } else { - GdkEventMotion *motion = (GdkEventMotion *) event; - double n_x, max_x; - - n_x = motion->x; - n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH; - n_x = fmod(n_x,(e_reflow->column_width + E_REFLOW_FULL_GUTTER)); - - max_x = E_REFLOW_BORDER_WIDTH; - max_x += (e_reflow->column_width + E_REFLOW_FULL_GUTTER) * e_reflow->column_count; - - if ( motion->y >= E_REFLOW_BORDER_WIDTH && motion->y <= e_reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER && max_x > motion->x) { - if ( e_reflow->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, e_reflow->arrow_cursor); - e_reflow->default_cursor_shown = FALSE; - } - } else - if ( ! e_reflow->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, e_reflow->default_cursor); - e_reflow->default_cursor_shown = TRUE; - } - - } - break; - case GDK_ENTER_NOTIFY: - if (!e_reflow->column_drag) { - GdkEventCrossing *crossing = (GdkEventCrossing *) event; - double n_x, max_x; - n_x = crossing->x; - n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH; - n_x = fmod(n_x,(e_reflow->column_width + E_REFLOW_FULL_GUTTER)); - - max_x = E_REFLOW_BORDER_WIDTH; - max_x += (e_reflow->column_width + E_REFLOW_FULL_GUTTER) * e_reflow->column_count; - if ( crossing->y >= E_REFLOW_BORDER_WIDTH && crossing->y <= e_reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER && max_x > crossing->x) { - if ( e_reflow->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, e_reflow->arrow_cursor); - e_reflow->default_cursor_shown = FALSE; - } - } - } - break; - case GDK_LEAVE_NOTIFY: - if (!e_reflow->column_drag) { - GdkEventCrossing *crossing = (GdkEventCrossing *) event; - double n_x; - n_x = crossing->x; - n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH; - n_x = fmod(n_x,(e_reflow->column_width + E_REFLOW_FULL_GUTTER)); - if ( !( crossing->y >= E_REFLOW_BORDER_WIDTH && crossing->y <= e_reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER ) ) { - if ( ! e_reflow->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, e_reflow->default_cursor); - e_reflow->default_cursor_shown = TRUE; - } - } - } - break; - default: - break; - } - - if (GNOME_CANVAS_ITEM_CLASS( parent_class )->event) - return (* GNOME_CANVAS_ITEM_CLASS( parent_class )->event) (item, event); - else - return 0; -} - -static void -e_reflow_real_add_item(EReflow *e_reflow, GnomeCanvasItem *item) -{ - e_reflow->items = g_list_append(e_reflow->items, item); - gtk_object_ref(GTK_OBJECT(item)); - if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) { - gnome_canvas_item_set(item, - "width", (double) e_reflow->column_width, - NULL); - e_reflow_post_add_item(e_reflow, item); - e_canvas_item_request_reflow(item); - } - -} - -static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable, - int x, int y, int width, int height) -{ - int x_rect, y_rect, width_rect, height_rect; - gdouble running_width; - EReflow *e_reflow = E_REFLOW(item); - int i; - double column_width; - - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->draw) - GNOME_CANVAS_ITEM_CLASS(parent_class)->draw (item, drawable, x, y, width, height); - column_width = e_reflow->column_width; - running_width = E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH; - x_rect = running_width; - y_rect = E_REFLOW_BORDER_WIDTH; - width_rect = E_REFLOW_DIVIDER_WIDTH; - height_rect = e_reflow->height - (E_REFLOW_BORDER_WIDTH * 2); - - /* Compute first column to draw. */ - i = x; - i /= column_width + E_REFLOW_FULL_GUTTER; - running_width += i * (column_width + E_REFLOW_FULL_GUTTER); - - for ( ; i < e_reflow->column_count; i++) { - if ( running_width > x + width ) - break; - x_rect = running_width; - gtk_paint_flat_box(GTK_WIDGET(item->canvas)->style, - drawable, - GTK_STATE_ACTIVE, - GTK_SHADOW_NONE, - NULL, - GTK_WIDGET(item->canvas), - "reflow", - x_rect - x, - y_rect - y, - width_rect, - height_rect); - running_width += E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH; - } - if (e_reflow->column_drag) { - int start_line = e_reflow_pick_line(e_reflow, - gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas))->value); - i = x - start_line * (column_width + E_REFLOW_FULL_GUTTER); - running_width = start_line * (column_width + E_REFLOW_FULL_GUTTER); - column_width = e_reflow->temp_column_width; - running_width -= start_line * (column_width + E_REFLOW_FULL_GUTTER); - i += start_line * (column_width + E_REFLOW_FULL_GUTTER); - running_width += E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH; - x_rect = running_width; - y_rect = E_REFLOW_BORDER_WIDTH; - width_rect = E_REFLOW_DIVIDER_WIDTH; - height_rect = e_reflow->height - (E_REFLOW_BORDER_WIDTH * 2); - - /* Compute first column to draw. */ - i /= column_width + E_REFLOW_FULL_GUTTER; - running_width += i * (column_width + E_REFLOW_FULL_GUTTER); - - for ( ; i < e_reflow->column_count; i++) { - if ( running_width > x + width ) - break; - x_rect = running_width; - gdk_draw_rectangle(drawable, - GTK_WIDGET(item->canvas)->style->fg_gc[GTK_STATE_NORMAL], - TRUE, - x_rect - x, - y_rect - y, - width_rect - 1, - height_rect - 1); - running_width += E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH; - } - } -} - -static void -e_reflow_update (GnomeCanvasItem *item, double affine[6], ArtSVP *clip_path, gint flags) -{ - EReflow *e_reflow; - double x0, x1, y0, y1; - - e_reflow = E_REFLOW (item); - - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->update) - GNOME_CANVAS_ITEM_CLASS(parent_class)->update (item, affine, clip_path, flags); - - x0 = item->x1; - y0 = item->y1; - x1 = item->x2; - y1 = item->y2; - if ( x1 < x0 + e_reflow->width ) - x1 = x0 + e_reflow->width; - if ( y1 < y0 + e_reflow->height ) - y1 = y0 + e_reflow->height; - item->x2 = x1; - item->y2 = y1; - - if (e_reflow->need_height_update) { - x0 = item->x1; - y0 = item->y1; - x1 = item->x2; - y1 = item->y2; - if ( x0 > 0 ) - x0 = 0; - if ( y0 > 0 ) - y0 = 0; - if ( x1 < E_REFLOW(item)->width ) - x1 = E_REFLOW(item)->width; - if ( x1 < E_REFLOW(item)->height ) - x1 = E_REFLOW(item)->height; - - gnome_canvas_request_redraw(item->canvas, x0, y0, x1, y1); - e_reflow->need_height_update = FALSE; - } else if (e_reflow->need_column_resize) { - int x_rect, y_rect, width_rect, height_rect; - int start_line = e_reflow_pick_line(e_reflow, - gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas))->value); - gdouble running_width; - int i; - double column_width; - - if ( e_reflow->previous_temp_column_width != -1 ) { - running_width = start_line * (e_reflow->column_width + E_REFLOW_FULL_GUTTER); - column_width = e_reflow->previous_temp_column_width; - running_width -= start_line * (column_width + E_REFLOW_FULL_GUTTER); - running_width += E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH; - y_rect = E_REFLOW_BORDER_WIDTH; - width_rect = E_REFLOW_DIVIDER_WIDTH; - height_rect = e_reflow->height - (E_REFLOW_BORDER_WIDTH * 2); - - for ( i = 0; i < e_reflow->column_count; i++) { - x_rect = running_width; - gnome_canvas_request_redraw(item->canvas, x_rect, y_rect, x_rect + width_rect, y_rect + height_rect); - running_width += E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH; - } - } - - if ( e_reflow->temp_column_width != -1 ) { - running_width = start_line * (e_reflow->column_width + E_REFLOW_FULL_GUTTER); - column_width = e_reflow->temp_column_width; - running_width -= start_line * (column_width + E_REFLOW_FULL_GUTTER); - running_width += E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH; - y_rect = E_REFLOW_BORDER_WIDTH; - width_rect = E_REFLOW_DIVIDER_WIDTH; - height_rect = e_reflow->height - (E_REFLOW_BORDER_WIDTH * 2); - - for ( i = 0; i < e_reflow->column_count; i++) { - x_rect = running_width; - gnome_canvas_request_redraw(item->canvas, x_rect, y_rect, x_rect + width_rect, y_rect + height_rect); - running_width += E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH; - } - } - - e_reflow->previous_temp_column_width = e_reflow->temp_column_width; - e_reflow->need_column_resize = FALSE; - } -} - -static void -e_reflow_resize_children (GnomeCanvasItem *item) -{ - GList *list; - EReflow *e_reflow; - - e_reflow = E_REFLOW (item); - for ( list = e_reflow->items; list; list = list->next ) { - GnomeCanvasItem *child = GNOME_CANVAS_ITEM(list->data); - gnome_canvas_item_set(child, - "width", (double) e_reflow->column_width, - NULL); - } -} - -static double -e_reflow_point (GnomeCanvasItem *item, - double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - double distance = 1; - - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->point) - distance = GNOME_CANVAS_ITEM_CLASS(parent_class)->point (item, x, y, cx, cy, actual_item); - if (*actual_item) - return 0; - - *actual_item = item; - return 0; -#if 0 - if (y >= E_REFLOW_BORDER_WIDTH && y <= e_reflow->height - E_REFLOW_BORDER_WIDTH) { - float n_x; - n_x = x; - n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH; - n_x = fmod(n_x, (e_reflow->column_width + E_REFLOW_FULL_GUTTER)); - if (n_x < E_REFLOW_FULL_GUTTER) { - *actual_item = item; - return 0; - } - } - return distance; -#endif -} - -static void -_reflow( EReflow *e_reflow ) -{ - gdouble running_height; - GList *list; - double item_height; - - if (e_reflow->columns) { - g_list_free (e_reflow->columns); - e_reflow->columns = NULL; - } - - e_reflow->column_count = 0; - - if (e_reflow->items == NULL) { - e_reflow->columns = NULL; - e_reflow->column_count = 0; - return; - } - - list = e_reflow->items; - - gtk_object_get (GTK_OBJECT(list->data), - "height", &item_height, - NULL); - running_height = E_REFLOW_BORDER_WIDTH + item_height + E_REFLOW_BORDER_WIDTH; - e_reflow->columns = g_list_append (e_reflow->columns, list); - e_reflow->column_count = 1; - - list = g_list_next(list); - - for ( ; list; list = g_list_next(list)) { - gtk_object_get (GTK_OBJECT(list->data), - "height", &item_height, - NULL); - if (running_height + item_height + E_REFLOW_BORDER_WIDTH > e_reflow->height) { - running_height = E_REFLOW_BORDER_WIDTH + item_height + E_REFLOW_BORDER_WIDTH; - e_reflow->columns = g_list_append (e_reflow->columns, list); - e_reflow->column_count ++; - } else { - running_height += item_height + E_REFLOW_BORDER_WIDTH; - } - } -} - -static void -set_empty(EReflow *e_reflow) -{ - if (e_reflow->items == NULL) { - if (e_reflow->empty_text) { - if (e_reflow->empty_message) { - gnome_canvas_item_set(e_reflow->empty_text, - "width", e_reflow->minimum_width, - "text", e_reflow->empty_message, - NULL); - e_canvas_item_move_absolute(e_reflow->empty_text, - e_reflow->minimum_width / 2, - 0); - } else { - gtk_object_destroy(GTK_OBJECT(e_reflow->empty_text)); - e_reflow->empty_text = NULL; - } - } else { - if (e_reflow->empty_message) - e_reflow->empty_text = - gnome_canvas_item_new(GNOME_CANVAS_GROUP(e_reflow), - e_text_get_type(), - "anchor", GTK_ANCHOR_N, - "width", e_reflow->minimum_width, - "clip", TRUE, - "use_ellipsis", TRUE, - "font_gdk", GTK_WIDGET(GNOME_CANVAS_ITEM(e_reflow)->canvas)->style->font, - "fill_color", "black", - "justification", GTK_JUSTIFY_CENTER, - "text", e_reflow->empty_message, - NULL); - e_canvas_item_move_absolute(e_reflow->empty_text, - e_reflow->minimum_width / 2, - 0); - } - } else { - if (e_reflow->empty_text) { - gtk_object_destroy(GTK_OBJECT(e_reflow->empty_text)); - e_reflow->empty_text = NULL; - } - } -} - -static void -e_reflow_reflow( GnomeCanvasItem *item, int flags ) -{ - EReflow *e_reflow = E_REFLOW(item); - if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) { - - gdouble old_width; - gdouble running_width; - - _reflow (e_reflow); - - old_width = e_reflow->width; - - running_width = E_REFLOW_BORDER_WIDTH; - - if (e_reflow->items == NULL) { - } else { - GList *list; - GList *next_column; - gdouble item_height; - gdouble running_height; - - running_height = E_REFLOW_BORDER_WIDTH; - - list = e_reflow->items; - gtk_object_get (GTK_OBJECT(list->data), - "height", &item_height, - NULL); - e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data), - (double) running_width, - (double) running_height); - running_height += item_height + E_REFLOW_BORDER_WIDTH; - next_column = g_list_next(e_reflow->columns); - list = g_list_next(list); - - for( ; list; list = g_list_next(list)) { - gtk_object_get (GTK_OBJECT(list->data), - "height", &item_height, - NULL); - - if (next_column && (next_column->data == list)) { - next_column = g_list_next (next_column); - running_height = E_REFLOW_BORDER_WIDTH; - running_width += e_reflow->column_width + E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH; - } - e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data), - (double) running_width, - (double) running_height); - - running_height += item_height + E_REFLOW_BORDER_WIDTH; - } - - } - e_reflow->width = running_width + e_reflow->column_width + E_REFLOW_BORDER_WIDTH; - if ( e_reflow->width < e_reflow->minimum_width ) - e_reflow->width = e_reflow->minimum_width; - if (old_width != e_reflow->width) - e_canvas_item_request_parent_reflow(item); - } -} - -void -e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item) -{ - if (E_REFLOW_CLASS(GTK_OBJECT(e_reflow)->klass)->add_item) - (E_REFLOW_CLASS(GTK_OBJECT(e_reflow)->klass)->add_item) (e_reflow, item); -} - -void -e_reflow_post_add_item(EReflow *e_reflow, GnomeCanvasItem *item) -{ - set_empty(e_reflow); -} diff --git a/widgets/e-reflow/e-reflow.h b/widgets/e-reflow/e-reflow.h deleted file mode 100644 index eb66b094a5..0000000000 --- a/widgets/e-reflow/e-reflow.h +++ /dev/null @@ -1,112 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-reflow.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef __E_REFLOW_H__ -#define __E_REFLOW_H__ - -#include <gnome.h> - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* EReflow - A canvas item container. - * - * The following arguments are available: - * - * name type read/write description - * -------------------------------------------------------------------------------- - * minimum_width double RW minimum width of the reflow. width >= minimum_width - * width double R width of the reflow - * height double RW height of the reflow - */ - -#define E_REFLOW_TYPE (e_reflow_get_type ()) -#define E_REFLOW(obj) (GTK_CHECK_CAST ((obj), E_REFLOW_TYPE, EReflow)) -#define E_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_REFLOW_TYPE, EReflowClass)) -#define E_IS_REFLOW(obj) (GTK_CHECK_TYPE ((obj), E_REFLOW_TYPE)) -#define E_IS_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_REFLOW_TYPE)) - - -typedef struct _EReflow EReflow; -typedef struct _EReflowClass EReflowClass; - -struct _EReflow -{ - GnomeCanvasGroup parent; - - /* item specific fields */ - GList *items; /* Of type GnomeCanvasItem */ - GList *columns; /* Of type GList of type GnomeCanvasItem (points into items) */ - gint column_count; /* Number of columnns */ - - GnomeCanvasItem *empty_text; - gchar *empty_message; - - double minimum_width; - double width; - double height; - - double column_width; - - int idle; - - /* These are all for when the column is being dragged. */ - gboolean column_drag; - gdouble start_x; - gint which_column_dragged; - double temp_column_width; - double previous_temp_column_width; - - guint need_height_update : 1; - guint need_column_resize : 1; - - guint default_cursor_shown : 1; - GdkCursor *arrow_cursor; - GdkCursor *default_cursor; -}; - -struct _EReflowClass -{ - GnomeCanvasGroupClass parent_class; - - /* Virtual methods. */ - void (* add_item) (EReflow *reflow, GnomeCanvasItem *item); -}; - -/* - * To be added to a reflow, an item must have the argument "width" as - * a Read/Write argument and "height" as a Read Only argument. It - * should also do an ECanvas parent reflow request if its size - * changes. - */ -void e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item); -GtkType e_reflow_get_type (void); - -/* Internal usage only: */ -void e_reflow_post_add_item(EReflow *e_reflow, GnomeCanvasItem *item); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_REFLOW_H__ */ diff --git a/widgets/e-table/.cvsignore b/widgets/e-table/.cvsignore deleted file mode 100644 index ecfa617948..0000000000 --- a/widgets/e-table/.cvsignore +++ /dev/null @@ -1,12 +0,0 @@ -.deps -.libs -.pure -Makefile -Makefile.in -*.lo -*.la -table-test -table-example-1 -table-example-2 -table-size-test -tree-example-1 diff --git a/widgets/e-table/ChangeLog b/widgets/e-table/ChangeLog deleted file mode 100644 index 9ff6fbfe97..0000000000 --- a/widgets/e-table/ChangeLog +++ /dev/null @@ -1,2508 +0,0 @@ -2000-08-22 Christopher James Lahey <clahey@helixcode.com> - - * e-cell-text.c, e-cell-toggle.c, e-cell-tree.c, e-table-item.c: - Moved drawing of the cell backgrounds from ECell into ETableItem. - - * e-tree-model.c: Include stdlib.c. - -2000-08-21 Lauris Kaplinski <lauris@helixcode.com> - - * e-cell-text.c: Changed UTF-8 syntax from char based to byte based - -2000-08-21 Chris Toshok <toshok@helixcode.com> - - * e-tree-example-1.c (remove_node): we can remove nodes with - children now. - - * e-tree-model.h: add prototype for e_tree_model_node_sort. - - * e-tree-model.c (etree_set_expanded): if the node is invisible, - just set its expanded flag and return. - (e_tree_model_root_node_set_visible): call set_expanded before we - remove it from the row array or else the aforementioned change - will result in nothing happening. - (e_tree_model_node_insert): use a position of -1 as "append". - (e_tree_model_node_insert): if the model was marked with - root_visible == FALSE, make sure to set it's expanded flag to TRUE - when the root node is inserted. - (e_tree_model_node_sort): new function. - -2000-08-21 Chris Toshok <toshok@helixcode.com> - - * e-table.c (e_table_drag_source_set): pass table, not site as the - closure for these drag signals, since e_table_drag_source_event_cb - assumes it's the table. - -2000-08-20 Christopher James Lahey <clahey@helixcode.com> - - * e-table-selection-model.c, e-table-selection-model.h: Added - e_table_selection_model_selected_count. - -2000-08-19 Lauris Kaplinski <lauris@helixcode.com> - - * e-cell-text.c: Use EFont wrapper - Use UTF-8 strings - -2000-08-19 Christopher James Lahey <clahey@helixcode.com> - - * e-cell-text.c: Made background colors alternate. - - * e-table-click-to-add.c: Made tabbing off the right edge of the - click to add commit the new values. - - * e-table-group-container.c, e-table-group-leaf.c, - e-table-group.c, e-table-group.h, e-table-sorted-variable.c, - e-table-subset-variable.c, e-table-subset-variable.h: Added a - decrement method. Made the add and remove methods not - automatically increment and decrement. - - * e-table-item.c: Fixed some view vs model issues for both rows - and columns. - - * e-table-model.c: Added debugging code. Removed automatic - signalling of changes by the ETableModel set_value_at function - (the model should send these signals itself.) - - * e-table.c: Added increment and decrement calls when a row is - removed or added from the source model. - -2000-08-09 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c, e-table-selection-model.c, - e-table-selection-model.h: Make right click select if the current - row is not selected. - -2000-08-08 Miguel de Icaza <miguel@helixcode.com> - - * e-table-header-item.c: Tag some strings for translation. - -2000-07-18 Miguel de Icaza <miguel@helixcode.com> - - * e-tree-model.c (etree_destroy): Call our parent's destroy - method. - -2000-08-09 Christopher James Lahey <clahey@helixcode.com> - - * e-table-header-item.c: Changed e_popup_menu_run call to match - the new arguments. - -2000-08-05 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c, e-table.h: Added functions to convert from view row - to model row or from model row to view row. Also changed - e_table_set_cursor_row and e_table_get_cursor_row to take a model - row as this works better with the rest of the model. Changed the - name of e_table_get_next_row_sorted and - e_table_get_prev_row_sorted. (Dropped the _sorted.) - -2000-08-05 Dan Winship <danw@helixcode.com> - - * e-table.c (e_table_get_{next,prev}_row_sorted): fix - -2000-08-05 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c: Added a function to get the next row with sorting - taken into account. - -2000-08-05 Christopher James Lahey <clahey@helixcode.com> - - * e-table-sorter.c: Made it so that selection ranges work even if - the table is using grouping. - -2000-08-05 Christopher James Lahey <clahey@helixcode.com> - - * Makefile.am, e-table-selection-model.c, - e-table-selection-model.h, e-table.c, e-table.h: Made selection - ranges work even if the table is sorted. - - * e-table-sorter.c, e-table-sorter.h: New files to help with - making selection ranges work even if sorted. - -2000-08-04 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c, e-table.h: Built code to have autodrags only work - from within the table and to report the row dragged from - automatically. - -2000-08-04 Christopher James Lahey <clahey@helixcode.com> - - * e-table-group-container.c, e-table-group-leaf.c, - e-table-group.c, e-table-group.h, e-table-item.c, e-table-item.h: - Made drag events calculate a row and column and signal that - information. - - * e-table-selection-model.c, e-table-selection-model.h: Changed - do_something to take a GdkModifierType. - -2000-08-02 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c, e-table-item.h: Add a handler for - "model_pre_change" and properly stop editing. - - * e-table-model.c, e-table-model.h: Added a "model_pre_change" - signal that gets sent before any row numbers are changed. - - * e-table-sorted-variable.c, e-table-subset-variable.c: Emit - "model_pre_change" signals as appropriate. - - * e-table-subset.c, e-table-subset.h: Proxy "model_pre_changed" - signals. - -2000-08-02 Christopher James Lahey <clahey@helixcode.com> - - * e-table-model.c, e-table-model.h: Changed the API for the - append_row function. Now accepts a model to copy data from - instead of returning a row number and leaving it up to ETableOne - to copy the data in. - - * e-table-one.c, e-table-one.h: Adapted to use new append_row API. - - * e-table-simple.c, e-table-simple.h, e-table-subset.c: Adapted to - supply new append_row API. - -2000-07-31 Christopher James Lahey <clahey@helixcode.com> - - * e-table-col.c, e-table-col.h: Added an argument to set a column - so that you can't sort by that column. - - * e-table-header-item.c: Obey the sortable column of ETableCol. - -2000-07-29 Christopher James Lahey <clahey@helixcode.com> - - * e-table-click-to-add.c: Made enter key destroy and recreate the - ETableItem. - - * e-table-item.c: Grab focus when person clicks even if cursor - isn't changing. - -2000-07-28 Dan Winship <danw@helixcode.com> - - * e-table-header.c (eth_destroy): Remove the idle handler before - destroying the data it operates on. - -2000-07-27 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c: Fixed up the table behavior so that it's not - always in an edit mode. - -2000-07-27 Christopher James Lahey <clahey@helixcode.com> - - * e-table-selection-model.c: Added a comment. - -2000-07-27 Christopher James Lahey <clahey@helixcode.com> - - * e-table-selection-model.c: Fixed shift click selections. - -2000-07-27 Christopher James Lahey <clahey@helixcode.com> - - * e-table-selection-model.c: Allocate correctly in the insert and - delete methods. - - * e-table-click-to-add.c: Removed the line that was causing this - to do bad things. - -2000-07-27 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c (eti_cursor_change): Grab focus properly. - - * e-table-item.c, e-table-click-to-add.c: Fixed ETableClickToAdd - to handle carriage return. This still doesn't quite work right. - -2000-07-27 Christopher James Lahey <clahey@helixcode.com> - - * e-table-click-to-add.c: Clear the selection model when - activating. - - * e-table-item.c: Fixed a bunch of model column vs. view column - issues. - - * e-table-selection-model.c: Set the cursor to -1, -1 and emi a - "cursor_changed" signal. - -2000-07-26 Christopher James Lahey <clahey@helixcode.com> - - * e-table-click-to-add.c: Fixed a reference. - - * e-table-selection-model.c, e-table-selection-model.h: Added a - clear function. - - * e-table.c, e-table.h: Made going from click to add to the main - table and back work better. - -2000-07-26 Christopher James Lahey <clahey@helixcode.com> - - * e-table-click-to-add.c, e-table-click-to-add.h: Added an - ETableSelectionModel so this won't crash. - -2000-07-26 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c: Fixed the model/view row confusion. - - * e-table-selection-model.c: Changed one expression to use a - #define properly. - -2000-07-26 Christopher James Lahey <clahey@helixcode.com> - - * e-table-group-container.c, e-table-group-container.h, - e-table-group-leaf.c, e-table-group-leaf.h: Added "table_selection_model" - argument. Removed foreach function and selection notification. - - * e-table-group.c, e-table-group.h: Removed foreach function and - selection notification. - - * e-table-header.c: Fixed header width calculation to include the - last column. - - * e-table-item.c, e-table-item.h: Fixed this to use the new - selection model. - - * e-table-scrolled.c, e-table-scrolled.h: Removed selection - notification. - - * e-table-selection-model.c, e-table-selection-model.h: Finished - notification signals and fixed a bunch of bit manipulations. - Implemented do_something method. - - * e-table.c, e-table.h: Create an ETableSelectionModel and use it - properly. - -2000-07-25 Christopher James Lahey <clahey@helixcode.com> - - * e-table-selection-model.c: Made foreach call the callback in top - to bottom order. - -2000-07-25 Christopher James Lahey <clahey@helixcode.com> - - * e-table-selection-model.c, e-table-selection-model.h: Replaced - get_selection_list with foreach. - - * e-table.h: Add a ETableSelectionModel. - -2000-07-25 Christopher James Lahey <clahey@helixcode.com> - - * Makefile.am: Added e-table-selection-model.c and - e-table-selection-model.h. - - * e-table-selection-model.c: Added the get_selection_list and - is_row_selected functions. Removed some unused code. - - * e-table-selection-model.h: Removed some unused code. - -2000-07-25 Christopher James Lahey <clahey@helixcode.com> - - * e-table-selection-model.c: Added comments to the bit field code. - - * e-table-selection-model.h: Made the selection data guint32s. - -2000-07-25 Christopher James Lahey <clahey@helixcode.com> - - * e-table-selection-model.c: More fixes. - -2000-07-25 Christopher James Lahey <clahey@helixcode.com> - - * e-table-selection-model.c: Fixed up the bit manipulation a bit - here. - -2000-07-25 Christopher James Lahey <clahey@helixcode.com> - - * e-table-selection-model.c, e-table-selection-model.h: New files - for doing a selection model. Not finished yet and thus not in - Makefile.am. - - * e-table.c, e-table.h: Renamed the new dnd signals so that they - won't conflict with the widget signals. - -2000-07-25 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c, e-table.h: Implemented some of the drag & drop code. - Drops all report as being on row 0, col 0. Also, automatic drags - don't set the row and column being dragged from. - -2000-07-23 Damon Chaplin <damon@helixcode.com> - - * e-cell-text.c: added a color_column where the color can be specified - as a string, e.g. "red" or "rgb:F/0/0". - - * e-cell-text.c (ect_leave_edit): don't call unbuild_current_cell() - since the CellEdit struct has been freed in ect_stop_editing() and so - has the text. - - * e-cell-text.c (unbuild_current_cell): set cell->text to NULL to make - sure we don't try to free it again. - -2000-07-21 Christopher James Lahey <clahey@helixcode.com> - - * e-table.h: Added some unused declarations for drag and drop - work. - -2000-07-14 Michael Meeks <michael@helixcode.com> - - * e-table-subset.c (etss_destroy): g_free things we g_malloc. - -2000-07-13 Christopher James Lahey <clahey@helixcode.com> - - * e-table-header-item.c: Changed the background color of the - header. - -2000-07-12 Christopher James Lahey <clahey@helixcode.com> - - * e-table-header-item.c: Made scroll wheel work properly in - header. - -2000-07-10 Ettore Perazzoli <ettore@helixcode.com> - - * e-table.c (set_scroll_adjustments): Be safe if @vadjustment is - NULL. - - * e-table-scrolled.c (e_table_scrolled_init): Set policy and - shadow type. - (e_table_scrolled_real_construct): Don't set the adjustments. - (e_table_scrolled_new): Create the widget with `gtk_widget_new()' - and pass hadjustment/vadjustment NULL values so that we get the - `GTK_OBJECT_CONSTRUCTED' approval. - -2000-07-10 Ettore Perazzoli <ettore@helixcode.com> - - * e-table-scrolled.h: s/GtkTable/EScrollFrameClass/. - -2000-07-09 Christopher James Lahey <clahey@helixcode.com> - - * Makefile.am: Add e-table-scrolled.c and e-table-scrolled.h. - - * e-table-item.c: Make sure that find_cell returns FALSE if the - item doesn't have any cells. - - * e-table-scrolled.c, e-table-scrolled.h: Added a widget to - contain an ETable and provide scrollbars (for ease of use.) - - * e-table.c, e-table.h: Make this support the scrollable interface - and not contain its own scrollbars. - -2000-07-09 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c (eti_event): Put back e_cell_event sometimes when - we're not editing. - -2000-07-09 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c: Set the dnd_code to something non-null for the - ETableHeaderItem. - -2000-07-09 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c: Set header canvas scroll region correctly. - -2000-07-09 Anders Carlsson <andersca@gnu.org> - - * e-table-header-item.c (ethi_drag_motion): Don't draw drop - marker when the layout won't be changed by the drop. - -2000-07-08 Ettore Perazzoli <ettore@helixcode.com> - - * e-table-item.c (eti_table_model_changed): Removed an unused - variable. - -2000-07-08 Dan Winship <danw@helixcode.com> - - * e-tree-model.c (e_tree_model_node_insert): When inserting a root - node, only call e_table_model_row_inserted if root_visible. - (e_tree_model_node_remove): Call e_table_model_row_deleted before - removing the row from the row_array, because the chain of signal - handlers will sometimes need that info. - -2000-07-08 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c (eti_event): Don't call e_cell_event if we're not - editing. - -2000-07-08 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c (eti_table_model_changed): Commented out some - unnecessary and buggy code. - -2000-07-06 Dan Winship <danw@helixcode.com> - - * e-tree-model.c (e_tree_model_node_remove): Make this work - recursively. - -2000-07-06 Chris Toshok <toshok@helixcode.com> - - * e-cell-tree.c (ect_draw): fix the conditions under which we draw - a horizontal line. - -2000-07-06 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c: Send GDK_BUTTON_RELEASE events to the ecell - associated with the cell (if it's the cursor.) - -2000-07-03 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c: Added a reflow_compare callback and did removal - if you do shift-click on a selected row that's not the cursor. - -2000-06-29 Christopher James Lahey <clahey@helixcode.com> - - * e-table-click-to-add.c: Made this appear a bit better. - - * e-table-defines.h: Cleaned this up a bit, added - ETableForeachFunc. - - * e-table-group-container.c, e-table-group-leaf.c, - e-table-group.c, e-table-group.h, e-table-item.c, e-table-item.h, - e-table.c, e-table.h: Changed e_table_select_row to - e_table_set_cursor_row. Changed e_table_get_selected_view_row to - e_table_get_cursor_row. Added e_table_selected_row_foreach. - - * e-table-header-item.c: Fixed some warnings. - - * e-table-sorted-variable.c: Removed some unneeded debugging print - statments. - - * e-tree-example-1.c: Changed e_table_get_selected_view_row to - e_table_get_cursor_row. - -2000-06-27 Christopher James Lahey <clahey@helixcode.com> - - * e-table-header-item.c: Added an unsort command. - - * e-table-item.c: leave_edit when you loose the cursor. - -2000-06-26 Christopher James Lahey <clahey@helixcode.com> - - * Makefile.am: Added e-table-click-to-add.c, - e-table-click-to-add.h, e-table-one.c, and e-table-one.h. - - * e-table-click-to-add.c, e-table-click-to-add.h: A new canvas - item that represents a single row that sometimes exists. It's for - adding new rows to your table. - - * e-table-example-1.c, e-table-example-2.c, e-table-size-test.c, - test-check.c, test-cols.c, test-table.c: Added value_to_string handlers. - - * e-table-group-container.c: Use value_to_string to make grouping - not crash for non string columns. Made some changes to work - properly in an ECanvasVbox. - - * e-table-group-leaf.c, e-table-item.c: Made some changes to work - properly in an ECanvasVbox. - - * e-table-model.c, e-table-model.h: Added append_row and - value_to_string methods. - - * e-table-one.c, e-table-one.h: Given a source ETableModel, this - provides a single row model that uses the initialize_value, - duplicate_value, free_value, and value_is_empty methods of the - original source to implement set_value and value_at (and proxies - most of the other methods.) This is used for ETableClickToAdd. - - * e-table-simple.c, e-table-simple.h: Added append_row and - value_to_string handlers. append_row uses a GtkArg instead of a - parameter to e_table_simple_new. - - * e-table-subset.c: Added append_row and value_to_string handlers. - - * e-table.c, e-table.h: Use a vbox containing an ETableClickToAdd - and an ETableItem instead of an ETableItem directly. Only show - the ETableClickToAdd if the top level of the xml SPEC has the - attribute click-to-add set to some non-zero integer. - (click-to-add="1"). Add a "click_to_add_message" argument. - - * e-tree-model.c: Add a commented out value_to_string handler. - -2000-06-23 Larry Ewing <lewing@helixcode.com> - - * e-cell-toggle.c (etog_draw): draw pixmaps with he right - background and selection colors. - -2000-06-23 Chris Toshok <toshok@helixcode.com> - - * e-tree-model.h, e-tree-model.c: add icon_at virtual function - - it was stupid to make the insert call take 2 pixbufs. the model - should give this information. - - * e-cell-tree.c: get rid of the opened/closed pixbuf stuff. call - e_tree_model_icon_of_node. - - * e-tree-example-1.c: add my_icon_at. - - * e-tree-simple.c (simple_icon_at): new function - (e_tree_simple_new): add icon_at parameter. - - * e-tree-simple.h: add SimpleIconAtFn. - -2000-06-23 Chris Toshok <toshok@helixcode.com> - - * e-tree-example-1.c (create_tree): use the expanded/unexpanded - pixbufs as node pixbufs for the first level of children, to test - the drawing. - - * e-tree-model.c (e_tree_model_node_get_closed_pixbuf): new function. - (e_tree_model_node_get_opened_pixbuf): same. - (e_tree_model_node_insert): add opened/closed pixbuf argument. - (e_tree_model_node_insert_before): same. - - * e-tree-model.h: add prototypes for opened/closed pixbuf - accessors, and add them to the e_tree_model_node_insert_* calls. - - * e-cell-tree.c (ect_draw): add opened/closed pixbuf drawing per node. - -2000-06-22 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c: Make the table not move around as you resize. - -2000-06-22 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c: Killed a warning. - -2000-06-22 Christopher James Lahey <clahey@helixcode.com> - - * e-table-group-container.c: Remove use of the "x" and "y" - arguments to EText. - - * e-table-item.c: Properly ref the source_model field. - - * test-check.c, test-cols.c, test-table.c: Remove use of the "x" - and "y" arguments to ETableHeaderItem. - -2000-06-21 Christopher James Lahey <clahey@helixcode.com> - - * e-table-field-chooser-dialog.c: Made the Close button work. - - * e-table-field-chooser.glade, e-table-field-chooser.glade.h: - Added a text description of this dialog. - -2000-06-21 Christopher James Lahey <clahey@helixcode.com> - - * e-table-header-item.c: Changed this to move the cell to the - nearest edge instead of to the left of the column it's over. - - * e-table-header.c: Made target_index equal to eti->col_count be a - valid parameter to e_table_header_move. - -2000-06-21 Christopher James Lahey <clahey@helixcode.com> - - * e-table-header.c: Made moving columns to the right work - properly. - -2000-06-20 Christopher James Lahey <clahey@helixcode.com> - - * e-table-group-leaf.c: Fix a minor warning. - - * e-table-item.c: Add to the selection if shift is held down. - Show cursor when changing sort (or if table changes majorly.) - -2000-06-20 Christopher James Lahey <clahey@helixcode.com> - - * e-table-defines.h: Fix HEADER_PADDING. - -2000-06-20 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c: Fix cursor column information. - -2000-06-20 Christopher James Lahey <clahey@helixcode.com> - - * e-table-group-container.c, e-table-group-leaf.c, - e-table-group.c, e-table-group.h: Removed the unfocus method since - that's handled by the canvas itself now. - - * e-table-item.c, e-table-item.h: Finished adapting ETableItem to - use the canvas selection/cursor system. Selection and cursor now - use row numbers associated with the source model instead of the - sorted model (if the model they are given is an ETableSubset.) - This has no effect on the interface, except that unfocus was - removed and e_table_item_focus was renamed to - e_table_item_set_cursor. - -2000-06-20 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c, e-table-item.h: Started adapting ETableItem to - use the canvas selection/cursor system. - -2000-06-17 Chris Toshok <toshok@helixcode.com> - - * e-tree-model.c (e_tree_model_node_insert): call - e_table_model_row_inserted instead of e_table_model_changed. - -2000-06-17 Christopher James Lahey <clahey@helixcode.com> - - * e-cell-text.c: Made cells with strikeout on have a line from the - left margin to the right margin, instead of just over the text. - -2000-06-16 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c, e-table.h: Moved the reflow signal handling into an - idle handler to fix a bug when resizing twice in succession. - -2000-06-15 Chris Toshok <toshok@helixcode.com> - - * e-cell-tree.c (ect_print): print the icon for the tree control. - -2000-06-14 Chris Toshok <toshok@helixcode.com> - - * e-tree-example-1.c (print_tree): new function, to generate - postscript so i can test tree printing. - (create_tree): add print button. - - * e-cell-tree.c (ect_print_height): implement function (in a - broken way for the time being, heh). - (ect_print): implement function to draw tree controls and offset - the subcell's printing. icons aren't printed yet, just lines. - (ect_draw): remove old unnecessary comments. only draw the - horizontal line in specific instances (well, add a test so a lone - root node doesn't get the horizontal line.) - (e_cell_tree_class_init): add print/print_height methods. - -2000-06-14 Christopher James Lahey <clahey@helixcode.com> - - * e-cell-text.c: Request the value of e_table_is_cell_editable of - the model_col instead of the view_col. - - * e-table-item.h: Slight style fixup. - -2000-06-13 Christopher James Lahey <clahey@helixcode.com> - - * e-cell-text.c: Clip the contained text. - - * e-table-group-container.c: Did a first pass at grouped - printing. This works, but there's no fancy boxes or headers - around the groups. - - * e-table-item.c: Added will_fit function and added quantize - function to _height. - -2000-06-12 Federico Mena Quintero <federico@helixcode.com> - - * e-table-model.[ch]: Removed the freeze/thaw stuff for the model. - As Chris wisely pointed out, having freeze/thaw on the model makes - its state inconsistent from the perspective of the views. - - * e-table-sorted-variable.c: Do not check for a frozen model. - * e-table-subset.c: Likewise. - * e-table-subset-variable.c: Likewise. - - * e-table-example-1.c: Removed the ETableModel thaw handler. - * e-table-example-2.c: Likewise. - * e-table-simple.c: Likewise. - * e-table-size-test.c: Likewise. - * test-check.c: Likewise. - * test-cols.c: Likewise. - * test-table.c: Likewise. - -2000-06-08 Federico Mena Quintero <federico@helixcode.com> - - * e-table-model.h (ETableModelClass): Added a freeze method. - - * e-table-model.c (e_table_model_freeze): Call the freeze method - instead of the thaw method! - - * e-table-simple.h (ETableSimple): Added the freeze function. - - * e-table-simple.c (simple_thaw): Check whether the function - exists. - (simple_freeze): New handler. - (e_table_simple_new): Take in and set the freeze handler. - (e_table_simple_class_init): Set the freeze handler. - - * test-check.c (check_test): Pass in the freeze handler to - e_table_simple_new(). - - * test-cols.c (multi_cols_test): Likewise. - - * e-table-example-2.c (create_table): Likewise. - - * e-table-example-1.c (create_table): Likewise. - - * test-table.c (table_browser_test): Likewise. - (do_e_table_demo): Likewise. - -2000-06-10 Chris Toshok <toshok@helixcode.com> - - * e-tree-example-1.c (create_tree): supply the pixbufs here. - - * e-cell-tree.h: change pixbuf names to open_pixbuf/closed_pixbuf. - - * e-cell-tree.c (e_cell_tree_construct): take open/closed pixbuf - parameters, and don't #include the .xpm files directly here. - (e_cell_tree_new): same. - (ect_draw): use the pixbufs from the ECellTree. - -2000-06-10 Chris Toshok <toshok@helixcode.com> - - * e-cell-tree.c (ect_event): offset events before passing them to - our subcell view. - -2000-06-10 Chris Toshok <toshok@helixcode.com> - - * e-table-item.c (eti_event): change things so we focus the cell - and select the row, and also dispatch the event to that row/cell. - This fixes the problem with the tree where you had to click twice - to activate the tree controls. - - * Makefile.am (libetable_a_SOURCES): remove e-tree-gnode.* and add - e-tree-simple.* - (icons): add tree-expanded.xpm and tree-unexpanded.xpm - - * e-cell-tree.c (ect_enter_edit): defer to subcell's view. - (ect_leave_edit): defer to subcell's view. - (visible_depth_of_node): visual depth, taking into account that - the root node of the model might not be displayed. - (offset_of_node): return the offset used to shift the subcell - over. - (ect_draw): don't draw vertical lines if we're the leftmode node - (a visual root node). also, don't shift x2 by the subcell offset, - so we get ellipses like we're supposed to. - (ect_event): remove GDK_BUTTON_RELEASE from the list of events - that we care about. - - * e-tree-example-1.c: lots of changes, a more dynamic UI so we can - test tree model api stuff. - - * e-tree-gnode.c, e-tree-gnode.c: removed files, since their guts - have been rolled into e-tree-model.c - - * e-tree-model.c, e-tree-model.h: substantially changed. too much - to really describe here. this should really be considered the - first revision of these files :) - - * e-tree-simple.c, e-tree-simple.h: analogous to e-table-simple, a - subclass that allows the use of function pointers. - -2000-06-11 Christopher James Lahey <clahey@helixcode.com> - - * e-table-model.c: Small syntactic changes. - - * e-table.c: Moved the table header into the scrolled view. - -2000-06-11 Ettore Perazzoli <ettore@helixcode.com> - - * Makefile.am (table_test_LDADD): Link with libemiscwidgets.a. - (table_size_test_LDADD): Likewise. - (table_example_1_LDADD): Likewise. - (table_example_2_LDADD): Likewise. - (tree_example_1_LDADD): Likewise. - -2000-06-10 Ettore Perazzoli <ettore@helixcode.com> - - * e-table.c (et_real_construct): EScrollFrame instead of - GtkScrolledWindow. - -2000-06-10 Christopher James Lahey <clahey@helixcode.com> - - * Makefile.am: Added $(GNOME_PRINT_LIBS) to all of the LDADDs. - - * e-cell-text.c: Added printing of text cells. - - * e-cell.c, e-cell.h: Added print and print_height methods. - - * e-table-field-chooser.glade: Added a minimum size. - - * e-table-group-container.c: Fixed a rectangle sizing bug. - - * e-table-group-leaf.c: Implemented get_printable. - - * e-table-group.c, e-table-group.h: Added a get_printable method - to return an EPrintable. - - * e-table-item.c, e-table-item.h: Added a get_printable function - to return an EPrintable. - - * e-table.c, e-table.h: Added a get_printable function to return - an EPrintable. - -2000-06-08 Chris Toshok <toshok@helixcode.com> - - * e-tree-gnode.c, e-tree-gnode.h: New files. A tree model using a - GNode structure to store it's info. - - * e-tree-model.c, e-tree-model.h: New files. A proxy model - sitting between a table model and the real tree model (of which - ETreeGNode is an example). - - * e-cell-tree.c, e-cell-tree.h: New files. A cell renderer - capable of wrapping up a subcell and drawing the tree controls for - expanding/collapsing trees. - - * tree-expanded.xpm, tree-unexpanded.xpm: New files. the standard - + and - icons. - - * e-tree-example-1.c: New file, giving a (pretty poor :) example - of using ETreeGNode. - - * Makefile.am: at the tree stuff to the build, and build - tree-example-1. - - * .cvsignore: ignore tree-example-1. - -2000-06-08 Christopher James Lahey <clahey@helixcode.com> - - * The field chooser works now. - - * e-table-field-chooser-dialog.c: Make the dialog resizable. - - * e-table-field-chooser-item.c: Requested a reflow on - realization. Made the correct column get dragged. - - * e-table-field-chooser.c: Set the height correctly. - - * e-table-field-chooser.glade: Replace the GnomeCanvas with an - ECanvas. - - * e-table-header-item.c: Receive drags from the new dialog. - -2000-06-08 Christopher James Lahey <clahey@helixcode.com> - - * e-table-field-chooser-dialog.c, e-table-field-chooser-dialog.h, - e-table-field-chooser-item.c, e-table-field-chooser.c, - e-table-field-chooser.glade, e-table-field-chooser.h, - e-table-header-item.c, e-table.c: More work on the Field Chooser. - Not quite done yet. - -2000-06-07 Christopher James Lahey <clahey@helixcode.com> - - * Makefile.am: Added e-table-field-chooser*. - - * e-table-defines.h: Moved some things to here. - - * e-table-field-chooser-dialog.c, e-table-field-chooser-dialog.h, - e-table-field-chooser-item.c, e-table-field-chooser-item.h, - e-table-field-chooser.c, e-table-field-chooser.glade, - e-table-field-chooser.glade.h, e-table-field-chooser.h: New dialog - to drag extra fields from. (Not yet finished.) - - * e-table-header-item.c, e-table-header-item.h: Changed to - accommodate e-table-field-chooser. - -2000-06-06 Christopher James Lahey <clahey@helixcode.com> - - * e-table-group-container.c, e-table-group-leaf.c, - e-table-group.c, e-table-group.h, e-table-item.c, e-table-item.h, - e-table.c, e-table.h: Added a right click signal. - - * e-table-sorted-variable.c: Fixed a buffer overrun. - -2000-06-02 Christopher James Lahey <clahey@helixcode.com> - - * e-table-sorted-variable.c: Fixed the multiple copies of rows in - ETable bug. - -2000-06-01 Dan Winship <danw@helixcode.com> - - * e-table-group.c (e_table_group_key_press): - * e-table.c (group_key_press): two more pastos - -2000-06-01 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c: Copy and paste error. - - * e-table-item.c: Mixed up parity on eti->editing. - -2000-06-01 Christopher James Lahey <clahey@helixcode.com> - - * e-table-group-container.c, e-table-group-leaf.c, - e-table-group.c, e-table-group.h, e-table-item.c, e-table-item.h, - e-table.c, e-table.h: Added a "key_press" signal. - -2000-06-01 Dan Winship <danw@helixcode.com> - - * e-cell-text.h: Remove an offending *. - -2000-06-01 Christopher James Lahey <clahey@helixcode.com> - - * e-table-sorted-variable.c: Made the sort when inserting a signal - row be syncronous. - -2000-06-01 Christopher James Lahey <clahey@helixcode.com> - - * e-cell-text.c, e-cell-text.h: Added "text_filter" argument that - takes a const void * and returns an allocated char *. - -2000-06-01 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c: Copy and paste error. - -2000-06-01 Christopher James Lahey <clahey@helixcode.com> - - * e-table-group-container.c, e-table-group-leaf.c, - e-table-group.c, e-table-group.h, e-table-item.c, e-table.c, - e-table.h: Added e_table_get_selected_view_row. - -2000-05-30 Christopher James Lahey <clahey@helixcode.com> - - * e-cell-text.c, e-cell-text.h: Added bold column's to ECellText. - -2000-05-30 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c: Make sure that the cursor is always shown when - the selection changes. - -2000-05-30 Christopher James Lahey <clahey@helixcode.com> - - * e-table-group-container.c, e-table-group-container.h, - e-table-group-leaf.c, e-table-group-leaf.h, e-table-group.c, - e-table-group.h, e-table-item.c, e-table-item.h, e-table.c, - e-table.h, test-check.c, test-cols.c, test-table.c: Fixed a bunch - of selection bugs. Removed "spreadsheet" argument (for now.) - Added "cursor_mode" argument. Added "cursor_change" signal. - Temporarily removed "selection_mode" argument. - -2000-05-28 Christopher James Lahey <clahey@helixcode.com> - - * e-table-group-container.c: Fixed setting of arguments. - -2000-05-28 Christopher James Lahey <clahey@helixcode.com> - - * e-table-group-container.c, e-table-group-leaf.c, - e-table-group.c, e-table-group.h, e-table-item.c, e-table-item.h, - e-table.c, e-table.h: Added double click handling. - -2000-05-26 Christopher James Lahey <clahey@helixcode.com> - - * e-cell-text.c, e-cell-text.h: Added "strikeout_column" argument. - -2000-05-26 Christopher James Lahey <clahey@helixcode.com> - - * e-table-group-container.c, e-table-group-container.h, - e-table-group-leaf.c, e-table-group-leaf.h, e-table.c, e-table.h: - Made "drawgrid", "drawfocus", "spreadsheet", and - "length_threshold" arguments set from the ETable effect all the - end ETableItems. - - * e-table-header.c: Made column resize a bit less bumpy. - -2000-05-25 Christopher James Lahey <clahey@helixcode.com> - - * e-table-header.c: Account for extra pixel at right end of - ETable. - - * e-table-item.c: Make grid less intrusive. - - * e-table.c: Make scrollbars disappear when appropriate. - -2000-05-25 Christopher James Lahey <clahey@helixcode.com> - - * e-table-header-item.c: Made dragging columns work. - -2000-05-23 Christopher James Lahey <clahey@helixcode.com> - - * e-table-header-item.c: Fixed the remove column callback. - -2000-05-23 Christopher James Lahey <clahey@helixcode.com> - - * e-table-header-item.c: Added right click menus to the table - header items. - - * e-table-sort-info.c: Fixed a small bug. - -2000-05-23 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c: Make scrollbar arrow buttons work. - -2000-05-19 Christopher James Lahey <clahey@helixcode.com> - - * e-table-example-1.c, e-table-example-2.c, e-table-simple.c, - e-table-simple.h, e-table-size-test.c, test-check.c, test-cols.c, - test-table.c: Added initialize_value and value_is_empty callbacks. - - * e-table-model.c, e-table-model.h: Added initialize_value and - value_is_callback virtual functions to the ETableModel class. - - * e-table-subset.c: Perpetuate the initialize_value and - value_is_empty methods. - -From a patch by Iain Holmes <ih@csd.abdn.ac.uk> - - * e-table-config.c, e-table.c: Fixed getting text content from a - node in the case of a non string based content field in the xml - library. - -2000-05-16 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c: Fixed a memory leak. - -2000-05-16 Christopher James Lahey <clahey@helixcode.com> - - * e-table-sorted-variable.c: Changed sorting to be at priority - level 30. - - * e-table.c: Changed rebuild of the table to be at priority level - 20. This gives it an advantage over pretty much everything, - including e-table-sorted-variable sorting and canvas redraw. - -2000-05-16 Christopher James Lahey <clahey@helixcode.com> - - * e-table-group-container.c: Removed a memory leak here. - - * e-table-group-leaf.c: Added a ref/sink pair. - - * e-table-group.c, e-table-header-item.c: Removed some unused - code. - -2000-05-16 Christopher James Lahey <clahey@helixcode.com> - - * e-table-sorted-variable.c: Fixed a FIXME comment. - - * e-table-header.c, e-table-header.h: Added code to put off size - calculation to the idle loop. Added code to not resize columns - with 0 expansion. Removed the set_width function; it's been - replaced with a Gtk+ arg. - - * Makefile.am: Added e-table-defines.h to the Makefile.am. - - * e-table-defines.h: A new file containing some #defines for use - in ETable. - -2000-05-14 Christopher James Lahey <clahey@helixcode.com> - - * Implemented the feature where the ETable columns automatically - fill the given space. - - * e-cell-text.c, e-cell-text.h: Moved #include - e-text-event-processor.h from the .h to the .c. - - * e-table-col.c, e-table-col.h: Added an expansion variable, and - made it so that width isn't set by the programmer but instead by - the e-table-header. - - * e-table-example-1.c, e-table-example-2.c, e-table-size-test.c, - test-check.c, test-cols.c, test-table.c: Fixed to handle new - ETable column resizing. - - * e-table-group-container.c, e-table-group-container.h, - e-table-group-leaf.c, e-table-group-leaf.h, e-table-group.c, - e-table-group.h, e-table-item.c, e-table-item.h: Fixed these to do - a proper canvas reflow/update loop. Changed them to take a - minimum width and return a width and a height. - - * e-table-header-item.c, e-table-header-item.h: Made this so that - it depends on e-table-header.c for deciding the actual size of - columns during resize (it was making incorrect decisions on its - own.) - - * e-table-header.c, e-table-header.h: Changed this to make sure - that the sum of the widths of the columns was always as close as - possible to the width of the window. This is done by taking a - full width and having each of the columns have an "expansion" - field. This field is what makes each column have approximately - the same portion of its part of the screen that it used to. - - * e-table.c: Changed this to set the width on the ETableHeader as - well as set the proper minimum width on the ETableGroup and get - the width and height it reports. - -2000-05-11 Miguel de Icaza <miguel@gnu.org> - - * e-table.c: Removed dead code. - -2000-04-14 Miguel de Icaza <miguel@gnu.org> - - * e-table-header-item.c (ethi_class_init): New signal action. - -2000-05-10 Christopher James Lahey <clahey@helixcode.com> - - * Makefile.am: Added e-table-col-dnd.h and table-test.h. - -2000-05-09 Christopher James Lahey <clahey@helixcode.com> - - * e-table-subset-variable.c: Fixed etssv_remove. - -2000-05-08 Christopher James Lahey <clahey@helixcode.com> - - * e-cell-text.c: Make multi-line texts display properly. Fixed - some mem leaks. - -2000-05-07 <toshok@the-dot-in.helixcode.com> - - * e-cell-text.c (ect_draw): free cell.starting_text here to avoid - a memory leak. - -2000-05-07 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c: Add a horizontal scrollbar. - -2000-05-07 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c, e-table-item.h, e-table.c, e-table.h: Handle - row_inserted and row_deleted signals properly. - - * e-table-model.c, e-table-model.h: Created the row_inserted and - row_deleted signals. - - * e-table-sorted-variable.c, e-table-subset-variable.c: Emit the - row_inserted and row_deleted signals as appropriate. - -2000-05-06 Chris Toshok <toshok@helixcode.com> - - * e-cell-text.c (ect_accept_edits): only to set_value_at if the - value is indeed different. - (ect_stop_editing): free edit->cell.starting_text - (build_current_cell): initialize edit->cell.starting_text as a - copy of the initial text. - -2000-05-06 Christopher James Lahey <clahey@helixcode.com> - - * e-table-group-container.c, e-table.c: Killed some warnings. - -2000-05-04 Chris Toshok <toshok@helixcode.com> - - * e-table-sorted-variable.c (etsv_sort): use rows here instead of - E_TABLE_SUBSET(etsv)->n_map, since the table can be populated by - the gtk_main_iteration above. otherwise the vals_closure may not - be fully populated. - -2000-05-04 Christopher James Lahey <clahey@helixcode.com> - - * e-table-group-container.c, e-table-group-leaf.c, - e-table-group.c, e-table-group.h: Add an e_table_group_add_all - function and implement it in the different ETableGroup classes. - - * e-table-sort-info.c: Make set_nth not call changed twice if it - needs to allocate more space. - - * e-table-sorted-variable.c, e-table-subset-variable.c, - e-table-subset-variable.h: Add and implement an - e_table_subset_variable_add_all command. - - * e-table.c: Use e_table_group_add_all as appropriate. Fix ETable - grouping xml to work if there is a text element at the bottom of - the grouping tree. - -2000-05-04 Christopher James Lahey <clahey@helixcode.com> - - * e-cell-text.c: Sped up e_cell_text's get_height function. - -2000-05-04 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c, e-table-item.h: Added a height_cache idle loop - so that the height_cache will be validated in the idle loop. - -2000-05-04 Christopher James Lahey <clahey@helixcode.com> - - * e-table-sorted-variable.c: Load all the data to be sorted by - before actually doing the sort. - -2000-05-04 Christopher James Lahey <clahey@helixcode.com> - - * e-cell-text.c, e-cell-text.h: Fix author information. - - * e-table-group-leaf.c: Set a length threshold of 200. - - * e-table-item.c: Height cache is now actually a map. Made - "length_threshold" argument work. If over the length threshold, - use the height cache to get a better estimate so that once the - height cache is full, height estimate is perfect. - -2000-05-04 Christopher James Lahey <clahey@helixcode.com> - - * e-table-sorted-variable.c (qsort_callback): Add back in main - loop calls during sorting. - -2000-05-04 Christopher James Lahey <clahey@helixcode.com> - - * e-table-sorted-variable.c: Replace insert sort completely with a - qsort. - -2000-05-04 Christopher James Lahey <clahey@helixcode.com> - - * e-table-sorted-variable.c: Changed the insert sort to be binary - instead of linear. - -2000-05-02 Matt Loper <matt@helixcode.com> - - * Makefile.am: set G_LOG_DOMAIN. - -2000-04-30 Christopher James Lahey <clahey@helixcode.com> - - * e-table-header-item.c: Made this more reentrant. - - * e-table-sorted-variable.c, e-table-sorted-variable.h: Does a - proper resort when the sorting info changes. - - * e-table.c, e-table.h: Made it so that ETable doesn't destroy and - recreate the entire table when sorting info changes. - -2000-04-27 Christopher James Lahey <clahey@helixcode.com> - - * arrow-down.xpm, arrow-up.xpm, e-cell-text.c, e-cell-toggle.c, - e-table-col.c, e-table-config.c, e-table-header-item.c: Fixed some - warnings. - -2000-04-26 Christopher James Lahey <clahey@helixcode.com> - - * e-table-header-item.c: Added a missing include. - -2000-04-24 Miguel de Icaza <miguel@helixcode.com> - - * e-table.c (e_table_class_init): Add argument handling here. - - * e-table-group-leaf.c (e_table_group_apply_to_leafs): New method. - Enables us to walk all the children of an ETableGroup. - - * e-table.c (et_get_arg, et_set_arg): Implement ::get and ::set - methods. - (e_table_construct_from_spec_file): Now we return the etable. - (e_table_construct): ditto. - (et_real_construct): Now we return the ETable. Returns NULL on - construct failure. - (e_table_new): ditto. - (e_table_new_from_spec_file): ditto. - - * (et_build_grouping_spec): Removed vestige code that still - contained references to the etable->specification XML code. - - Dumped all the ifdefed out code. - - * e-table.h: Removed ETable->specification finally. - -2000-04-25 Christopher James Lahey <clahey@helixcode.com> - - * e-table-size-test.c: Fixed a warning. - - * e-table-item.c: Removed the unnecessary gnome_canvas_update_bbox. - -2000-04-24 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c: Fixed some warnings. - -2000-04-23 Iain Holmes <ih@csd.abdn.ac.uk> - - * e-table-item.c (eti_bounds): Calculate the width of the table from the - width of all the columns, and update the eti->width field as appropiate. - (eti_update): Update the bbox. - -2000-04-17 Chris Toshok <toshok@helixcode.com> - - * Makefile.am (noinst_PROGRAMS): add table-size-test - - * .cvsignore: add table-size-test. - - * e-cell-text.c (ect_ecent): use e_table_model_is_cell_editable - instead of E_CELL_EDITABLE. - - * e-cell-toggle.c (etog_event): same. - - * e-cell.c (e_cell_init): don't call e_cell_set_editable. that - info comes from the model. - (e_cell_set_editable): removed function. - - * e-cell.h: remove the E_CELL_EDITABLE flag. that should be - retrieved from the model. also, remove the prototype for - e_cell_set_editable. - - * e-table-size-test.c: new file, for a stress test of sorts, of a - large, uneditable e-table. - -2000-04-16 Anders Carlsson <andersca@gnu.org> - - * e-table-item.c (eti_event): Propagate mouse wheel events upwards. - - * e-table.c (et_real_construct): Use a GtkScrolledWindow here - instead of a GtkScrollbar, since it makes mouse wheel scrolling - much easier. - -2000-04-15 Matt Loper <matt@helixcode.com> - - * e-table.c (et_xml_to_header): sanity-check our parameters. - (et_grouping_xml_to_sort_info): same. - (et_real_construct): Bail if we couldn't get the children we - wanted. - -2000-04-14 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c, e-table-item.h: Added a row height cache. - -2000-04-15 Ettore Perazzoli <ettore@helixcode.com> - - * e-table.c (e_table_construct): Use `strlen (copy)' instead of - `strlen (copy) + 1' as the size argument for `xmlParseMemory()'. - -2000-04-14 Miguel de Icaza <miguel@gnu.org> - - * e-table.c, e-table.h: Switch the parent object to be a GtkTable. - (et_real_construct): apply massaging and some loving action to - make the thing behave as a GtkTable. - (e_table_init): More love. - -2000-04-12 Miguel de Icaza <miguel@gnu.org> - - * e-table-header-item.c (ethi_drag_motion): Remove test for - source. We will fix this later. - - (ethi_end_resize): Reset resize_guide here. - -2000-04-11 Miguel de Icaza <miguel@helixcode.com> - - * e-table-header-item.c (ethi_add_destroy_marker): Add group - indent width here. - (is_pointer_on_division): Use the group indent here, so the - resize pointer is shown at the correct time. - (TOLERANCE): Bump it up to 3 - (draw_button): Do not paint an arrow if there is an icon present, - and not enough space to paint. - -2000-04-10 Miguel de Icaza <miguel@helixcode.com> - - * e-table-header-item.c (make_shapped_window_from_xpm): New - routine, creates a shapped mask window from an xpm buffer. - (ethi_add_drop_marker): New version, uses shaped windows instead - of canvas items to signal the drop location. - (ethi_maybe_start_drag): Disable dragging if there is only one - column left. - -2000-04-10 Miguel de Icaza <miguel@gnu.org> - - * e-table-header-item.c (ethi_drag_motion): Drop frozen count - support from here. - (ethi_start_drag): ditto. - - * e-table-header.h: Kill frozen_count. - -2000-04-09 Matt Loper <matt@helixcode.com> - - * e-table-col.c (e_table_col_new_with_pixbuf): ref etc->ecell, - like in e_table_col_new, since that same ECell is unref'd in - etc_destroy(). - -2000-04-08 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c: Separated some functions into an xml bit and a - generic bit. - -2000-04-06 Christopher James Lahey <clahey@helixcode.com> - - * test-cols.c, test-table.c: Got rid of some warnings. - - * e-table-group-container.c, e-table-group-container.h, - e-table-group-leaf.c, e-table-group-leaf.h, e-table-group.c, - e-table-group.h, e-table-header-item.c, e-table-header-item.h, - e-table-sort-info.c, e-table-sort-info.h, - e-table-sorted-variable.c, e-table-sorted-variable.h, e-table.c, - e-table.h: Changed ETableSortInfo to not use xml internally. - -2000-04-06 Miguel de Icaza <miguel@gnu.org> - - * e-cell-text.c: Killed ARG_EDITABLE. - (ect_event): Updated to new editable setup. - (e_cell_text_new): Kill editable argument. - - * e-cell-toggle.c (etog_event): Handle editability here - - * e-cell-text.h: Removed editable bit field from here, it is now - taken care at the e-cell level. - - * e-cell.c (e_cell_set_editable): New function. - (e_cell_init): Set editable to TRUE by default. - - * test-check.c (check_test): update to new api - - * test-table.c (table_browser_test): ditto. - (do_e_table_demo): ditto. - - * test-cols.c (multi_cols_test): ditto - -2000-04-02 Miguel de Icaza <miguel@gnu.org> - - * e-table-sort-info.c (e_table_sort_info_class_init): Kill - argument. Do not use XML internally - (e_table_sort_info_set_sorting): New function, use this to set the - sorting. - (e_table_sort_info_set_grouping): This one to do the grouping/. - -2000-04-01 Miguel de Icaza <miguel@gnu.org> - - * e-table.c (e_table_build_column_spec): Drop frozen support. - (e_table_make_header): Drop frozen support. - - * e-table-header.c (e_table_header_new): Drop frozen support. - - * e-table-header-item.c (ethi_drag_motion): Drop frozen support. - (ethi_drag_drop): Drop frozen support. - (ethi_start_drag): Drop frozen support. - - * e-table.c (e_table_construct_from_spec_file): Robustify: support - the case in which the XML could not be parsed; Propagate errors. - (e_table_new): Handle failure. - (e_table_new_from_spec_file): ditto. - Renamed multiple internal functions whose prefix was et_ to be e_table_ - -2000-03-31 Miguel de Icaza <miguel@gnu.org> - - * e-table-simple.h: Constify this. - -2000-04-04 Christopher James Lahey <clahey@helixcode.com> - - * e-table-text-model.c: Make this assert a bit more readable. - - * e-table-item.c: Fix update loop behavior. - -2000-03-30 Miguel de Icaza <miguel@gnu.org> - - * Makefile.am (EXTRA_DIST): Added Glade files to the - distribution. - -2000-03-28 Matt Loper <matt@helixcode.com> - - * e-table-text-model.c (e_table_text_model_destroy): made - assertion more accurate. - -2000-03-27 Michael Meeks <michael@helixcode.com> - - * e-table-item.c (eti_update): try and fix the convoluted logic. - (eti_bounds): Implement; should fix the re-draw bugs. - - * e-table-group-container.c: kill many redundant prototypes, - stylistic cleans. - -2000-03-26 Matias Mutchinick <matias@seul.org> - - * e-cell-toggle.c (etog_draw): Removed extra code that computed - bogus width. This was the actual source of the problem with the - miss-rendering feature. - -2000-03-26 Miguel de Icaza <miguel@gnu.org> - - * e-table-header-item.c (ethi_realize): Remove warning from here. - - * test-table.c (table_browser_test): Use ECanvas, not GnomeCanvas, - to support reflow. - * test-cols.c (multi_cols_test): ditto - * e-table.c (e_table_setup_header): ditto - - * e-table-header-item.c (ethi_font_load): Replace font. - (ethi_realize): ditto. - -2000-03-22 Matt Loper <matt@helixcode.com> - - * e-table-text-model.c (e_table_text_model_destroy): Added some - assertions. - -2000-03-21 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c: Make rectangles resize properly when receiving the - "model_changed" signal. - -2000-03-20 Christopher James Lahey <clahey@helixcode.com> - - * e-table-group-container.c, e-table-group-container.h, - e-table-group-leaf.c, e-table-group.c, e-table-group.h: Updated - these to use the new ECanvas reflow infrastructure. - - * e-table-item.c, e-table-item.h: Updated these to use the new - ECanvas reflow infrastructure. Fixed the bounding box. - - * e-table.c, e-table.h: Made the header have no extra space around it. - -2000-03-19 Christopher James Lahey <clahey@helixcode.com> - - * e-table-header.c: Fixed a crashing bug when you close an - ETable. - -2000-03-13 Christopher James Lahey <clahey@helixcode.com> - - * e-cell-text.c: Fixed a crashing bug when you cancel an edit. - -2000-03-12 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c: Made this use an ECanvas. Fixed a bug where - e_table_new_from_spec_file was calling e_table_construct instead - of e_table_construct_from_spec_file. - - * e-table-item.c, e-table-header-item.c, e-table-column-item.c: - Switched these to use GTK_TYPE_OBJECT and GTK_VALUE_OBJECT instead - of GTK_TYPE_POINTER and GTK_TYPE_OBJECT. - - * e-cell-text.c: Got rid of a crashing bug. - - * e-table-text-model.c, e-table-text-model.h: A new object which - is an e-text-model which uses an e-table-model for its data. - - * Makefile.am: Added e-table-text-model.c and - e-table-text-model.h. - - * .cvsignore: Added table-example-1 and table-example-2. - -2000-03-08 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c: Changed the destroy function to disconnect from - signals before unrefing the objects the sinnals are on. Changed - the destroy function to match the objects and signal ids properly - in its disconnect section. - - * e-table-item.c, e-table-item.h: Changed this to do follow the - canvas rules better. - - * e-table-header-item.c, e-table-header-item.h: Made - ETableHeaderItem connect to the "sort_info_changed" on its - ETableSortInfo instead of just manually redrawing itself. Fixed - the update function a bit to follow the canvas rules a bit better. - -2000-03-06 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c: Made rows get unselected when switching from one - group to the next. - -2000-03-06 Christopher James Lahey <clahey@helixcode.com> - - * e-table-group-container.c: Use the style's font if lucidasans-10 - is not found. - -2000-03-06 Christopher James Lahey <clahey@helixcode.com> - - * e-table-header-item.c, e-table-header-item.h: Made it so that - columns would be properly indented. - -2000-03-06 Christopher James Lahey <clahey@helixcode.com> - - * e-table-sorted-variable.c: Have identical values get sorted by - their actual row. - -2000-03-06 Christopher James Lahey <clahey@helixcode.com> - - * e-cell-text.c: Draw selected row. - -2000-03-06 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c, e-table.h: Add a "row_selection" signal. - - * test-table.c: Test the new "row_selection" signal. - - * e-table-group-container.c, e-table-group-leaf.c: Implement the - "row_selection" property properly. - - * e-table-group.c, e-table-group.h: Add a "row_selection" signal. - -2000-03-05 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c, e-table.h: Added support for the sorting info. The - Etable creates a sort_info object, and then connects to the - signals to rearrange the rows when the sort_info changes. It also - passes the info object to the ETableHeaderItem. - - * e-table-model.c: Fixed a typo where ETableModel was written as - ETableModle. - - * e-table-header.c, e-table-header.h: Added some code for sorting - here, but it's not used. I don't think we want this code, but I - wanted to check it in at least once so that it's not lost. - - * e-table-header-item.c, e-table-header-item.h: Added a - "sort_info" argument to ETableHeaderItem. Added display of - current sort settings. Added support for clicking to change the - sort settings. - - * e-table-col.h: E_TABLE_COL_ARROW_NONE is marked as being = 0 - since this is required in other places. (I think C defines this - as being the case, but it's good to have the = 0 there so that - it's obvious that it has to be first.) - - * TODO: Mark sorting as done. - - * e-table-sort-info.c, e-table-sort-info.h: New files for - containing the xml grouping/sorting information and for sending - signals on that information. - - * Makefile.am: Added e-table-sort-info.c and e-table-sort-info.h. - -2000-03-04 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c: Added saving of frozen_columns count. Added a - vertical scrollbar to ETable. - -2000-03-04 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c: Push the proper visual and colormap for ETable to work. - -2000-03-04 Christopher James Lahey <clahey@helixcode.com> - - * TODO: Touched this up a bit. - - * e-table-group.c, e-table-group-leaf.c: Check for NULL before - calling gtk_object_unref or gtk_object_destroy. - -2000-03-04 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c: Fixed a crash error. - -2000-03-04 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c: Fixed a compile warning. - - * e-table.c: Fixed a crash error. - -2000-03-04 Christopher James Lahey <clahey@helixcode.com> - - * TODO: Added a bunch of stuff to the TODO list. Put +s before a - few of the items that are finished. - - * test-table.c: Add a button to save the spec file. - - * e-table.c, e-table.h: Add loading configurations from files as - well as the ability to get the current configuration out of the - widget. - -2000-03-03 Christopher James Lahey <clahey@helixcode.com> - - * e-table.c: Removed some unused code. - - * e-table-header-item.c, e-table-header-item.h: Removed the unused - normal_cursor variable and object. - - * e-table-col.c: Maintain a reference count in the contained ECell. - -2000-03-01 Ettore Perazzoli <ettore@helixcode.com> - - * Makefile.am: Use `libeutil.la', not `libeutil.a'. - -2000-02-29 Christopher James Lahey <clahey@helixcode.com> - - * test-table.c: Test frozen columns - - * e-table.c: Make frozen columns available through the xml file. - - * e-table-header.c, e-table-header.h, e-table-header-item.c: Added - frozen columns API to let you specify some number of leading - columns as undraggable. - - * Makefile.am: Add e-table-example-1.c and e-table-example-2.c. - - * e-table-example-1.c, e-table-example-2.c: New files. A couple - of examples of ETable use. - -2000-02-28 NotZed <NotZed@HelixCode.com> - - * Makefile.am (table_test_LDADD): Fixed references to eutil. - -2000-02-28 Christopher James Lahey <clahey@helixcode.com> - - * e-table-header-item.c, e-table-header.c: Fixed a couple of crash - bugs. - -2000-02-25 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c: Made the E table item redraw properly. - - * e-table-group-container.c: Added handling to distinguish between - n items and 1 item. Got rid of a crash due to an abandoned timeout - callback. - -2000-02-24 Christopher James Lahey <clahey@helixcode.com> - - * e-cell-text.c: Made carriage return stop editting instead of - inserting a carriage return. - -2000-02-24 Christopher James Lahey <clahey@helixcode.com> - - * test-table.c: Added duplicate_value and add_value. Use the new - compare functions. Made it so we only create one model to better - test model view stuff. Changed the test to not have as many - extra, useless, columns. - - * test-cols.c, test-check.c: Added duplicate_value and add_value. - Use the new compare functions. - - * e-table.c, e-table.h: Use all the new features of e-table-groups - (sorting and grouping). Handle on the fly reorganization of - groups in an idle loop. Compare functions now are to return -1 if - the first item is greater, 0 if they are equal, or 1 if the second - item is greater. - - * e-table-subset.c, e-table-subset.h: Made e-table-subset - disconnect properly from its signals when it dies. - - * e-table-subset-variable.c, e-table-subset-variable.h: - Virtualized the add and remove commands so that - e_table_sorted_variable could override the add command to do - sorting. - - * e-table-sorted.c: Fixed this to inherit properly from - ETableSubset. - - * e-table-simple.h, e-table-simple.c: Added handling of - duplicate_value and free_value; - - * e-table-model.c, e-table-model.h: Added duplicate_value and - free_value for memory allocation of table elements outside the - table. - - * e-table-item.c: Fixed a crashing bug. - - * e-table-group.c: Added sorting. Fixed destruction to delete the - right things. - - * e-table-group-leaf.c, e-table-group-leaf.h: Pass column and sort - order information into the e_table_sorted_variable. Properly - destroy things when deleted. - - * e-table-group-container.c, e-table-group-container.h: Properly - handle the list of subgroups. Handle proper sorting and grouping - of subgroups. - - * e-table-sorted-variable.c, e-table-sorted-variable.h: Files to - do a sorted model that stays sorted as you add and remove rows. - - * Makefile.am: Added e-table-sorted-variable.c and - e-table-sorted-variable.h. - -2000-02-24 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c: Made keyboard focus navigation work across - groups. - - * e-table-header.c: Made e_table_header_col_diff not crash if you - give it a column less than 0 (it truncates negative column values - to 0.) - - * e-table-group.c, e-table-group.h: Added e_table_group_get_header - to get the ETableHeader for this ETableGroup. - - * e-table-group-container.c: Made shift tab work. - -2000-02-24 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c: Made changing focus work. - -2000-02-24 Christopher James Lahey <clahey@helixcode.com> - - * e-table-subset-variable.c, e-table-subset-variable.h: A new - model which is a subset, but you can add and remove rows. - - * test-table.c: Added a thaw method for use with the - e-table-subset (emits model_changed.) Adapted to the changes to - e_table_item. Properly parse headers. Adapted to the changes to - e_table, including creating example xml spec data. - - * test-cols.c, test-check.c: Added a thaw method for use with the - e-table-subset (emits model_changed.) Adapted to the changes to - e_table_item. - - * e-table.c, e-table.h: Reworked e-table to use the ETable - grouping system. The only difference for the interface is that - instead of passing in a column_spec and a grouping_spec, you pass - in a single string that is an xml format that includes both pieces - of information. - - * e-table-subset.h: Added rules for emacs to do correct - indentation. - - * e-table-subset.c: Implemented freezing. No signals are emitted - while frozen and "model_changed" is emitted when thawed. - - * e-table-sorted.h: ETableSortedClass has ETableSubset as its - parent object instead of ETableSubsetClass. Fixed this. - - * e-table-simple.c, e-table-simple.h: Implemented the thaw method. - Use of simple now requires an extra argument (the thaw method.) - - * e-table-model.h, e-table-model.c: Added e_table_model_freeze and - e_table_model_thaw. - - * e-table-item.h, e-table-item.c: Reworked this a bit to make it - provide some things the new group system needed and to make - inter-item keyboard focus work. Changed the external interface - only in the list of arguments it recognizes and signals it emits. - Instead of "x" and "y", you have to use - e_canvas_item_move_absolute and instead of emitting a - "height_changed" signal, it emits a "resize" signal. There's new - "has_focus", "width", and "height" arguments and a function to get - the currently focused column. - - * e-table-header-item.c: Got rid of some warnings here. Changed - the - - * e-table-group-leaf.h, e-table-group-leaf.c, - e-table-group-container.h, e-table-group-container.c: New types to - make e_table_group work properly. - - * e-table-group.h, e-table-group.c: Completely reworked e-table - grouping. e-table-group now uses a hierarchical structure. - - * e-cell.h: Added e_cell_print. This doesn't work yet. - - * e-cell.c: Made e_cell_realize exist. (It was improperly named - e_cell_view_realize in the .c.) - - * e-cell-text.c: Made the blinking cursor disappear properly. - - * check-filled.xpm, check-empty.xpm: Made these const char *[] - instead of char *[] to avoid compiler warnings. - - * Makefile.am: Added e-table-group-container.c, - e-table-group-container.h, e-table-group-leaf.c, - e-table-group-leaf.h, e-table-subset-variable.c, - e-table-subset-variable.h. - -2000-02-18 Miguel de Icaza <miguel@nuclecu.unam.mx> - - * e-table-header.c: Include <string.h> - - * Makefile.am (INCLUDES): Add EXTRA_GNOME_CFLAGS to INCLUDES> - -2000-02-12 Iain Holmes <ih@csd.abdn.ac.uk> - - * e-table-header-item.c (ethi_drag_motion): Check the ethi is actually - the one being dragged. Prevents crashes when trying to drag headeritems - and there are multiple headeritems on the same canvas. - (ethi_drag_end): Same. - (ethi_drag_drop): Same. - (ethi_drag_leave): Same. - -2000-02-11 Christopher James Lahey <clahey@helixcode.com> - - * test-check.c: Added test of sort arrows. - - * e-table-col.h, e-table-col.c: Added sort arrows for column - headers (It doesn't actually sort. It just displays the arrows.) - - * e-table-header-item.c: Added display of arrows. - -2000-02-11 Christopher James Lahey <clahey@helixcode.com> - - * clip.png: Test column header image. - - * test-check.c: Test pixbuf column headers. - - * e-table-col.h, e-table-col.c: Added pixbufs for column headers. - - * e-table-header-item.c (draw_button): Draw pixbuf column headers properly. - -2000-02-11 Christopher James Lahey <clahey@helixcode.com> - - * e-cell-text.h, e-cell-text.c: Add an editable argument to - e_cell_text_new. - - * test-table.c, test-cols.c, test-check.c: Set the editable - argument to e_cell_text_new. - -2000-02-11 Christopher James Lahey <clahey@helixcode.com> - - * e-table-header-item.h, e-table-header-item.c: Added reordering - of columns. - - * e-table-header.c: Fixed a couple of bugs in the move column and - remove column functions. - -2000-02-11 Christopher James Lahey <clahey@helixcode.com> - - * e-cell-text.c: Made space around text look right. Added a - blinking cursor. - -2000-02-11 Miguel de Icaza <miguel@gnu.org> - - * e-table-item.c (eti_header_structure_changed): Add nice - assertion. - -2000-02-10 Christopher James Lahey <clahey@helixcode.com> - - * e-cell-text.c: Handle button releases properly. - - * e-table-header-item.c (ethi_start_drag): Added a drag icon. - -2000-02-09 Christopher James Lahey <clahey@helixcode.com> - - * e-cell-text.c: Tweaked e-cell-text. Added a white background - and tweaked the borders. - -2000-02-09 Christopher James Lahey <clahey@helixcode.com> - - * Makefile.am: Changes where e-text is included from. - -2000-02-07 Christopher James Lahey <clahey@helixcode.com> - - * e-table-item.c (eti_event): Fixed some motion event - bugs. (incorrect x and y.) - - * Makefile.am: Added includes for dependencies in - evolution/widgets/libevolutionwidgets.a - - * e-cell-text.h, e-cell-text.c: Completely revamped using code - from e-text.c and e-text.h. - -2000-02-07 Miguel de Icaza <miguel@gnu.org> - - * e-table.c (e_table_setup_table): Setup the scroll region of the - table canvas on size allocation. - (e_table_canvas_realize): Do not set the scrollregion here. - (e_table_canvas_init): Move root initialization here. - -2000-01-30 Miguel de Icaza <miguel@gnu.org> - - * e-table-simple.c (e_table_simple_new): Add data field back in. - -1999-12-30 Miguel de Icaza <miguel@gnu.org> - - * e-table-item.c (eti_attach_cell_views): New routine, creates the - cell views. - (eti_detach_cell_views): Detaches the cell_views from the - ETableItem. - (eti_realize_cell_views, eti_unrealize_cell_views): Simplified to - just do realize/unrealize notification. - (eti_add_table_model): Only attach the cells when we have both the - table model and the header model. - - * e-cell.h (ECellClass): Added two new methods: new_view and - kill_view which drive the view process (instead of putting that on - realize/unrealize). - - * e-cell.c: Adapt the code to use the new scheme for view - instantiation. - - * e-cell-text.c, e-cell-toggle.c: Adapted to the new class - changes. - -1999-12-22 Miguel de Icaza <miguel@helixcode.com> - - * e-table-item.c (e_table_item_focus): grab focus here with the - canvas method. - -1999-12-20 Miguel de Icaza <miguel@helixcode.com> - - * e-table-group.c (etg_update): Change the dimensions only if the - child changes its own. - - * e-table-item.c (eti_table_model_changed): Emit new signal on - table height change. - (eti_class_init): Register new "height_change" signal. - -1999-12-19 Damon Chaplin <damon@karuna.freeserve.co.uk> - - * Makefile.am (SUBDIRS): created SUBDIRS with meeting-time-sel. - - * meeting-time-sel/Makefile.am: - * meeting-time-sel/.cvsignore: - * meeting-time-sel/e-meeting-time-sel.h: - * meeting-time-sel/e-meeting-time-sel.c: - * meeting-time-sel/e-meeting-time-sel-item.h: - * meeting-time-sel/e-meeting-time-sel-item.c: - * meeting-time-sel/e-meeting-time-sel-list-item.h: - * meeting-time-sel/e-meeting-time-sel-list-item.c: - * meeting-time-sel/e-meeting-time-sel-mail.xpm: - * meeting-time-sel/e-meeting-time-sel-no-mail.xpm: - * meeting-time-sel/test-meeting-time-sel.c: new files implementing - the meeting time selector. - -1999-12-12 Miguel de Icaza <miguel@helixcode.com> - - * e-table-item.c (eti_class_init): X and Y arguments are now - doubles (to make it consistent with the rest of the canvas x, y - arguments). - - * e-table.c (e_table_create_leaf): Use new argument values here - - * test-*.c: Update to new argument types for x and y - - * e-table-group.c: New implementation as a canvas item used to - group childs. - - * e-table-item.c (eti_update): Make this play nicely with groups. - (eti_draw): ditto. - (eti_request_region_redraw): ditto. - (eti_item_region_redraw): New function. - - * e-table-subset.c (etss_proxy_model_row_changed): Added model - proxying. - - * e-cell.h: Drop ETableModel from the ECell; - (realize): Now takes an ETableModel - - * e-cell-checkbox.c: Adapted to new class - changes; - * e-cell-toggle.c: ditto - - * e-table-subset.c (etss_row_count): Fix this guy. - -1999-12-11 Miguel de Icaza <miguel@helixcode.com> - - * e-table-item.c (eti_unrealize_cell_views): Null the cell views. - (eti_header_structure_changed): Only unrealize/realize if we were - realized before. - - * e-table-header.c (e_table_header_add_column): Allow -1 as an - insert position - -1999-12-11 Miguel de Icaza <miguel@helixcode.com> - - * e-table.c: Massive fixage. - - * test-table.c: Updates to test the mega widget. - -1999-12-10 Miguel de Icaza <miguel@helixcode.com> - - * e-table.c: New file, implements the mega widget. - -1999-12-09 Miguel de Icaza <miguel@gnu.org> - - * e-table-header.c (e_table_header_col_diff): fix this routine. - -1999-12-04 Miguel de Icaza <miguel@gnu.org> - - * e-table-header-item.c (ethi_event): Started drag and drop - support. - - * e-table-item.c (eti_table_model_changed): The columns are - controled by the Header, not by the TableModel. - - * e-table-header-item.c (ethi_draw): Fixed redraw logic to support - arbitrary header positioning. - - * e-cell.h: Revamped e-cell interface. We now provide the model - column and the view column to all methods (so that the methods can - talk to the view and to the model at the same time). - - * e-table-item.c: Update to new API - * e-cell-test.c: Update to new API - -1999-12-03 Miguel de Icaza <miguel@gnu.org> - - * e-cell.c (e_cell_class_init): Provide emtpy methods for - enter_edit, and leave_edit. - - * e-table-item.c: Killed draw cell. - (eti_draw): Perform column mapping here. - (e_table_item_leave_edit): ditto. - (e_table_item_enter_edit): ditto. - (eti_event): ditto. - -1999-12-02 Miguel de Icaza <miguel@gnu.org> - - * e-table-header.c (e_table_header_index): fixed api. - -1999-12-01 Miguel de Icaza <miguel@gnu.org> - - * test-cols.c (multi_cols_test): Update to simplified API. - * test-check.c (check_test): ditto - * test-table.c (table_browser_test): ditto - - * e-table-simple.c (e_table_simple_class_init): Kill column_name method. - - * e-table-model.h: Kill column_name method. - - * e-table-col.c (e_table_col_new): Instead of using a column name, - use a column index. - - * e-cell-text.c (ect_draw): Keep track of the originally allocated - piece of code. - - * e-table-header-item.c (ethi_unrealize): Removed change cursor - from here. - - * e-cell-text.c (ect_draw): Memory leak fix. - - * table-test.c (main): Enhance the demo to load sample.table - automatically, to get memprof working. - - * e-table-header.c (eth_do_remove): Take an argument: do -remove. - - * e-table-header.c (e_table_header_add_column): Sink ETableCol to - own the object. - - * e-table-col.h: Made ETableCol a GtkObject to make reference - counting the lifecycle method for these objects. - - * e-table-col.c (e_table_col_destroy): New API call. - - * e-table-subset.c (e_table_subset_get_toplevel): New API call. - -1999-11-30 Miguel de Icaza <miguel@gnu.org> - - * e-cell-checkbox.c (e_cell_checkbox_new): This one derives from - e-cell-toggle. - - * check-emtpy.xpm, check-filled.xpm: new files. - - * e-cell-toggle.c (etog_draw): Paint in white. - If we have transparency enabled, do the nice alpha computation. - - * test-table.c, test-cols.c: new files; They implement the split - tests. - -1999-11-29 Miguel de Icaza <miguel@gnu.org> - - * e-table-col.c (e_table_col_new): Set etc->resizeable. - - * e-table-header-item.c (ethi_event): Handle non-resizeables - columns; Add support for minimum width. - - * e-cell-toggle.c, e-cell-toggle.h: New file. Implement a - multi-state image toggle cell object. - - * e-cell-text.c (ect_leave_edit): Handle the case of us calling - leave edit manually. - (ect_stop_editing): Leave manually editing here. - (ect_draw): Add one pixel to the border for left and right; - Handle off-screen cursor (must be improved). - (ect_edit_select_all): New function. - (ect_event): Select all text on editing start - - * e-table-item.c (eti_event): Map mouse events and dispatch them. - (eti_event): Add spreadsheet mode for editing; Enter editing only - with visual characters; - Leave editing mode when a different row has been selected. - (eti_get_height): Fix the computation for this; Fix logic for the - length_threshold. - - (eti_draw): Add borders on all sides of the box; - Only draw focus if the cell is not being edited. - -1999-11-28 Miguel de Icaza <miguel@gnu.org> - - * e-table-item.c (eti_draw): Focus inside, not outside. - (eti_realize): Enhance our focus gc. - - * e-cell-text.c (ect_enter_edit, ect_leave_edit): New methods; - They implement editing. - - * e-cell.h: new methods: enter_edit, leave_edit - - * e-table-model.h (set_value_at): make val argument const. - - * e-table-simple.c (simple_set_value_at): Make value argument const; - - * e-table-item.c (eti_set_arg): Add new mode: draw_focus; - -1999-11-27 Miguel de Icaza <miguel@gnu.org> - - * e-table-item.c (eti_event): beginning of the keyboard navigation. - - * e-table-model.c (e_table_model_row_changed): new function. - (e_table_model_cell_changed): new function. - (e_table_model_class_init): New signals. - - * e-table-item.c (eti_request_region_redraw): x2, y2 offsets were - wrong. - (eti_select): Repaint selected region. - (eti_request_region_redraw): Fix range. - (eti_draw): Correct offset computation here. - (e_table_item_class_init): New method: row_selection, handles the - selection. - - Now it implement GTK_SELECTION_SINGLE and GTK_SELECTION_MULTIPLE. - - Focusing and selection should be correct now. - -1999-11-26 Miguel de Icaza <miguel@gnu.org> - - * e-table-item.c (eti_realize): Compute height using the ecell - methods here. - (eti_get_height): new method to compute dimensions. - - * e-cursors.c: use a different cursor. - - * e-table-model.h: kill height and row_height methods. - - * e-cell.c (ec_height): New method. - - * e-cell-text.c (ect_realize): Load the font from the canvas. - (ect_draw): New color setup. - Center in the row. - (ect_height): Implement new method. - -1999-11-26 Michael Meeks <mmeeks@gnu.org> - - * ROADMAP.e-table: small spelling/typo fixes. - -1999-11-25 Miguel de Icaza <miguel@gnu.org> - - * e-table-item.c (eti_event): Work on mouse-button event - propagation to cells. - - * e-cell-text.c (ect_draw): Use CellViews now. - - * e-table-item.c (eti_realize_cell_views): New routine: Realizes - the cell views - (eti_unrealize_cell_views): New routine: unrealizes the cell views. - - * e-table-item.h: Move cell_views array here. - - * table-test.c (value_at): Fix return value. - (main): use new invocation method. - - * e-table-header-item.c (ethi_realize): Realize cells. - - * e-table-item.c (eti_header_dim_changed): redraw before and after. - - * e-table-header-item.c (ethi_event): Add continuous resizing. - -1999-11-24 Miguel de Icaza <miguel@gnu.org> - - * e-table-subset.h, e-table-subset.c: New files, used to implement - subset tables. - - * e-table-sorted.h, e-table-sorted.c: Now they derive from - e-table-subset. - - * e-cell.c, e-cell.h: realize method now return per view instance - data. - -1999-11-20 Miguel de Icaza <miguel@gnu.org> - - * e-table-item.c (eti_draw): WOOOOHOOOOOoO! It took me quite a - while to figure this one out. Fixed. - - * e-table-header-item.c (ethi_set_arg): Compute width, keep track - of it. - (ethi_add_table_header): Monitor changes to the Header model; - Queue updates. - (ethi_draw): Fix the redraw logic here. - - * table-test.c (main): Change the sample code, so we can better - debug this. - - * e-table-item.c (eti_header_structure_changed): Keep track of - width; - (eti_header_dim_changed): ditto. - (eti_draw): Many redraw fixes. - -1999-11-19 Miguel de Icaza <miguel@gnu.org> - - * e-table-item.c (eti_realize): Hook up; Load gcs. - (eti_unrealize): Hook up. - - * e-table-sorted.c: Finished implementing. - -1999-11-18 Miguel de Icaza <miguel@gnu.org> - - * e-table-model.c (e_table_model_class_init): Add model_changed - signal here. - - * e-table-item.c, e-table-item.h: New files. They implement the - view of the ETableModel as Canvas Items. - - * e-table-header-item.c (ethi_set_arg): Ref header here. - (ethi_destroy): Unref it here. - -1999-11-17 Ettore Perazzoli <ettore@gnu.org> - - * e-msg-composer-address-dialog.c: Moved to `$(srcdir)/composer'. - * e-msg-composer-address-dialog.h: Likewise. - * e-msg-composer-address-entry.c: Likewise. - * e-msg-composer-address-entry.h: Likewise. - * e-msg-composer-attachment-bar.c: Likewise. - * e-msg-composer-attachment-bar.h: Likewise. - * e-msg-composer-attachment.c: Likewise. - * e-msg-composer-attachment.h: Likewise. - * e-msg-composer-hdrs.c: Likewise. - * e-msg-composer-hdrs.h: Likewise. - * e-msg-composer.c: Likewise. - * e-msg-composer.h: Likewise. - * e-msg-composer-address-dialog.glade: Likewise. - * e-msg-composer-attachment.glade: Likewise. - * e-msg-composer.glade: Likewise. - * Makefile.am: Updated accordingly. - -Nov 14 1999 Elliot Lee - * Makefile.am: It's libevolutionwidgets.la, not .a - -1999-11-14 Miguel de Icaza <miguel@gnu.org> - - * e-table-header-item.c (is_pointer_on_division): Add resizing - capabilities. - - * e-table-sorted.c: Finish implementation. - -1999-11-13 Miguel de Icaza <miguel@gnu.org> - - * e-table-sorted.c: Implement e-table-sorted object. - -1999-11-12 Miguel de Icaza <miguel@gnu.org> - - * e-table-header-item.c: Make the thing configurable. - - * e-table-header-item.h: Add font field, location, height. - -1999-11-12 Ettore Perazzoli <ettore@gnu.org> - - * e-msg-composer-hdrs.c: New member `tooltips' in `struct - _EMsgComposerHdrsPrivate'. - (init): Initialize it. - (destroy): New function. - (class_init): Install it as the `destroy' GtkObject method. - (add_header): New parameters `tip', `tip_private'. Setup a - tooltip for the entry with them. - (setup_headers): Updated accordingly. - -1999-11-11 Miguel de Icaza <miguel@gnu.org> - - * e-table-header.c (e_table_header_add_column): Update offsets. - (eth_update_offsets): New routine. - - * e-table-col.h, e-table-col.c: New files. - - * e-table-header.h (e_table_header_get_selected_indexes): - Pretify. - - * table-test.c (main): New file; used for testing ETable package. - - * e-table-simple.h: Fix type. - -1999-11-12 Ettore Perazzoli <ettore@gnu.org> - - * e-msg-composer-address-dialog.glade: Cosmetical changes. - - * e-msg-composer-attachment-bar.c (size_to_string): New helper - function. - (update): Put the size in the icon's label using this function. - (ICON_SEPARATORS): Remove '.' to avoid wrapping of the size string - on the decimal dot. But gnome-libs is broken and this has no real - effect! :-( - (e_msg_composer_attachment_bar_new): No longer make text editable. - Use the `GTK_SELECTION_MULTIPLE' selection mode. - (remove_selected): No longer assume only one attachment is - selected. - - * e-msg-composer-attachment.c: #include <sys/stat.h> - (init): Initialize all the members. - (e_msg_composer_attachment_new): Set size using `stat()'. - - * e-msg-composer-attachment.h: New member `size' in `struct - _EMsgComposerAttachment'. - - * e-msg-composer.c (setup_signals): Connect `address_dialog_cb' to - the "show_address_dialog" signal of the header widget. - - * e-msg-composer-hdrs.c (add_address_header): Renamed to - `add_header'. New parameter `addrbook_button': if true, use a - button instead of a label and make it trigger an - "show_address_dialog" signal. - (address_button_clicked_cb): Signal handler to handle this on a - "clicked" signal from the button. - (setup_headers): Updated accordingly. Also, make "Subject" the - last item. (This makes it look more like Outlook and friends.) - - * e-msg-composer-hdrs.c: New signal "show_address_dialog". - * e-msg-composer-hdrs.h: Updated accordingly. - - * e-msg-composer-hdrs.c (add_address_header): Reduce padding - considerably. - - * e-msg-composer.c (e_msg_composer_construct): Do not use any - padding in the main vbox. - - * Makefile.am: Moved the `e-table*' sources to `EXTRA_DIST'. - Compile as a shared library. - -1999-11-08 Ettore Perazzoli <ettore@gnu.org> - - * e-msg-composer-address-dialog.c: Implemented cut & paste for the - recipient lists. - (init): Initialize `cut_buffer'. - (destroy): Free it. - (recipient_clist_selection_get_cb): New function. - (recipient_clist_selection_received_cb): New function. - (recipient_clist_selection_clear_event_cb): New function. - (setup_recipient_list_signals): Install them as signal handlers - for "selection_get", "selection_received" and - "selection_clear_event" respectively. - (copy_recipient_cb): New function implementing the "copy" - operation. - (cut_recipient_cb): New function implementing the "cut" operation. - (paste_recipient_cb): New function implementing the "paste" - operation. - - * e-msg-composer-address-dialog.h: New member `cut_buffer' in - `struct _EMsgComposerAddressDialog'. - -1999-11-07 Ettore Perazzoli <ettore@gnu.org> - - * e-msg-composer-address-dialog.c: New context menu - `recipient_list_popup_info' for the recipient CLists. - (recipient_clist_button_press_cb): New function. - (setup_signals): Install it as the "button_press_event" signal - handler for popping up the CList context menu. - - * e-msg-composer.c (free_string_list): New helper function. - (setup_address_dialog): Setup the initial values in the address - dialog according to the ones in the header widget. - - * e-msg-composer-hdrs.c (e_msg_composer_hdrs_get_to): New function. - (e_msg_composer_hdrs_get_cc): New function. - (e_msg_composer_hdrs_get_bcc): New function. - - * e-msg-composer.c (setup_address_dialog): New helper function. - (address_dialog_cb): Use it. - - * e-msg-composer-address-dialog.c (add_address): Do not set the - row data anymore. Instead, put the full address description - (i.e. complete with the email address, not just the full name) in - the CList. - (add_address): Do nothing if no item is selected in the address - CList. - (get_list): Get the address list from the CList without passing - through the address CList. - (set_list): New helper function. - (e_msg_composer_address_dialog_set_to_list): New function. - (e_msg_composer_address_dialog_set_cc_list): New function. - (e_msg_composer_address_dialog_set_bcc_list): New function. - - * e-msg-composer.c (address_dialog_apply_cb): Apply values from - the address dialog into the composer. - - * e-msg-composer-hdrs.c (e_msg_composer_hdrs_set_to): New function. - (e_msg_composer_hdrs_set_cc): New function. - (e_msg_composer_hdrs_set_bcc): New function. - - * e-msg-composer-address-entry.c - (e_msg_composer_address_entry_set_list): New function. - - * e-msg-composer-address-dialog.c (apply): New helper function. - (clicked): New function, `clicked' method for the `GnomeDialog' - class. - (class_init): Install it. - -1999-11-06 Ettore Perazzoli <ettore@gnu.org> - - * e-msg-composer-attachment-bar.c (destroy): Call the destroy - method of the parent class. - - * e-msg-composer.c: #include "e-msg-composer-address-dialog.h". - (address_dialog_cb): New callback to start the address dialog. - (setup_signals): Connect it to the appropriate button/menu item. - (init): Initialize the new `address_dialog' member to NULL. - (destroy): Destroy the `address_dialog' if not NULL. - - * e-msg-composer.h: New member `address_dialog' in `struct - _EMsgComposer'. - - * e-msg-composer.glade: Added button to activate the address - composition dialog. - - * e-msg-composer-address-dialog.h, e-msg-composer-address-dialog.c: - New files implementing the address composition dialog for Evolution. - - * e-msg-composer-address-dialog.glade: New file. - - * e-msg-composer-attachment.c: `signals' made static. - -1999-11-05 Ettore Perazzoli <ettore@gnu.org> - - * Makefile.am: Compile the new files in a `libevolutionwidgets' - library. - (CPPFLAGS): #define `E_GUIDIR'. - - * e-msg-composer.c, e-msg-composer.h: New files implementing an - initial version of the Evolution message composer widget. - - * e-msg-composer-address-entry.c, e-msg-composer-address-entry.h: - New files implementing a GtkEntry customized for entering email - address lists. - - * e-msg-composer-attachment-bar.c, e-msg-composer-attachment-bar.h: - New files implementing a widget for editing mail attachments. - - * e-msg-composer-attachment.c, e-msg-composer-attachment.h: New - files implementing file attachment objects for the message - composer. - - * e-msg-composer-hdrs.c, e-msg-composer-hdrs.h: New files - implementing a widget for editing of email message headers. - - * e-msg-composer-attachment.glade: New file. - * e-msg-composer.glade: New file. - -1999-10-31 Miguel de Icaza <miguel@gnu.org> - - * widgets/e-table-column.c, e-table-column.h: New file, implements the - e-table-column object. - - * widget/e-table-model.h, e-table-model.c, e-table-simple.c, - e-table-simple.h: New files. Implements the column model and - a simple table wrapper. - diff --git a/widgets/e-table/LICENSE b/widgets/e-table/LICENSE deleted file mode 100644 index b1f6ae08a4..0000000000 --- a/widgets/e-table/LICENSE +++ /dev/null @@ -1 +0,0 @@ -This code is released under the terms of the GNU GPL. diff --git a/widgets/e-table/Makefile.am b/widgets/e-table/Makefile.am deleted file mode 100644 index 30ee6f3d7d..0000000000 --- a/widgets/e-table/Makefile.am +++ /dev/null @@ -1,180 +0,0 @@ - -gladedir = $(datadir)/evolution/glade -glade_DATA = \ - e-table-config.glade \ - e-table-group.glade \ - e-table-field-chooser.glade - -glade_headers = \ - e-table-config.glade.h \ - e-table-group.glade.h \ - e-table-field-chooser.glade.h - -INCLUDES = \ - $(EXTRA_GNOME_CFLAGS) \ - $(GNOME_PRINT_CFLAGS) \ - $(GNOME_INCLUDEDIR) \ - -DETABLE_GLADEDIR=\"$(gladedir)\" \ - -I$(top_srcdir)/widgets/e-text \ - -I$(top_srcdir)/e-util \ - -I$(top_srcdir) \ - -DG_LOG_DOMAIN=\"e-table\" - -noinst_LIBRARIES = \ - libetable.a - -libetable_a_SOURCES = \ - e-cell.c \ - e-cell.h \ - e-cell-checkbox.c \ - e-cell-checkbox.h \ - e-cell-text.c \ - e-cell-text.h \ - e-cell-toggle.c \ - e-cell-toggle.h \ - e-cell-tree.c \ - e-cell-tree.h \ - e-table.c \ - e-table.h \ - e-table-click-to-add.c \ - e-table-click-to-add.h \ - e-table-col-dnd.h \ - e-table-col.c \ - e-table-col.h \ - e-table-config.c \ - e-table-config.h \ - e-table-defines.h \ - e-table-field-chooser-dialog.c \ - e-table-field-chooser-dialog.h \ - e-table-field-chooser-item.c \ - e-table-field-chooser-item.h \ - e-table-field-chooser.c \ - e-table-field-chooser.h \ - e-table-group.c \ - e-table-group.h \ - e-table-group-container.c \ - e-table-group-container.h \ - e-table-group-leaf.c \ - e-table-group-leaf.h \ - e-table-header.c \ - e-table-header.h \ - e-table-header-item.c \ - e-table-header-item.h \ - e-table-item.c \ - e-table-item.h \ - e-table-model.c \ - e-table-model.h \ - e-table-one.c \ - e-table-one.h \ - e-table-scrolled.c \ - e-table-scrolled.h \ - e-table-selection-model.c \ - e-table-selection-model.h \ - e-table-simple.c \ - e-table-simple.h \ - e-table-sort-info.c \ - e-table-sort-info.h \ - e-table-sorted.c \ - e-table-sorted.h \ - e-table-sorted-variable.c \ - e-table-sorted-variable.h \ - e-table-sorter.c \ - e-table-sorter.h \ - e-table-subset.c \ - e-table-subset.h \ - e-table-subset-variable.c \ - e-table-subset-variable.h \ - e-table-text-model.c \ - e-table-text-model.h \ - e-tree-model.c \ - e-tree-model.h \ - e-tree-simple.c \ - e-tree-simple.h - -noinst_PROGRAMS = \ - table-test table-example-1 table-example-2 table-size-test tree-example-1 - -table_test_SOURCES = \ - test-table.c \ - test-check.c \ - test-cols.c \ - table-test.c \ - table-test.h - -table_test_LDADD = \ - libetable.a \ - $(EXTRA_GNOME_LIBS) \ - $(top_builddir)/widgets/e-text/libetext.a \ - $(top_builddir)/widgets/misc/libemiscwidgets.a \ - $(top_builddir)/e-util/libeutil.la \ - $(GNOME_PRINT_LIBS) - -table_test_LDFLAGS = `gnome-config --libs gdk_pixbuf` - -table_size_test_SOURCES = \ - e-table-size-test.c - -table_size_test_LDADD = \ - libetable.a \ - $(EXTRA_GNOME_LIBS) \ - $(top_builddir)/widgets/e-text/libetext.a \ - $(top_builddir)/widgets/misc/libemiscwidgets.a \ - $(top_builddir)/e-util/libeutil.la \ - $(GNOME_PRINT_LIBS) - -table_size_test_LDFLAGS = `gnome-config --libs gdk_pixbuf` - -table_example_1_SOURCES = \ - e-table-example-1.c - -table_example_1_LDADD = \ - libetable.a \ - $(EXTRA_GNOME_LIBS) \ - $(top_builddir)/widgets/e-text/libetext.a \ - $(top_builddir)/widgets/misc/libemiscwidgets.a \ - $(top_builddir)/e-util/libeutil.la \ - $(GNOME_PRINT_LIBS) - -table_example_1_LDFLAGS = `gnome-config --libs gdk_pixbuf` - -table_example_2_SOURCES = \ - e-table-example-2.c - -table_example_2_LDADD = \ - libetable.a \ - $(EXTRA_GNOME_LIBS) \ - $(top_builddir)/widgets/e-text/libetext.a \ - $(top_builddir)/widgets/misc/libemiscwidgets.a \ - $(top_builddir)/e-util/libeutil.la \ - $(GNOME_PRINT_LIBS) - -table_example_2_LDFLAGS = `gnome-config --libs gdk_pixbuf` - -tree_example_1_SOURCES = \ - e-tree-example-1.c - -tree_example_1_LDFLAGS = `gnome-config --libs gdk_pixbuf` - -tree_example_1_LDADD = \ - libetable.a \ - $(EXTRA_GNOME_LIBS) \ - $(top_builddir)/widgets/e-text/libetext.a \ - $(top_builddir)/widgets/misc/libemiscwidgets.a \ - $(top_builddir)/e-util/libeutil.la \ - $(GNOME_PRINT_LIBS) - -icons = \ - arrow-down.xpm \ - arrow-up.xpm \ - add-col.xpm \ - check-empty.xpm \ - check-filled.xpm \ - remove-col.xpm \ - tree-expanded.xpm \ - tree-unexpanded.xpm - -EXTRA_DIST = \ - sample.table \ - $(icons) \ - $(glade_DATA) \ - $(glade_headers) diff --git a/widgets/e-table/ROADMAP.e-table b/widgets/e-table/ROADMAP.e-table deleted file mode 100644 index 4edacced86..0000000000 --- a/widgets/e-table/ROADMAP.e-table +++ /dev/null @@ -1,113 +0,0 @@ - -The E-Table package implements an editable table that provides -user-defined rendering, user-defined editing, sorting and grouping of -the objects displayed. - -It is inspired by Java's Swing JTable object. There are models for -the actual table contents and for the table headers; they are the -actual repository of information. - -The objects are rendered by various view objects. In the current code -base, we use we use GnomeCanvasItems to do the rendering. One for -each table and one for the headers. - -* The main widget - -e-table.c, e-table.h: - - Implements a full widget. Uses various components described - below. Handles column display as well as grouping/nesting - -* The Models - -All of them are GtkObjects. - -e-table-model.h, e-table-model.c: - - These implement the abstract E-Table-Model class. You - can derive this object to create your own data repository. - - These emits signals to notify the views about selection, and - changes in the model. - -e-table-simple.h, e-table-simple.c: - - A simple implementation of e-table-model that uses callback - routines (you provide the callbacks). For lazy people, like - me. - -e-cell.c, e-cell.h: - - These are actually mis-named. Objects of type e-cell know - about rendering a single cell, and these are attached to the - e-table-cols (described next). - - The user provides the various rendering modes as e-cells (they - are actually column-rendering repositories). - - This is just an abstract class. I will provide various - e-cells: a text cell, a checkbox cell, an image cell, and - perhaps an n-state image cell (one that switches the image when - the cell is clicked). - -e-table-col.h, e-table-col.c: - - Describes a single column (the size, the string displayed, the - rendering function for each row and comparison function for - this field). - - -* The Views - -e-table-header.h, e-table-header.c: - - These implement the ETableHeaderItem canvas item. This item is - used both to control the columns displayed as well as displaying them. - - They describe what columns are shown in the screen and in - which order. - - These emit signals: column-size-changed and structure-changed - (if a column is added/removed) - -e-table-item.c, e-table-item.h - - This is a canvas item that renders the contents of a - ETableModel into the screen. - -e-table-header-item.c, e-table-header-item.h - - This canvas item renders the ETableHeader headings. - -e-cell-text.c, e-cell-text.h - - Not really a view, but actually a derivative of e-cell that - implements text display: supports justification and font - setting. Will add color in the future most likely - -e-cell-toggle.c, e-cell-toggle.h - - A derivative of e-cell as well that support N-toggle values - using images. - -e-cell-check.c, e-cell-check.h - - An e-cell-toggle with two states only (for checkboxes). - -* The Filters - -e-table-sorted.c, e-table-sorted.h - - This is an ETableModel that can sort an existing ETableModel. - -e-table-subset.c, e-table-subset.h - - Not finished, but it is just an ETableModel that happens to be - a subset of another ETableModel. - -* Everything - -e-table.c, e-table.h - - In the future these guys will implement the whole widget for - doing table editing. Nothing done about these yet. diff --git a/widgets/e-table/TODO b/widgets/e-table/TODO deleted file mode 100644 index 40e214bc96..0000000000 --- a/widgets/e-table/TODO +++ /dev/null @@ -1,99 +0,0 @@ -Short Term TODO items: - -Bonobo Issues: - 1. DnD does not seem to be working, it always defaults to "destroy column". - 2. Cursor location is not propagated (no feedback). - -Functionality: - - 2. Implement GUI grouping. - 3. Implement context menu on item-bars. - 4. Implement config tool for the view. - 5. Add multi-sorting. - -GUI: - 1. Implement behaviours for "line-selection" - 2. Implement good behaviour for editing. - 3. Use the theme information for the captions. - 4. Use the font from the widget style. - 5. Fix the update problems when a group is resized. - -Implement e-cell-height -Implement computation of heights from the e-cell-heights -Make sure we compute the height from that -Include spacing in columns and rows for the decoration lines -Add threshold to compute a "global" size -Implement the two methods for row finding: by full thing, or by a factor. - - -+ Add editing -mouse grabbing for scrolling - - -1. Make sure that all values are updated on header changes and table - model changes (they are slightly out of sync now) - -* Correctness - - * Make sure we can boot and shutdown with no memory leaks. - - * Run Insure on the thing. - -+ * Propagation - -+ * Row changes should be reflected in the subsets. - - - -* Add an ETable::get_specification method to get the current layout information. - - * Add input and output of column widths and minimum column widths. - -+ * Add GUI sort - - * Add depressed button state to ETableHeaderItem? - -* Add GUI grouping - - * Create ETableGroupItem class. - * Make it work. (A large step) - -* Add a context menu - - * Define the menu - * Create the menu object. - * Hook up all the menu items. - -* Add a possible column list GUI - - * Create ETableColumnList class. - * Hook it up to ETableHeader. - * Figure out the correct semantics for the connection between the ETableHeader and the ETableColumnList. - * Implement widget display. - * Implement drag&drop. - -* Add closing and openning of groups - - * Add + button to group display. - * Build in semantics for clicking on the button. - * Make sub items hide & show. - * Resize group. - * Figure out how to save this data. - -* Data entry ("Click here to add...") - - * Add "Allocate" to the ETableModel - * Implement ETableDataEntry (a subclass of ETableModel). - * Build GUI for the data entry model. This should be fairly simple. - -* Usability - - * When the widget grows, the columns should resize to occupy all the - available space - -* Draw little arrows for new column position instead of little triangles. -* Make new column position be closest to position instead of rounding to the left. -* Copy gtk_dnd as e_dnd. - -* Fix known bug about navigating out of the bottom of the table. - diff --git a/widgets/e-table/add-col.xpm b/widgets/e-table/add-col.xpm deleted file mode 100644 index 9c5f314c8e..0000000000 --- a/widgets/e-table/add-col.xpm +++ /dev/null @@ -1,22 +0,0 @@ -/* XPM */ -static char * add_col_xpm[] = { -"16 16 3 1", -" c None", -". c #000000", -"+ c #FFFFFF", -" ", -" ", -" ", -" ", -" .............. ", -" .++++++++++++. ", -" .++++++++++++. ", -" ....+++....... ", -" .+. ", -" . ", -" ", -" ", -" ", -" ", -" ", -" "}; diff --git a/widgets/e-table/arrow-down.xpm b/widgets/e-table/arrow-down.xpm deleted file mode 100644 index f1e6cb4b3c..0000000000 --- a/widgets/e-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/e-table/arrow-up.xpm b/widgets/e-table/arrow-up.xpm deleted file mode 100644 index 0cc5b9a00c..0000000000 --- a/widgets/e-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/e-table/check-empty.xpm b/widgets/e-table/check-empty.xpm deleted file mode 100644 index 746b20234e..0000000000 --- a/widgets/e-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/e-table/check-filled.xpm b/widgets/e-table/check-filled.xpm deleted file mode 100644 index c0468fc25b..0000000000 --- a/widgets/e-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/e-table/clip.png b/widgets/e-table/clip.png Binary files differdeleted file mode 100644 index 27aa5f072f..0000000000 --- a/widgets/e-table/clip.png +++ /dev/null diff --git a/widgets/e-table/e-cell-checkbox.c b/widgets/e-table/e-cell-checkbox.c deleted file mode 100644 index 1d7c319f74..0000000000 --- a/widgets/e-table/e-cell-checkbox.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * e-cell-checkbox.c: Checkbox cell renderer - * - * Author: - * Miguel de Icaza (miguel@kernel.org) - * - * (C) 1999 Helix Code, Inc - */ -#include <config.h> -#include <gtk/gtkenums.h> -#include <gtk/gtkentry.h> -#include <gtk/gtkwindow.h> -#include <gtk/gtksignal.h> -#include <gdk/gdkkeysyms.h> -#include <libgnomeui/gnome-canvas.h> -#include "e-cell-checkbox.h" -#include "e-util/e-util.h" -#include "e-table-item.h" - -#include "check-empty.xpm" -#include "check-filled.xpm" - -#define PARENT_TYPE e_cell_toggle_get_type () - -static GdkPixbuf *checks [2]; - -static void -e_cell_checkbox_class_init (GtkObjectClass *object_class) -{ - checks [0] = gdk_pixbuf_new_from_xpm_data (check_empty_xpm); - checks [1] = gdk_pixbuf_new_from_xpm_data (check_filled_xpm); -} - -E_MAKE_TYPE(e_cell_checkbox, "ECellCheckbox", ECellCheckbox, e_cell_checkbox_class_init, NULL, PARENT_TYPE); - -ECell * -e_cell_checkbox_new (void) -{ - ECellCheckbox *eccb = gtk_type_new (e_cell_checkbox_get_type ()); - - e_cell_toggle_construct (E_CELL_TOGGLE (eccb), 2, 2, checks); - - return (ECell *) eccb; -} diff --git a/widgets/e-table/e-cell-checkbox.h b/widgets/e-table/e-cell-checkbox.h deleted file mode 100644 index 969e4a5edc..0000000000 --- a/widgets/e-table/e-cell-checkbox.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _E_CELL_CHECKBOX_H_ -#define _E_CELL_CHECKBOX_H_ - -#include "e-cell-toggle.h" - -#define E_CELL_CHECKBOX_TYPE (e_cell_checkbox_get_type ()) -#define E_CELL_CHECKBOX(o) (GTK_CHECK_CAST ((o), E_CELL_CHECKBOX_TYPE, ECellCheckbox)) -#define E_CELL_CHECKBOX_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_CHECKBOX_TYPE, ECellCheckboxClass)) -#define E_IS_CELL_CHECKBOX(o) (GTK_CHECK_TYPE ((o), E_CELL_CHECKBOX_TYPE)) -#define E_IS_CELL_CHECKBOX_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_CHECKBOX_TYPE)) - -typedef struct { - ECellToggle parent; -} ECellCheckbox; - -typedef struct { - ECellToggleClass parent_class; -} ECellCheckboxClass; - -GtkType e_cell_checkbox_get_type (void); -ECell *e_cell_checkbox_new (void); - -#endif /* _E_CELL_CHECKBOX_H_ */ - diff --git a/widgets/e-table/e-cell-string.c b/widgets/e-table/e-cell-string.c deleted file mode 100644 index 992b1bd10e..0000000000 --- a/widgets/e-table/e-cell-string.c +++ /dev/null @@ -1,9 +0,0 @@ -ECell * -e_cell_string_new (void) -{ - ECell *ecell; - - ecell = gtk_type_new (ecell); - - return ecell; -} diff --git a/widgets/e-table/e-cell-text.c b/widgets/e-table/e-cell-text.c deleted file mode 100644 index 279ef4975b..0000000000 --- a/widgets/e-table/e-cell-text.c +++ /dev/null @@ -1,2314 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-cell-text.c - Text cell renderer - * Copyright (C) 2000 Helix Code, Inc. - * - * Authors: Miguel de Icaza <miguel@helixcode.com> - * Chris Lahey <clahey@helixcode.com> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - * - * TODO: - * Clean up UTF-8 handling - * UTF-8 selection - */ - -#include <config.h> -#include <gtk/gtkenums.h> -#include <gtk/gtkentry.h> -#include <gtk/gtkwindow.h> -#include <gtk/gtkinvisible.h> -#include <gtk/gtksignal.h> -#include <gdk/gdkkeysyms.h> -#include <libgnomeui/gnome-canvas.h> -#include <stdio.h> -#include <unicode.h> -#include "e-cell-text.h" -#include "e-util/e-util.h" -#include "e-util/e-font.h" -#include "e-table-item.h" -#include "e-text-event-processor.h" -#include "e-text-event-processor-emacs-like.h" - -#include <gdk/gdkx.h> /* for BlackPixel */ -#include <ctype.h> -#include <math.h> - -/* This defines a line of text */ -struct line { - char *text; /* Line's text UTF-8, it is a pointer into the text->text string */ - int length; /* Line's length in BYTES */ - int width; /* Line's width in pixels */ - int ellipsis_length; /* Length before adding ellipsis in BYTES */ -}; - -/* Object argument IDs */ -enum { - ARG_0, - ARG_TEXT, /* UTF-8 */ - ARG_X, - ARG_Y, - ARG_FONT, - ARG_FONTSET, - ARG_FONT_GDK, - ARG_ANCHOR, - ARG_JUSTIFICATION, - ARG_CLIP_WIDTH, - ARG_CLIP_HEIGHT, - ARG_CLIP, - ARG_X_OFFSET, - ARG_Y_OFFSET, - ARG_FILL_COLOR, - ARG_FILL_COLOR_GDK, - ARG_FILL_COLOR_RGBA, - ARG_FILL_STIPPLE, - ARG_TEXT_WIDTH, - ARG_TEXT_HEIGHT, - ARG_USE_ELLIPSIS, - ARG_ELLIPSIS, - ARG_STRIKEOUT_COLUMN, - ARG_BOLD_COLUMN, - ARG_TEXT_FILTER, - ARG_COLOR_COLUMN, -}; - - -enum { - E_SELECTION_PRIMARY, - E_SELECTION_CLIPBOARD -}; - -static GdkAtom clipboard_atom = GDK_NONE; - -#define PARENT_TYPE e_cell_get_type () - -#define TEXT_PAD 4 - -typedef struct { - gpointer lines; /* Text split into lines (private field) */ - int num_lines; /* Number of lines of text */ - int max_width; - int ref_count; -} ECellTextLineBreaks; - - -typedef struct _CellEdit CellEdit; - -typedef struct { - ECellView cell_view; - GdkGC *gc; -#if 0 - GdkFont *font; -#else - EFont *font; -#endif - GdkCursor *i_cursor; - GdkBitmap *stipple; /* Stipple for text */ - - GnomeCanvas *canvas; - - /* - * During editing. - */ - CellEdit *edit; - - - int xofs, yofs; /* This gets added to the x - and y for the cell text. */ - double ellipsis_width; /* The width of the ellipsis. */ - -} ECellTextView; - -typedef struct _CurrentCell{ - ECellTextView *text_view; - int width; - char *text; - int model_col, view_col, row; - ECellTextLineBreaks *breaks; -} CurrentCell; - -#define CURRENT_CELL(x) ((CurrentCell *)(x)) - -struct _CellEdit { - CurrentCell cell; - - char *old_text; - - /* - * Where the editing is taking place - */ - - int xofs_edit, yofs_edit; /* Offset because of editing. - This is negative compared - to the other offsets. */ - - /* This needs to be reworked a bit once we get line wrapping. */ - int selection_start; /* Start of selection - IN BYTES */ - int selection_end; /* End of selection - IN BYTES */ - gboolean select_by_word; /* Current selection is by word */ - - /* This section is for drag scrolling and blinking cursor. */ - /* Cursor handling. */ - gint timeout_id; /* Current timeout id for scrolling */ - GTimer *timer; /* Timer for blinking cursor and scrolling */ - - gint lastx, lasty; /* Last x and y motion events */ - gint last_state; /* Last state */ - gulong scroll_start; /* Starting time for scroll (microseconds) */ - - gint show_cursor; /* Is cursor currently shown */ - gboolean button_down; /* Is mouse button 1 down */ - - ETextEventProcessor *tep; /* Text Event Processor */ - - /* Hmmm... this should probably be in native encoding? */ - - GtkWidget *invisible; /* For selection handling */ - gboolean has_selection; /* TRUE if we have the selection */ - gchar *primary_selection; /* Primary selection text */ - gint primary_length; /* Primary selection text length in BYTES */ - gchar *clipboard_selection; /* Clipboard selection text */ - gint clipboard_length; /* Clipboard selection text length in BYTES */ - - guint pointer_in : 1; - guint default_cursor_shown : 1; -}; - -static void e_cell_text_view_command (ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data); - -static void e_cell_text_view_get_selection (CellEdit *edit, GdkAtom selection, guint32 time); -static void e_cell_text_view_supply_selection (CellEdit *edit, guint time, GdkAtom selection, char *data, gint length); - -static GtkWidget *e_cell_text_view_get_invisible (CellEdit *edit); -static void _selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - CellEdit *edit); -static void _selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - CellEdit *edit); -static void _selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - CellEdit *edit); -static int number_of_lines (char *text); -static void split_into_lines (CurrentCell *cell); -static void unref_lines (CurrentCell *cell); -static void calc_line_widths (CurrentCell *cell); -static int get_line_ypos (CurrentCell *cell, struct line *line); -static int get_line_xpos (CurrentCell *cell, struct line *line); -static void _get_tep (CellEdit *edit); - -static gint _get_position_from_xy (CurrentCell *cell, gint x, gint y); -static void _get_xy_from_position (CurrentCell *cell, gint position, gint *xp, gint *yp); -static gboolean _blink_scroll_timeout (gpointer data); - -static void build_current_cell (CurrentCell *cell, ECellTextView *text_view, int model_col, int view_col, int row); -static void unbuild_current_cell (CurrentCell *cell); -static void calc_ellipsis (ECellTextView *text_view); -static void ect_free_color (gchar *color_spec, GdkColor *color, GdkColormap *colormap); -static GdkColor* e_cell_text_get_color (ECellTextView *cell_view, gchar *color_spec); - -static ECellClass *parent_class; - -static void -ect_queue_redraw (ECellTextView *text_view, int view_col, int view_row) -{ - e_table_item_redraw_range ( - text_view->cell_view.e_table_item_view, - view_col, view_row, view_col, view_row); -} - -/* - * Accept the currently edited text. if it's the same as what's in the cell, do nothing. - */ -static void -ect_accept_edits (ECellTextView *text_view) -{ - CurrentCell *cell = (CurrentCell *) text_view->edit; - - if (strcmp (text_view->edit->old_text, cell->text)) { - e_table_model_set_value_at (text_view->cell_view.e_table_model, - cell->model_col, cell->row, cell->text); - } -} - -/* - * Shuts down the editing process - */ -static void -ect_stop_editing (ECellTextView *text_view) -{ - CellEdit *edit = text_view->edit; - int row, view_col; - - if (!edit) - return; - - row = edit->cell.row; - view_col = edit->cell.view_col; - - g_free (edit->old_text); - edit->old_text = NULL; - g_free (edit->cell.text); - edit->cell.text = NULL; - if (edit->invisible) - gtk_widget_unref (edit->invisible); - if (edit->tep) - gtk_object_unref (GTK_OBJECT(edit->tep)); - if (edit->primary_selection) - g_free (edit->primary_selection); - if (edit->clipboard_selection) - g_free (edit->clipboard_selection); - if (! edit->default_cursor_shown){ - gdk_window_set_cursor (GTK_WIDGET(text_view->canvas)->window, NULL); - edit->default_cursor_shown = TRUE; - } - if (edit->timeout_id) { - g_source_remove (edit->timeout_id); - edit->timeout_id = 0; - } - if (edit->timer) { - g_timer_stop (edit->timer); - g_timer_destroy (edit->timer); - edit->timer = NULL; - } - - g_free (edit); - - text_view->edit = NULL; - ect_queue_redraw (text_view, view_col, row); -} - -/* - * Cancels the edits - */ -static void -ect_cancel_edit (ECellTextView *text_view) -{ - ect_stop_editing (text_view); -} - -/* - * ECell::new_view method - */ -static ECellView * -ect_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - ECellText *ect = E_CELL_TEXT (ecell); - ECellTextView *text_view = g_new0 (ECellTextView, 1); - GnomeCanvas *canvas = GNOME_CANVAS_ITEM (e_table_item_view)->canvas; - - text_view->cell_view.ecell = ecell; - text_view->cell_view.e_table_model = table_model; - text_view->cell_view.e_table_item_view = e_table_item_view; - - if (ect->font_name){ -#if 0 - GdkFont *f; - - f = gdk_fontset_load (ect->font_name); - text_view->font = f; -#endif - text_view->font = e_font_from_gdk_name (ect->font_name); - } - if (!text_view->font){ - text_view->font = e_font_from_gdk_font (GTK_WIDGET (canvas)->style->font); - } - - text_view->canvas = canvas; - - text_view->xofs = 0.0; - text_view->yofs = 0.0; - - return (ECellView *)text_view; -} - -/* - * ECell::kill_view method - */ -static void -ect_kill_view (ECellView *ecv) -{ - ECellTextView *text_view = (ECellTextView *) ecv; - - g_free (text_view); -} - -/* - * ECell::realize method - */ -static void -ect_realize (ECellView *ecell_view) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - - text_view->gc = gdk_gc_new (GTK_WIDGET (text_view->canvas)->window); - - text_view->i_cursor = gdk_cursor_new (GDK_XTERM); - - calc_ellipsis (text_view); - - if (parent_class->realize) - (* parent_class->realize) (ecell_view); -} - -/* - * ECell::unrealize method - */ -static void -ect_unrealize (ECellView *ecv) -{ - ECellTextView *text_view = (ECellTextView *) ecv; - ECellText *ect = (ECellText*) ecv->ecell; - GdkColormap *colormap; - - gdk_gc_unref (text_view->gc); - text_view->gc = NULL; - - if (text_view->edit){ - ect_cancel_edit (text_view); - } - - if (text_view->font) - e_font_unref (text_view->font); - - if (text_view->stipple) - gdk_bitmap_unref (text_view->stipple); - - gdk_cursor_destroy (text_view->i_cursor); - - if (ect->colors) { - colormap = gtk_widget_get_colormap (GTK_WIDGET (text_view->canvas)); - g_hash_table_foreach (ect->colors, (GHFunc) ect_free_color, - colormap); - g_hash_table_destroy (ect->colors); - ect->colors = NULL; - } - - if (parent_class->unrealize) - (* parent_class->unrealize) (ecv); -} - -static void -ect_free_color (gchar *color_spec, GdkColor *color, GdkColormap *colormap) -{ - - g_free (color_spec); - - /* This frees the color. Note we don't free it if it is the special - value. */ - if (color != (GdkColor*) 1) { - gdk_colors_free (colormap, &color->pixel, 1, 0); - - /* This frees the memory for the GdkColor. */ - gdk_color_free (color); - } -} - -/* - * ECell::draw method - */ -static void -ect_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, gboolean selected, - int x1, int y1, int x2, int y2) -{ - /* New ECellText */ - ECellText *ect = E_CELL_TEXT (ecell_view->ecell); - ECellTextView *text_view = (ECellTextView *) ecell_view; - GtkWidget *canvas = GTK_WIDGET (text_view->canvas); - GdkRectangle rect, *clip_rect; - struct line *lines; - int i; - int xpos, ypos; - int start_char, end_char; - int sel_start, sel_end; - GdkRectangle sel_rect; - GdkGC *fg_gc; - EFont *font = text_view->font; - const int height = e_font_height (text_view->font); - CellEdit *edit = text_view->edit; - gboolean edit_display = FALSE; - ECellTextLineBreaks *linebreaks; - GdkColor *foreground, *cell_foreground, *cursor_color; - gchar *color_spec; - - EFontStyle style = E_FONT_PLAIN; - - if (ect->bold_column >= 0 && e_table_model_value_at(ecell_view->e_table_model, ect->bold_column, row)) - style = E_FONT_BOLD; - - if (edit){ - if ((edit->cell.view_col == view_col) && (edit->cell.row == row)) { - edit_display = TRUE; - fg_gc = canvas->style->fg_gc[edit->has_selection ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE]; - } else - fg_gc = canvas->style->fg_gc[GTK_STATE_ACTIVE]; - } else { - fg_gc = canvas->style->fg_gc[GTK_STATE_ACTIVE]; - } - - /* - * Be a nice citizen: clip to the region we are supposed to draw on - */ - rect.x = x1; - rect.y = y1; - rect.width = x2 - x1; - rect.height = y2 - y1; - - gdk_gc_set_clip_rectangle (text_view->gc, &rect); - gdk_gc_set_clip_rectangle (fg_gc, &rect); - clip_rect = ▭ - - if (selected){ - foreground = &canvas->style->text [GTK_STATE_SELECTED]; - } else { - foreground = &canvas->style->text [GTK_STATE_NORMAL]; - } - - cursor_color = foreground; - - if (ect->color_column != -1) { - color_spec = e_table_model_value_at (ecell_view->e_table_model, - ect->color_column, row); - cell_foreground = e_cell_text_get_color (text_view, - color_spec); - if (cell_foreground) - foreground = cell_foreground; - } - - gdk_gc_set_foreground (text_view->gc, foreground); - - x1 += 4; - y1 += 1; - x2 -= 4; - y2 -= 1; - - rect.x = x1; - rect.y = y1; - rect.width = x2 - x1; - rect.height = y2 - y1; - - gdk_gc_set_clip_rectangle (text_view->gc, &rect); - gdk_gc_set_clip_rectangle (fg_gc, &rect); - clip_rect = ▭ - - if (edit_display){ - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - - cell->width = x2 - x1; - - split_into_lines (cell); - - linebreaks = cell->breaks; - - lines = linebreaks->lines; - ypos = get_line_ypos (cell, lines); - ypos += e_font_ascent (text_view->font); - ypos -= edit->yofs_edit; - - for (i = 0; i < linebreaks->num_lines; i++) { - xpos = get_line_xpos (cell, lines); - xpos -= edit->xofs_edit; - - /* start_char, end_char, sel_start and sel_end are IN BYTES */ - - start_char = lines->text - cell->text; - end_char = start_char + lines->length; - - sel_start = edit->selection_start; - sel_end = edit->selection_end; - - if (sel_start > sel_end){ - sel_start ^= sel_end; - sel_end ^= sel_start; - sel_start ^= sel_end; - } - if (sel_start < start_char) - sel_start = start_char; - if (sel_end > end_char) - sel_end = end_char; - - if (sel_start < sel_end){ - sel_rect.x = xpos + x1 + e_font_utf8_text_width (font, style, lines->text, sel_start - start_char); - sel_rect.y = ypos + y1 - e_font_ascent (font); - sel_rect.width = e_font_utf8_text_width (font, style, - lines->text + sel_start - start_char, - sel_end - sel_start); - sel_rect.height = height; - gtk_paint_flat_box (canvas->style, - drawable, - edit->has_selection ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE, - GTK_SHADOW_NONE, - clip_rect, - canvas, - "text", - sel_rect.x, - sel_rect.y, - sel_rect.width, - sel_rect.height); - - e_font_draw_utf8_text (drawable, font, style, text_view->gc, xpos + x1, ypos + y1, - lines->text, - sel_start - start_char); - e_font_draw_utf8_text (drawable, font, style, fg_gc, - xpos + x1 + e_font_utf8_text_width (font, style, lines->text, sel_start - start_char), - ypos + y1, - lines->text + sel_start - start_char, - sel_end - sel_start); - e_font_draw_utf8_text (drawable, font, style, text_view->gc, - xpos + x1 + e_font_utf8_text_width (font, style, lines->text, sel_end - start_char), - ypos + y1, - lines->text + sel_end - start_char, - end_char - sel_end); -#if 0 /* Do Bold in EFont directly */ - /* Draw 1,0 moved image, to simulate bold font */ - /* We move that to EFont */ - if (bold) { - e_font_draw_utf8_text (drawable, font, text_view->gc, xpos + x1 + 1, ypos + y1, - lines->text, - sel_start - start_char); - e_font_draw_utf8_text (drawable, font, fg_gc, - xpos + x1 + 1 + e_font_utf8_text_width (font, lines->text, sel_start - start_char), - ypos + y1, - g_utf8_offset_to_pointer (lines->text, sel_start - start_char), - sel_end - sel_start); - e_font_draw_utf8_text (drawable, font, text_view->gc, - xpos + x1 + 1 + e_font_utf8_text_width (font, lines->text, sel_end - start_char), - ypos + y1, - g_utf8_offset_to_pointer (lines->text, sel_end - start_char), - end_char - sel_end); - } -#endif - } else { - e_font_draw_utf8_text (drawable, font, style, text_view->gc, - xpos + x1, ypos + y1, - lines->text, - lines->length); -#if 0 - if (bold) { - e_font_draw_ucs2_text (drawable, - font, - text_view->gc, - xpos + x1 + 1, - ypos + y1, - lines->text, - lines->length); - } -#endif - } - if (edit->selection_start == edit->selection_end && - edit->selection_start >= start_char && - edit->selection_start <= end_char && - edit->show_cursor) { - gdk_gc_set_foreground (text_view->gc, cursor_color); - gdk_draw_rectangle (drawable, - text_view->gc, - TRUE, - xpos + x1 + e_font_utf8_text_width (font, style, lines->text, sel_start - start_char), - ypos + y1 - e_font_ascent (font), - 1, - height); - } - if (ect->strikeout_column >= 0 && e_table_model_value_at(ecell_view->e_table_model, ect->strikeout_column, row)) { - gdk_draw_rectangle (drawable, - text_view->gc, - TRUE, - x1, ypos + y1 - (e_font_ascent (font) / 2), - x2 - x1, - 1); - } - ypos += height; - lines ++; - } - unref_lines (cell); - } else { - - ECellTextLineBreaks *linebreaks; - CurrentCell cell; - build_current_cell (&cell, text_view, model_col, view_col, row); - - cell.width = x2 - x1; - - split_into_lines (&cell); - - linebreaks = cell.breaks; - lines = linebreaks->lines; - ypos = get_line_ypos (&cell, lines); - ypos += e_font_ascent (text_view->font); - - - for (i = 0; i < linebreaks->num_lines; i++) { - xpos = get_line_xpos (&cell, lines); - if (ect->use_ellipsis && lines->ellipsis_length < lines->length) { - e_font_draw_utf8_text (drawable, font, style, text_view->gc, - xpos + x1, ypos + y1, - lines->text, - lines->ellipsis_length); - e_font_draw_utf8_text (drawable, font, style, text_view->gc, - xpos + x1 + lines->width - text_view->ellipsis_width, - ypos + y1, - ect->ellipsis ? ect->ellipsis : "...", - ect->ellipsis ? strlen (ect->ellipsis) : 3); -#if 0 - if (bold) { - e_font_draw_ucs2_text (drawable, - font, - text_view->gc, - xpos + x1 + 1, - ypos + y1, - lines->text, - lines->ellipsis_length); - e_font_draw_utf8_text (drawable, - font, - text_view->gc, - xpos + x1 + 1 + - lines->width - text_view->ellipsis_width, - ypos + y1, - ect->ellipsis ? ect->ellipsis : "...", - ect->ellipsis ? strlen (ect->ellipsis) : 3); - } -#endif - } else { - e_font_draw_utf8_text (drawable, font, style, text_view->gc, - xpos + x1, - ypos + y1, - lines->text, - lines->length); -#if 0 - if (bold) { - e_font_draw_ucs2_text (drawable, - font, - text_view->gc, - xpos + x1 + 1, - ypos + y1, - lines->text, - lines->length); - } -#endif - } - if (ect->strikeout_column >= 0 && e_table_model_value_at(ecell_view->e_table_model, ect->strikeout_column, row)) { - gdk_draw_rectangle (drawable, - text_view->gc, - TRUE, - x1, ypos + y1 - (e_font_ascent (font) / 2), - x2 - x1, - 1); - } - ypos += height; - lines++; - } - unref_lines (&cell); - unbuild_current_cell (&cell); - } - - gdk_gc_set_clip_rectangle (text_view->gc, NULL); - gdk_gc_set_clip_rectangle (fg_gc, NULL); -#if 0 - /* Old ECellText */ - - int xoff; - gboolean edit_display = FALSE; - - /* - * Figure if this cell is being edited - */ - if (edit_display){ - CellEdit *edit = text_view->edit; - const char *text = gtk_entry_get_text (edit->entry); - GdkWChar *p, *text_wc = g_new (GdkWChar, strlen (text) + 1); - int text_wc_len = gdk_mbstowcs (text_wc, text, strlen (text)); - const int cursor_pos = GTK_EDITABLE (edit->entry)->current_pos; - const int left_len = gdk_text_width_wc (text_view->font, text_wc, cursor_pos); - - text_wc [text_wc_len] = 0; - /* - * Paint - */ - gdk_gc_set_foreground (text_view->gc, &w->style->base [GTK_STATE_NORMAL]); - gdk_draw_rectangle (drawable, text_view->gc, TRUE, - rect.x, rect.y, rect.width, rect.height); - gdk_gc_set_foreground (text_view->gc, &w->style->text [GTK_STATE_NORMAL]); - - { - GdkGC *gc = text_view->gc; - const int y = y2 - font->descent - ((y2-y1-height)/2); - int px, i; - - /* - * Border - */ - x1 += 2; - x2--; - - px = x1; - - /* - * If the cursor is outside the visible range - * - * FIXME: we really want a better behaviour. - */ - if ((px + left_len) > x2) - px -= left_len - (x2-x1); - - /* - * Draw - */ - for (i = 0, p = text_wc; *p; p++, i++){ - gdk_draw_text_wc ( - drawable, font, gc, px, y, p, 1); - - if (i == cursor_pos){ - gdk_draw_line ( - drawable, gc, - px, y - font->ascent, - px, y + font->descent - 1); - } - - px += gdk_text_width_wc (font, p, 1); - } - - if (i == cursor_pos){ - gdk_draw_line ( - drawable, gc, - px, y - font->ascent, - px, y + font->descent - 1); - } - } - g_free (text_wc); - } else { - /* - * Regular cell - */ - GdkColor *background, *foreground; - int width; - - /* - * Border - */ - x1++; - x2--; - - /* - * Compute draw mode - */ - switch (ect->justify){ - case GTK_JUSTIFY_LEFT: - xoff = 1; - break; - - case GTK_JUSTIFY_RIGHT: - width = 1 + gdk_text_width (font, str, strlen (str)); - xoff = (x2 - x1) - width; - break; - - case GTK_JUSTIFY_CENTER: - xoff = ((x2 - x1) - gdk_text_width (font, str, strlen (str))) / 2; - break; - default: - xoff = 0; - g_warning ("Can not handle GTK_JUSTIFY_FILL"); - break; - } - - - if (selected){ - background = &w->style->bg [GTK_STATE_SELECTED]; - foreground = &w->style->text [GTK_STATE_SELECTED]; - } else { - background = &w->style->base [GTK_STATE_NORMAL]; - foreground = &w->style->text [GTK_STATE_NORMAL]; - } - - gdk_gc_set_foreground (text_view->gc, background); - gdk_draw_rectangle (drawable, text_view->gc, TRUE, - rect.x, rect.y, rect.width, rect.height); - gdk_gc_set_foreground (text_view->gc, foreground); - - gdk_draw_string ( - drawable, font, text_view->gc, - x1 + xoff, - y2 - font->descent - ((y2-y1-height)/2), str); - } -#endif -} - -/* - * Selects the entire string - */ -static void -ect_edit_select_all (ECellTextView *text_view) -{ - g_assert (text_view->edit); - - text_view->edit->selection_start = 0; - text_view->edit->selection_end = strlen (text_view->edit->cell.text); -} - -/* - * ECell::event method - */ -static gint -ect_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - ETextEventProcessorEvent e_tep_event; - gboolean edit_display = FALSE; - CellEdit *edit = text_view->edit; - GtkWidget *canvas = GTK_WIDGET (text_view->canvas); - gint return_val = 0; - - CurrentCell cell, *cellptr; - build_current_cell (&cell, text_view, model_col, view_col, row); - - - if (edit){ - if ((edit->cell.view_col == view_col) && (edit->cell.row == row)) { - edit_display = TRUE; - cellptr = CURRENT_CELL(edit); - } else { - cellptr = &cell; - } - } else { - cellptr = &cell; - } - - e_tep_event.type = event->type; - switch (event->type) { - case GDK_FOCUS_CHANGE: - break; - case GDK_KEY_PRESS: /* Fall Through */ - case GDK_KEY_RELEASE: - if (event->key.keyval == GDK_Escape){ - ect_cancel_edit (text_view); - return_val = TRUE; - break; - } - - if ((!edit_display) && e_table_model_is_cell_editable (ecell_view->e_table_model, model_col, row)) { - e_table_item_enter_edit (text_view->cell_view.e_table_item_view, view_col, row); - ect_edit_select_all (text_view); - edit = text_view->edit; - cellptr = CURRENT_CELL(edit); - edit_display = TRUE; - } - if (edit_display) { - GdkEventKey key = event->key; - if (key.keyval == GDK_KP_Enter || key.keyval == GDK_Return){ - e_table_item_leave_edit (text_view->cell_view.e_table_item_view); - } else { - e_tep_event.key.time = key.time; - e_tep_event.key.state = key.state; - e_tep_event.key.keyval = key.keyval; - e_tep_event.key.length = key.length; - e_tep_event.key.string = key.string; - _get_tep (edit); - return_val = e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - break; - } - } - - else - return 0; - break; - case GDK_BUTTON_PRESS: /* Fall Through */ - case GDK_BUTTON_RELEASE: - event->button.x -= 4; - event->button.y -= 1; - if ((!edit_display) - && e_table_model_is_cell_editable (ecell_view->e_table_model, model_col, row) - && event->type == GDK_BUTTON_RELEASE - && event->button.button == 1) { - GdkEventButton button = event->button; - - e_table_item_enter_edit (text_view->cell_view.e_table_item_view, view_col, row); - edit = text_view->edit; - cellptr = CURRENT_CELL(edit); - edit_display = TRUE; - - e_tep_event.button.type = GDK_BUTTON_PRESS; - e_tep_event.button.time = button.time; - e_tep_event.button.state = button.state; - e_tep_event.button.button = button.button; - e_tep_event.button.position = _get_position_from_xy (cellptr, button.x, button.y); - _get_tep (edit); - return_val = e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - if (event->button.button == 1) { - if (event->type == GDK_BUTTON_PRESS) - edit->button_down = TRUE; - else - edit->button_down = FALSE; - } - edit->lastx = button.x; - edit->lasty = button.y; - edit->last_state = button.state; - - e_tep_event.button.type = GDK_BUTTON_RELEASE; - } - if (edit_display) { - GdkEventButton button = event->button; - e_tep_event.button.time = button.time; - e_tep_event.button.state = button.state; - e_tep_event.button.button = button.button; - e_tep_event.button.position = _get_position_from_xy (cellptr, button.x, button.y); - _get_tep (edit); - return_val = e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - if (event->button.button == 1) { - if (event->type == GDK_BUTTON_PRESS) - edit->button_down = TRUE; - else - edit->button_down = FALSE; - } - edit->lastx = button.x; - edit->lasty = button.y; - edit->last_state = button.state; - } - break; - case GDK_MOTION_NOTIFY: - event->motion.x -= 4; - event->motion.y -= 1; - if (edit_display) { - GdkEventMotion motion = event->motion; - e_tep_event.motion.time = motion.time; - e_tep_event.motion.state = motion.state; - e_tep_event.motion.position = _get_position_from_xy (cellptr, motion.x, motion.y); - _get_tep (edit); - return_val = e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - edit->lastx = motion.x; - edit->lasty = motion.y; - edit->last_state = motion.state; - } - break; - case GDK_ENTER_NOTIFY: -#if 0 - edit->pointer_in = TRUE; -#endif - if (edit_display) { - if (edit->default_cursor_shown){ - gdk_window_set_cursor (canvas->window, text_view->i_cursor); - edit->default_cursor_shown = FALSE; - } - } - break; - case GDK_LEAVE_NOTIFY: -#if 0 - text_view->pointer_in = FALSE; -#endif - if (edit_display) { - if (! edit->default_cursor_shown){ - gdk_window_set_cursor (canvas->window, NULL); - edit->default_cursor_shown = TRUE; - } - } - break; - default: - break; - } - - unbuild_current_cell (&cell); - if (return_val) - return return_val; -#if 0 - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS(parent_class)->event (item, event); -#endif - else - return 0; - -#if 0 - switch (event->type){ - case GDK_BUTTON_PRESS: - /* - * Adjust for the border we use - */ - event->button.x++; - - printf ("Button pressed at %g %g\n", event->button.x, event->button.y); - if (text_view->edit){ - printf ("FIXME: Should handle click here\n"); - } else - e_table_item_enter_edit (text_view->cell_view.e_table_item_view, view_col, row); - break; - - case GDK_KEY_PRESS: - if (event->key.keyval == GDK_Escape){ - ect_cancel_edit (text_view); - return TRUE; - } - - if (!text_view->edit){ - e_table_item_enter_edit (text_view->cell_view.e_table_item_view, view_col, row); - ect_edit_select_all (text_view); - } - - gtk_widget_event (GTK_WIDGET (text_view->edit->entry), event); - ect_queue_redraw (text_view, view_col, row); - break; -#endif -} - -/* - * ECell::height method - */ -static int -ect_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - EFont *font; - ECellText *ect = E_CELL_TEXT(ecell_view->ecell); - - font = text_view->font; - if (ect->filter) { - gchar *string; - gint value; - - string = (*ect->filter)(e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - value = e_font_height (font) * number_of_lines(string) + TEXT_PAD; - - g_free(string); - - return value; - } else { - gchar * string; - gint value; - - string = e_table_model_value_at (ecell_view->e_table_model, model_col, row); - - value = e_font_height (font) * number_of_lines (string) + TEXT_PAD; - - return value; - } -} - -/* - * ECellView::enter_edit method - */ -static void * -ect_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - CellEdit *edit; - ECellText *ect = E_CELL_TEXT(ecell_view->ecell); - - edit = g_new (CellEdit, 1); - text_view->edit = edit; - - build_current_cell (CURRENT_CELL(edit), text_view, model_col, view_col, row); - - edit->xofs_edit = 0.0; - edit->yofs_edit = 0.0; - - edit->selection_start = 0; - edit->selection_end = 0; - edit->select_by_word = FALSE; - - edit->timeout_id = g_timeout_add (10, _blink_scroll_timeout, text_view); - edit->timer = g_timer_new (); - g_timer_elapsed (edit->timer, &(edit->scroll_start)); - g_timer_start (edit->timer); - - edit->lastx = 0; - edit->lasty = 0; - edit->last_state = 0; - - edit->scroll_start = 0; - edit->show_cursor = TRUE; - edit->button_down = FALSE; - - edit->tep = NULL; - - edit->has_selection = FALSE; - - edit->invisible = NULL; - edit->primary_selection = NULL; - edit->primary_length = 0; - edit->clipboard_selection = NULL; - edit->clipboard_length = 0; - - edit->pointer_in = FALSE; - edit->default_cursor_shown = TRUE; - - if (ect->filter) { - edit->old_text = (*ect->filter)(e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - } else { - edit->old_text = g_strdup (e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - } - edit->cell.text = g_strdup (edit->old_text); - -#if 0 - if (edit->pointer_in){ - if (edit->default_cursor_shown){ - gdk_window_set_cursor (GTK_WIDGET(item->canvas)->window, text_view->i_cursor); - edit->default_cursor_shown = FALSE; - } - } -#endif - - ect_queue_redraw (text_view, view_col, row); - - return NULL; -} - -/* - * ECellView::leave_edit method - */ -static void -ect_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - CellEdit *edit = text_view->edit; - - if (edit){ - ect_accept_edits (text_view); - ect_stop_editing (text_view); - /* FIXME: edit is freed in ect_stop_editing() so I've - commented this out - Damon. */ - /*unbuild_current_cell (CURRENT_CELL(edit));*/ - } else { - /* - * We did invoke this leave edit internally - */ - } -} - -static void -ect_print (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width, double height) -{ - GnomeFont *font = gnome_font_new ("Helvetica", 12); - char *string; - ECellText *ect = E_CELL_TEXT(ecell_view->ecell); - if (ect->filter) { - string = (*ect->filter)(e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - } else { - string = e_table_model_value_at (ecell_view->e_table_model, model_col, row); - } - gnome_print_gsave(context); - if (gnome_print_moveto(context, 2, 2) == -1) - /* FIXME */; - if (gnome_print_lineto(context, width - 2, 2) == -1) - /* FIXME */; - if (gnome_print_lineto(context, width - 2, height - 2) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 2, height - 2) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 2, 2) == -1) - /* FIXME */; - if (gnome_print_clip(context) == -1) - /* FIXME */; - gnome_print_moveto(context, 2, (height - gnome_font_get_ascender(font) + gnome_font_get_descender(font)) / 2); - gnome_print_setfont(context, font); - gnome_print_show(context, string); - gnome_print_grestore(context); - if (ect->filter) { - g_free(string); - } -} - -static gdouble -ect_print_height (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width) -{ - return 16; -} - -/* - * GtkObject::destroy method - */ -static void -ect_destroy (GtkObject *object) -{ - ECellText *ect = E_CELL_TEXT (object); - - g_free (ect->font_name); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} -/* Set_arg handler for the text item */ -static void -ect_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ECellText *text; - - text = E_CELL_TEXT (object); - - switch (arg_id) { - case ARG_STRIKEOUT_COLUMN: - text->strikeout_column = GTK_VALUE_INT (*arg); - break; - - case ARG_BOLD_COLUMN: - text->bold_column = GTK_VALUE_INT (*arg); - break; - - case ARG_COLOR_COLUMN: - text->color_column = GTK_VALUE_INT (*arg); - break; - - case ARG_TEXT_FILTER: - text->filter = GTK_VALUE_POINTER (*arg); - break; - default: - return; - } -} - -/* Get_arg handler for the text item */ -static void -ect_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ECellText *text; - - text = E_CELL_TEXT (object); - - switch (arg_id) { - case ARG_STRIKEOUT_COLUMN: - GTK_VALUE_INT (*arg) = text->strikeout_column; - break; - - case ARG_BOLD_COLUMN: - GTK_VALUE_INT (*arg) = text->bold_column; - break; - - case ARG_COLOR_COLUMN: - GTK_VALUE_INT (*arg) = text->color_column; - break; - - case ARG_TEXT_FILTER: - GTK_VALUE_POINTER (*arg) = text->filter; - break; - - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -e_cell_text_class_init (GtkObjectClass *object_class) -{ - ECellClass *ecc = (ECellClass *) object_class; - - object_class->destroy = ect_destroy; - - ecc->new_view = ect_new_view; - ecc->kill_view = ect_kill_view; - ecc->realize = ect_realize; - ecc->unrealize = ect_unrealize; - ecc->draw = ect_draw; - ecc->event = ect_event; - ecc->height = ect_height; - ecc->enter_edit = ect_enter_edit; - ecc->leave_edit = ect_leave_edit; - ecc->print = ect_print; - ecc->print_height = ect_print_height; - - object_class->get_arg = ect_get_arg; - object_class->set_arg = ect_set_arg; - - parent_class = gtk_type_class (PARENT_TYPE); - - gtk_object_add_arg_type ("ECellText::strikeout_column", - GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_STRIKEOUT_COLUMN); - gtk_object_add_arg_type ("ECellText::bold_column", - GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_BOLD_COLUMN); - gtk_object_add_arg_type ("ECellText::color_column", - GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_COLOR_COLUMN); - gtk_object_add_arg_type ("ECellText::text_filter", - GTK_TYPE_POINTER, GTK_ARG_READWRITE, ARG_TEXT_FILTER); - - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); -} - -static void -e_cell_text_init (ECellText *ect) -{ - ect->strikeout_column = -1; - ect->bold_column = -1; - ect->color_column = -1; -} - -E_MAKE_TYPE(e_cell_text, "ECellText", ECellText, e_cell_text_class_init, e_cell_text_init, PARENT_TYPE); - -ECell * -e_cell_text_new (ETableModel *etm, const char *fontname, GtkJustification justify) -{ - ECellText *ect = gtk_type_new (e_cell_text_get_type ()); - - ect->ellipsis = NULL; - ect->use_ellipsis = TRUE; - - ect->font_name = g_strdup (fontname); - ect->justify = justify; - - return (ECell *) ect; -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static int -get_line_xpos (CurrentCell *cell, struct line *line) -{ - int x; - - ECellTextView *text_view = cell->text_view; - ECellText *ect = E_CELL_TEXT (((ECellView *)cell->text_view)->ecell); - - x = text_view->xofs + ect->x; - - switch (ect->justify) { - case GTK_JUSTIFY_RIGHT: - x += cell->width - line->width; - break; - - case GTK_JUSTIFY_CENTER: - x += (cell->width - line->width) / 2; - break; - - default: - /* For GTK_JUSTIFY_LEFT, we don't have to do anything. We do not support - * GTK_JUSTIFY_FILL, yet. - */ - break; - } - - return x; -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static int -get_line_ypos (CurrentCell *cell, struct line *line) -{ - int y; - - ECellTextView *text_view = cell->text_view; - ECellText *ect = E_CELL_TEXT (((ECellView *)cell->text_view)->ecell); - ECellTextLineBreaks *linebreaks = cell->breaks; - - struct line *lines = linebreaks->lines; - - EFont *font; - - font = text_view->font; - - y = text_view->yofs + ect->y; - y += (line - lines) * e_font_height (font); - - return y; -} - -/* fixme: Handle Font attributes */ -/* position is in BYTES */ - -static void -_get_xy_from_position (CurrentCell *cell, gint position, gint *xp, gint *yp) -{ - if (xp || yp) { - struct line *lines; - int x, y; - int j; - ECellTextView *text_view = cell->text_view; - ECellTextLineBreaks *linebreaks; - EFont *font; - - font = text_view->font; - - split_into_lines (cell); - - linebreaks = cell->breaks; - lines = linebreaks->lines; - - x = get_line_xpos (cell, lines); - y = get_line_ypos (cell, lines); - for (j = 0, lines = linebreaks->lines; j < linebreaks->num_lines; lines++, j++) { - if (lines->text > cell->text + position) - break; - y += e_font_height (font); - } - lines --; - y -= e_font_descent (font); - - x += e_font_utf8_text_width (font, E_FONT_PLAIN, - lines->text, - position - (lines->text - cell->text)); - if ((CellEdit *) cell == cell->text_view->edit){ - x -= ((CellEdit *)cell)->xofs_edit; - y -= ((CellEdit *)cell)->yofs_edit; - } - if (xp) - *xp = x; - if (yp) - *yp = y; - unref_lines (cell); - } -} - -static gint -_get_position_from_xy (CurrentCell *cell, gint x, gint y) -{ - int i, j; - int xpos, ypos; - struct line *lines; - int return_val; - gchar *p; - - ECellTextView *text_view = cell->text_view; - ECellTextLineBreaks *linebreaks; - EFont *font; - - font = text_view->font; - - split_into_lines (cell); - - linebreaks = cell->breaks; - - lines = linebreaks->lines; - - if ((CellEdit *) cell == cell->text_view->edit){ - x += ((CellEdit *)cell)->xofs_edit; - y += ((CellEdit *)cell)->yofs_edit; - } - - ypos = get_line_ypos (cell, linebreaks->lines); - j = 0; - while (y > ypos) { - ypos += e_font_height (font); - j ++; - } - j--; - if (j >= linebreaks->num_lines) - j = linebreaks->num_lines - 1; - if (j < 0) - j = 0; - i = 0; - - lines += j; - xpos = get_line_xpos (cell, lines); - - for (p = lines->text; p < lines->text + lines->length; p = unicode_next_utf8 (p)) { - gint charwidth; - - charwidth = e_font_utf8_char_width (font, E_FONT_PLAIN, p); - - xpos += charwidth / 2; - if (xpos > x) { - break; - } - xpos += (charwidth + 1) / 2; - } - - return_val = p - cell->text; - - unref_lines (cell); - - return return_val; -} - -#define SCROLL_WAIT_TIME 30000 - -static gboolean -_blink_scroll_timeout (gpointer data) -{ - CurrentCell *cell = CURRENT_CELL(data); - ECellTextView *text_view = (ECellTextView *) data; - ECellText *ect = E_CELL_TEXT (((ECellView *)text_view)->ecell); - CellEdit *edit = text_view->edit; - ECellTextLineBreaks *linebreaks = cell->breaks; - - gulong current_time; - gboolean scroll = FALSE; - gboolean redraw = FALSE; - - g_timer_elapsed (edit->timer, ¤t_time); - - if (edit->scroll_start + SCROLL_WAIT_TIME > 1000000) { - if (current_time > edit->scroll_start - (1000000 - SCROLL_WAIT_TIME) && - current_time < edit->scroll_start) - scroll = TRUE; - } else { - if (current_time > edit->scroll_start + SCROLL_WAIT_TIME || - current_time < edit->scroll_start) - scroll = TRUE; - } - if (scroll && edit->button_down) { - /* FIXME: Copy this for y. */ - if (edit->lastx - ect->x > cell->width && - edit->xofs_edit < linebreaks->max_width - cell->width) { - edit->xofs_edit += 4; - if (edit->xofs_edit > linebreaks->max_width - cell->width + 1) - edit->xofs_edit = linebreaks->max_width - cell->width + 1; - redraw = TRUE; - } - if (edit->lastx - ect->x < 0 && - edit->xofs_edit > 0) { - edit->xofs_edit -= 4; - if (edit->xofs_edit < 0) - edit->xofs_edit = 0; - redraw = TRUE; - } - if (redraw) { - ETextEventProcessorEvent e_tep_event; - e_tep_event.type = GDK_MOTION_NOTIFY; - e_tep_event.motion.state = edit->last_state; - e_tep_event.motion.time = 0; - e_tep_event.motion.position = _get_position_from_xy (cell, edit->lastx, edit->lasty); - _get_tep (edit); - e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - edit->scroll_start = current_time; - } - } - - if (!((current_time / 500000) % 2)) { - if (!edit->show_cursor) - redraw = TRUE; - edit->show_cursor = TRUE; - } else { - if (edit->show_cursor) - redraw = TRUE; - edit->show_cursor = FALSE; - } - if (redraw){ - ect_queue_redraw (text_view, edit->cell.view_col, edit->cell.row); - } - return TRUE; -} - -static int -_get_position (ECellTextView *text_view, ETextEventProcessorCommand *command) -{ - int length; - int x, y; - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - EFont *font; - gchar *p; - int unival; - - font = text_view->font; - - switch (command->position) { - - case E_TEP_VALUE: - return command->value; - - case E_TEP_SELECTION: - return edit->selection_end; - - case E_TEP_START_OF_BUFFER: - return 0; - - /* fixme: this probably confuses TEP */ - - case E_TEP_END_OF_BUFFER: - return strlen (cell->text); - - case E_TEP_START_OF_LINE: - - if (edit->selection_end < 1) return 0; - - p = unicode_previous_utf8 (cell->text, cell->text + edit->selection_end); - - if (p == cell->text) return 0; - - p = unicode_previous_utf8 (cell->text, p); - - while (p && p > cell->text) { - if (*p == '\n') return p - cell->text + 1; - p = unicode_previous_utf8 (cell->text, p); - } - - return 0; - - case E_TEP_END_OF_LINE: - - length = strlen (cell->text); - if (edit->selection_end >= length) return length; - - p = unicode_next_utf8 (cell->text + edit->selection_end); - - while (*p) { - if (*p == '\n') return p - cell->text; - p = unicode_next_utf8 (p); - } - - return p - cell->text; - - case E_TEP_FORWARD_CHARACTER: - - length = strlen (cell->text); - if (edit->selection_end >= length) return length; - - p = unicode_next_utf8 (cell->text + edit->selection_end); - - return p - cell->text; - - case E_TEP_BACKWARD_CHARACTER: - - if (edit->selection_end < 1) return 0; - - p = unicode_previous_utf8 (cell->text, cell->text + edit->selection_end); - - if (p == NULL) return 0; - - return p - cell->text; - - case E_TEP_FORWARD_WORD: - - length = strlen (cell->text); - if (edit->selection_end >= length) return length; - - p = unicode_next_utf8 (cell->text + edit->selection_end); - - while (*p) { - unicode_get_utf8 (p, &unival); - if (unicode_isspace (unival)) return p - cell->text; - p = unicode_next_utf8 (p); - } - - return p - cell->text; - - case E_TEP_BACKWARD_WORD: - - if (edit->selection_end < 1) return 0; - - p = unicode_previous_utf8 (cell->text, cell->text + edit->selection_end); - - if (p == cell->text) return 0; - - p = unicode_previous_utf8 (cell->text, p); - - while (p && p > cell->text) { - unicode_get_utf8 (p, &unival); - if (unicode_isspace (unival)) { - return (unicode_next_utf8 (p) - cell->text); - } - p = unicode_previous_utf8 (cell->text, p); - } - - return 0; - - case E_TEP_FORWARD_LINE: - _get_xy_from_position (cell, edit->selection_end, &x, &y); - y += e_font_height (font); - return _get_position_from_xy (cell, x, y); - case E_TEP_BACKWARD_LINE: - _get_xy_from_position (cell, edit->selection_end, &x, &y); - y -= e_font_height (font); - return _get_position_from_xy (cell, x, y); - - case E_TEP_FORWARD_PARAGRAPH: - case E_TEP_BACKWARD_PARAGRAPH: - - case E_TEP_FORWARD_PAGE: - case E_TEP_BACKWARD_PAGE: - return edit->selection_end; - default: - return edit->selection_end; - } - g_assert_not_reached (); - return 0; /* Kill warning */ -} - -static void -_delete_selection (ECellTextView *text_view) -{ - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - gint length; - gchar *sp, *ep; - - if (edit->selection_end == edit->selection_start) return; - - if (edit->selection_end < edit->selection_start) { - edit->selection_end ^= edit->selection_start; - edit->selection_start ^= edit->selection_end; - edit->selection_end ^= edit->selection_start; - } - - sp = cell->text + edit->selection_start; - ep = cell->text + edit->selection_end; - length = strlen (ep) + 1; - - memmove (sp, ep, length); - - edit->selection_end = edit->selection_start; -} - -/* fixme: */ -/* NB! We expect value to be length IN BYTES */ - -static void -_insert (ECellTextView *text_view, char *string, int value) -{ - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - char *temp; - - if (value <= 0) return; - - temp = g_new (gchar, strlen (cell->text) + value + 1); - - strncpy (temp, cell->text, edit->selection_start); - strncpy (temp + edit->selection_start, string, value); - strcpy (temp + edit->selection_start + value, cell->text + edit->selection_end); - - g_free (cell->text); - - cell->text = temp; - - edit->selection_start += value; - edit->selection_end = edit->selection_start; -} - -static void -e_cell_text_view_command (ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data) -{ - CellEdit *edit = (CellEdit *) data; - CurrentCell *cell = CURRENT_CELL(edit); - ECellTextView *text_view = cell->text_view; - - gboolean change = FALSE; - gboolean redraw = FALSE; - - int sel_start, sel_end; - EFont *font; - - font = text_view->font; - - switch (command->action) { - case E_TEP_MOVE: - edit->selection_start = _get_position (text_view, command); - edit->selection_end = edit->selection_start; - if (edit->timer) { - g_timer_reset (edit->timer); - } - redraw = TRUE; - break; - case E_TEP_SELECT: - edit->selection_end = _get_position (text_view, command); - sel_start = MIN(edit->selection_start, edit->selection_end); - sel_end = MAX(edit->selection_start, edit->selection_end); - if (sel_start != sel_end) { - e_cell_text_view_supply_selection (edit, command->time, GDK_SELECTION_PRIMARY, - cell->text + sel_start, - sel_end - sel_start); - } else if (edit->timer) { - g_timer_reset (edit->timer); - } - redraw = TRUE; - break; - case E_TEP_DELETE: - if (edit->selection_end == edit->selection_start) { - edit->selection_end = _get_position (text_view, command); - } - _delete_selection (text_view); - if (edit->timer) { - g_timer_reset (edit->timer); - } - redraw = TRUE; - change = TRUE; - break; - - case E_TEP_INSERT: - if (edit->selection_end != edit->selection_start) { - _delete_selection (text_view); - } - _insert (text_view, command->string, command->value); - if (edit->timer) { - g_timer_reset (edit->timer); - } - redraw = TRUE; - change = TRUE; - break; - case E_TEP_COPY: - sel_start = MIN(edit->selection_start, edit->selection_end); - sel_end = MAX(edit->selection_start, edit->selection_end); - if (sel_start != sel_end) { - e_cell_text_view_supply_selection (edit, command->time, clipboard_atom, - cell->text + sel_start, - sel_end - sel_start); - } - if (edit->timer) { - g_timer_reset (edit->timer); - } - break; - case E_TEP_PASTE: - e_cell_text_view_get_selection (edit, clipboard_atom, command->time); - if (edit->timer) { - g_timer_reset (edit->timer); - } - redraw = TRUE; - change = TRUE; - break; - case E_TEP_GET_SELECTION: - e_cell_text_view_get_selection (edit, GDK_SELECTION_PRIMARY, command->time); - break; - case E_TEP_ACTIVATE: - e_table_item_leave_edit (text_view->cell_view.e_table_item_view); - break; - case E_TEP_SET_SELECT_BY_WORD: - edit->select_by_word = command->value; - break; - case E_TEP_GRAB: - case E_TEP_UNGRAB: -#if 0 - case E_TEP_GRAB: - gnome_canvas_item_grab (GNOME_CANVAS_ITEM(text), - GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, - text_view->i_cursor, - command->time); - break; - gnome_canvas_item_ungrab (GNOME_CANVAS_ITEM(text), command->time); - break; -#endif - case E_TEP_NOP: - break; - } - - if (!edit->button_down) { - int x; - int i; - struct line *lines; - ECellTextLineBreaks *linebreaks; - - split_into_lines (cell); - - linebreaks = cell->breaks; - - for (lines = linebreaks->lines, i = 0; i < linebreaks->num_lines ; i++, lines ++) { - if ((lines->text - cell->text) > edit->selection_end) { - break; - } - } - lines --; - x = e_font_utf8_text_width (font, E_FONT_PLAIN, - lines->text, - edit->selection_end - (lines->text - cell->text)); - - - if (x < edit->xofs_edit) { - edit->xofs_edit = x; - redraw = TRUE; - } - - if (2 + x - cell->width > edit->xofs_edit) { - edit->xofs_edit = 2 + x - cell->width; - redraw = TRUE; - } - unref_lines (cell); - } - - if (redraw){ - ect_queue_redraw (text_view, edit->cell.view_col, edit->cell.row); - } -#if 0 - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); -#endif -} - -static void _invisible_destroy (GtkInvisible *invisible, - CellEdit *edit) -{ - edit->invisible = NULL; -} - -static GtkWidget *e_cell_text_view_get_invisible (CellEdit *edit) -{ - GtkWidget *invisible; - if (edit->invisible) { - invisible = edit->invisible; - } else { - invisible = gtk_invisible_new (); - edit->invisible = invisible; - - gtk_selection_add_target (invisible, - GDK_SELECTION_PRIMARY, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_PRIMARY); - gtk_selection_add_target (invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_CLIPBOARD); - - gtk_signal_connect (GTK_OBJECT(invisible), "selection_get", - GTK_SIGNAL_FUNC (_selection_get), - edit); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_clear_event", - GTK_SIGNAL_FUNC (_selection_clear_event), - edit); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_received", - GTK_SIGNAL_FUNC (_selection_received), - edit); - - gtk_signal_connect (GTK_OBJECT(invisible), "destroy", - GTK_SIGNAL_FUNC (_invisible_destroy), - edit); - } - return invisible; -} - -static void -_selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - CellEdit *edit) -{ - if (event->selection == GDK_SELECTION_PRIMARY) { - g_free (edit->primary_selection); - edit->primary_selection = NULL; - edit->primary_length = 0; - - edit->has_selection = FALSE; -#if 0 - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); -#endif - - } else if (event->selection == clipboard_atom) { - g_free (edit->clipboard_selection); - edit->clipboard_selection = NULL; - edit->clipboard_length = 0; - } -} - -static void -_selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - CellEdit *edit) -{ - switch (info) { - case E_SELECTION_PRIMARY: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, edit->primary_selection, edit->primary_length); - break; - case E_SELECTION_CLIPBOARD: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, edit->clipboard_selection, edit->clipboard_length); - break; - } -} - -/* fixme: What happens, if delivered string is not UTF-8? */ - -static void -_selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - CellEdit *edit) -{ - if (selection_data->length < 0 || selection_data->type != GDK_SELECTION_TYPE_STRING) { - return; - } else { - ETextEventProcessorCommand command; - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.string = selection_data->data; - command.value = selection_data->length; - command.time = time; - e_cell_text_view_command (edit->tep, &command, edit); - } -} - -static void e_cell_text_view_supply_selection (CellEdit *edit, guint time, GdkAtom selection, char *data, gint length) -{ - gboolean successful; - GtkWidget *invisible; - - invisible = e_cell_text_view_get_invisible (edit); - - if (selection == GDK_SELECTION_PRIMARY){ - if (edit->primary_selection) { - g_free (edit->primary_selection); - } - edit->primary_selection = g_strndup (data, length); - edit->primary_length = length; - } else if (selection == clipboard_atom) { - if (edit->clipboard_selection) { - g_free (edit->clipboard_selection); - } - edit->clipboard_selection = g_strndup (data, length); - edit->clipboard_length = length; - } - - successful = gtk_selection_owner_set (invisible, - selection, - time); - - if (selection == GDK_SELECTION_PRIMARY) - edit->has_selection = successful; -} - -static void -e_cell_text_view_get_selection (CellEdit *edit, GdkAtom selection, guint32 time) -{ - GtkWidget *invisible; - invisible = e_cell_text_view_get_invisible (edit); - gtk_selection_convert (invisible, - selection, - GDK_SELECTION_TYPE_STRING, - time); -} - -static void -_get_tep (CellEdit *edit) -{ - if (!edit->tep) { - edit->tep = e_text_event_processor_emacs_like_new (); - gtk_object_ref (GTK_OBJECT (edit->tep)); - gtk_object_sink (GTK_OBJECT (edit->tep)); - gtk_signal_connect (GTK_OBJECT(edit->tep), - "command", - GTK_SIGNAL_FUNC(e_cell_text_view_command), - (gpointer) edit); - } -} - -static int -number_of_lines (char *text) -{ - int num_lines = 0; - gchar *p; - - if (!text) return 0; - - for (p = text; *p; p = unicode_next_utf8 (p)) { - if (*p == '\n') num_lines++; - } - - num_lines++; - return num_lines; -} - -/* Splits the text of the text item into lines */ -static void -split_into_lines (CurrentCell *cell) -{ - char *p; - struct line *lines; - gint len; - - char *text = cell->text; - ECellTextLineBreaks *linebreaks = cell->breaks; - - if (! cell->breaks) { - cell->breaks = g_new (ECellTextLineBreaks, 1); - cell->breaks->ref_count = 1; - } else { - cell->breaks->ref_count ++; - return; - } - linebreaks = cell->breaks; - - /* Check if already split. */ - - linebreaks->lines = NULL; - linebreaks->num_lines = 0; - - if (!text) - return; - - /* First, count the number of lines */ - - linebreaks->num_lines = number_of_lines(cell->text); - - /* Allocate array of lines and calculate split positions */ - - linebreaks->lines = lines = g_new0 (struct line, linebreaks->num_lines); - - len = 0; - for (p = text; *p; p = unicode_next_utf8 (p)) { - if (len == 0) lines->text = p; - if (*p == '\n') { - lines->length = p - lines->text; - lines++; - len = 0; - } else - len++; - } - - if (len == 0) - lines->text = p; - lines->length = p - lines->text; - - calc_line_widths (cell); -} - -/* Free lines structure. */ -static void -unref_lines (CurrentCell *cell) -{ - if (cell->breaks){ - cell->breaks->ref_count --; - if (cell->breaks->ref_count <= 0){ - g_free (cell->breaks->lines); - g_free (cell->breaks); - cell->breaks = NULL; - } - } -} - -static void -calc_ellipsis (ECellTextView *text_view) -{ - ECellText *ect = E_CELL_TEXT (((ECellView *)text_view)->ecell); - EFont *font; - - font = text_view->font; - if (font) - text_view->ellipsis_width = - e_font_utf8_text_width (font, E_FONT_PLAIN, - ect->ellipsis ? ect->ellipsis : "...", - ect->ellipsis ? strlen (ect->ellipsis) : 3); -} - -/* Calculates the line widths (in pixels) of the text's splitted lines */ -static void -calc_line_widths (CurrentCell *cell) -{ - ECellTextView *text_view = cell->text_view; - ECellText *ect = E_CELL_TEXT (((ECellView *)text_view)->ecell); - ECellTextLineBreaks *linebreaks = cell->breaks; - struct line *lines; - int i; - int j; - EFont *font; - - font = text_view->font; - - lines = linebreaks->lines; - linebreaks->max_width = 0; - - if (!lines) return; - - for (i = 0; i < linebreaks->num_lines; i++) { - if (lines->length != 0) { - if (font) { - lines->width = e_font_utf8_text_width (font, E_FONT_PLAIN, - lines->text, lines->length); - lines->ellipsis_length = 0; - } else { - lines->width = 0; - } - - if (ect->use_ellipsis && - (!(text_view->edit && - cell->row == text_view->edit->cell.row && - cell->view_col == text_view->edit->cell.view_col)) && - lines->width > cell->width) { - if (font) { - lines->ellipsis_length = 0; - for (j = 0; j < lines->length; j++){ - if (e_font_utf8_text_width (font, E_FONT_PLAIN, lines->text, j) + - text_view->ellipsis_width <= cell->width) - lines->ellipsis_length = j; - else - break; - } - } - else - lines->ellipsis_length = 0; - lines->width = e_font_utf8_text_width (font, E_FONT_PLAIN, lines->text, lines->ellipsis_length) + - text_view->ellipsis_width; - } - else - lines->ellipsis_length = lines->length; - - if (lines->width > linebreaks->max_width) - linebreaks->max_width = lines->width; - } else { - lines->width = 0; - lines->ellipsis_length = 0; - } - - lines++; - } -} - -static void -build_current_cell (CurrentCell *cell, ECellTextView *text_view, int model_col, int view_col, int row) -{ - ECellView *ecell_view = (ECellView *) text_view; - ECellText *ect = E_CELL_TEXT (ecell_view->ecell); - - cell->text_view = text_view; - cell->model_col = model_col; - cell->view_col = view_col; - cell->row = row; - cell->breaks = NULL; - - if (ect->filter) { - cell->text = (*ect->filter)(e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - } else { - cell->text = g_strdup (e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - } - cell->width = e_table_header_get_column ( - ((ETableItem *)ecell_view->e_table_item_view)->header, - view_col)->width - 8; -} - -static void -unbuild_current_cell (CurrentCell *cell) -{ - g_free(cell->text); - cell->text = NULL; -} - - -static GdkColor* -e_cell_text_get_color (ECellTextView *cell_view, gchar *color_spec) -{ - ECellText *ect = E_CELL_TEXT (((ECellView*) cell_view)->ecell); - GdkColormap *colormap; - GdkColor *color, tmp_color; - - /* If the color spec is NULL we use the default color. */ - if (color_spec == NULL) - return NULL; - - /* Create the hash table if we haven't already. */ - if (!ect->colors) - ect->colors = g_hash_table_new (g_str_hash, g_str_equal); - - /* See if we've already allocated the color. Note that we use a - special value of (GdkColor*) 1 in the hash to indicate that we've - already tried and failed to allocate the color, so we don't keep - trying to allocate it. */ - color = g_hash_table_lookup (ect->colors, color_spec); - if (color == (GdkColor*) 1) - return NULL; - if (color) - return color; - - /* Try to parse the color. */ - if (gdk_color_parse (color_spec, &tmp_color)) { - colormap = gtk_widget_get_colormap (GTK_WIDGET (cell_view->canvas)); - - /* Try to allocate the color. */ - if (gdk_color_alloc (colormap, &tmp_color)) - color = gdk_color_copy (&tmp_color); - } - - g_hash_table_insert (ect->colors, g_strdup (color_spec), - color ? color : (GdkColor*) 1); - return color; -} - diff --git a/widgets/e-table/e-cell-text.h b/widgets/e-table/e-cell-text.h deleted file mode 100644 index e0296998b3..0000000000 --- a/widgets/e-table/e-cell-text.h +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ECellText - Text item for e-table. - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * Drawing and event handling from: - * - * EText - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey <clahey@helixcode.com> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> */ -#ifndef _E_CELL_TEXT_H_ -#define _E_CELL_TEXT_H_ - -#include <libgnomeui/gnome-canvas.h> -#include "e-cell.h" - -/* Should return a malloced object. */ -typedef char *(*ECellTextFilter) (const void *); - -#define E_CELL_TEXT_TYPE (e_cell_text_get_type ()) -#define E_CELL_TEXT(o) (GTK_CHECK_CAST ((o), E_CELL_TEXT_TYPE, ECellText)) -#define E_CELL_TEXT_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_TEXT_TYPE, ECellTextClass)) -#define E_IS_CELL_TEXT(o) (GTK_CHECK_TYPE ((o), E_CELL_TEXT_TYPE)) -#define E_IS_CELL_TEXT_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_TEXT_TYPE)) - -typedef struct { - ECell parent; - - GtkJustification justify; - char *font_name; - - double x, y; /* Position at anchor */ - - gulong pixel; /* Fill color */ - - /* Clip handling */ - char *ellipsis; /* The ellipsis characters. NULL = "...". */ - - guint use_ellipsis : 1; /* Whether to use the ellipsis. */ - - int strikeout_column; - int bold_column; - - /* This column in the ETable should return a string specifying a color, - either a color name like "red" or a color spec like "rgb:F/0/0". - See the XParseColor man page for the formats available. */ - int color_column; - - ECellTextFilter filter; - - /* This stores the colors we have allocated. */ - GHashTable *colors; -} ECellText; - -typedef struct { - ECellClass parent_class; -} ECellTextClass; - -GtkType e_cell_text_get_type (void); -ECell *e_cell_text_new (ETableModel *model, const char *fontname, GtkJustification justify); - -#endif /* _E_CELL_TEXT_H_ */ - - diff --git a/widgets/e-table/e-cell-toggle.c b/widgets/e-table/e-cell-toggle.c deleted file mode 100644 index 1be01348db..0000000000 --- a/widgets/e-table/e-cell-toggle.c +++ /dev/null @@ -1,289 +0,0 @@ -/* - * e-cell-toggle.c: Multi-state image toggle cell object. - * - * Author: - * Miguel de Icaza (miguel@kernel.org) - * - * (C) 1999, 2000 Helix Code, Inc - */ -#include <config.h> -#include <gtk/gtkenums.h> -#include <gtk/gtkentry.h> -#include <gtk/gtkwindow.h> -#include <gtk/gtksignal.h> -#include <gdk/gdkkeysyms.h> -#include <libgnomeui/gnome-canvas.h> -#include "e-cell-toggle.h" -#include "e-util/e-util.h" -#include "e-table-item.h" - -#define PARENT_TYPE e_cell_get_type () - -typedef struct { - ECellView cell_view; - GdkGC *gc; - GnomeCanvas *canvas; -} ECellToggleView; - -static ECellClass *parent_class; - -static void -etog_queue_redraw (ECellToggleView *text_view, int view_col, int view_row) -{ - e_table_item_redraw_range ( - text_view->cell_view.e_table_item_view, - view_col, view_row, view_col, view_row); -} - -/* - * ECell::realize method - */ -static ECellView * -etog_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - ECellToggleView *toggle_view = g_new0 (ECellToggleView, 1); - ETableItem *eti = E_TABLE_ITEM (e_table_item_view); - GnomeCanvas *canvas = GNOME_CANVAS_ITEM (eti)->canvas; - - toggle_view->cell_view.ecell = ecell; - toggle_view->cell_view.e_table_model = table_model; - toggle_view->cell_view.e_table_item_view = e_table_item_view; - toggle_view->canvas = canvas; - - return (ECellView *) toggle_view; -} - -static void -etog_kill_view (ECellView *ecell_view) -{ - g_free (ecell_view); -} - -static void -etog_realize (ECellView *ecell_view) -{ - ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; - - toggle_view->gc = gdk_gc_new (GTK_WIDGET (toggle_view->canvas)->window); -} - -/* - * ECell::unrealize method - */ -static void -etog_unrealize (ECellView *ecv) -{ - ECellToggleView *toggle_view = (ECellToggleView *) ecv; - - gdk_gc_unref (toggle_view->gc); - toggle_view->gc = NULL; -} - -/* - * ECell::draw method - */ -static void -etog_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, gboolean selected, - int x1, int y1, int x2, int y2) -{ - ECellToggle *toggle = E_CELL_TOGGLE (ecell_view->ecell); -#if 0 - ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; -#endif - GdkPixbuf *image; - int x, y, width, height; - - const int value = GPOINTER_TO_INT ( - e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - - if (value >= toggle->n_states){ - g_warning ("Value from the table model is %d, the states we support are [0..%d)\n", - value, toggle->n_states); - return; - } - - image = toggle->images [value]; - - if ((x2 - x1) < gdk_pixbuf_get_width (image)){ - x = x1; - width = x2 - x1; - } else { - x = x1 + ((x2 - x1) - gdk_pixbuf_get_width (image)) / 2; - width = gdk_pixbuf_get_width (image); - } - - if ((y2 - y1) < gdk_pixbuf_get_height (image)){ - y = y1; - height = y2 - y1; - } else { - y = y1 + ((y2 - y1) - gdk_pixbuf_get_height (image)) / 2; - height = gdk_pixbuf_get_height (image); - } - -#if 0 /* do alpha */ - if (gdk_pixbuf_get_has_alpha (image)) { - flat = gdk_pixbuf_composite_color_simple ( - image, - gdk_pixbuf_get_width (image), - gdk_pixbuf_get_height (image), - GDK_INTERP_NEAREST, - 255, - 32, - 0xffffff, 0xffffff); - - gdk_pixbuf_render_to_drawable (flat, drawable, - toggle_view->gc, - 0, 0, - x, y, - width, height, - GDK_RGB_DITHER_NORMAL, - 0, 0); - gdk_pixbuf_unref (flat); - } else { - gdk_pixbuf_render_to_drawable (image, drawable, - toggle_view->gc, - 0, 0, - x, y, - width, height, - GDK_RGB_DITHER_NORMAL, - 0, 0); - } -#else - gdk_pixbuf_render_to_drawable_alpha (image, drawable, - 0, 0, - x, y, - width, height, - GDK_PIXBUF_ALPHA_BILEVEL, - 128, - GDK_RGB_DITHER_NORMAL, - x, y); -#endif -} - -static void -etog_set_value (ECellToggleView *toggle_view, int model_col, int view_col, int row, int value) -{ - ECell *ecell = toggle_view->cell_view.ecell; - ECellToggle *toggle = E_CELL_TOGGLE (ecell); - - if (value >= toggle->n_states) - value = 0; - - e_table_model_set_value_at (toggle_view->cell_view.e_table_model, - model_col, row, GINT_TO_POINTER (value)); - etog_queue_redraw (toggle_view, view_col, row); -} - -/* - * ECell::event method - */ -static gint -etog_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row) -{ - ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; - void *_value = e_table_model_value_at (ecell_view->e_table_model, model_col, row); - const int value = GPOINTER_TO_INT (_value); - - switch (event->type){ - case GDK_BUTTON_RELEASE: - if (!e_table_model_is_cell_editable(ecell_view->e_table_model, model_col, row)) - return FALSE; - - etog_set_value (toggle_view, model_col, view_col, row, value + 1); - return TRUE; - - case GDK_KEY_PRESS: - if (!e_table_model_is_cell_editable(ecell_view->e_table_model, model_col, row)) - return FALSE; - - if (event->key.keyval == GDK_space){ - etog_set_value (toggle_view, model_col, view_col, row, value + 1); - return TRUE; - } - return FALSE; - - default: - return FALSE; - } - return TRUE; -} - -/* - * ECell::height method - */ -static int -etog_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - ECellToggle *toggle = E_CELL_TOGGLE (ecell_view->ecell); - - return toggle->height; -} - -static void -etog_destroy (GtkObject *object) -{ - ECellToggle *etog = E_CELL_TOGGLE (object); - int i; - - for (i = 0; i < etog->n_states; i++) - gdk_pixbuf_unref (etog->images [i]); - - g_free (etog->images); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -static void -e_cell_toggle_class_init (GtkObjectClass *object_class) -{ - ECellClass *ecc = (ECellClass *) object_class; - - object_class->destroy = etog_destroy; - - ecc->new_view = etog_new_view; - ecc->kill_view = etog_kill_view; - ecc->realize = etog_realize; - ecc->unrealize = etog_unrealize; - ecc->draw = etog_draw; - ecc->event = etog_event; - ecc->height = etog_height; - - parent_class = gtk_type_class (PARENT_TYPE); -} - -E_MAKE_TYPE(e_cell_toggle, "ECellToggle", ECellToggle, e_cell_toggle_class_init, NULL, PARENT_TYPE); - -void -e_cell_toggle_construct (ECellToggle *etog, int border, int n_states, GdkPixbuf **images) -{ - int max_height = 0; - int i; - - etog->border = border; - etog->n_states = n_states; - - etog->images = g_new (GdkPixbuf *, n_states); - - for (i = 0; i < n_states; i++){ - etog->images [i] = images [i]; - gdk_pixbuf_ref (images [i]); - - if (gdk_pixbuf_get_height (images [i]) > max_height) - max_height = gdk_pixbuf_get_height (images [i]); - } - - etog->height = max_height; -} - -ECell * -e_cell_toggle_new (int border, int n_states, GdkPixbuf **images) -{ - ECellToggle *etog = gtk_type_new (e_cell_toggle_get_type ()); - - e_cell_toggle_construct (etog, border, n_states, images); - - return (ECell *) etog; -} - - diff --git a/widgets/e-table/e-cell-toggle.h b/widgets/e-table/e-cell-toggle.h deleted file mode 100644 index d5773b454a..0000000000 --- a/widgets/e-table/e-cell-toggle.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _E_CELL_TOGGLE_H_ -#define _E_CELL_TOGGLE_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gdk-pixbuf/gdk-pixbuf.h> -#include "e-cell.h" - -#define E_CELL_TOGGLE_TYPE (e_cell_toggle_get_type ()) -#define E_CELL_TOGGLE(o) (GTK_CHECK_CAST ((o), E_CELL_TOGGLE_TYPE, ECellToggle)) -#define E_CELL_TOGGLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_TOGGLE_TYPE, ECellToggleClass)) -#define E_IS_CELL_TOGGLE(o) (GTK_CHECK_TYPE ((o), E_CELL_TOGGLE_TYPE)) -#define E_IS_CELL_TOGGLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_TOGGLE_TYPE)) - -typedef struct { - ECell parent; - - int border; - int n_states; - GdkPixbuf **images; - - int height; -} ECellToggle; - -typedef struct { - ECellClass parent_class; -} ECellToggleClass; - -GtkType e_cell_toggle_get_type (void); -ECell *e_cell_toggle_new (int border, int n_states, GdkPixbuf **images); -void e_cell_toggle_construct (ECellToggle *etog, int border, - int n_states, GdkPixbuf **images); - -#endif /* _E_CELL_TOGGLE_H_ */ - - diff --git a/widgets/e-table/e-cell-tree.c b/widgets/e-table/e-cell-tree.c deleted file mode 100644 index d4106271e6..0000000000 --- a/widgets/e-table/e-cell-tree.c +++ /dev/null @@ -1,542 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-cell-tree.c - Tree cell renderer - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Toshok <toshok@helixcode.com> - * - * A majority of code taken from: - * - * the ECellText renderer. - * - * Copyright (C) 1998 The Free Software Foundation - * - */ - -#include <config.h> -#include <gtk/gtkenums.h> -#include <gtk/gtkentry.h> -#include <gtk/gtkwindow.h> -#include <gtk/gtkinvisible.h> -#include <gtk/gtksignal.h> -#include <gdk/gdkkeysyms.h> -#include <libgnomeui/gnome-canvas.h> -#include <stdio.h> -#include "e-table-sorted-variable.h" -#include "e-tree-model.h" -#include "e-cell-tree.h" -#include "e-util/e-util.h" -#include "e-table-item.h" - -#include <gdk/gdkx.h> /* for BlackPixel */ -#include <ctype.h> -#include <math.h> - -#define PARENT_TYPE e_cell_get_type () - -typedef struct { - ECellView cell_view; - ECellView *subcell_view; - GdkGC *gc; - - GnomeCanvas *canvas; - -} ECellTreeView; - -static ECellClass *parent_class; - -#define INDENT_AMOUNT 16 - -static int -visible_depth_of_node (ETreeModel *tree_model, ETreePath *path) -{ - return (e_tree_model_node_depth (tree_model, path) - - (e_tree_model_root_node_is_visible (tree_model) ? 0 : 1)); -} - -static gint -offset_of_node (ETreeModel *tree_model, ETreePath *path) -{ - return (visible_depth_of_node(tree_model, path) + 1) * INDENT_AMOUNT; -} - -static ETreePath* -e_cell_tree_get_node (ETreeModel *tree_model, int row) -{ - return (ETreePath*)e_table_model_value_at (E_TABLE_MODEL(tree_model), -1, row); -} - -static ETreeModel* -e_cell_tree_get_tree_model (ETableModel *table_model, int row) -{ - return (ETreeModel*)e_table_model_value_at (table_model, -2, row); -} - -/* - * ECell::new_view method - */ -static ECellView * -ect_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - ECellTree *ect = E_CELL_TREE (ecell); - ECellTreeView *tree_view = g_new0 (ECellTreeView, 1); - GnomeCanvas *canvas = GNOME_CANVAS_ITEM (e_table_item_view)->canvas; - - tree_view->cell_view.ecell = ecell; - tree_view->cell_view.e_table_model = table_model; - tree_view->cell_view.e_table_item_view = e_table_item_view; - - /* create our subcell view */ - tree_view->subcell_view = e_cell_new_view (ect->subcell, table_model, e_table_item_view /* XXX */); - - tree_view->canvas = canvas; - - return (ECellView *)tree_view; -} - -/* - * ECell::kill_view method - */ -static void -ect_kill_view (ECellView *ecv) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecv; - - /* kill our subcell view */ - e_cell_kill_view (tree_view->subcell_view); - - g_free (tree_view); -} - -/* - * ECell::realize method - */ -static void -ect_realize (ECellView *ecell_view) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - - /* realize our subcell view */ - e_cell_realize (tree_view->subcell_view); - - tree_view->gc = gdk_gc_new (GTK_WIDGET (tree_view->canvas)->window); - - gdk_gc_set_line_attributes (tree_view->gc, 1, - GDK_LINE_ON_OFF_DASH, None, None); - gdk_gc_set_dashes (tree_view->gc, 0, "\1\1", 2); - - if (parent_class->realize) - (* parent_class->realize) (ecell_view); -} - -/* - * ECell::unrealize method - */ -static void -ect_unrealize (ECellView *ecv) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecv; - - /* unrealize our subcell view. */ - e_cell_unrealize (tree_view->subcell_view); - - gdk_gc_unref (tree_view->gc); - tree_view->gc = NULL; - - if (parent_class->unrealize) - (* parent_class->unrealize) (ecv); -} - -/* - * ECell::draw method - */ -static void -ect_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, gboolean selected, - int x1, int y1, int x2, int y2) -{ - ECellTreeView *tree_view = (ECellTreeView *)ecell_view; - ETreeModel *tree_model = e_cell_tree_get_tree_model(ecell_view->e_table_model, row); - ETreePath *node; - GdkRectangle rect, *clip_rect; - GtkWidget *canvas = GTK_WIDGET (tree_view->canvas); - GdkGC *fg_gc = canvas->style->fg_gc[GTK_STATE_ACTIVE]; - GdkColor *foreground; - - int offset, subcell_offset; - gboolean expanded, expandable; - - /* only draw the tree effects if we're the active sort */ - if (/* XXX */ TRUE) { - GdkPixbuf *node_image; - int node_image_width = 0, node_image_height = 0; - ETreePath *parent_node; - - node = e_cell_tree_get_node (tree_model, row); - - offset = offset_of_node (tree_model, node); - expandable = e_tree_model_node_is_expandable (tree_model, node); - expanded = e_tree_model_node_is_expanded (tree_model, node); - subcell_offset = offset; - - node_image = e_tree_model_icon_of_node (tree_model, node); - - if (node_image) { - node_image_width = gdk_pixbuf_get_width (node_image); - node_image_height = gdk_pixbuf_get_height (node_image); - } - - /* - * Be a nice citizen: clip to the region we are supposed to draw on - */ - rect.x = x1; - rect.y = y1; - rect.width = subcell_offset + node_image_width; - rect.height = y2 - y1; - - gdk_gc_set_clip_rectangle (tree_view->gc, &rect); - gdk_gc_set_clip_rectangle (fg_gc, &rect); - clip_rect = ▭ - - if (selected) { - foreground = &canvas->style->text [GTK_STATE_SELECTED]; - } else { - foreground = &canvas->style->text [GTK_STATE_NORMAL]; - } - - gdk_gc_set_foreground (tree_view->gc, foreground); - - /* draw our lines */ - if (E_CELL_TREE(tree_view->cell_view.ecell)->draw_lines) { - - if (visible_depth_of_node (tree_model, node) > 0 - || e_tree_model_node_get_children (tree_model, node, NULL) > 0) - gdk_draw_line (drawable, tree_view->gc, - rect.x + offset - INDENT_AMOUNT / 2 + 1, - rect.y + rect.height / 2, - rect.x + offset, - rect.y + rect.height / 2); - - if (visible_depth_of_node (tree_model, node) != 0) { - gdk_draw_line (drawable, tree_view->gc, - rect.x + offset - INDENT_AMOUNT / 2, - rect.y, - rect.x + offset - INDENT_AMOUNT / 2, - (e_tree_model_node_get_next (tree_model, node) - ? rect.y + rect.height - : rect.y + rect.height / 2)); - } - - /* now traverse back up to the root of the tree, checking at - each level if the node has siblings, and drawing the - correct vertical pipe for it's configuration. */ - parent_node = e_tree_model_node_get_parent (tree_model, node); - offset -= INDENT_AMOUNT; - while (parent_node && visible_depth_of_node (tree_model, parent_node) != 0) { - if (e_tree_model_node_get_next(tree_model, parent_node)) { - gdk_draw_line (drawable, tree_view->gc, - rect.x + offset - INDENT_AMOUNT / 2, - rect.y, - rect.x + offset - INDENT_AMOUNT / 2, - rect.y + rect.height); - } - parent_node = e_tree_model_node_get_parent (tree_model, parent_node); - offset -= INDENT_AMOUNT; - } - } - - /* now draw our icon if we're expandable */ - if (expandable) { - GdkPixbuf *image; - int image_width, image_height; - - image = (expanded - ? E_CELL_TREE(tree_view->cell_view.ecell)->open_pixbuf - : E_CELL_TREE(tree_view->cell_view.ecell)->closed_pixbuf); - - image_width = gdk_pixbuf_get_width(image); - image_height = gdk_pixbuf_get_height(image); - - gdk_pixbuf_render_to_drawable_alpha (image, - drawable, - 0, 0, - x1 + subcell_offset - INDENT_AMOUNT / 2 - image_width / 2, - y1 + (y2 - y1) / 2 - image_height / 2, - image_width, image_height, - GDK_PIXBUF_ALPHA_BILEVEL, - 128, - GDK_RGB_DITHER_NORMAL, - image_width, 0); - } - - if (node_image) { - gdk_pixbuf_render_to_drawable_alpha (node_image, - drawable, - 0, 0, - x1 + subcell_offset, - y1 + (y2 - y1) / 2 - node_image_height / 2, - node_image_width, node_image_height, - GDK_PIXBUF_ALPHA_BILEVEL, - 128, - GDK_RGB_DITHER_NORMAL, - node_image_width, 0); - subcell_offset += node_image_width; - } - } - - /* Now cause our subcell to draw its contents, shifted by - subcell_offset pixels */ - e_cell_draw (tree_view->subcell_view, drawable, - model_col, view_col, row, selected, - x1 + subcell_offset, y1, x2, y2); -} - -/* - * ECell::event method - */ -static gint -ect_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - ETreeModel *tree_model = e_cell_tree_get_tree_model (ecell_view->e_table_model, row); - ETreePath *node = e_cell_tree_get_node (tree_model, row); - int offset = offset_of_node (tree_model, node); - - switch (event->type) { - case GDK_BUTTON_PRESS: { - /* if the event happened in our area of control (and - we care about it), handle it. */ - - /* only activate the tree control if the click/release happens in the icon's area. */ - if (event->button.x > (offset - INDENT_AMOUNT) && event->button.x < offset) { - if (e_tree_model_node_is_expandable (tree_model, node)) { - e_tree_model_node_set_expanded (tree_model, - node, - !e_tree_model_node_is_expanded(tree_model, node)); - } - return TRUE; - } - else if (event->button.x < (offset - INDENT_AMOUNT)) - return TRUE; - } - default: - /* modify the event and pass it off to our subcell_view */ - switch (event->type) { - case GDK_BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - event->button.x -= offset; - break; - case GDK_MOTION_NOTIFY: - event->motion.x -= offset; - break; - default: - /* nada */ - } - e_cell_event(tree_view->subcell_view, event, model_col, view_col, row); - return TRUE; - } -} - -/* - * ECell::height method - */ -static int -ect_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - - return e_cell_height (tree_view->subcell_view, model_col, view_col, row); -} - -/* - * ECellView::enter_edit method - */ -static void * -ect_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) -{ - /* just defer to our subcell's view */ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - - return e_cell_enter_edit (tree_view->subcell_view, model_col, view_col, row); -} - -/* - * ECellView::leave_edit method - */ -static void -ect_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context) -{ - /* just defer to our subcell's view */ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - - e_cell_leave_edit (tree_view->subcell_view, model_col, view_col, row, edit_context); -} - -static void -ect_print (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width, double height) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - - if (/* XXX only if we're the active sort */ TRUE) { - ETreeModel *tree_model = e_cell_tree_get_tree_model (ecell_view->e_table_model, row); - ETreePath *node = e_cell_tree_get_node (tree_model, row); - int offset = offset_of_node (tree_model, node); - int subcell_offset = offset; - gboolean expandable = e_tree_model_node_is_expandable (tree_model, node); - gboolean expanded = e_tree_model_node_is_expanded (tree_model, node); - - /* draw our lines */ - if (E_CELL_TREE(tree_view->cell_view.ecell)->draw_lines) { - - if (!e_tree_model_node_is_root (tree_model, node) - || e_tree_model_node_get_children (tree_model, node, NULL) > 0) { - gnome_print_moveto (context, - offset - INDENT_AMOUNT / 2, - height / 2); - - gnome_print_lineto (context, - offset, - height / 2); - } - - if (visible_depth_of_node (tree_model, node) != 0) { - gnome_print_moveto (context, - offset - INDENT_AMOUNT / 2, - height); - gnome_print_lineto (context, - offset - INDENT_AMOUNT / 2, - (e_tree_model_node_get_next (tree_model, node) - ? 0 - : height / 2)); - } - - /* now traverse back up to the root of the tree, checking at - each level if the node has siblings, and drawing the - correct vertical pipe for it's configuration. */ - node = e_tree_model_node_get_parent (tree_model, node); - offset -= INDENT_AMOUNT; - while (node && visible_depth_of_node (tree_model, node) != 0) { - if (e_tree_model_node_get_next(tree_model, node)) { - gnome_print_moveto (context, - offset - INDENT_AMOUNT / 2, - height); - gnome_print_lineto (context, - offset - INDENT_AMOUNT / 2, - 0); - } - node = e_tree_model_node_get_parent (tree_model, node); - offset -= INDENT_AMOUNT; - } - } - - /* now draw our icon if we're expandable */ - if (expandable) { - double image_matrix [6] = {16, 0, 0, 16, 0, 0}; - GdkPixbuf *image = (expanded - ? E_CELL_TREE(tree_view->cell_view.ecell)->open_pixbuf - : E_CELL_TREE(tree_view->cell_view.ecell)->closed_pixbuf); - int image_width, image_height, image_rowstride; - guchar *image_pixels; - - image_width = gdk_pixbuf_get_width(image); - image_height = gdk_pixbuf_get_height(image); - image_pixels = gdk_pixbuf_get_pixels(image); - image_rowstride = gdk_pixbuf_get_rowstride(image); - - image_matrix [4] = subcell_offset - INDENT_AMOUNT / 2 - image_width / 2; - image_matrix [5] = height / 2 - image_height / 2; - - gnome_print_gsave (context); - gnome_print_concat (context, image_matrix); - - gnome_print_rgbaimage (context, image_pixels, image_width, image_height, image_rowstride); - gnome_print_grestore (context); - } - - gnome_print_stroke (context); - - if (gnome_print_translate(context, subcell_offset, 0) == -1) - /* FIXME */; - width -= subcell_offset; - } - - - e_cell_print (tree_view->subcell_view, context, model_col, view_col, row, width, height); -} - -static gdouble -ect_print_height (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width) -{ - return 12; /* XXX */ -} - -/* - * GtkObject::destroy method - */ -static void -ect_destroy (GtkObject *object) -{ - ECellTree *ect = E_CELL_TREE (object); - - /* destroy our subcell */ - gtk_object_destroy (GTK_OBJECT (ect->subcell)); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -static void -e_cell_tree_class_init (GtkObjectClass *object_class) -{ - ECellClass *ecc = (ECellClass *) object_class; - - object_class->destroy = ect_destroy; - - ecc->new_view = ect_new_view; - ecc->kill_view = ect_kill_view; - ecc->realize = ect_realize; - ecc->unrealize = ect_unrealize; - ecc->draw = ect_draw; - ecc->event = ect_event; - ecc->height = ect_height; - ecc->enter_edit = ect_enter_edit; - ecc->leave_edit = ect_leave_edit; - ecc->print = ect_print; - ecc->print_height = ect_print_height; - - parent_class = gtk_type_class (PARENT_TYPE); -} - -E_MAKE_TYPE(e_cell_tree, "ECellTree", ECellTree, e_cell_tree_class_init, NULL, PARENT_TYPE); - -void -e_cell_tree_construct (ECellTree *ect, - GdkPixbuf *open_pixbuf, - GdkPixbuf *closed_pixbuf, - gboolean draw_lines, - ECell *subcell) -{ - ect->subcell = subcell; - ect->open_pixbuf = open_pixbuf; - ect->closed_pixbuf = closed_pixbuf; - ect->draw_lines = draw_lines; -} - - -ECell * -e_cell_tree_new (ETableModel *etm, - GdkPixbuf *open_pixbuf, - GdkPixbuf *closed_pixbuf, - gboolean draw_lines, - ECell *subcell) -{ - ECellTree *ect = gtk_type_new (e_cell_tree_get_type ()); - - e_cell_tree_construct (ect, open_pixbuf, closed_pixbuf, draw_lines, subcell); - - return (ECell *) ect; -} diff --git a/widgets/e-table/e-cell-tree.h b/widgets/e-table/e-cell-tree.h deleted file mode 100644 index ef6babeda4..0000000000 --- a/widgets/e-table/e-cell-tree.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ECellTree - Tree item for e-table. - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Toshok <toshok@helixcode.com> - * - */ -#ifndef _E_CELL_TREE_H_ -#define _E_CELL_TREE_H_ - -#include <libgnomeui/gnome-canvas.h> -#include "e-cell.h" - -#define E_CELL_TREE_TYPE (e_cell_tree_get_type ()) -#define E_CELL_TREE(o) (GTK_CHECK_CAST ((o), E_CELL_TREE_TYPE, ECellTree)) -#define E_CELL_TREE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_TREE_TYPE, ECellTreeClass)) -#define E_IS_CELL_TREE(o) (GTK_CHECK_TYPE ((o), E_CELL_TREE_TYPE)) -#define E_IS_CELL_TREE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_TREE_TYPE)) - -typedef struct { - ECell parent; - - gboolean draw_lines; - - GdkPixbuf *open_pixbuf; - GdkPixbuf *closed_pixbuf; - - ECell *subcell; -} ECellTree; - -typedef struct { - ECellClass parent_class; -} ECellTreeClass; - -GtkType e_cell_tree_get_type (void); -ECell *e_cell_tree_new (ETableModel *model, - GdkPixbuf *open_pixbuf, - GdkPixbuf *closed_pixbuf, - gboolean draw_lines, - ECell *subcell); -void e_cell_tree_construct (ECellTree *ect, - GdkPixbuf *open_pixbuf, - GdkPixbuf *closed_pixbuf, - gboolean draw_lines, - ECell *subcell); - -#endif /* _E_CELL_TREE_H_ */ - - diff --git a/widgets/e-table/e-cell.c b/widgets/e-table/e-cell.c deleted file mode 100644 index 75be2ce916..0000000000 --- a/widgets/e-table/e-cell.c +++ /dev/null @@ -1,200 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-cell.c: base class for cell renderers in e-table - * - * Author: - * Miguel de Icaza (miguel@kernel.org) - * - * (C) 1999 Helix Code, Inc - */ -#include <config.h> -#include "e-cell.h" -#include "e-util/e-util.h" - -#define PARENT_TYPE gtk_object_get_type () - -static ECellView * -ec_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - return NULL; -} - -static void -ec_realize (ECellView *e_cell) -{ -} - -static void -ec_kill_view (ECellView *ecell_view) -{ -} - -static void -ec_unrealize (ECellView *e_cell) -{ -} - -static void -ec_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, gboolean selected, - int x1, int y1, int x2, int y2) -{ - g_error ("e-cell-draw invoked\n"); -} - -static gint -ec_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row) -{ - g_error ("e-cell-event invoked\n"); - return 0; -} - -static gint -ec_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - g_error ("e-cell-event invoked\n"); - return 0; -} - -static void -ec_focus (ECellView *ecell_view, int model_col, int view_col, int row, int x1, int y1, int x2, int y2) -{ - ecell_view->focus_col = view_col; - ecell_view->focus_row = row; - ecell_view->focus_x1 = x1; - ecell_view->focus_y1 = y1; - ecell_view->focus_x2 = x2; - ecell_view->focus_y2 = y2; -} - -static void -ec_unfocus (ECellView *ecell_view) -{ - ecell_view->focus_col = -1; - ecell_view->focus_row = -1; - ecell_view->focus_x1 = -1; - ecell_view->focus_y1 = -1; - ecell_view->focus_x2 = -1; - ecell_view->focus_y2 = -1; -} - -static void * -ec_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) -{ - return NULL; -} - -static void -ec_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *context) -{ -} - -static void -e_cell_class_init (GtkObjectClass *object_class) -{ - ECellClass *ecc = (ECellClass *) object_class; - - ecc->realize = ec_realize; - ecc->unrealize = ec_unrealize; - ecc->new_view = ec_new_view; - ecc->kill_view = ec_kill_view; - ecc->draw = ec_draw; - ecc->event = ec_event; - ecc->focus = ec_focus; - ecc->unfocus = ec_unfocus; - ecc->height = ec_height; - ecc->enter_edit = ec_enter_edit; - ecc->leave_edit = ec_leave_edit; - ecc->print = NULL; - ecc->print_height = NULL; -} - -static void -e_cell_init (GtkObject *object) -{ -} - -E_MAKE_TYPE(e_cell, "ECell", ECell, e_cell_class_init, e_cell_init, PARENT_TYPE); - - -void -e_cell_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->event ( - ecell_view, event, model_col, view_col, row); -} - -ECellView * -e_cell_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell)->klass)->new_view ( - ecell, table_model, e_table_item_view); -} - -void -e_cell_realize (ECellView *ecell_view) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->realize (ecell_view); -} - -void -e_cell_kill_view (ECellView *ecell_view) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->kill_view (ecell_view); -} - -void -e_cell_unrealize (ECellView *ecell_view) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->unrealize (ecell_view); -} - -void -e_cell_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, gboolean selected, int x1, int y1, int x2, int y2) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->draw ( - ecell_view, drawable, model_col, view_col, row, selected, x1, y1, x2, y2); -} - -void -e_cell_print (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width, double height) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->print - (ecell_view, context, model_col, view_col, row, width, height); -} - -gdouble -e_cell_print_height (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width) -{ - if (E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->print_height) - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->print_height - (ecell_view, context, model_col, view_col, row, width); - else - return 0.0; -} - -int -e_cell_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->height ( - ecell_view, model_col, view_col, row); -} - -void * -e_cell_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->enter_edit ( - ecell_view, model_col, view_col, row); -} - -void -e_cell_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->leave_edit ( - ecell_view, model_col, view_col, row, edit_context); -} diff --git a/widgets/e-table/e-cell.h b/widgets/e-table/e-cell.h deleted file mode 100644 index 40b257f264..0000000000 --- a/widgets/e-table/e-cell.h +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_CELL_H_ -#define _E_CELL_H_ - -#include <gdk/gdktypes.h> -#include <libgnomeprint/gnome-print.h> -#include "e-table-model.h" - -#define E_CELL_TYPE (e_cell_get_type ()) -#define E_CELL(o) (GTK_CHECK_CAST ((o), E_CELL_TYPE, ECell)) -#define E_CELL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_TYPE, ECellClass)) -#define E_IS_CELL(o) (GTK_CHECK_TYPE ((o), E_CELL_TYPE)) -#define E_IS_CELL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_TYPE)) - -typedef struct _ECell ECell; -typedef struct _ECellView ECellView; - -struct _ECell { - GtkObject object; -}; - -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; -}; - -#define E_CELL_IS_FOCUSED(ecell_view) (ecell_view->focus_x1 != -1) - -typedef struct { - GtkObjectClass parent_class; - - ECellView *(*new_view) (ECell *ecell, ETableModel *table_model, void *e_table_item_view); - void (*kill_view) (ECellView *ecell_view); - - void (*realize) (ECellView *ecell_view); - void (*unrealize) (ECellView *ecell_view); - - void (*draw) (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, - gboolean selected, int x1, int y1, int x2, int y2); - gint (*event) (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row); - void (*focus) (ECellView *ecell_view, int model_col, int view_col, - int row, int x1, int y1, int x2, int y2); - void (*unfocus) (ECellView *ecell_view); - int (*height) (ECellView *ecell_view, int model_col, int view_col, int row); - - void *(*enter_edit) (ECellView *ecell_view, int model_col, int view_col, int row); - void (*leave_edit) (ECellView *ecell_view, int model_col, int view_col, int row, void *context); - void (*print) (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - gdouble width, gdouble height); - gdouble (*print_height) (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, gdouble width); -} ECellClass; - -GtkType e_cell_get_type (void); -ECellView *e_cell_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view); -void e_cell_kill_view (ECellView *ecell_view); - -void e_cell_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row); - -void e_cell_realize (ECellView *ecell_view); -void e_cell_unrealize (ECellView *ecell_view); - -void e_cell_draw (ECellView *ecell_view, GdkDrawable *dr, - int model_col, int view_col, int row, gboolean selected, - int x1, int y1, int x2, int y2); -void e_cell_print (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width, double height); -gdouble e_cell_print_height (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, gdouble width); -void e_cell_focus (ECellView *ecell_view, int model_col, int view_col, int row, - int x1, int y1, int x2, int y2); -void e_cell_unfocus (ECellView *ecell_view); -int e_cell_height (ECellView *ecell_view, int model_col, int view_col, int row); - -void *e_cell_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row); -void e_cell_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context); - -#endif /* _E_CELL_H_ */ diff --git a/widgets/e-table/e-table-click-to-add.c b/widgets/e-table/e-table-click-to-add.c deleted file mode 100644 index ba38078b2c..0000000000 --- a/widgets/e-table/e-table-click-to-add.c +++ /dev/null @@ -1,504 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-click-to-add.c: A canvas item based view of the ETableColumn. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, 2000 Helix Code, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include <libgnomeui/gnome-canvas.h> -#include <libgnomeui/gnome-canvas-util.h> -#include <libgnomeui/gnome-canvas-rect-ellipse.h> -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include "e-table-header.h" -#include "e-table-click-to-add.h" -#include "e-table-defines.h" -#include "e-table-one.h" -#include "widgets/e-text/e-text.h" -#include "e-util/e-canvas.h" -#include "e-util/e-canvas-utils.h" - -enum { - CURSOR_CHANGE, - LAST_SIGNAL -}; - -static gint etcta_signals [LAST_SIGNAL] = { 0, }; - -#define PARENT_OBJECT_TYPE gnome_canvas_group_get_type () - -#define ELEMENTS(x) (sizeof (x) / sizeof (x[0])) - -static GnomeCanvasGroupClass *etcta_parent_class; - -enum { - ARG_0, - ARG_HEADER, - ARG_MODEL, - ARG_MESSAGE, - ARG_WIDTH, - ARG_HEIGHT, -}; - -static void -etcta_cursor_change (GtkObject *object, gint row, gint col, ETableClickToAdd *etcta) -{ - gtk_signal_emit (GTK_OBJECT (etcta), - etcta_signals [CURSOR_CHANGE], - row, col); -} - -static void -etcta_add_table_header (ETableClickToAdd *etcta, ETableHeader *header) -{ - etcta->eth = header; - if (etcta->eth) - gtk_object_ref (GTK_OBJECT (etcta->eth)); - if (etcta->row) - gnome_canvas_item_set(GNOME_CANVAS_ITEM(etcta->row), - "ETableHeader", header, - NULL); -} - -static void -etcta_drop_table_header (ETableClickToAdd *etcta) -{ - GtkObject *header; - - if (!etcta->eth) - return; - - header = GTK_OBJECT (etcta->eth); - - gtk_object_unref (header); - etcta->eth = NULL; -} - -static void -etcta_add_one (ETableClickToAdd *etcta, ETableModel *one) -{ - etcta->one = one; - if (etcta->one) - gtk_object_ref (GTK_OBJECT(etcta->one)); - if (etcta->row) - gnome_canvas_item_set(GNOME_CANVAS_ITEM(etcta->row), - "ETableModel", one, - NULL); - gtk_object_set(GTK_OBJECT(etcta->selection), - "model", one, - NULL); -} - -static void -etcta_drop_one (ETableClickToAdd *etcta) -{ - if (!etcta->one) - return; - gtk_object_unref (GTK_OBJECT(etcta->one)); - etcta->one = NULL; - gtk_object_set(GTK_OBJECT(etcta->selection), - "model", NULL, - NULL); -} - -static void -etcta_add_model (ETableClickToAdd *etcta, ETableModel *model) -{ - etcta->model = model; - if (etcta->model) - gtk_object_ref (GTK_OBJECT(etcta->model)); -} - -static void -etcta_drop_model (ETableClickToAdd *etcta) -{ - etcta_drop_one (etcta); - if (!etcta->model) - return; - gtk_object_unref (GTK_OBJECT(etcta->model)); - etcta->model = NULL; -} - -static void -etcta_add_message (ETableClickToAdd *etcta, char *message) -{ - etcta->message = g_strdup(message); -} - -static void -etcta_drop_message (ETableClickToAdd *etcta) -{ - g_free(etcta->message); - etcta->message = NULL; -} - - -static void -etcta_destroy (GtkObject *object){ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (object); - - etcta_drop_table_header (etcta); - etcta_drop_model (etcta); - etcta_drop_message (etcta); - gtk_object_unref(GTK_OBJECT(etcta->selection)); - - if (GTK_OBJECT_CLASS (etcta_parent_class)->destroy) - (*GTK_OBJECT_CLASS (etcta_parent_class)->destroy) (object); -} - -static void -etcta_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableClickToAdd *etcta; - - item = GNOME_CANVAS_ITEM (o); - etcta = E_TABLE_CLICK_TO_ADD (o); - - switch (arg_id){ - case ARG_HEADER: - etcta_drop_table_header (etcta); - etcta_add_table_header (etcta, E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg))); - break; - case ARG_MODEL: - etcta_drop_model (etcta); - etcta_add_model (etcta, E_TABLE_MODEL(GTK_VALUE_OBJECT (*arg))); - break; - case ARG_MESSAGE: - etcta_drop_message (etcta); - etcta_add_message (etcta, GTK_VALUE_STRING (*arg)); - break; - case ARG_WIDTH: - etcta->width = GTK_VALUE_DOUBLE (*arg); - if (etcta->row) - gnome_canvas_item_set(etcta->row, - "minimum_width", etcta->width, - NULL); - if (etcta->text) - gnome_canvas_item_set(etcta->text, - "width", etcta->width - 4, - NULL); - if (etcta->rect) - gnome_canvas_item_set(etcta->rect, - "x2", etcta->width - 1, - NULL); - break; - } - gnome_canvas_item_request_update(item); -} - -static void -etcta_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableClickToAdd *etcta; - - etcta = E_TABLE_CLICK_TO_ADD (o); - - switch (arg_id){ - case ARG_HEADER: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etcta->eth); - break; - case ARG_MODEL: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etcta->model); - break; - case ARG_MESSAGE: - GTK_VALUE_STRING (*arg) = g_strdup(etcta->message); - break; - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = etcta->width; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = etcta->height; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -etcta_realize (GnomeCanvasItem *item) -{ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item); - etcta->text = gnome_canvas_item_new(GNOME_CANVAS_GROUP(item), - e_text_get_type(), - "text", etcta->message ? etcta->message : "", - "anchor", GTK_ANCHOR_NW, - "width", etcta->width - 4, - NULL); - e_canvas_item_move_absolute (etcta->text, 2, 2); - etcta->rect = gnome_canvas_item_new(GNOME_CANVAS_GROUP(item), - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) etcta->width - 1, - "y2", (double) etcta->height - 1, - "outline_color", "black", - "fill_color", NULL, - NULL); - - if (GNOME_CANVAS_ITEM_CLASS (etcta_parent_class)->realize) - (*GNOME_CANVAS_ITEM_CLASS (etcta_parent_class)->realize)(item); -} - -static void -etcta_unrealize (GnomeCanvasItem *item) -{ - if (GNOME_CANVAS_ITEM_CLASS (etcta_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (etcta_parent_class)->unrealize)(item); -} - -static double -etcta_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - -/* - * Handles the events on the ETableClickToAdd, particularly it creates the ETableItem and passes in some events. - */ -static int -etcta_event (GnomeCanvasItem *item, GdkEvent *e) -{ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item); - int ret_val = TRUE; - - switch (e->type){ - case GDK_BUTTON_PRESS: - if (etcta->text) { - gtk_object_destroy(GTK_OBJECT(etcta->text)); - etcta->text = NULL; - } - if (etcta->rect) { - gtk_object_destroy(GTK_OBJECT(etcta->rect)); - etcta->rect = NULL; - } - if (!etcta->row) { - ETableModel *one; - - one = e_table_one_new(etcta->model); - etcta_add_one (etcta, one); - gtk_object_unref(GTK_OBJECT(one)); - - e_table_selection_model_clear(etcta->selection); - - etcta->row = gnome_canvas_item_new(GNOME_CANVAS_GROUP(item), - e_table_item_get_type(), - "ETableHeader", etcta->eth, - "ETableModel", etcta->one, - "minimum_width", etcta->width, - "drawgrid", TRUE, - "table_selection_model", etcta->selection, - NULL); - - } - /* Fall through. No break; */ - case GDK_BUTTON_RELEASE: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - if (etcta->row) { - gnome_canvas_item_i2w (item, &e->button.x, &e->button.y); - gnome_canvas_item_w2i (etcta->row, &e->button.x, &e->button.y); - gtk_signal_emit_by_name(GTK_OBJECT(etcta->row), "event", e, &ret_val); - gnome_canvas_item_i2w (etcta->row, &e->button.x, &e->button.y); - gnome_canvas_item_w2i (item, &e->button.x, &e->button.y); - } - break; - - case GDK_KEY_PRESS: - switch (e->key.keyval) { - case GDK_Return: - case GDK_KP_Enter: - case GDK_ISO_Enter: - case GDK_3270_Enter: - - case GDK_Tab: - case GDK_KP_Tab: - case GDK_ISO_Left_Tab: - - if (etcta->row) { - ETableModel *one; - - e_table_one_commit(E_TABLE_ONE(etcta->one)); - etcta_drop_one (etcta); - gtk_object_destroy(GTK_OBJECT(etcta->row)); - etcta->row = NULL; - - one = e_table_one_new(etcta->model); - etcta_add_one (etcta, one); - gtk_object_unref(GTK_OBJECT(one)); - - e_table_selection_model_clear(etcta->selection); - - etcta->row = gnome_canvas_item_new(GNOME_CANVAS_GROUP(item), - e_table_item_get_type(), - "ETableHeader", etcta->eth, - "ETableModel", etcta->one, - "minimum_width", etcta->width, - "drawgrid", TRUE, - "table_selection_model", etcta->selection, - NULL); - - e_table_item_set_cursor(E_TABLE_ITEM(etcta->row), 0, 0); - } - break; - default: - break; - } - - default: - return FALSE; - } - return TRUE; -} - -static void -etcta_reflow (GnomeCanvasItem *item, int flags) -{ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item); - - double old_height = etcta->height; - - if (etcta->text) { - gtk_object_get(GTK_OBJECT(etcta->text), - "height", &etcta->height, - NULL); - etcta->height += 4; - } - if (etcta->row) { - gtk_object_get(GTK_OBJECT(etcta->row), - "height", &etcta->height, - NULL); - } - - if (etcta->rect) { - gtk_object_set(GTK_OBJECT(etcta->rect), - "y2", etcta->height - 1, - NULL); - } - if (old_height != etcta->height) - e_canvas_item_request_parent_reflow(item); -} - -static void -etcta_class_init (ETableClickToAddClass *klass) -{ - GnomeCanvasItemClass *item_class = GNOME_CANVAS_ITEM_CLASS(klass); - GtkObjectClass *object_class = GTK_OBJECT_CLASS(klass); - - etcta_parent_class = gtk_type_class (PARENT_OBJECT_TYPE); - - klass->cursor_change = NULL; - - object_class->destroy = etcta_destroy; - object_class->set_arg = etcta_set_arg; - object_class->get_arg = etcta_get_arg; - - item_class->realize = etcta_realize; - item_class->unrealize = etcta_unrealize; - item_class->point = etcta_point; - item_class->event = etcta_event; - - gtk_object_add_arg_type ("ETableClickToAdd::header", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_HEADER); - gtk_object_add_arg_type ("ETableClickToAdd::model", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_MODEL); - gtk_object_add_arg_type ("ETableClickToAdd::message", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_MESSAGE); - gtk_object_add_arg_type ("ETableClickToAdd::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ETableClickToAdd::height", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_HEIGHT); - - etcta_signals [CURSOR_CHANGE] = - gtk_signal_new ("cursor_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClickToAddClass, cursor_change), - gtk_marshal_NONE__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, etcta_signals, LAST_SIGNAL); -} - -static void -etcta_init (GnomeCanvasItem *item) -{ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item); - - etcta->one = NULL; - etcta->model = NULL; - etcta->eth = NULL; - - etcta->message = NULL; - - etcta->row = NULL; - etcta->text = NULL; - etcta->rect = NULL; - - etcta->selection = e_table_selection_model_new(); - gtk_signal_connect(GTK_OBJECT(etcta->selection), "cursor_changed", - GTK_SIGNAL_FUNC(etcta_cursor_change), etcta); - - e_canvas_item_set_reflow_callback(item, etcta_reflow); -} - -GtkType -e_table_click_to_add_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableClickToAdd", - sizeof (ETableClickToAdd), - sizeof (ETableClickToAddClass), - (GtkClassInitFunc) etcta_class_init, - (GtkObjectInitFunc) etcta_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_OBJECT_TYPE, &info); - } - - return type; -} - -void -e_table_click_to_add_commit (ETableClickToAdd *etcta) -{ - if (etcta->row) { - e_table_one_commit(E_TABLE_ONE(etcta->one)); - etcta_drop_one (etcta); - gtk_object_destroy(GTK_OBJECT(etcta->row)); - etcta->row = NULL; - } - if (!etcta->text) { - etcta->text = gnome_canvas_item_new(GNOME_CANVAS_GROUP(etcta), - e_text_get_type(), - "text", etcta->message ? etcta->message : "", - "anchor", GTK_ANCHOR_NW, - "width", etcta->width - 4, - NULL); - e_canvas_item_move_absolute (etcta->text, 2, 2); - } - if (!etcta->rect) { - etcta->rect = gnome_canvas_item_new(GNOME_CANVAS_GROUP(etcta), - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) etcta->width - 1, - "y2", (double) etcta->height - 1, - "outline_color", "black", - "fill_color", NULL, - NULL); - } -} diff --git a/widgets/e-table/e-table-click-to-add.h b/widgets/e-table/e-table-click-to-add.h deleted file mode 100644 index 1dcbf9ef52..0000000000 --- a/widgets/e-table/e-table-click-to-add.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_CLICK_TO_ADD_H_ -#define _E_TABLE_CLICK_TO_ADD_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gnome-xml/tree.h> -#include "e-table-header.h" -#include "e-table-sort-info.h" -#include "e-table-item.h" -#include "e-table-selection-model.h" - -#define E_TABLE_CLICK_TO_ADD_TYPE (e_table_click_to_add_get_type ()) -#define E_TABLE_CLICK_TO_ADD(o) (GTK_CHECK_CAST ((o), E_TABLE_CLICK_TO_ADD_TYPE, ETableClickToAdd)) -#define E_TABLE_CLICK_TO_ADD_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_CLICK_TO_ADD_TYPE, ETableClickToAddClass)) -#define E_IS_TABLE_CLICK_TO_ADD(o) (GTK_CHECK_TYPE ((o), E_TABLE_CLICK_TO_ADD_TYPE)) -#define E_IS_TABLE_CLICK_TO_ADD_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_CLICK_TO_ADD_TYPE)) - -typedef struct { - GnomeCanvasGroup parent; - - ETableModel *one; /* The ETableOne. */ - - ETableModel *model; /* The backend model. */ - ETableHeader *eth; /* This is just to give to the ETableItem. */ - - char *message; - - GnomeCanvasItem *row; /* If row is NULL, we're sitting with no data and a "Click here" message. */ - GnomeCanvasItem *text; /* If text is NULL, row shouldn't be. */ - GnomeCanvasItem *rect; /* What the heck. Why not. */ - - gdouble width; - gdouble height; - - ETableSelectionModel *selection; -} ETableClickToAdd; - -typedef struct { - GnomeCanvasGroupClass parent_class; - - /* - * signals - */ - void (*cursor_change) (ETableClickToAdd *etcta, gint row, gint col); -} ETableClickToAddClass; - -GtkType e_table_click_to_add_get_type (void); - -void e_table_click_to_add_commit (ETableClickToAdd *etcta); - -#endif /* _E_TABLE_CLICK_TO_ADD_H_ */ diff --git a/widgets/e-table/e-table-col-dnd.h b/widgets/e-table/e-table-col-dnd.h deleted file mode 100644 index c1c26175c7..0000000000 --- a/widgets/e-table/e-table-col-dnd.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _E_TABLE_COL_DND_H_ -#define _E_TABLE_COL_DND_H_ - -#define TARGET_ETABLE_COL_TYPE "application/x-etable-column-header" - -enum { - TARGET_ETABLE_COL_HEADER -}; - -#endif /* _E_TABLE_COL_DND_H_ */ diff --git a/widgets/e-table/e-table-col.c b/widgets/e-table/e-table-col.c deleted file mode 100644 index e767aa5567..0000000000 --- a/widgets/e-table/e-table-col.c +++ /dev/null @@ -1,168 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-col.c: ETableCol implementation - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc - */ -#include <config.h> -#include <gtk/gtkobject.h> -#include <gtk/gtksignal.h> -#include "e-table-col.h" -#include "e-util/e-util.h" - -#define PARENT_TYPE (gtk_object_get_type ()) - -static GtkObjectClass *parent_class; - - -enum { - ARG_0, - ARG_SORTABLE, -}; - -static void -etc_destroy (GtkObject *object) -{ - ETableCol *etc = E_TABLE_COL (object); - - gtk_object_unref (GTK_OBJECT(etc->ecell)); - - if (etc->is_pixbuf) - gdk_pixbuf_unref (etc->pixbuf); - else - g_free (etc->text); - - (*parent_class->destroy)(object); -} - - -static void -etc_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableCol *etc = E_TABLE_COL (o); - - switch (arg_id){ - case ARG_SORTABLE: - etc->sortable = GTK_VALUE_BOOL(*arg); - break; - } -} - -static void -etc_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableCol *etc = E_TABLE_COL (o); - - switch (arg_id){ - case ARG_SORTABLE: - GTK_VALUE_BOOL(*arg) = etc->sortable; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -e_table_col_class_init (GtkObjectClass *object_class) -{ - parent_class = gtk_type_class (PARENT_TYPE); - object_class->destroy = etc_destroy; - object_class->get_arg = etc_get_arg; - object_class->set_arg = etc_set_arg; - - gtk_object_add_arg_type ("ETableCol::sortable", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_SORTABLE); -} - -static void -e_table_col_init (ETableCol *etc) -{ - etc->width = 0; - etc->sortable = 1; - etc->groupable = 1; -} - -E_MAKE_TYPE(e_table_col, "ETableCol", ETableCol, e_table_col_class_init, e_table_col_init, PARENT_TYPE); - -ETableCol * -e_table_col_new (int col_idx, const char *text, double expansion, int min_width, - ECell *ecell, GCompareFunc compare, gboolean resizable) -{ - ETableCol *etc; - - g_return_val_if_fail (expansion >= 0, NULL); - g_return_val_if_fail (min_width >= 0, NULL); - g_return_val_if_fail (compare != NULL, NULL); - - etc = gtk_type_new (E_TABLE_COL_TYPE); - - etc->is_pixbuf = FALSE; - - etc->col_idx = col_idx; - etc->text = g_strdup (text); - etc->pixbuf = NULL; - etc->expansion = expansion; - etc->min_width = min_width; - etc->ecell = ecell; - etc->compare = compare; - - etc->arrow = E_TABLE_COL_ARROW_NONE; - - etc->selected = 0; - etc->resizeable = resizable; - - gtk_object_ref (GTK_OBJECT(etc->ecell)); - - return etc; -} - -ETableCol * -e_table_col_new_with_pixbuf (int col_idx, GdkPixbuf *pixbuf, double expansion, int min_width, - ECell *ecell, GCompareFunc compare, gboolean resizable) -{ - ETableCol *etc; - - g_return_val_if_fail (expansion >= 0, NULL); - g_return_val_if_fail (min_width >= 0, NULL); - g_return_val_if_fail (compare != NULL, NULL); - - etc = gtk_type_new (E_TABLE_COL_TYPE); - - etc->is_pixbuf = TRUE; - - etc->col_idx = col_idx; - etc->text = NULL; - etc->pixbuf = pixbuf; - etc->expansion = expansion; - etc->min_width = min_width; - etc->ecell = ecell; - etc->compare = compare; - - etc->arrow = E_TABLE_COL_ARROW_NONE; - - etc->selected = 0; - etc->resizeable = resizable; - - gtk_object_ref (GTK_OBJECT(etc->ecell)); - gdk_pixbuf_ref (etc->pixbuf); - - return etc; -} - -void -e_table_col_set_arrow (ETableCol *col, ETableColArrow arrow) -{ - col->arrow = arrow; -} - -ETableColArrow -e_table_col_get_arrow (ETableCol *col) -{ - return col->arrow; -} - - diff --git a/widgets/e-table/e-table-col.h b/widgets/e-table/e-table-col.h deleted file mode 100644 index 39aeb26ba9..0000000000 --- a/widgets/e-table/e-table-col.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_COL_H_ -#define _E_TABLE_COL_H_ - -#include "e-cell.h" -#include <gdk-pixbuf/gdk-pixbuf.h> - -#define E_TABLE_COL_TYPE (e_table_col_get_type ()) -#define E_TABLE_COL(o) (GTK_CHECK_CAST ((o), E_TABLE_COL_TYPE, ETableCol)) -#define E_TABLE_COL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_COL_TYPE, ETableColClass)) -#define E_IS_TABLE_COL(o) (GTK_CHECK_TYPE ((o), E_TABLE_COL_TYPE)) -#define E_IS_TABLE_COL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_COL_TYPE)) - -typedef struct _ETableCol ETableCol; -typedef struct _ETableColClass ETableColClass; -typedef enum _ETableColArrow ETableColArrow; - -enum _ETableColArrow { - E_TABLE_COL_ARROW_NONE = 0, - E_TABLE_COL_ARROW_UP, - E_TABLE_COL_ARROW_DOWN -}; - -/* - * Information about a single column - */ -struct _ETableCol { - GtkObject base; - char *text; - GdkPixbuf *pixbuf; - int min_width; - int width; - double expansion; - short x; - GCompareFunc compare; - unsigned int is_pixbuf:1; - unsigned int selected:1; - unsigned int resizeable:1; - unsigned int sortable:1; - unsigned int groupable:1; - int col_idx; - - ETableColArrow arrow; - - ECell *ecell; -}; - -struct _ETableColClass { - GtkObjectClass parent_class; -}; - -GtkType e_table_col_get_type (void); -ETableCol *e_table_col_new (int col_idx, const char *text, - double expansion, int min_width, - ECell *ecell, GCompareFunc compare, - gboolean resizable); -ETableCol *e_table_col_new_with_pixbuf (int col_idx, GdkPixbuf *pixbuf, - double expansion, int min_width, - ECell *ecell, GCompareFunc compare, - gboolean resizable); -void e_table_col_destroy (ETableCol *etc); -void e_table_col_set_arrow (ETableCol *col, ETableColArrow arrow); -ETableColArrow e_table_col_get_arrow (ETableCol *col); - - -#endif /* _E_TABLE_COL_H_ */ - diff --git a/widgets/e-table/e-table-column-model.h b/widgets/e-table/e-table-column-model.h deleted file mode 100644 index 043dd783ca..0000000000 --- a/widgets/e-table/e-table-column-model.h +++ /dev/null @@ -1,5 +0,0 @@ - -class ETableColumnModel { - virtual void add_column (ETableCol *et) = 0; - virtual ETableCol *get_column (int column); - virtual diff --git a/widgets/e-table/e-table-column.c b/widgets/e-table/e-table-column.c deleted file mode 100644 index d17a285321..0000000000 --- a/widgets/e-table/e-table-column.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * e-table-column.c: TableColumn implementation - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc - */ -#include <config.h> -#include "e-table-column.h" - -enum { - STRUCTURE_CHANGE, - DIMENSION_CHANGE, - LAST_SIGNAL -}; - -static guint etc_signals [LAST_SIGNAL] = { 0, }; - -static GtkObjectClass *e_table_column_parent_class; - -static void -e_table_column_destroy (GtkObject *object) -{ - ETableColumn *etc = E_TABLE_COLUMN (object); - const int cols = etc->col_count; - - /* - * Destroy listeners - */ - for (l = etc->listeners; l; l = l->next) - g_free (l->data); - g_slist_free (etc->listeners); - etc->listeners = NULL; - - /* - * Destroy columns - */ - for (i = 0; i < cols; i++) - e_table_column_remove (etc, i); - - if (e_table_column_parent_class->destroy) - e_table_column_parent_class->destroy (object); -} - -static void -e_table_column_class_init (GtkObjectClass *object_class) -{ - object_class->destroy = e_table_column_destroy; - - e_table_column_parent_class = (gtk_type_class (gtk_object_get_type ())); - - etc_signals [STRUCTURE_CHANGE] = - gtk_signal_new ("structure_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableColumn, structure_change), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - etc_signals [DIMENSION_CHANGE] = - gtk_signal_new ("dimension_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableColumn, dimension_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, etc_signals, LAST_SIGNAL); -} - -GtkType -e_table_column_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableColumn", - sizeof (ETableColumn), - sizeof (ETableColumnClass), - (GtkClassInitFunc) e_table_column_class_init, - (GtkObjectInitFunc) NULL, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &info); - } - - return type; -} - -static void -etc_do_insert (ETableColumn *etc, int pos, ETableCol *val) -{ - memcpy (&etc->columns [pos+1], &etc->columns [pos], - sizeof (ETableCol *) * (etc->col_count - pos)); - etc->columns [pos] = val; -} - -void -e_table_column_add_column (ETableColumn *etc, ETableCol *tc, int pos) -{ - ETableCol **new_ptr; - - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (tc != NULL); - g_return_if_fail (pos >= 0 && pos < etc->col_count); - - if (pos == -1) - pos = etc->col_count; - etc->columns = g_realloc (etc->columns, sizeof (ETableCol *) * (etc->col_count + 1)); - etc_do_insert (etc, pos, tc); - etc->col_count++; - - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [STRUCTURE_CHANGE]); -} - -ETableCol * -e_table_column_get_column (ETableColumn *etc, int column) -{ - g_return_val_if_fail (etc != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), NULL); - - if (column < 0) - return NULL; - - if (column >= etc->col_count) - return NULL; - - return etc->columns [column]; -} - -int -e_table_column_count (ETableColumn *etc) -{ - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - return etc->col_count; -} - -int -e_table_column_index (ETableColumn *etc, const char *identifier) -{ - int i; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - g_return_val_if_fail (identifier != NULL, 0); - - for (i = 0; i < etc->col_count; i++){ - ETableCol *tc = etc->columns [i]; - - if (strcmp (i->id, identifier) == 0) - return i; - } - - return -1; -} - -int -e_table_column_get_index_at (ETableColumn *etc, int x_offset) -{ - int i, total; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - g_return_val_if_fail (identifier != NULL, 0); - - total = 0; - for (i = 0; i < etc->col_count; i++){ - total += etc->columns [i]->width; - - if (x_offset < total) - return i; - } - - return -1; -} - -ETableCol ** -e_table_column_get_columns (ETableColumn *etc) -{ - ETableCol **ret; - int i; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - ret = g_new (ETableCol *, etc->col_count + 1); - memcpy (ret, etc->columns, sizeof (ETableCol *) * etc->col_count); - ret [etc->col_count] = NULL; - - return ret; -} - -gboolean -e_table_column_selection_ok (ETableColumn *etc) -{ - g_return_val_if_fail (etc != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), FALSE); - - return etc->selectable; -} - -int -ve_table_column_get_selected (ETableColumn *etc) -{ - int i; - int selected = 0; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - for (i = 0; i < etc->col_count; i++){ - if (etc->columns [i]->selected) - selected++; - } - - return selected; -} - -int -e_table_column_total_width (ETableColumn *etc) -{ - int total; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - total = 0; - for (i = 0; i < etc->col_count; i++) - total += etc->columns [i].width; - - return total; -} - -static void -etc_do_remove (ETableColumn *etc, int idx) -{ - memcpy (&etc->columns [idx], &etc->columns [idx+1], - sizeof (ETableCol *) * etc->col_count - idx); - etc->col_count--; -} - -void -e_table_column_move (ETableColumn *etc, int source_index, int target_index) -{ - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (source_index >= 0); - g_return_if_fail (target_index >= 0); - g_return_if_fail (source_index < etc->col_count); - g_return_if_fail (target_index < etc->col_count); - - old = etc->columns [source_index]; - etc_do_remove (etc, source_index); - etc_do_insert (etc, target_index, old); - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [STRUCTURE_CHANGE]); -} - -void -e_table_column_remove (ETableColumn *etc, int idx) -{ - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < etc->col_count); - - etc_do_remove (etc, idx); - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [STRUCTURE_CHANGE]); -} - -void -e_table_column_set_selection (ETableColumn *etc, gboolean allow_selection); -{ -} - -void -e_table_column_set_size (ETableColumn *etc, int idx, int size) -{ - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < etc->col_count); - g_return_if_fail (size > 0); - - etc->columns [idx]->width = size; - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [SIZE_CHANGE], idx); -} diff --git a/widgets/e-table/e-table-config.c b/widgets/e-table/e-table-config.c deleted file mode 100644 index 5d078f8f86..0000000000 --- a/widgets/e-table/e-table-config.c +++ /dev/null @@ -1,233 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table.c: A graphical view of a Table. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, Helix Code, Inc - */ -#include <config.h> -#include <gnome.h> -#include <glade/glade.h> -#include <gnome-xml/xmlmemory.h> -#include "e-util/e-util.h" -#include "e-util/e-xml-utils.h" -#include "e-util/e-canvas.h" -#include "e-table.h" -#include "e-table-header-item.h" -#include "e-table-subset.h" -#include "e-table-item.h" -#include "e-table-group.h" -#include "e-table-config.h" - -typedef struct { - GladeXML *gui; - char *old_spec; -} ConfigData; - -static void -load_data (GladeXML *xml, char *label_widget, const char *content) -{ - GtkLabel *label = GTK_LABEL (glade_xml_get_widget (xml, label_widget)); - - gtk_label_set_text (label, content); -} - -static char * -get_fields (ETable *etable, xmlNode *xmlRoot) -{ - xmlNode *xmlColumns; - xmlNode *column; - GString *res; - char *s; - - res = g_string_new (""); - xmlColumns = e_xml_get_child_by_name (xmlRoot, "columns-shown"); - - for (column = xmlColumns->childs; column; column = column->next){ - ETableCol *ecol; - char *content; - int col; - - content = xmlNodeListGetString (column->doc, column->childs, 1); - col = atoi (content); - xmlFree (content); - - ecol = e_table_header_get_column (etable->header, col); - - g_string_append (res, ecol->text); - if (column->next) - g_string_append (res, ", "); - } - s = res->str; - g_string_free (res, FALSE); - - return s; -} - -static char * -get_grouping (ETable *etable, xmlNode *xmlRoot) -{ - xmlNode *xmlGrouping; - GString *res; - char *s; - - res = g_string_new (""); - xmlGrouping = e_xml_get_child_by_name (xmlRoot, "grouping"); - - s = res->str; - g_string_free (res, FALSE); - - return s; -} - -static char * -get_sort (ETable *etable) -{ - return g_strdup ("None"); -} - -static char * -get_filter (ETable *etable) -{ - return g_strdup ("None"); -} - -/* - * Loads a user-readable definition of the various e-table parameters - * into the dialog for configuring it - */ -static void -load_label_data (GladeXML *gui, ETable *etable) -{ - /* FIXME: Set this to the right value. */ - xmlNode *xmlRoot = NULL; - char *s; - -/* xmlRoot = xmlDocGetRootElement (etable->specification); */ - - s = get_fields (etable, xmlRoot); - load_data (gui, "label1", s); - g_free (s); - - s = get_grouping (etable, xmlRoot); - load_data (gui, "label2", s); - g_free (s); - - s = get_sort (etable); - load_data (gui, "label3", s); - g_free (s); - - s = get_filter (etable); - load_data (gui, "label4", s); - g_free (s); -} - -static void -cb_button_fields (GtkWidget *widget, ETable *etable) -{ -} - -static void -cb_button_grouping (GtkWidget *widget, ETable *etable) -{ -} - -static void -cb_button_sort (GtkWidget *widget, ETable *etable) -{ -} - -static void -cb_button_filter (GtkWidget *widget, ETable *etable) -{ -} - -GnomeDialog * -e_table_gui_config (ETable *etable) -{ - GladeXML *gui; - GnomeDialog *dialog; - ConfigData *config_data; - - glade_gnome_init (); - gui = glade_xml_new (ETABLE_GLADEDIR "/e-table-config.glade", NULL); - if (!gui) - return NULL; - - dialog = GNOME_DIALOG (glade_xml_get_widget (gui, "e-table-config")); - - gtk_signal_connect ( - GTK_OBJECT (glade_xml_get_widget (gui, "button-fields")), - "clicked", GTK_SIGNAL_FUNC (cb_button_fields), etable); - gtk_signal_connect ( - GTK_OBJECT (glade_xml_get_widget (gui, "button-grouping")), - "clicked", GTK_SIGNAL_FUNC (cb_button_grouping), etable); - gtk_signal_connect ( - GTK_OBJECT (glade_xml_get_widget (gui, "button-sort")), - "clicked", GTK_SIGNAL_FUNC (cb_button_sort), etable); - gtk_signal_connect ( - GTK_OBJECT (glade_xml_get_widget (gui, "button-filter")), - "clicked", GTK_SIGNAL_FUNC (cb_button_filter), etable); - - load_label_data (gui, etable); - - config_data = g_new (ConfigData, 1); - config_data->gui = gui; - config_data->old_spec = e_table_get_specification (etable); - - gtk_object_set_data ( - GTK_OBJECT (dialog), "config-data", - config_data); - - return dialog; -} - -static void -e_table_gui_destroy_config_data (GtkWidget *widget) -{ - ConfigData *cd = gtk_object_get_data (GTK_OBJECT (widget), "config-data"); - - g_free (cd->old_spec); - gtk_object_destroy (GTK_OBJECT (cd->gui)); - g_free (cd); -} - -void -e_table_gui_config_accept (GtkWidget *widget, ETable *etable) -{ - e_table_gui_destroy_config_data (widget); -} - -void -e_table_gui_config_cancel (GtkWidget *widget, ETable *etable) -{ - e_table_gui_destroy_config_data (widget); -} - -void -e_table_do_gui_config (GtkWidget *parent, ETable *etable) -{ - GnomeDialog *dialog; - int r; - - dialog = GNOME_DIALOG (e_table_gui_config (etable)); - if (!dialog) - return; - - if (parent) - gnome_dialog_set_parent (dialog, GTK_WINDOW (parent)); - - r = gnome_dialog_run (GNOME_DIALOG (dialog)); - - if (r == -1 || r == 1) - e_table_gui_config_cancel (GTK_WIDGET (dialog), etable); - else - e_table_gui_config_accept (GTK_WIDGET (dialog), etable); - - if (r != -1) - gtk_object_destroy (GTK_OBJECT (dialog)); -} - - diff --git a/widgets/e-table/e-table-config.glade b/widgets/e-table/e-table-config.glade deleted file mode 100644 index 15223f21f1..0000000000 --- a/widgets/e-table/e-table-config.glade +++ /dev/null @@ -1,302 +0,0 @@ -<?xml version="1.0"?> -<GTK-Interface> - -<project> - <name>E-table</name> - <program_name>e-table</program_name> - <directory></directory> - <source_directory></source_directory> - <pixmaps_directory></pixmaps_directory> - <language>C</language> - <gnome_support>True</gnome_support> - <gettext_support>True</gettext_support> - <use_widget_names>False</use_widget_names> - <output_main_file>False</output_main_file> - <output_support_files>False</output_support_files> - <output_build_files>False</output_build_files> - <backup_source_files>True</backup_source_files> - <main_source_file>interface.c</main_source_file> - <main_header_file>interface.h</main_header_file> - <handler_source_file>callbacks.c</handler_source_file> - <handler_header_file>callbacks.h</handler_header_file> - <support_source_file>support.c</support_source_file> - <support_header_file>support.h</support_header_file> - <output_translatable_strings>True</output_translatable_strings> - <translatable_strings_file>e-table-config.glade.h</translatable_strings_file> -</project> - -<widget> - <class>GnomeDialog</class> - <name>e-table-config</name> - <visible>False</visible> - <type>GTK_WINDOW_TOPLEVEL</type> - <position>GTK_WIN_POS_NONE</position> - <modal>False</modal> - <allow_shrink>False</allow_shrink> - <allow_grow>False</allow_grow> - <auto_shrink>False</auto_shrink> - <auto_close>False</auto_close> - <hide_on_close>False</hide_on_close> - - <widget> - <class>GtkVBox</class> - <child_name>GnomeDialog:vbox</child_name> - <name>dialog-vbox2</name> - <homogeneous>False</homogeneous> - <spacing>0</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkFrame</class> - <name>top-frame</name> - <border_width>2</border_width> - <label></label> - <label_xalign>0</label_xalign> - <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkTable</class> - <name>table1</name> - <border_width>2</border_width> - <rows>4</rows> - <columns>2</columns> - <homogeneous>False</homogeneous> - <row_spacing>2</row_spacing> - <column_spacing>4</column_spacing> - - <widget> - <class>GtkButton</class> - <name>button-fields</name> - <can_focus>True</can_focus> - <label>Fields</label> - <child> - <left_attach>0</left_attach> - <right_attach>1</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - </widget> - - <widget> - <class>GtkButton</class> - <name>button-grouping</name> - <can_focus>True</can_focus> - <label>Grouping</label> - <child> - <left_attach>0</left_attach> - <right_attach>1</right_attach> - <top_attach>1</top_attach> - <bottom_attach>2</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - </widget> - - <widget> - <class>GtkButton</class> - <name>button-sort</name> - <can_focus>True</can_focus> - <label>Sort</label> - <child> - <left_attach>0</left_attach> - <right_attach>1</right_attach> - <top_attach>2</top_attach> - <bottom_attach>3</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - </widget> - - <widget> - <class>GtkButton</class> - <name>button-filter</name> - <can_focus>True</can_focus> - <label>Filter</label> - <child> - <left_attach>0</left_attach> - <right_attach>1</right_attach> - <top_attach>3</top_attach> - <bottom_attach>4</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label1</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <left_attach>1</left_attach> - <right_attach>2</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>False</yfill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label2</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <left_attach>1</left_attach> - <right_attach>2</right_attach> - <top_attach>1</top_attach> - <bottom_attach>2</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>False</yfill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label3</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <left_attach>1</left_attach> - <right_attach>2</right_attach> - <top_attach>2</top_attach> - <bottom_attach>3</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>False</yfill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label4</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <left_attach>1</left_attach> - <right_attach>2</right_attach> - <top_attach>3</top_attach> - <bottom_attach>4</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>False</yfill> - </child> - </widget> - </widget> - </widget> - - <widget> - <class>GtkHButtonBox</class> - <child_name>GnomeDialog:action_area</child_name> - <name>dialog-action_area2</name> - <layout_style>GTK_BUTTONBOX_END</layout_style> - <spacing>0</spacing> - <child_min_width>85</child_min_width> - <child_min_height>27</child_min_height> - <child_ipad_x>7</child_ipad_x> - <child_ipad_y>0</child_ipad_y> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - <pack>GTK_PACK_END</pack> - </child> - - <widget> - <class>GtkButton</class> - <name>button12</name> - <can_default>True</can_default> - <can_focus>True</can_focus> - <stock_button>GNOME_STOCK_BUTTON_OK</stock_button> - </widget> - - <widget> - <class>GtkButton</class> - <name>button14</name> - <can_default>True</can_default> - <can_focus>True</can_focus> - <stock_button>GNOME_STOCK_BUTTON_CANCEL</stock_button> - </widget> - </widget> - </widget> -</widget> - -</GTK-Interface> diff --git a/widgets/e-table/e-table-config.glade.h b/widgets/e-table/e-table-config.glade.h deleted file mode 100644 index 4dc2ec8d31..0000000000 --- a/widgets/e-table/e-table-config.glade.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Translatable strings file generated by Glade. - * Add this file to your project's POTFILES.in. - * DO NOT compile it as part of your application. - */ - -gchar *s = N_("Fields"); -gchar *s = N_("Grouping"); -gchar *s = N_("Sort"); -gchar *s = N_("Filter"); diff --git a/widgets/e-table/e-table-config.h b/widgets/e-table/e-table-config.h deleted file mode 100644 index 617ef6a331..0000000000 --- a/widgets/e-table/e-table-config.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _E_TABLE_CONFIG_H -#define _E_TABLE_CONFIG_H - -GnomeDialog *e_table_gui_config (ETable *etable); -void e_table_do_gui_config (GtkWidget *, ETable *etable); - -void e_table_gui_config_accept (GtkWidget *widget, ETable *etable); -void e_table_gui_config_cancel (GtkWidget *widget, ETable *etable); - - -#endif /* _E_TABLE_CONFIG_H */ diff --git a/widgets/e-table/e-table-defines.h b/widgets/e-table/e-table-defines.h deleted file mode 100644 index 9bb9e107ac..0000000000 --- a/widgets/e-table/e-table-defines.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __E_TABLE_DEFINES__ -#define __E_TABLE_DEFINES__ 1 - -#define BUTTON_HEIGHT 10 -#define BUTTON_PADDING 2 -#define GROUP_INDENT (BUTTON_HEIGHT + (BUTTON_PADDING * 2)) - -/* Padding above and below of the string in the header display */ -#define HEADER_PADDING 2 - -#define MIN_ARROW_SIZE 10 - -typedef void (*ETableForeachFunc) (int model_row, - gpointer closure); - -#endif diff --git a/widgets/e-table/e-table-example-1.c b/widgets/e-table/e-table-example-1.c deleted file mode 100644 index 7c289778aa..0000000000 --- a/widgets/e-table/e-table-example-1.c +++ /dev/null @@ -1,287 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* This code is GPL. */ -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "e-util/e-cursors.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-cell-checkbox.h" -#include "e-table.h" - -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include "table-test.h" - -/* - * One way in which we make it simpler to build an ETableModel is through - * the ETableSimple class. Instead of creating your own ETableModel - * class, you simply create a new object of the ETableSimple class. You - * give it a bunch of functions that act as callbacks. - * - * You also get to pass a void * to ETableSimple and it gets passed to - * your callbacks. This would be for having multiple models of the same - * type. This is just an example though, so we statically define all the - * data and ignore the void *data parameter. - * - * In our example we will be creating a table model with 6 columns and 10 - * rows. This corresponds to having 6 different types of information and - * 10 different sets of data in our database. - * - * The headers will be hard coded, as will be the example data. - * - */ - -/* - * There are two different meanings to the word "column". The first is - * the model column. A model column corresponds to a specific type of - * data. This is very much like the usage in a database table where a - * column is a field in the database. - * - * The second type of column is a view column. A view column - * corresponds to a visually displayed column. Each view column - * corresponds to a specific model column, though a model column may - * have any number of view columns associated with it, from zero to - * greater than one. - * - * Also, a view column doesn't necessarily depend on only one model - * column. In some cases, the view column renderer can be given a - * reference to another column to get extra information about its - * display. -*/ - -#define ROWS 10 -#define COLS 4 - -#define IMPORTANCE_COLUMN 4 -#define COLOR_COLUMN 5 - -/* - * Here we define the initial layout of the table. This is an xml - * format that allows you to change the initial ordering of the - * columns or to do sorting or grouping initially. This specification - * shows all 5 columns, but moves the importance column nearer to the - * front. It also sorts by the "Full Name" column (ascending.) - * Sorting and grouping take the model column as their arguments - * (sorting is specified by the "column" argument to the leaf elemnt. - */ - -#define INITIAL_SPEC "<ETableSpecification> \ - <columns-shown> \ - <column> 0 </column> \ - <column> 4 </column> \ - <column> 1 </column> \ - <column> 2 </column> \ - <column> 3 </column> \ - </columns-shown> \ - <grouping> <leaf column=\"1\" ascending=\"1\"/> </grouping> \ -</ETableSpecification>" - -char *headers [COLS] = { - "Email", - "Full Name", - "Address", - "Phone" -}; - -/* - * Virtual Column list: - * 0 Email - * 1 Full Name - * 2 Address - * 3 Phone - */ - -char *table_data [ROWS] [COLS]; - -/* - * ETableSimple callbacks - * These are the callbacks that define the behavior of our custom model. - */ - -/* - * Since our model is a constant size, we can just return its size in - * the column and row count fields. - */ - -/* This function returns the number of columns in our ETableModel. */ -static int -my_col_count (ETableModel *etc, void *data) -{ - return COLS; -} - -/* This function returns the number of rows in our ETableModel. */ -static int -my_row_count (ETableModel *etc, void *data) -{ - return ROWS; -} - -/* This function returns the value at a particular point in our ETableModel. */ -static void * -my_value_at (ETableModel *etc, int col, int row, void *data) -{ - return (void *) table_data [row] [col]; -} - -/* This function sets the value at a particular point in our ETableModel. */ -static void -my_set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_free (table_data [row] [col]); - table_data [row] [col] = g_strdup (val); -} - -/* This function returns whether a particular cell is editable. */ -static gboolean -my_is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -/* This function duplicates the value passed to it. */ -static void * -my_duplicate_value (ETableModel *etc, int col, const void *value, void *data) -{ - return g_strdup (value); -} - -/* This function frees the value passed to it. */ -static void -my_free_value (ETableModel *etc, int col, void *value, void *data) -{ - g_free (value); -} - -/* This function creates an empty value. */ -static void * -my_initialize_value (ETableModel *etc, int col, void *data) -{ - return g_strdup (""); -} - -/* This function reports if a value is empty. */ -static gboolean -my_value_is_empty (ETableModel *etc, int col, const void *value, void *data) -{ - return !(value && *(char *)value); -} - -/* This function reports if a value is empty. */ -static char * -my_value_to_string (ETableModel *etc, int col, const void *value, void *data) -{ - return g_strdup(value); -} - -/* We create a window containing our new table. */ -static void -create_table (void) -{ - GtkWidget *e_table, *window, *frame; - ECell *cell_left_just; - ETableHeader *e_table_header; - int i, j; - ETableModel *e_table_model = NULL; - - /* First we fill in the simple data. */ - for (i = 0; i < ROWS; i++){ - for (j = 0; j < COLS; j++) - table_data [i] [j] = g_strdup (""); - } - /* Next we create our model. This uses the functions we defined - earlier. */ - e_table_model = e_table_simple_new ( - my_col_count, my_row_count, my_value_at, - my_set_value_at, my_is_cell_editable, - my_duplicate_value, my_free_value, - my_initialize_value, my_value_is_empty, - my_value_to_string, - NULL); - /* - * Next we create a header. The ETableHeader is used in two - * different way. The first is the full_header. This is the - * list of possible columns in the view. The second use is - * completely internal. Many of the ETableHeader functions are - * for that purpose. The only functions we really need are - * e_table_header_new and e_table_header_add_col. - * - * First we create the header. - */ - e_table_header = e_table_header_new (); - - /* - * Next we have to build renderers for all of the columns. - * Since all our columns are text columns, we can simply use - * the same renderer over and over again. If we had different - * types of columns, we could use a different renderer for - * each column. - */ - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - /* - * Next we create a column object for each view column and add - * them to the header. We don't create a column object for - * the importance column since it will not be shown. - */ - for (i = 0; i < COLS; i++) { - /* Create the column. */ - ETableCol *ecol = e_table_col_new ( - i, headers [i], - 1.0, 20, cell_left_just, - g_str_compare, TRUE); - /* Add it to the header. */ - e_table_header_add_column (e_table_header, ecol, i); - } - - /* - * Here we create a window for our new table. This window - * will get shown and the person will be able to test their - * item. - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - - /* This frame is simply to get a bevel around our table. */ - frame = gtk_frame_new (NULL); - - /* - * Here we create the table. We give it the three pieces of - * the table we've created, the header, the model, and the - * initial layout. It does the rest. - */ - e_table = e_table_new (e_table_header, e_table_model, INITIAL_SPEC); - - /* Build the gtk widget hierarchy. */ - gtk_container_add (GTK_CONTAINER (frame), e_table); - gtk_container_add (GTK_CONTAINER (window), frame); - - /* Size the initial window. */ - gtk_widget_set_usize (window, 200, 200); - - /* Show it all. */ - gtk_widget_show_all (window); -} - -/* This is the main function which just initializes gnome and call our create_table function */ - -int -main (int argc, char *argv []) -{ - gnome_init ("TableExample", "TableExample", argc, argv); - e_cursors_init (); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - create_table (); - - gtk_main (); - - e_cursors_shutdown (); - return 0; -} - diff --git a/widgets/e-table/e-table-example-2.c b/widgets/e-table/e-table-example-2.c deleted file mode 100644 index e9d8d9ea80..0000000000 --- a/widgets/e-table/e-table-example-2.c +++ /dev/null @@ -1,330 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* This code is GPL. */ -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "e-util/e-cursors.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-cell-checkbox.h" -#include "e-table.h" - -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include "table-test.h" - -/* -One way in which we make it simpler to build an ETableModel is through -the ETableSimple class. Instead of creating your own ETableModel -class, you simply create a new object of the ETableSimple class. You -give it a bunch of functions that act as callbacks. - -You also get to pass a void * to ETableSimple and it gets passed to -your callbacks. This would be for having multiple models of the same -type. This is just an example though, so we statically define all the -data and ignore the void *data parameter. - -In our example we will be creating a table model with 6 columns and 10 -rows. This corresponds to having 6 different types of information and -10 different sets of data in our database. - -The headers will be hard coded, as will be the example data. - -*/ - -/* - There are two different meanings to the word "column". The first is - the model column. A model column corresponds to a specific type of - data. This is very much like the usage in a database table where a - column is a field in the database. - - The second type of column is a view column. A view column - corresponds to a visually displayed column. Each view column - corresponds to a specific model column, though a model column may - have any number of view columns associated with it, from zero to - greater than one. - - Also, a view column doesn't necessarily depend on only one model - column. In some cases, the view column renderer can be given a - reference to another column to get extra information about its - display. -*/ - -#define ROWS 10 -#define VIEW_COLS 4 -#define PHYSICAL_COLS 5 -#define VIRTUAL_COLS 6 - -#define IMPORTANCE_COLUMN 4 -#define COLOR_COLUMN 5 - -/* Here we define the initial layout of the table. This is an xml - format that allows you to change the initial ordering of the - columns or to do sorting or grouping initially. This specification - shows all 5 columns, but moves the importance column nearer to the - front. It also sorts by the "Full Name" column (ascending.) - Sorting and grouping take the model column as their arguments - (sorting is specified by the "column" argument to the leaf elemnt. */ -#define INITIAL_SPEC "<ETableSpecification> \ - <columns-shown> \ - <column> 0 </column> \ - <column> 4 </column> \ - <column> 1 </column> \ - <column> 2 </column> \ - <column> 3 </column> \ - </columns-shown> \ - <grouping> <leaf column=\"1\" ascending=\"1\"/> </grouping> \ -</ETableSpecification>" - -char *headers[VIEW_COLS] = { - "Email", - "Full Name", - "Address", - "Phone" -}; - -/* Virtual Column list: - 0 Full Name - 1 Email - 2 Address - 3 Phone - 4 Importance field. This field will be a boolean. It also has a - special header, so doesn't appear in the headers list. - 5 Color field. This column is also not displayed. It is also - not stored in the database. It's calculated based on the - Importance field. -*/ - -char *table_data[ROWS][VIEW_COLS]; -gboolean importance_data[ROWS]; - -/* - * ETableSimple callbacks - * These are the callbacks that define the behavior of our custom model. - */ - -/* Since our model is a constant size, we can just return its size in - the column and row count fields. */ - -static GdkColor *color1; -static GdkColor *color2; - -static int -my_col_count (ETableModel *etc, void *data) -{ - return VIRTUAL_COLS; -} - -static int -my_row_count (ETableModel *etc, void *data) -{ - return ROWS; -} - -static void * -my_value_at (ETableModel *etc, int col, int row, void *data) -{ - if (col == COLOR_COLUMN){ - if (importance_data[row]){ - return color1; - } else { - return color2; - } - } else if (col == IMPORTANCE_COLUMN){ - return (gpointer) importance_data[row]; - } else { - return (void *) table_data [row][col]; - } -} - -static void -my_set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - if (col == COLOR_COLUMN){ - } else if (col == IMPORTANCE_COLUMN){ - importance_data[row] = (gboolean) val; - } else { - g_free (table_data [row][col]); - table_data [row][col] = g_strdup (val); - } -} - -static gboolean -my_is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - if (col == IMPORTANCE_COLUMN) - return FALSE; - else - return TRUE; -} - -static void * -my_duplicate_value (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == COLOR_COLUMN){ - return (void *) value; - } else if (col == IMPORTANCE_COLUMN){ - return (void *) value; - } else { - return g_strdup (value); - } -} - -static void -my_free_value (ETableModel *etc, int col, void *value, void *data) -{ - if (col == COLOR_COLUMN){ - } else if (col == IMPORTANCE_COLUMN){ - } else { - g_free (value); - } -} - -static void * -my_initialize_value (ETableModel *etc, int col, void *data) -{ - if (col == COLOR_COLUMN){ - return NULL; - } else if (col == IMPORTANCE_COLUMN){ - return NULL; - } else { - return g_strdup (""); - } -} - -static gboolean -my_value_is_empty (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == COLOR_COLUMN){ - return value == NULL; - } else if (col == IMPORTANCE_COLUMN){ - return value == NULL; - } else { - return !(value && *(char *)value); - } -} - -static char * -my_value_to_string (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == COLOR_COLUMN){ - return g_strdup_printf("%d", (int) value); - } else if (col == IMPORTANCE_COLUMN){ - return g_strdup_printf("%d", (int) value); - } else { - return g_strdup(value); - } -} - -/* We create a window containing our new table. */ -static void -create_table () -{ - GtkWidget *e_table, *window, *frame; - ECell *cell_left_just; - ECell *cell_checkbox; - ETableHeader *e_table_header; - int i, j; - ETableModel *e_table_model = NULL; - ETableCol *ecol; - GdkPixbuf *pixbuf; - - /* First we fill in the simple data. */ - for (i = 0; i < ROWS; i++){ - for (j = 0; j < VIEW_COLS; j++){ - table_data[i][j] = g_strdup (""); - } - importance_data[i] = FALSE; - } - /* Next we create our model. This uses the functions we defined - earlier. */ - e_table_model = e_table_simple_new ( - my_col_count, my_row_count, my_value_at, - my_set_value_at, my_is_cell_editable, - my_duplicate_value, my_free_value, - my_initialize_value, my_value_is_empty, - my_value_to_string, - NULL); - /* - Next we create a header. The ETableHeader is used in two - different way. The first is the full_header. This is the - list of possible columns in the view. The second use is - completely internal. Many of the ETableHeader functions are - for that purpose. The only functions we really need are - e_table_header_new and e_table_header_add_col. - - First we create the header. */ - e_table_header = e_table_header_new (); - - /* Next we have to build renderers for all of the columns. - Since all our columns are text columns, we can simply use - the same renderer over and over again. If we had different - types of columns, we could use a different renderer for - each column. */ - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - /* Next we create a column object for each view column and add - them to the header. We don't create a column object for - the importance column since it will not be shown. */ - for (i = 0; i < VIEW_COLS; i++){ - /* Create the column. */ - ETableCol *ecol = e_table_col_new ( - i, headers [i], - 1.0, 20, cell_left_just, - g_str_compare, TRUE); - /* Add it to the header. */ - e_table_header_add_column (e_table_header, ecol, i); - } - - /* Next we add a special column for the check box. */ - - cell_checkbox = e_cell_checkbox_new (); - pixbuf = gdk_pixbuf_new_from_file ("clip.png"); - ecol = e_table_col_new_with_pixbuf (i, pixbuf, 0.0, 18, cell_checkbox, g_int_compare, TRUE); - e_table_header_add_column (e_table_header, ecol, i); - - /* - * Setup GUI - */ - /* Here we create a window for our new table. This window - will get shown and the person will be able to test their - item. */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - /* This frame is simply to get a bevel around our table. */ - frame = gtk_frame_new (NULL); - /* Here we create the table. We give it the three pieces of - the table we've created, the header, the model, and the - initial layout. It does the rest. */ - e_table = e_table_new (e_table_header, e_table_model, INITIAL_SPEC); - - /* Build the gtk widget hierarchy. */ - gtk_container_add (GTK_CONTAINER (frame), e_table); - gtk_container_add (GTK_CONTAINER (window), frame); - - /* Size the initial window. */ - gtk_widget_set_usize (window, 200, 200); - /* Show it all. */ - gtk_widget_show_all (window); -} - - - -int -main (int argc, char *argv []) -{ - gnome_init ("TableExample", "TableExample", argc, argv); - e_cursors_init (); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - create_table (); - - gtk_main (); - - e_cursors_shutdown (); - return 0; -} diff --git a/widgets/e-table/e-table-field-chooser-dialog.c b/widgets/e-table/e-table-field-chooser-dialog.c deleted file mode 100644 index b54c57e80e..0000000000 --- a/widgets/e-table/e-table-field-chooser-dialog.c +++ /dev/null @@ -1,190 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-field-chooser-dialog.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <config.h> -#include <gnome.h> -#include <e-table-field-chooser-dialog.h> - -static void e_table_field_chooser_dialog_init (ETableFieldChooserDialog *card); -static void e_table_field_chooser_dialog_class_init (ETableFieldChooserDialogClass *klass); -static void e_table_field_chooser_dialog_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); -static void e_table_field_chooser_dialog_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_table_field_chooser_dialog_destroy (GtkObject *object); -static void e_table_field_chooser_dialog_clicked (GnomeDialog *dialog, gint button); - -static GnomeDialogClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0, - ARG_DND_CODE, - ARG_FULL_HEADER, -}; - -GtkType -e_table_field_chooser_dialog_get_type (void) -{ - static GtkType table_field_chooser_dialog_type = 0; - - if (!table_field_chooser_dialog_type) - { - static const GtkTypeInfo table_field_chooser_dialog_info = - { - "ETableFieldChooserDialog", - sizeof (ETableFieldChooserDialog), - sizeof (ETableFieldChooserDialogClass), - (GtkClassInitFunc) e_table_field_chooser_dialog_class_init, - (GtkObjectInitFunc) e_table_field_chooser_dialog_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - table_field_chooser_dialog_type = gtk_type_unique (gnome_dialog_get_type (), &table_field_chooser_dialog_info); - } - - return table_field_chooser_dialog_type; -} - -static void -e_table_field_chooser_dialog_class_init (ETableFieldChooserDialogClass *klass) -{ - GtkObjectClass *object_class; - GnomeDialogClass *dialog_class; - - object_class = (GtkObjectClass*) klass; - dialog_class = GNOME_DIALOG_CLASS (klass); - - parent_class = gtk_type_class (gnome_dialog_get_type ()); - - object_class->destroy = e_table_field_chooser_dialog_destroy; - object_class->set_arg = e_table_field_chooser_dialog_set_arg; - object_class->get_arg = e_table_field_chooser_dialog_get_arg; - - dialog_class->clicked = e_table_field_chooser_dialog_clicked; - - gtk_object_add_arg_type ("ETableFieldChooserDialog::dnd_code", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_DND_CODE); - gtk_object_add_arg_type ("ETableFieldChooserDialog::full_header", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_FULL_HEADER); -} - -static void -e_table_field_chooser_dialog_init (ETableFieldChooserDialog *e_table_field_chooser_dialog) -{ - GtkWidget *widget; - - e_table_field_chooser_dialog->etfc = NULL; - e_table_field_chooser_dialog->dnd_code = g_strdup(""); - e_table_field_chooser_dialog->full_header = NULL; - - gnome_dialog_append_buttons(GNOME_DIALOG(e_table_field_chooser_dialog), - GNOME_STOCK_BUTTON_CLOSE, - NULL); - - gtk_window_set_policy(GTK_WINDOW(e_table_field_chooser_dialog), FALSE, TRUE, FALSE); - - widget = e_table_field_chooser_new(); - e_table_field_chooser_dialog->etfc = E_TABLE_FIELD_CHOOSER(widget); - - gtk_object_set(GTK_OBJECT(widget), - "dnd_code", e_table_field_chooser_dialog->dnd_code, - "full_header", e_table_field_chooser_dialog->full_header, - NULL); - - gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(e_table_field_chooser_dialog)->vbox), - widget, TRUE, TRUE, 0); - - gtk_widget_show(GTK_WIDGET(widget)); -} - -GtkWidget* -e_table_field_chooser_dialog_new (void) -{ - GtkWidget *widget = GTK_WIDGET (gtk_type_new (e_table_field_chooser_dialog_get_type ())); - return widget; -} - -static void -e_table_field_chooser_dialog_destroy (GtkObject *object) -{ - ETableFieldChooserDialog *etfcd = E_TABLE_FIELD_CHOOSER_DIALOG (object); - g_free(etfcd->dnd_code); - if (etfcd->full_header) - gtk_object_unref(GTK_OBJECT(etfcd->full_header)); -} - -static void -e_table_field_chooser_dialog_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableFieldChooserDialog *etfcd = E_TABLE_FIELD_CHOOSER_DIALOG(object); - switch (arg_id){ - case ARG_DND_CODE: - g_free(etfcd->dnd_code); - etfcd->dnd_code = g_strdup(GTK_VALUE_STRING (*arg)); - if (etfcd->etfc) - gtk_object_set(GTK_OBJECT(etfcd->etfc), - "dnd_code", etfcd->dnd_code, - NULL); - break; - case ARG_FULL_HEADER: - if (etfcd->full_header) - gtk_object_unref(GTK_OBJECT(etfcd->full_header)); - if (GTK_VALUE_OBJECT(*arg)) - etfcd->full_header = E_TABLE_HEADER(GTK_VALUE_OBJECT(*arg)); - else - etfcd->full_header = NULL; - if (etfcd->full_header) - gtk_object_ref(GTK_OBJECT(etfcd->full_header)); - if (etfcd->etfc) - gtk_object_set(GTK_OBJECT(etfcd->etfc), - "full_header", etfcd->full_header, - NULL); - break; - default: - break; - } -} - -static void -e_table_field_chooser_dialog_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableFieldChooserDialog *etfcd = E_TABLE_FIELD_CHOOSER_DIALOG(object); - switch (arg_id) { - case ARG_DND_CODE: - GTK_VALUE_STRING (*arg) = g_strdup (etfcd->dnd_code); - break; - case ARG_FULL_HEADER: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etfcd->full_header); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -e_table_field_chooser_dialog_clicked (GnomeDialog *dialog, int button) -{ - if (button == 0) - gnome_dialog_close(dialog); -} diff --git a/widgets/e-table/e-table-field-chooser-dialog.h b/widgets/e-table/e-table-field-chooser-dialog.h deleted file mode 100644 index c209210dda..0000000000 --- a/widgets/e-table/e-table-field-chooser-dialog.h +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-table-field-chooser-dialog.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef __E_TABLE_FIELD_CHOOSER_DIALOG_H__ -#define __E_TABLE_FIELD_CHOOSER_DIALOG_H__ - -#include <gnome.h> -#include <glade/glade.h> -#include "e-table-field-chooser.h" -#include "e-table-header.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ETableFieldChooserDialog - A dialog displaying information about a contact. - * - * The following arguments are available: - * - * name type read/write description - * -------------------------------------------------------------------------------- - */ - -#define E_TABLE_FIELD_CHOOSER_DIALOG_TYPE (e_table_field_chooser_dialog_get_type ()) -#define E_TABLE_FIELD_CHOOSER_DIALOG(obj) (GTK_CHECK_CAST ((obj), E_TABLE_FIELD_CHOOSER_DIALOG_TYPE, ETableFieldChooserDialog)) -#define E_TABLE_FIELD_CHOOSER_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TABLE_FIELD_CHOOSER_DIALOG_TYPE, ETableFieldChooserDialogClass)) -#define E_IS_TABLE_FIELD_CHOOSER_DIALOG(obj) (GTK_CHECK_TYPE ((obj), E_TABLE_FIELD_CHOOSER_DIALOG_TYPE)) -#define E_IS_TABLE_FIELD_CHOOSER_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TABLE_FIELD_CHOOSER_DIALOG_TYPE)) - - -typedef struct _ETableFieldChooserDialog ETableFieldChooserDialog; -typedef struct _ETableFieldChooserDialogClass ETableFieldChooserDialogClass; - -struct _ETableFieldChooserDialog -{ - GnomeDialog parent; - - /* item specific fields */ - ETableFieldChooser *etfc; - gchar *dnd_code; - ETableHeader *full_header; -}; - -struct _ETableFieldChooserDialogClass -{ - GnomeDialogClass parent_class; -}; - - -GtkWidget *e_table_field_chooser_dialog_new(void); -GtkType e_table_field_chooser_dialog_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TABLE_FIELD_CHOOSER_DIALOG_H__ */ diff --git a/widgets/e-table/e-table-field-chooser-item.c b/widgets/e-table/e-table-field-chooser-item.c deleted file mode 100644 index e23fc4c9f5..0000000000 --- a/widgets/e-table/e-table-field-chooser-item.c +++ /dev/null @@ -1,566 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-column-view.c: A canvas item based view of the ETableColumn. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, 2000 Helix Code, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkdnd.h> -#include <libgnomeui/gnome-canvas.h> -#include <libgnomeui/gnome-canvas-util.h> -#include <libgnomeui/gnome-canvas-polygon.h> -#include <libgnomeui/gnome-canvas-rect-ellipse.h> -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include "e-util/e-xml-utils.h" -#include "e-util/e-canvas.h" - -#include "e-table-header.h" -#include "e-table-col-dnd.h" -#include "e-table-defines.h" - -#include "e-table-field-chooser-item.h" - -#if 0 -enum { - BUTTON_PRESSED, - LAST_SIGNAL -}; - -static guint etfci_signals [LAST_SIGNAL] = { 0, }; -#endif - -#define PARENT_OBJECT_TYPE gnome_canvas_item_get_type () - -#define ELEMENTS(x) (sizeof (x) / sizeof (x[0])) - -static GnomeCanvasItemClass *etfci_parent_class; - -static void etfci_drop_table_header (ETableFieldChooserItem *etfci); - -enum { - ARG_0, - ARG_FULL_HEADER, - ARG_DND_CODE, - ARG_WIDTH, - ARG_HEIGHT, -}; - -static void -etfci_destroy (GtkObject *object){ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (object); - - etfci_drop_table_header (etfci); - - gdk_font_unref(etfci->font); - - if (GTK_OBJECT_CLASS (etfci_parent_class)->destroy) - (*GTK_OBJECT_CLASS (etfci_parent_class)->destroy) (object); -} - -static void -etfci_reflow (GnomeCanvasItem *item, gint flags) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - double old_height; - - old_height = etfci->height; - - etfci->height = e_table_header_count (etfci->full_header) * etfci->button_height; - - if (old_height != etfci->height) - e_canvas_item_request_parent_reflow(item); - - gnome_canvas_item_request_update(item); -} - -static void -etfci_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - double i2c [6]; - ArtPoint c1, c2, i1, i2; - - if (GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)->update) - (*GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)->update)(item, affine, clip_path, flags); - - i1.x = i1.y = 0; - i2.x = etfci->width; - i2.y = etfci->height; - - gnome_canvas_item_i2c_affine (item, i2c); - art_affine_point (&c1, &i1, i2c); - art_affine_point (&c2, &i2, i2c); - - if (item->x1 != c1.x || - item->y1 != c1.y || - item->x2 != c2.x || - item->y2 != c2.y) - { - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); - item->x1 = c1.x; - item->y1 = c1.y; - item->x2 = c2.x; - item->y2 = c2.y; - - gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item); - } - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); -} - -static void -etfci_font_load (ETableFieldChooserItem *etfci, char *font) -{ - if (etfci->font) - gdk_font_unref (etfci->font); - etfci->font = NULL; - - if (font) - etfci->font = gdk_fontset_load (font); - - if (etfci->font == NULL) { - etfci->font = GTK_WIDGET(GNOME_CANVAS_ITEM(etfci)->canvas)->style->font; - gdk_font_ref(etfci->font); - } - - etfci->button_height = etfci->font->ascent + etfci->font->descent + HEADER_PADDING; -} - -static void -etfci_drop_table_header (ETableFieldChooserItem *etfci) -{ - GtkObject *header; - - if (!etfci->full_header) - return; - - header = GTK_OBJECT (etfci->full_header); - if (etfci->structure_change_id) - gtk_signal_disconnect (header, etfci->structure_change_id); - if (etfci->dimension_change_id) - gtk_signal_disconnect (header, etfci->dimension_change_id); - etfci->structure_change_id = 0; - etfci->dimension_change_id = 0; - - if (header) - gtk_object_unref (header); - etfci->full_header = NULL; - etfci->height = 0; - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(etfci)); -} - -static void -structure_changed (ETableHeader *header, ETableFieldChooserItem *etfci) -{ - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(etfci)); -} - -static void -dimension_changed (ETableHeader *header, int col, ETableFieldChooserItem *etfci) -{ - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(etfci)); -} - -static void -etfci_add_table_header (ETableFieldChooserItem *etfci, ETableHeader *header) -{ - etfci->full_header = header; - gtk_object_ref (GTK_OBJECT (etfci->full_header)); - - etfci->structure_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "structure_change", - GTK_SIGNAL_FUNC(structure_changed), etfci); - etfci->dimension_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "dimension_change", - GTK_SIGNAL_FUNC(dimension_changed), etfci); - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(etfci)); -} - -static void -etfci_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableFieldChooserItem *etfci; - - item = GNOME_CANVAS_ITEM (o); - etfci = E_TABLE_FIELD_CHOOSER_ITEM (o); - - switch (arg_id){ - case ARG_FULL_HEADER: - etfci_drop_table_header (etfci); - if (GTK_VALUE_OBJECT (*arg)) - etfci_add_table_header (etfci, E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg))); - break; - - case ARG_DND_CODE: - g_free(etfci->dnd_code); - etfci->dnd_code = g_strdup(GTK_VALUE_STRING (*arg)); - break; - - case ARG_WIDTH: - etfci->width = GTK_VALUE_DOUBLE (*arg); - gnome_canvas_item_request_update(item); - break; - } -} - -static void -etfci_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableFieldChooserItem *etfci; - - item = GNOME_CANVAS_ITEM (o); - etfci = E_TABLE_FIELD_CHOOSER_ITEM (o); - - switch (arg_id){ - - case ARG_DND_CODE: - GTK_VALUE_STRING (*arg) = g_strdup (etfci->dnd_code); - break; - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = etfci->width; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = etfci->height; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -etfci_drag_data_get (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - ETableFieldChooserItem *etfci) -{ - if (etfci->drag_col != -1) { - gchar *string = g_strdup_printf("%d", etfci->drag_col); - gtk_selection_data_set(selection_data, - GDK_SELECTION_TYPE_STRING, - sizeof(string[0]), - string, - strlen(string)); - g_free(string); - } -} - -static void -etfci_drag_end (GtkWidget *canvas, - GdkDragContext *context, - ETableFieldChooserItem *etfci) -{ - etfci->drag_col = -1; -} - -static void -etfci_realize (GnomeCanvasItem *item) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - GdkWindow *window; - - if (GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)-> realize) - (*GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)->realize)(item); - - window = GTK_WIDGET (item->canvas)->window; - - if (!etfci->font) - etfci_font_load (etfci, NULL); - - etfci->drag_end_id = gtk_signal_connect ( - GTK_OBJECT (item->canvas), "drag_end", - GTK_SIGNAL_FUNC (etfci_drag_end), etfci); - etfci->drag_data_get_id = gtk_signal_connect ( - GTK_OBJECT (item->canvas), "drag_data_get", - GTK_SIGNAL_FUNC (etfci_drag_data_get), etfci); - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(etfci)); -} - -static void -etfci_unrealize (GnomeCanvasItem *item) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - - if (etfci->font) - gdk_font_unref (etfci->font); - etfci->font = NULL; - - gtk_signal_disconnect (GTK_OBJECT (item->canvas), etfci->drag_end_id); - etfci->drag_end_id = 0; - gtk_signal_disconnect (GTK_OBJECT (item->canvas), etfci->drag_data_get_id); - etfci->drag_data_get_id = 0; - - if (GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)->unrealize)(item); -} - -static void -draw_button (ETableFieldChooserItem *etfci, ETableCol *col, - GdkDrawable *drawable, GtkStyle *style, - int x, int y, int width, int height) -{ - GdkRectangle clip; - int xtra; - GdkRectangle area; - - GtkWidget *widget = GTK_WIDGET(GNOME_CANVAS_ITEM(etfci)->canvas); - - gdk_window_clear_area (drawable, x, y, width, height); - - area.x = x; - area.y = y; - area.width = width; - area.height = height; - - gtk_paint_box (style, drawable, - GTK_STATE_NORMAL, GTK_SHADOW_OUT, - &area, widget, "button", - x, y, width, height); - - clip.x = x + HEADER_PADDING / 2; - clip.y = y + HEADER_PADDING / 2; - clip.width = width - HEADER_PADDING; - clip.height = etfci->button_height; - - if (col->is_pixbuf){ - xtra = (clip.width - gdk_pixbuf_get_width (col->pixbuf))/2; - - xtra += HEADER_PADDING / 2; - - gdk_pixbuf_render_to_drawable_alpha (col->pixbuf, - drawable, - 0, 0, - x + xtra, y + (clip.height - gdk_pixbuf_get_height (col->pixbuf)) / 2, - gdk_pixbuf_get_width (col->pixbuf), gdk_pixbuf_get_height(col->pixbuf), - GDK_PIXBUF_ALPHA_FULL, 128, - GDK_RGB_DITHER_NORMAL, - 0, 0); - } else { - /* Center the thing */ - xtra = (clip.width - gdk_string_measure (etfci->font, col->text))/2; - - /* Skip over border */ - if (xtra < 0) - xtra = 0; - - xtra += HEADER_PADDING / 2; - - gdk_draw_text ( - drawable, etfci->font, - style->text_gc[GTK_STATE_NORMAL], x + xtra, y + etfci->button_height - etfci->font->descent - HEADER_PADDING / 2, - col->text, strlen (col->text)); - } -} - -static void -etfci_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - const int rows = e_table_header_count (etfci->full_header); - int y1, y2; - int row; - - y1 = y2 = 0; - for (row = 0; row < rows; row++, y1 = y2){ - ETableCol *ecol = e_table_header_get_column (etfci->full_header, row); - - y2 += etfci->button_height; - - if (y1 > (y + height)) - break; - - if (y2 < y) - continue; - - draw_button (etfci, ecol, drawable, - GTK_WIDGET (canvas)->style, - - x, y1 - y, etfci->width, y2 - y1); - } -} - -static double -etfci_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - -static gboolean -etfci_maybe_start_drag (ETableFieldChooserItem *etfci, double x, double y) -{ - if (!etfci->maybe_drag) - return FALSE; - - if (MAX (abs (etfci->click_x - x), - abs (etfci->click_y - y)) <= 3) - return FALSE; - - return TRUE; -} - -static void -etfci_start_drag (ETableFieldChooserItem *etfci, GdkEvent *event, double x, double y) -{ - GtkWidget *widget = GTK_WIDGET (GNOME_CANVAS_ITEM (etfci)->canvas); - GtkTargetList *list; - GdkDragContext *context; - ETableCol *ecol; - GdkPixmap *pixmap; - int drag_col; - - GtkTargetEntry etfci_drag_types [] = { - { TARGET_ETABLE_COL_TYPE, 0, TARGET_ETABLE_COL_HEADER }, - }; - - drag_col = y / etfci->button_height; - - if (drag_col < 0 || drag_col > e_table_header_count(etfci->full_header)) - return; - - ecol = e_table_header_get_column (etfci->full_header, drag_col); - - etfci->drag_col = ecol->col_idx; - - etfci_drag_types[0].target = g_strdup_printf("%s-%s", etfci_drag_types[0].target, etfci->dnd_code); - list = gtk_target_list_new (etfci_drag_types, ELEMENTS (etfci_drag_types)); - context = gtk_drag_begin (widget, list, GDK_ACTION_MOVE, 1, event); - g_free(etfci_drag_types[0].target); - - - pixmap = gdk_pixmap_new (widget->window, etfci->width, etfci->button_height, -1); - draw_button (etfci, ecol, pixmap, - widget->style, - 0, 0, etfci->width, etfci->button_height); - gtk_drag_set_icon_pixmap (context, - gdk_window_get_colormap (widget->window), - pixmap, - NULL, - etfci->width / 2, - etfci->button_height / 2); - gdk_pixmap_unref (pixmap); - etfci->maybe_drag = FALSE; -} - -/* - * Handles the events on the ETableFieldChooserItem - */ -static int -etfci_event (GnomeCanvasItem *item, GdkEvent *e) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - int x, y; - - switch (e->type){ - case GDK_MOTION_NOTIFY: - gnome_canvas_w2c (canvas, e->motion.x, e->motion.y, &x, &y); - - if (etfci_maybe_start_drag (etfci, x, y)) - etfci_start_drag (etfci, e, x, y); - break; - - case GDK_BUTTON_PRESS: - gnome_canvas_w2c (canvas, e->button.x, e->button.y, &x, &y); - - if (e->button.button == 1){ - etfci->click_x = x; - etfci->click_y = y; - etfci->maybe_drag = TRUE; - } - break; - - case GDK_BUTTON_RELEASE: { - etfci->maybe_drag = FALSE; - break; - } - - default: - return FALSE; - } - return TRUE; -} - -static void -etfci_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - - etfci_parent_class = gtk_type_class (PARENT_OBJECT_TYPE); - - object_class->destroy = etfci_destroy; - object_class->set_arg = etfci_set_arg; - object_class->get_arg = etfci_get_arg; - - item_class->update = etfci_update; - item_class->realize = etfci_realize; - item_class->unrealize = etfci_unrealize; - item_class->draw = etfci_draw; - item_class->point = etfci_point; - item_class->event = etfci_event; - - gtk_object_add_arg_type ("ETableFieldChooserItem::dnd_code", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_DND_CODE); - gtk_object_add_arg_type ("ETableFieldChooserItem::full_header", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_FULL_HEADER); - gtk_object_add_arg_type ("ETableFieldChooserItem::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ETableFieldChooserItem::height", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_HEIGHT); -} - -static void -etfci_init (GnomeCanvasItem *item) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - - etfci->full_header = NULL; - - etfci->height = etfci->width = 0; - etfci->button_height = 0; - - etfci->font = NULL; - - etfci->structure_change_id = 0; - etfci->dimension_change_id = 0; - - etfci->dnd_code = NULL; - - etfci->maybe_drag = 0; - etfci->drag_end_id = 0; - - e_canvas_item_set_reflow_callback(item, etfci_reflow); -} - -GtkType -e_table_field_chooser_item_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableFieldChooserItem", - sizeof (ETableFieldChooserItem), - sizeof (ETableFieldChooserItemClass), - (GtkClassInitFunc) etfci_class_init, - (GtkObjectInitFunc) etfci_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_OBJECT_TYPE, &info); - } - - return type; -} - diff --git a/widgets/e-table/e-table-field-chooser-item.h b/widgets/e-table/e-table-field-chooser-item.h deleted file mode 100644 index 4b349f40e3..0000000000 --- a/widgets/e-table/e-table-field-chooser-item.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_FIELD_CHOOSER_ITEM_H_ -#define _E_TABLE_FIELD_CHOOSER_ITEM_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gnome-xml/tree.h> -#include "e-table-header.h" - -#define E_TABLE_FIELD_CHOOSER_ITEM_TYPE (e_table_field_chooser_item_get_type ()) -#define E_TABLE_FIELD_CHOOSER_ITEM(o) (GTK_CHECK_CAST ((o), E_TABLE_FIELD_CHOOSER_ITEM_TYPE, ETableFieldChooserItem)) -#define E_TABLE_FIELD_CHOOSER_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_FIELD_CHOOSER_ITEM_TYPE, ETableFieldChooserItemClass)) -#define E_IS_TABLE_FIELD_CHOOSER_ITEM(o) (GTK_CHECK_TYPE ((o), E_TABLE_FIELD_CHOOSER_ITEM_TYPE)) -#define E_IS_TABLE_FIELD_CHOOSER_ITEM_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_FIELD_CHOOSER_ITEM_TYPE)) - -typedef struct { - GnomeCanvasItem parent; - ETableHeader *full_header; - - double height, width; - double button_height; - - GdkFont *font; - - /* - * Ids - */ - int structure_change_id, dimension_change_id; - - gchar *dnd_code; - - /* - * For dragging columns - */ - guint maybe_drag:1; - int click_x, click_y; - int drag_col; - guint drag_data_get_id; - guint drag_end_id; -} ETableFieldChooserItem; - -typedef struct { - GnomeCanvasItemClass parent_class; -} ETableFieldChooserItemClass; - -GtkType e_table_field_chooser_item_get_type (void); - -#endif /* _E_TABLE_FIELD_CHOOSER_ITEM_H_ */ diff --git a/widgets/e-table/e-table-field-chooser.c b/widgets/e-table/e-table-field-chooser.c deleted file mode 100644 index 0d56945f7f..0000000000 --- a/widgets/e-table/e-table-field-chooser.c +++ /dev/null @@ -1,246 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-field-chooser.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <config.h> -#include <gnome.h> -#include <e-table-field-chooser.h> -#include <e-table-field-chooser-item.h> - -static void e_table_field_chooser_init (ETableFieldChooser *card); -static void e_table_field_chooser_class_init (ETableFieldChooserClass *klass); -static void e_table_field_chooser_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); -static void e_table_field_chooser_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_table_field_chooser_destroy (GtkObject *object); - -static GtkVBoxClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0, - ARG_FULL_HEADER, - ARG_DND_CODE, -}; - -GtkType -e_table_field_chooser_get_type (void) -{ - static GtkType table_field_chooser_type = 0; - - if (!table_field_chooser_type) - { - static const GtkTypeInfo table_field_chooser_info = - { - "ETableFieldChooser", - sizeof (ETableFieldChooser), - sizeof (ETableFieldChooserClass), - (GtkClassInitFunc) e_table_field_chooser_class_init, - (GtkObjectInitFunc) e_table_field_chooser_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - table_field_chooser_type = gtk_type_unique (gtk_vbox_get_type (), &table_field_chooser_info); - } - - return table_field_chooser_type; -} - -static void -e_table_field_chooser_class_init (ETableFieldChooserClass *klass) -{ - GtkObjectClass *object_class; - GtkVBoxClass *vbox_class; - - object_class = (GtkObjectClass*) klass; - vbox_class = (GtkVBoxClass *) klass; - - parent_class = gtk_type_class (gtk_vbox_get_type ()); - - object_class->set_arg = e_table_field_chooser_set_arg; - object_class->get_arg = e_table_field_chooser_get_arg; - object_class->destroy = e_table_field_chooser_destroy; - gtk_object_add_arg_type ("ETableFieldChooser::dnd_code", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_DND_CODE); - gtk_object_add_arg_type ("ETableFieldChooser::full_header", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_FULL_HEADER); -} - -static void allocate_callback(GtkWidget *canvas, GtkAllocation *allocation, ETableFieldChooser *etfc) -{ - double height; - etfc->last_alloc = *allocation; - gnome_canvas_item_set( etfc->item, - "width", (double) allocation->width, - NULL ); - gtk_object_get(GTK_OBJECT(etfc->item), - "height", &height, - NULL); - height = MAX(height, allocation->height); - gnome_canvas_set_scroll_region(GNOME_CANVAS( etfc->canvas ), 0, 0, allocation->width - 1, height - 1); - gnome_canvas_item_set( etfc->rect, - "x2", (double) allocation->width, - "y2", (double) height, - NULL ); -} - -static void resize(GnomeCanvas *canvas, ETableFieldChooser *etfc) -{ - double height; - gtk_object_get(GTK_OBJECT(etfc->item), - "height", &height, - NULL); - - height = MAX(height, etfc->last_alloc.height); - - gnome_canvas_set_scroll_region (GNOME_CANVAS(etfc->canvas), 0, 0, etfc->last_alloc.width - 1, height - 1); - gnome_canvas_item_set( etfc->rect, - "x2", (double) etfc->last_alloc.width, - "y2", (double) height, - NULL ); -} - -static void -e_table_field_chooser_init (ETableFieldChooser *etfc) -{ - GladeXML *gui; - GtkWidget *widget; - - gui = glade_xml_new (ETABLE_GLADEDIR "/e-table-field-chooser.glade", NULL); - etfc->gui = gui; - - widget = glade_xml_get_widget(gui, "vbox-top"); - if (!widget) { - return; - } - gtk_widget_reparent(widget, - GTK_WIDGET(etfc)); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - etfc->canvas = GNOME_CANVAS(glade_xml_get_widget(gui, "canvas-buttons")); - - etfc->rect = gnome_canvas_item_new(gnome_canvas_root( GNOME_CANVAS( etfc->canvas ) ), - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) 100, - "y2", (double) 100, - "fill_color", "white", - NULL ); - - etfc->item = gnome_canvas_item_new(gnome_canvas_root(etfc->canvas), - e_table_field_chooser_item_get_type(), - "width", (double) 100, - "full_header", etfc->full_header, - "dnd_code", etfc->dnd_code, - NULL ); - - gtk_signal_connect( GTK_OBJECT( etfc->canvas ), "reflow", - GTK_SIGNAL_FUNC( resize ), - etfc); - - gnome_canvas_set_scroll_region ( GNOME_CANVAS( etfc->canvas ), - 0, 0, - 100, 100 ); - - /* Connect the signals */ - gtk_signal_connect (GTK_OBJECT (etfc->canvas), "size_allocate", - GTK_SIGNAL_FUNC (allocate_callback), - etfc); - - gtk_widget_pop_visual (); - gtk_widget_pop_colormap (); - gtk_widget_show(widget); -} - -static void -e_table_field_chooser_destroy (GtkObject *object) -{ - ETableFieldChooser *etfc = E_TABLE_FIELD_CHOOSER(object); - - g_free(etfc->dnd_code); - if (etfc->full_header) - gtk_object_unref(GTK_OBJECT(etfc->full_header)); - - if (etfc->gui) - gtk_object_unref(GTK_OBJECT(etfc->gui)); -} - -GtkWidget* -e_table_field_chooser_new (void) -{ - GtkWidget *widget = GTK_WIDGET (gtk_type_new (e_table_field_chooser_get_type ())); - return widget; -} - -static void -e_table_field_chooser_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableFieldChooser *etfc = E_TABLE_FIELD_CHOOSER(object); - - switch (arg_id){ - case ARG_DND_CODE: - g_free(etfc->dnd_code); - etfc->dnd_code = g_strdup(GTK_VALUE_STRING (*arg)); - if (etfc->item) - gtk_object_set(GTK_OBJECT(etfc->item), - "dnd_code", etfc->dnd_code, - NULL); - break; - case ARG_FULL_HEADER: - if (etfc->full_header) - gtk_object_unref(GTK_OBJECT(etfc->full_header)); - if (GTK_VALUE_OBJECT(*arg)) - etfc->full_header = E_TABLE_HEADER(GTK_VALUE_OBJECT(*arg)); - else - etfc->full_header = NULL; - if (etfc->full_header) - gtk_object_ref(GTK_OBJECT(etfc->full_header)); - if (etfc->item) - gtk_object_set(GTK_OBJECT(etfc->item), - "full_header", etfc->full_header, - NULL); - break; - default: - break; - } -} - -static void -e_table_field_chooser_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableFieldChooser *etfc = E_TABLE_FIELD_CHOOSER(object); - - switch (arg_id) { - case ARG_DND_CODE: - GTK_VALUE_STRING (*arg) = g_strdup (etfc->dnd_code); - break; - case ARG_FULL_HEADER: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etfc->full_header); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} diff --git a/widgets/e-table/e-table-field-chooser.glade b/widgets/e-table/e-table-field-chooser.glade deleted file mode 100644 index a5cd37c2df..0000000000 --- a/widgets/e-table/e-table-field-chooser.glade +++ /dev/null @@ -1,131 +0,0 @@ -<?xml version="1.0"?> -<GTK-Interface> - -<project> - <name>e-table-field-chooser</name> - <program_name>e-table-field-chooser</program_name> - <directory></directory> - <source_directory>src</source_directory> - <pixmaps_directory>pixmaps</pixmaps_directory> - <language>C</language> - <gnome_support>True</gnome_support> - <gettext_support>True</gettext_support> - <use_widget_names>True</use_widget_names> - <output_main_file>False</output_main_file> - <output_support_files>False</output_support_files> - <output_build_files>False</output_build_files> - <gnome_help_support>True</gnome_help_support> - <output_translatable_strings>True</output_translatable_strings> - <translatable_strings_file>e-table-field-chooser.glade.h</translatable_strings_file> -</project> - -<widget> - <class>GnomeDialog</class> - <name>dialog-field-chooser</name> - <visible>False</visible> - <title>Field Chooser</title> - <type>GTK_WINDOW_TOPLEVEL</type> - <position>GTK_WIN_POS_NONE</position> - <modal>False</modal> - <allow_shrink>False</allow_shrink> - <allow_grow>True</allow_grow> - <auto_shrink>False</auto_shrink> - <auto_close>False</auto_close> - <hide_on_close>False</hide_on_close> - - <widget> - <class>GtkVBox</class> - <child_name>GnomeDialog:vbox</child_name> - <name>dialog-vbox1</name> - <homogeneous>False</homogeneous> - <spacing>8</spacing> - <child> - <padding>4</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkHButtonBox</class> - <child_name>GnomeDialog:action_area</child_name> - <name>dialog-action_area1</name> - <layout_style>GTK_BUTTONBOX_END</layout_style> - <spacing>8</spacing> - <child_min_width>85</child_min_width> - <child_min_height>27</child_min_height> - <child_ipad_x>7</child_ipad_x> - <child_ipad_y>0</child_ipad_y> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - <pack>GTK_PACK_END</pack> - </child> - - <widget> - <class>GtkButton</class> - <name>button3</name> - <can_default>True</can_default> - <can_focus>True</can_focus> - <stock_button>GNOME_STOCK_BUTTON_CLOSE</stock_button> - </widget> - </widget> - - <widget> - <class>GtkVBox</class> - <name>vbox-top</name> - <homogeneous>False</homogeneous> - <spacing>4</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkLabel</class> - <name>label1</name> - <label>To add a column to your table, drag it into -the location in which you want it to appear.</label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkScrolledWindow</class> - <name>scrolledwindow1</name> - <width>200</width> - <height>200</height> - <hscrollbar_policy>GTK_POLICY_AUTOMATIC</hscrollbar_policy> - <vscrollbar_policy>GTK_POLICY_AUTOMATIC</vscrollbar_policy> - <hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy> - <vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>Custom</class> - <name>canvas-buttons</name> - <creation_function>e_canvas_new</creation_function> - <int1>0</int1> - <int2>0</int2> - <last_modification_time>Thu, 08 Jun 2000 07:27:33 GMT</last_modification_time> - </widget> - </widget> - </widget> - </widget> -</widget> - -</GTK-Interface> diff --git a/widgets/e-table/e-table-field-chooser.glade.h b/widgets/e-table/e-table-field-chooser.glade.h deleted file mode 100644 index a36bd6052c..0000000000 --- a/widgets/e-table/e-table-field-chooser.glade.h +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Translatable strings file generated by Glade. - * Add this file to your project's POTFILES.in. - * DO NOT compile it as part of your application. - */ - -gchar *s = N_("Field Chooser"); -gchar *s = N_("To add a column to your table, drag it into\n" - "the location in which you want it to appear."); diff --git a/widgets/e-table/e-table-field-chooser.h b/widgets/e-table/e-table-field-chooser.h deleted file mode 100644 index d84aafdc63..0000000000 --- a/widgets/e-table/e-table-field-chooser.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-contact-editor-fullname.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef __E_TABLE_FIELD_CHOOSER_H__ -#define __E_TABLE_FIELD_CHOOSER_H__ - -#include <gnome.h> -#include <glade/glade.h> -#include "e-table-header.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ETableFieldChooser - A dialog displaying information about a contact. - * - * The following arguments are available: - * - * name type read/write description - * -------------------------------------------------------------------------------- - */ - -#define E_TABLE_FIELD_CHOOSER_TYPE (e_table_field_chooser_get_type ()) -#define E_TABLE_FIELD_CHOOSER(obj) (GTK_CHECK_CAST ((obj), E_TABLE_FIELD_CHOOSER_TYPE, ETableFieldChooser)) -#define E_TABLE_FIELD_CHOOSER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TABLE_FIELD_CHOOSER_TYPE, ETableFieldChooserClass)) -#define E_IS_TABLE_FIELD_CHOOSER(obj) (GTK_CHECK_TYPE ((obj), E_TABLE_FIELD_CHOOSER_TYPE)) -#define E_IS_TABLE_FIELD_CHOOSER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TABLE_FIELD_CHOOSER_TYPE)) - - -typedef struct _ETableFieldChooser ETableFieldChooser; -typedef struct _ETableFieldChooserClass ETableFieldChooserClass; - -struct _ETableFieldChooser -{ - GtkVBox parent; - - /* item specific fields */ - GladeXML *gui; - GnomeCanvas *canvas; - GnomeCanvasItem *item; - - GnomeCanvasItem *rect; - GtkAllocation last_alloc; - - gchar *dnd_code; - ETableHeader *full_header; -}; - -struct _ETableFieldChooserClass -{ - GtkVBoxClass parent_class; -}; - - -GtkWidget *e_table_field_chooser_new(void); -GtkType e_table_field_chooser_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TABLE_FIELD_CHOOSER_H__ */ diff --git a/widgets/e-table/e-table-group-container.c b/widgets/e-table/e-table-group-container.c deleted file mode 100644 index 3a68bc044b..0000000000 --- a/widgets/e-table/e-table-group-container.c +++ /dev/null @@ -1,1169 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-Table-Group.c: Implements the grouping objects for elements on a table - * - * Author: - * Chris Lahey <clahey@helixcode.com> - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, 2000 Helix Code, Inc. - */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-table-group-container.h" -#include "e-table-group-leaf.h" -#include "e-table-item.h" -#include <libgnomeui/gnome-canvas-rect-ellipse.h> -#include "e-util/e-util.h" -#include "e-util/e-canvas.h" -#include "e-util/e-canvas-utils.h" -#include "widgets/e-text/e-text.h" -#include "e-table-defines.h" - -#define TITLE_HEIGHT 16 - -#define PARENT_TYPE e_table_group_get_type () - -static GnomeCanvasGroupClass *etgc_parent_class; - -/* The arguments we take */ -enum { - ARG_0, - ARG_HEIGHT, - ARG_WIDTH, - ARG_MINIMUM_WIDTH, - ARG_FROZEN, - ARG_TABLE_DRAW_GRID, - ARG_TABLE_DRAW_FOCUS, - ARG_CURSOR_MODE, - ARG_TABLE_SELECTION_MODEL, - ARG_LENGTH_THRESHOLD, -}; - -typedef struct { - ETableGroup *child; - void *key; - char *string; - GnomeCanvasItem *text; - GnomeCanvasItem *rect; - gint count; -} ETableGroupContainerChildNode; - -static EPrintable * -etgc_get_printable (ETableGroup *etg); - - -static void -e_table_group_container_child_node_free (ETableGroupContainer *etgc, - ETableGroupContainerChildNode *child_node) -{ - ETableGroup *etg = E_TABLE_GROUP (etgc); - ETableGroup *child = child_node->child; - - gtk_object_destroy (GTK_OBJECT (child)); - e_table_model_free_value (etg->model, etgc->ecol->col_idx, - child_node->key); - g_free(child_node->string); - gtk_object_destroy (GTK_OBJECT (child_node->text)); - gtk_object_destroy (GTK_OBJECT (child_node->rect)); -} - -static void -e_table_group_container_list_free (ETableGroupContainer *etgc) -{ - ETableGroupContainerChildNode *child_node; - GList *list; - - for (list = etgc->children; list; list = g_list_next (list)) { - child_node = (ETableGroupContainerChildNode *) list->data; - e_table_group_container_child_node_free (etgc, child_node); - } - - g_list_free (etgc->children); -} - -static void -etgc_destroy (GtkObject *object) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (object); - - if (etgc->font) - gdk_font_unref (etgc->font); - etgc->font = NULL; - - if (etgc->ecol) - gtk_object_unref (GTK_OBJECT(etgc->ecol)); - - if (etgc->sort_info) - gtk_object_unref (GTK_OBJECT(etgc->sort_info)); - - if (etgc->table_selection_model) - gtk_object_unref (GTK_OBJECT(etgc->table_selection_model)); - - if (etgc->rect) - gtk_object_destroy (GTK_OBJECT(etgc->rect)); - - e_table_group_container_list_free (etgc); - - GTK_OBJECT_CLASS (etgc_parent_class)->destroy (object); -} - -void -e_table_group_container_construct (GnomeCanvasGroup *parent, ETableGroupContainer *etgc, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, ETableSortInfo *sort_info, int n) -{ - ETableCol *col; - ETableSortColumn column = e_table_sort_info_grouping_get_nth(sort_info, n); - - if (column.column > e_table_header_count (full_header)) - col = e_table_header_get_column (full_header, e_table_header_count (full_header) - 1); - else - col = e_table_header_get_column (full_header, column.column); - - e_table_group_construct (parent, E_TABLE_GROUP (etgc), full_header, header, model); - etgc->ecol = col; - gtk_object_ref (GTK_OBJECT(etgc->ecol)); - etgc->sort_info = sort_info; - gtk_object_ref (GTK_OBJECT(etgc->sort_info)); - etgc->n = n; - etgc->ascending = column.ascending; - - - etgc->font = gdk_font_load ("lucidasans-10"); - if (!etgc->font){ - etgc->font = GTK_WIDGET (GNOME_CANVAS_ITEM (etgc)->canvas)->style->font; - - gdk_font_ref (etgc->font); - } - etgc->open = TRUE; -} - -ETableGroup * -e_table_group_container_new (GnomeCanvasGroup *parent, ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, ETableSortInfo *sort_info, int n) -{ - ETableGroupContainer *etgc; - - g_return_val_if_fail (parent != NULL, NULL); - - etgc = gtk_type_new (e_table_group_container_get_type ()); - - e_table_group_container_construct (parent, etgc, full_header, header, - model, sort_info, n); - return E_TABLE_GROUP (etgc); -} - - -static int -etgc_event (GnomeCanvasItem *item, GdkEvent *event) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(item); - gboolean return_val = TRUE; - gboolean change_focus = FALSE; - gboolean use_col = FALSE; - gint start_col = 0; - gint old_col; - EFocus direction = E_FOCUS_START; - - switch (event->type) { - case GDK_KEY_PRESS: - if (event->key.keyval == GDK_Tab || - event->key.keyval == GDK_KP_Tab || - event->key.keyval == GDK_ISO_Left_Tab) { - change_focus = TRUE; - use_col = TRUE; - start_col = (event->key.state & GDK_SHIFT_MASK) ? -1 : 0; - direction = (event->key.state & GDK_SHIFT_MASK) ? E_FOCUS_END : E_FOCUS_START; - } else if (event->key.keyval == GDK_Left || - event->key.keyval == GDK_KP_Left) { - change_focus = TRUE; - use_col = TRUE; - start_col = -1; - direction = E_FOCUS_END; - } else if (event->key.keyval == GDK_Right || - event->key.keyval == GDK_KP_Right) { - change_focus = TRUE; - use_col = TRUE; - start_col = 0; - direction = E_FOCUS_START; - } else if (event->key.keyval == GDK_Down || - event->key.keyval == GDK_KP_Down) { - change_focus = TRUE; - use_col = FALSE; - direction = E_FOCUS_START; - } else if (event->key.keyval == GDK_Up || - event->key.keyval == GDK_KP_Up) { - change_focus = TRUE; - use_col = FALSE; - direction = E_FOCUS_END; - } else if (event->key.keyval == GDK_Return || - event->key.keyval == GDK_KP_Enter) { - change_focus = TRUE; - use_col = FALSE; - direction = E_FOCUS_START; - } - if (change_focus){ - GList *list; - for (list = etgc->children; list; list = list->next) { - ETableGroupContainerChildNode *child_node; - ETableGroup *child; - - child_node = (ETableGroupContainerChildNode *)list->data; - child = child_node->child; - - if (e_table_group_get_focus (child)) { - old_col = e_table_group_get_focus_column (child); - if (old_col == -1) - old_col = 0; - if (start_col == -1) - start_col = e_table_header_count (e_table_group_get_header (child)) - 1; - - if (direction == E_FOCUS_END) - list = list->prev; - else - list = list->next; - - if (list) { - child_node = (ETableGroupContainerChildNode *)list->data; - child = child_node->child; - if (use_col) - e_table_group_set_focus (child, direction, start_col); - else - e_table_group_set_focus (child, direction, old_col); - return 1; - } else { - return 0; - } - } - } - if (direction == E_FOCUS_END) - list = g_list_last(etgc->children); - else - list = etgc->children; - if (list) { - ETableGroupContainerChildNode *child_node; - ETableGroup *child; - - child_node = (ETableGroupContainerChildNode *)list->data; - child = child_node->child; - - if (start_col == -1) - start_col = e_table_header_count (e_table_group_get_header (child)) - 1; - - e_table_group_set_focus (child, direction, start_col); - return 1; - } - } - return_val = FALSE; - break; - default: - return_val = FALSE; - break; - } - if (return_val == FALSE) { - if (GNOME_CANVAS_ITEM_CLASS(etgc_parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS (etgc_parent_class)->event (item, event); - } - return return_val; - -} - -/* Realize handler for the text item */ -static void -etgc_realize (GnomeCanvasItem *item) -{ - ETableGroupContainer *etgc; - - if (GNOME_CANVAS_ITEM_CLASS (etgc_parent_class)->realize) - (* GNOME_CANVAS_ITEM_CLASS (etgc_parent_class)->realize) (item); - - etgc = E_TABLE_GROUP_CONTAINER (item); - - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etgc)); -} - -/* Unrealize handler for the etgc item */ -static void -etgc_unrealize (GnomeCanvasItem *item) -{ - ETableGroupContainer *etgc; - - etgc = E_TABLE_GROUP_CONTAINER (item); - - if (GNOME_CANVAS_ITEM_CLASS (etgc_parent_class)->unrealize) - (* GNOME_CANVAS_ITEM_CLASS (etgc_parent_class)->unrealize) (item); -} - -static void -compute_text (ETableGroupContainer *etgc, ETableGroupContainerChildNode *child_node) -{ - gchar *text; - if (etgc->ecol->text) - text = g_strdup_printf ("%s : %s (%d item%s)", - etgc->ecol->text, - child_node->string, - (gint) child_node->count, - child_node->count == 1 ? "" : "s"); - else - text = g_strdup_printf ("%s (%d item%s)", - child_node->string, - (gint) child_node->count, - child_node->count == 1 ? "" : "s"); - gnome_canvas_item_set (child_node->text, - "text", text, - NULL); - g_free (text); -} - -static void -child_cursor_change (ETableGroup *etg, int row, - ETableGroupContainer *etgc) -{ - e_table_group_cursor_change (E_TABLE_GROUP (etgc), row); -} - -static void -child_double_click (ETableGroup *etg, int row, - ETableGroupContainer *etgc) -{ - e_table_group_double_click (E_TABLE_GROUP (etgc), row); -} - -static gint -child_right_click (ETableGroup *etg, int row, int col, GdkEvent *event, - ETableGroupContainer *etgc) -{ - return e_table_group_right_click (E_TABLE_GROUP (etgc), row, col, event); -} - -static gint -child_key_press (ETableGroup *etg, int row, int col, GdkEvent *event, - ETableGroupContainer *etgc) -{ - return e_table_group_key_press (E_TABLE_GROUP (etgc), row, col, event); -} - -static void -etgc_add (ETableGroup *etg, gint row) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (etg); - void *val = e_table_model_value_at (etg->model, etgc->ecol->col_idx, row); - GCompareFunc comp = etgc->ecol->compare; - GList *list = etgc->children; - ETableGroup *child; - ETableGroupContainerChildNode *child_node; - int i = 0; - - for (; list; list = g_list_next (list), i++){ - int comp_val; - - child_node = list->data; - comp_val = (*comp)(child_node->key, val); - if (comp_val == 0) { - child = child_node->child; - child_node->count ++; - e_table_group_add (child, row); - compute_text (etgc, child_node); - return; - } - if ((comp_val > 0 && etgc->ascending) || - (comp_val < 0 && (!etgc->ascending))) - break; - } - child_node = g_new (ETableGroupContainerChildNode, 1); - child_node->rect = gnome_canvas_item_new (GNOME_CANVAS_GROUP (etgc), - gnome_canvas_rect_get_type (), - "fill_color", "grey70", - "outline_color", "grey50", - NULL); - child_node->text = gnome_canvas_item_new (GNOME_CANVAS_GROUP (etgc), - e_text_get_type (), - "font_gdk", etgc->font, - "anchor", GTK_ANCHOR_SW, - "fill_color", "black", - NULL); - child = e_table_group_new (GNOME_CANVAS_GROUP (etgc), etg->full_header, - etg->header, etg->model, etgc->sort_info, etgc->n + 1); - gnome_canvas_item_set(GNOME_CANVAS_ITEM(child), - "drawgrid", etgc->draw_grid, - "drawfocus", etgc->draw_focus, - "cursor_mode", etgc->cursor_mode, - "table_selection_model", etgc->table_selection_model, - "length_threshold", etgc->length_threshold, - NULL); - gtk_signal_connect (GTK_OBJECT (child), "cursor_change", - GTK_SIGNAL_FUNC (child_cursor_change), etgc); - gtk_signal_connect (GTK_OBJECT (child), "double_click", - GTK_SIGNAL_FUNC (child_double_click), etgc); - gtk_signal_connect (GTK_OBJECT (child), "right_click", - GTK_SIGNAL_FUNC (child_right_click), etgc); - gtk_signal_connect (GTK_OBJECT (child), "key_press", - GTK_SIGNAL_FUNC (child_key_press), etgc); - child_node->child = child; - child_node->key = e_table_model_duplicate_value (etg->model, etgc->ecol->col_idx, val); - child_node->string = e_table_model_value_to_string (etg->model, etgc->ecol->col_idx, val); - child_node->count = 1; - e_table_group_add (child, row); - - if (list) - etgc->children = g_list_insert (etgc->children, child_node, i); - else - etgc->children = g_list_append (etgc->children, child_node); - - compute_text (etgc, child_node); - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etgc)); -} - -static void -etgc_add_all (ETableGroup *etg) -{ - int rows = e_table_model_row_count(etg->model); - int i; - for (i = 0; i < rows; i++) - etgc_add(etg, i); -} - -static gboolean -etgc_remove (ETableGroup *etg, gint row) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - GList *list; - - for (list = etgc->children ; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = list->data; - ETableGroup *child = child_node->child; - - if (e_table_group_remove (child, row)) { - child_node->count --; - if (child_node->count == 0) { - e_table_group_container_child_node_free (etgc, child_node); - etgc->children = g_list_remove (etgc->children, child_node); - g_free (child_node); - } else - compute_text (etgc, child_node); - - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etgc)); - - return TRUE; - } - } - return FALSE; -} - -static int -etgc_row_count (ETableGroup *etg) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - GList *list; - gint count = 0; - for (list = etgc->children; list; list = g_list_next(list)) { - ETableGroup *group = ((ETableGroupContainerChildNode *)list->data)->child; - gint this_count = e_table_group_row_count(group); - count += this_count; - } - return count; -} - -static void -etgc_increment (ETableGroup *etg, gint position, gint amount) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - GList *list = etgc->children; - - for (list = etgc->children ; list; list = g_list_next (list)) - e_table_group_increment (((ETableGroupContainerChildNode *)list->data)->child, - position, amount); -} - -static void -etgc_decrement (ETableGroup *etg, gint position, gint amount) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - GList *list = etgc->children; - - for (list = etgc->children ; list; list = g_list_next (list)) - e_table_group_decrement (((ETableGroupContainerChildNode *)list->data)->child, - position, amount); -} - -static void -etgc_set_cursor_row (ETableGroup *etg, gint row) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - GList *list; - 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); - if (row < this_count) { - e_table_group_set_cursor_row(group, row); - return; - } - row -= this_count; - } -} - -static int -etgc_get_cursor_row (ETableGroup *etg) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - GList *list; - int count = 0; - for (list = etgc->children; list; list = g_list_next(list)) { - ETableGroup *group = ((ETableGroupContainerChildNode *)list->data)->child; - int row = e_table_group_get_cursor_row(group); - if (row != -1) - return count + row; - count += e_table_group_row_count(group); - } - return -1; -} - -static void -etgc_set_focus (ETableGroup *etg, EFocus direction, gint view_col) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - if (etgc->children) { - if (direction == E_FOCUS_END) - e_table_group_set_focus (((ETableGroupContainerChildNode *)g_list_last (etgc->children)->data)->child, - direction, view_col); - else - e_table_group_set_focus (((ETableGroupContainerChildNode *)etgc->children->data)->child, - direction, view_col); - } -} - -static gint -etgc_get_focus_column (ETableGroup *etg) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - if (etgc->children) { - GList *list; - for (list = etgc->children; list; list = list->next) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - ETableGroup *child = child_node->child; - if (e_table_group_get_focus (child)) { - return e_table_group_get_focus_column (child); - } - } - } - return 0; -} - -static void -etgc_compute_location (ETableGroup *etg, int *x, int *y, int *row, int *col) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - - if (row) - *row = -1; - if (col) - *col = -1; - - *x -= GROUP_INDENT; - *y -= TITLE_HEIGHT; - - if (*x >= 0 && *y >= 0 && etgc->children) { - GList *list; - for (list = etgc->children; list; list = list->next) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - ETableGroup *child = child_node->child; - - e_table_group_compute_location (child, x, y, row, col); - if ((*row != -1) && (*col != -1)) - return; - } - } -} - -static void etgc_thaw (ETableGroup *etg) -{ - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(etg)); -} - -static void -etgc_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (object); - GList *list; - - switch (arg_id) { - case ARG_FROZEN: - if (GTK_VALUE_BOOL (*arg)) - etg->frozen = TRUE; - else { - etg->frozen = FALSE; - etgc_thaw (etg); - } - break; - case ARG_MINIMUM_WIDTH: - case ARG_WIDTH: - etgc->minimum_width = GTK_VALUE_DOUBLE(*arg); - - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - gtk_object_set (GTK_OBJECT(child_node->child), - "minimum_width", etgc->minimum_width - GROUP_INDENT, - NULL); - } - break; - case ARG_LENGTH_THRESHOLD: - etgc->length_threshold = GTK_VALUE_INT (*arg); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - gtk_object_set (GTK_OBJECT(child_node->child), - "length_threshold", GTK_VALUE_INT (*arg), - NULL); - } - break; - - case ARG_TABLE_SELECTION_MODEL: - if (etgc->table_selection_model) - gtk_object_unref(GTK_OBJECT(etgc->table_selection_model)); - etgc->table_selection_model = E_TABLE_SELECTION_MODEL(GTK_VALUE_OBJECT (*arg)); - if (etgc->table_selection_model) - gtk_object_ref(GTK_OBJECT(etgc->table_selection_model)); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - gtk_object_set (GTK_OBJECT(child_node->child), - "table_selection_model", etgc->table_selection_model, - NULL); - } - break; - - case ARG_TABLE_DRAW_GRID: - etgc->draw_grid = GTK_VALUE_BOOL (*arg); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - gtk_object_set (GTK_OBJECT(child_node->child), - "drawgrid", GTK_VALUE_BOOL (*arg), - NULL); - } - break; - - case ARG_TABLE_DRAW_FOCUS: - etgc->draw_focus = GTK_VALUE_BOOL (*arg); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - gtk_object_set (GTK_OBJECT(child_node->child), - "drawfocus", GTK_VALUE_BOOL (*arg), - NULL); - } - break; - - case ARG_CURSOR_MODE: - etgc->cursor_mode = GTK_VALUE_INT (*arg); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - gtk_object_set (GTK_OBJECT(child_node->child), - "cursor_mode", GTK_VALUE_INT (*arg), - NULL); - } - break; - default: - break; - } -} - -static void -etgc_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (object); - - switch (arg_id) { - case ARG_FROZEN: - GTK_VALUE_BOOL (*arg) = etg->frozen; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = etgc->height; - break; - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = etgc->width; - break; - case ARG_MINIMUM_WIDTH: - etgc->minimum_width = GTK_VALUE_DOUBLE(*arg); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -etgc_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - ETableGroupClass *e_group_class = E_TABLE_GROUP_CLASS(object_class); - - object_class->destroy = etgc_destroy; - object_class->set_arg = etgc_set_arg; - object_class->get_arg = etgc_get_arg; - - item_class->event = etgc_event; - item_class->realize = etgc_realize; - item_class->unrealize = etgc_unrealize; - - etgc_parent_class = gtk_type_class (PARENT_TYPE); - - e_group_class->add = etgc_add; - e_group_class->add_all = etgc_add_all; - e_group_class->remove = etgc_remove; - e_group_class->increment = etgc_increment; - e_group_class->decrement = etgc_decrement; - e_group_class->row_count = etgc_row_count; - e_group_class->set_focus = etgc_set_focus; - e_group_class->set_cursor_row = etgc_set_cursor_row; - e_group_class->get_cursor_row = etgc_get_cursor_row; - e_group_class->get_focus_column = etgc_get_focus_column; - e_group_class->get_printable = etgc_get_printable; - e_group_class->compute_location = etgc_compute_location; - - gtk_object_add_arg_type ("ETableGroupContainer::drawgrid", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_GRID); - gtk_object_add_arg_type ("ETableGroupContainer::drawfocus", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_FOCUS); - gtk_object_add_arg_type ("ETableGroupContainer::cursor_mode", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_CURSOR_MODE); - gtk_object_add_arg_type ("ETableGroupContainer::table_selection_model", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_TABLE_SELECTION_MODEL); - gtk_object_add_arg_type ("ETableGroupContainer::length_threshold", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_LENGTH_THRESHOLD); - - gtk_object_add_arg_type ("ETableGroupContainer::frozen", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_FROZEN); - gtk_object_add_arg_type ("ETableGroupContainer::height", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_HEIGHT); - gtk_object_add_arg_type ("ETableGroupContainer::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ETableGroupContainer::minimum_width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_MINIMUM_WIDTH); -} - -static void -etgc_reflow (GnomeCanvasItem *item, gint flags) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(item); - gboolean frozen; - - gtk_object_get (GTK_OBJECT(etgc), - "frozen", &frozen, - NULL); - - if (frozen) - return; - - - if (GTK_OBJECT_FLAGS(etgc)& GNOME_CANVAS_ITEM_REALIZED){ - gdouble running_height = 0; - gdouble running_width = 0; - gdouble old_height; - gdouble old_width; - - old_height = etgc->height; - old_width = etgc->width; - if (etgc->children == NULL){ - } else { - GList *list; - gdouble extra_height = 0; - gdouble item_height = 0; - gdouble item_width = 0; - - if (etgc->font) - extra_height += etgc->font->ascent + etgc->font->descent + BUTTON_PADDING * 2; - - extra_height = MAX(extra_height, BUTTON_HEIGHT + BUTTON_PADDING * 2); - - running_height = extra_height; - - for ( list = etgc->children; list; list = g_list_next (list)){ - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data; - ETableGroup *child = child_node->child; - - gtk_object_get (GTK_OBJECT(child), - "width", &item_width, - NULL); - - if (item_width > running_width) - running_width = item_width; - } - for ( list = etgc->children; list; list = g_list_next (list)){ - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data; - ETableGroup *child = child_node->child; - gtk_object_get (GTK_OBJECT(child), - "height", &item_height, - NULL); - - e_canvas_item_move_absolute (GNOME_CANVAS_ITEM(child_node->text), - GROUP_INDENT, - running_height - BUTTON_PADDING); - - e_canvas_item_move_absolute (GNOME_CANVAS_ITEM(child), - GROUP_INDENT, - running_height); - - gnome_canvas_item_set (GNOME_CANVAS_ITEM(child_node->rect), - "x1", (double) 0, - "x2", (double) running_width + GROUP_INDENT, - "y1", (double) running_height - extra_height, - "y2", (double) running_height + item_height, - NULL); - - running_height += item_height + extra_height; - } - running_height -= extra_height; - } - if (running_height != old_height || running_width != old_width) { - etgc->height = running_height; - etgc->width = running_width; - e_canvas_item_request_parent_reflow (item); - } - } -} - -static void -etgc_init (GtkObject *object) -{ - ETableGroupContainer *container = E_TABLE_GROUP_CONTAINER(object); - container->children = FALSE; - - e_canvas_item_set_reflow_callback (GNOME_CANVAS_ITEM(object), etgc_reflow); - - container->draw_grid = 1; - container->draw_focus = 1; - container->cursor_mode = E_TABLE_CURSOR_SIMPLE; - container->length_threshold = -1; - container->table_selection_model = NULL; -} - -E_MAKE_TYPE (e_table_group_container, "ETableGroupContainer", ETableGroupContainer, etgc_class_init, etgc_init, PARENT_TYPE); - -void -e_table_group_apply_to_leafs (ETableGroup *etg, ETableGroupLeafFn fn, void *closure) -{ - if (E_IS_TABLE_GROUP_CONTAINER (etg)){ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (etg); - GList *list = etgc->children; - - for (list = etgc->children; list; list = list->next){ - ETableGroupContainerChildNode *child_node = list->data; - - e_table_group_apply_to_leafs (child_node->child, fn, closure); - } - } else if (E_IS_TABLE_GROUP_LEAF (etg)){ - (*fn) (E_TABLE_GROUP_LEAF (etg)->item, closure); - } else { - g_error ("Unknown ETableGroup found: %s", - gtk_type_name (GTK_OBJECT (etg)->klass->type)); - } -} - - -typedef struct { - ETableGroupContainer *etgc; - GList *child; - EPrintable *child_printable; -} ETGCPrintContext; - -#if 0 -#define CHECK(x) if((x) == -1) return -1; - -static gint -gp_draw_rect (GnomePrintContext *context, gdouble x, gdouble y, gdouble width, gdouble height, gdouble r, gdouble g, gdouble b) -{ - CHECK(gnome_print_moveto(context, x, y)); - CHECK(gnome_print_lineto(context, x + width, y)); - CHECK(gnome_print_lineto(context, x + width, y - height)); - CHECK(gnome_print_lineto(context, x, y - height)); - CHECK(gnome_print_lineto(context, x, y)); - return gnome_print_fill(context); -} -#endif - -static void -e_table_group_container_print_page (EPrintable *ep, - GnomePrintContext *context, - gdouble width, - gdouble height, - gboolean quantize, - ETGCPrintContext *groupcontext) -{ - gdouble yd = height; - gdouble child_height; - ETableGroupContainerChildNode *child_node; - GList *child; - EPrintable *child_printable; - - child_printable = groupcontext->child_printable; - child = groupcontext->child; - - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - else { - if (!child) { - return; - } else { - child_node = child->data; - child_printable = e_table_group_get_printable(child_node->child); - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - e_printable_reset(child_printable); - } - } - - while (1) { - child_height = e_printable_height(child_printable, context, width - 36, yd, quantize); - - if (gnome_print_gsave(context) == -1) - /* FIXME */; - if (gnome_print_translate(context, 36, yd - child_height) == -1) - /* FIXME */; - - if (gnome_print_moveto(context, 0, 0) == -1) - /* FIXME */; - if (gnome_print_lineto(context, width - 36, 0) == -1) - /* FIXME */; - if (gnome_print_lineto(context, width - 36, child_height) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 0, child_height) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 0, 0) == -1) - /* FIXME */; - if (gnome_print_clip(context) == -1) - /* FIXME */; - - e_printable_print_page(child_printable, context, width - 36, child_height, quantize); - - if (gnome_print_grestore(context) == -1) - /* FIXME */; - - yd -= child_height; - - if (e_printable_data_left(child_printable)) - break; - - child = child->next; - if (!child) { - child_printable = NULL; - break; - } - - child_node = child->data; - if (child_printable) - gtk_object_unref(GTK_OBJECT(child_printable)); - child_printable = e_table_group_get_printable(child_node->child); - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - e_printable_reset(child_printable); - } - - if (groupcontext->child_printable) - gtk_object_unref(GTK_OBJECT(groupcontext->child_printable)); - groupcontext->child_printable = child_printable; - groupcontext->child = child; - -} - -static gboolean -e_table_group_container_data_left (EPrintable *ep, - ETGCPrintContext *groupcontext) -{ - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "data_left"); - return groupcontext->child != NULL; -} - -static void -e_table_group_container_reset (EPrintable *ep, - ETGCPrintContext *groupcontext) -{ - groupcontext->child = groupcontext->etgc->children; - if (groupcontext->child_printable) - gtk_object_unref(GTK_OBJECT(groupcontext->child_printable)); - groupcontext->child_printable = NULL; -} - -static gdouble -e_table_group_container_height (EPrintable *ep, - GnomePrintContext *context, - gdouble width, - gdouble max_height, - gboolean quantize, - ETGCPrintContext *groupcontext) -{ - gdouble height = 0; - gdouble child_height; - gdouble yd = max_height; - ETableGroupContainerChildNode *child_node; - GList *child; - EPrintable *child_printable; - - child_printable = groupcontext->child_printable; - child = groupcontext->child; - - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - else { - if (!child) { - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "height"); - return 0; - } else { - child_node = child->data; - child_printable = e_table_group_get_printable(child_node->child); - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - e_printable_reset(child_printable); - } - } - - while (1) { - child_height = e_printable_height(child_printable, context, width - 36, yd, quantize); - - height += child_height; - - if (yd != -1) { - if (!e_printable_will_fit(child_printable, context, width - 36, yd, quantize)) { - break; - } - - yd -= child_height; - } - - child = child->next; - if (!child) { - break; - } - - child_node = child->data; - if (child_printable) - gtk_object_unref(GTK_OBJECT(child_printable)); - child_printable = e_table_group_get_printable(child_node->child); - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - e_printable_reset(child_printable); - } - if (child_printable) - gtk_object_unref(GTK_OBJECT(child_printable)); - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "height"); - return height; -} - -static gboolean -e_table_group_container_will_fit (EPrintable *ep, - GnomePrintContext *context, - gdouble width, - gdouble max_height, - gboolean quantize, - ETGCPrintContext *groupcontext) -{ - gboolean will_fit = TRUE; - gdouble child_height; - gdouble yd = max_height; - ETableGroupContainerChildNode *child_node; - GList *child; - EPrintable *child_printable; - - child_printable = groupcontext->child_printable; - child = groupcontext->child; - - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - else { - if (!child) { - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "will_fit"); - return will_fit; - } else { - child_node = child->data; - child_printable = e_table_group_get_printable(child_node->child); - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - e_printable_reset(child_printable); - } - } - - while (1) { - child_height = e_printable_height(child_printable, context, width - 36, yd, quantize); - - if (yd != -1) { - if (!e_printable_will_fit(child_printable, context, width - 36, yd, quantize)) { - will_fit = FALSE; - break; - } - - yd -= child_height; - } - - child = child->next; - if (!child) { - break; - } - - child_node = child->data; - if (child_printable) - gtk_object_unref(GTK_OBJECT(child_printable)); - child_printable = e_table_group_get_printable(child_node->child); - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - e_printable_reset(child_printable); - } - - if (child_printable) - gtk_object_unref(GTK_OBJECT(child_printable)); - - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "will_fit"); - return will_fit; -} - -static void -e_table_group_container_printable_destroy (GtkObject *object, - ETGCPrintContext *groupcontext) -{ - gtk_object_unref(GTK_OBJECT(groupcontext->etgc)); - if (groupcontext->child_printable) - gtk_object_ref(GTK_OBJECT(groupcontext->child_printable)); - g_free(groupcontext); -} - -static EPrintable * -etgc_get_printable (ETableGroup *etg) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - EPrintable *printable = e_printable_new(); - ETGCPrintContext *groupcontext; - - groupcontext = g_new(ETGCPrintContext, 1); - groupcontext->etgc = etgc; - gtk_object_ref(GTK_OBJECT(etgc)); - groupcontext->child = etgc->children; - groupcontext->child_printable = NULL; - - gtk_signal_connect (GTK_OBJECT(printable), - "print_page", - GTK_SIGNAL_FUNC(e_table_group_container_print_page), - groupcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "data_left", - GTK_SIGNAL_FUNC(e_table_group_container_data_left), - groupcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "reset", - GTK_SIGNAL_FUNC(e_table_group_container_reset), - groupcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "height", - GTK_SIGNAL_FUNC(e_table_group_container_height), - groupcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "will_fit", - GTK_SIGNAL_FUNC(e_table_group_container_will_fit), - groupcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "destroy", - GTK_SIGNAL_FUNC(e_table_group_container_printable_destroy), - groupcontext); - - return printable; -} diff --git a/widgets/e-table/e-table-group-container.h b/widgets/e-table/e-table-group-container.h deleted file mode 100644 index bdb717b92d..0000000000 --- a/widgets/e-table/e-table-group-container.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_GROUP_CONTAINER_H_ -#define _E_TABLE_GROUP_CONTAINER_H_ - -#include <libgnomeui/gnome-canvas.h> -#include "e-table-model.h" -#include "e-table-header.h" -#include "e-table-group.h" -#include "e-table-item.h" - -#define E_TABLE_GROUP_CONTAINER_TYPE (e_table_group_container_get_type ()) -#define E_TABLE_GROUP_CONTAINER(o) (GTK_CHECK_CAST ((o), E_TABLE_GROUP_CONTAINER_TYPE, ETableGroupContainer)) -#define E_TABLE_GROUP_CONTAINER_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_GROUP_CONTAINER_TYPE, ETableGroupContainerClass)) -#define E_IS_TABLE_GROUP_CONTAINER(o) (GTK_CHECK_TYPE ((o), E_TABLE_GROUP_CONTAINER_TYPE)) -#define E_IS_TABLE_GROUP_CONTAINER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_GROUP_CONTAINER_TYPE)) - -typedef struct { - ETableGroup group; - - /* - * The ETableCol used to group this set - */ - ETableCol *ecol; - gint ascending; - - /* - * List of ETableGroups we stack - */ - GList *children; - - /* - * The canvas rectangle that contains the children - */ - GnomeCanvasItem *rect; - - GdkFont *font; - - gdouble width, height, minimum_width; - - ETableSortInfo *sort_info; - int n; - int length_threshold; - - ETableSelectionModel *table_selection_model; - - guint draw_grid : 1; - guint draw_focus : 1; - ETableCursorMode cursor_mode; - - /* - * State: the ETableGroup is open or closed - */ - guint open:1; -} ETableGroupContainer; - -typedef struct { - ETableGroupClass parent_class; -} ETableGroupContainerClass; - -ETableGroup *e_table_group_container_new (GnomeCanvasGroup *parent, ETableHeader *full_header, ETableHeader *header, - ETableModel *model, ETableSortInfo *sort_info, int n); -void e_table_group_container_construct (GnomeCanvasGroup *parent, ETableGroupContainer *etgc, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, ETableSortInfo *sort_info, int n); - -GtkType e_table_group_container_get_type (void); - -#endif /* _E_TABLE_GROUP_CONTAINER_H_ */ diff --git a/widgets/e-table/e-table-group-leaf.c b/widgets/e-table/e-table-group-leaf.c deleted file mode 100644 index c4792eb87e..0000000000 --- a/widgets/e-table/e-table-group-leaf.c +++ /dev/null @@ -1,425 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-Table-Group.c: Implements the grouping objects for elements on a table - * - * Author: - * Miguel de Icaza (miguel@gnu.org () - * - * Copyright 1999, Helix Code, Inc. - */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-table-group-leaf.h" -#include "e-table-item.h" -#include <libgnomeui/gnome-canvas-rect-ellipse.h> -#include "e-util/e-util.h" -#include "e-util/e-canvas.h" - -#define PARENT_TYPE e_table_group_get_type () - -static GnomeCanvasGroupClass *etgl_parent_class; - -/* The arguments we take */ -enum { - ARG_0, - ARG_HEIGHT, - ARG_WIDTH, - ARG_MINIMUM_WIDTH, - ARG_FROZEN, - ARG_TABLE_DRAW_GRID, - ARG_TABLE_DRAW_FOCUS, - ARG_CURSOR_MODE, - ARG_LENGTH_THRESHOLD, - ARG_TABLE_SELECTION_MODEL, -}; - -static void etgl_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void etgl_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); - -static void -etgl_destroy (GtkObject *object) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF(object); - if (etgl->subset) - gtk_object_unref (GTK_OBJECT(etgl->subset)); - if (etgl->item) - gtk_object_destroy (GTK_OBJECT(etgl->item)); - if (etgl->table_selection_model) - gtk_object_unref (GTK_OBJECT(etgl->table_selection_model)); - if (GTK_OBJECT_CLASS (etgl_parent_class)->destroy) - GTK_OBJECT_CLASS (etgl_parent_class)->destroy (object); -} - -static void -e_table_group_leaf_construct (GnomeCanvasGroup *parent, - ETableGroupLeaf *etgl, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info) -{ - etgl->subset = E_TABLE_SUBSET_VARIABLE(e_table_sorted_variable_new (model, full_header, sort_info)); - gtk_object_ref(GTK_OBJECT(etgl->subset)); - gtk_object_sink(GTK_OBJECT(etgl->subset)); - e_table_group_construct (parent, E_TABLE_GROUP (etgl), full_header, header, model); -} - -ETableGroup * -e_table_group_leaf_new (GnomeCanvasGroup *parent, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info) -{ - ETableGroupLeaf *etgl; - - g_return_val_if_fail (parent != NULL, NULL); - - etgl = gtk_type_new (e_table_group_leaf_get_type ()); - - e_table_group_leaf_construct (parent, etgl, full_header, - header, model, sort_info); - return E_TABLE_GROUP (etgl); -} - -static void -etgl_cursor_change (GtkObject *object, gint row, ETableGroupLeaf *etgl) -{ - if (row < E_TABLE_SUBSET(etgl->subset)->n_map) - e_table_group_cursor_change (E_TABLE_GROUP(etgl), E_TABLE_SUBSET(etgl->subset)->map_table[row]); -} - -static void -etgl_double_click (GtkObject *object, gint row, ETableGroupLeaf *etgl) -{ - if (row < E_TABLE_SUBSET(etgl->subset)->n_map) - e_table_group_double_click (E_TABLE_GROUP(etgl), E_TABLE_SUBSET(etgl->subset)->map_table[row]); -} - -static gint -etgl_key_press (GtkObject *object, gint row, gint col, GdkEvent *event, ETableGroupLeaf *etgl) -{ - if (row < E_TABLE_SUBSET(etgl->subset)->n_map) - return e_table_group_key_press (E_TABLE_GROUP(etgl), E_TABLE_SUBSET(etgl->subset)->map_table[row], col, event); - else - return 0; -} - -static gint -etgl_right_click (GtkObject *object, gint row, gint col, GdkEvent *event, ETableGroupLeaf *etgl) -{ - if (row < E_TABLE_SUBSET(etgl->subset)->n_map) - return e_table_group_right_click (E_TABLE_GROUP(etgl), E_TABLE_SUBSET(etgl->subset)->map_table[row], col, event); - else - return 0; -} - -static void -etgl_reflow (GnomeCanvasItem *item, gint flags) -{ - ETableGroupLeaf *leaf = E_TABLE_GROUP_LEAF(item); - gtk_object_get(GTK_OBJECT(leaf->item), - "height", &leaf->height, - NULL); - gtk_object_get(GTK_OBJECT(leaf->item), - "width", &leaf->width, - NULL); - e_canvas_item_request_parent_reflow (item); -} - -static void -etgl_realize (GnomeCanvasItem *item) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF(item); - - if (GNOME_CANVAS_ITEM_CLASS (etgl_parent_class)->realize) - GNOME_CANVAS_ITEM_CLASS (etgl_parent_class)->realize (item); - - etgl->item = E_TABLE_ITEM(gnome_canvas_item_new (GNOME_CANVAS_GROUP(etgl), - e_table_item_get_type (), - "ETableHeader", E_TABLE_GROUP(etgl)->header, - "ETableModel", etgl->subset, - "drawgrid", etgl->draw_grid, - "drawfocus", etgl->draw_focus, - "cursor_mode", etgl->cursor_mode, - "minimum_width", etgl->minimum_width, - "length_threshold", etgl->length_threshold, - "table_selection_model", etgl->table_selection_model, - NULL)); - - gtk_signal_connect (GTK_OBJECT(etgl->item), "cursor_change", - GTK_SIGNAL_FUNC(etgl_cursor_change), etgl); - gtk_signal_connect (GTK_OBJECT(etgl->item), "double_click", - GTK_SIGNAL_FUNC(etgl_double_click), etgl); - gtk_signal_connect (GTK_OBJECT(etgl->item), "right_click", - GTK_SIGNAL_FUNC(etgl_right_click), etgl); - gtk_signal_connect (GTK_OBJECT(etgl->item), "key_press", - GTK_SIGNAL_FUNC(etgl_key_press), etgl); - e_canvas_item_request_reflow(item); -} - -static void -etgl_add (ETableGroup *etg, gint row) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - e_table_subset_variable_add (etgl->subset, row); -} - -static void -etgl_add_all (ETableGroup *etg) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - e_table_subset_variable_add_all (etgl->subset); -} - -static gboolean -etgl_remove (ETableGroup *etg, gint row) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - return e_table_subset_variable_remove (etgl->subset, row); -} - -static void -etgl_increment (ETableGroup *etg, gint position, gint amount) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - e_table_subset_variable_increment (etgl->subset, position, amount); -} - -static void -etgl_decrement (ETableGroup *etg, gint position, gint amount) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - e_table_subset_variable_decrement (etgl->subset, position, amount); -} - -static int -etgl_row_count (ETableGroup *etg) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - return e_table_model_row_count(E_TABLE_MODEL(etgl->subset)); -} - -static void -etgl_set_focus (ETableGroup *etg, EFocus direction, gint view_col) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - if (direction == E_FOCUS_END) { - e_table_item_set_cursor (etgl->item, view_col, e_table_model_row_count(E_TABLE_MODEL(etgl->subset)) - 1); - } else { - e_table_item_set_cursor (etgl->item, view_col, 0); - } -} - -static void -etgl_set_cursor_row (ETableGroup *etg, gint row) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - gnome_canvas_item_set(GNOME_CANVAS_ITEM(etgl->item), - "cursor_row", row, - NULL); -} - -static int -etgl_get_cursor_row (ETableGroup *etg) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - int row; - gtk_object_get(GTK_OBJECT(etgl->item), - "cursor_row", &row, - NULL); - return row; -} - -static gint -etgl_get_focus_column (ETableGroup *etg) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - return e_table_item_get_focused_column (etgl->item); -} - -static EPrintable * -etgl_get_printable (ETableGroup *etg) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - return e_table_item_get_printable (etgl->item); -} - -static void -etgl_compute_location (ETableGroup *etg, int *x, int *y, int *row, int *col) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - e_table_item_compute_location (etgl->item, x, y, row, col); -} - -static void -etgl_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (object); - - switch (arg_id) { - case ARG_FROZEN: - if (GTK_VALUE_BOOL (*arg)) - etg->frozen = TRUE; - else { - etg->frozen = FALSE; - } - break; - case ARG_MINIMUM_WIDTH: - case ARG_WIDTH: - etgl->minimum_width = GTK_VALUE_DOUBLE(*arg); - if (etgl->item) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etgl->item), - "minimum_width", etgl->minimum_width, - NULL); - } - break; - case ARG_LENGTH_THRESHOLD: - etgl->length_threshold = GTK_VALUE_INT (*arg); - if (etgl->item) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etgl->item), - "length_threshold", GTK_VALUE_INT (*arg), - NULL); - } - break; - case ARG_TABLE_SELECTION_MODEL: - if (etgl->table_selection_model) - gtk_object_unref(GTK_OBJECT(etgl->table_selection_model)); - etgl->table_selection_model = E_TABLE_SELECTION_MODEL(GTK_VALUE_OBJECT (*arg)); - if (etgl->table_selection_model) - gtk_object_ref(GTK_OBJECT(etgl->table_selection_model)); - if (etgl->item) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etgl->item), - "table_selection_model", etgl->table_selection_model, - NULL); - } - - case ARG_TABLE_DRAW_GRID: - etgl->draw_grid = GTK_VALUE_BOOL (*arg); - if (etgl->item) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etgl->item), - "drawgrid", GTK_VALUE_BOOL (*arg), - NULL); - } - break; - - case ARG_TABLE_DRAW_FOCUS: - etgl->draw_focus = GTK_VALUE_BOOL (*arg); - if (etgl->item) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etgl->item), - "drawfocus", GTK_VALUE_BOOL (*arg), - NULL); - } - break; - - case ARG_CURSOR_MODE: - etgl->cursor_mode = GTK_VALUE_INT (*arg); - if (etgl->item) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etgl->item), - "cursor_mode", GTK_VALUE_INT (*arg), - NULL); - } - break; - default: - break; - } -} - -static void -etgl_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (object); - - switch (arg_id) { - case ARG_FROZEN: - GTK_VALUE_BOOL (*arg) = etg->frozen; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = etgl->height; - break; - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = etgl->width; - break; - case ARG_MINIMUM_WIDTH: - GTK_VALUE_DOUBLE (*arg) = etgl->minimum_width; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -etgl_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - ETableGroupClass *e_group_class = E_TABLE_GROUP_CLASS(object_class); - - object_class->destroy = etgl_destroy; - object_class->set_arg = etgl_set_arg; - object_class->get_arg = etgl_get_arg; - - item_class->realize = etgl_realize; - - etgl_parent_class = gtk_type_class (PARENT_TYPE); - - e_group_class->add = etgl_add; - e_group_class->add_all = etgl_add_all; - e_group_class->remove = etgl_remove; - e_group_class->increment = etgl_increment; - e_group_class->decrement = etgl_decrement; - e_group_class->row_count = etgl_row_count; - e_group_class->set_focus = etgl_set_focus; - e_group_class->set_cursor_row = etgl_set_cursor_row; - e_group_class->get_cursor_row = etgl_get_cursor_row; - e_group_class->get_focus_column = etgl_get_focus_column; - e_group_class->get_printable = etgl_get_printable; - e_group_class->compute_location = etgl_compute_location; - - gtk_object_add_arg_type ("ETableGroupLeaf::drawgrid", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_GRID); - gtk_object_add_arg_type ("ETableGroupLeaf::drawfocus", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_FOCUS); - gtk_object_add_arg_type ("ETableGroupLeaf::cursor_mode", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_CURSOR_MODE); - gtk_object_add_arg_type ("ETableGroupLeaf::length_threshold", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_LENGTH_THRESHOLD); - gtk_object_add_arg_type ("ETableGroupLeaf::table_selection_model", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_TABLE_SELECTION_MODEL); - - gtk_object_add_arg_type ("ETableGroupLeaf::height", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_HEIGHT); - gtk_object_add_arg_type ("ETableGroupLeaf::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ETableGroupLeaf::minimum_width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_MINIMUM_WIDTH); - gtk_object_add_arg_type ("ETableGroupLeaf::frozen", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_FROZEN); -} - -static void -etgl_init (GtkObject *object) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (object); - - etgl->width = 1; - etgl->height = 1; - etgl->minimum_width = 0; - - etgl->subset = NULL; - etgl->item = NULL; - - etgl->draw_grid = 1; - etgl->draw_focus = 1; - etgl->cursor_mode = E_TABLE_CURSOR_SIMPLE; - etgl->length_threshold = -1; - - etgl->table_selection_model = NULL; - - e_canvas_item_set_reflow_callback (GNOME_CANVAS_ITEM(object), etgl_reflow); -} - -E_MAKE_TYPE (e_table_group_leaf, "ETableGroupLeaf", ETableGroupLeaf, etgl_class_init, etgl_init, PARENT_TYPE); diff --git a/widgets/e-table/e-table-group-leaf.h b/widgets/e-table/e-table-group-leaf.h deleted file mode 100644 index 1cc041206b..0000000000 --- a/widgets/e-table/e-table-group-leaf.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_GROUP_LEAF_H_ -#define _E_TABLE_GROUP_LEAF_H_ - -#include <libgnomeui/gnome-canvas.h> -#include "e-table-group.h" -#include "e-table-sorted-variable.h" -#include "e-table-item.h" - -#define E_TABLE_GROUP_LEAF_TYPE (e_table_group_leaf_get_type ()) -#define E_TABLE_GROUP_LEAF(o) (GTK_CHECK_CAST ((o), E_TABLE_GROUP_LEAF_TYPE, ETableGroupLeaf)) -#define E_TABLE_GROUP_LEAF_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_GROUP_LEAF_TYPE, ETableGroupLeafClass)) -#define E_IS_TABLE_GROUP_LEAF(o) (GTK_CHECK_TYPE ((o), E_TABLE_GROUP_LEAF_TYPE)) -#define E_IS_TABLE_GROUP_LEAF_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_GROUP_LEAF_TYPE)) - -typedef struct { - ETableGroup group; - - /* - * Item. - */ - ETableItem *item; - - gdouble height; - gdouble width; - gdouble minimum_width; - - ETableSubsetVariable *subset; - - int length_threshold; - - guint draw_grid : 1; - guint draw_focus : 1; - ETableCursorMode cursor_mode; - - ETableSelectionModel *table_selection_model; -} ETableGroupLeaf; - -typedef struct { - ETableGroupClass parent_class; -} ETableGroupLeafClass; - -ETableGroup *e_table_group_leaf_new (GnomeCanvasGroup *parent, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info); -GtkType e_table_group_leaf_get_type (void); - - -#endif /* _E_TABLE_GROUP_LEAF_H_ */ - diff --git a/widgets/e-table/e-table-group.c b/widgets/e-table/e-table-group.c deleted file mode 100644 index fbd9026096..0000000000 --- a/widgets/e-table/e-table-group.c +++ /dev/null @@ -1,420 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-Table-Group.c: Implements the grouping objects for elements on a table - * - * Author: - * Miguel de Icaza (miguel@helixcode.com) - * Chris Lahey (clahey@helixcode.com) - * - * Copyright 1999, 2000 Helix Code, Inc. - */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-table-group.h" -#include "e-table-group-container.h" -#include "e-table-group-leaf.h" -#include "e-table-item.h" -#include <libgnomeui/gnome-canvas-rect-ellipse.h> -#include "e-util/e-util.h" - -#define PARENT_TYPE gnome_canvas_group_get_type () - -#define ETG_CLASS(e) (E_TABLE_GROUP_CLASS(GTK_OBJECT(e)->klass)) - -static GnomeCanvasGroupClass *etg_parent_class; - -enum { - CURSOR_CHANGE, - DOUBLE_CLICK, - RIGHT_CLICK, - KEY_PRESS, - LAST_SIGNAL -}; - -static gint etg_signals [LAST_SIGNAL] = { 0, }; - -static gboolean etg_get_focus (ETableGroup *etg); -static void etg_destroy (GtkObject *object); - -static void -etg_destroy (GtkObject *object) -{ - ETableGroup *etg = E_TABLE_GROUP(object); - if (etg->header) - gtk_object_unref (GTK_OBJECT(etg->header)); - if (etg->full_header) - gtk_object_unref (GTK_OBJECT(etg->full_header)); - if (etg->model) - gtk_object_unref (GTK_OBJECT(etg->model)); - if (GTK_OBJECT_CLASS (etg_parent_class)->destroy) - GTK_OBJECT_CLASS (etg_parent_class)->destroy (object); -} - -ETableGroup * -e_table_group_new (GnomeCanvasGroup *parent, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info, - int n) -{ - g_return_val_if_fail (model != NULL, NULL); - - if (n < e_table_sort_info_grouping_get_count(sort_info)) { - return e_table_group_container_new (parent, full_header, header, model, sort_info, n); - } else { - return e_table_group_leaf_new (parent, full_header, header, model, sort_info); - } - return NULL; -} - -void -e_table_group_construct (GnomeCanvasGroup *parent, - ETableGroup *etg, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model) -{ - etg->full_header = full_header; - gtk_object_ref (GTK_OBJECT(etg->full_header)); - etg->header = header; - gtk_object_ref (GTK_OBJECT(etg->header)); - etg->model = model; - gtk_object_ref (GTK_OBJECT(etg->model)); - gnome_canvas_item_constructv (GNOME_CANVAS_ITEM (etg), parent, 0, NULL); -} - -void -e_table_group_add (ETableGroup *etg, - gint row) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->add) - ETG_CLASS (etg)->add (etg, row); -} - -void -e_table_group_add_all (ETableGroup *etg) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->add_all) - ETG_CLASS (etg)->add_all (etg); -} - -gboolean -e_table_group_remove (ETableGroup *etg, - gint row) -{ - g_return_val_if_fail (etg != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), FALSE); - - if (ETG_CLASS (etg)->remove) - return ETG_CLASS (etg)->remove (etg, row); - else - return FALSE; -} - -gint -e_table_group_get_count (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), 0); - - if (ETG_CLASS (etg)->get_count) - return ETG_CLASS (etg)->get_count (etg); - else - return 0; -} - -gint -e_table_group_row_count (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), 0); - - if (ETG_CLASS (etg)->row_count) - return ETG_CLASS (etg)->row_count (etg); - else - return 0; -} - -void -e_table_group_increment (ETableGroup *etg, - gint position, - gint amount) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->increment) - ETG_CLASS (etg)->increment (etg, position, amount); -} - -void -e_table_group_decrement (ETableGroup *etg, - gint position, - gint amount) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->decrement) - ETG_CLASS (etg)->decrement (etg, position, amount); -} - -void -e_table_group_set_focus (ETableGroup *etg, - EFocus direction, - gint row) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->set_focus) - ETG_CLASS (etg)->set_focus (etg, direction, row); -} - -void -e_table_group_set_cursor_row (ETableGroup *etg, - gint row) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->set_cursor_row) - ETG_CLASS (etg)->set_cursor_row (etg, row); -} - -int -e_table_group_get_cursor_row (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, -1); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), -1); - - if (ETG_CLASS (etg)->get_cursor_row) - return ETG_CLASS (etg)->get_cursor_row (etg); - else - return -1; -} - -gboolean -e_table_group_get_focus (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), FALSE); - - if (ETG_CLASS (etg)->get_focus) - return ETG_CLASS (etg)->get_focus (etg); - else - return FALSE; -} - -gboolean -e_table_group_get_focus_column (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), FALSE); - - if (ETG_CLASS (etg)->get_focus_column) - return ETG_CLASS (etg)->get_focus_column (etg); - else - return FALSE; -} - -ETableCol * -e_table_group_get_ecol (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), NULL); - - if (ETG_CLASS (etg)->get_ecol) - return ETG_CLASS (etg)->get_ecol (etg); - else - return NULL; -} - -EPrintable * -e_table_group_get_printable (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), NULL); - - if (ETG_CLASS (etg)->get_printable) - return ETG_CLASS (etg)->get_printable (etg); - else - return NULL; -} - -void -e_table_group_compute_location (ETableGroup *etg, int *x, int *y, int *row, int *col) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->compute_location) - ETG_CLASS (etg)->compute_location (etg, x, y, row, col); -} - -void -e_table_group_cursor_change (ETableGroup *e_table_group, gint row) -{ - g_return_if_fail (e_table_group != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (e_table_group)); - - gtk_signal_emit (GTK_OBJECT (e_table_group), - etg_signals [CURSOR_CHANGE], - row); -} - -void -e_table_group_double_click (ETableGroup *e_table_group, gint row) -{ - g_return_if_fail (e_table_group != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (e_table_group)); - - gtk_signal_emit (GTK_OBJECT (e_table_group), - etg_signals [DOUBLE_CLICK], - row); -} - -gint -e_table_group_right_click (ETableGroup *e_table_group, gint row, gint col, GdkEvent *event) -{ - gint return_val = 0; - - g_return_val_if_fail (e_table_group != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_GROUP (e_table_group), 0); - - gtk_signal_emit (GTK_OBJECT (e_table_group), - etg_signals [RIGHT_CLICK], - row, col, event, &return_val); - - return return_val; -} - -gint -e_table_group_key_press (ETableGroup *e_table_group, gint row, gint col, GdkEvent *event) -{ - gint return_val = 0; - - g_return_val_if_fail (e_table_group != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_GROUP (e_table_group), 0); - - gtk_signal_emit (GTK_OBJECT (e_table_group), - etg_signals [KEY_PRESS], - row, col, event, &return_val); - - return return_val; -} - -ETableHeader * -e_table_group_get_header (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), NULL); - - return etg->header; -} - -static int -etg_event (GnomeCanvasItem *item, GdkEvent *event) -{ - ETableGroup *etg = E_TABLE_GROUP (item); - gboolean return_val = TRUE; - - switch (event->type) { - - case GDK_FOCUS_CHANGE: - etg->has_focus = event->focus_change.in; - return_val = FALSE; - - default: - return_val = FALSE; - } - if (return_val == FALSE){ - if (GNOME_CANVAS_ITEM_CLASS(etg_parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS(etg_parent_class)->event (item, event); - } - return return_val; - -} - -static gboolean -etg_get_focus (ETableGroup *etg) -{ - return etg->has_focus; -} - -static void -etg_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - ETableGroupClass *klass = (ETableGroupClass *) object_class; - - object_class->destroy = etg_destroy; - - item_class->event = etg_event; - - klass->cursor_change = NULL; - klass->double_click = NULL; - klass->right_click = NULL; - klass->key_press = NULL; - - klass->add = NULL; - klass->add_all = NULL; - klass->remove = NULL; - klass->get_count = NULL; - klass->row_count = NULL; - klass->increment = NULL; - klass->decrement = NULL; - klass->set_focus = NULL; - klass->set_cursor_row = NULL; - klass->get_cursor_row = NULL; - klass->get_focus = etg_get_focus; - klass->get_ecol = NULL; - klass->get_printable = NULL; - klass->compute_location = NULL; - - etg_parent_class = gtk_type_class (PARENT_TYPE); - - etg_signals [CURSOR_CHANGE] = - gtk_signal_new ("cursor_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableGroupClass, cursor_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - etg_signals [DOUBLE_CLICK] = - gtk_signal_new ("double_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableGroupClass, double_click), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - etg_signals [RIGHT_CLICK] = - gtk_signal_new ("right_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableGroupClass, right_click), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - etg_signals [KEY_PRESS] = - gtk_signal_new ("key_press", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableGroupClass, key_press), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - gtk_object_class_add_signals (object_class, etg_signals, LAST_SIGNAL); -} - -E_MAKE_TYPE (e_table_group, "ETableGroup", ETableGroup, etg_class_init, NULL, PARENT_TYPE); diff --git a/widgets/e-table/e-table-group.glade b/widgets/e-table/e-table-group.glade deleted file mode 100644 index 39274d3c61..0000000000 --- a/widgets/e-table/e-table-group.glade +++ /dev/null @@ -1,208 +0,0 @@ -<?xml version="1.0"?> -<GTK-Interface> - -<project> - <directory></directory> - <source_directory>src</source_directory> - <pixmaps_directory>pixmaps</pixmaps_directory> - <language>C</language> - <gnome_support>True</gnome_support> - <gettext_support>True</gettext_support> - <use_widget_names>False</use_widget_names> - <output_main_file>False</output_main_file> - <output_support_files>False</output_support_files> - <output_build_files>False</output_build_files> - <backup_source_files>False</backup_source_files> - <main_source_file>interface.c</main_source_file> - <main_header_file>interface.h</main_header_file> - <handler_source_file>callbacks.c</handler_source_file> - <handler_header_file>callbacks.h</handler_header_file> - <support_source_file>support.c</support_source_file> - <support_header_file>support.h</support_header_file> - <output_translatable_strings>True</output_translatable_strings> - <translatable_strings_file>e-table-group.glade.h</translatable_strings_file> -</project> - -<widget> - <class>GtkWindow</class> - <name>window1</name> - <title>window1</title> - <type>GTK_WINDOW_TOPLEVEL</type> - <position>GTK_WIN_POS_NONE</position> - <modal>False</modal> - <allow_shrink>False</allow_shrink> - <allow_grow>True</allow_grow> - <auto_shrink>False</auto_shrink> - - <widget> - <class>GtkTable</class> - <name>table1</name> - <rows>3</rows> - <columns>3</columns> - <homogeneous>False</homogeneous> - <row_spacing>0</row_spacing> - <column_spacing>0</column_spacing> - - <widget> - <class>GtkFrame</class> - <name>frame1</name> - <border_width>4</border_width> - <label>Available fields</label> - <label_xalign>0</label_xalign> - <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type> - <child> - <left_attach>0</left_attach> - <right_attach>1</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>True</xexpand> - <yexpand>True</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - - <widget> - <class>GtkScrolledWindow</class> - <name>scrolledwindow1</name> - <hscrollbar_policy>GTK_POLICY_ALWAYS</hscrollbar_policy> - <vscrollbar_policy>GTK_POLICY_ALWAYS</vscrollbar_policy> - <hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy> - <vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy> - - <widget> - <class>GtkCList</class> - <name>clist1</name> - <can_focus>True</can_focus> - <columns>1</columns> - <column_widths>80</column_widths> - <selection_mode>GTK_SELECTION_SINGLE</selection_mode> - <show_titles>False</show_titles> - <shadow_type>GTK_SHADOW_NONE</shadow_type> - - <widget> - <class>GtkLabel</class> - <child_name>CList:title</child_name> - <name>label1</name> - <label>label1</label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - </widget> - </widget> - </widget> - </widget> - - <widget> - <class>GtkFrame</class> - <name>frame2</name> - <border_width>4</border_width> - <label>Show in this order</label> - <label_xalign>0</label_xalign> - <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type> - <child> - <left_attach>2</left_attach> - <right_attach>3</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>True</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - - <widget> - <class>GtkScrolledWindow</class> - <name>scrolledwindow2</name> - <hscrollbar_policy>GTK_POLICY_ALWAYS</hscrollbar_policy> - <vscrollbar_policy>GTK_POLICY_ALWAYS</vscrollbar_policy> - <hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy> - <vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy> - - <widget> - <class>GtkCList</class> - <name>clist2</name> - <can_focus>True</can_focus> - <columns>1</columns> - <column_widths>80</column_widths> - <selection_mode>GTK_SELECTION_SINGLE</selection_mode> - <show_titles>False</show_titles> - <shadow_type>GTK_SHADOW_NONE</shadow_type> - - <widget> - <class>GtkLabel</class> - <child_name>CList:title</child_name> - <name>label2</name> - <label>label2</label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - </widget> - </widget> - </widget> - </widget> - - <widget> - <class>GtkVBox</class> - <name>vbox1</name> - <border_width>4</border_width> - <homogeneous>False</homogeneous> - <spacing>0</spacing> - <child> - <left_attach>1</left_attach> - <right_attach>2</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>4</xpad> - <ypad>4</ypad> - <xexpand>True</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>False</xfill> - <yfill>True</yfill> - </child> - - <widget> - <class>GtkButton</class> - <name>button1</name> - <border_width>4</border_width> - <can_focus>True</can_focus> - <label>Add >></label> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkButton</class> - <name>button2</name> - <border_width>4</border_width> - <can_focus>True</can_focus> - <label><< Remove</label> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - </widget> -</widget> - -</GTK-Interface> diff --git a/widgets/e-table/e-table-group.glade.h b/widgets/e-table/e-table-group.glade.h deleted file mode 100644 index 3ab6304734..0000000000 --- a/widgets/e-table/e-table-group.glade.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Translatable strings file generated by Glade. - * Add this file to your project's POTFILES.in. - * DO NOT compile it as part of your application. - */ - -gchar *s = N_("window1"); -gchar *s = N_("Available fields"); -gchar *s = N_("label1"); -gchar *s = N_("Show in this order"); -gchar *s = N_("label2"); -gchar *s = N_("Add >>"); -gchar *s = N_("<< Remove"); diff --git a/widgets/e-table/e-table-group.h b/widgets/e-table/e-table-group.h deleted file mode 100644 index a3afe7f5e1..0000000000 --- a/widgets/e-table/e-table-group.h +++ /dev/null @@ -1,135 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_GROUP_H_ -#define _E_TABLE_GROUP_H_ - -#include <libgnomeui/gnome-canvas.h> -#include "e-table-model.h" -#include "e-table-header.h" -#include "e-table-sort-info.h" -#include "e-table-defines.h" -#include "e-util/e-util.h" -#include "e-util/e-printable.h" - -#define E_TABLE_GROUP_TYPE (e_table_group_get_type ()) -#define E_TABLE_GROUP(o) (GTK_CHECK_CAST ((o), E_TABLE_GROUP_TYPE, ETableGroup)) -#define E_TABLE_GROUP_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_GROUP_TYPE, ETableGroupClass)) -#define E_IS_TABLE_GROUP(o) (GTK_CHECK_TYPE ((o), E_TABLE_GROUP_TYPE)) -#define E_IS_TABLE_GROUP_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_GROUP_TYPE)) - -typedef struct { - GnomeCanvasGroup group; - - /* - * The full header. - */ - ETableHeader *full_header; - ETableHeader *header; - - /* - * The model we pull data from. - */ - ETableModel *model; - - /* - * Whether we should add indentation and open/close markers, - * or if we just act as containers of subtables. - */ - guint transparent : 1; - - guint has_focus : 1; - - guint frozen : 1; -} ETableGroup; - -typedef struct { - GnomeCanvasGroupClass parent_class; - - /* Signals */ - void (*cursor_change) (ETableGroup *etg, int row); - void (*double_click) (ETableGroup *etg, int row); - gint (*right_click) (ETableGroup *etg, int row, int col, GdkEvent *event); - gint (*key_press) (ETableGroup *etg, int row, int col, GdkEvent *event); - - /* Virtual functions. */ - void (*add) (ETableGroup *etg, gint row); - void (*add_all) (ETableGroup *etg); - gboolean (*remove) (ETableGroup *etg, gint row); - gint (*get_count) (ETableGroup *etg); - 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); - void (*set_cursor_row) (ETableGroup *etg, gint row); - int (*get_cursor_row) (ETableGroup *etg); - gboolean (*get_focus) (ETableGroup *etg); - gint (*get_focus_column) (ETableGroup *etg); - ETableCol *(*get_ecol) (ETableGroup *etg); - EPrintable *(*get_printable) (ETableGroup *etg); - void (*compute_location) (ETableGroup *etg, int *x, int *y, int *row, int *col); - -} ETableGroupClass; - -/* Virtual functions */ -void e_table_group_add (ETableGroup *etg, - gint row); -void e_table_group_add_all (ETableGroup *etg); -gboolean e_table_group_remove (ETableGroup *etg, - gint row); -gint e_table_group_get_count (ETableGroup *etg); -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); -void e_table_group_set_cursor_row (ETableGroup *etg, - gint row); -int e_table_group_get_cursor_row (ETableGroup *etg); -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); -ETableCol *e_table_group_get_ecol (ETableGroup *etg); -EPrintable *e_table_group_get_printable (ETableGroup *etg); -void e_table_group_compute_location (ETableGroup *etg, - int *x, - int *y, - int *row, - int *col); - -ETableGroup *e_table_group_new (GnomeCanvasGroup *parent, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info, - int n); -void e_table_group_construct (GnomeCanvasGroup *parent, - ETableGroup *etg, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model); - -/* For emitting the signals */ -void e_table_group_cursor_change (ETableGroup *etg, - gint row); -void e_table_group_double_click (ETableGroup *etg, - gint row); -gint e_table_group_right_click (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event); -gint e_table_group_key_press (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event); - -GtkType e_table_group_get_type (void); - -typedef void (*ETableGroupLeafFn) (void *e_table_item, void *closure); -void e_table_group_apply_to_leafs (ETableGroup *etg, - ETableGroupLeafFn fn, void *closure); - -#endif /* _E_TABLE_GROUP_H_ */ diff --git a/widgets/e-table/e-table-header-item.c b/widgets/e-table/e-table-header-item.c deleted file mode 100644 index 506ad546ca..0000000000 --- a/widgets/e-table/e-table-header-item.c +++ /dev/null @@ -1,1449 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-column-view.c: A canvas item based view of the ETableColumn. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, 2000 Helix Code, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkdnd.h> -#include <libgnomeui/gnome-canvas.h> -#include <libgnomeui/gnome-canvas-util.h> -#include <libgnomeui/gnome-canvas-polygon.h> -#include <libgnomeui/gnome-canvas-rect-ellipse.h> -#include <gdk-pixbuf/gdk-pixbuf.h> -#include "e-util/e-cursors.h" -#include "e-util/e-xml-utils.h" -#include "e-util/e-popup-menu.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-col-dnd.h" -#include "e-table-defines.h" -#include "e-table-field-chooser-dialog.h" - -#include "add-col.xpm" -#include "remove-col.xpm" -#include "arrow-up.xpm" -#include "arrow-down.xpm" - -enum { - BUTTON_PRESSED, - LAST_SIGNAL -}; - -static guint ethi_signals [LAST_SIGNAL] = { 0, }; - -#define ARROW_DOWN_HEIGHT 16 -#define ARROW_PTR 7 - -/* Defines the tolerance for proximity of the column division to the cursor position */ -#define TOLERANCE 4 - -#define ETHI_RESIZING(x) ((x)->resize_col != -1) - -#define PARENT_OBJECT_TYPE gnome_canvas_item_get_type () - -#define ELEMENTS(x) (sizeof (x) / sizeof (x[0])) - -static GnomeCanvasItemClass *ethi_parent_class; - -static void ethi_drop_table_header (ETableHeaderItem *ethi); - -/* - * They display the arrows for the drop location. - */ - -static GtkWidget *arrow_up, *arrow_down; - -/* - * DnD icons - */ -static GdkColormap *dnd_colormap; -static GdkPixmap *remove_col_pixmap, *remove_col_mask; -static GdkPixmap *add_col_pixmap, *add_col_mask; - -enum { - ARG_0, - ARG_TABLE_HEADER, - ARG_FULL_HEADER, - ARG_DND_CODE, - ARG_TABLE_FONTSET, - ARG_SORT_INFO -}; - -static void -ethi_destroy (GtkObject *object){ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (object); - - ethi_drop_table_header (ethi); - - if (ethi->sort_info){ - if (ethi->sort_info_changed_id) - gtk_signal_disconnect (GTK_OBJECT(ethi->sort_info), ethi->sort_info_changed_id); - if (ethi->group_info_changed_id) - gtk_signal_disconnect (GTK_OBJECT(ethi->sort_info), ethi->group_info_changed_id); - gtk_object_unref (GTK_OBJECT(ethi->sort_info)); - } - - if (GTK_OBJECT_CLASS (ethi_parent_class)->destroy) - (*GTK_OBJECT_CLASS (ethi_parent_class)->destroy) (object); -} - -static void -ethi_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - - double i2c [6]; - ArtPoint c1, c2, i1, i2; - - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->update) - (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->update)(item, affine, clip_path, flags); - - - if (ethi->sort_info) - ethi->group_indent_width = e_table_sort_info_grouping_get_count(ethi->sort_info) * GROUP_INDENT; - else - ethi->group_indent_width = 0; - - ethi->width = e_table_header_total_width (ethi->eth) + ethi->group_indent_width; - - i1.x = i1.y = 0; - i2.x = ethi->width; - i2.y = ethi->height; - - gnome_canvas_item_i2c_affine (item, i2c); - art_affine_point (&c1, &i1, i2c); - art_affine_point (&c2, &i2, i2c); - - if (item->x1 != c1.x || - item->y1 != c1.y || - item->x2 != c2.x || - item->y2 != c2.y) - { - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); - item->x1 = c1.x; - item->y1 = c1.y; - item->x2 = c2.x; - item->y2 = c2.y; - - gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item); - } - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); -} - -static void -ethi_font_load (ETableHeaderItem *ethi, char *font) -{ - if (ethi->font) - gdk_font_unref (ethi->font); - - ethi->font = gdk_fontset_load (font); - if (ethi->font == NULL) - ethi->font = gdk_font_load ("-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-iso8859-1"); - - ethi->height = ethi->font->ascent + ethi->font->descent + HEADER_PADDING; - if (ethi->height < MIN_ARROW_SIZE + 4 + HEADER_PADDING) - ethi->height = MIN_ARROW_SIZE + 4 + HEADER_PADDING; -} - -static void -ethi_drop_table_header (ETableHeaderItem *ethi) -{ - GtkObject *header; - - if (!ethi->eth) - return; - - header = GTK_OBJECT (ethi->eth); - gtk_signal_disconnect (header, ethi->structure_change_id); - gtk_signal_disconnect (header, ethi->dimension_change_id); - - gtk_object_unref (header); - ethi->eth = NULL; - ethi->width = 0; -} - -static void -structure_changed (ETableHeader *header, ETableHeaderItem *ethi) -{ - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(ethi)); -} - -static void -dimension_changed (ETableHeader *header, int col, ETableHeaderItem *ethi) -{ - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(ethi)); -} - -static void -ethi_add_table_header (ETableHeaderItem *ethi, ETableHeader *header) -{ - ethi->eth = header; - gtk_object_ref (GTK_OBJECT (ethi->eth)); - - ethi->structure_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "structure_change", - GTK_SIGNAL_FUNC(structure_changed), ethi); - ethi->dimension_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "dimension_change", - GTK_SIGNAL_FUNC(dimension_changed), ethi); - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(ethi)); -} - -static void -ethi_sort_info_changed (ETableSortInfo *sort_info, ETableHeaderItem *ethi) -{ - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(ethi)); -} - -static void -ethi_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableHeaderItem *ethi; - - item = GNOME_CANVAS_ITEM (o); - ethi = E_TABLE_HEADER_ITEM (o); - - switch (arg_id){ - case ARG_TABLE_HEADER: - ethi_drop_table_header (ethi); - ethi_add_table_header (ethi, E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg))); - break; - - case ARG_FULL_HEADER: - if (ethi->full_header) - gtk_object_unref(GTK_OBJECT(ethi->full_header)); - ethi->full_header = E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg)); - if (ethi->full_header) - gtk_object_ref(GTK_OBJECT(ethi->full_header)); - break; - - case ARG_DND_CODE: - g_free(ethi->dnd_code); - ethi->dnd_code = g_strdup (GTK_VALUE_STRING (*arg)); - break; - - case ARG_TABLE_FONTSET: - ethi_font_load (ethi, GTK_VALUE_STRING (*arg)); - break; - - case ARG_SORT_INFO: - if (ethi->sort_info){ - if (ethi->sort_info_changed_id) - gtk_signal_disconnect ( - GTK_OBJECT(ethi->sort_info), - ethi->sort_info_changed_id); - - if (ethi->group_info_changed_id) - gtk_signal_disconnect ( - GTK_OBJECT(ethi->sort_info), - ethi->group_info_changed_id); - gtk_object_unref (GTK_OBJECT(ethi->sort_info)); - } - ethi->sort_info = GTK_VALUE_POINTER (*arg); - gtk_object_ref (GTK_OBJECT(ethi->sort_info)); - ethi->sort_info_changed_id = - gtk_signal_connect ( - GTK_OBJECT(ethi->sort_info), "sort_info_changed", - GTK_SIGNAL_FUNC(ethi_sort_info_changed), ethi); - ethi->group_info_changed_id = - gtk_signal_connect ( - GTK_OBJECT(ethi->sort_info), "group_info_changed", - GTK_SIGNAL_FUNC(ethi_sort_info_changed), ethi); - break; - - } - gnome_canvas_item_request_update(item); -} - -static void -ethi_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableHeaderItem *ethi; - - ethi = E_TABLE_HEADER_ITEM (o); - - switch (arg_id){ - case ARG_FULL_HEADER: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT (ethi->full_header); - break; - case ARG_DND_CODE: - GTK_VALUE_STRING (*arg) = g_strdup (ethi->dnd_code); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static int -ethi_find_col_by_x (ETableHeaderItem *ethi, int x) -{ - const int cols = e_table_header_count (ethi->eth); - int x1 = 0; - int col; - - if (x < x1) - return -1; - - x1 += ethi->group_indent_width; - - for (col = 0; col < cols; col++){ - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - - if ((x >= x1) && (x <= x1 + ecol->width)) - return col; - - x1 += ecol->width; - } - return -1; -} - -static int -ethi_find_col_by_x_nearest (ETableHeaderItem *ethi, int x) -{ - const int cols = e_table_header_count (ethi->eth); - int x1 = 0; - int col; - - if (x < x1) - return -1; - - x1 += ethi->group_indent_width; - - for (col = 0; col < cols; col++){ - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - - x1 += (ecol->width / 2); - - if (x <= x1) - return col; - - x1 += (ecol->width + 1) / 2; - } - return col; -} - -static void -ethi_remove_drop_marker (ETableHeaderItem *ethi) -{ - if (ethi->drag_mark == -1) - return; - - gtk_widget_hide (arrow_up); - gtk_widget_hide (arrow_down); - - ethi->drag_mark = -1; -} - -static GtkWidget * -make_shapped_window_from_xpm (const char **xpm) -{ - GdkPixbuf *pixbuf; - GdkPixmap *pixmap; - GdkBitmap *bitmap; - GtkWidget *win, *pix; - - pixbuf = gdk_pixbuf_new_from_xpm_data (xpm); - gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &bitmap, 128); - gdk_pixbuf_unref (pixbuf); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - win = gtk_window_new (GTK_WINDOW_POPUP); - pix = gtk_pixmap_new (pixmap, bitmap); - gtk_widget_realize (win); - gtk_container_add (GTK_CONTAINER (win), pix); - gtk_widget_shape_combine_mask (win, bitmap, 0, 0); - gtk_widget_pop_visual (); - gtk_widget_pop_colormap (); - - gdk_pixmap_unref (pixmap); - gdk_bitmap_unref (bitmap); - - return win; -} - -static void -ethi_add_drop_marker (ETableHeaderItem *ethi, int col) -{ - int rx, ry; - int x; - - if (ethi->drag_mark == col) - return; - - ethi->drag_mark = col; - - x = e_table_header_col_diff (ethi->eth, 0, col); - if (col > 0) - x += ethi->group_indent_width; - - if (!arrow_up){ - arrow_up = make_shapped_window_from_xpm (arrow_up_xpm); - arrow_down = make_shapped_window_from_xpm (arrow_down_xpm); - } - - gdk_window_get_origin ( - GTK_WIDGET (GNOME_CANVAS_ITEM (ethi)->canvas)->window, - &rx, &ry); - - gtk_widget_set_uposition (arrow_down, rx + x - ARROW_PTR, ry - ARROW_DOWN_HEIGHT); - gtk_widget_show_all (arrow_down); - - gtk_widget_set_uposition (arrow_up, rx + x - ARROW_PTR, ry + ethi->height); - gtk_widget_show_all (arrow_up); -} - -#define gray50_width 2 -#define gray50_height 2 -static char gray50_bits [] = { - 0x02, 0x01, }; - -static void -ethi_add_destroy_marker (ETableHeaderItem *ethi) -{ - double x1; - - if (ethi->remove_item) - gtk_object_destroy (GTK_OBJECT (ethi->remove_item)); - - if (!ethi->stipple) - ethi->stipple = gdk_bitmap_create_from_data ( - NULL, gray50_bits, gray50_width, gray50_height); - - x1 = (double) e_table_header_col_diff (ethi->eth, 0, ethi->drag_col); - if (ethi->drag_col > 0) - x1 += ethi->group_indent_width; - - ethi->remove_item = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (GNOME_CANVAS_ITEM (ethi)->canvas->root), - gnome_canvas_rect_get_type (), - "x1", x1 + 1, - "y1", (double) 1, - "x2", (double) x1 + e_table_header_col_diff ( - ethi->eth, ethi->drag_col, ethi->drag_col+1) - 2, - - "y2", (double) ethi->height - 2, - "fill_color", "red", - "fill_stipple", ethi->stipple, - NULL); -} - -static void -ethi_remove_destroy_marker (ETableHeaderItem *ethi) -{ - if (!ethi->remove_item) - return; - - gtk_object_destroy (GTK_OBJECT (ethi->remove_item)); - ethi->remove_item = NULL; -} - -#if 0 -static gboolean -moved (ETableHeaderItem *ethi, guint col, guint model_col) -{ - if (col == -1) - return TRUE; - ecol = e_table_header_get_column (ethi->eth, col); - if (ecol->col_idx == model_col) - return FALSE; - if (col > 0) { - ecol = e_table_header_get_column (ethi->eth, col - 1); - if (ecol->col_idx == model_col) - return FALSE; - } - return TRUE; -} -#endif - -static gboolean -ethi_drag_motion (GtkObject *canvas, GdkDragContext *context, - gint x, gint y, guint time, - ETableHeaderItem *ethi) -{ - gdk_drag_status (context, 0, time); - if ((x >= 0) && (x <= (ethi->width)) && - (y >= 0) && (y <= (ethi->height))){ - int col; - - col = ethi_find_col_by_x_nearest (ethi, x); - - if (col == ethi->drag_col || col == ethi->drag_col + 1) { - if (ethi->drag_col != -1) - ethi_remove_destroy_marker (ethi); - - ethi_remove_drop_marker (ethi); - gdk_drag_status (context, context->suggested_action, time); - } - else if (col != -1){ - if (ethi->drag_col != -1) - ethi_remove_destroy_marker (ethi); - - ethi_add_drop_marker (ethi, col); - gdk_drag_status (context, context->suggested_action, time); - } else { - ethi_remove_drop_marker (ethi); - if (ethi->drag_col != -1) - ethi_add_destroy_marker (ethi); - } - } else { - ethi_remove_drop_marker (ethi); - if (ethi->drag_col != -1) - ethi_add_destroy_marker (ethi); - } - - return TRUE; -} - -static void -ethi_drag_end (GtkWidget *canvas, GdkDragContext *context, ETableHeaderItem *ethi) -{ - if (context->action == 0) { - e_table_header_remove (ethi->eth, ethi->drag_col); - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(ethi)); - } - ethi_remove_drop_marker (ethi); - ethi_remove_destroy_marker (ethi); - ethi->drag_col = -1; -} - -static void -ethi_drag_data_received (GtkWidget *canvas, - GdkDragContext *drag_context, - gint x, - gint y, - GtkSelectionData *data, - guint info, - guint time, - ETableHeaderItem *ethi) -{ - int found = FALSE; - int count = e_table_header_count(ethi->eth); - int column = atoi(data->data); - int drop_col = ethi->drop_col; - int i; - ethi->drop_col = -1; - if (column < 0) - return; - for (i = 0; i < count; i++) { - ETableCol *ecol = e_table_header_get_column (ethi->eth, i); - if (ecol->col_idx == column) { - e_table_header_move(ethi->eth, i, drop_col); - found = TRUE; - break; - } - } - if (!found) { - count = e_table_header_count(ethi->full_header); - for (i = 0; i < count; i++) { - ETableCol *ecol = e_table_header_get_column (ethi->full_header, i); - if (ecol->col_idx == column) { - e_table_header_add_column (ethi->eth, ecol, drop_col); - break; - } - } - } - ethi_remove_drop_marker (ethi); - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(ethi)); -} - -static void -ethi_drag_data_get (GtkWidget *canvas, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - ETableHeaderItem *ethi) -{ - if (ethi->drag_col != -1) { - ETableCol *ecol = e_table_header_get_column (ethi->eth, ethi->drag_col); - - gchar *string = g_strdup_printf("%d", ecol->col_idx); - gtk_selection_data_set(selection_data, - GDK_SELECTION_TYPE_STRING, - sizeof(string[0]), - string, - strlen(string)); - g_free(string); - } -} - -static gboolean -ethi_drag_drop (GtkWidget *canvas, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETableHeaderItem *ethi) -{ - gboolean successful = FALSE; - - if ((x >= 0) && (x <= (ethi->width)) && - (y >= 0) && (y <= (ethi->height))){ - int col; - - col = ethi_find_col_by_x_nearest (ethi, x); - - ethi_add_drop_marker (ethi, col); - - ethi->drop_col = col; - - if (col != -1) { - char *target = g_strdup_printf ("%s-%s", TARGET_ETABLE_COL_TYPE, ethi->dnd_code); - gtk_drag_get_data (canvas, context, gdk_atom_intern(target, FALSE), time); - g_free (target); - } - } - gtk_drag_finish (context, successful, successful, time); - return successful; -} - -static void -ethi_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time, ETableHeaderItem *ethi) -{ - ethi_remove_drop_marker (ethi); - if (ethi->drag_col != -1) - ethi_add_destroy_marker (ethi); -} - -static void -ethi_realize (GnomeCanvasItem *item) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - GdkWindow *window; - GdkColor c; - GtkTargetEntry ethi_drop_types [] = { - { TARGET_ETABLE_COL_TYPE, 0, TARGET_ETABLE_COL_HEADER }, - }; - - - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)-> realize) - (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->realize)(item); - - window = GTK_WIDGET (item->canvas)->window; - - ethi->gc = gdk_gc_new (window); - gnome_canvas_get_color (item->canvas, "black", &c); - gdk_gc_set_foreground (ethi->gc, &c); - - if (!ethi->font) - ethi_font_load (ethi, "-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-iso8859-1"); - - /* - * Now, configure DnD - */ - ethi_drop_types[0].target = g_strdup_printf("%s-%s", ethi_drop_types[0].target, ethi->dnd_code); - gtk_drag_dest_set (GTK_WIDGET (item->canvas), 0, - ethi_drop_types, ELEMENTS (ethi_drop_types), - GDK_ACTION_MOVE); - g_free(ethi_drop_types[0].target); - - /* Drop signals */ - ethi->drag_motion_id = gtk_signal_connect (GTK_OBJECT (item->canvas), "drag_motion", - GTK_SIGNAL_FUNC (ethi_drag_motion), ethi); - ethi->drag_leave_id = gtk_signal_connect (GTK_OBJECT (item->canvas), "drag_leave", - GTK_SIGNAL_FUNC (ethi_drag_leave), ethi); - ethi->drag_drop_id = gtk_signal_connect (GTK_OBJECT (item->canvas), "drag_drop", - GTK_SIGNAL_FUNC (ethi_drag_drop), ethi); - ethi->drag_data_received_id = gtk_signal_connect (GTK_OBJECT (item->canvas), "drag_data_received", - GTK_SIGNAL_FUNC (ethi_drag_data_received), ethi); - - /* Drag signals */ - ethi->drag_end_id = gtk_signal_connect (GTK_OBJECT (item->canvas), "drag_end", - GTK_SIGNAL_FUNC (ethi_drag_end), ethi); - ethi->drag_data_get_id = gtk_signal_connect (GTK_OBJECT (item->canvas), "drag_data_get", - GTK_SIGNAL_FUNC (ethi_drag_data_get), ethi); - -} - -static void -ethi_unrealize (GnomeCanvasItem *item) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - - gdk_gc_unref (ethi->gc); - ethi->gc = NULL; - - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_motion_id); - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_leave_id); - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_drop_id); - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_data_received_id); - - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_end_id); - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_data_get_id); - - if (ethi->stipple){ - gdk_bitmap_unref (ethi->stipple); - ethi->stipple = NULL; - } - - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->unrealize)(item); -} - -static void -draw_button (ETableHeaderItem *ethi, ETableCol *col, - GdkDrawable *drawable, GdkGC *gc, GtkStyle *style, - int x, int y, int width, int height, ETableColArrow arrow) -{ - GdkRectangle clip; - int xtra; - - gdk_draw_rectangle ( - drawable, gc, TRUE, - x + 1, y + 1, width - 2, height -2); - - gtk_draw_shadow ( - style, drawable, - GTK_STATE_NORMAL, GTK_SHADOW_OUT, - x , y, width, height); - - clip.x = x + HEADER_PADDING / 2; - clip.y = y + HEADER_PADDING / 2; - clip.width = width - HEADER_PADDING; - clip.height = ethi->height; - - gdk_gc_set_clip_rectangle (ethi->gc, &clip); - - if (col->is_pixbuf){ - xtra = (clip.width - gdk_pixbuf_get_width (col->pixbuf))/2; - - xtra += HEADER_PADDING / 2; - - gdk_pixbuf_render_to_drawable_alpha (col->pixbuf, - drawable, - 0, 0, - x + xtra, y + (clip.height - gdk_pixbuf_get_height (col->pixbuf)) / 2, - gdk_pixbuf_get_width (col->pixbuf), gdk_pixbuf_get_height(col->pixbuf), - GDK_PIXBUF_ALPHA_FULL, 128, - GDK_RGB_DITHER_NORMAL, - 0, 0); - } else { - /* Center the thing */ - xtra = (clip.width - gdk_string_measure (ethi->font, col->text))/2; - - /* Skip over border */ - if (xtra < 0) - xtra = 0; - - xtra += HEADER_PADDING / 2; - - gdk_draw_text ( - drawable, ethi->font, - ethi->gc, x + xtra, y + ethi->height - ethi->font->descent - HEADER_PADDING / 2, - col->text, strlen (col->text)); - } - - if (col->pixbuf){ - if ((gdk_pixbuf_get_width (col->pixbuf) + MIN_ARROW_SIZE + 4) > width) - return; - } - - switch (arrow){ - case E_TABLE_COL_ARROW_NONE: - break; - - case E_TABLE_COL_ARROW_UP: - case E_TABLE_COL_ARROW_DOWN: - gtk_paint_arrow ( - gtk_widget_get_style (GTK_WIDGET(GNOME_CANVAS_ITEM(ethi)->canvas)), - drawable, - GTK_STATE_NORMAL, - GTK_SHADOW_IN, - &clip, - GTK_WIDGET(GNOME_CANVAS_ITEM(ethi)->canvas), - "header", - (arrow == E_TABLE_COL_ARROW_UP) ? GTK_ARROW_UP : GTK_ARROW_DOWN, - TRUE, - x + HEADER_PADDING / 2 + clip.width - MIN_ARROW_SIZE - 2, - y + (ethi->height - MIN_ARROW_SIZE) / 2, - MIN_ARROW_SIZE, - MIN_ARROW_SIZE); - break; - } -} - -static void -ethi_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - GdkGC *gc; - const int cols = e_table_header_count (ethi->eth); - int x1, x2; - int col; - GHashTable *arrows = g_hash_table_new (NULL, NULL); - - - if (ethi->sort_info) { - int length = e_table_sort_info_grouping_get_count(ethi->sort_info); - int i; - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_grouping_get_nth(ethi->sort_info, i); - g_hash_table_insert (arrows, - (gpointer) column.column, - (gpointer) (column.ascending ? - E_TABLE_COL_ARROW_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, - (gpointer) column.column, - (gpointer) (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; - for (col = 0; col < cols; col++, x1 = x2){ - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - int col_width; - - col_width = ecol->width; - - x2 += col_width; - - if (x1 > (x + width)) - break; - - if (x2 < x) - continue; - - gc = GTK_WIDGET (canvas)->style->bg_gc [GTK_STATE_NORMAL]; - - draw_button (ethi, ecol, drawable, gc, - GTK_WIDGET (canvas)->style, - x1 - x, - y, x2 - x1, ethi->height, - (ETableColArrow) g_hash_table_lookup (arrows, (gpointer) ecol->col_idx)); - } - g_hash_table_destroy (arrows); -} - -static double -ethi_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - -/* - * is_pointer_on_division: - * - * Returns whether @pos is a column header division; If @the_total is not NULL, - * then the actual position is returned here. If @return_ecol is not NULL, - * then the ETableCol that actually contains this point is returned here - */ -static gboolean -is_pointer_on_division (ETableHeaderItem *ethi, int pos, int *the_total, int *return_col) -{ - const int cols = e_table_header_count (ethi->eth); - int col, total; - - total = 0; - for (col = 0; col < cols; col++){ - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - - if (col == 0) - total += ethi->group_indent_width; - - total += ecol->width; - - if ((total - TOLERANCE < pos)&& (pos < total + TOLERANCE)){ - if (return_col) - *return_col = col; - if (the_total) - *the_total = total; - - return TRUE; - } - - if (total > pos + TOLERANCE) - return FALSE; - } - - return FALSE; -} - -#define convert(c,sx,sy,x,y) gnome_canvas_w2c (c,sx,sy,x,y) - -static void -set_cursor (ETableHeaderItem *ethi, int pos) -{ - GtkWidget *canvas = GTK_WIDGET (GNOME_CANVAS_ITEM (ethi)->canvas); - - /* We might be invoked before we are realized */ - if (!canvas->window) - return; - - if (is_pointer_on_division (ethi, pos, NULL, NULL)) - e_cursor_set (canvas->window, E_CURSOR_SIZE_X); - else - e_cursor_set (canvas->window, E_CURSOR_ARROW); -} - -static void -ethi_end_resize (ETableHeaderItem *ethi) -{ - ethi->resize_col = -1; - ethi->resize_guide = GINT_TO_POINTER (0); - - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(ethi)); -} - -static gboolean -ethi_maybe_start_drag (ETableHeaderItem *ethi, GdkEventMotion *event) -{ - if (!ethi->maybe_drag) - return FALSE; - - if (ethi->eth->col_count < 2) - return FALSE; - - if (MAX (abs (ethi->click_x - event->x), - abs (ethi->click_y - event->y)) <= 3) - return FALSE; - - return TRUE; -} - -static void -ethi_start_drag (ETableHeaderItem *ethi, GdkEvent *event) -{ - GtkWidget *widget = GTK_WIDGET (GNOME_CANVAS_ITEM (ethi)->canvas); - GtkTargetList *list; - GdkDragContext *context; - ETableCol *ecol; - int col_width; - GdkPixmap *pixmap; - GdkGC *gc; - int group_indent = 0; - GHashTable *arrows = g_hash_table_new (NULL, NULL); - - GtkTargetEntry ethi_drag_types [] = { - { TARGET_ETABLE_COL_TYPE, 0, TARGET_ETABLE_COL_HEADER }, - }; - - ethi->drag_col = ethi_find_col_by_x (ethi, event->motion.x); - - if (ethi->drag_col == -1) - return; - - if (ethi->sort_info) { - int length = e_table_sort_info_grouping_get_count(ethi->sort_info); - int i; - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_grouping_get_nth(ethi->sort_info, i); - group_indent ++; - g_hash_table_insert (arrows, - (gpointer) column.column, - (gpointer) (column.ascending ? - E_TABLE_COL_ARROW_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, - (gpointer) column.column, - (gpointer) (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, ELEMENTS (ethi_drag_types)); - context = gtk_drag_begin (widget, list, GDK_ACTION_MOVE, 1, event); - g_free(ethi_drag_types[0].target); - - ecol = e_table_header_get_column (ethi->eth, ethi->drag_col); - col_width = ecol->width; - pixmap = gdk_pixmap_new (widget->window, col_width, ethi->height, -1); - gc = widget->style->bg_gc [GTK_STATE_ACTIVE]; - draw_button (ethi, ecol, pixmap, gc, - widget->style, - 0, 0, col_width, ethi->height, - (ETableColArrow) g_hash_table_lookup (arrows, (gpointer) ecol->col_idx)); - gtk_drag_set_icon_pixmap (context, - gdk_window_get_colormap (widget->window), - pixmap, - NULL, - col_width / 2, - ethi->height / 2); - gdk_pixmap_unref (pixmap); - - ethi->maybe_drag = FALSE; - g_hash_table_destroy (arrows); -} - -typedef struct { - ETableHeaderItem *ethi; - int col; -} EthiHeaderInfo; - -static void -ethi_popup_sort_ascending(GtkWidget *widget, EthiHeaderInfo *info) -{ - ETableCol *col; - int model_col; - int length; - int i; - int found = FALSE; - ETableHeaderItem *ethi = info->ethi; - - col = e_table_header_get_column (ethi->eth, info->col); - model_col = col->col_idx; - - length = e_table_sort_info_grouping_get_count(ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_grouping_get_nth(ethi->sort_info, i); - if (model_col == column.column){ - column.ascending = 1; - e_table_sort_info_grouping_set_nth(ethi->sort_info, i, column); - found = 1; - break; - } - } - if (!found) { - length = e_table_sort_info_sorting_get_count(ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(ethi->sort_info, i); - if (model_col == column.column){ - column.ascending = 1; - e_table_sort_info_sorting_set_nth(ethi->sort_info, i, column); - found = 1; - break; - } - } - } - if (!found) { - ETableSortColumn column = { model_col, 1 }; - length = e_table_sort_info_sorting_get_count(ethi->sort_info); - if (length == 0) - length++; - e_table_sort_info_sorting_set_nth(ethi->sort_info, length - 1, column); - } -} - -static void -ethi_popup_sort_descending(GtkWidget *widget, EthiHeaderInfo *info) -{ - ETableCol *col; - int model_col; - int length; - int i; - int found = FALSE; - ETableHeaderItem *ethi = info->ethi; - - col = e_table_header_get_column (ethi->eth, info->col); - model_col = col->col_idx; - - length = e_table_sort_info_grouping_get_count(ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_grouping_get_nth(ethi->sort_info, i); - if (model_col == column.column){ - column.ascending = 0; - e_table_sort_info_grouping_set_nth(ethi->sort_info, i, column); - found = 1; - break; - } - } - if (!found) { - length = e_table_sort_info_sorting_get_count(ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(ethi->sort_info, i); - if (model_col == column.column){ - column.ascending = 0; - e_table_sort_info_sorting_set_nth(ethi->sort_info, i, column); - found = 1; - break; - } - } - } - if (!found) { - ETableSortColumn column = { model_col, 0 }; - length = e_table_sort_info_sorting_get_count(ethi->sort_info); - if (length == 0) - length++; - e_table_sort_info_sorting_set_nth(ethi->sort_info, length - 1, column); - } -} - -static void -ethi_popup_unsort(GtkWidget *widget, EthiHeaderInfo *info) -{ - ETableHeaderItem *ethi = info->ethi; - - e_table_sort_info_grouping_truncate(ethi->sort_info, 0); - e_table_sort_info_sorting_truncate(ethi->sort_info, 0); -} - -static void -ethi_popup_group_field(GtkWidget *widget, EthiHeaderInfo *info) -{ - ETableCol *col; - int model_col; - ETableHeaderItem *ethi = info->ethi; - ETableSortColumn column; - - col = e_table_header_get_column (ethi->eth, info->col); - model_col = col->col_idx; - - column.column = model_col; - column.ascending = 1; - e_table_sort_info_grouping_set_nth(ethi->sort_info, 0, column); - e_table_sort_info_grouping_truncate(ethi->sort_info, 1); -} - -static void -ethi_popup_group_box(GtkWidget *widget, EthiHeaderInfo *info) -{ -} - -static void -ethi_popup_remove_column(GtkWidget *widget, EthiHeaderInfo *info) -{ - e_table_header_remove(info->ethi->eth, info->col); -} - -static void -ethi_popup_field_chooser(GtkWidget *widget, EthiHeaderInfo *info) -{ - GtkWidget *etfcd = e_table_field_chooser_dialog_new(); - gtk_object_set(GTK_OBJECT(etfcd), - "full_header", info->ethi->full_header, - "dnd_code", info->ethi->dnd_code, - NULL); - gtk_widget_show(etfcd); -} - -static void -ethi_popup_alignment(GtkWidget *widget, EthiHeaderInfo *info) -{ -} - -static void -ethi_popup_best_fit(GtkWidget *widget, EthiHeaderInfo *info) -{ -} - -static void -ethi_popup_format_columns(GtkWidget *widget, EthiHeaderInfo *info) -{ -} - -static void -ethi_popup_customize_view(GtkWidget *widget, EthiHeaderInfo *info) -{ -} - -/* Bit 1 is always disabled. */ -/* Bit 2 is disabled if not "sortable". */ -static EPopupMenu ethi_context_menu [] = { - { N_("Sort Ascending"), NULL, GTK_SIGNAL_FUNC(ethi_popup_sort_ascending), 2}, - { N_("Sort Descending"), NULL, GTK_SIGNAL_FUNC(ethi_popup_sort_descending), 2}, - { N_("Unsort"), NULL, GTK_SIGNAL_FUNC(ethi_popup_unsort), 0}, - { "", NULL, GTK_SIGNAL_FUNC(NULL), 0}, - { N_("Group By This Field"), NULL, GTK_SIGNAL_FUNC(ethi_popup_group_field), 0}, - { N_("Group By Box"), NULL, GTK_SIGNAL_FUNC(ethi_popup_group_box), 1}, - { "", NULL, GTK_SIGNAL_FUNC(NULL), 1}, - { N_("Remove This Column"), NULL, GTK_SIGNAL_FUNC(ethi_popup_remove_column), 0}, - { N_("Field Chooser"), NULL, GTK_SIGNAL_FUNC(ethi_popup_field_chooser), 0}, - { "", NULL, GTK_SIGNAL_FUNC(NULL), 1}, - { N_("Alignment"), NULL, GTK_SIGNAL_FUNC(ethi_popup_alignment), 1}, - { N_("Best Fit"), NULL, GTK_SIGNAL_FUNC(ethi_popup_best_fit), 1}, - { N_("Format Columns..."), NULL, GTK_SIGNAL_FUNC(ethi_popup_format_columns), 1}, - { "", NULL, GTK_SIGNAL_FUNC(NULL), 1}, - { N_("Customize Current View..."), NULL, GTK_SIGNAL_FUNC(ethi_popup_customize_view), 1}, - { NULL, NULL, NULL, 0 } -}; - -static void -ethi_header_context_menu (ETableHeaderItem *ethi, GdkEventButton *event) -{ - EthiHeaderInfo *info = g_new(EthiHeaderInfo, 1); - ETableCol *col; - info->ethi = ethi; - info->col = ethi_find_col_by_x (ethi, event->x); - col = e_table_header_get_column (ethi->eth, info->col); - e_popup_menu_run (ethi_context_menu, event, 1 + (col->sortable ? 0 : 2), 0, info); -} - -static void -ethi_button_pressed (ETableHeaderItem *ethi, GdkEventButton *event) -{ - gtk_signal_emit (GTK_OBJECT (ethi), - ethi_signals [BUTTON_PRESSED], event); -} - -/* - * Handles the events on the ETableHeaderItem, particularly it handles resizing - */ -static int -ethi_event (GnomeCanvasItem *item, GdkEvent *e) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - const gboolean resizing = ETHI_RESIZING (ethi); - int x, y, start, col; - int was_maybe_drag = 0; - - switch (e->type){ - case GDK_ENTER_NOTIFY: - convert (canvas, e->crossing.x, e->crossing.y, &x, &y); - set_cursor (ethi, x); - break; - - case GDK_LEAVE_NOTIFY: - e_cursor_set (GTK_WIDGET (canvas)->window, E_CURSOR_ARROW); - break; - - case GDK_MOTION_NOTIFY: - - convert (canvas, e->motion.x, e->motion.y, &x, &y); - if (resizing){ - int new_width; - - if (ethi->resize_guide == NULL){ - /* Quick hack until I actually bind the views */ - ethi->resize_guide = GINT_TO_POINTER (1); - - gnome_canvas_item_grab (item, - GDK_POINTER_MOTION_MASK | - GDK_BUTTON_RELEASE_MASK, - e_cursor_get (E_CURSOR_SIZE_X), - e->button.time); - } - - new_width = x - ethi->resize_start_pos; - - e_table_header_set_size (ethi->eth, ethi->resize_col, new_width); - - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(ethi)); - } else if (ethi_maybe_start_drag (ethi, &e->motion)){ - ethi_start_drag (ethi, e); - } else - set_cursor (ethi, x); - break; - - case GDK_BUTTON_PRESS: - if (e->button.button > 3) - return FALSE; - - convert (canvas, e->button.x, e->button.y, &x, &y); - - if (is_pointer_on_division (ethi, x, &start, &col) && e->button.button == 1){ - ETableCol *ecol; - - /* - * Record the important bits. - * - * By setting resize_pos to a non -1 value, - * we know that we are being resized (used in the - * other event handlers). - */ - ecol = e_table_header_get_column (ethi->eth, col); - - if (!ecol->resizeable) - break; - ethi->resize_col = col; - ethi->resize_start_pos = start - ecol->width; - ethi->resize_min_width = ecol->min_width; - } else { - if (e->button.button == 1){ - ethi->click_x = e->button.x; - ethi->click_y = e->button.y; - ethi->maybe_drag = TRUE; - } else if (e->button.button == 3){ - ethi_header_context_menu (ethi, &e->button); - } else - ethi_button_pressed (ethi, &e->button); - } - break; - - case GDK_2BUTTON_PRESS: - if (!resizing) - break; - - if (e->button.button != 1) - break; - 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 *col; - int model_col; - int length; - int i; - int found = FALSE; - - col = e_table_header_get_column (ethi->eth, ethi_find_col_by_x (ethi, e->button.x)); - model_col = col->col_idx; - - length = e_table_sort_info_grouping_get_count(ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_grouping_get_nth(ethi->sort_info, i); - if (model_col == column.column){ - int ascending = column.ascending; - ascending = ! ascending; - column.ascending = ascending; - e_table_sort_info_grouping_set_nth(ethi->sort_info, i, column); - found = 1; - break; - } - } - if(col->sortable) { - if (!found) { - length = e_table_sort_info_sorting_get_count(ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(ethi->sort_info, i); - if (model_col == column.column){ - int ascending = column.ascending; - ascending = ! ascending; - column.ascending = ascending; - e_table_sort_info_sorting_set_nth(ethi->sort_info, i, column); - found = 1; - break; - } - } - } - if (!found) { - ETableSortColumn column = { model_col, 1 }; - length = e_table_sort_info_sorting_get_count(ethi->sort_info); - if (length == 0) - length++; - e_table_sort_info_sorting_set_nth(ethi->sort_info, length - 1, column); - } - } - } - - if (needs_ungrab) - gnome_canvas_item_ungrab (item, e->button.time); - - break; - } - - default: - return FALSE; - } - return TRUE; -} - -static void -ethi_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - - ethi_parent_class = gtk_type_class (PARENT_OBJECT_TYPE); - - object_class->destroy = ethi_destroy; - object_class->set_arg = ethi_set_arg; - object_class->get_arg = ethi_get_arg; - - item_class->update = ethi_update; - item_class->realize = ethi_realize; - item_class->unrealize = ethi_unrealize; - item_class->draw = ethi_draw; - item_class->point = ethi_point; - item_class->event = ethi_event; - - gtk_object_add_arg_type ("ETableHeaderItem::ETableHeader", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_TABLE_HEADER); - gtk_object_add_arg_type ("ETableHeaderItem::full_header", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_FULL_HEADER); - gtk_object_add_arg_type ("ETableHeaderItem::dnd_code", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_DND_CODE); - gtk_object_add_arg_type ("ETableHeaderItem::fontset", GTK_TYPE_STRING, - GTK_ARG_WRITABLE, ARG_TABLE_FONTSET); - gtk_object_add_arg_type ("ETableHeaderItem::sort_info", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_SORT_INFO); - - /* - * Create our pixmaps for DnD - */ - dnd_colormap = gtk_widget_get_default_colormap (); - remove_col_pixmap = gdk_pixmap_colormap_create_from_xpm_d ( - NULL, dnd_colormap, - &remove_col_mask, NULL, remove_col_xpm); - - add_col_pixmap = gdk_pixmap_colormap_create_from_xpm_d ( - NULL, dnd_colormap, - &add_col_mask, NULL, add_col_xpm); - - ethi_signals [BUTTON_PRESSED] = - gtk_signal_new ("button_pressed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableHeaderItemClass, button_pressed), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, GTK_TYPE_POINTER); - -} - -static void -ethi_init (GnomeCanvasItem *item) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - - ethi->resize_col = -1; - - item->x1 = 0; - item->y1 = 0; - item->x2 = 0; - item->y2 = 0; - - ethi->drag_col = -1; - ethi->drag_mark = -1; - - ethi->sort_info = NULL; - - ethi->sort_info_changed_id = 0; - ethi->group_info_changed_id = 0; - - ethi->group_indent_width = 0; -} - -GtkType -e_table_header_item_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableHeaderItem", - sizeof (ETableHeaderItem), - sizeof (ETableHeaderItemClass), - (GtkClassInitFunc) ethi_class_init, - (GtkObjectInitFunc) ethi_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_OBJECT_TYPE, &info); - } - - return type; -} diff --git a/widgets/e-table/e-table-header-item.h b/widgets/e-table/e-table-header-item.h deleted file mode 100644 index 15b627bfa9..0000000000 --- a/widgets/e-table/e-table-header-item.h +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_HEADER_ITEM_H_ -#define _E_TABLE_HEADER_ITEM_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gnome-xml/tree.h> -#include "e-table-header.h" -#include "e-table-sort-info.h" - -#define E_TABLE_HEADER_ITEM_TYPE (e_table_header_item_get_type ()) -#define E_TABLE_HEADER_ITEM(o) (GTK_CHECK_CAST ((o), E_TABLE_HEADER_ITEM_TYPE, ETableHeaderItem)) -#define E_TABLE_HEADER_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_HEADER_ITEM_TYPE, ETableHeaderItemClass)) -#define E_IS_TABLE_HEADER_ITEM(o) (GTK_CHECK_TYPE ((o), E_TABLE_HEADER_ITEM_TYPE)) -#define E_IS_TABLE_HEADER_ITEM_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_HEADER_ITEM_TYPE)) - -typedef struct { - GnomeCanvasItem parent; - ETableHeader *eth; - - GdkGC *gc; - GdkCursor *change_cursor; - - short height, width; - GdkFont *font; - - /* - * Used during resizing; Could be shorts - */ - int resize_col; - int resize_start_pos; - int resize_min_width; - - GtkObject *resize_guide; - - int group_indent_width; - - /* - * Ids - */ - int structure_change_id, dimension_change_id; - - /* - * For dragging columns - */ - guint maybe_drag:1; - guint dnd_ready:1; - int click_x, click_y; - int drag_col, drop_col, drag_mark; - guint drag_motion_id, drag_end_id, drag_leave_id, drag_drop_id, drag_data_received_id, drag_data_get_id; - guint sort_info_changed_id, group_info_changed_id; - GnomeCanvasItem *remove_item; - GdkBitmap *stipple; - - gchar *dnd_code; - - /* - * For column sorting info - */ - ETableSortInfo *sort_info; - - /* For adding fields. */ - ETableHeader *full_header; -} ETableHeaderItem; - -typedef struct { - GnomeCanvasItemClass parent_class; - - /* - * signals - */ - void (*button_pressed) (ETableHeaderItem *ethi, GdkEventButton *button); -} ETableHeaderItemClass; - -GtkType e_table_header_item_get_type (void); - -#endif /* _E_TABLE_HEADER_ITEM_H_ */ diff --git a/widgets/e-table/e-table-header.c b/widgets/e-table/e-table-header.c deleted file mode 100644 index fddda13da8..0000000000 --- a/widgets/e-table/e-table-header.c +++ /dev/null @@ -1,665 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-col-head.c: TableColHead implementation - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc - */ -#include <config.h> -#include <string.h> -#include <gtk/gtkobject.h> -#include <gtk/gtksignal.h> -#include "e-table-header.h" -#include "e-table-defines.h" - -/* The arguments we take */ -enum { - ARG_0, - ARG_SORT_INFO, - ARG_WIDTH, -}; - -enum { - STRUCTURE_CHANGE, - DIMENSION_CHANGE, - LAST_SIGNAL -}; - -static void eth_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void eth_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void eth_do_remove (ETableHeader *eth, int idx, gboolean do_unref); -static void eth_set_width(ETableHeader *eth, int width); -static void eth_set_size (ETableHeader *eth, int idx, int size); -static void eth_calc_widths (ETableHeader *eth); -static void dequeue(ETableHeader *eth, int *column, int *width); - -static guint eth_signals [LAST_SIGNAL] = { 0, }; - -static GtkObjectClass *e_table_header_parent_class; - -struct two_ints { - int column; - int width; -}; - -static gboolean -dequeue_idle(ETableHeader *eth) -{ - int column, width; - dequeue(eth, &column, &width); - while(eth->change_queue && ((struct two_ints *)eth->change_queue->data)->column == column) - dequeue(eth, &column, &width); - if (column == -1) - eth_set_width(eth, width); - else if (column < eth->col_count) - eth_set_size(eth, column, width); - if (eth->change_queue) - return TRUE; - else { - eth_calc_widths(eth); - eth->idle = 0; - return FALSE; - } -} - -static void -enqueue(ETableHeader *eth, int column, int width) -{ - struct two_ints *store; - store = g_new(struct two_ints, 1); - store->column = column; - store->width = width; - - eth->change_tail = g_slist_last(g_slist_append(eth->change_tail, store)); - if (!eth->change_queue) - eth->change_queue = eth->change_tail; - - if (!eth->idle) { - eth->idle = g_idle_add_full(G_PRIORITY_LOW, (GSourceFunc) dequeue_idle, eth, NULL); - } -} - -static void -dequeue(ETableHeader *eth, int *column, int *width) -{ - GSList *head; - struct two_ints *store; - head = eth->change_queue; - eth->change_queue = eth->change_queue->next; - if (!eth->change_queue) - eth->change_tail = NULL; - store = head->data; - g_slist_free_1(head); - if (column) - *column = store->column; - if (width) - *width = store->width; - g_free(store); -} - -static void -eth_destroy (GtkObject *object) -{ - ETableHeader *eth = E_TABLE_HEADER (object); - const int cols = eth->col_count; - int i; - - if (eth->sort_info) { - if (eth->sort_info_group_change_id) - gtk_signal_disconnect(GTK_OBJECT(eth->sort_info), - eth->sort_info_group_change_id); - gtk_object_unref(GTK_OBJECT(eth->sort_info)); - } - - if (eth->idle) - g_source_remove(eth->idle); - g_slist_foreach(eth->change_queue, (GFunc) g_free, NULL); - g_slist_free(eth->change_queue); - - /* - * Destroy columns - */ - for (i = cols - 1; i >= 0; i--){ - eth_do_remove (eth, i, TRUE); - } - - if (e_table_header_parent_class->destroy) - e_table_header_parent_class->destroy (object); -} - -static void -e_table_header_class_init (GtkObjectClass *object_class) -{ - object_class->destroy = eth_destroy; - object_class->set_arg = eth_set_arg; - object_class->get_arg = eth_get_arg; - - - e_table_header_parent_class = (gtk_type_class (gtk_object_get_type ())); - - gtk_object_add_arg_type ("ETableHeader::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ETableHeader::sort_info", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_SORT_INFO); - - eth_signals [STRUCTURE_CHANGE] = - gtk_signal_new ("structure_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableHeaderClass, structure_change), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - eth_signals [DIMENSION_CHANGE] = - gtk_signal_new ("dimension_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableHeaderClass, dimension_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, eth_signals, LAST_SIGNAL); -} - -static void -e_table_header_init (ETableHeader *eth) -{ - eth->col_count = 0; - eth->width = 0; - - eth->sort_info = NULL; - eth->sort_info_group_change_id = 0; - - eth->columns = NULL; - eth->selectable = FALSE; - - eth->change_queue = NULL; - eth->change_tail = NULL; -} - -GtkType -e_table_header_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableHeader", - sizeof (ETableHeader), - sizeof (ETableHeaderClass), - (GtkClassInitFunc) e_table_header_class_init, - (GtkObjectInitFunc) e_table_header_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &info); - } - - return type; -} - -ETableHeader * -e_table_header_new (void) -{ - ETableHeader *eth; - - eth = gtk_type_new (e_table_header_get_type ()); - - return eth; -} - -static void -eth_group_info_changed(ETableSortInfo *info, ETableHeader *eth) -{ - enqueue(eth, -1, eth->nominal_width); -} - -static void -eth_set_width(ETableHeader *eth, int width) -{ - eth->width = width; -} - -static void -eth_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableHeader *eth = E_TABLE_HEADER (object); - - switch (arg_id) { - case ARG_WIDTH: - eth->nominal_width = GTK_VALUE_DOUBLE (*arg); - enqueue(eth, -1, GTK_VALUE_DOUBLE (*arg)); - break; - case ARG_SORT_INFO: - if (eth->sort_info) { - if (eth->sort_info_group_change_id) - gtk_signal_disconnect(GTK_OBJECT(eth->sort_info), eth->sort_info_group_change_id); - gtk_object_unref(GTK_OBJECT(eth->sort_info)); - } - eth->sort_info = E_TABLE_SORT_INFO(GTK_VALUE_OBJECT (*arg)); - if (eth->sort_info) { - gtk_object_ref(GTK_OBJECT(eth->sort_info)); - eth->sort_info_group_change_id - = gtk_signal_connect(GTK_OBJECT(eth->sort_info), "group_info_changed", - GTK_SIGNAL_FUNC(eth_group_info_changed), eth); - } - enqueue(eth, -1, eth->nominal_width); - break; - default: - break; - } -} - -static void -eth_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableHeader *eth = E_TABLE_HEADER (object); - - switch (arg_id) { - case ARG_SORT_INFO: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(eth->sort_info); - break; - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = eth->nominal_width; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -eth_update_offsets (ETableHeader *eth) -{ - int i; - int x = 0; - - for (i = 0; i < eth->col_count; i++){ - ETableCol *etc = eth->columns [i]; - - etc->x = x; - x += etc->width; - } -} - -static void -eth_do_insert (ETableHeader *eth, int pos, ETableCol *val) -{ - memmove (ð->columns [pos+1], ð->columns [pos], - sizeof (ETableCol *) * (eth->col_count - pos)); - eth->columns [pos] = val; - eth->col_count ++; -} - -void -e_table_header_add_column (ETableHeader *eth, ETableCol *tc, int pos) -{ - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (tc != NULL); - g_return_if_fail (E_IS_TABLE_COL (tc)); - g_return_if_fail (pos >= -1 && pos <= eth->col_count); - - if (pos == -1) - pos = eth->col_count; - eth->columns = g_realloc (eth->columns, sizeof (ETableCol *) * (eth->col_count + 1)); - - /* - * We are the primary owners of the column - */ - gtk_object_ref (GTK_OBJECT (tc)); - gtk_object_sink (GTK_OBJECT (tc)); - - eth_do_insert (eth, pos, tc); - - enqueue(eth, -1, eth->nominal_width); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [STRUCTURE_CHANGE]); -} - -ETableCol * -e_table_header_get_column (ETableHeader *eth, int column) -{ - g_return_val_if_fail (eth != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), NULL); - - if (column < 0) - return NULL; - - if (column >= eth->col_count) - return NULL; - - return eth->columns [column]; -} - -int -e_table_header_count (ETableHeader *eth) -{ - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - return eth->col_count; -} - -int -e_table_header_index (ETableHeader *eth, int col) -{ - g_return_val_if_fail (eth != NULL, -1); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), -1); - g_return_val_if_fail (col < eth->col_count, -1); - - return eth->columns [col]->col_idx; -} - -int -e_table_header_get_index_at (ETableHeader *eth, int x_offset) -{ - int i, total; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - total = 0; - for (i = 0; i < eth->col_count; i++){ - total += eth->columns [i]->width; - - if (x_offset < total) - return i; - } - - return -1; -} - -ETableCol ** -e_table_header_get_columns (ETableHeader *eth) -{ - ETableCol **ret; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - ret = g_new (ETableCol *, eth->col_count + 1); - memcpy (ret, eth->columns, sizeof (ETableCol *) * eth->col_count); - ret [eth->col_count] = NULL; - - return ret; -} - -gboolean -e_table_header_selection_ok (ETableHeader *eth) -{ - g_return_val_if_fail (eth != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), FALSE); - - return eth->selectable; -} - -int -e_table_header_get_selected (ETableHeader *eth) -{ - int i; - int selected = 0; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - for (i = 0; i < eth->col_count; i++){ - if (eth->columns [i]->selected) - selected++; - } - - return selected; -} - -int -e_table_header_total_width (ETableHeader *eth) -{ - int total, i; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - total = 0; - for (i = 0; i < eth->col_count; i++) - total += eth->columns [i]->width; - - return total; -} - -static void -eth_do_remove (ETableHeader *eth, int idx, gboolean do_unref) -{ - if (do_unref) - gtk_object_unref (GTK_OBJECT (eth->columns [idx])); - - memmove (ð->columns [idx], ð->columns [idx+1], - sizeof (ETableCol *) * (eth->col_count - idx - 1)); - eth->col_count--; -} - -void -e_table_header_move (ETableHeader *eth, int source_index, int target_index) -{ - ETableCol *old; - - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (source_index >= 0); - g_return_if_fail (target_index >= 0); - g_return_if_fail (source_index < eth->col_count); - g_return_if_fail (target_index < eth->col_count + 1); /* Can be moved beyond the last item. */ - - if (source_index < target_index) - target_index --; - - old = eth->columns [source_index]; - eth_do_remove (eth, source_index, FALSE); - eth_do_insert (eth, target_index, old); - eth_update_offsets (eth); - - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [DIMENSION_CHANGE]); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [STRUCTURE_CHANGE]); -} - -void -e_table_header_remove (ETableHeader *eth, int idx) -{ - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < eth->col_count); - - eth_do_remove (eth, idx, TRUE); - enqueue(eth, -1, eth->nominal_width); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [STRUCTURE_CHANGE]); -} - -void -e_table_header_set_selection (ETableHeader *eth, gboolean allow_selection) -{ -} - -void -e_table_header_set_size(ETableHeader *eth, int idx, int size) -{ - enqueue(eth, idx, size); -} - -static void -eth_set_size (ETableHeader *eth, int idx, int size) -{ - double expansion; - double old_expansion; - int min_width; - int left_width; - int total_extra; - int expandable_count; - int usable_width; - int i; - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < eth->col_count); - - /* If this column is not resizable, don't do anything. */ - if (!eth->columns[idx]->resizeable) - return; - - expansion = 0; - min_width = 0; - left_width = 0; - expandable_count = -1; - - /* Calculate usable area. */ - for (i = 0; i < idx; i++) { - left_width += eth->columns[i]->width; - } - /* - 1 to account for the last pixel border. */ - usable_width = eth->width - left_width - 1; - - if (eth->sort_info) - usable_width -= e_table_sort_info_grouping_get_count(eth->sort_info) * GROUP_INDENT; - - /* Calculate minimum_width of stuff on the right as well as - * total usable expansion on the right. - */ - for (; i < eth->col_count; i++) { - min_width += eth->columns[i]->min_width; - if (eth->columns[i]->resizeable) { - expansion += eth->columns[i]->expansion; - expandable_count ++; - } - } - /* If there's no room for anything, don't change. */ - if (expansion == 0) - return; - - /* (1) If none of the columns to the right are expandable, use - * all the expansion space in this column. - */ - if(expandable_count == 0) { - eth->columns[idx]->expansion = expansion; - for (i = idx + 1; i < eth->col_count; i++) { - eth->columns[i]->expansion = 0; - } - return; - } - - total_extra = usable_width - min_width; - /* If there's no extra space, set all expansions to 0. */ - if (total_extra <= 0) { - for (i = idx; i < eth->col_count; i++) { - eth->columns[i]->expansion = 0; - } - return; - } - - /* If you try to resize smaller than the minimum width, it - * uses the minimum. */ - if (size < eth->columns[idx]->min_width) - size = eth->columns[idx]->min_width; - - /* 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->columns[idx]->expansion = expansion; - for (i = idx + 1; i < eth->col_count; i++) { - eth->columns[i]->expansion = 0; - } - return; - } - - /* The old_expansion used by columns to the right. */ - old_expansion = expansion; - old_expansion -= eth->columns[idx]->expansion; - /* Set the new expansion so that it will generate the desired size. */ - eth->columns[idx]->expansion = expansion * (((double)(size - eth->columns[idx]->min_width))/((double)total_extra)); - /* The expansion left for the columns on the right. */ - expansion -= eth->columns[idx]->expansion; - - /* (2) If the old columns to the right didn't have any - * expansion before, expand them evenly. old_expansion > 0 by - * expansion = SUM(i=idx to col_count -1, - * columns[i]->min_width) - columns[idx]->min_width) = - * SUM(non-negatives). - */ - if (old_expansion == 0) { - for (i = idx + 1; i < eth->col_count; i++) { - if (eth->columns[idx]->resizeable) { - /* expandable_count != 0 by (1) */ - eth->columns[i]->expansion = expansion / expandable_count; - } - } - return; - } - - /* Remove from total_extra the amount used for this column. */ - total_extra -= size - eth->columns[idx]->min_width; - for (i = idx + 1; i < eth->col_count; i++) { - if (eth->columns[idx]->resizeable) { - /* old_expansion != 0 by (2) */ - eth->columns[i]->expansion *= expansion / old_expansion; - } - } -} - -int -e_table_header_col_diff (ETableHeader *eth, int start_col, int end_col) -{ - int total, col; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - { - if (start_col < 0) - start_col = 0; - if (end_col > eth->col_count) - end_col = eth->col_count; - - total = 0; - for (col = start_col; col < end_col; col++){ - - total += eth->columns [col]->width; - } - } - - return total; -} - -static void -eth_calc_widths (ETableHeader *eth) -{ - int i; - int extra; - double expansion; - int last_position = 0; - double next_position = 0; - int last_resizable = -1; - /* - 1 to account for the last pixel border. */ - extra = eth->width - 1; - expansion = 0; - for (i = 0; i < eth->col_count; i++) { - extra -= eth->columns[i]->min_width; - if (eth->columns[i]->resizeable && eth->columns[i]->expansion > 0) - last_resizable = i; - expansion += eth->columns[i]->resizeable ? eth->columns[i]->expansion : 0; - eth->columns[i]->width = eth->columns[i]->min_width; - } - if (eth->sort_info) - extra -= e_table_sort_info_grouping_get_count(eth->sort_info) * GROUP_INDENT; - if (expansion == 0 || extra <= 0) - return; - for (i = 0; i < last_resizable; i++) { - next_position += extra * (eth->columns[i]->resizeable ? eth->columns[i]->expansion : 0)/expansion; - eth->columns[i]->width += next_position - last_position; - last_position = next_position; - } - eth->columns[i]->width += extra - last_position; - - eth_update_offsets (eth); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [DIMENSION_CHANGE]); -} diff --git a/widgets/e-table/e-table-header.h b/widgets/e-table/e-table-header.h deleted file mode 100644 index 0dcce14b1e..0000000000 --- a/widgets/e-table/e-table-header.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_COLUMN_H_ -#define _E_TABLE_COLUMN_H_ - -#include <gtk/gtkobject.h> -#include <gdk/gdk.h> -#include "e-table-sort-info.h" -#include "e-table-col.h" - -typedef struct _ETableHeader ETableHeader; - -#define E_TABLE_HEADER_TYPE (e_table_header_get_type ()) -#define E_TABLE_HEADER(o) (GTK_CHECK_CAST ((o), E_TABLE_HEADER_TYPE, ETableHeader)) -#define E_TABLE_HEADER_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_HEADER_TYPE, ETableHeaderClass)) -#define E_IS_TABLE_HEADER(o) (GTK_CHECK_TYPE ((o), E_TABLE_HEADER_TYPE)) -#define E_IS_TABLE_HEADER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_HEADER_TYPE)) - -/* - * A Columnar header. - */ -struct _ETableHeader { - GtkObject base; - - int col_count; - int width; - int nominal_width; - - ETableSortInfo *sort_info; - int sort_info_group_change_id; - - ETableCol **columns; - gboolean selectable; - - GSList *change_queue, *change_tail; - gint idle; -}; - -typedef struct { - GtkObjectClass parent_class; - - void (*structure_change) (ETableHeader *eth); - void (*dimension_change) (ETableHeader *eth, int col); -} ETableHeaderClass; - -GtkType e_table_header_get_type (void); -ETableHeader *e_table_header_new (void); - -void e_table_header_add_column (ETableHeader *eth, - ETableCol *tc, int pos); -ETableCol * e_table_header_get_column (ETableHeader *eth, - int column); -int e_table_header_count (ETableHeader *eth); -int e_table_header_index (ETableHeader *eth, - int col); -int e_table_header_get_index_at (ETableHeader *eth, - int x_offset); -ETableCol **e_table_header_get_columns (ETableHeader *eth); - -gboolean e_table_header_selection_ok (ETableHeader *eth); -int e_table_header_get_selected (ETableHeader *eth); -int e_table_header_total_width (ETableHeader *eth); -void e_table_header_move (ETableHeader *eth, - int source_index, - int target_index); -void e_table_header_remove (ETableHeader *eth, int idx); -void e_table_header_set_size (ETableHeader *eth, int idx, int size); -void e_table_header_set_selection (ETableHeader *eth, - gboolean allow_selection); - -int e_table_header_col_diff (ETableHeader *eth, - int start_col, int end_col); - -void e_table_header_calc_widths (ETableHeader *eth); - -GList *e_table_header_get_selected_indexes (ETableHeader *eth); - - -#endif /* _E_TABLE_HEADER_H_ */ - diff --git a/widgets/e-table/e-table-item.c b/widgets/e-table/e-table-item.c deleted file mode 100644 index 0f70861f1e..0000000000 --- a/widgets/e-table/e-table-item.c +++ /dev/null @@ -1,2228 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-item.c: A GnomeCanvasItem that is a view of an ETableModel. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, Helix Code, Inc. - * - * TODO: - * Add a border to the thing, so that focusing works properly. - * - */ -#include <config.h> -#include <stdio.h> -#include <gtk/gtksignal.h> -#include <gdk/gdkkeysyms.h> -#include <math.h> -#include "e-table-item.h" -#include "e-table-subset.h" -#include "e-cell.h" -#include "e-util/e-canvas.h" -#include "e-util/e-canvas-utils.h" -#include "e-util/e-util.h" - -#define PARENT_OBJECT_TYPE gnome_canvas_item_get_type () - -#define FOCUSED_BORDER 2 - -static GnomeCanvasItemClass *eti_parent_class; - -enum { - CURSOR_CHANGE, - DOUBLE_CLICK, - RIGHT_CLICK, - KEY_PRESS, - LAST_SIGNAL -}; - -static gint eti_signals [LAST_SIGNAL] = { 0, }; - -enum { - ARG_0, - ARG_TABLE_HEADER, - ARG_TABLE_MODEL, - ARG_TABLE_SELECTION_MODEL, - ARG_TABLE_DRAW_GRID, - ARG_TABLE_DRAW_FOCUS, - ARG_CURSOR_MODE, - ARG_LENGTH_THRESHOLD, - ARG_CURSOR_ROW, - - ARG_MINIMUM_WIDTH, - ARG_WIDTH, - ARG_HEIGHT, -}; - -static int eti_get_height (ETableItem *eti); -static int eti_get_minimum_width (ETableItem *eti); -static int eti_row_height (ETableItem *eti, int row); -static void e_table_item_focus (ETableItem *eti, int col, int row, GdkModifierType state); -static void eti_cursor_change (ETableSelectionModel *selection, int row, int col, ETableItem *eti); -static void eti_selection_change (ETableSelectionModel *selection, ETableItem *eti); -#if 0 -static void eti_request_region_show (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row); -#endif -#define ETI_ROW_HEIGHT(eti,row) ((eti)->height_cache && (eti)->height_cache[(row)] != -1 ? (eti)->height_cache[(row)] : eti_row_height((eti),(row))) - -inline static gint -model_to_view_row(ETableItem *eti, int row) -{ - int i; - if (eti->uses_source_model) { - ETableSubset *etss = E_TABLE_SUBSET(eti->table_model); - if (eti->row_guess >= 0 && eti->row_guess < etss->n_map) { - if (etss->map_table[eti->row_guess] == row) { - return eti->row_guess; - } - } - for (i = 0; i < etss->n_map; i++) { - if (etss->map_table[i] == row) - return i; - } - return -1; - } else - return row; -} - -inline static gint -view_to_model_row(ETableItem *eti, int row) -{ - if (eti->uses_source_model) { - ETableSubset *etss = E_TABLE_SUBSET(eti->table_model); - if (row >= 0 && row < etss->n_map) - return etss->map_table[row]; - else - return -1; - } else - return row; -} - -inline static gint -model_to_view_col(ETableItem *eti, int col) -{ - int i; - for (i = 0; i < eti->cols; i++) { - ETableCol *ecol = e_table_header_get_column (eti->header, i); - if (ecol->col_idx == col) - return i; - } - return -1; -} - -inline static gint -view_to_model_col(ETableItem *eti, int col) -{ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - return ecol->col_idx; -} - -static gboolean -eti_editing (ETableItem *eti) -{ - if (eti->editing_col == -1) - return FALSE; - else - return TRUE; -} - -/* - * During realization, we have to invoke the per-ecell realize routine - * (On our current setup, we have one e-cell per column. - * - * We might want to optimize this to only realize the unique e-cells: - * ie, a strings-only table, uses the same e-cell for every column, and - * we might want to avoid realizing each e-cell. - */ -static void -eti_realize_cell_views (ETableItem *eti) -{ - int i; - - for (i = 0; i < eti->n_cells; i++) - e_cell_realize (eti->cell_views [i]); - eti->cell_views_realized = 1; -} - -static void -eti_attach_cell_views (ETableItem *eti) -{ - int i; - - g_assert (eti->header); - g_assert (eti->table_model); - - /* - * Now realize the various ECells - */ - eti->n_cells = eti->cols; - eti->cell_views = g_new (ECellView *, eti->n_cells); - - for (i = 0; i < eti->n_cells; i++){ - ETableCol *ecol = e_table_header_get_column (eti->header, i); - - eti->cell_views [i] = e_cell_new_view (ecol->ecell, eti->table_model, eti); - } - - eti->needs_compute_height = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); -} - -/* - * During unrealization: we invoke every e-cell (one per column in the current - * setup) to dispose all X resources allocated - */ -static void -eti_unrealize_cell_views (ETableItem *eti) -{ - int i; - - if (eti->cell_views_realized == 0) - return; - - for (i = 0; i < eti->n_cells; i++) - e_cell_unrealize (eti->cell_views [i]); - eti->cell_views_realized = 0; -} - -static void -eti_detach_cell_views (ETableItem *eti) -{ - int i; - - for (i = 0; i < eti->n_cells; i++){ - e_cell_kill_view (eti->cell_views [i]); - eti->cell_views [i] = NULL; - } - - g_free (eti->cell_views); - eti->cell_views = NULL; - eti->n_cells = 0; -} - -static void -eti_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2) -{ - double i2c [6]; - ArtPoint c1, c2, i1, i2; - ETableItem *eti = E_TABLE_ITEM (item); - - /* Wrong BBox's are the source of redraw nightmares */ - - gnome_canvas_item_i2c_affine (GNOME_CANVAS_ITEM (eti), i2c); - - i1.x = eti->x1; - i1.y = eti->y1; - i2.x = eti->x1 + eti->width; - i2.y = eti->y1 + eti->height; - art_affine_point (&c1, &i1, i2c); - art_affine_point (&c2, &i2, i2c); - - *x1 = c1.x; - *y1 = c1.y; - *x2 = c2.x + 1; - *y2 = c2.y + 1; -} - -static void -eti_reflow (GnomeCanvasItem *item, gint flags) -{ - ETableItem *eti = E_TABLE_ITEM (item); - - if (eti->needs_compute_height) { - int new_height = eti_get_height (eti); - - if (new_height != eti->height) { - eti->height = new_height; - e_canvas_item_request_parent_reflow (GNOME_CANVAS_ITEM (eti)); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); - } - eti->needs_compute_height = 0; - } - if (eti->needs_compute_width) { - int new_width = eti_get_minimum_width (eti); - new_width = MAX(new_width, eti->minimum_width); - if (new_width != eti->width) { - eti->width = new_width; - e_canvas_item_request_parent_reflow (GNOME_CANVAS_ITEM (eti)); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); - } - eti->needs_compute_width = 0; - } -} - -/* - * GnomeCanvasItem::update method - */ -static void -eti_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - ArtPoint o1, o2; - ETableItem *eti = E_TABLE_ITEM (item); - - if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->update) - (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->update)(item, affine, clip_path, flags); - - o1.x = item->x1; - o1.y = item->y1; - o2.x = item->x2; - o2.y = item->y2; - - eti_bounds (item, &item->x1, &item->y1, &item->x2, &item->y2); - if (item->x1 != o1.x || - item->y1 != o1.y || - item->x2 != o2.x || - item->y2 != o2.y) { - gnome_canvas_request_redraw (item->canvas, o1.x, o1.y, o2.x, o2.y); - eti->needs_redraw = 1; - } - - if (eti->needs_redraw) { - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, - item->x2, item->y2); - eti->needs_redraw = 0; - } -} - -/* - * eti_remove_table_model: - * - * Invoked to release the table model associated with this ETableItem - */ -static void -eti_remove_table_model (ETableItem *eti) -{ - if (!eti->table_model) - return; - - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_pre_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_row_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_cell_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_row_inserted_id); - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_row_deleted_id); - gtk_object_unref (GTK_OBJECT (eti->table_model)); - if (eti->source_model) - gtk_object_unref (GTK_OBJECT (eti->source_model)); - - eti->table_model_pre_change_id = 0; - eti->table_model_change_id = 0; - eti->table_model_row_change_id = 0; - eti->table_model_cell_change_id = 0; - eti->table_model_row_inserted_id = 0; - eti->table_model_row_deleted_id = 0; - eti->table_model = NULL; - eti->source_model = NULL; - eti->uses_source_model = 0; -} - -/* - * eti_remove_table_model: - * - * Invoked to release the table model associated with this ETableItem - */ -static void -eti_remove_table_selection_model (ETableItem *eti) -{ - if (!eti->selection) - return; - - gtk_signal_disconnect (GTK_OBJECT (eti->selection), - eti->selection_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->selection), - eti->cursor_change_id); - gtk_object_unref (GTK_OBJECT (eti->selection)); - - eti->selection_change_id = 0; - eti->cursor_change_id = 0; - eti->selection = NULL; -} - -/* - * eti_remove_header_model: - * - * Invoked to release the header model associated with this ETableItem - */ -static void -eti_remove_header_model (ETableItem *eti) -{ - if (!eti->header) - return; - - gtk_signal_disconnect (GTK_OBJECT (eti->header), - eti->header_structure_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->header), - eti->header_dim_change_id); - - if (eti->cell_views){ - eti_unrealize_cell_views (eti); - eti_detach_cell_views (eti); - } - gtk_object_unref (GTK_OBJECT (eti->header)); - - - eti->header_structure_change_id = 0; - eti->header_dim_change_id = 0; - eti->header = NULL; -} - -/* - * eti_row_height_real: - * - * Returns the height used by row @row. This does not include the one-pixel - * used as a separator between rows - */ -static int -eti_row_height_real (ETableItem *eti, int row) -{ - const int cols = e_table_header_count (eti->header); - int col; - int h, max_h; - - g_assert (eti->cell_views); - - max_h = 0; - - for (col = 0; col < cols; col++){ - h = e_cell_height (eti->cell_views [col], view_to_model_col(eti, col), col, row); - - if (h > max_h) - max_h = h; - } - return max_h; -} - -static gboolean -height_cache_idle(ETableItem *eti) -{ - int changed = 0; - int i; - if (!eti->height_cache) { - eti->height_cache = g_new(int, eti->rows); - } - for (i = eti->height_cache_idle_count; i < eti->rows; i++) { - if (eti->height_cache[i] == -1) { - eti_row_height(eti, i); - changed ++; - if (changed >= 20) - break; - } - } - if (changed >= 20) { - eti->height_cache_idle_count = i; - return TRUE; - } - eti->height_cache_idle_id = 0; - return FALSE; -} - -static void -free_height_cache (ETableItem *eti) -{ - if (eti->height_cache) - g_free (eti->height_cache); - eti->height_cache = NULL; - eti->height_cache_idle_count = 0; - - if (eti->height_cache_idle_id == 0) - eti->height_cache_idle_id = g_idle_add_full(G_PRIORITY_LOW, (GSourceFunc) height_cache_idle, eti, NULL); -} - -static void -calculate_height_cache (ETableItem *eti) -{ - int i; - free_height_cache(eti); - eti->height_cache = g_new(int, eti->rows); - for (i = 0; i < eti->rows; i++) { - eti->height_cache[i] = -1; - } -} - - -/* - * eti_row_height: - * - * Returns the height used by row @row. This does not include the one-pixel - * used as a separator between rows - */ -static int -eti_row_height (ETableItem *eti, int row) -{ - if (!eti->height_cache) { - calculate_height_cache (eti); - } - if (eti->height_cache[row] == -1) { - eti->height_cache[row] = eti_row_height_real(eti, row); - if (row > 0 && - eti->length_threshold != -1 && - eti->rows > eti->length_threshold && - eti->height_cache[row] != eti_row_height(eti, 0)) { - eti->needs_compute_height = 1; - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(eti)); - } - } - return eti->height_cache[row]; -} - -/* - * eti_get_height: - * - * Returns the height of the ETableItem. - * - * The ETableItem might compute the whole height by asking every row its - * size. There is a special mode (designed to work when there are too - * many rows in the table that performing the previous step could take - * too long) set by the ETableItem->length_threshold that would determine - * when the height is computed by using the first row as the size for - * every other row in the ETableItem. - */ -static int -eti_get_height (ETableItem *eti) -{ - const int rows = eti->rows; - int row; - int height; - - if (rows == 0) - return 0; - - if (eti->length_threshold != -1){ - if (rows > eti->length_threshold){ - int row_height = eti_row_height(eti, 0); - if (eti->height_cache) { - height = 0; - for (row = 0; row < rows; row++) { - if (eti->height_cache[row] == -1) { - height += (row_height + 1) * (rows - row); - break; - } - else - height += eti->height_cache[row] + 1; - } - } else - height = (eti_row_height (eti, 0) + 1) * rows; - - /* - * 1 pixel at the top - */ - return height + 1; - } - } - - height = 1; - for (row = 0; row < rows; row++) - height += eti_row_height (eti, row) + 1; - - return height; -} - -static int -eti_get_minimum_width (ETableItem *eti) -{ - int width = 0; - int col; - for (col = 0; col < eti->cols; col++){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - width += ecol->min_width; - } - return width; -} - -static void -eti_item_region_redraw (ETableItem *eti, int x0, int y0, int x1, int y1) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); - ArtDRect rect; - double i2c [6]; - - rect.x0 = x0; - rect.y0 = y0; - rect.x1 = x1; - rect.y1 = y1; - - gnome_canvas_item_i2c_affine (item, i2c); - art_drect_affine_transform (&rect, &rect, i2c); - - gnome_canvas_request_redraw (item->canvas, rect.x0, rect.y0, rect.x1, rect.y1); -} - -/* - * Callback routine: invoked before the ETableModel has suffers a change - */ -static void -eti_table_model_pre_change (ETableModel *table_model, ETableItem *eti) -{ - if (eti_editing (eti)) - e_table_item_leave_edit (eti); -} - -/* - * Callback routine: invoked when the ETableModel has suffered a change - */ -static void -eti_table_model_changed (ETableModel *table_model, ETableItem *eti) -{ -#if 0 - int view_row; -#endif - - eti->rows = e_table_model_row_count (eti->table_model); - - free_height_cache(eti); - - eti->needs_compute_height = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); - -#if 0 - view_row = model_to_view_row(eti, eti->cursor_row); - if (view_row >= 0 && eti->cursor_col >= 0) - eti_request_region_show (eti, eti->cursor_col, view_row, eti->cursor_col, view_row); -#endif -} - -/* - * Computes the distance between @start_row and @end_row in pixels - */ -static int -eti_row_diff (ETableItem *eti, int start_row, int end_row) -{ - int row, total; - - total = 0; - - for (row = start_row; row < end_row; row++) - total += eti_row_height (eti, row) + 1; - - return total; -} - -/* - * eti_request_region_redraw: - * - * Request a canvas redraw on the range (start_col, start_row) to (end_col, end_row). - * This is inclusive (ie, you can use: 0,0-0,0 to redraw the first cell). - * - * The @border argument is a number of pixels around the region that should also be queued - * for redraw. This is typically used by the focus routines to queue a redraw for the - * border as well. - */ -static void -eti_request_region_redraw (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row, int border) -{ - int x1, y1, width, height; - - if (eti->rows > 0) { - - x1 = e_table_header_col_diff (eti->header, 0, start_col); - y1 = eti_row_diff (eti, 0, start_row); - width = e_table_header_col_diff (eti->header, start_col, end_col + 1); - height = eti_row_diff (eti, start_row, end_row + 1); - - eti_item_region_redraw (eti, eti->x1 + x1 - border, - eti->y1 + y1 - border, - eti->x1 + x1 + width + 1 + border, - eti->y1 + y1 + height + 1 + border); - } -} - -/* - * eti_request_region_show - * - * Request a canvas show on the range (start_col, start_row) to (end_col, end_row). - * This is inclusive (ie, you can use: 0,0-0,0 to show the first cell). - */ -static void -eti_request_region_show (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row) -{ - int x1, y1, x2, y2; - - x1 = e_table_header_col_diff (eti->header, 0, start_col); - y1 = eti_row_diff (eti, 0, start_row); - x2 = x1 + e_table_header_col_diff (eti->header, start_col, end_col + 1); - y2 = y1 + eti_row_diff (eti, start_row, end_row + 1); - - e_canvas_item_show_area(GNOME_CANVAS_ITEM(eti), x1, y1, x2, y2); -} - -static void -eti_table_model_row_changed (ETableModel *table_model, int row, ETableItem *eti) -{ - if (eti->renderers_can_change_size) { - eti_table_model_changed (table_model, eti); - return; - } - - eti_request_region_redraw (eti, 0, row, eti->cols, row, 0); -} - -static void -eti_table_model_cell_changed (ETableModel *table_model, int col, int row, ETableItem *eti) -{ - if (eti->renderers_can_change_size) { - eti_table_model_changed (table_model, eti); - return; - } - - eti_request_region_redraw (eti, 0, row, eti->cols -1, row, 0); -} - -static void -eti_table_model_row_inserted (ETableModel *table_model, int row, ETableItem *eti) -{ - eti_table_model_changed (table_model, eti); -} - -static void -eti_table_model_row_deleted (ETableModel *table_model, int row, ETableItem *eti) -{ - eti_table_model_changed (table_model, eti); -} - -void -e_table_item_redraw_range (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row) -{ - int border; - int cursor_col, cursor_row; - - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - "cursor_row", &cursor_row, - NULL); - - if ((start_col == cursor_col) || - (end_col == cursor_col) || - (view_to_model_row(eti, start_row) == cursor_row) || - (view_to_model_row(eti, end_row) == cursor_row)) - border = 2; - else - border = 0; - - eti_request_region_redraw(eti, start_col, start_row, end_col, end_row, border); -} - -static void -eti_add_table_model (ETableItem *eti, ETableModel *table_model) -{ - g_assert (eti->table_model == NULL); - - eti->table_model = table_model; - gtk_object_ref (GTK_OBJECT (eti->table_model)); - - eti->table_model_pre_change_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_pre_change", - GTK_SIGNAL_FUNC (eti_table_model_pre_change), eti); - - eti->table_model_change_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_changed", - GTK_SIGNAL_FUNC (eti_table_model_changed), eti); - - eti->table_model_row_change_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_row_changed", - GTK_SIGNAL_FUNC (eti_table_model_row_changed), eti); - - eti->table_model_cell_change_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_cell_changed", - GTK_SIGNAL_FUNC (eti_table_model_cell_changed), eti); - - eti->table_model_row_inserted_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_row_inserted", - GTK_SIGNAL_FUNC (eti_table_model_row_inserted), eti); - - eti->table_model_row_deleted_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_row_deleted", - GTK_SIGNAL_FUNC (eti_table_model_row_deleted), eti); - - if (eti->header) { - eti_detach_cell_views (eti); - eti_attach_cell_views (eti); - } - - if (E_IS_TABLE_SUBSET(table_model)) { - eti->uses_source_model = 1; - eti->source_model = E_TABLE_SUBSET(table_model)->source; - if (eti->source_model) - gtk_object_ref(GTK_OBJECT(eti->source_model)); - } - - eti_table_model_changed (table_model, eti); -} - -static void -eti_add_table_selection_model (ETableItem *eti, ETableSelectionModel *selection) -{ - g_assert (eti->selection == NULL); - - eti->selection = selection; - gtk_object_ref (GTK_OBJECT (eti->selection)); - - eti->selection_change_id = gtk_signal_connect ( - GTK_OBJECT (selection), "selection_changed", - GTK_SIGNAL_FUNC (eti_selection_change), eti); - - eti->cursor_change_id = gtk_signal_connect ( - GTK_OBJECT (selection), "cursor_changed", - GTK_SIGNAL_FUNC (eti_cursor_change), eti); - - eti_selection_change(selection, eti); -} - -static void -eti_header_dim_changed (ETableHeader *eth, int col, ETableItem *eti) -{ - eti->needs_compute_width = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); -} - -static void -eti_header_structure_changed (ETableHeader *eth, ETableItem *eti) -{ - eti->cols = e_table_header_count (eti->header); - eti->width = e_table_header_total_width (eti->header); - - /* - * There should be at least one column - */ - g_assert (eti->cols != 0); - - if (eti->cell_views){ - eti_unrealize_cell_views (eti); - eti_detach_cell_views (eti); - eti_attach_cell_views (eti); - eti_realize_cell_views (eti); - } else { - if (eti->table_model) { - eti_detach_cell_views (eti); - eti_attach_cell_views (eti); - } - } - eti->needs_compute_width = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); -} - -static void -eti_add_header_model (ETableItem *eti, ETableHeader *header) -{ - g_assert (eti->header == NULL); - - eti->header = header; - gtk_object_ref (GTK_OBJECT (header)); - - eti_header_structure_changed (header, eti); - - eti->header_dim_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "dimension_change", - GTK_SIGNAL_FUNC (eti_header_dim_changed), eti); - - eti->header_structure_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "structure_change", - GTK_SIGNAL_FUNC (eti_header_structure_changed), eti); -} - -/* - * GtkObject::destroy method - */ -static void -eti_destroy (GtkObject *object) -{ - ETableItem *eti = E_TABLE_ITEM (object); - - eti_remove_header_model (eti); - eti_remove_table_model (eti); - eti_remove_table_selection_model (eti); - - if (eti->selection) - gtk_object_unref(GTK_OBJECT(eti->selection)); - - if (eti->height_cache_idle_id) - g_source_remove(eti->height_cache_idle_id); - - g_free (eti->height_cache); - - if (GTK_OBJECT_CLASS (eti_parent_class)->destroy) - (*GTK_OBJECT_CLASS (eti_parent_class)->destroy) (object); -} - -static void -eti_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableItem *eti; - int cursor_col; - - item = GNOME_CANVAS_ITEM (o); - eti = E_TABLE_ITEM (o); - - switch (arg_id){ - case ARG_TABLE_HEADER: - eti_remove_header_model (eti); - eti_add_header_model (eti, E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg))); - break; - - case ARG_TABLE_MODEL: - eti_remove_table_model (eti); - eti_add_table_model (eti, E_TABLE_MODEL(GTK_VALUE_OBJECT (*arg))); - break; - - case ARG_TABLE_SELECTION_MODEL: - eti_remove_table_selection_model (eti); - if (GTK_VALUE_OBJECT (*arg)) - eti_add_table_selection_model (eti, E_TABLE_SELECTION_MODEL(GTK_VALUE_OBJECT (*arg))); - break; - - case ARG_LENGTH_THRESHOLD: - eti->length_threshold = GTK_VALUE_INT (*arg); - break; - - case ARG_TABLE_DRAW_GRID: - eti->draw_grid = GTK_VALUE_BOOL (*arg); - break; - - case ARG_TABLE_DRAW_FOCUS: - eti->draw_focus = GTK_VALUE_BOOL (*arg); - break; - - case ARG_CURSOR_MODE: - eti->cursor_mode = GTK_VALUE_INT (*arg); - break; - - case ARG_MINIMUM_WIDTH: - case ARG_WIDTH: - if (eti->minimum_width == eti->width && GTK_VALUE_DOUBLE (*arg) > eti->width) - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); - eti->minimum_width = GTK_VALUE_DOUBLE (*arg); - if (eti->minimum_width < eti->width) - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); - break; - case ARG_CURSOR_ROW: - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - NULL); - - e_table_item_focus (eti, cursor_col != -1 ? cursor_col : 0, view_to_model_row(eti, GTK_VALUE_INT (*arg)), 0); - break; - } - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(eti)); -} - -static void -eti_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableItem *eti; - int row; - - item = GNOME_CANVAS_ITEM (o); - eti = E_TABLE_ITEM (o); - - switch (arg_id){ - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = eti->width; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = eti->height; - break; - case ARG_MINIMUM_WIDTH: - GTK_VALUE_DOUBLE (*arg) = eti->minimum_width; - break; - case ARG_CURSOR_ROW: - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &row, - NULL); - GTK_VALUE_INT (*arg) = model_to_view_row(eti, row); - break; - default: - arg->type = GTK_TYPE_INVALID; - } -} - -static void -eti_init (GnomeCanvasItem *item) -{ - ETableItem *eti = E_TABLE_ITEM (item); - - eti->editing_col = -1; - eti->editing_row = -1; - eti->height = 0; - eti->width = 0; - eti->minimum_width = 0; - - eti->height_cache = NULL; - eti->height_cache_idle_id = 0; - eti->height_cache_idle_count = 0; - - eti->length_threshold = -1; - eti->renderers_can_change_size = 1; - - eti->uses_source_model = 0; - eti->source_model = NULL; - - eti->row_guess = -1; - eti->cursor_mode = E_TABLE_CURSOR_SIMPLE; - - eti->selection_change_id = 0; - eti->cursor_change_id = 0; - eti->selection = NULL; - - eti->needs_redraw = 0; - eti->needs_compute_height = 0; - - e_canvas_item_set_reflow_callback (GNOME_CANVAS_ITEM (eti), eti_reflow); -} - -#define gray50_width 2 -#define gray50_height 2 -static const char gray50_bits[] = { - 0x02, 0x01, }; - -static void -eti_realize (GnomeCanvasItem *item) -{ - ETableItem *eti = E_TABLE_ITEM (item); - GtkWidget *canvas_widget = GTK_WIDGET (item->canvas); - GdkWindow *window; - - if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->realize) - (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->realize)(item); - - /* - * Gdk Resource allocation - */ - window = canvas_widget->window; - - eti->fill_gc = gdk_gc_new (window); - - eti->grid_gc = gdk_gc_new (window); -#if 0 - /* This sets it to gray */ -/* gdk_gc_set_foreground (eti->grid_gc, &canvas_widget->style->bg [GTK_STATE_NORMAL]); */ -#else - gdk_gc_set_foreground (eti->grid_gc, &canvas_widget->style->dark [GTK_STATE_NORMAL]); -#endif - eti->focus_gc = gdk_gc_new (window); - gdk_gc_set_foreground (eti->focus_gc, &canvas_widget->style->bg [GTK_STATE_NORMAL]); - gdk_gc_set_background (eti->focus_gc, &canvas_widget->style->fg [GTK_STATE_NORMAL]); - eti->stipple = gdk_bitmap_create_from_data (NULL, gray50_bits, gray50_width, gray50_height); - gdk_gc_set_ts_origin (eti->focus_gc, 0, 0); - gdk_gc_set_stipple (eti->focus_gc, eti->stipple); - gdk_gc_set_fill (eti->focus_gc, GDK_OPAQUE_STIPPLED); - - if (eti->cell_views == NULL) - eti_attach_cell_views (eti); - - eti_realize_cell_views (eti); - - eti->needs_compute_height = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); -} - -static void -eti_unrealize (GnomeCanvasItem *item) -{ - ETableItem *eti = E_TABLE_ITEM (item); - - if (eti_editing (eti)) - e_table_item_leave_edit (eti); - - gdk_gc_unref (eti->fill_gc); - eti->fill_gc = NULL; - gdk_gc_unref (eti->grid_gc); - eti->grid_gc = NULL; - gdk_gc_unref (eti->focus_gc); - eti->focus_gc = NULL; - gdk_bitmap_unref (eti->stipple); - eti->stipple = NULL; - - eti_unrealize_cell_views (eti); - - eti->height = 0; - - if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize)(item); -} - -static void -eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - ETableItem *eti = E_TABLE_ITEM (item); - const int rows = eti->rows; - const int cols = eti->cols; - int row, col, y1, y2; - int first_col, last_col, x_offset; - int first_row, last_row, y_offset, yd; - int x1, x2; - int f_x1, f_x2, f_y1, f_y2; - gboolean f_found; - double i2c [6]; - ArtPoint eti_base, eti_base_item; - GtkWidget *canvas = GTK_WIDGET(item->canvas); - GdkColor *background; - - /* - * Clear the background - */ -#if 0 - gdk_draw_rectangle ( - drawable, eti->fill_gc, TRUE, - eti->x1 - x, eti->y1 - y, eti->width, eti->height); -#endif - - /* - * Find out our real position after grouping - */ - gnome_canvas_item_i2c_affine (item, i2c); - eti_base_item.x = eti->x1; - eti_base_item.y = eti->y1; - art_affine_point (&eti_base, &eti_base_item, i2c); - - /* - * First column to draw, last column to draw - */ - first_col = -1; - last_col = x_offset = 0; - x1 = x2 = floor (eti_base.x); - for (col = 0; col < cols; col++, x1 = x2){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - x2 = x1 + ecol->width; - - if (x1 > (x + width)) - break; - if (x2 < x) - continue; - if (first_col == -1){ - x_offset = x1 - x; - first_col = col; - } - } - last_col = col; - - /* - * Nothing to paint - */ - if (first_col == -1) - return; - - /* - * Compute row span. - */ - first_row = -1; - y_offset = 0; - y1 = y2 = floor (eti_base.y) + 1; - for (row = 0; row < rows; row++, y1 = y2){ - - y2 += ETI_ROW_HEIGHT (eti, row) + 1; - - if (y1 > y + height) - break; - - if (y2 < y) - continue; - - if (first_row == -1){ - y_offset = y1 - y; - first_row = row; - } - } - last_row = row; - - if (first_row == -1) - return; - - /* - * Draw cells - */ - yd = y_offset; - f_x1 = f_x2 = f_y1 = f_y2 = -1; - f_found = FALSE; - - if (eti->draw_grid && first_row == 0){ - gdk_draw_line ( - drawable, eti->grid_gc, - eti_base.x - x, yd, eti_base.x + eti->width - x, yd); - } - yd++; - - for (row = first_row; row < last_row; row++){ - int xd, height; - gboolean selected; - gint cursor_col, cursor_row; - - height = ETI_ROW_HEIGHT (eti, row); - - xd = x_offset; -/* printf ("paint: %d %d\n", yd, yd + height); */ - - selected = e_table_selection_model_is_row_selected(eti->selection, view_to_model_row(eti,row)); - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - "cursor_row", &cursor_row, - NULL); - - for (col = first_col; col < last_col; col++){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - ECellView *ecell_view = eti->cell_views [col]; - gboolean col_selected = selected; - switch (eti->cursor_mode) { - case E_TABLE_CURSOR_SIMPLE: - if (cursor_col == ecol->col_idx && cursor_row == view_to_model_row(eti, row)) - col_selected = !col_selected; - break; - case E_TABLE_CURSOR_LINE: - /* Nothing */ - break; - } - - if (selected){ - background = &canvas->style->bg [GTK_STATE_SELECTED]; - } else { - if (row % 2) - background = &canvas->style->base [GTK_STATE_NORMAL]; - else - background = &canvas->style->base [GTK_STATE_SELECTED]; - } - - gdk_gc_set_foreground (eti->fill_gc, background); - gdk_draw_rectangle (drawable, eti->fill_gc, TRUE, - xd, yd, ecol->width, height); - - e_cell_draw (ecell_view, drawable, ecol->col_idx, col, row, col_selected, - xd, yd, xd + ecol->width, yd + height); - - 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; - } - - xd += ecol->width; - } - yd += height; - - if (eti->draw_grid) - gdk_draw_line ( - drawable, eti->grid_gc, - eti_base.x - x, yd, eti_base.x + eti->width - x, yd); - yd++; - } - - if (eti->draw_grid){ - int xd = x_offset; - - for (col = first_col; col <= last_col; col++){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - gdk_draw_line ( - drawable, eti->grid_gc, - xd, y_offset, xd, yd - 1); - - /* - * This looks wierd, but it is to draw the last line - */ - if (ecol) - xd += ecol->width; - } - } - - /* - * Draw focus - */ - if (f_found && eti->draw_focus){ - gdk_draw_rectangle (drawable, eti->focus_gc, FALSE, - f_x1 + 1, f_y1, f_x2 - f_x1 - 2, f_y2 - f_y1 - 1); - } -} - -static double -eti_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - - return 0.0; -} - -static gboolean -find_cell (ETableItem *eti, double x, double y, int *col_res, int *row_res, double *x1_res, double *y1_res) -{ - const int cols = eti->cols; - const int rows = eti->rows; - gdouble x1, y1, x2, y2; - int col, row; - - /* FIXME: this routine is inneficient, fix later */ - - if (cols == 0 || rows == 0) - return FALSE; - - x -= eti->x1; - y -= eti->y1; - - x1 = 0; - for (col = 0; col < cols - 1; col++, x1 = x2){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - if (x < x1) - return FALSE; - - x2 = x1 + ecol->width; - - if (x <= x2) - break; - } - - y1 = y2 = 0; - for (row = 0; row < rows - 1; row++, y1 = y2){ - if (y < y1) - return FALSE; - - y2 += ETI_ROW_HEIGHT (eti, row) + 1; - - if (y <= y2) - break; - } - *col_res = col; - if (x1_res) - *x1_res = x - x1; - *row_res = row; - if (y1_res) - *y1_res = y - y1; - return TRUE; -} - -static void -eti_cursor_move (ETableItem *eti, gint row, gint column) -{ - e_table_item_leave_edit (eti); - e_table_item_focus (eti, view_to_model_col(eti, column), view_to_model_row(eti, row), 0); -} - -static void -eti_cursor_move_left (ETableItem *eti) -{ - int cursor_col, cursor_row; - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - "cursor_row", &cursor_row, - NULL); - - eti_cursor_move (eti, model_to_view_row(eti, cursor_row), model_to_view_col(eti, cursor_col) - 1); -} - -static void -eti_cursor_move_right (ETableItem *eti) -{ - int cursor_col, cursor_row; - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - "cursor_row", &cursor_row, - NULL); - - eti_cursor_move (eti, model_to_view_row(eti, cursor_row), model_to_view_col(eti, cursor_col) + 1); -} - -static void -eti_cursor_move_up (ETableItem *eti) -{ - int cursor_col, cursor_row; - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - "cursor_row", &cursor_row, - NULL); - - eti_cursor_move (eti, model_to_view_row(eti, cursor_row) - 1, model_to_view_col(eti, cursor_col)); -} - -static void -eti_cursor_move_down (ETableItem *eti) -{ - int cursor_col, cursor_row; - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - "cursor_row", &cursor_row, - NULL); - - eti_cursor_move (eti, model_to_view_row(eti, cursor_row) + 1, model_to_view_col(eti, cursor_col)); -} - -/* FIXME: cursor */ -static int -eti_event (GnomeCanvasItem *item, GdkEvent *e) -{ - ETableItem *eti = E_TABLE_ITEM (item); - ECellView *ecell_view; - gint return_val = TRUE; - - switch (e->type){ - case GDK_BUTTON_PRESS: { - double x1, y1; - int col, row; - gint cursor_row, cursor_col; - - e_canvas_item_grab_focus(GNOME_CANVAS_ITEM(eti)); - - switch (e->button.button) { - case 1: /* Fall through. */ - case 2: - gnome_canvas_item_w2i (item, &e->button.x, &e->button.y); - - if (!find_cell (eti, e->button.x, e->button.y, &col, &row, &x1, &y1)) - return TRUE; - - e_table_selection_model_do_something(eti->selection, view_to_model_row(eti, row), view_to_model_col(eti, col), e->button.state); - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (cursor_row == view_to_model_row(eti, row) && cursor_col == view_to_model_col(eti, col)){ - - if ((!eti_editing(eti)) && e_table_model_is_cell_editable(eti->selection->model, cursor_col, cursor_row)) { - e_table_item_enter_edit (eti, col, row); - } - - ecell_view = eti->cell_views [col]; - - /* - * Adjust the event positions - */ - e->button.x = x1; - e->button.y = y1; - - e_cell_event (ecell_view, e, view_to_model_col(eti, col), col, row); - } - break; - case 3: - gnome_canvas_item_w2i (item, &e->button.x, &e->button.y); - if (!find_cell (eti, e->button.x, e->button.y, &col, &row, &x1, &y1)) - return TRUE; - - e_table_selection_model_maybe_do_something(eti->selection, view_to_model_row(eti, row), view_to_model_col(eti, col), 0); - - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [RIGHT_CLICK], - row, col, e, &return_val); - break; - case 4: - case 5: - return FALSE; - break; - - } - break; - } - - case GDK_BUTTON_RELEASE: { - double x1, y1; - int col, row; - gint cursor_row, cursor_col; - - switch (e->button.button) { - case 1: /* Fall through. */ - case 2: - gnome_canvas_item_w2i (item, &e->button.x, &e->button.y); - - if (!find_cell (eti, e->button.x, e->button.y, &col, &row, &x1, &y1)) - return TRUE; - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (cursor_row == view_to_model_row(eti, row) && cursor_col == view_to_model_col(eti, col)){ - - ecell_view = eti->cell_views [col]; - - /* - * Adjust the event positions - */ - e->button.x = x1; - e->button.y = y1; - - e_cell_event (ecell_view, e, view_to_model_col(eti, col), col, row); - } - break; - case 3: - case 4: - case 5: - return FALSE; - break; - - } - break; - } - - case GDK_2BUTTON_PRESS: { - double x1, y1; - int col, row; - - if (e->button.button == 5 || - e->button.button == 4) - return FALSE; - - gnome_canvas_item_w2i (item, &e->button.x, &e->button.y); - - if (!find_cell (eti, e->button.x, e->button.y, &col, &row, &x1, &y1)) - return TRUE; - - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [DOUBLE_CLICK], - row); - break; - } - case GDK_MOTION_NOTIFY: { - int col, row; - double x1, y1; - gint cursor_col, cursor_row; - - gnome_canvas_item_w2i (item, &e->motion.x, &e->motion.y); - - if (!find_cell (eti, e->motion.x, e->motion.y, &col, &row, &x1, &y1)) - return TRUE; - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (cursor_row == view_to_model_row(eti, row) && cursor_col == view_to_model_col(eti, col)){ - ecell_view = eti->cell_views [col]; - - /* - * Adjust the event positions - */ - e->motion.x = x1; - e->motion.y = y1; - - e_cell_event (ecell_view, e, view_to_model_col(eti, col), col, row); - } - break; - } - - case GDK_KEY_PRESS: { - gint cursor_row, cursor_col; - gint handled = TRUE; - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (cursor_col == -1) - return FALSE; - - switch (e->key.keyval){ - case GDK_Left: - if (eti_editing (eti)) { - handled = FALSE; - break; - } - - if (cursor_col != view_to_model_col(eti, 0)) - eti_cursor_move_left (eti); - break; - - case GDK_Right: - if (eti_editing (eti)) { - handled = FALSE; - break; - } - - if (cursor_col != view_to_model_col(eti, eti->cols - 1)) - eti_cursor_move_right (eti); - break; - - case GDK_Up: - if (cursor_row != view_to_model_row(eti, 0)) - eti_cursor_move_up (eti); - else - return_val = FALSE; - break; - - case GDK_Down: - if (cursor_row != view_to_model_row(eti, eti->rows - 1)) - eti_cursor_move_down (eti); - else - return_val = FALSE; - break; - - case GDK_Tab: - case GDK_KP_Tab: - case GDK_ISO_Left_Tab: - if ((e->key.state & GDK_SHIFT_MASK) != 0){ - /* shift tab */ - if (cursor_col != view_to_model_col(eti, 0)) - eti_cursor_move_left (eti); - else if (cursor_row != view_to_model_row(eti, 0)) - eti_cursor_move (eti, model_to_view_row(eti, cursor_row) - 1, eti->cols - 1); - else - return_val = FALSE; - } else { - if (cursor_col != view_to_model_col (eti, eti->cols - 1)) - eti_cursor_move_right (eti); - else if (cursor_row != view_to_model_row(eti, eti->rows - 1)) - eti_cursor_move (eti, model_to_view_row(eti, cursor_row) + 1, 0); - else - return_val = FALSE; - } - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (cursor_col >= 0 && cursor_row >= 0 && return_val && - (!eti_editing(eti)) && e_table_model_is_cell_editable(eti->selection->model, cursor_col, cursor_row)) { - e_table_item_enter_edit (eti, model_to_view_col(eti, cursor_col), model_to_view_row(eti, cursor_row)); - } - break; - - case GDK_Return: - case GDK_KP_Enter: - case GDK_ISO_Enter: - case GDK_3270_Enter: - if (eti_editing (eti)){ - e_table_item_leave_edit (eti); -#if 0 - ecell_view = eti->cell_views [eti->editing_col]; - e_cell_event (ecell_view, e, view_to_model_col(eti, eti->editing_col), eti->editing_col, eti->editing_row); -#endif - } - return_val = FALSE; - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [KEY_PRESS], - model_to_view_row(eti, cursor_row), cursor_col, e, &return_val); - break; - - default: - handled = FALSE; - break; - } - if (!handled) { - if (!eti_editing (eti)){ - gint col, row; - row = model_to_view_row(eti, cursor_row); - col = model_to_view_col(eti, cursor_col); - if (col != -1 && row != -1 && e_table_model_is_cell_editable(eti->selection->model, cursor_col, cursor_row)) { - e_table_item_enter_edit (eti, col, row); - } - } - if (!eti_editing (eti)){ - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [KEY_PRESS], - model_to_view_row(eti, cursor_row), cursor_col, e, &return_val); - } else { - ecell_view = eti->cell_views [eti->editing_col]; - e_cell_event (ecell_view, e, view_to_model_col(eti, eti->editing_col), eti->editing_col, eti->editing_row); - } - } - break; - } - - case GDK_KEY_RELEASE: { - gint cursor_row, cursor_col; - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (cursor_col == -1) - return FALSE; - - if (eti_editing (eti)){ - ecell_view = eti->cell_views [eti->editing_col]; - e_cell_event (ecell_view, e, view_to_model_col(eti, eti->editing_col), eti->editing_col, eti->editing_row); - } - break; - } - - default: - return_val = FALSE; - } - return return_val; -} - -static void -eti_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - ETableItemClass *eti_class = (ETableItemClass *) object_class; - - eti_parent_class = gtk_type_class (PARENT_OBJECT_TYPE); - - object_class->destroy = eti_destroy; - object_class->set_arg = eti_set_arg; - object_class->get_arg = eti_get_arg; - - item_class->update = eti_update; - item_class->realize = eti_realize; - item_class->unrealize = eti_unrealize; - item_class->draw = eti_draw; - item_class->point = eti_point; - item_class->event = eti_event; - - eti_class->cursor_change = NULL; - eti_class->double_click = NULL; - eti_class->right_click = NULL; - eti_class->key_press = NULL; - - gtk_object_add_arg_type ("ETableItem::ETableHeader", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_TABLE_HEADER); - gtk_object_add_arg_type ("ETableItem::ETableModel", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_TABLE_MODEL); - gtk_object_add_arg_type ("ETableItem::table_selection_model", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_TABLE_SELECTION_MODEL); - gtk_object_add_arg_type ("ETableItem::drawgrid", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_GRID); - gtk_object_add_arg_type ("ETableItem::drawfocus", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_FOCUS); - gtk_object_add_arg_type ("ETableItem::cursor_mode", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_CURSOR_MODE); - gtk_object_add_arg_type ("ETableItem::length_threshold", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_LENGTH_THRESHOLD); - - gtk_object_add_arg_type ("ETableItem::minimum_width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_MINIMUM_WIDTH); - gtk_object_add_arg_type ("ETableItem::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ETableItem::height", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_HEIGHT); - gtk_object_add_arg_type ("ETableItem::cursor_row", GTK_TYPE_INT, - GTK_ARG_READWRITE, ARG_CURSOR_ROW); - - eti_signals [CURSOR_CHANGE] = - gtk_signal_new ("cursor_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableItemClass, cursor_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - eti_signals [DOUBLE_CLICK] = - gtk_signal_new ("double_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableItemClass, double_click), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - eti_signals [RIGHT_CLICK] = - gtk_signal_new ("right_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableItemClass, right_click), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - eti_signals [KEY_PRESS] = - gtk_signal_new ("key_press", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableItemClass, key_press), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - gtk_object_class_add_signals (object_class, eti_signals, LAST_SIGNAL); - -} - -GtkType -e_table_item_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableItem", - sizeof (ETableItem), - sizeof (ETableItemClass), - (GtkClassInitFunc) eti_class_init, - (GtkObjectInitFunc) eti_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_OBJECT_TYPE, &info); - } - - return type; -} - -void -e_table_item_set_cursor (ETableItem *eti, int col, int row) -{ - e_table_item_focus(eti, col, view_to_model_row(eti, row), 0); -} - -static void -e_table_item_focus (ETableItem *eti, int col, int row, GdkModifierType state) -{ - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (row == -1) { - row = view_to_model_row(eti, eti->rows - 1); - } - - if (col == -1) { - col = eti->cols - 1; - } - - if (row != -1) { - e_table_selection_model_do_something(eti->selection, - row, col, - state); - } -} - -gint -e_table_item_get_focused_column (ETableItem *eti) -{ - int cursor_col; - - g_return_val_if_fail (eti != NULL, -1); - g_return_val_if_fail (E_IS_TABLE_ITEM (eti), -1); - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - NULL); - - return cursor_col; -} - -gboolean -e_table_item_is_row_selected (ETableItem *eti, int row) -{ - g_return_val_if_fail (eti != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_ITEM (eti), FALSE); - - return e_table_selection_model_is_row_selected(eti->selection, row); -} - -static void -eti_cursor_change (ETableSelectionModel *selection, int row, int col, ETableItem *eti) -{ - int view_row = model_to_view_row(eti, row); - int view_col = model_to_view_col(eti, col); - - if (view_row == -1 || view_col == -1) { - e_table_item_leave_edit (eti); - return; - } - - eti_request_region_show (eti, view_col, view_row, view_col, view_row); - e_canvas_item_grab_focus(GNOME_CANVAS_ITEM(eti)); - if (eti_editing(eti)) - e_table_item_leave_edit (eti); - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [CURSOR_CHANGE], - view_row); - eti->needs_redraw = TRUE; - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(eti)); -} - -static void -eti_selection_change (ETableSelectionModel *selection, ETableItem *eti) -{ - eti->needs_redraw = TRUE; - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(eti)); -} - -void -e_table_item_enter_edit (ETableItem *eti, int col, int row) -{ - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (eti_editing (eti)) - e_table_item_leave_edit(eti); - - eti->editing_col = col; - eti->editing_row = row; - - eti->edit_ctx = e_cell_enter_edit (eti->cell_views [col], view_to_model_col(eti, col), col, row); -} - -void -e_table_item_leave_edit (ETableItem *eti) -{ - int col, row; - void *edit_ctx; - - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (!eti_editing (eti)) - return; - - col = eti->editing_col; - row = eti->editing_row; - edit_ctx = eti->edit_ctx; - - eti->editing_col = -1; - eti->editing_row = -1; - eti->edit_ctx = NULL; - - e_cell_leave_edit (eti->cell_views [col], - view_to_model_col(eti, col), - col, row, edit_ctx); -} - -void -e_table_item_compute_location (ETableItem *eti, - int *x, - int *y, - int *row, - int *col) -{ - if (!find_cell (eti, *x, *y, col, row, NULL, NULL)) { - *y -= eti_get_height(eti); - } - -} - -typedef struct { - ETableItem *item; - int rows_printed; -} ETableItemPrintContext; - -static gdouble * -e_table_item_calculate_print_widths (ETableHeader *eth, gdouble width) -{ - int i; - double extra; - double expansion; - int last_resizable = -1; - gdouble scale = 300.0L / 70.0L; - gdouble *widths = g_new(gdouble, e_table_header_count(eth)); - /* - 1 to account for the last pixel border. */ - extra = width - 1; - expansion = 0; - for (i = 0; i < eth->col_count; i++) { - extra -= eth->columns[i]->min_width * scale; - if (eth->columns[i]->resizeable && eth->columns[i]->expansion > 0) - last_resizable = i; - expansion += eth->columns[i]->resizeable ? eth->columns[i]->expansion : 0; - widths[i] = eth->columns[i]->min_width * scale; - } - for (i = 0; i <= last_resizable; i++) { - widths[i] += extra * (eth->columns[i]->resizeable ? eth->columns[i]->expansion : 0)/expansion; - } - - return widths; -} - -static gdouble -eti_printed_row_height (ETableItem *eti, gdouble *widths, GnomePrintContext *context, gint row) -{ - int col; - int cols = eti->cols; - gdouble height = 0; - for (col = 0; col < cols; col++) { - ECellView *ecell_view = eti->cell_views [col]; - gdouble this_height = e_cell_print_height (ecell_view, context, view_to_model_col(eti, col), col, row, - widths[col] - 1); - if (this_height > height) - height = this_height; - } - return height; -} - -#define CHECK(x) if((x) == -1) return -1; - -static gint -gp_draw_rect (GnomePrintContext *context, gdouble x, gdouble y, gdouble width, gdouble height) -{ - CHECK(gnome_print_moveto(context, x, y)); - CHECK(gnome_print_lineto(context, x + width, y)); - CHECK(gnome_print_lineto(context, x + width, y - height)); - CHECK(gnome_print_lineto(context, x, y - height)); - CHECK(gnome_print_lineto(context, x, y)); - return gnome_print_fill(context); -} - -static void -e_table_item_print_page (EPrintable *ep, - GnomePrintContext *context, - gdouble width, - gdouble height, - gboolean quantize, - ETableItemPrintContext *itemcontext) -{ - ETableItem *eti = itemcontext->item; - const int rows = eti->rows; - const int cols = eti->cols; - int rows_printed = itemcontext->rows_printed; - gdouble *widths; - int row, col; - gdouble yd = height; - - widths = e_table_item_calculate_print_widths (itemcontext->item->header, width); - - /* - * Draw cells - */ - if (eti->draw_grid){ - gp_draw_rect(context, 0, yd, width, 1); - } - yd--; - - for (row = rows_printed; row < rows; row++){ - gdouble xd = 1, row_height; - - row_height = eti_printed_row_height(eti, widths, context, row); - if (quantize) { - if (yd - row_height - 1 < 0 && row != rows_printed) { - break; - } - } else { - if (yd < 0) { - break; - } - } - - for (col = 0; col < cols; col++){ - ECellView *ecell_view = eti->cell_views [col]; - - if (gnome_print_gsave(context) == -1) - /* FIXME */; - if (gnome_print_translate(context, xd, yd - row_height) == -1) - /* FIXME */; - - if (gnome_print_moveto(context, 0, 0) == -1) - /* FIXME */; - if (gnome_print_lineto(context, widths[col] - 1, 0) == -1) - /* FIXME */; - if (gnome_print_lineto(context, widths[col] - 1, row_height) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 0, row_height) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 0, 0) == -1) - /* FIXME */; - if (gnome_print_clip(context) == -1) - /* FIXME */; - - e_cell_print (ecell_view, context, view_to_model_col(eti, col), col, row, - widths[col] - 1, row_height); - - if (gnome_print_grestore(context) == -1) - /* FIXME */; - - xd += widths[col]; - } - yd -= row_height; - - if (eti->draw_grid){ - gp_draw_rect(context, 0, yd, width, 1); - } - yd--; - } - - itemcontext->rows_printed = row; - - if (eti->draw_grid){ - gdouble xd = 0; - - for (col = 0; col < cols; col++){ - gp_draw_rect(context, xd, height, 1, height - yd); - - xd += widths[col]; - } - gp_draw_rect(context, xd, height, 1, height - yd); - } - - g_free (widths); -} - -static gboolean -e_table_item_data_left (EPrintable *ep, - ETableItemPrintContext *itemcontext) -{ - ETableItem *item = itemcontext->item; - int rows_printed = itemcontext->rows_printed; - - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "data_left"); - return rows_printed < item->rows; -} - -static void -e_table_item_reset (EPrintable *ep, - ETableItemPrintContext *itemcontext) -{ - itemcontext->rows_printed = 0; -} - -static gdouble -e_table_item_height (EPrintable *ep, - GnomePrintContext *context, - gdouble width, - gdouble max_height, - gboolean quantize, - ETableItemPrintContext *itemcontext) -{ - ETableItem *item = itemcontext->item; - const int rows = item->rows; - int rows_printed = itemcontext->rows_printed; - gdouble *widths; - int row; - gdouble yd = 0; - - widths = e_table_item_calculate_print_widths (itemcontext->item->header, width); - - /* - * Draw cells - */ - yd++; - - for (row = rows_printed; row < rows; row++){ - gdouble row_height; - - row_height = eti_printed_row_height(item, widths, context, row); - if (quantize) { - if (max_height != -1 && yd + row_height + 1 > max_height && row != rows_printed) { - break; - } - } else { - if (max_height != -1 && yd > max_height) { - break; - } - } - - yd += row_height; - - yd++; - } - - g_free (widths); - - if (max_height != -1 && (!quantize) && yd > max_height) - yd = max_height; - - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "height"); - return yd; -} - -static gboolean -e_table_item_will_fit (EPrintable *ep, - GnomePrintContext *context, - gdouble width, - gdouble max_height, - gboolean quantize, - ETableItemPrintContext *itemcontext) -{ - ETableItem *item = itemcontext->item; - const int rows = item->rows; - int rows_printed = itemcontext->rows_printed; - gdouble *widths; - int row; - gdouble yd = 0; - gboolean ret_val = TRUE; - - widths = e_table_item_calculate_print_widths (itemcontext->item->header, width); - - /* - * Draw cells - */ - yd++; - - for (row = rows_printed; row < rows; row++){ - gdouble row_height; - - row_height = eti_printed_row_height(item, widths, context, row); - if (quantize) { - if (max_height != -1 && yd + row_height + 1 > max_height && row != rows_printed) { - ret_val = FALSE; - break; - } - } else { - if (max_height != -1 && yd > max_height) { - ret_val = FALSE; - break; - } - } - - yd += row_height; - - yd++; - } - - g_free (widths); - - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "will_fit"); - return ret_val; -} - -static void -e_table_item_printable_destroy (GtkObject *object, - ETableItemPrintContext *itemcontext) -{ - gtk_object_unref(GTK_OBJECT(itemcontext->item)); - g_free(itemcontext); -} - -EPrintable * -e_table_item_get_printable (ETableItem *item) -{ - EPrintable *printable = e_printable_new(); - ETableItemPrintContext *itemcontext; - - itemcontext = g_new(ETableItemPrintContext, 1); - itemcontext->item = item; - gtk_object_ref(GTK_OBJECT(item)); - itemcontext->rows_printed = 0; - - gtk_signal_connect (GTK_OBJECT(printable), - "print_page", - GTK_SIGNAL_FUNC(e_table_item_print_page), - itemcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "data_left", - GTK_SIGNAL_FUNC(e_table_item_data_left), - itemcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "reset", - GTK_SIGNAL_FUNC(e_table_item_reset), - itemcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "height", - GTK_SIGNAL_FUNC(e_table_item_height), - itemcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "will_fit", - GTK_SIGNAL_FUNC(e_table_item_will_fit), - itemcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "destroy", - GTK_SIGNAL_FUNC(e_table_item_printable_destroy), - itemcontext); - - return printable; -} diff --git a/widgets/e-table/e-table-item.h b/widgets/e-table/e-table-item.h deleted file mode 100644 index 2d81bca758..0000000000 --- a/widgets/e-table/e-table-item.h +++ /dev/null @@ -1,143 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_ITEM_H_ -#define _E_TABLE_ITEM_H_ - -#include <libgnomeui/gnome-canvas.h> -#include "e-table-model.h" -#include "e-table-header.h" -#include "e-table-selection-model.h" -#include "e-table-defines.h" -#include <e-util/e-printable.h> - -#define E_TABLE_ITEM_TYPE (e_table_item_get_type ()) -#define E_TABLE_ITEM(o) (GTK_CHECK_CAST ((o), E_TABLE_ITEM_TYPE, ETableItem)) -#define E_TABLE_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_ITEM_TYPE, ETableItemClass)) -#define E_IS_TABLE_ITEM(o) (GTK_CHECK_TYPE ((o), E_TABLE_ITEM_TYPE)) -#define E_IS_TABLE_ITEM_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_ITEM_TYPE)) - -/* list selection modes */ -typedef enum -{ - E_TABLE_CURSOR_LINE, - E_TABLE_CURSOR_SIMPLE, -} ETableCursorMode; - -typedef struct { - GnomeCanvasItem parent; - ETableModel *table_model; - ETableHeader *header; - - ETableModel *source_model; - ETableSelectionModel *selection; - - int x1, y1; - int minimum_width, width, height; - - int cols, rows; - - /* - * Ids for the signals we connect to - */ - int header_dim_change_id; - int header_structure_change_id; - int table_model_pre_change_id; - int table_model_change_id; - int table_model_row_change_id; - int table_model_cell_change_id; - int table_model_row_inserted_id; - int table_model_row_deleted_id; - - int selection_change_id; - int cursor_change_id; - - GdkGC *fill_gc; - GdkGC *grid_gc; - GdkGC *focus_gc; - GdkBitmap *stipple; - - guint draw_grid:1; - guint draw_focus:1; - guint renderers_can_change_size:1; - guint cell_views_realized:1; - - guint needs_redraw : 1; - guint needs_compute_height : 1; - guint needs_compute_width : 1; - - guint uses_source_model : 1; - - /* - * Realized views, per column - */ - ECellView **cell_views; - int n_cells; - - int *height_cache; - int height_cache_idle_id; - int height_cache_idle_count; - - /* - * Lengh Threshold: above this, we stop computing correctly - * the size - */ - int length_threshold; - - gint row_guess; - ETableCursorMode cursor_mode; - - /* - * During editing - */ - int editing_col, editing_row; - void *edit_ctx; - -} ETableItem; - -typedef struct { - GnomeCanvasItemClass parent_class; - - void (*cursor_change) (ETableItem *eti, int row); - void (*double_click) (ETableItem *eti, int row); - gint (*right_click) (ETableItem *eti, int row, int col, GdkEvent *event); - gint (*key_press) (ETableItem *eti, int row, int col, GdkEvent *event); -} ETableItemClass; - -GtkType e_table_item_get_type (void); - - -/* - * Focus - */ -void e_table_item_set_cursor (ETableItem *eti, int col, int row); - -gint e_table_item_get_focused_column (ETableItem *eti); - -/* - * Handling the selection - */ -gboolean e_table_item_is_row_selected (ETableItem *e_table_Item, - int row); - -void e_table_item_selected_row_foreach (ETableItem *eti, - ETableForeachFunc func, - gpointer closure); - -void e_table_item_leave_edit (ETableItem *eti); -void e_table_item_enter_edit (ETableItem *eti, int col, int row); - -void e_table_item_redraw_range (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row); - -EPrintable *e_table_item_get_printable (ETableItem *eti); -void e_table_item_print_height (ETableItem *eti, - GnomePrintContext *context, - gdouble width); -void e_table_item_compute_location (ETableItem *eti, - int *x, - int *y, - int *row, - int *col); - - -#endif /* _E_TABLE_ITEM_H_ */ diff --git a/widgets/e-table/e-table-model.c b/widgets/e-table/e-table-model.c deleted file mode 100644 index d9c0c4fd38..0000000000 --- a/widgets/e-table/e-table-model.c +++ /dev/null @@ -1,354 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-model.c: a Table Model - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-table-model.h" - -#define ETM_CLASS(e) ((ETableModelClass *)((GtkObject *)e)->klass) - -#define PARENT_TYPE gtk_object_get_type () - -#define d(x) - -d(static gint depth = 0); - - -static GtkObjectClass *e_table_model_parent_class; - -enum { - MODEL_CHANGED, - MODEL_PRE_CHANGE, - MODEL_ROW_CHANGED, - MODEL_CELL_CHANGED, - MODEL_ROW_INSERTED, - MODEL_ROW_DELETED, - ROW_SELECTION, - LAST_SIGNAL -}; - -static guint e_table_model_signals [LAST_SIGNAL] = { 0, }; - -int -e_table_model_column_count (ETableModel *e_table_model) -{ - g_return_val_if_fail (e_table_model != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), 0); - - return ETM_CLASS (e_table_model)->column_count (e_table_model); -} - - -int -e_table_model_row_count (ETableModel *e_table_model) -{ - g_return_val_if_fail (e_table_model != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), 0); - - return ETM_CLASS (e_table_model)->row_count (e_table_model); -} - -void * -e_table_model_value_at (ETableModel *e_table_model, int col, int row) -{ - g_return_val_if_fail (e_table_model != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - return ETM_CLASS (e_table_model)->value_at (e_table_model, col, row); -} - -void -e_table_model_set_value_at (ETableModel *e_table_model, int col, int row, const void *data) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - ETM_CLASS (e_table_model)->set_value_at (e_table_model, col, row, data); -} - -gboolean -e_table_model_is_cell_editable (ETableModel *e_table_model, int col, int row) -{ - g_return_val_if_fail (e_table_model != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), FALSE); - - return ETM_CLASS (e_table_model)->is_cell_editable (e_table_model, col, row); -} - -void -e_table_model_append_row (ETableModel *e_table_model, ETableModel *source, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - if (ETM_CLASS (e_table_model)->append_row) - ETM_CLASS (e_table_model)->append_row (e_table_model, source, row); -} - -void * -e_table_model_duplicate_value (ETableModel *e_table_model, int col, const void *value) -{ - g_return_val_if_fail (e_table_model != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - if (ETM_CLASS (e_table_model)->duplicate_value) - return ETM_CLASS (e_table_model)->duplicate_value (e_table_model, col, value); - else - return NULL; -} - -void -e_table_model_free_value (ETableModel *e_table_model, int col, void *value) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - if (ETM_CLASS (e_table_model)->free_value) - ETM_CLASS (e_table_model)->free_value (e_table_model, col, value); -} - -void * -e_table_model_initialize_value (ETableModel *e_table_model, int col) -{ - g_return_val_if_fail (e_table_model != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - if (ETM_CLASS (e_table_model)->initialize_value) - return ETM_CLASS (e_table_model)->initialize_value (e_table_model, col); - else - return NULL; -} - -gboolean -e_table_model_value_is_empty (ETableModel *e_table_model, int col, const void *value) -{ - g_return_val_if_fail (e_table_model != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), FALSE); - - if (ETM_CLASS (e_table_model)->value_is_empty) - return ETM_CLASS (e_table_model)->value_is_empty (e_table_model, col, value); - else - return FALSE; -} - -char * -e_table_model_value_to_string (ETableModel *e_table_model, int col, const void *value) -{ - g_return_val_if_fail (e_table_model != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - if (ETM_CLASS (e_table_model)->value_to_string) - return ETM_CLASS (e_table_model)->value_to_string (e_table_model, col, value); - else - return g_strdup(""); -} - -static void -e_table_model_destroy (GtkObject *object) -{ - if (e_table_model_parent_class->destroy) - (*e_table_model_parent_class->destroy)(object); -} - -static void -e_table_model_class_init (GtkObjectClass *object_class) -{ - ETableModelClass *klass = E_TABLE_MODEL_CLASS(object_class); - e_table_model_parent_class = gtk_type_class (PARENT_TYPE); - - object_class->destroy = e_table_model_destroy; - - e_table_model_signals [MODEL_CHANGED] = - gtk_signal_new ("model_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_table_model_signals [MODEL_PRE_CHANGE] = - gtk_signal_new ("model_pre_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_pre_change), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_table_model_signals [MODEL_ROW_CHANGED] = - gtk_signal_new ("model_row_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_row_changed), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - e_table_model_signals [MODEL_CELL_CHANGED] = - gtk_signal_new ("model_cell_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_cell_changed), - gtk_marshal_NONE__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); - - e_table_model_signals [MODEL_ROW_INSERTED] = - gtk_signal_new ("model_row_inserted", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_row_inserted), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - e_table_model_signals [MODEL_ROW_DELETED] = - gtk_signal_new ("model_row_deleted", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_row_deleted), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, e_table_model_signals, LAST_SIGNAL); - - klass->column_count = NULL; - klass->row_count = NULL; - klass->value_at = NULL; - klass->set_value_at = NULL; - klass->is_cell_editable = NULL; - klass->append_row = NULL; - - klass->duplicate_value = NULL; - klass->free_value = NULL; - klass->initialize_value = NULL; - klass->value_is_empty = NULL; - klass->value_to_string = NULL; - klass->model_changed = NULL; - klass->model_row_changed = NULL; - klass->model_cell_changed = NULL; - klass->model_row_inserted = NULL; - klass->model_row_deleted = NULL; -} - - -guint -e_table_model_get_type (void) -{ - static guint type = 0; - - if (!type) - { - GtkTypeInfo info = - { - "ETableModel", - sizeof (ETableModel), - sizeof (ETableModelClass), - (GtkClassInitFunc) e_table_model_class_init, - NULL, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - type = gtk_type_unique (PARENT_TYPE, &info); - } - - return type; -} - -#if d(!)0 -static void -print_tabs (void) -{ - int i; - for (i = 0; i < depth; i++) - g_print("\t"); -} -#endif - -void -e_table_model_pre_change (ETableModel *e_table_model) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - d(print_tabs()); - d(g_print("Emitting pre_change on model 0x%p.\n", e_table_model)); - d(depth++); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_PRE_CHANGE]); - d(depth--); -} - -void -e_table_model_changed (ETableModel *e_table_model) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - d(print_tabs()); - d(g_print("Emitting model_changed on model 0x%p.\n", e_table_model)); - d(depth++); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_CHANGED]); - d(depth--); -} - -void -e_table_model_row_changed (ETableModel *e_table_model, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - d(print_tabs()); - d(g_print("Emitting row_changed on model 0x%p, row %d.\n", e_table_model, row)); - d(depth++); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_ROW_CHANGED], row); - d(depth--); -} - -void -e_table_model_cell_changed (ETableModel *e_table_model, int col, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - d(print_tabs()); - d(g_print("Emitting cell_changed on model 0x%p, row %d, col %d.\n", e_table_model, row, col)); - d(depth++); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_CELL_CHANGED], col, row); - d(depth--); -} - -void -e_table_model_row_inserted (ETableModel *e_table_model, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - d(print_tabs()); - d(g_print("Emitting row_inserted on model 0x%p, row %d.\n", e_table_model, row)); - d(depth++); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_ROW_INSERTED], row); - d(depth--); -} - -void -e_table_model_row_deleted (ETableModel *e_table_model, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - d(print_tabs()); - d(g_print("Emitting row_deleted on model 0x%p, row %d.\n", e_table_model, row)); - d(depth++); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_ROW_DELETED], row); - d(depth--); -} diff --git a/widgets/e-table/e-table-model.h b/widgets/e-table/e-table-model.h deleted file mode 100644 index d4fae1659e..0000000000 --- a/widgets/e-table/e-table-model.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_MODEL_H_ -#define _E_TABLE_MODEL_H_ - -#include <gtk/gtkobject.h> - -#define E_TABLE_MODEL_TYPE (e_table_model_get_type ()) -#define E_TABLE_MODEL(o) (GTK_CHECK_CAST ((o), E_TABLE_MODEL_TYPE, ETableModel)) -#define E_TABLE_MODEL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_MODEL_TYPE, ETableModelClass)) -#define E_IS_TABLE_MODEL(o) (GTK_CHECK_TYPE ((o), E_TABLE_MODEL_TYPE)) -#define E_IS_TABLE_MODEL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_MODEL_TYPE)) - -typedef struct { - GtkObject base; -} ETableModel; - -typedef struct { - GtkObjectClass parent_class; - - /* - * Virtual methods - */ - int (*column_count) (ETableModel *etm); - int (*row_count) (ETableModel *etm); - void *(*value_at) (ETableModel *etm, int col, int row); - void (*set_value_at) (ETableModel *etm, int col, int row, const void *value); - gboolean (*is_cell_editable) (ETableModel *etm, int col, int row); - void (*append_row) (ETableModel *etm, ETableModel *source, int row); - - /* Allocate a copy of the given value. */ - void *(*duplicate_value) (ETableModel *etm, int col, const void *value); - /* Free an allocated value. */ - void (*free_value) (ETableModel *etm, int col, void *value); - /* Return an allocated empty value. */ - void *(*initialize_value) (ETableModel *etm, int col); - /* Return TRUE if value is equivalent to an empty cell. */ - gboolean (*value_is_empty) (ETableModel *etm, int col, const void *value); - /* Return an allocated string. */ - char *(*value_to_string) (ETableModel *etm, int col, const void *value); - - /* - * Signals - */ - - /* - * These all come after the change has been made. - * Major structural changes: model_changed - * Changes only in a row: row_changed - * Only changes in a cell: cell_changed - * A row inserted: row_inserted - * A row deleted: row_deleted - */ - void (*model_pre_change) (ETableModel *etm); - - void (*model_changed) (ETableModel *etm); - void (*model_row_changed) (ETableModel *etm, int row); - void (*model_cell_changed) (ETableModel *etm, int col, int row); - void (*model_row_inserted) (ETableModel *etm, int row); - void (*model_row_deleted) (ETableModel *etm, int row); -} ETableModelClass; - -GtkType e_table_model_get_type (void); - -int e_table_model_column_count (ETableModel *e_table_model); -const char *e_table_model_column_name (ETableModel *e_table_model, int col); -int e_table_model_row_count (ETableModel *e_table_model); -void *e_table_model_value_at (ETableModel *e_table_model, int col, int row); -void e_table_model_set_value_at (ETableModel *e_table_model, int col, int row, const void *value); -gboolean e_table_model_is_cell_editable (ETableModel *e_table_model, int col, int row); -void e_table_model_append_row (ETableModel *e_table_model, ETableModel *source, int row); - -void *e_table_model_duplicate_value (ETableModel *e_table_model, int col, const void *value); -void e_table_model_free_value (ETableModel *e_table_model, int col, void *value); -void *e_table_model_initialize_value (ETableModel *e_table_model, int col); -gboolean e_table_model_value_is_empty (ETableModel *e_table_model, int col, const void *value); -char *e_table_model_value_to_string (ETableModel *e_table_model, int col, const void *value); - -/* - * Routines for emitting signals on the e_table - */ -void e_table_model_pre_change (ETableModel *e_table_model); -void e_table_model_changed (ETableModel *e_table_model); -void e_table_model_row_changed (ETableModel *e_table_model, int row); -void e_table_model_cell_changed (ETableModel *e_table_model, int col, int row); -void e_table_model_row_inserted (ETableModel *e_table_model, int row); -void e_table_model_row_deleted (ETableModel *e_table_model, int row); - -#endif /* _E_TABLE_MODEL_H_ */ diff --git a/widgets/e-table/e-table-one.c b/widgets/e-table/e-table-one.c deleted file mode 100644 index 40c24517f8..0000000000 --- a/widgets/e-table/e-table-one.c +++ /dev/null @@ -1,236 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-model.c: a one table model implementation that uses function - * pointers to simplify the creation of new, exotic and colorful tables in - * no time. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ - -#include <config.h> -#include "e-table-one.h" - -#define PARENT_TYPE e_table_model_get_type () - -static int -one_column_count (ETableModel *etm) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - return e_table_model_column_count(one->source); - else - return 0; -} - -static int -one_row_count (ETableModel *etm) -{ - return 1; -} - -static void * -one_value_at (ETableModel *etm, int col, int row) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->data) - return one->data[col]; - else - return NULL; -} - -static void -one_set_value_at (ETableModel *etm, int col, int row, const void *val) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->data && one->source) { - e_table_model_free_value(one->source, col, one->data[col]); - one->data[col] = e_table_model_duplicate_value(one->source, col, val); - } -} - -static gboolean -one_is_cell_editable (ETableModel *etm, int col, int row) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - return e_table_model_is_cell_editable(one->source, 0, row); - else - return FALSE; -} - -/* The default for one_duplicate_value is to return the raw value. */ -static void * -one_duplicate_value (ETableModel *etm, int col, const void *value) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - return e_table_model_duplicate_value(one->source, col, value); - else - return (void *)value; -} - -static void -one_free_value (ETableModel *etm, int col, void *value) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - e_table_model_free_value(one->source, col, value); -} - -static void * -one_initialize_value (ETableModel *etm, int col) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - return e_table_model_initialize_value (one->source, col); - else - return NULL; -} - -static gboolean -one_value_is_empty (ETableModel *etm, int col, const void *value) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - return e_table_model_value_is_empty (one->source, col, value); - else - return FALSE; -} - -static char * -one_value_to_string (ETableModel *etm, int col, const void *value) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - return e_table_model_value_to_string (one->source, col, value); - else - return g_strdup(""); -} - -static void -one_destroy (GtkObject *object) -{ - ETableOne *one = E_TABLE_ONE(object); - - if (one->source) { - int i; - int col_count; - - col_count = e_table_model_column_count(one->source); - - if (one->data) { - for (i = 0; i < col_count; i++) { - e_table_model_free_value(one->source, i, one->data[i]); - } - } - - gtk_object_unref(GTK_OBJECT(one->source)); - } - - g_free(one->data); -} - -static void -e_table_one_class_init (GtkObjectClass *object_class) -{ - ETableModelClass *model_class = (ETableModelClass *) object_class; - - model_class->column_count = one_column_count; - model_class->row_count = one_row_count; - model_class->value_at = one_value_at; - model_class->set_value_at = one_set_value_at; - model_class->is_cell_editable = one_is_cell_editable; - model_class->duplicate_value = one_duplicate_value; - model_class->free_value = one_free_value; - model_class->initialize_value = one_initialize_value; - model_class->value_is_empty = one_value_is_empty; - model_class->value_to_string = one_value_to_string; - - object_class->destroy = one_destroy; -} - -static void -e_table_one_init (GtkObject *object) -{ - ETableOne *one = E_TABLE_ONE(object); - - one->source = NULL; - one->data = NULL; -} - -GtkType -e_table_one_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableOne", - sizeof (ETableOne), - sizeof (ETableOneClass), - (GtkClassInitFunc) e_table_one_class_init, - (GtkObjectInitFunc) e_table_one_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_TYPE, &info); - } - - return type; -} - -ETableModel * -e_table_one_new (ETableModel *source) -{ - ETableOne *eto; - int col_count; - int i; - - eto = gtk_type_new (e_table_one_get_type ()); - - eto->source = source; - - col_count = e_table_model_column_count(source); - eto->data = g_new(void *, col_count); - for (i = 0; i < col_count; i++) { - eto->data[i] = e_table_model_initialize_value(source, i); - } - - if (source) - gtk_object_ref(GTK_OBJECT(source)); - - return (ETableModel *) eto; -} - -void -e_table_one_commit (ETableOne *one) -{ - if (one->source) { - int empty = TRUE; - int col; - int cols = e_table_model_column_count(one->source); - for (col = 0; col < cols; col++) { - if (!e_table_model_value_is_empty(one->source, col, one->data[col])) { - empty = FALSE; - break; - } - } - if (!empty) { - e_table_model_append_row(one->source, E_TABLE_MODEL(one), 0); - } - } -} diff --git a/widgets/e-table/e-table-one.h b/widgets/e-table/e-table-one.h deleted file mode 100644 index c6958cee3a..0000000000 --- a/widgets/e-table/e-table-one.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_ONE_H_ -#define _E_TABLE_ONE_H_ - -#include "e-table-model.h" - -#define E_TABLE_ONE_TYPE (e_table_one_get_type ()) -#define E_TABLE_ONE(o) (GTK_CHECK_CAST ((o), E_TABLE_ONE_TYPE, ETableOne)) -#define E_TABLE_ONE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_ONE_TYPE, ETableOneClass)) -#define E_IS_TABLE_ONE(o) (GTK_CHECK_TYPE ((o), E_TABLE_ONE_TYPE)) -#define E_IS_TABLE_ONE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_ONE_TYPE)) - -typedef struct { - ETableModel parent; - - ETableModel *source; - void **data; -} ETableOne; - -typedef struct { - ETableModelClass parent_class; -} ETableOneClass; - -GtkType e_table_one_get_type (void); - -ETableModel *e_table_one_new (ETableModel *source); -void e_table_one_commit (ETableOne *one); - -#endif /* _E_TABLE_ONE_H_ */ - diff --git a/widgets/e-table/e-table-scrolled.c b/widgets/e-table/e-table-scrolled.c deleted file mode 100644 index f70ca5320a..0000000000 --- a/widgets/e-table/e-table-scrolled.c +++ /dev/null @@ -1,341 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-scrolled.c: A graphical view of a Table. - * - * Author: - * Chris Lahey <clahey@helixcode.com> - * Miguel de Icaza (miguel@helixcode.com) - * - * Copyright 2000, 1999, Helix Code, Inc - */ -#include <config.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <stdio.h> -#include <libgnomeui/gnome-canvas.h> -#include <gtk/gtksignal.h> -#include <gnome-xml/parser.h> -#include <gnome-xml/xmlmemory.h> - -#include "e-table.h" -#include "e-table-scrolled.h" - -#define COLUMN_HEADER_HEIGHT 16 - -#define PARENT_TYPE e_scroll_frame_get_type () - -static GtkObjectClass *parent_class; - -enum { - CURSOR_CHANGE, - DOUBLE_CLICK, - RIGHT_CLICK, - KEY_PRESS, - LAST_SIGNAL -}; - -enum { - ARG_0, - ARG_TABLE_DRAW_GRID, - ARG_TABLE_DRAW_FOCUS, - ARG_CURSOR_MODE, - ARG_LENGTH_THRESHOLD, - ARG_CLICK_TO_ADD_MESSAGE, -}; - -static gint ets_signals [LAST_SIGNAL] = { 0, }; - -static void -cursor_change_proxy (ETable *et, int row, ETableScrolled *ets) -{ - gtk_signal_emit (GTK_OBJECT (ets), - ets_signals [CURSOR_CHANGE], - row); -} - -static void -double_click_proxy (ETable *et, int row, ETableScrolled *ets) -{ - gtk_signal_emit (GTK_OBJECT (ets), - ets_signals [DOUBLE_CLICK], - row); -} - -static gint -right_click_proxy (ETable *et, int row, int col, GdkEvent *event, ETableScrolled *ets) -{ - int return_val = 0; - gtk_signal_emit (GTK_OBJECT (ets), - ets_signals [RIGHT_CLICK], - row, col, event, &return_val); - return return_val; -} - -static gint -key_press_proxy (ETable *et, int row, int col, GdkEvent *event, ETableScrolled *ets) -{ - int return_val; - gtk_signal_emit (GTK_OBJECT (ets), - ets_signals [KEY_PRESS], - row, col, event, &return_val); - return return_val; -} - -static void -e_table_scrolled_init (GtkObject *object) -{ - ETableScrolled *ets; - EScrollFrame *scroll_frame; - - ets = E_TABLE_SCROLLED (object); - scroll_frame = E_SCROLL_FRAME (object); - - ets->table = gtk_type_new(e_table_get_type()); - - e_scroll_frame_set_policy (scroll_frame, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - e_scroll_frame_set_shadow_type (scroll_frame, GTK_SHADOW_IN); -} - -static void -e_table_scrolled_real_construct (ETableScrolled *ets) -{ - gtk_object_set(GTK_OBJECT(ets), - "shadow_type", GTK_SHADOW_IN, - "hscrollbar_policy", GTK_POLICY_NEVER, - "vscrollbar_policy", GTK_POLICY_AUTOMATIC, - NULL); - - gtk_container_add(GTK_CONTAINER(ets), GTK_WIDGET(ets->table)); - - gtk_signal_connect(GTK_OBJECT(ets->table), "cursor_change", - GTK_SIGNAL_FUNC(cursor_change_proxy), ets); - gtk_signal_connect(GTK_OBJECT(ets->table), "double_click", - GTK_SIGNAL_FUNC(double_click_proxy), ets); - gtk_signal_connect(GTK_OBJECT(ets->table), "right_click", - GTK_SIGNAL_FUNC(right_click_proxy), ets); - gtk_signal_connect(GTK_OBJECT(ets->table), "key_press", - GTK_SIGNAL_FUNC(key_press_proxy), ets); - - gtk_widget_show(GTK_WIDGET(ets->table)); -} - -ETableScrolled * -e_table_scrolled_construct (ETableScrolled *ets, ETableHeader *full_header, - ETableModel *etm, const char *spec) -{ - e_table_construct(ets->table, full_header, etm, spec); - - e_table_scrolled_real_construct(ets); - - return ets; -} - -ETableScrolled * -e_table_scrolled_construct_from_spec_file (ETableScrolled *ets, ETableHeader *full_header, ETableModel *etm, - const char *filename) -{ - e_table_construct_from_spec_file(ets->table, full_header, etm, filename); - - e_table_scrolled_real_construct(ets); - - return ets; -} - -GtkWidget * -e_table_scrolled_new (ETableHeader *full_header, ETableModel *etm, const char *spec) -{ - ETableScrolled *ets; - - ets = E_TABLE_SCROLLED (gtk_widget_new (e_table_scrolled_get_type (), - "hadjustment", NULL, - "vadjustment", NULL, - NULL)); - - ets = e_table_scrolled_construct (ets, full_header, etm, spec); - - return GTK_WIDGET (ets); -} - -GtkWidget * -e_table_scrolled_new_from_spec_file (ETableHeader *full_header, ETableModel *etm, const char *filename) -{ - ETableScrolled *ets; - - ets = gtk_type_new (e_table_scrolled_get_type ()); - - ets = e_table_scrolled_construct_from_spec_file (ets, full_header, etm, filename); - - return GTK_WIDGET (ets); -} - -gchar * -e_table_scrolled_get_specification (ETableScrolled *ets) -{ - return e_table_get_specification(ets->table); -} - -void -e_table_scrolled_save_specification (ETableScrolled *ets, gchar *filename) -{ - e_table_save_specification(ets->table, filename); -} - -void -e_table_scrolled_set_cursor_row (ETableScrolled *ets, int row) -{ - e_table_set_cursor_row(ets->table, row); -} - -int -e_table_scrolled_get_cursor_row (ETableScrolled *ets) -{ - return e_table_get_cursor_row(ets->table); -} - -void -e_table_scrolled_selected_row_foreach (ETableScrolled *ets, - ETableForeachFunc callback, - gpointer closure) -{ - e_table_selected_row_foreach(ets->table, - callback, - closure); -} - -EPrintable * -e_table_scrolled_get_printable (ETableScrolled *ets) -{ - return e_table_get_printable(ets->table); -} - -static void -ets_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableScrolled *ets = E_TABLE_SCROLLED (o); - gboolean bool_val; - gchar *string_val; - - switch (arg_id){ - case ARG_TABLE_DRAW_GRID: - gtk_object_get(GTK_OBJECT(ets->table), - "drawgrid", &bool_val, - NULL); - GTK_VALUE_BOOL (*arg) = bool_val; - break; - - case ARG_TABLE_DRAW_FOCUS: - gtk_object_get(GTK_OBJECT(ets->table), - "drawfocus", &bool_val, - NULL); - GTK_VALUE_BOOL (*arg) = bool_val; - break; - - case ARG_CLICK_TO_ADD_MESSAGE: - gtk_object_get(GTK_OBJECT(ets->table), - "click_to_add_message", &string_val, - NULL); - GTK_VALUE_STRING (*arg) = string_val; - break; - } -} - -static void -ets_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableScrolled *ets = E_TABLE_SCROLLED (o); - - switch (arg_id){ - case ARG_LENGTH_THRESHOLD: - gtk_object_set(GTK_OBJECT(ets->table), - "length_threshold", GTK_VALUE_INT (*arg), - NULL); - break; - - case ARG_TABLE_DRAW_GRID: - gtk_object_set(GTK_OBJECT(ets->table), - "drawgrid", GTK_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_TABLE_DRAW_FOCUS: - gtk_object_set(GTK_OBJECT(ets->table), - "drawfocus", GTK_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_CURSOR_MODE: - gtk_object_set(GTK_OBJECT(ets->table), - "cursor_mode", GTK_VALUE_INT (*arg), - NULL); - break; - case ARG_CLICK_TO_ADD_MESSAGE: - gtk_object_set(GTK_OBJECT(ets->table), - "click_to_add_message", GTK_VALUE_STRING (*arg), - NULL); - break; - } -} - -static void -e_table_scrolled_class_init (GtkObjectClass *object_class) -{ - ETableScrolledClass *klass = E_TABLE_SCROLLED_CLASS(object_class); - parent_class = gtk_type_class (PARENT_TYPE); - - object_class->set_arg = ets_set_arg; - object_class->get_arg = ets_get_arg; - - klass->cursor_change = NULL; - klass->double_click = NULL; - klass->right_click = NULL; - klass->key_press = NULL; - - ets_signals [CURSOR_CHANGE] = - gtk_signal_new ("cursor_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableScrolledClass, cursor_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - ets_signals [DOUBLE_CLICK] = - gtk_signal_new ("double_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableScrolledClass, double_click), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - ets_signals [RIGHT_CLICK] = - gtk_signal_new ("right_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableScrolledClass, right_click), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - ets_signals [KEY_PRESS] = - gtk_signal_new ("key_press", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableScrolledClass, key_press), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - gtk_object_class_add_signals (object_class, ets_signals, LAST_SIGNAL); - - gtk_object_add_arg_type ("ETableScrolled::drawgrid", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_TABLE_DRAW_GRID); - gtk_object_add_arg_type ("ETableScrolled::drawfocus", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_TABLE_DRAW_FOCUS); - gtk_object_add_arg_type ("ETableScrolled::cursor_mode", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_CURSOR_MODE); - gtk_object_add_arg_type ("ETableScrolled::length_threshold", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_LENGTH_THRESHOLD); - gtk_object_add_arg_type ("ETableScrolled::click_to_add_message", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_CLICK_TO_ADD_MESSAGE); -} - -E_MAKE_TYPE(e_table_scrolled, "ETableScrolled", ETableScrolled, e_table_scrolled_class_init, e_table_scrolled_init, PARENT_TYPE); - diff --git a/widgets/e-table/e-table-scrolled.h b/widgets/e-table/e-table-scrolled.h deleted file mode 100644 index d5a0c06a58..0000000000 --- a/widgets/e-table/e-table-scrolled.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SCROLLED_H_ -#define _E_TABLE_SCROLLED_H_ - -#include "widgets/misc/e-scroll-frame.h" -#include "e-table-model.h" -#include "e-table-header.h" -#include "e-table.h" -#include "e-util/e-printable.h" - -BEGIN_GNOME_DECLS - -#define E_TABLE_SCROLLED_TYPE (e_table_scrolled_get_type ()) -#define E_TABLE_SCROLLED(o) (GTK_CHECK_CAST ((o), E_TABLE_SCROLLED_TYPE, ETableScrolled)) -#define E_TABLE_SCROLLED_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SCROLLED_TYPE, ETableScrolledClass)) -#define E_IS_SCROLLED_TABLE(o) (GTK_CHECK_TYPE ((o), E_TABLE_SCROLLED_TYPE)) -#define E_IS_SCROLLED_TABLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SCROLLED_TYPE)) - -typedef struct { - EScrollFrame parent; - - ETable *table; -} ETableScrolled; - -typedef struct { - EScrollFrameClass parent_class; - - void (*cursor_change) (ETableScrolled *est, int row); - void (*double_click) (ETableScrolled *est, int row); - gint (*right_click) (ETableScrolled *est, int row, int col, GdkEvent *event); - gint (*key_press) (ETableScrolled *est, int row, int col, GdkEvent *event); -} ETableScrolledClass; - -GtkType e_table_scrolled_get_type (void); - -ETableScrolled *e_table_scrolled_construct (ETableScrolled *ets, ETableHeader *full_header, ETableModel *etm, - const char *spec); -GtkWidget *e_table_scrolled_new (ETableHeader *full_header, ETableModel *etm, - const char *spec); - -ETableScrolled *e_table_scrolled_construct_from_spec_file (ETableScrolled *e_table_scrolled, - ETableHeader *full_header, - ETableModel *etm, - const char *filename); -GtkWidget *e_table_scrolled_new_from_spec_file (ETableHeader *full_header, - ETableModel *etm, - const char *filename); - -gchar *e_table_scrolled_get_specification (ETableScrolled *e_table_scrolled); -void e_table_scrolled_save_specification (ETableScrolled *e_table_scrolled, gchar *filename); - -void e_table_scrolled_set_cursor_row (ETableScrolled *e_table_scrolled, - int row); -/* -1 means we don't have the cursor. */ -int e_table_scrolled_get_cursor_row (ETableScrolled *e_table_scrolled); -void e_table_scrolled_selected_row_foreach (ETableScrolled *e_table_scrolled, - ETableForeachFunc callback, - gpointer closure); -EPrintable *e_table_scrolled_get_printable (ETableScrolled *e_table_scrolled); - -END_GNOME_DECLS - -#endif /* _E_TABLE_SCROLLED_H_ */ - diff --git a/widgets/e-table/e-table-selection-model.c b/widgets/e-table/e-table-selection-model.c deleted file mode 100644 index 9079ce8623..0000000000 --- a/widgets/e-table/e-table-selection-model.c +++ /dev/null @@ -1,500 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-selection-model.c: a Table Selection Model - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-table-selection-model.h" -#include "e-util/e-util.h" - -#define ETSM_CLASS(e) ((ETableSelectionModelClass *)((GtkObject *)e)->klass) - -#define PARENT_TYPE gtk_object_get_type () - -#define ONES ((guint32) 0xffffffff) - -#define BOX(n) ((n) / 32) -#define OFFSET(n) (31 - ((n) % 32)) -#define BITMASK(n) ((guint32)(((guint32) 0x1) << OFFSET(n))) -#define BITMASK_LEFT(n) ((guint32)(((guint32) ONES) << (32 - ((n) % 32)))) -#define BITMASK_RIGHT(n) ((guint32)(((guint32) ONES) >> ((n) % 32))) - -static GtkObjectClass *e_table_selection_model_parent_class; - -enum { - CURSOR_CHANGED, - SELECTION_CHANGED, - LAST_SIGNAL -}; - -static guint e_table_selection_model_signals [LAST_SIGNAL] = { 0, }; - -enum { - ARG_0, - ARG_MODEL, - ARG_SORTER, - ARG_CURSOR_ROW, - ARG_CURSOR_COL, -}; - -static void -model_changed(ETableModel *etm, ETableSelectionModel *etsm) -{ - e_table_selection_model_clear(etsm); -} - -#if 0 -static void -model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm) -{ - int box; - int i; - if(etsm->row_count >= 0) { - /* Add another word if needed. */ - if ((etsm->row_count & 0x1f) == 0) { - etsm->selection = g_renew(etsm->selection, gint, (etsm->row_count >> 5) + 1); - etsm->selection[etsm->row_count >> 5] = 0; - } - - /* The box is the word that our row is in. */ - box = BOX(row); - /* Shift all words to the right of our box right one bit. */ - for (i = etsm->row_count >> 5; i > box; i--) { - etsm->selection[i] = (etsm->selection[i] >> 1) | (etsm->selection[i - 1] << 31); - } - - /* Shift right half of box one bit to the right. */ - etsm->selection[box] = (etsm->selection[box] & BITMASK_LEFT(row)) | ((etsm->selection[box] & BITMASK_RIGHT(row)) >> 1); - etsm->row_count ++; - } -} - -static void -model_row_deleted(ETableModel *etm, int row, ETableSelectionModel *etsm) -{ - int box; - int i; - int last; - if(etsm->row_count >= 0) { - guint32 bitmask; - box = row >> 5; - last = etsm->row_count >> 5; - - /* Build bitmasks for the left and right half of the box */ - bitmask = BITMASK_RIGHT(row) >> 1; - /* Shift right half of box one bit to the left. */ - etsm->selection[box] = (etsm->selection[box] & BITMASK_LEFT(row))| ((etsm->selection[box] & bitmask) << 1); - - /* Shift all words to the right of our box left one bit. */ - if (box < last) { - etsm->selection[box] &= etsm->selection[box + 1] >> 31; - - for (i = box + 1; i < last; i++) { - etsm->selection[i] = (etsm->selection[i] << 1) | (etsm->selection[i + 1] >> 31); - } - etsm->selection[i] = etsm->selection[i] << 1; - } - etsm->row_count --; - /* Remove the last word if not needed. */ - if ((etsm->row_count & 0x1f) == 0) { - etsm->selection = g_renew(etsm->selection, gint, etsm->row_count >> 5); - } - } -} - -#else - -static void -model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm) -{ - model_changed(etm, etsm); -} - -static void -model_row_deleted(ETableModel *etm, int row, ETableSelectionModel *etsm) -{ - model_changed(etm, etsm); -} -#endif - -inline static void -add_model(ETableSelectionModel *etsm, ETableModel *model) -{ - etsm->model = model; - if (model) { - gtk_object_ref(GTK_OBJECT(model)); - etsm->model_changed_id = gtk_signal_connect(GTK_OBJECT(model), "model_changed", - GTK_SIGNAL_FUNC(model_changed), etsm); - etsm->model_row_inserted_id = gtk_signal_connect(GTK_OBJECT(model), "model_row_inserted", - GTK_SIGNAL_FUNC(model_row_inserted), etsm); - etsm->model_row_deleted_id = gtk_signal_connect(GTK_OBJECT(model), "model_row_deleted", - GTK_SIGNAL_FUNC(model_row_deleted), etsm); - } -} - -inline static void -drop_model(ETableSelectionModel *etsm) -{ - if (etsm->model) { - gtk_signal_disconnect(GTK_OBJECT(etsm->model), - etsm->model_changed_id); - gtk_signal_disconnect(GTK_OBJECT(etsm->model), - etsm->model_row_inserted_id); - gtk_signal_disconnect(GTK_OBJECT(etsm->model), - etsm->model_row_deleted_id); - gtk_object_unref(GTK_OBJECT(etsm->model)); - } - etsm->model = NULL; -} - -inline static void -add_sorter(ETableSelectionModel *etsm, ETableSorter *sorter) -{ - etsm->sorter = sorter; - if (sorter) { - gtk_object_ref(GTK_OBJECT(sorter)); - } -} - -inline static void -drop_sorter(ETableSelectionModel *etsm) -{ - if (etsm->sorter) { - gtk_object_unref(GTK_OBJECT(etsm->sorter)); - } - etsm->sorter = NULL; -} - -static void -etsm_destroy (GtkObject *object) -{ - ETableSelectionModel *etsm; - - etsm = E_TABLE_SELECTION_MODEL (object); - - drop_model(etsm); - drop_sorter(etsm); - - g_free(etsm->selection); -} - -static void -etsm_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableSelectionModel *etsm = E_TABLE_SELECTION_MODEL (o); - - switch (arg_id){ - case ARG_MODEL: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etsm->model); - break; - - case ARG_SORTER: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etsm->sorter); - break; - - case ARG_CURSOR_ROW: - GTK_VALUE_INT(*arg) = etsm->cursor_row; - break; - - case ARG_CURSOR_COL: - GTK_VALUE_INT(*arg) = etsm->cursor_col; - break; - } -} - -static void -etsm_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableSelectionModel *etsm = E_TABLE_SELECTION_MODEL (o); - - switch (arg_id){ - case ARG_MODEL: - drop_model(etsm); - add_model(etsm, GTK_VALUE_OBJECT (*arg) ? E_TABLE_MODEL(GTK_VALUE_OBJECT (*arg)) : NULL); - break; - - case ARG_SORTER: - drop_sorter(etsm); - add_sorter(etsm, GTK_VALUE_OBJECT (*arg) ? E_TABLE_SORTER(GTK_VALUE_OBJECT (*arg)) : NULL); - break; - - case ARG_CURSOR_ROW: - e_table_selection_model_do_something(etsm, GTK_VALUE_INT(*arg), etsm->cursor_col, 0); - break; - - case ARG_CURSOR_COL: - e_table_selection_model_do_something(etsm, etsm->cursor_row, GTK_VALUE_INT(*arg), 0); - break; - } -} - -static void -e_table_selection_model_init (ETableSelectionModel *selection) -{ - selection->selection = NULL; - selection->row_count = -1; - selection->model = NULL; -} - -static void -e_table_selection_model_class_init (ETableSelectionModelClass *klass) -{ - GtkObjectClass *object_class; - - e_table_selection_model_parent_class = gtk_type_class (gtk_object_get_type ()); - - object_class = GTK_OBJECT_CLASS(klass); - - object_class->destroy = etsm_destroy; - object_class->get_arg = etsm_get_arg; - object_class->set_arg = etsm_set_arg; - - e_table_selection_model_signals [CURSOR_CHANGED] = - gtk_signal_new ("cursor_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableSelectionModelClass, cursor_changed), - gtk_marshal_NONE__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); - - e_table_selection_model_signals [SELECTION_CHANGED] = - gtk_signal_new ("selection_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableSelectionModelClass, selection_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - klass->cursor_changed = NULL; - klass->selection_changed = NULL; - - gtk_object_class_add_signals (object_class, e_table_selection_model_signals, LAST_SIGNAL); - - gtk_object_add_arg_type ("ETableSelectionModel::model", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_MODEL); - gtk_object_add_arg_type ("ETableSelectionModel::sorter", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_SORTER); - gtk_object_add_arg_type ("ETableSelectionModel::cursor_row", GTK_TYPE_INT, - GTK_ARG_READWRITE, ARG_CURSOR_ROW); - gtk_object_add_arg_type ("ETableSelectionModel::cursor_col", GTK_TYPE_INT, - GTK_ARG_READWRITE, ARG_CURSOR_COL); -} - -E_MAKE_TYPE(e_table_selection_model, "ETableSelectionModel", ETableSelectionModel, - e_table_selection_model_class_init, e_table_selection_model_init, PARENT_TYPE); - -ETableSelectionModel * -e_table_selection_model_new (void) -{ - return gtk_type_new (e_table_selection_model_get_type ()); -} - -gboolean -e_table_selection_model_is_row_selected (ETableSelectionModel *selection, - gint n) -{ - if (selection->row_count < n) - return 0; - else - return (selection->selection[BOX(n)] >> OFFSET(n)) & 0x1; -} - -void -e_table_selection_model_foreach (ETableSelectionModel *selection, - ETableForeachFunc callback, - gpointer closure) -{ - int i; - int last = (selection->row_count + 31) / 32; - for (i = 0; i < last; i++) { - if (selection->selection[i]) { - int j; - guint32 value = selection->selection[i]; - for (j = 0; j < 32; j++) { - if (value & 0x80000000) { - callback(i * 32 + j, closure); - } - value <<= 1; - } - } - } -} - -#define OPERATE(object, mask, grow) ((grow) ? ((object) |= (~(mask))) : ((object) &= (mask))) - -static void -change_one_row(ETableSelectionModel *selection, int row, gboolean grow) -{ - int i; - i = BOX(row); - - OPERATE(selection->selection[i], BITMASK_LEFT(row) | BITMASK_RIGHT(row + 1), grow); -} - -static void -change_selection(ETableSelectionModel *selection, int start, int end, gboolean grow) -{ - int i, last; - if (start != end) { - if (selection->sorter && e_table_sorter_needs_sorting(selection->sorter)) { - for ( i = start; i < end; i++) { - change_one_row(selection, e_table_sorter_sorted_to_model(selection->sorter, i), grow); - } - } else { - i = BOX(start); - last = BOX(end); - - if (i == last) { - OPERATE(selection->selection[i], BITMASK_LEFT(start) | BITMASK_RIGHT(end), grow); - } else { - OPERATE(selection->selection[i], BITMASK_LEFT(start), grow); - if (grow) - for (i ++; i < last; i++) - selection->selection[i] = ONES; - else - for (i ++; i < last; i++) - selection->selection[i] = 0; - OPERATE(selection->selection[i], BITMASK_RIGHT(end), grow); - } - } - } -} - -void e_table_selection_model_do_something (ETableSelectionModel *selection, - guint row, - guint col, - GdkModifierType state) -{ - gint shift_p = state & GDK_SHIFT_MASK; - gint ctrl_p = state & GDK_CONTROL_MASK; - if (selection->row_count < 0) { - if (selection->model) { - selection->row_count = e_table_model_row_count(selection->model); - g_free(selection->selection); - selection->selection = g_new0(gint, (selection->row_count + 31) / 32); - } - } - if (selection->row_count >= 0 && row < selection->row_count) { - if (shift_p) { - int old_start; - int old_end; - int new_start; - int new_end; - if (selection->sorter && e_table_sorter_needs_sorting(selection->sorter)) { - old_start = MIN (e_table_sorter_model_to_sorted(selection->sorter, selection->selection_start_row), - e_table_sorter_model_to_sorted(selection->sorter, selection->cursor_row)); - old_end = MAX (e_table_sorter_model_to_sorted(selection->sorter, selection->selection_start_row), - e_table_sorter_model_to_sorted(selection->sorter, selection->cursor_row)) + 1; - new_start = MIN (e_table_sorter_model_to_sorted(selection->sorter, selection->selection_start_row), - e_table_sorter_model_to_sorted(selection->sorter, row)); - new_end = MAX (e_table_sorter_model_to_sorted(selection->sorter, selection->selection_start_row), - e_table_sorter_model_to_sorted(selection->sorter, row)) + 1; - } else { - old_start = MIN (selection->selection_start_row, selection->cursor_row); - old_end = MAX (selection->selection_start_row, selection->cursor_row) + 1; - new_start = MIN (selection->selection_start_row, row); - new_end = MAX (selection->selection_start_row, row) + 1; - } - /* This wouldn't work nearly so smoothly if one end of the selection held in place. */ - if (old_start < new_start) - change_selection(selection, old_start, new_start, FALSE); - if (new_start < old_start) - change_selection(selection, new_start, old_start, TRUE); - if (old_end < new_end) - change_selection(selection, old_end, new_end, TRUE); - if (new_end < old_end) - change_selection(selection, new_end, old_end, FALSE); - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals [SELECTION_CHANGED]); - } else { - if (ctrl_p) { - if (selection->selection[BOX(row)] & BITMASK(row)) - selection->selection[BOX(row)] &= ~BITMASK(row); - else - selection->selection[BOX(row)] |= BITMASK(row); - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals [SELECTION_CHANGED]); - } else { - int i; - for (i = 0; i < ((selection->row_count + 31) / 32); i++) { - if (!((i == BOX(row) && selection->selection[i] == BITMASK(row)) || - (i != BOX(row) && selection->selection[i] == 0))) { - g_free(selection->selection); - selection->selection = g_new0(gint, (selection->row_count + 31) / 32); - selection->selection[BOX(row)] = BITMASK(row); - - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals [SELECTION_CHANGED]); - break; - } - } - } - selection->selection_start_row = row; - } - if (selection->cursor_row != row || - selection->cursor_col != col) { - selection->cursor_row = row; - selection->cursor_col = col; - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals[CURSOR_CHANGED], row, col); - } - } -} - -void e_table_selection_model_maybe_do_something (ETableSelectionModel *selection, - guint row, - guint col, - GdkModifierType state) -{ - if (e_table_selection_model_is_row_selected(selection, row)) { - selection->cursor_row = row; - selection->cursor_col = col; - } else { - e_table_selection_model_do_something(selection, row, col, state); - } -} - -void -e_table_selection_model_clear(ETableSelectionModel *selection) -{ - g_free(selection->selection); - selection->selection = NULL; - selection->row_count = -1; - selection->cursor_row = -1; - selection->cursor_col = -1; - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals [CURSOR_CHANGED], -1, -1); - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals [SELECTION_CHANGED]); -} - -#define PART(x,n) (((x) & (0x01010101 << n)) >> n) -#define SECTION(x, n) (((x) >> (n * 8)) & 0xff) - -gint -e_table_selection_model_selected_count (ETableSelectionModel *selection) -{ - gint count; - int i; - int last; - - count = 0; - - last = BOX(selection->row_count - 1); - - for (i = 0; i <= last; i++) { - int j; - guint32 thiscount = 0; - for (j = 0; j < 8; j++) - thiscount += PART(selection->selection[i], j); - for (j = 0; j < 4; j++) - count += SECTION(thiscount, j); - } - - return count; -} diff --git a/widgets/e-table/e-table-selection-model.h b/widgets/e-table/e-table-selection-model.h deleted file mode 100644 index 6d7b25ed3d..0000000000 --- a/widgets/e-table/e-table-selection-model.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SELECTION_MODEL_H_ -#define _E_TABLE_SELECTION_MODEL_H_ - -#include <gtk/gtkobject.h> -#include "widgets/e-table/e-table-model.h" -#include "widgets/e-table/e-table-defines.h" -#include "widgets/e-table/e-table-sorter.h" - -#define E_TABLE_SELECTION_MODEL_TYPE (e_table_selection_model_get_type ()) -#define E_TABLE_SELECTION_MODEL(o) (GTK_CHECK_CAST ((o), E_TABLE_SELECTION_MODEL_TYPE, ETableSelectionModel)) -#define E_TABLE_SELECTION_MODEL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SELECTION_MODEL_TYPE, ETableSelectionModelClass)) -#define E_IS_TABLE_SELECTION_MODEL(o) (GTK_CHECK_TYPE ((o), E_TABLE_SELECTION_MODEL_TYPE)) -#define E_IS_TABLE_SELECTION_MODEL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SELECTION_MODEL_TYPE)) - -typedef struct { - GtkObject base; - - ETableModel *model; - ETableSorter *sorter; - - gint row_count; - guint32 *selection; - - gint cursor_row; - gint cursor_col; - gint selection_start_row; - - guint model_changed_id; - guint model_row_inserted_id, model_row_deleted_id; - - guint frozen : 1; - guint selection_model_changed : 1; - guint group_info_changed : 1; -} ETableSelectionModel; - -typedef struct { - GtkObjectClass parent_class; - - /* - * Signals - */ - - void (*cursor_changed) (ETableSelectionModel *selection, int row, int col); - void (*selection_changed) (ETableSelectionModel *selection); - -} ETableSelectionModelClass; - -GtkType e_table_selection_model_get_type (void); - -gboolean e_table_selection_model_is_row_selected (ETableSelectionModel *selection, - gint n); -void e_table_selection_model_foreach (ETableSelectionModel *selection, - ETableForeachFunc callback, - gpointer closure); - -void e_table_selection_model_do_something (ETableSelectionModel *selection, - guint row, - guint col, - GdkModifierType state); -void e_table_selection_model_maybe_do_something (ETableSelectionModel *selection, - guint row, - guint col, - GdkModifierType state); -void e_table_selection_model_clear (ETableSelectionModel *selection); -gint e_table_selection_model_selected_count (ETableSelectionModel *selection); - -ETableSelectionModel *e_table_selection_model_new (void); - -#endif /* _E_TABLE_SELECTION_MODEL_H_ */ diff --git a/widgets/e-table/e-table-simple.c b/widgets/e-table/e-table-simple.c deleted file mode 100644 index 8c8ed87b70..0000000000 --- a/widgets/e-table/e-table-simple.c +++ /dev/null @@ -1,242 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-model.c: a simple table model implementation that uses function - * pointers to simplify the creation of new, exotic and colorful tables in - * no time. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ - -#include <config.h> -#include "e-table-simple.h" - -enum { - ARG_0, - ARG_APPEND_ROW, -}; - -#define PARENT_TYPE e_table_model_get_type () - -static int -simple_column_count (ETableModel *etm) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->col_count) - return simple->col_count (etm, simple->data); - else - return 0; -} - -static int -simple_row_count (ETableModel *etm) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->row_count) - return simple->row_count (etm, simple->data); - else - return 0; -} - -static void * -simple_value_at (ETableModel *etm, int col, int row) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->value_at) - return simple->value_at (etm, col, row, simple->data); - else - return NULL; -} - -static void -simple_set_value_at (ETableModel *etm, int col, int row, const void *val) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->set_value_at) - simple->set_value_at (etm, col, row, val, simple->data); -} - -static gboolean -simple_is_cell_editable (ETableModel *etm, int col, int row) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->is_cell_editable) - return simple->is_cell_editable (etm, col, row, simple->data); - else - return FALSE; -} - -/* The default for simple_duplicate_value is to return the raw value. */ -static void * -simple_duplicate_value (ETableModel *etm, int col, const void *value) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->duplicate_value) - return simple->duplicate_value (etm, col, value, simple->data); - else - return (void *)value; -} - -static void -simple_free_value (ETableModel *etm, int col, void *value) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->free_value) - simple->free_value (etm, col, value, simple->data); -} - -static void * -simple_initialize_value (ETableModel *etm, int col) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->initialize_value) - return simple->initialize_value (etm, col, simple->data); - else - return NULL; -} - -static gboolean -simple_value_is_empty (ETableModel *etm, int col, const void *value) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->value_is_empty) - return simple->value_is_empty (etm, col, value, simple->data); - else - return FALSE; -} - -static char * -simple_value_to_string (ETableModel *etm, int col, const void *value) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->value_to_string) - return simple->value_to_string (etm, col, value, simple->data); - else - return g_strdup (""); -} - -static void -simple_append_row (ETableModel *etm, ETableModel *source, int row) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->append_row) - simple->append_row (etm, source, row, simple->data); -} - -static void -simple_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableSimple *simple = E_TABLE_SIMPLE (o); - - switch (arg_id){ - case ARG_APPEND_ROW: - GTK_VALUE_POINTER(*arg) = simple->append_row; - break; - } -} - -static void -simple_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableSimple *simple = E_TABLE_SIMPLE (o); - - switch (arg_id){ - case ARG_APPEND_ROW: - simple->append_row = GTK_VALUE_POINTER(*arg); - break; - default: - arg->type = GTK_TYPE_INVALID; - } -} - -static void -e_table_simple_class_init (GtkObjectClass *object_class) -{ - ETableModelClass *model_class = (ETableModelClass *) object_class; - - object_class->set_arg = simple_set_arg; - object_class->get_arg = simple_get_arg; - - model_class->column_count = simple_column_count; - model_class->row_count = simple_row_count; - model_class->value_at = simple_value_at; - model_class->set_value_at = simple_set_value_at; - model_class->is_cell_editable = simple_is_cell_editable; - model_class->duplicate_value = simple_duplicate_value; - model_class->free_value = simple_free_value; - model_class->initialize_value = simple_initialize_value; - model_class->value_is_empty = simple_value_is_empty; - model_class->value_to_string = simple_value_to_string; - model_class->append_row = simple_append_row; - - gtk_object_add_arg_type ("ETableSimple::append_row", GTK_TYPE_POINTER, - GTK_ARG_READWRITE, ARG_APPEND_ROW); -} - -GtkType -e_table_simple_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableSimple", - sizeof (ETableSimple), - sizeof (ETableSimpleClass), - (GtkClassInitFunc) e_table_simple_class_init, - (GtkObjectInitFunc) NULL, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_TYPE, &info); - } - - return type; -} - -ETableModel * -e_table_simple_new (ETableSimpleColumnCountFn col_count, - ETableSimpleRowCountFn row_count, - ETableSimpleValueAtFn value_at, - ETableSimpleSetValueAtFn set_value_at, - ETableSimpleIsCellEditableFn is_cell_editable, - ETableSimpleDuplicateValueFn duplicate_value, - ETableSimpleFreeValueFn free_value, - ETableSimpleInitializeValueFn initialize_value, - ETableSimpleValueIsEmptyFn value_is_empty, - ETableSimpleValueToStringFn value_to_string, - void *data) -{ - ETableSimple *et; - - et = gtk_type_new (e_table_simple_get_type ()); - - et->col_count = col_count; - et->row_count = row_count; - et->value_at = value_at; - et->set_value_at = set_value_at; - et->is_cell_editable = is_cell_editable; - et->duplicate_value = duplicate_value; - et->free_value = free_value; - et->initialize_value = initialize_value; - et->value_is_empty = value_is_empty; - et->value_to_string = value_to_string; - et->data = data; - - return (ETableModel *) et; -} diff --git a/widgets/e-table/e-table-simple.h b/widgets/e-table/e-table-simple.h deleted file mode 100644 index 34e76eed79..0000000000 --- a/widgets/e-table/e-table-simple.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SIMPLE_H_ -#define _E_TABLE_SIMPLE_H_ - -#include "e-table-model.h" - -#define E_TABLE_SIMPLE_TYPE (e_table_simple_get_type ()) -#define E_TABLE_SIMPLE(o) (GTK_CHECK_CAST ((o), E_TABLE_SIMPLE_TYPE, ETableSimple)) -#define E_TABLE_SIMPLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SIMPLE_TYPE, ETableSimpleClass)) -#define E_IS_TABLE_SIMPLE(o) (GTK_CHECK_TYPE ((o), E_TABLE_SIMPLE_TYPE)) -#define E_IS_TABLE_SIMPLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SIMPLE_TYPE)) - -typedef int (*ETableSimpleColumnCountFn) (ETableModel *etm, void *data); -typedef int (*ETableSimpleRowCountFn) (ETableModel *etm, void *data); -typedef void *(*ETableSimpleValueAtFn) (ETableModel *etm, int col, int row, void *data); -typedef void (*ETableSimpleSetValueAtFn) (ETableModel *etm, int col, int row, const void *val, void *data); -typedef gboolean (*ETableSimpleIsCellEditableFn) (ETableModel *etm, int col, int row, void *data); -typedef void (*ETableSimpleAppendRowFn) (ETableModel *etm, ETableModel *model, int row, void *data); -typedef void *(*ETableSimpleDuplicateValueFn) (ETableModel *etm, int col, const void *val, void *data); -typedef void (*ETableSimpleFreeValueFn) (ETableModel *etm, int col, void *val, void *data); -typedef void *(*ETableSimpleInitializeValueFn) (ETableModel *etm, int col, void *data); -typedef gboolean (*ETableSimpleValueIsEmptyFn) (ETableModel *etm, int col, const void *val, void *data); -typedef char *(*ETableSimpleValueToStringFn) (ETableModel *etm, int col, const void *val, void *data); - -typedef struct { - ETableModel parent; - - ETableSimpleColumnCountFn col_count; - ETableSimpleRowCountFn row_count; - ETableSimpleValueAtFn value_at; - ETableSimpleSetValueAtFn set_value_at; - ETableSimpleIsCellEditableFn is_cell_editable; - ETableSimpleDuplicateValueFn duplicate_value; - ETableSimpleFreeValueFn free_value; - ETableSimpleInitializeValueFn initialize_value; - ETableSimpleValueIsEmptyFn value_is_empty; - ETableSimpleValueToStringFn value_to_string; - ETableSimpleAppendRowFn append_row; - void *data; -} ETableSimple; - -typedef struct { - ETableModelClass parent_class; -} ETableSimpleClass; - -GtkType e_table_simple_get_type (void); - -ETableModel *e_table_simple_new (ETableSimpleColumnCountFn col_count, - ETableSimpleRowCountFn row_count, - ETableSimpleValueAtFn value_at, - ETableSimpleSetValueAtFn set_value_at, - ETableSimpleIsCellEditableFn is_cell_editable, - ETableSimpleDuplicateValueFn duplicate_value, - ETableSimpleFreeValueFn free_value, - ETableSimpleInitializeValueFn initialize_value, - ETableSimpleValueIsEmptyFn value_is_empty, - ETableSimpleValueToStringFn value_to_string, - void *data); - -#endif /* _E_TABLE_SIMPLE_H_ */ - diff --git a/widgets/e-table/e-table-size-test.c b/widgets/e-table/e-table-size-test.c deleted file mode 100644 index 2bc18235e8..0000000000 --- a/widgets/e-table/e-table-size-test.c +++ /dev/null @@ -1,288 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* This code is GPL. */ -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "e-util/e-cursors.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-cell-checkbox.h" -#include "e-table.h" - -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include "table-test.h" - -/* - * One way in which we make it simpler to build an ETableModel is through - * the ETableSimple class. Instead of creating your own ETableModel - * class, you simply create a new object of the ETableSimple class. You - * give it a bunch of functions that act as callbacks. - * - * You also get to pass a void * to ETableSimple and it gets passed to - * your callbacks. This would be for having multiple models of the same - * type. This is just an example though, so we statically define all the - * data and ignore the void *data parameter. - * - * In our example we will be creating a table model with 6 columns and 10 - * rows. This corresponds to having 6 different types of information and - * 10 different sets of data in our database. - * - * The headers will be hard coded, as will be the example data. - * - */ - -/* - * There are two different meanings to the word "column". The first is - * the model column. A model column corresponds to a specific type of - * data. This is very much like the usage in a database table where a - * column is a field in the database. - * - * The second type of column is a view column. A view column - * corresponds to a visually displayed column. Each view column - * corresponds to a specific model column, though a model column may - * have any number of view columns associated with it, from zero to - * greater than one. - * - * Also, a view column doesn't necessarily depend on only one model - * column. In some cases, the view column renderer can be given a - * reference to another column to get extra information about its - * display. -*/ - -#define ROWS 5000 -#define COLS 4 - -#define IMPORTANCE_COLUMN 4 -#define COLOR_COLUMN 5 - -/* - * Here we define the initial layout of the table. This is an xml - * format that allows you to change the initial ordering of the - * columns or to do sorting or grouping initially. This specification - * shows all 5 columns, but moves the importance column nearer to the - * front. It also sorts by the "Full Name" column (ascending.) - * Sorting and grouping take the model column as their arguments - * (sorting is specified by the "column" argument to the leaf elemnt. - */ - -#define INITIAL_SPEC "<ETableSpecification> \ - <columns-shown> \ - <column> 0 </column> \ - <column> 4 </column> \ - <column> 1 </column> \ - <column> 2 </column> \ - <column> 3 </column> \ - </columns-shown> \ - <grouping> <leaf column=\"1\" ascending=\"1\"/> </grouping> \ -</ETableSpecification>" - -char *headers [COLS] = { - "Email", - "Full Name", - "Address", - "Phone" -}; - -/* - * Virtual Column list: - * 0 Email - * 1 Full Name - * 2 Address - * 3 Phone - */ - -/* - * ETableSimple callbacks - * These are the callbacks that define the behavior of our custom model. - */ - -/* - * Since our model is a constant size, we can just return its size in - * the column and row count fields. - */ - -/* This function returns the number of columns in our ETableModel. */ -static int -my_col_count (ETableModel *etc, void *data) -{ - return COLS; -} - -/* This function returns the number of rows in our ETableModel. */ -static int -my_row_count (ETableModel *etc, void *data) -{ - return ROWS; -} - -/* This function returns the value at a particular point in our ETableModel. */ -static void * -my_value_at (ETableModel *etc, int col, int row, void *data) -{ - static guchar t[] = {'A', 0xc3, 0x84, 0xc3, 0x95, 0xc3, 0x94, 0xc3, 0xb5, 0x00}; - -#if 0 - if (col == 1) return "toshok@helixcode.com"; -#else - if (col == 1) return t; -#endif - else if (col == 2) return "Chris Toshok"; - else if (col == 3) return "43 Vicksburg, SF"; - else if (col == 4) return "415-867-5309"; - else return NULL; -} - -/* This function sets the value at a particular point in our ETableModel. */ -static void -my_set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ -} - -/* This function returns whether a particular cell is editable. */ -static gboolean -my_is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return FALSE; -} - -/* This function duplicates the value passed to it. */ -static void * -my_duplicate_value (ETableModel *etc, int col, const void *value, void *data) -{ - return g_strdup (value); -} - -/* This function frees the value passed to it. */ -static void -my_free_value (ETableModel *etc, int col, void *value, void *data) -{ - g_free (value); -} - -/* This function creates an empty value. */ -static void * -my_initialize_value (ETableModel *etc, int col, void *data) -{ - return g_strdup (""); -} - -/* This function reports if a value is empty. */ -static gboolean -my_value_is_empty (ETableModel *etc, int col, const void *value, void *data) -{ - return !(value && *(char *)value); -} - -/* This function reports if a value is empty. */ -static char * -my_value_to_string (ETableModel *etc, int col, const void *value, void *data) -{ - return g_strdup(value); -} - -/* We create a window containing our new table. */ -static void -create_table (void) -{ - GtkWidget *e_table, *window, *frame; - ECell *cell_left_just; - ETableHeader *e_table_header; - ETableModel *e_table_model = NULL; - int i; - - /* Next we create our model. This uses the functions we defined - earlier. */ - e_table_model = e_table_simple_new ( - my_col_count, my_row_count, my_value_at, - my_set_value_at, my_is_cell_editable, - my_duplicate_value, my_free_value, - my_initialize_value, my_value_is_empty, - my_value_to_string, - NULL); - /* - * Next we create a header. The ETableHeader is used in two - * different way. The first is the full_header. This is the - * list of possible columns in the view. The second use is - * completely internal. Many of the ETableHeader functions are - * for that purpose. The only functions we really need are - * e_table_header_new and e_table_header_add_col. - * - * First we create the header. - */ - e_table_header = e_table_header_new (); - - /* - * Next we have to build renderers for all of the columns. - * Since all our columns are text columns, we can simply use - * the same renderer over and over again. If we had different - * types of columns, we could use a different renderer for - * each column. - */ - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - /* - * Next we create a column object for each view column and add - * them to the header. We don't create a column object for - * the importance column since it will not be shown. - */ - for (i = 0; i < COLS; i++) { - /* Create the column. */ - ETableCol *ecol = e_table_col_new ( - i, headers [i], - 1.0, 20, cell_left_just, - g_str_compare, TRUE); - /* Add it to the header. */ - e_table_header_add_column (e_table_header, ecol, i); - } - - /* - * Here we create a window for our new table. This window - * will get shown and the person will be able to test their - * item. - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - - /* This frame is simply to get a bevel around our table. */ - frame = gtk_frame_new (NULL); - - /* - * Here we create the table. We give it the three pieces of - * the table we've created, the header, the model, and the - * initial layout. It does the rest. - */ - e_table = e_table_new (e_table_header, e_table_model, INITIAL_SPEC); - - /* Build the gtk widget hierarchy. */ - gtk_container_add (GTK_CONTAINER (frame), e_table); - gtk_container_add (GTK_CONTAINER (window), frame); - - /* Size the initial window. */ - gtk_widget_set_usize (window, 300, 200); - - /* Show it all. */ - gtk_widget_show_all (window); -} - -/* This is the main function which just initializes gnome and call our create_table function */ - -int -main (int argc, char *argv []) -{ - gnome_init ("TableExample", "TableExample", argc, argv); - e_cursors_init (); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - create_table (); - - gtk_main (); - - e_cursors_shutdown (); - return 0; -} - diff --git a/widgets/e-table/e-table-sort-info.c b/widgets/e-table/e-table-sort-info.c deleted file mode 100644 index 32ba3d9e65..0000000000 --- a/widgets/e-table/e-table-sort-info.c +++ /dev/null @@ -1,238 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-sort-info.c: a Table Model - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-table-sort-info.h" -#include "e-util/e-util.h" - -#define ETM_CLASS(e) ((ETableSortInfoClass *)((GtkObject *)e)->klass) - -#define PARENT_TYPE gtk_object_get_type () - - -static GtkObjectClass *e_table_sort_info_parent_class; - -enum { - SORT_INFO_CHANGED, - GROUP_INFO_CHANGED, - LAST_SIGNAL -}; - -static guint e_table_sort_info_signals [LAST_SIGNAL] = { 0, }; - -static void -etsi_destroy (GtkObject *object) -{ - ETableSortInfo *etsi; - - etsi = E_TABLE_SORT_INFO (object); - - if (etsi->groupings) - g_free(etsi->groupings); - if (etsi->sortings) - g_free(etsi->sortings); -} - -static void -e_table_sort_info_init (ETableSortInfo *info) -{ - info->group_count = 0; - info->groupings = NULL; - info->sort_count = 0; - info->sortings = NULL; - info->frozen = 0; - info->sort_info_changed = 0; - info->group_info_changed = 0; -} - -static void -e_table_sort_info_class_init (ETableSortInfoClass *klass) -{ - GtkObjectClass *object_class; - - e_table_sort_info_parent_class = gtk_type_class (gtk_object_get_type ()); - - object_class = GTK_OBJECT_CLASS(klass); - - object_class->destroy = etsi_destroy; - - e_table_sort_info_signals [SORT_INFO_CHANGED] = - gtk_signal_new ("sort_info_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableSortInfoClass, sort_info_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_table_sort_info_signals [GROUP_INFO_CHANGED] = - gtk_signal_new ("group_info_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableSortInfoClass, group_info_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - klass->sort_info_changed = NULL; - klass->group_info_changed = NULL; - - gtk_object_class_add_signals (object_class, e_table_sort_info_signals, LAST_SIGNAL); -} - -E_MAKE_TYPE(e_table_sort_info, "ETableSortInfo", ETableSortInfo, - e_table_sort_info_class_init, e_table_sort_info_init, PARENT_TYPE); - -static void -e_table_sort_info_sort_info_changed (ETableSortInfo *info) -{ - g_return_if_fail (info != NULL); - g_return_if_fail (E_IS_TABLE_SORT_INFO (info)); - - if (info->frozen) { - info->sort_info_changed = 1; - } else { - gtk_signal_emit (GTK_OBJECT (info), - e_table_sort_info_signals [SORT_INFO_CHANGED]); - } -} - -static void -e_table_sort_info_group_info_changed (ETableSortInfo *info) -{ - g_return_if_fail (info != NULL); - g_return_if_fail (E_IS_TABLE_SORT_INFO (info)); - - if (info->frozen) { - info->group_info_changed = 1; - } else { - gtk_signal_emit (GTK_OBJECT (info), - e_table_sort_info_signals [GROUP_INFO_CHANGED]); - } -} - -void -e_table_sort_info_freeze (ETableSortInfo *info) -{ - info->frozen = 1; -} - -void -e_table_sort_info_thaw (ETableSortInfo *info) -{ - info->frozen = 0; - 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); - } -} - - -guint -e_table_sort_info_grouping_get_count (ETableSortInfo *info) -{ - return info->group_count; -} - -static void -e_table_sort_info_grouping_real_truncate (ETableSortInfo *info, int length) -{ - if (length < info->group_count) { - info->group_count = length; - } - if (length > info->group_count) { - info->groupings = g_realloc(info->groupings, length * sizeof(ETableSortColumn)); - info->group_count = length; - } -} - -void -e_table_sort_info_grouping_truncate (ETableSortInfo *info, int length) -{ - e_table_sort_info_grouping_real_truncate(info, length); - e_table_sort_info_group_info_changed(info); -} - -ETableSortColumn -e_table_sort_info_grouping_get_nth (ETableSortInfo *info, int n) -{ - if (n < info->group_count) { - return info->groupings[n]; - } else { - ETableSortColumn fake = {0, 0}; - return fake; - } -} - -void -e_table_sort_info_grouping_set_nth (ETableSortInfo *info, int n, ETableSortColumn column) -{ - if (n >= info->group_count) { - e_table_sort_info_grouping_real_truncate(info, n + 1); - } - info->groupings[n] = column; - e_table_sort_info_group_info_changed(info); -} - - -guint -e_table_sort_info_sorting_get_count (ETableSortInfo *info) -{ - return info->sort_count; -} - -static void -e_table_sort_info_sorting_real_truncate (ETableSortInfo *info, int length) -{ - if (length < info->sort_count) { - info->sort_count = length; - } - if (length > info->sort_count) { - info->sortings = g_realloc(info->sortings, length * sizeof(ETableSortColumn)); - info->sort_count = length; - } -} - -void -e_table_sort_info_sorting_truncate (ETableSortInfo *info, int length) -{ - e_table_sort_info_sorting_real_truncate (info, length); - e_table_sort_info_sort_info_changed(info); -} - -ETableSortColumn -e_table_sort_info_sorting_get_nth (ETableSortInfo *info, int n) -{ - if (n < info->sort_count) { - return info->sortings[n]; - } else { - ETableSortColumn fake = {0, 0}; - return fake; - } -} - -void -e_table_sort_info_sorting_set_nth (ETableSortInfo *info, int n, ETableSortColumn column) -{ - if (n >= info->sort_count) { - e_table_sort_info_sorting_real_truncate(info, n + 1); - } - info->sortings[n] = column; - e_table_sort_info_sort_info_changed(info); -} - - -ETableSortInfo * -e_table_sort_info_new (void) -{ - return gtk_type_new (e_table_sort_info_get_type ()); -} diff --git a/widgets/e-table/e-table-sort-info.h b/widgets/e-table/e-table-sort-info.h deleted file mode 100644 index 6446230116..0000000000 --- a/widgets/e-table/e-table-sort-info.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SORT_INFO_H_ -#define _E_TABLE_SORT_INFO_H_ - -#include <gtk/gtkobject.h> - -#define E_TABLE_SORT_INFO_TYPE (e_table_sort_info_get_type ()) -#define E_TABLE_SORT_INFO(o) (GTK_CHECK_CAST ((o), E_TABLE_SORT_INFO_TYPE, ETableSortInfo)) -#define E_TABLE_SORT_INFO_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SORT_INFO_TYPE, ETableSortInfoClass)) -#define E_IS_TABLE_SORT_INFO(o) (GTK_CHECK_TYPE ((o), E_TABLE_SORT_INFO_TYPE)) -#define E_IS_TABLE_SORT_INFO_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SORT_INFO_TYPE)) - -typedef struct _ETableSortColumn ETableSortColumn; - -struct _ETableSortColumn { - guint column : 31; - guint ascending : 1; -}; - -typedef struct { - GtkObject base; - - gint group_count; - ETableSortColumn *groupings; - gint sort_count; - ETableSortColumn *sortings; - - guint frozen : 1; - guint sort_info_changed : 1; - guint group_info_changed : 1; -} ETableSortInfo; - -typedef struct { - GtkObjectClass parent_class; - - /* - * Signals - */ - void (*sort_info_changed) (ETableSortInfo *info); - void (*group_info_changed) (ETableSortInfo *info); -} ETableSortInfoClass; - -GtkType e_table_sort_info_get_type (void); - -void e_table_sort_info_freeze (ETableSortInfo *info); -void e_table_sort_info_thaw (ETableSortInfo *info); - -guint e_table_sort_info_grouping_get_count (ETableSortInfo *info); -void e_table_sort_info_grouping_truncate (ETableSortInfo *info, int length); -ETableSortColumn e_table_sort_info_grouping_get_nth (ETableSortInfo *info, int n); -void e_table_sort_info_grouping_set_nth (ETableSortInfo *info, int n, ETableSortColumn column); - -guint e_table_sort_info_sorting_get_count (ETableSortInfo *info); -void e_table_sort_info_sorting_truncate (ETableSortInfo *info, int length); -ETableSortColumn e_table_sort_info_sorting_get_nth (ETableSortInfo *info, int n); -void e_table_sort_info_sorting_set_nth (ETableSortInfo *info, int n, ETableSortColumn column); - -ETableSortInfo *e_table_sort_info_new (void); - -#endif /* _E_TABLE_SORT_INFO_H_ */ diff --git a/widgets/e-table/e-table-sorted-variable.c b/widgets/e-table/e-table-sorted-variable.c deleted file mode 100644 index 7584b31a74..0000000000 --- a/widgets/e-table/e-table-sorted-variable.c +++ /dev/null @@ -1,337 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-sorted.c: Implements a table that sorts another table - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> -#include <string.h> -#include "e-util/e-util.h" -#include "e-table-sorted-variable.h" - -#define PARENT_TYPE E_TABLE_SUBSET_VARIABLE_TYPE - -#define INCREMENT_AMOUNT 100 - -static ETableSubsetVariableClass *etsv_parent_class; - -static void etsv_proxy_model_changed (ETableModel *etm, ETableSortedVariable *etsv); -#if 0 -static void etsv_proxy_model_row_changed (ETableModel *etm, int row, ETableSortedVariable *etsv); -static void etsv_proxy_model_cell_changed (ETableModel *etm, int col, int row, ETableSortedVariable *etsv); -#endif -static void etsv_sort_info_changed (ETableSortInfo *info, ETableSortedVariable *etsv); -static void etsv_sort (ETableSortedVariable *etsv); -static void etsv_add (ETableSubsetVariable *etssv, gint row); -static void etsv_add_all (ETableSubsetVariable *etssv); - -static void -etsv_destroy (GtkObject *object) -{ - ETableSortedVariable *etsv = E_TABLE_SORTED_VARIABLE (object); - ETableSubset *etss = E_TABLE_SUBSET (object); - - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etsv->table_model_changed_id); -#if 0 - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etsv->table_model_row_changed_id); - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etsv->table_model_cell_changed_id); -#endif - gtk_signal_disconnect (GTK_OBJECT (etsv->sort_info), - etsv->sort_info_changed_id); - - if (etsv->sort_idle_id) { - g_source_remove(etsv->sort_idle_id); - } - - etsv->table_model_changed_id = 0; - etsv->table_model_row_changed_id = 0; - etsv->table_model_cell_changed_id = 0; - - if (etsv->sort_info) - gtk_object_unref(GTK_OBJECT(etsv->sort_info)); - if (etsv->full_header) - gtk_object_unref(GTK_OBJECT(etsv->full_header)); - - GTK_OBJECT_CLASS (etsv_parent_class)->destroy (object); -} - -static void -etsv_class_init (GtkObjectClass *object_class) -{ - ETableSubsetVariableClass *etssv_class = E_TABLE_SUBSET_VARIABLE_CLASS(object_class); - - etsv_parent_class = gtk_type_class (PARENT_TYPE); - - object_class->destroy = etsv_destroy; - - etssv_class->add = etsv_add; - etssv_class->add_all = etsv_add_all; -} - -static void -etsv_init (ETableSortedVariable *etsv) -{ - etsv->full_header = NULL; - etsv->sort_info = NULL; - - etsv->table_model_changed_id = 0; - etsv->table_model_row_changed_id = 0; - etsv->table_model_cell_changed_id = 0; - etsv->sort_info_changed_id = 0; - - etsv->sort_idle_id = 0; -} - -E_MAKE_TYPE(e_table_sorted_variable, "ETableSortedVariable", ETableSortedVariable, etsv_class_init, etsv_init, PARENT_TYPE); - -static gboolean -etsv_sort_idle(ETableSortedVariable *etsv) -{ - gtk_object_ref(GTK_OBJECT(etsv)); - etsv_sort(etsv); - etsv->sort_idle_id = 0; - gtk_object_unref(GTK_OBJECT(etsv)); - return FALSE; -} - -/* This takes source rows. */ -static int -etsv_compare(ETableSortedVariable *etsv, int row1, int row2) -{ - int j; - int sort_count = e_table_sort_info_sorting_get_count(etsv->sort_info); - int comp_val = 0; - int ascending = 1; - ETableSubset *etss = E_TABLE_SUBSET(etsv); - - for (j = 0; j < sort_count; j++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(etsv->sort_info, j); - ETableCol *col; - if (column.column > e_table_header_count (etsv->full_header)) - col = e_table_header_get_column (etsv->full_header, e_table_header_count (etsv->full_header) - 1); - else - col = e_table_header_get_column (etsv->full_header, column.column); - comp_val = (*col->compare)(e_table_model_value_at (etss->source, col->col_idx, row1), - e_table_model_value_at (etss->source, col->col_idx, row2)); - ascending = column.ascending; - if (comp_val != 0) - break; - } - if (comp_val == 0) { - if (row1 < row2) - comp_val = -1; - if (row1 > row2) - comp_val = 1; - } - if (!ascending) - comp_val = -comp_val; - return comp_val; -} - - -static void -etsv_add (ETableSubsetVariable *etssv, - gint row) -{ - ETableModel *etm = E_TABLE_MODEL(etssv); - ETableSubset *etss = E_TABLE_SUBSET(etssv); - ETableSortedVariable *etsv = E_TABLE_SORTED_VARIABLE (etssv); - int i; - - if (etss->n_map + 1 > etssv->n_vals_allocated) { - etssv->n_vals_allocated += INCREMENT_AMOUNT; - etss->map_table = g_realloc (etss->map_table, (etssv->n_vals_allocated) * sizeof(int)); - } - i = etss->n_map; - if (etsv->sort_idle_id == 0) { - i = 0; - while (i < etss->n_map && etsv_compare(etsv, etss->map_table[i], row) < 0) - i++; - memmove(etss->map_table + i + 1, etss->map_table + i, (etss->n_map - i) * sizeof(int)); - } - etss->map_table[i] = row; - etss->n_map++; - - e_table_model_row_inserted (etm, i); -} - -static void -etsv_add_all (ETableSubsetVariable *etssv) -{ - ETableModel *etm = E_TABLE_MODEL(etssv); - ETableSubset *etss = E_TABLE_SUBSET(etssv); - ETableSortedVariable *etsv = E_TABLE_SORTED_VARIABLE (etssv); - int rows; - int i; - - e_table_model_pre_change(etm); - - rows = e_table_model_row_count(etss->source); - - if (etss->n_map + rows > etssv->n_vals_allocated){ - etssv->n_vals_allocated += MAX(INCREMENT_AMOUNT, rows); - etss->map_table = g_realloc (etss->map_table, etssv->n_vals_allocated * sizeof(int)); - } - for (i = 0; i < rows; i++) - etss->map_table[etss->n_map++] = i; - - if (etsv->sort_idle_id == 0) { - etsv->sort_idle_id = g_idle_add_full(50, (GSourceFunc) etsv_sort_idle, etsv, NULL); - } - - e_table_model_changed (etm); -} - -ETableModel * -e_table_sorted_variable_new (ETableModel *source, ETableHeader *full_header, ETableSortInfo *sort_info) -{ - ETableSortedVariable *etsv = gtk_type_new (E_TABLE_SORTED_VARIABLE_TYPE); - ETableSubsetVariable *etssv = E_TABLE_SUBSET_VARIABLE (etsv); - - if (e_table_subset_variable_construct (etssv, source) == NULL){ - gtk_object_destroy (GTK_OBJECT (etsv)); - return NULL; - } - - etsv->sort_info = sort_info; - gtk_object_ref(GTK_OBJECT(etsv->sort_info)); - etsv->full_header = full_header; - gtk_object_ref(GTK_OBJECT(etsv->full_header)); - - etsv->table_model_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_changed", - GTK_SIGNAL_FUNC (etsv_proxy_model_changed), etsv); -#if 0 - etsv->table_model_row_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_row_changed", - GTK_SIGNAL_FUNC (etsv_proxy_model_row_changed), etsv); - etsv->table_model_cell_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_cell_changed", - GTK_SIGNAL_FUNC (etsv_proxy_model_cell_changed), etsv); -#endif - etsv->sort_info_changed_id = gtk_signal_connect (GTK_OBJECT (sort_info), "sort_info_changed", - GTK_SIGNAL_FUNC (etsv_sort_info_changed), etsv); - - return E_TABLE_MODEL(etsv); -} - -static void -etsv_proxy_model_changed (ETableModel *etm, ETableSortedVariable *etsv) -{ - /* FIXME: do_resort (); */ -} -#if 0 -static void -etsv_proxy_model_row_changed (ETableModel *etm, int row, ETableSortedVariable *etsv) -{ - ETableSubsetVariable *etssv = E_TABLE_SUBSET_VARIABLE(etsv); - - if (e_table_subset_variable_remove(etssv, row)) - e_table_subset_variable_add (etssv, row); -} - -static void -etsv_proxy_model_cell_changed (ETableModel *etm, int col, int row, ETableSortedVariable *etsv) -{ - ETableSubsetVariable *etssv = E_TABLE_SUBSET_VARIABLE(etsv); - - if (e_table_subset_variable_remove(etssv, row)) - e_table_subset_variable_add (etssv, row); -} -#endif - -static void -etsv_sort_info_changed (ETableSortInfo *info, ETableSortedVariable *etsv) -{ - etsv_sort(etsv); -} - -static ETableSortedVariable *etsv_closure; -void **vals_closure; -int cols_closure; -int *ascending_closure; -GCompareFunc *compare_closure; - -/* FIXME: Make it not cache the second and later columns (as if anyone cares.) */ - -static int -qsort_callback(const void *data1, const void *data2) -{ - gint row1 = *(int *)data1; - gint row2 = *(int *)data2; - int j; - int sort_count = e_table_sort_info_sorting_get_count(etsv_closure->sort_info); - int comp_val = 0; - int ascending = 1; - for (j = 0; j < sort_count; j++) { - comp_val = (*(compare_closure[j]))(vals_closure[cols_closure * row1 + j], vals_closure[cols_closure * row2 + j]); - ascending = ascending_closure[j]; - if (comp_val != 0) - break; - } - if (comp_val == 0) { - if (row1 < row2) - comp_val = -1; - if (row1 > row2) - comp_val = 1; - } - if (!ascending) - comp_val = -comp_val; - return comp_val; -} - - -static void -etsv_sort(ETableSortedVariable *etsv) -{ - ETableSubset *etss = E_TABLE_SUBSET(etsv); - static int reentering = 0; - int rows = E_TABLE_SUBSET(etsv)->n_map; - int total_rows; - int i; - int j; - int cols; - if (reentering) - return; - reentering = 1; - - e_table_model_pre_change(E_TABLE_MODEL(etsv)); - - total_rows = e_table_model_row_count(E_TABLE_SUBSET(etsv)->source); - cols = e_table_sort_info_sorting_get_count(etsv->sort_info); - cols_closure = cols; - etsv_closure = etsv; - vals_closure = g_new(void *, total_rows * cols); - ascending_closure = g_new(int, cols); - compare_closure = g_new(GCompareFunc, cols); - for (j = 0; j < cols; j++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(etsv->sort_info, j); - ETableCol *col; - if (column.column > e_table_header_count (etsv->full_header)) - col = e_table_header_get_column (etsv->full_header, e_table_header_count (etsv->full_header) - 1); - else - col = e_table_header_get_column (etsv->full_header, column.column); - for (i = 0; i < rows; i++) { -#if 0 - if( !(i & 0xff) ) { - while(gtk_events_pending()) - gtk_main_iteration(); - } -#endif - vals_closure[E_TABLE_SUBSET(etsv)->map_table[i] * cols + j] = e_table_model_value_at (etss->source, col->col_idx, E_TABLE_SUBSET(etsv)->map_table[i]); - } - compare_closure[j] = col->compare; - ascending_closure[j] = column.ascending; - } - qsort(E_TABLE_SUBSET(etsv)->map_table, rows, sizeof(int), qsort_callback); - g_free(vals_closure); - g_free(ascending_closure); - g_free(compare_closure); - e_table_model_changed (E_TABLE_MODEL(etsv)); - reentering = 0; -} diff --git a/widgets/e-table/e-table-sorted-variable.h b/widgets/e-table/e-table-sorted-variable.h deleted file mode 100644 index c6a57c5ede..0000000000 --- a/widgets/e-table/e-table-sorted-variable.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SORTED_VARIABLE_H_ -#define _E_TABLE_SORTED_VARIABLE_H_ - -#include <gtk/gtkobject.h> -#include "e-table-model.h" -#include "e-table-subset-variable.h" -#include "e-table-sort-info.h" -#include "e-table-header.h" - -#define E_TABLE_SORTED_VARIABLE_TYPE (e_table_sorted_variable_get_type ()) -#define E_TABLE_SORTED_VARIABLE(o) (GTK_CHECK_CAST ((o), E_TABLE_SORTED_VARIABLE_TYPE, ETableSortedVariable)) -#define E_TABLE_SORTED_VARIABLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SORTED_VARIABLE_TYPE, ETableSortedVariableClass)) -#define E_IS_TABLE_SORTED_VARIABLE(o) (GTK_CHECK_TYPE ((o), E_TABLE_SORTED_VARIABLE_TYPE)) -#define E_IS_TABLE_SORTED_VARIABLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SORTED_VARIABLE_TYPE)) - -typedef struct { - ETableSubsetVariable base; - - ETableSortInfo *sort_info; - - ETableHeader *full_header; - - int table_model_changed_id; - int table_model_row_changed_id; - int table_model_cell_changed_id; - int sort_info_changed_id; - int sort_idle_id; -} ETableSortedVariable; - -typedef struct { - ETableSubsetVariableClass parent_class; -} ETableSortedVariableClass; - -GtkType e_table_sorted_variable_get_type (void); -ETableModel *e_table_sorted_variable_new (ETableModel *etm, ETableHeader *header, ETableSortInfo *sort_info); - -#endif /* _E_TABLE_SORTED_VARIABLE_H_ */ diff --git a/widgets/e-table/e-table-sorted.c b/widgets/e-table/e-table-sorted.c deleted file mode 100644 index c754f4cff7..0000000000 --- a/widgets/e-table/e-table-sorted.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * E-table-sorted.c: Implements a table that sorts another table - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include "e-util/e-util.h" -#include "e-table-sorted.h" - -#define PARENT_TYPE E_TABLE_SUBSET_TYPE - -static ETableSubsetClass *ets_parent_class; - -static void -ets_class_init (GtkObjectClass *klass) -{ - ets_parent_class = gtk_type_class (PARENT_TYPE); -} - -E_MAKE_TYPE(e_table_sorted, "ETableSorted", ETableSorted, ets_class_init, NULL, PARENT_TYPE); - -static ETableSorted *sort_ets; - -static int -my_sort (const void *a, const void *b) -{ - ETableModel *source = E_TABLE_SUBSET (sort_ets)->source; - const int *ia = (const int *) a; - const int *ib = (const int *) b; - void *va, *vb; - - va = e_table_model_value_at (source, sort_ets->sort_col, *ia); - vb = e_table_model_value_at (source, sort_ets->sort_col, *ib); - - return (*sort_ets->compare) (va, vb); -} - -static void -do_sort (ETableSorted *ets) -{ - ETableSubset *etss = E_TABLE_SUBSET (ets); - g_assert (sort_ets == NULL); - - sort_ets = ets; - qsort (etss->map_table, etss->n_map, sizeof (unsigned int), my_sort); - sort_ets = NULL; -} - -ETableModel * -e_table_sorted_new (ETableModel *source, int col, GCompareFunc compare) -{ - ETableSorted *ets = gtk_type_new (E_TABLE_SORTED_TYPE); - ETableSubset *etss = E_TABLE_SUBSET (ets); - const int nvals = e_table_model_row_count (source); - int i; - - if (e_table_subset_construct (etss, source, nvals) == NULL){ - gtk_object_destroy (GTK_OBJECT (ets)); - return NULL; - } - - ets->compare = compare; - ets->sort_col = col; - - /* Init */ - for (i = 0; i < nvals; i++) - etss->map_table [i] = i; - - do_sort (ets); - - return (ETableModel *) ets; -} - -void -e_table_sorted_resort (ETableSorted *ets, int col, GCompareFunc compare) -{ - if (col == -1 || compare == NULL) - do_sort (ets); - else { - ets->sort_col = col; - ets->compare = compare; - do_sort (ets); - } -} - diff --git a/widgets/e-table/e-table-sorted.h b/widgets/e-table/e-table-sorted.h deleted file mode 100644 index 92bd8d1522..0000000000 --- a/widgets/e-table/e-table-sorted.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _E_TABLE_SORTED_H_ -#define _E_TABLE_SORTED_H_ - -#include <gtk/gtkobject.h> -#include "e-table-model.h" -#include "e-table-subset.h" - -#define E_TABLE_SORTED_TYPE (e_table_sorted_get_type ()) -#define E_TABLE_SORTED(o) (GTK_CHECK_CAST ((o), E_TABLE_SORTED_TYPE, ETableSorted)) -#define E_TABLE_SORTED_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SORTED_TYPE, ETableSortedClass)) -#define E_IS_TABLE_SORTED(o) (GTK_CHECK_TYPE ((o), E_TABLE_SORTED_TYPE)) -#define E_IS_TABLE_SORTED_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SORTED_TYPE)) - -typedef struct { - ETableSubset base; - - short sort_col; - GCompareFunc compare; -} ETableSorted; - -typedef struct { - ETableSubsetClass parent_class; -} ETableSortedClass; - -GtkType e_table_sorted_get_type (void); -ETableModel *e_table_sorted_new (ETableModel *etm, int col, GCompareFunc compare); -void e_table_sorted_resort (ETableSorted *ets, int col, GCompareFunc compare); - -#endif /* _E_TABLE_SORTED_H_ */ diff --git a/widgets/e-table/e-table-sorter.c b/widgets/e-table/e-table-sorter.c deleted file mode 100644 index eb2391b0d0..0000000000 --- a/widgets/e-table/e-table-sorter.c +++ /dev/null @@ -1,295 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-sorted.c: Implements a table that sorts another table - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> -#include <string.h> -#include "e-util/e-util.h" -#include "e-table-sorter.h" - -#define PARENT_TYPE gtk_object_get_type() - -#define INCREMENT_AMOUNT 100 - -static GtkObjectClass *parent_class; - -static void ets_model_changed (ETableModel *etm, ETableSorter *ets); -static void ets_model_row_changed (ETableModel *etm, int row, ETableSorter *ets); -static void ets_model_cell_changed (ETableModel *etm, int col, int row, ETableSorter *ets); -static void ets_sort_info_changed (ETableSortInfo *info, ETableSorter *ets); -static void ets_clean (ETableSorter *ets); -static void ets_sort (ETableSorter *ets); -static void ets_backsort (ETableSorter *ets); - -static void -ets_destroy (GtkObject *object) -{ - ETableSorter *ets = E_TABLE_SORTER (object); - - gtk_signal_disconnect (GTK_OBJECT (ets->source), - ets->table_model_changed_id); - gtk_signal_disconnect (GTK_OBJECT (ets->source), - ets->table_model_row_changed_id); - gtk_signal_disconnect (GTK_OBJECT (ets->source), - ets->table_model_cell_changed_id); - gtk_signal_disconnect (GTK_OBJECT (ets->sort_info), - ets->sort_info_changed_id); - - ets->table_model_changed_id = 0; - ets->table_model_row_changed_id = 0; - ets->table_model_cell_changed_id = 0; - ets->sort_info_changed_id = 0; - - if (ets->sort_info) - gtk_object_unref(GTK_OBJECT(ets->sort_info)); - if (ets->full_header) - gtk_object_unref(GTK_OBJECT(ets->full_header)); - if (ets->source) - gtk_object_unref(GTK_OBJECT(ets->source)); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -static void -ets_class_init (ETableSorterClass *klass) -{ - GtkObjectClass *object_class = GTK_OBJECT_CLASS(klass); - - parent_class = gtk_type_class (PARENT_TYPE); - - object_class->destroy = ets_destroy; -} - -static void -ets_init (ETableSorter *ets) -{ - ets->full_header = NULL; - ets->sort_info = NULL; - ets->source = NULL; - - ets->needs_sorting = -1; - - ets->table_model_changed_id = 0; - ets->table_model_row_changed_id = 0; - ets->table_model_cell_changed_id = 0; - ets->sort_info_changed_id = 0; -} - -E_MAKE_TYPE(e_table_sorter, "ETableSorter", ETableSorter, ets_class_init, ets_init, PARENT_TYPE); - -ETableSorter * -e_table_sorter_new (ETableModel *source, ETableHeader *full_header, ETableSortInfo *sort_info) -{ - ETableSorter *ets = gtk_type_new (E_TABLE_SORTER_TYPE); - - ets->sort_info = sort_info; - gtk_object_ref(GTK_OBJECT(ets->sort_info)); - ets->full_header = full_header; - gtk_object_ref(GTK_OBJECT(ets->full_header)); - ets->source = source; - gtk_object_ref(GTK_OBJECT(ets->source)); - - ets->table_model_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_changed", - GTK_SIGNAL_FUNC (ets_model_changed), ets); - ets->table_model_row_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_row_changed", - GTK_SIGNAL_FUNC (ets_model_row_changed), ets); - ets->table_model_cell_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_cell_changed", - GTK_SIGNAL_FUNC (ets_model_cell_changed), ets); - ets->sort_info_changed_id = gtk_signal_connect (GTK_OBJECT (sort_info), "sort_info_changed", - GTK_SIGNAL_FUNC (ets_sort_info_changed), ets); - - return ets; -} - -static void -ets_model_changed (ETableModel *etm, ETableSorter *ets) -{ - ets_clean(ets); -} - -static void -ets_model_row_changed (ETableModel *etm, int row, ETableSorter *ets) -{ - ets_clean(ets); -} - -static void -ets_model_cell_changed (ETableModel *etm, int col, int row, ETableSorter *ets) -{ - ets_clean(ets); -} - -static void -ets_sort_info_changed (ETableSortInfo *info, ETableSorter *ets) -{ - ets_clean(ets); -} - -static ETableSorter *ets_closure; -void **vals_closure; -int cols_closure; -int *ascending_closure; -GCompareFunc *compare_closure; - -/* FIXME: Make it not cache the second and later columns (as if anyone cares.) */ - -static int -qsort_callback(const void *data1, const void *data2) -{ - gint row1 = *(int *)data1; - gint row2 = *(int *)data2; - int j; - int sort_count = e_table_sort_info_sorting_get_count(ets_closure->sort_info) + e_table_sort_info_grouping_get_count(ets_closure->sort_info); - int comp_val = 0; - int ascending = 1; - for (j = 0; j < sort_count; j++) { - comp_val = (*(compare_closure[j]))(vals_closure[cols_closure * row1 + j], vals_closure[cols_closure * row2 + j]); - ascending = ascending_closure[j]; - if (comp_val != 0) - break; - } - if (comp_val == 0) { - if (row1 < row2) - comp_val = -1; - if (row1 > row2) - comp_val = 1; - } - if (!ascending) - comp_val = -comp_val; - return comp_val; -} - -static void -ets_clean(ETableSorter *ets) -{ - g_free(ets->sorted); - ets->sorted = NULL; - - g_free(ets->backsorted); - ets->backsorted = NULL; - - ets->needs_sorting = -1; -} - -static void -ets_sort(ETableSorter *ets) -{ - int rows; - int i; - int j; - int cols; - int group_cols; - - if (ets->sorted) - return; - - rows = e_table_model_row_count(ets->source); - group_cols = e_table_sort_info_grouping_get_count(ets->sort_info); - cols = e_table_sort_info_sorting_get_count(ets->sort_info) + group_cols; - - ets->sorted = g_new(int, rows); - for (i = 0; i < rows; i++) - ets->sorted[i] = i; - - cols_closure = cols; - ets_closure = ets; - - vals_closure = g_new(void *, rows * cols); - ascending_closure = g_new(int, cols); - compare_closure = g_new(GCompareFunc, cols); - - for (j = 0; j < cols; j++) { - ETableSortColumn column; - ETableCol *col; - - if (j < group_cols) - column = e_table_sort_info_grouping_get_nth(ets->sort_info, j); - else - column = e_table_sort_info_sorting_get_nth(ets->sort_info, j - group_cols); - - if (column.column > e_table_header_count (ets->full_header)) - col = e_table_header_get_column (ets->full_header, e_table_header_count (ets->full_header) - 1); - else - col = e_table_header_get_column (ets->full_header, column.column); - - for (i = 0; i < rows; i++) { - vals_closure[i * cols + j] = e_table_model_value_at (ets->source, col->col_idx, i); - } - - compare_closure[j] = col->compare; - ascending_closure[j] = column.ascending; - } - qsort(ets->sorted, rows, sizeof(int), qsort_callback); - - g_free(vals_closure); - g_free(ascending_closure); - g_free(compare_closure); -} - -static void -ets_backsort(ETableSorter *ets) -{ - int i, rows; - - if (ets->backsorted) - return; - - ets_sort(ets); - - rows = e_table_model_row_count(ets->source); - ets->backsorted = g_new0(int, rows); - - for (i = 0; i < rows; i++) { - ets->backsorted[ets->sorted[i]] = i; - } -} - -gboolean -e_table_sorter_needs_sorting(ETableSorter *ets) -{ - if (ets->needs_sorting < 0) { - if (e_table_sort_info_sorting_get_count(ets->sort_info) + e_table_sort_info_grouping_get_count(ets->sort_info)) - ets->needs_sorting = 1; - else - ets->needs_sorting = 0; - } - return ets->needs_sorting; -} - - -gint -e_table_sorter_model_to_sorted (ETableSorter *sorter, int row) -{ - int rows = e_table_model_row_count(sorter->source); - - g_return_val_if_fail(row >= 0, -1); - g_return_val_if_fail(row < rows, -1); - - if (e_table_sorter_needs_sorting(sorter)) { - ets_backsort(sorter); - return sorter->backsorted[row]; - } else - return row; -} - -gint -e_table_sorter_sorted_to_model (ETableSorter *sorter, int row) -{ - int rows = e_table_model_row_count(sorter->source); - - g_return_val_if_fail(row >= 0, -1); - g_return_val_if_fail(row < rows, -1); - - if (e_table_sorter_needs_sorting(sorter)) { - ets_sort(sorter); - return sorter->sorted[row]; - } else - return row; -} diff --git a/widgets/e-table/e-table-sorter.h b/widgets/e-table/e-table-sorter.h deleted file mode 100644 index f5a71565a3..0000000000 --- a/widgets/e-table/e-table-sorter.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SORTER_H_ -#define _E_TABLE_SORTER_H_ - -#include <gtk/gtkobject.h> -#include "e-table-model.h" -#include "e-table-subset-variable.h" -#include "e-table-sort-info.h" -#include "e-table-header.h" - -#define E_TABLE_SORTER_TYPE (e_table_sorter_get_type ()) -#define E_TABLE_SORTER(o) (GTK_CHECK_CAST ((o), E_TABLE_SORTER_TYPE, ETableSorter)) -#define E_TABLE_SORTER_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SORTER_TYPE, ETableSorterClass)) -#define E_IS_TABLE_SORTER(o) (GTK_CHECK_TYPE ((o), E_TABLE_SORTER_TYPE)) -#define E_IS_TABLE_SORTER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SORTER_TYPE)) - -typedef struct { - GtkObject base; - - ETableModel *source; - ETableHeader *full_header; - ETableSortInfo *sort_info; - - int needs_sorting; - - int *sorted; - int *backsorted; - - int table_model_changed_id; - int table_model_row_changed_id; - int table_model_cell_changed_id; - int sort_info_changed_id; -} ETableSorter; - -typedef struct { - GtkObjectClass parent_class; -} ETableSorterClass; - -GtkType e_table_sorter_get_type (void); -ETableSorter *e_table_sorter_new (ETableModel *etm, ETableHeader *full_header, ETableSortInfo *sort_info); - -gint e_table_sorter_model_to_sorted (ETableSorter *sorter, int row); -gint e_table_sorter_sorted_to_model (ETableSorter *sorter, int row); - -gboolean e_table_sorter_needs_sorting (ETableSorter *sorter); - -#endif /* _E_TABLE_SORTER_H_ */ diff --git a/widgets/e-table/e-table-subset-variable.c b/widgets/e-table/e-table-subset-variable.c deleted file mode 100644 index d429604301..0000000000 --- a/widgets/e-table/e-table-subset-variable.c +++ /dev/null @@ -1,193 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-subset.c: Implements a table that contains a subset of another table. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> -#include <string.h> -#include "e-util/e-util.h" -#include "e-table-subset-variable.h" - -#define ETSSV_CLASS(e) ((ETableSubsetVariableClass *)((GtkObject *)e)->klass) - -#define PARENT_TYPE E_TABLE_SUBSET_TYPE - -#define INCREMENT_AMOUNT 10 - -static ETableSubsetClass *etssv_parent_class; - -static void -etssv_add (ETableSubsetVariable *etssv, - gint row) -{ - ETableModel *etm = E_TABLE_MODEL(etssv); - ETableSubset *etss = E_TABLE_SUBSET(etssv); - - e_table_model_pre_change(etm); - - if (etss->n_map + 1 > etssv->n_vals_allocated){ - etss->map_table = g_realloc (etss->map_table, (etssv->n_vals_allocated + INCREMENT_AMOUNT) * sizeof(int)); - etssv->n_vals_allocated += INCREMENT_AMOUNT; - } - - etss->map_table[etss->n_map++] = row; - - e_table_model_row_inserted (etm, etss->n_map - 1); -} - -static void -etssv_add_all (ETableSubsetVariable *etssv) -{ - ETableModel *etm = E_TABLE_MODEL(etssv); - ETableSubset *etss = E_TABLE_SUBSET(etssv); - int rows; - int i; - - e_table_model_pre_change(etm); - - rows = e_table_model_row_count(etss->source); - if (etss->n_map + rows > etssv->n_vals_allocated){ - etssv->n_vals_allocated += MAX(INCREMENT_AMOUNT, rows); - etss->map_table = g_realloc (etss->map_table, etssv->n_vals_allocated * sizeof(int)); - } - for (i = 0; i < rows; i++) - etss->map_table[etss->n_map++] = i; - - e_table_model_changed (etm); -} - -static gboolean -etssv_remove (ETableSubsetVariable *etssv, - gint row) -{ - ETableModel *etm = E_TABLE_MODEL(etssv); - ETableSubset *etss = E_TABLE_SUBSET(etssv); - int i; - - for (i = 0; i < etss->n_map; i++){ - if (etss->map_table[i] == row) { - e_table_model_pre_change (etm); - memmove (etss->map_table + i, etss->map_table + i + 1, (etss->n_map - i - 1) * sizeof(int)); - etss->n_map --; - - e_table_model_row_deleted (etm, i); - return TRUE; - } - } - return FALSE; -} - -static void -etssv_class_init (GtkObjectClass *object_class) -{ - ETableSubsetVariableClass *klass = E_TABLE_SUBSET_VARIABLE_CLASS(object_class); - etssv_parent_class = gtk_type_class (PARENT_TYPE); - - klass->add = etssv_add; - klass->add_all = etssv_add_all; - klass->remove = etssv_remove; -} - -E_MAKE_TYPE(e_table_subset_variable, "ETableSubsetVariable", ETableSubsetVariable, etssv_class_init, NULL, PARENT_TYPE); - -ETableModel * -e_table_subset_variable_construct (ETableSubsetVariable *etssv, - ETableModel *source) -{ - if (e_table_subset_construct (E_TABLE_SUBSET(etssv), source, 1) == NULL) - return NULL; - E_TABLE_SUBSET(etssv)->n_map = 0; - - return E_TABLE_MODEL (etssv); -} - -ETableModel * -e_table_subset_variable_new (ETableModel *source) -{ - ETableSubsetVariable *etssv = gtk_type_new (E_TABLE_SUBSET_VARIABLE_TYPE); - - if (e_table_subset_variable_construct (etssv, source) == NULL){ - gtk_object_destroy (GTK_OBJECT (etssv)); - return NULL; - } - - return (ETableModel *) etssv; -} - -void -e_table_subset_variable_add (ETableSubsetVariable *etssv, - gint row) -{ - g_return_if_fail (etssv != NULL); - g_return_if_fail (E_IS_TABLE_SUBSET_VARIABLE(etssv)); - - if (ETSSV_CLASS(etssv)->add) - ETSSV_CLASS (etssv)->add (etssv, row); -} - -void -e_table_subset_variable_add_all (ETableSubsetVariable *etssv) -{ - g_return_if_fail (etssv != NULL); - g_return_if_fail (E_IS_TABLE_SUBSET_VARIABLE(etssv)); - - if (ETSSV_CLASS(etssv)->add_all) - ETSSV_CLASS (etssv)->add_all (etssv); -} - -gboolean -e_table_subset_variable_remove (ETableSubsetVariable *etssv, - gint row) -{ - g_return_val_if_fail (etssv != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_SUBSET_VARIABLE(etssv), FALSE); - - if (ETSSV_CLASS(etssv)->remove) - return ETSSV_CLASS (etssv)->remove (etssv, row); - else - return FALSE; -} - -void -e_table_subset_variable_increment (ETableSubsetVariable *etssv, - gint position, - gint amount) -{ - int i; - ETableSubset *etss = E_TABLE_SUBSET(etssv); - for (i = 0; i < etss->n_map; i++) { - if (etss->map_table[i] > position) - etss->map_table[i] += amount; - } -} - -void -e_table_subset_variable_decrement (ETableSubsetVariable *etssv, - gint position, - gint amount) -{ - int i; - ETableSubset *etss = E_TABLE_SUBSET(etssv); - for (i = 0; i < etss->n_map; i++) { - if (etss->map_table[i] > position) - etss->map_table[i] -= amount; - } -} - -void -e_table_subset_variable_set_allocation (ETableSubsetVariable *etssv, - gint total) -{ - ETableSubset *etss = E_TABLE_SUBSET(etssv); - if (total <= 0) - total = 1; - if (total > etss->n_map){ - etss->map_table = g_realloc (etss->map_table, total * sizeof(int)); - } -} diff --git a/widgets/e-table/e-table-subset-variable.h b/widgets/e-table/e-table-subset-variable.h deleted file mode 100644 index 9d44828728..0000000000 --- a/widgets/e-table/e-table-subset-variable.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SUBSET_VARIABLE_H_ -#define _E_TABLE_SUBSET_VARIABLE_H_ - -#include <gtk/gtkobject.h> -#include "e-table-subset.h" - -#define E_TABLE_SUBSET_VARIABLE_TYPE (e_table_subset_variable_get_type ()) -#define E_TABLE_SUBSET_VARIABLE(o) (GTK_CHECK_CAST ((o), E_TABLE_SUBSET_VARIABLE_TYPE, ETableSubsetVariable)) -#define E_TABLE_SUBSET_VARIABLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SUBSET_VARIABLE_TYPE, ETableSubsetVariableClass)) -#define E_IS_TABLE_SUBSET_VARIABLE(o) (GTK_CHECK_TYPE ((o), E_TABLE_SUBSET_VARIABLE_TYPE)) -#define E_IS_TABLE_SUBSET_VARIABLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SUBSET_VARIABLE_TYPE)) - -typedef struct { - ETableSubset base; - - int n_vals_allocated; -} ETableSubsetVariable; - -typedef struct { - ETableSubsetClass parent_class; - - void (*add) (ETableSubsetVariable *ets, - gint row); - void (*add_all) (ETableSubsetVariable *ets); - gboolean (*remove) (ETableSubsetVariable *ets, - gint row); -} ETableSubsetVariableClass; - -GtkType e_table_subset_variable_get_type (void); -ETableModel *e_table_subset_variable_new (ETableModel *etm); -ETableModel *e_table_subset_variable_construct (ETableSubsetVariable *etssv, - ETableModel *source); -void e_table_subset_variable_add (ETableSubsetVariable *ets, - gint row); -void e_table_subset_variable_add_all (ETableSubsetVariable *ets); -gboolean e_table_subset_variable_remove (ETableSubsetVariable *ets, - gint row); -void e_table_subset_variable_increment (ETableSubsetVariable *ets, - gint position, - gint amount); -void e_table_subset_variable_decrement (ETableSubsetVariable *ets, - gint position, - gint amount); -void e_table_subset_variable_set_allocation (ETableSubsetVariable *ets, - gint total); -#endif /* _E_TABLE_SUBSET_VARIABLE_H_ */ - diff --git a/widgets/e-table/e-table-subset.c b/widgets/e-table/e-table-subset.c deleted file mode 100644 index 1cac0f88ea..0000000000 --- a/widgets/e-table/e-table-subset.c +++ /dev/null @@ -1,253 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-subset.c: Implements a table that contains a subset of another table. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> -#include "e-util/e-util.h" -#include "e-table-subset.h" - -#define PARENT_TYPE E_TABLE_MODEL_TYPE - -static ETableModelClass *etss_parent_class; - -static void -etss_destroy (GtkObject *object) -{ - ETableSubset *etss = E_TABLE_SUBSET (object); - - if (etss->source) - gtk_object_unref (GTK_OBJECT (etss->source)); - - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etss->table_model_pre_change_id); - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etss->table_model_changed_id); - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etss->table_model_row_changed_id); - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etss->table_model_cell_changed_id); - - etss->table_model_pre_change_id = 0; - etss->table_model_changed_id = 0; - etss->table_model_row_changed_id = 0; - etss->table_model_cell_changed_id = 0; - - g_free (etss->map_table); - - GTK_OBJECT_CLASS (etss_parent_class)->destroy (object); -} - -static int -etss_column_count (ETableModel *etm) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_column_count (etss->source); -} - -static int -etss_row_count (ETableModel *etm) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return etss->n_map; -} - -static void * -etss_value_at (ETableModel *etm, int col, int row) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_value_at (etss->source, col, etss->map_table [row]); -} - -static void -etss_set_value_at (ETableModel *etm, int col, int row, const void *val) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_set_value_at (etss->source, col, etss->map_table [row], val); -} - -static gboolean -etss_is_cell_editable (ETableModel *etm, int col, int row) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_is_cell_editable (etss->source, col, etss->map_table [row]); -} - -static void -etss_append_row (ETableModel *etm, ETableModel *source, int row) -{ - ETableSubset *etss = (ETableSubset *)etm; - e_table_model_append_row (etss->source, source, row); -} - -static void * -etss_duplicate_value (ETableModel *etm, int col, const void *value) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_duplicate_value (etss->source, col, value); -} - -static void -etss_free_value (ETableModel *etm, int col, void *value) -{ - ETableSubset *etss = (ETableSubset *)etm; - - e_table_model_free_value (etss->source, col, value); -} - -static void * -etss_initialize_value (ETableModel *etm, int col) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_initialize_value (etss->source, col); -} - -static gboolean -etss_value_is_empty (ETableModel *etm, int col, const void *value) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_value_is_empty (etss->source, col, value); -} - -static char * -etss_value_to_string (ETableModel *etm, int col, const void *value) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_value_to_string (etss->source, col, value); -} - -static void -etss_class_init (GtkObjectClass *klass) -{ - ETableModelClass *table_class = (ETableModelClass *) klass; - - etss_parent_class = gtk_type_class (PARENT_TYPE); - - klass->destroy = etss_destroy; - - table_class->column_count = etss_column_count; - table_class->row_count = etss_row_count; - table_class->value_at = etss_value_at; - table_class->set_value_at = etss_set_value_at; - table_class->is_cell_editable = etss_is_cell_editable; - table_class->append_row = etss_append_row; - table_class->duplicate_value = etss_duplicate_value; - table_class->free_value = etss_free_value; - table_class->initialize_value = etss_initialize_value; - table_class->value_is_empty = etss_value_is_empty; - table_class->value_to_string = etss_value_to_string; -} - -E_MAKE_TYPE(e_table_subset, "ETableSubset", ETableSubset, etss_class_init, NULL, PARENT_TYPE); - -static void -etss_proxy_model_pre_change (ETableModel *etm, ETableSubset *etss) -{ - e_table_model_pre_change (E_TABLE_MODEL (etss)); -} - -static void -etss_proxy_model_changed (ETableModel *etm, ETableSubset *etss) -{ - e_table_model_changed (E_TABLE_MODEL (etss)); -} - -static void -etss_proxy_model_row_changed (ETableModel *etm, int row, ETableSubset *etss) -{ - const int n = etss->n_map; - const int * const map_table = etss->map_table; - int i; - - for (i = 0; i < n; i++){ - if (map_table [i] == row){ - e_table_model_row_changed (E_TABLE_MODEL (etss), i); - return; - } - } -} - -static void -etss_proxy_model_cell_changed (ETableModel *etm, int col, int row, ETableSubset *etss) -{ - const int n = etss->n_map; - const int * const map_table = etss->map_table; - int i; - - for (i = 0; i < n; i++){ - if (map_table [i] == row){ - e_table_model_cell_changed (E_TABLE_MODEL (etss), col, i); - return; - } - } -} - -ETableModel * -e_table_subset_construct (ETableSubset *etss, ETableModel *source, int nvals) -{ - unsigned int *buffer; - int i; - - buffer = (unsigned int *) g_malloc (sizeof (unsigned int) * nvals); - if (buffer == NULL) - return NULL; - etss->map_table = buffer; - etss->n_map = nvals; - etss->source = source; - gtk_object_ref (GTK_OBJECT (source)); - - /* Init */ - for (i = 0; i < nvals; i++) - etss->map_table [i] = i; - - etss->table_model_pre_change_id = gtk_signal_connect (GTK_OBJECT (source), "model_pre_change", - GTK_SIGNAL_FUNC (etss_proxy_model_pre_change), etss); - etss->table_model_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_changed", - GTK_SIGNAL_FUNC (etss_proxy_model_changed), etss); - etss->table_model_row_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_row_changed", - GTK_SIGNAL_FUNC (etss_proxy_model_row_changed), etss); - etss->table_model_cell_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_cell_changed", - GTK_SIGNAL_FUNC (etss_proxy_model_cell_changed), etss); - - return E_TABLE_MODEL (etss); -} - -ETableModel * -e_table_subset_new (ETableModel *source, const int nvals) -{ - ETableSubset *etss = gtk_type_new (E_TABLE_SUBSET_TYPE); - - if (e_table_subset_construct (etss, source, nvals) == NULL){ - gtk_object_destroy (GTK_OBJECT (etss)); - return NULL; - } - - return (ETableModel *) etss; -} - -ETableModel * -e_table_subset_get_toplevel (ETableSubset *table) -{ - g_return_val_if_fail (table != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_SUBSET (table), NULL); - - if (E_IS_TABLE_SUBSET (table->source)) - return e_table_subset_get_toplevel (E_TABLE_SUBSET (table->source)); - else - return table->source; -} diff --git a/widgets/e-table/e-table-subset.h b/widgets/e-table/e-table-subset.h deleted file mode 100644 index 9e10de7a4b..0000000000 --- a/widgets/e-table/e-table-subset.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SUBSET_H_ -#define _E_TABLE_SUBSET_H_ - -#include <gtk/gtkobject.h> -#include "e-table-model.h" - -#define E_TABLE_SUBSET_TYPE (e_table_subset_get_type ()) -#define E_TABLE_SUBSET(o) (GTK_CHECK_CAST ((o), E_TABLE_SUBSET_TYPE, ETableSubset)) -#define E_TABLE_SUBSET_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SUBSET_TYPE, ETableSubsetClass)) -#define E_IS_TABLE_SUBSET(o) (GTK_CHECK_TYPE ((o), E_TABLE_SUBSET_TYPE)) -#define E_IS_TABLE_SUBSET_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SUBSET_TYPE)) - -typedef struct { - ETableModel base; - - ETableModel *source; - int n_map; - int *map_table; - - int table_model_pre_change_id; - int table_model_changed_id; - int table_model_row_changed_id; - int table_model_cell_changed_id; -} ETableSubset; - -typedef struct { - ETableModelClass parent_class; -} ETableSubsetClass; - -GtkType e_table_subset_get_type (void); -ETableModel *e_table_subset_new (ETableModel *etm, int n_vals); -ETableModel *e_table_subset_construct (ETableSubset *ets, ETableModel *source, int nvals); - -ETableModel *e_table_subset_get_toplevel (ETableSubset *table_model); - -#endif /* _E_TABLE_SUBSET_H_ */ - diff --git a/widgets/e-table/e-table-text-model.c b/widgets/e-table/e-table-text-model.c deleted file mode 100644 index 5b6fa8b707..0000000000 --- a/widgets/e-table/e-table-text-model.c +++ /dev/null @@ -1,220 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ETableTextModel - Text item model for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey <clahey@umich.edu> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> */ - -#include <config.h> -#include <ctype.h> -#include "e-table-text-model.h" - -static void e_table_text_model_class_init (ETableTextModelClass *class); -static void e_table_text_model_init (ETableTextModel *model); -static void e_table_text_model_destroy (GtkObject *object); - -static gchar *e_table_text_model_get_text (ETextModel *model); -static void e_table_text_model_set_text (ETextModel *model, gchar *text); -static void e_table_text_model_insert (ETextModel *model, gint postion, gchar *text); -static void e_table_text_model_insert_length (ETextModel *model, gint postion, gchar *text, gint length); -static void e_table_text_model_delete (ETextModel *model, gint postion, gint length); - -static GtkObject *parent_class; - - - -/** - * e_table_text_model_get_type: - * @void: - * - * Registers the &ETableTextModel class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &ETableTextModel class. - **/ -GtkType -e_table_text_model_get_type (void) -{ - static GtkType model_type = 0; - - if (!model_type) { - GtkTypeInfo model_info = { - "ETableTextModel", - sizeof (ETableTextModel), - sizeof (ETableTextModelClass), - (GtkClassInitFunc) e_table_text_model_class_init, - (GtkObjectInitFunc) e_table_text_model_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - model_type = gtk_type_unique (e_text_model_get_type (), &model_info); - } - - return model_type; -} - -/* Class initialization function for the text item */ -static void -e_table_text_model_class_init (ETableTextModelClass *klass) -{ - GtkObjectClass *object_class; - ETextModelClass *model_class; - - object_class = (GtkObjectClass *) klass; - model_class = (ETextModelClass *) klass; - - parent_class = gtk_type_class (e_text_model_get_type ()); - - model_class->get_text = e_table_text_model_get_text; - model_class->set_text = e_table_text_model_set_text; - model_class->insert = e_table_text_model_insert; - model_class->insert_length = e_table_text_model_insert_length; - model_class->delete = e_table_text_model_delete; - - object_class->destroy = e_table_text_model_destroy; -} - -/* Object initialization function for the text item */ -static void -e_table_text_model_init (ETableTextModel *model) -{ - model->model = NULL; - model->row = 0; - model->model_col = 0; - model->cell_changed_signal_id = 0; - model->row_changed_signal_id = 0; -} - -/* Destroy handler for the text item */ -static void -e_table_text_model_destroy (GtkObject *object) -{ - ETableTextModel *model; - - g_return_if_fail (object != NULL); - g_return_if_fail (E_IS_TABLE_TEXT_MODEL (object)); - - model = E_TABLE_TEXT_MODEL (object); - - if (model->model) - g_assert (GTK_IS_OBJECT (model->model)); - - if (model->cell_changed_signal_id) - gtk_signal_disconnect (GTK_OBJECT(model->model), - model->cell_changed_signal_id); - - if (model->row_changed_signal_id) - gtk_signal_disconnect (GTK_OBJECT(model->model), - model->row_changed_signal_id); - - if (model->model) - gtk_object_unref (GTK_OBJECT(model->model)); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} -static gchar * -e_table_text_model_get_text (ETextModel *text_model) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model) - return (gchar *)e_table_model_value_at (model->model, model->model_col, model->row); - else - return ""; -} - -static void -e_table_text_model_set_text (ETextModel *text_model, gchar *text) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model) - e_table_model_set_value_at (model->model, model->model_col, model->row, (void *) text); -} - -static void -e_table_text_model_insert (ETextModel *text_model, gint position, gchar *text) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model){ - gchar *temp = (gchar *)e_table_model_value_at (model->model, model->model_col, model->row); - temp = g_strdup_printf ("%.*s%s%s", position, temp, text, temp + position); - e_table_model_set_value_at (model->model, model->model_col, model->row, temp); - g_free (temp); - } -} - -static void -e_table_text_model_insert_length (ETextModel *text_model, gint position, gchar *text, gint length) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model){ - gchar *temp = (gchar *)e_table_model_value_at (model->model, model->model_col, model->row); - temp = g_strdup_printf ("%.*s%.*s%s", position, temp, length, text, temp + position); - e_table_model_set_value_at (model->model, model->model_col, model->row, temp); - g_free (temp); - } -} - -static void -e_table_text_model_delete (ETextModel *text_model, gint position, gint length) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model){ - gchar *temp = (gchar *)e_table_model_value_at (model->model, model->model_col, model->row); - temp = g_strdup_printf ("%.*s%s", position, temp, temp + position + length); - e_table_model_set_value_at (model->model, model->model_col, model->row, temp); - g_free (temp); - } -} - -static void -cell_changed (ETableModel *table_model, int model_col, int row, ETableTextModel *model) -{ - if (model->model_col == model_col && - model->row == row) - e_text_model_changed (E_TEXT_MODEL(model)); -} - -static void -row_changed (ETableModel *table_model, int row, ETableTextModel *model) -{ - if (model->row == row) - e_text_model_changed (E_TEXT_MODEL(model)); -} - -ETableTextModel * -e_table_text_model_new (ETableModel *table_model, int row, int model_col) -{ - ETableTextModel *model = gtk_type_new (e_table_text_model_get_type ()); - model->model = table_model; - if (model->model){ - gtk_object_ref (GTK_OBJECT(model->model)); - model->cell_changed_signal_id = - gtk_signal_connect (GTK_OBJECT(model->model), - "model_cell_changed", - GTK_SIGNAL_FUNC(cell_changed), - model); - model->row_changed_signal_id = - gtk_signal_connect (GTK_OBJECT(model->model), - "model_row_changed", - GTK_SIGNAL_FUNC(row_changed), - model); - } - model->row = row; - model->model_col = model_col; - return model; -} - diff --git a/widgets/e-table/e-table-text-model.h b/widgets/e-table/e-table-text-model.h deleted file mode 100644 index dcc9afde7c..0000000000 --- a/widgets/e-table/e-table-text-model.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ETableTextModel - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey <clahey@umich.edu> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> */ - -#ifndef E_TABLE_TEXT_MODEL_H -#define E_TABLE_TEXT_MODEL_H - -#include <gnome.h> -#include "e-text-model.h" -#include "e-table-model.h" - - -BEGIN_GNOME_DECLS - -#define E_TYPE_TABLE_TEXT_MODEL (e_table_text_model_get_type ()) -#define E_TABLE_TEXT_MODEL(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TABLE_TEXT_MODEL, ETableTextModel)) -#define E_TABLE_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TABLE_TEXT_MODEL, ETableTextModelClass)) -#define E_IS_TABLE_TEXT_MODEL(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TABLE_TEXT_MODEL)) -#define E_IS_TABLE_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TABLE_TEXT_MODEL)) - -typedef struct _ETableTextModel ETableTextModel; -typedef struct _ETableTextModelClass ETableTextModelClass; - -struct _ETableTextModel { - ETextModel parent; - - ETableModel *model; - int row; - int model_col; - - int cell_changed_signal_id; - int row_changed_signal_id; -}; - -struct _ETableTextModelClass { - ETextModelClass parent_class; - -}; - - -/* Standard Gtk function */ -GtkType e_table_text_model_get_type (void); -ETableTextModel *e_table_text_model_new (ETableModel *table_model, int row, int model_col); - -END_GNOME_DECLS - -#endif diff --git a/widgets/e-table/e-table-tree.h b/widgets/e-table/e-table-tree.h deleted file mode 100644 index e7e125a6af..0000000000 --- a/widgets/e-table/e-table-tree.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _E_TABLE_TREE_H_ -#define _E_TABLE_TREE_H_ - -typedef struct { - char *title; - - union { - ETableModel *table; - GList *children; - } u; - - guint expanded :1; - guint is_leaf :1; -} ETableGroup; - -ETableGroup *e_table_group_new (const char *title, ETableModel *table); -ETableGroup *e_table_group_new_leaf (const char *title); - -#endif /* _E_TABLE_TREE_H_ */ diff --git a/widgets/e-table/e-table.c b/widgets/e-table/e-table.c deleted file mode 100644 index bd6d7bc60c..0000000000 --- a/widgets/e-table/e-table.c +++ /dev/null @@ -1,1669 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table.c: A graphical view of a Table. - * - * Author: - * Miguel de Icaza (miguel@helixcode.com) - * Chris Lahey (clahey@helixcode.com) - * - * Copyright 1999, Helix Code, Inc - */ -#include <config.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#ifdef HAVE_ALLOCA_H -#include <alloca.h> -#endif -#include <stdio.h> -#include <libgnomeui/gnome-canvas.h> -#include <gtk/gtksignal.h> -#include <gnome-xml/parser.h> -#include <gnome-xml/xmlmemory.h> - -#include "e-util/e-util.h" -#include "e-util/e-xml-utils.h" -#include "e-util/e-canvas.h" -#include "e-util/e-canvas-vbox.h" -#include "e-table.h" -#include "e-table-header-item.h" -#include "e-table-subset.h" -#include "e-table-item.h" -#include "e-table-group.h" -#include "e-table-group-leaf.h" -#include "e-table-click-to-add.h" - -#define COLUMN_HEADER_HEIGHT 16 - -#define PARENT_TYPE gtk_table_get_type () - -static GtkObjectClass *e_table_parent_class; - -enum { - CURSOR_CHANGE, - DOUBLE_CLICK, - RIGHT_CLICK, - KEY_PRESS, - - TABLE_DRAG_BEGIN, - TABLE_DRAG_END, - TABLE_DRAG_DATA_GET, - TABLE_DRAG_DATA_DELETE, - - TABLE_DRAG_LEAVE, - TABLE_DRAG_MOTION, - TABLE_DRAG_DROP, - TABLE_DRAG_DATA_RECEIVED, - - LAST_SIGNAL -}; - -enum { - ARG_0, - ARG_TABLE_DRAW_GRID, - ARG_TABLE_DRAW_FOCUS, - ARG_CURSOR_MODE, - ARG_LENGTH_THRESHOLD, - ARG_CLICK_TO_ADD_MESSAGE, -}; - -static gint et_signals [LAST_SIGNAL] = { 0, }; - -static void e_table_fill_table (ETable *e_table, ETableModel *model); -static gboolean changed_idle (gpointer data); - -static void et_drag_begin (GtkWidget *widget, - GdkDragContext *context, - ETable *et); -static void et_drag_end (GtkWidget *widget, - GdkDragContext *context, - ETable *et); -static void et_drag_data_get(GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - ETable *et); -static void et_drag_data_delete(GtkWidget *widget, - GdkDragContext *context, - ETable *et); - -static void et_drag_leave(GtkWidget *widget, - GdkDragContext *context, - guint time, - ETable *et); -static gboolean et_drag_motion(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETable *et); -static gboolean et_drag_drop(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETable *et); -static void et_drag_data_received(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time, - ETable *et); -static gint e_table_drag_source_event_cb (GtkWidget *widget, - GdkEvent *event, - ETable *table); - -static void -et_destroy (GtkObject *object) -{ - ETable *et = E_TABLE (object); - - - gtk_signal_disconnect (GTK_OBJECT (et->model), - et->table_model_change_id); - gtk_signal_disconnect (GTK_OBJECT (et->model), - et->table_row_change_id); - gtk_signal_disconnect (GTK_OBJECT (et->model), - et->table_cell_change_id); - gtk_signal_disconnect (GTK_OBJECT (et->model), - et->table_row_inserted_id); - gtk_signal_disconnect (GTK_OBJECT (et->model), - et->table_row_deleted_id); - if (et->group_info_change_id) - gtk_signal_disconnect (GTK_OBJECT (et->sort_info), - et->group_info_change_id); - - if (et->reflow_idle_id) - g_source_remove(et->reflow_idle_id); - et->reflow_idle_id = 0; - - gtk_object_unref (GTK_OBJECT (et->model)); - gtk_object_unref (GTK_OBJECT (et->full_header)); - gtk_object_unref (GTK_OBJECT (et->header)); - gtk_object_unref (GTK_OBJECT (et->sort_info)); - gtk_object_unref (GTK_OBJECT (et->sorter)); - gtk_widget_destroy (GTK_WIDGET (et->header_canvas)); - gtk_widget_destroy (GTK_WIDGET (et->table_canvas)); - - if (et->rebuild_idle_id) { - g_source_remove (et->rebuild_idle_id); - et->rebuild_idle_id = 0; - } - - g_free(et->click_to_add_message); - - (*e_table_parent_class->destroy)(object); -} - -static void -e_table_init (GtkObject *object) -{ - ETable *e_table = E_TABLE (object); - GtkTable *gtk_table = GTK_TABLE (object); - - gtk_table->homogeneous = FALSE; - - e_table->sort_info = NULL; - e_table->group_info_change_id = 0; - e_table->reflow_idle_id = 0; - - e_table->draw_grid = 1; - e_table->draw_focus = 1; - e_table->cursor_mode = E_TABLE_CURSOR_SIMPLE; - e_table->length_threshold = 200; - - e_table->need_rebuild = 0; - e_table->rebuild_idle_id = 0; - - e_table->click_to_add_message = NULL; - - e_table->drag_get_data_row = -1; - e_table->drag_get_data_col = -1; - e_table->drop_row = -1; - e_table->drop_col = -1; - e_table->site = NULL; - e_table->drag_source_button_press_event_id = 0; - e_table->drag_source_motion_notify_event_id = 0; - - e_table->sorter = NULL; - e_table->selection = e_table_selection_model_new(); - e_table->cursor_loc = E_TABLE_CURSOR_LOC_NONE; -} - -static void -header_canvas_size_allocate (GtkWidget *widget, GtkAllocation *alloc, ETable *e_table) -{ - gnome_canvas_set_scroll_region ( - GNOME_CANVAS (e_table->header_canvas), - 0, 0, alloc->width - 1, COLUMN_HEADER_HEIGHT - 1); -} - -static void -sort_info_changed (ETableSortInfo *info, ETable *et) -{ - et->need_rebuild = TRUE; - if (!et->rebuild_idle_id) - et->rebuild_idle_id = g_idle_add_full (20, changed_idle, et, NULL); -} - -static void -e_table_setup_header (ETable *e_table) -{ - e_table->header_canvas = GNOME_CANVAS (e_canvas_new ()); - - gtk_widget_show (GTK_WIDGET (e_table->header_canvas)); - - 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", "(unset)", - NULL); - - gtk_signal_connect ( - GTK_OBJECT (e_table->header_canvas), "size_allocate", - GTK_SIGNAL_FUNC (header_canvas_size_allocate), e_table); - - gtk_widget_set_usize (GTK_WIDGET (e_table->header_canvas), -1, COLUMN_HEADER_HEIGHT); -} - -static gboolean -table_canvas_reflow_idle (ETable *e_table) -{ - gdouble height, width; - GtkAllocation *alloc = &(GTK_WIDGET (e_table->table_canvas)->allocation); - - gtk_object_get (GTK_OBJECT (e_table->canvas_vbox), - "height", &height, - "width", &width, - NULL); - height = MAX ((int)height, alloc->height); - width = MAX((int)width, alloc->width); - /* I have no idea why this needs to be -1, but it works. */ - gnome_canvas_set_scroll_region ( - GNOME_CANVAS (e_table->table_canvas), - 0, 0, width - 1, height - 1); - e_table->reflow_idle_id = 0; - return FALSE; -} - -static void -table_canvas_size_allocate (GtkWidget *widget, GtkAllocation *alloc, - ETable *e_table) -{ - gdouble width; - width = alloc->width; - - gtk_object_set (GTK_OBJECT (e_table->canvas_vbox), - "width", width, - NULL); - gtk_object_set (GTK_OBJECT (e_table->header), - "width", width, - NULL); - if (e_table->reflow_idle_id) - g_source_remove(e_table->reflow_idle_id); - table_canvas_reflow_idle(e_table); -} - -static void -table_canvas_reflow (GnomeCanvas *canvas, ETable *e_table) -{ - if (!e_table->reflow_idle_id) - e_table->reflow_idle_id = g_idle_add_full (400, (GSourceFunc) table_canvas_reflow_idle, e_table, NULL); -} - -static void -click_to_add_cursor_change (ETableClickToAdd *etcta, int row, int col, ETable *et) -{ - if (et->cursor_loc == E_TABLE_CURSOR_LOC_TABLE) { - e_table_selection_model_clear(et->selection); - } - et->cursor_loc = E_TABLE_CURSOR_LOC_ETCTA; -} - -static void -group_cursor_change (ETableGroup *etg, int row, ETable *et) -{ - if (et->cursor_loc == E_TABLE_CURSOR_LOC_ETCTA && et->click_to_add) { - e_table_click_to_add_commit(E_TABLE_CLICK_TO_ADD(et->click_to_add)); - } - et->cursor_loc = E_TABLE_CURSOR_LOC_TABLE; - gtk_signal_emit (GTK_OBJECT (et), - et_signals [CURSOR_CHANGE], - row); -} - -static void -group_double_click (ETableGroup *etg, int row, ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [DOUBLE_CLICK], - row); -} - -static gint -group_right_click (ETableGroup *etg, int row, int col, GdkEvent *event, ETable *et) -{ - int return_val; - gtk_signal_emit (GTK_OBJECT (et), - et_signals [RIGHT_CLICK], - row, col, event, &return_val); - return return_val; -} - -static gint -group_key_press (ETableGroup *etg, int row, int col, GdkEvent *event, ETable *et) -{ - int return_val; - gtk_signal_emit (GTK_OBJECT (et), - et_signals [KEY_PRESS], - row, col, event, &return_val); - return return_val; -} - -static gboolean -changed_idle (gpointer data) -{ - ETable *et = E_TABLE (data); - - if (et->need_rebuild) { - gtk_object_destroy (GTK_OBJECT (et->group)); - et->group = e_table_group_new (GNOME_CANVAS_GROUP (et->canvas_vbox), - et->full_header, - et->header, - et->model, - et->sort_info, - 0); - e_canvas_vbox_add_item(E_CANVAS_VBOX(et->canvas_vbox), GNOME_CANVAS_ITEM(et->group)); - gnome_canvas_item_set(GNOME_CANVAS_ITEM(et->group), - "drawgrid", et->draw_grid, - "drawfocus", et->draw_focus, - "cursor_mode", et->cursor_mode, - "length_threshold", et->length_threshold, - "table_selection_model", et->selection, - NULL); - gtk_signal_connect (GTK_OBJECT (et->group), "cursor_change", - GTK_SIGNAL_FUNC (group_cursor_change), et); - gtk_signal_connect (GTK_OBJECT (et->group), "double_click", - GTK_SIGNAL_FUNC (group_double_click), et); - gtk_signal_connect (GTK_OBJECT (et->group), "right_click", - GTK_SIGNAL_FUNC (group_right_click), et); - gtk_signal_connect (GTK_OBJECT (et->group), "key_press", - GTK_SIGNAL_FUNC (group_key_press), et); - e_table_fill_table (et, et->model); - - gtk_object_set (GTK_OBJECT (et->canvas_vbox), - "width", (double) GTK_WIDGET (et->table_canvas)->allocation.width, - NULL); - } - - et->need_rebuild = 0; - et->rebuild_idle_id = 0; - - return FALSE; -} - -static void -et_table_model_changed (ETableModel *model, ETable *et) -{ - et->need_rebuild = TRUE; - if (!et->rebuild_idle_id) - et->rebuild_idle_id = g_idle_add_full (20, changed_idle, et, NULL); -} - -static void -et_table_row_changed (ETableModel *table_model, int row, ETable *et) -{ - if (!et->need_rebuild) { - if (e_table_group_remove (et->group, row)) - e_table_group_add (et->group, row); - } -} - -static void -et_table_cell_changed (ETableModel *table_model, int view_col, int row, ETable *et) -{ - et_table_row_changed (table_model, row, et); -} - -static void -et_table_row_inserted (ETableModel *table_model, int row, ETable *et) -{ - int row_count = e_table_model_row_count(table_model); - if (!et->need_rebuild) { - if (row != row_count - 1) - e_table_group_increment(et->group, row, 1); - e_table_group_add (et->group, row); - } -} - -static void -et_table_row_deleted (ETableModel *table_model, int row, ETable *et) -{ - int row_count = e_table_model_row_count(table_model); - if (!et->need_rebuild) { - e_table_group_remove (et->group, row); - if (row != row_count - 1) - e_table_group_decrement(et->group, row, 1); - } -} - -static void -e_table_setup_table (ETable *e_table, ETableHeader *full_header, ETableHeader *header, - ETableModel *model) -{ - e_table->table_canvas = GNOME_CANVAS (e_canvas_new ()); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "size_allocate", - GTK_SIGNAL_FUNC (table_canvas_size_allocate), e_table); - - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "drag_begin", - GTK_SIGNAL_FUNC (et_drag_begin), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "drag_end", - GTK_SIGNAL_FUNC (et_drag_end), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "drag_data_get", - GTK_SIGNAL_FUNC (et_drag_data_get), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "drag_data_delete", - GTK_SIGNAL_FUNC (et_drag_data_delete), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "drag_motion", - GTK_SIGNAL_FUNC (et_drag_motion), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "drag_leave", - GTK_SIGNAL_FUNC (et_drag_leave), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "drag_drop", - GTK_SIGNAL_FUNC (et_drag_drop), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "drag_data_received", - GTK_SIGNAL_FUNC (et_drag_data_received), e_table); - - gtk_signal_connect (GTK_OBJECT(e_table->table_canvas), "reflow", - GTK_SIGNAL_FUNC (table_canvas_reflow), e_table); - - gtk_widget_show (GTK_WIDGET (e_table->table_canvas)); - - - e_table->canvas_vbox = gnome_canvas_item_new(gnome_canvas_root(e_table->table_canvas), - e_canvas_vbox_get_type(), - "spacing", 10.0, - NULL); - - if (e_table->use_click_to_add) { - e_table->click_to_add = gnome_canvas_item_new (GNOME_CANVAS_GROUP(e_table->canvas_vbox), - e_table_click_to_add_get_type (), - "header", e_table->header, - "model", e_table->model, - "message", e_table->click_to_add_message, - NULL); - - e_canvas_vbox_add_item(E_CANVAS_VBOX(e_table->canvas_vbox), e_table->click_to_add); - gtk_signal_connect(GTK_OBJECT (e_table->click_to_add), "cursor_change", - GTK_SIGNAL_FUNC(click_to_add_cursor_change), e_table); - } - - e_table->group = e_table_group_new ( - GNOME_CANVAS_GROUP (e_table->canvas_vbox), - full_header, header, - model, e_table->sort_info, 0); - e_canvas_vbox_add_item(E_CANVAS_VBOX(e_table->canvas_vbox), GNOME_CANVAS_ITEM(e_table->group)); - - gnome_canvas_item_set(GNOME_CANVAS_ITEM(e_table->group), - "drawgrid", e_table->draw_grid, - "drawfocus", e_table->draw_focus, - "cursor_mode", e_table->cursor_mode, - "length_threshold", e_table->length_threshold, - "table_selection_model", e_table->selection, - NULL); - - gtk_signal_connect (GTK_OBJECT (e_table->group), "cursor_change", - GTK_SIGNAL_FUNC(group_cursor_change), e_table); - gtk_signal_connect (GTK_OBJECT (e_table->group), "double_click", - GTK_SIGNAL_FUNC(group_double_click), e_table); - gtk_signal_connect (GTK_OBJECT (e_table->group), "right_click", - GTK_SIGNAL_FUNC(group_right_click), e_table); - gtk_signal_connect (GTK_OBJECT (e_table->group), "key_press", - GTK_SIGNAL_FUNC(group_key_press), e_table); - - e_table->table_model_change_id = gtk_signal_connect ( - GTK_OBJECT (model), "model_changed", - GTK_SIGNAL_FUNC (et_table_model_changed), e_table); - - e_table->table_row_change_id = gtk_signal_connect ( - GTK_OBJECT (model), "model_row_changed", - GTK_SIGNAL_FUNC (et_table_row_changed), e_table); - - e_table->table_cell_change_id = gtk_signal_connect ( - GTK_OBJECT (model), "model_cell_changed", - GTK_SIGNAL_FUNC (et_table_cell_changed), e_table); - - e_table->table_row_inserted_id = gtk_signal_connect ( - GTK_OBJECT (model), "model_row_inserted", - GTK_SIGNAL_FUNC (et_table_row_inserted), e_table); - - e_table->table_row_deleted_id = gtk_signal_connect ( - GTK_OBJECT (model), "model_row_deleted", - GTK_SIGNAL_FUNC (et_table_row_deleted), e_table); - -} - -static void -e_table_fill_table (ETable *e_table, ETableModel *model) -{ - e_table_group_add_all (e_table->group); -} - -static ETableHeader * -et_xml_to_header (ETable *e_table, ETableHeader *full_header, xmlNode *xmlColumns) -{ - ETableHeader *nh; - xmlNode *column; - const int max_cols = e_table_header_count (full_header); - - g_return_val_if_fail (e_table, NULL); - g_return_val_if_fail (full_header, NULL); - g_return_val_if_fail (xmlColumns, NULL); - - nh = e_table_header_new (); - - for (column = xmlColumns->childs; column; column = column->next) { - gchar *content; - int col; - - content = xmlNodeListGetString (column->doc, column->childs, 1); - col = atoi (content); - xmlFree (content); - - if (col >= max_cols) - continue; - - e_table_header_add_column (nh, e_table_header_get_column (full_header, col), -1); - } - - return nh; -} - -static void -et_grouping_xml_to_sort_info (ETable *table, xmlNode *grouping) -{ - int i; - - g_return_if_fail (table!=NULL); - g_return_if_fail (grouping!=NULL); - - table->sort_info = e_table_sort_info_new (); - - gtk_object_ref (GTK_OBJECT (table->sort_info)); - gtk_object_sink (GTK_OBJECT (table->sort_info)); - - i = 0; - for (grouping = grouping->childs; grouping && !strcmp (grouping->name, "group"); grouping = grouping->childs) { - ETableSortColumn column; - column.column = e_xml_get_integer_prop_by_name (grouping, "column"); - column.ascending = e_xml_get_integer_prop_by_name (grouping, "ascending"); - e_table_sort_info_grouping_set_nth(table->sort_info, i++, column); - } - i = 0; - for (; grouping && !strcmp (grouping->name, "leaf"); grouping = grouping->childs) { - ETableSortColumn column; - column.column = e_xml_get_integer_prop_by_name (grouping, "column"); - column.ascending = e_xml_get_integer_prop_by_name (grouping, "ascending"); - e_table_sort_info_sorting_set_nth(table->sort_info, i++, column); - } - - table->group_info_change_id = - gtk_signal_connect (GTK_OBJECT (table->sort_info), "group_info_changed", - GTK_SIGNAL_FUNC (sort_info_changed), table); -} - -static ETable * -et_real_construct (ETable *e_table, ETableHeader *full_header, ETableModel *etm, - xmlDoc *xmlSpec) -{ - xmlNode *xmlRoot; - xmlNode *xmlColumns; - xmlNode *xmlGrouping; - gboolean no_header; - int row = 0; - - xmlRoot = xmlDocGetRootElement (xmlSpec); - xmlColumns = e_xml_get_child_by_name (xmlRoot, "columns-shown"); - xmlGrouping = e_xml_get_child_by_name (xmlRoot, "grouping"); - - if ((xmlColumns == NULL) || (xmlGrouping == NULL)) - return NULL; - - no_header = e_xml_get_integer_prop_by_name(xmlRoot, "no-header"); - e_table->use_click_to_add = e_xml_get_integer_prop_by_name(xmlRoot, "click-to-add"); - - - e_table->full_header = full_header; - gtk_object_ref (GTK_OBJECT (full_header)); - - e_table->model = etm; - gtk_object_ref (GTK_OBJECT (etm)); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - e_table->header = et_xml_to_header (e_table, full_header, xmlColumns); - et_grouping_xml_to_sort_info (e_table, xmlGrouping); - - gtk_object_set(GTK_OBJECT(e_table->header), - "sort_info", e_table->sort_info, - NULL); - - e_table->sorter = e_table_sorter_new(etm, e_table->full_header, e_table->sort_info); - - gtk_object_set (GTK_OBJECT (e_table->selection), - "model", etm, - "sorter", e_table->sorter, - NULL); - - if (!no_header) { - e_table_setup_header (e_table); - } - e_table_setup_table (e_table, full_header, e_table->header, etm); - e_table_fill_table (e_table, etm); - - gtk_layout_get_vadjustment (GTK_LAYOUT (e_table->table_canvas))->step_increment = 20; - gtk_adjustment_changed(gtk_layout_get_vadjustment (GTK_LAYOUT (e_table->table_canvas))); - - if (!no_header) { - /* - * The header - */ - gtk_table_attach (GTK_TABLE (e_table), GTK_WIDGET (e_table->header_canvas), - 0, 1, 0 + row, 1 + row, - GTK_FILL | GTK_EXPAND, - GTK_FILL, 0, 0); - row ++; - } - gtk_table_attach (GTK_TABLE (e_table), GTK_WIDGET (e_table->table_canvas), - 0, 1, 0 + row, 1 + row, - GTK_FILL | GTK_EXPAND, - GTK_FILL | GTK_EXPAND, - 0, 0); - - gtk_widget_pop_colormap (); - gtk_widget_pop_visual (); - - return e_table; -} - -ETable * -e_table_construct (ETable *e_table, ETableHeader *full_header, - ETableModel *etm, const char *spec) -{ - xmlDoc *xmlSpec; - char *copy; - copy = g_strdup (spec); - - xmlSpec = xmlParseMemory (copy, strlen(copy)); - e_table = et_real_construct (e_table, full_header, etm, xmlSpec); - xmlFreeDoc (xmlSpec); - g_free (copy); - - return e_table; -} - -ETable * -e_table_construct_from_spec_file (ETable *e_table, ETableHeader *full_header, ETableModel *etm, - const char *filename) -{ - xmlDoc *xmlSpec; - - xmlSpec = xmlParseFile (filename); - e_table = et_real_construct (e_table, full_header, etm, xmlSpec); - xmlFreeDoc (xmlSpec); - - return e_table; -} - -GtkWidget * -e_table_new (ETableHeader *full_header, ETableModel *etm, const char *spec) -{ - ETable *e_table; - - e_table = gtk_type_new (e_table_get_type ()); - - e_table = e_table_construct (e_table, full_header, etm, spec); - - return GTK_WIDGET (e_table); -} - -GtkWidget * -e_table_new_from_spec_file (ETableHeader *full_header, ETableModel *etm, const char *filename) -{ - ETable *e_table; - - e_table = gtk_type_new (e_table_get_type ()); - - e_table = e_table_construct_from_spec_file (e_table, full_header, etm, filename); - - return (GtkWidget *) e_table; -} - -static xmlNode * -et_build_column_spec (ETable *e_table) -{ - xmlNode *columns_shown; - gint i; - gint col_count; - - columns_shown = xmlNewNode (NULL, "columns-shown"); - - col_count = e_table_header_count (e_table->header); - for (i = 0; i < col_count; i++){ - gchar *text = g_strdup_printf ("%d", e_table_header_index(e_table->header, i)); - xmlNewChild (columns_shown, NULL, "column", text); - g_free (text); - } - - return columns_shown; -} - -static xmlNode * -et_build_grouping_spec (ETable *e_table) -{ - xmlNode *node; - xmlNode *grouping; - int i; - const int sort_count = e_table_sort_info_sorting_get_count (e_table->sort_info); - const int group_count = e_table_sort_info_grouping_get_count (e_table->sort_info); - - grouping = xmlNewNode (NULL, "grouping"); - node = grouping; - - for (i = 0; i < group_count; i++) { - ETableSortColumn column = e_table_sort_info_grouping_get_nth(e_table->sort_info, i); - xmlNode *new_node = xmlNewChild(node, NULL, "group", NULL); - - e_xml_set_integer_prop_by_name (new_node, "column", column.column); - e_xml_set_integer_prop_by_name (new_node, "ascending", column.ascending); - node = new_node; - } - - for (i = 0; i < sort_count; i++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(e_table->sort_info, i); - xmlNode *new_node = xmlNewChild(node, NULL, "leaf", NULL); - - e_xml_set_integer_prop_by_name (new_node, "column", column.column); - e_xml_set_integer_prop_by_name (new_node, "ascending", column.ascending); - node = new_node; - } - - return grouping; -} - -static xmlDoc * -et_build_tree (ETable *e_table) -{ - xmlDoc *doc; - xmlNode *root; - - doc = xmlNewDoc ("1.0"); - if (doc == NULL) - return NULL; - - root = xmlNewDocNode (doc, NULL, "ETableSpecification", NULL); - xmlDocSetRootElement (doc, root); - xmlAddChild (root, et_build_column_spec (e_table)); - xmlAddChild (root, et_build_grouping_spec (e_table)); - - return doc; -} - -gchar * -e_table_get_specification (ETable *e_table) -{ - xmlDoc *doc; - xmlChar *buffer; - gint size; - - doc = et_build_tree (e_table); - xmlDocDumpMemory (doc, &buffer, &size); - xmlFreeDoc (doc); - - return buffer; -} - -void -e_table_save_specification (ETable *e_table, gchar *filename) -{ - xmlDoc *doc = et_build_tree (e_table); - - xmlSaveFile (filename, doc); - xmlFreeDoc (doc); -} - -void -e_table_set_cursor_row (ETable *e_table, int row) -{ - row = e_table_sorter_model_to_sorted(e_table->sorter, row); - if (row != -1) - e_table_group_set_cursor_row(e_table->group, row); -} - -int -e_table_get_cursor_row (ETable *e_table) -{ - int row = e_table_group_get_cursor_row(e_table->group); - row = e_table_sorter_sorted_to_model(e_table->sorter, row); - return row; -} - -void -e_table_selected_row_foreach (ETable *e_table, - ETableForeachFunc callback, - gpointer closure) -{ - e_table_selection_model_foreach(e_table->selection, - callback, - closure); -} - - -EPrintable * -e_table_get_printable (ETable *e_table) -{ - return e_table_group_get_printable(e_table->group); -} - -static void -et_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETable *etable = E_TABLE (o); - - switch (arg_id){ - case ARG_TABLE_DRAW_GRID: - GTK_VALUE_BOOL (*arg) = etable->draw_grid; - break; - - case ARG_TABLE_DRAW_FOCUS: - GTK_VALUE_BOOL (*arg) = etable->draw_focus; - break; - - case ARG_CLICK_TO_ADD_MESSAGE: - GTK_VALUE_STRING (*arg) = g_strdup (etable->click_to_add_message); - break; - } -} - -typedef struct { - char *arg; - gboolean setting; -} bool_closure; - -static void -et_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETable *etable = E_TABLE (o); - - switch (arg_id){ - case ARG_LENGTH_THRESHOLD: - etable->length_threshold = GTK_VALUE_INT (*arg); - if (etable->group) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etable->group), - "length_threshold", GTK_VALUE_INT (*arg), - NULL); - } - break; - - case ARG_TABLE_DRAW_GRID: - etable->draw_grid = GTK_VALUE_BOOL (*arg); - if (etable->group) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etable->group), - "drawgrid", GTK_VALUE_BOOL (*arg), - NULL); - } - break; - - case ARG_TABLE_DRAW_FOCUS: - etable->draw_focus = GTK_VALUE_BOOL (*arg); - if (etable->group) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etable->group), - "drawfocus", GTK_VALUE_BOOL (*arg), - NULL); - } - break; - - case ARG_CURSOR_MODE: - etable->cursor_mode = GTK_VALUE_INT (*arg); - if (etable->group) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etable->group), - "cursor_mode", GTK_VALUE_INT (*arg), - NULL); - } - break; - case ARG_CLICK_TO_ADD_MESSAGE: - if (etable->click_to_add_message) - g_free(etable->click_to_add_message); - etable->click_to_add_message = g_strdup(GTK_VALUE_STRING (*arg)); - if (etable->click_to_add) - gnome_canvas_item_set(etable->click_to_add, - "message", etable->click_to_add_message, - NULL); - break; - } -} - -static void -set_scroll_adjustments (ETable *table, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment) -{ - if (vadjustment != NULL) { - vadjustment->step_increment = 20; - gtk_adjustment_changed(vadjustment); - } - - gtk_layout_set_hadjustment (GTK_LAYOUT(table->table_canvas), - hadjustment); - gtk_layout_set_vadjustment (GTK_LAYOUT(table->table_canvas), - vadjustment); - gtk_layout_set_hadjustment (GTK_LAYOUT(table->header_canvas), - hadjustment); -} - -gint -e_table_get_next_row (ETable *e_table, - gint model_row) -{ - if (e_table->sorter) { - int i; - i = e_table_sorter_model_to_sorted(e_table->sorter, model_row); - i++; - if (i < e_table_model_row_count(e_table->model)) { - return e_table_sorter_sorted_to_model(e_table->sorter, i); - } else - return -1; - } else - if (model_row < e_table_model_row_count(e_table->model) - 1) - return model_row + 1; - else - return -1; -} - -gint -e_table_get_prev_row (ETable *e_table, - gint model_row) -{ - if (e_table->sorter) { - int i; - i = e_table_sorter_model_to_sorted(e_table->sorter, model_row); - i--; - if (i >= 0) - return e_table_sorter_sorted_to_model(e_table->sorter, i); - else - return -1; - } else - return model_row - 1; -} - -gint -e_table_model_to_view_row (ETable *e_table, - gint model_row) -{ - if (e_table->sorter) - return e_table_sorter_model_to_sorted(e_table->sorter, model_row); - else - return model_row; -} - -gint -e_table_view_to_model_row (ETable *e_table, - gint view_row) -{ - if (e_table->sorter) - return e_table_sorter_sorted_to_model(e_table->sorter, view_row); - else - return view_row; -} - -struct _ETableDragSourceSite -{ - GdkModifierType start_button_mask; - GtkTargetList *target_list; /* Targets for drag data */ - GdkDragAction actions; /* Possible actions */ - GdkColormap *colormap; /* Colormap for drag icon */ - GdkPixmap *pixmap; /* Icon for drag data */ - GdkBitmap *mask; - - /* Stored button press information to detect drag beginning */ - gint state; - gint x, y; - gint row, col; -}; - -typedef enum -{ - GTK_DRAG_STATUS_DRAG, - GTK_DRAG_STATUS_WAIT, - GTK_DRAG_STATUS_DROP -} GtkDragStatus; - -typedef struct _GtkDragDestInfo GtkDragDestInfo; -typedef struct _GtkDragSourceInfo GtkDragSourceInfo; - -struct _GtkDragDestInfo -{ - GtkWidget *widget; /* Widget in which drag is in */ - GdkDragContext *context; /* Drag context */ - GtkDragSourceInfo *proxy_source; /* Set if this is a proxy drag */ - GtkSelectionData *proxy_data; /* Set while retrieving proxied data */ - gboolean dropped : 1; /* Set after we receive a drop */ - guint32 proxy_drop_time; /* Timestamp for proxied drop */ - gboolean proxy_drop_wait : 1; /* Set if we are waiting for a - * status reply before sending - * a proxied drop on. - */ - gint drop_x, drop_y; /* Position of drop */ -}; - -struct _GtkDragSourceInfo -{ - GtkWidget *widget; - GtkTargetList *target_list; /* Targets for drag data */ - GdkDragAction possible_actions; /* Actions allowed by source */ - GdkDragContext *context; /* drag context */ - GtkWidget *icon_window; /* Window for drag */ - GtkWidget *ipc_widget; /* GtkInvisible for grab, message passing */ - GdkCursor *cursor; /* Cursor for drag */ - gint hot_x, hot_y; /* Hot spot for drag */ - gint button; /* mouse button starting drag */ - - GtkDragStatus status; /* drag status */ - GdkEvent *last_event; /* motion event waiting for response */ - - gint start_x, start_y; /* Initial position */ - gint cur_x, cur_y; /* Current Position */ - - GList *selections; /* selections we've claimed */ - - GtkDragDestInfo *proxy_dest; /* Set if this is a proxy drag */ - - guint drop_timeout; /* Timeout for aborting drop */ - guint destroy_icon : 1; /* If true, destroy icon_window - */ -}; - -/* Drag & drop stuff. */ -/* Target */ -void e_table_drag_get_data (ETable *table, - int row, - int col, - GdkDragContext *context, - GdkAtom target, - guint32 time) -{ - table->drag_get_data_row = row; - table->drag_get_data_col = col; - gtk_drag_get_data(GTK_WIDGET(table), - context, - target, - time); - -} - -void e_table_drag_highlight (ETable *table, - int row, - int col) /* col == -1 to highlight entire row. */ -{ -} - -void e_table_drag_unhighlight (ETable *table) -{ -} - -void e_table_drag_dest_set (ETable *table, - GtkDestDefaults flags, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions) -{ - 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) -{ - 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) -{ - gtk_drag_dest_unset(widget); -} - -/* Source side */ - -void e_table_drag_source_set (ETable *table, - GdkModifierType start_button_mask, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions) -{ - ETableDragSourceSite *site; - GtkWidget *canvas = GTK_WIDGET(table->table_canvas); - - g_return_if_fail (table != NULL); - - site = table->site; - - gtk_widget_add_events (canvas, - gtk_widget_get_events (canvas) | - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | - GDK_BUTTON_MOTION_MASK); - - if (site) { - if (site->target_list) - gtk_target_list_unref (site->target_list); - } else { - site = g_new0 (ETableDragSourceSite, 1); - - table->drag_source_button_press_event_id = - gtk_signal_connect (GTK_OBJECT (canvas), "button_press_event", - GTK_SIGNAL_FUNC (e_table_drag_source_event_cb), - table); - table->drag_source_motion_notify_event_id = - gtk_signal_connect (GTK_OBJECT (canvas), "motion_notify_event", - GTK_SIGNAL_FUNC (e_table_drag_source_event_cb), - table); - - table->site = site; - } - - site->start_button_mask = start_button_mask; - - if (targets) - site->target_list = gtk_target_list_new (targets, n_targets); - else - site->target_list = NULL; - - site->actions = actions; -} - -void e_table_drag_source_unset (ETable *table) -{ - ETableDragSourceSite *site; - - g_return_if_fail (table != NULL); - - site = table->site; - - if (site) { - gtk_signal_disconnect (GTK_OBJECT (table->table_canvas), table->drag_source_button_press_event_id); - gtk_signal_disconnect (GTK_OBJECT (table->table_canvas), table->drag_source_motion_notify_event_id); - g_free(site); - table->site = NULL; - } -} - -/* There probably should be functions for setting the targets - * as a GtkTargetList - */ - -GdkDragContext * -e_table_drag_begin (ETable *table, - int row, - int col, - GtkTargetList *targets, - GdkDragAction actions, - gint button, - GdkEvent *event) -{ - table->drag_row = row; - table->drag_col = col; - - return gtk_drag_begin(GTK_WIDGET(table), - targets, - actions, - button, - event); -} - -static void -e_table_compute_location(ETable *table, - GtkWidget *widget, - int x, - int y, - int *row, - int *col) -{ - if (!(row || col)) - return; - e_table_group_compute_location(table->group, &x, &y, row, col); -} - -static void -et_drag_begin (GtkWidget *widget, - GdkDragContext *context, - ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_BEGIN], - et->drag_row, - et->drag_col, - context); -} - -static void -et_drag_end (GtkWidget *widget, - GdkDragContext *context, - ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_END], - et->drag_row, - et->drag_col, - context); -} - -static void -et_drag_data_get(GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_DATA_GET], - et->drag_row, - et->drag_col, - context, - selection_data, - info, - time); -} - -static void -et_drag_data_delete(GtkWidget *widget, - GdkDragContext *context, - ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_DATA_DELETE], - et->drag_row, - et->drag_col, - context); -} - -static void -et_drag_leave(GtkWidget *widget, - GdkDragContext *context, - guint time, - ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_LEAVE], - et->drop_row, - et->drop_col, - context, - time); - et->drop_row = -1; - et->drop_col = -1; -} - -static gboolean -et_drag_motion(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETable *et) -{ - gboolean ret_val; - int row, col; - e_table_compute_location(et, - widget, - x, - y, - &row, - &col); - if (et->drop_row >= 0 && et->drop_col >= 0 && - row != et->drop_row && col != et->drop_row) { - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_LEAVE], - et->drop_row, - et->drop_col, - context, - time); - } - et->drop_row = row; - et->drop_col = col; - if (row >= 0 && col >= 0) - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_MOTION], - et->drop_row, - et->drop_col, - context, - x, - y, - time, - &ret_val); - return ret_val; -} - -static gboolean -et_drag_drop(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETable *et) -{ - gboolean ret_val; - int row, col; - e_table_compute_location(et, - widget, - x, - y, - &row, - &col); - if (et->drop_row >= 0 && et->drop_col >= 0 && - row != et->drop_row && col != et->drop_row) { - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_LEAVE], - et->drop_row, - et->drop_col, - context, - time); - if (row >= 0 && col >= 0) - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_MOTION], - row, - col, - context, - x, - y, - time, - &ret_val); - } - et->drop_row = row; - et->drop_col = col; - if (row >= 0 && col >= 0) - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_DROP], - et->drop_row, - et->drop_col, - context, - x, - y, - time, - &ret_val); - et->drop_row = -1; - et->drop_col = -1; - return ret_val; -} - -static void -et_drag_data_received(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time, - ETable *et) -{ - int row, col; - e_table_compute_location(et, - widget, - x, - y, - &row, - &col); - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_MOTION], - row, - col, - context, - x, - y, - selection_data, - info, - time); -} - -static gint -e_table_drag_source_event_cb (GtkWidget *widget, - GdkEvent *event, - ETable *table) -{ - ETableDragSourceSite *site; - site = table->site; - - switch (event->type) { - case GDK_BUTTON_PRESS: - if ((GDK_BUTTON1_MASK << (event->button.button - 1)) & site->start_button_mask) { - int row, col; - e_table_compute_location(table, widget, event->button.x, event->button.y, &row, &col); - if (row >= 0 && col >= 0) { - site->state |= (GDK_BUTTON1_MASK << (event->button.button - 1)); - site->x = event->button.x; - site->y = event->button.y; - site->row = row; - site->col = col; - } - } - break; - - case GDK_BUTTON_RELEASE: - if ((GDK_BUTTON1_MASK << (event->button.button - 1)) & site->start_button_mask) { - site->state &= ~(GDK_BUTTON1_MASK << (event->button.button - 1)); - } - break; - - case GDK_MOTION_NOTIFY: - if (site->state & event->motion.state & site->start_button_mask) { - /* FIXME: This is really broken and can leave us - * with a stuck grab - */ - int i; - for (i=1; i<6; i++) { - if (site->state & event->motion.state & - GDK_BUTTON1_MASK << (i - 1)) - break; - } - - if (MAX (abs (site->x - event->motion.x), - abs (site->y - event->motion.y)) > 3) { - GtkDragSourceInfo *info; - GdkDragContext *context; - - site->state = 0; - context = e_table_drag_begin (table, site->row, site->col, - site->target_list, - site->actions, - i, event); - - - info = g_dataset_get_data (context, "gtk-info"); - - if (!info->icon_window) { - if (site->pixmap) - gtk_drag_set_icon_pixmap (context, - site->colormap, - site->pixmap, - site->mask, -2, -2); - else - gtk_drag_set_icon_default (context); - } - - return TRUE; - } - } - break; - - default: /* hit for 2/3BUTTON_PRESS */ - break; - } - return FALSE; -} - -static void -e_table_class_init (GtkObjectClass *object_class) -{ - ETableClass *klass = E_TABLE_CLASS(object_class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(object_class); - - e_table_parent_class = gtk_type_class (PARENT_TYPE); - - object_class->destroy = et_destroy; - object_class->set_arg = et_set_arg; - object_class->get_arg = et_get_arg; - - klass->cursor_change = NULL; - klass->double_click = NULL; - klass->right_click = NULL; - klass->key_press = NULL; - - klass->table_drag_begin = NULL; - klass->table_drag_end = NULL; - klass->table_drag_data_get = NULL; - klass->table_drag_data_delete = NULL; - - klass->table_drag_leave = NULL; - klass->table_drag_motion = NULL; - klass->table_drag_drop = NULL; - klass->table_drag_data_received = NULL; - - et_signals [CURSOR_CHANGE] = - gtk_signal_new ("cursor_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, cursor_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - et_signals [DOUBLE_CLICK] = - gtk_signal_new ("double_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, double_click), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - et_signals [RIGHT_CLICK] = - gtk_signal_new ("right_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, right_click), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - et_signals [KEY_PRESS] = - gtk_signal_new ("key_press", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, key_press), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - et_signals[TABLE_DRAG_BEGIN] = - gtk_signal_new ("table_drag_begin", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_begin), - gtk_marshal_NONE__INT_INT_POINTER, - GTK_TYPE_NONE, 3, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT); - et_signals[TABLE_DRAG_END] = - gtk_signal_new ("table_drag_end", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_end), - gtk_marshal_NONE__INT_INT_POINTER, - GTK_TYPE_NONE, 3, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT); - et_signals[TABLE_DRAG_DATA_GET] = - gtk_signal_new ("table_drag_data_get", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_data_get), - e_marshal_NONE__INT_INT_POINTER_POINTER_UINT_UINT, - GTK_TYPE_NONE, 6, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT, - GTK_TYPE_SELECTION_DATA, - GTK_TYPE_UINT, - GTK_TYPE_UINT); - et_signals[TABLE_DRAG_DATA_DELETE] = - gtk_signal_new ("table_drag_data_delete", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_data_delete), - gtk_marshal_NONE__INT_INT_POINTER, - GTK_TYPE_NONE, 3, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT); - - et_signals[TABLE_DRAG_LEAVE] = - gtk_signal_new ("table_drag_leave", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_leave), - e_marshal_NONE__INT_INT_POINTER_UINT, - GTK_TYPE_NONE, 4, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT, - GTK_TYPE_UINT); - et_signals[TABLE_DRAG_MOTION] = - gtk_signal_new ("table_drag_motion", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_motion), - e_marshal_BOOL__INT_INT_POINTER_INT_INT_UINT, - GTK_TYPE_BOOL, 6, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_UINT); - et_signals[TABLE_DRAG_DROP] = - gtk_signal_new ("table_drag_drop", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_drop), - e_marshal_BOOL__INT_INT_POINTER_INT_INT_UINT, - GTK_TYPE_BOOL, 6, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_UINT); - et_signals[TABLE_DRAG_DATA_RECEIVED] = - gtk_signal_new ("table_drag_data_received", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_data_received), - e_marshal_NONE__INT_INT_POINTER_INT_INT_POINTER_UINT_UINT, - GTK_TYPE_NONE, 8, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_SELECTION_DATA, - GTK_TYPE_UINT, - GTK_TYPE_UINT); - - gtk_object_class_add_signals (object_class, et_signals, LAST_SIGNAL); - - klass->set_scroll_adjustments = set_scroll_adjustments; - - widget_class->set_scroll_adjustments_signal = - gtk_signal_new ("set_scroll_adjustments", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, set_scroll_adjustments), - gtk_marshal_NONE__POINTER_POINTER, - GTK_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT); - - gtk_object_add_arg_type ("ETable::drawgrid", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_TABLE_DRAW_GRID); - gtk_object_add_arg_type ("ETable::drawfocus", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_TABLE_DRAW_FOCUS); - gtk_object_add_arg_type ("ETable::cursor_mode", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_CURSOR_MODE); - gtk_object_add_arg_type ("ETable::length_threshold", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_LENGTH_THRESHOLD); - gtk_object_add_arg_type ("ETable::click_to_add_message", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_CLICK_TO_ADD_MESSAGE); -} - -E_MAKE_TYPE(e_table, "ETable", ETable, e_table_class_init, e_table_init, PARENT_TYPE); - diff --git a/widgets/e-table/e-table.h b/widgets/e-table/e-table.h deleted file mode 100644 index 19dcbfecc8..0000000000 --- a/widgets/e-table/e-table.h +++ /dev/null @@ -1,252 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_H_ -#define _E_TABLE_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gtk/gtktable.h> -#include <gnome-xml/tree.h> -#include "e-table-model.h" -#include "e-table-header.h" -#include "e-table-group.h" -#include "e-table-sort-info.h" -#include "e-table-item.h" -#include "e-table-selection-model.h" -#include "e-util/e-printable.h" - -BEGIN_GNOME_DECLS - -#define E_TABLE_TYPE (e_table_get_type ()) -#define E_TABLE(o) (GTK_CHECK_CAST ((o), E_TABLE_TYPE, ETable)) -#define E_TABLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_TYPE, ETableClass)) -#define E_IS_TABLE(o) (GTK_CHECK_TYPE ((o), E_TABLE_TYPE)) -#define E_IS_TABLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_TYPE)) - -typedef struct _ETableDragSourceSite ETableDragSourceSite; - -typedef enum { - E_TABLE_CURSOR_LOC_NONE = 0, - E_TABLE_CURSOR_LOC_ETCTA = 1 << 0, - E_TABLE_CURSOR_LOC_TABLE = 1 << 1, -} ETableCursorLoc; - -typedef struct { - GtkTable parent; - - ETableModel *model; - - ETableHeader *full_header, *header; - - GnomeCanvasItem *canvas_vbox; - ETableGroup *group; - - ETableSortInfo *sort_info; - ETableSorter *sorter; - - ETableSelectionModel *selection; - ETableCursorLoc cursor_loc; - - int table_model_change_id; - int table_row_change_id; - int table_cell_change_id; - int table_row_inserted_id; - int table_row_deleted_id; - - int group_info_change_id; - - int reflow_idle_id; - - GnomeCanvas *header_canvas, *table_canvas; - - GnomeCanvasItem *header_item, *root; - - gint length_threshold; - - gint rebuild_idle_id; - guint need_rebuild:1; - - /* - * Configuration settings - */ - guint draw_grid : 1; - guint draw_focus : 1; - guint row_selection_active : 1; - - char *click_to_add_message; - GnomeCanvasItem *click_to_add; - gboolean use_click_to_add; - - ETableCursorMode cursor_mode; - - int drag_get_data_row; - int drag_get_data_col; - - int drop_row; - int drop_col; - - int drag_row; - int drag_col; - ETableDragSourceSite *site; - - int drag_source_button_press_event_id; - int drag_source_motion_notify_event_id; -} ETable; - -typedef struct { - GtkTableClass parent_class; - - void (*cursor_change) (ETable *et, int row); - void (*double_click) (ETable *et, int row); - gint (*right_click) (ETable *et, int row, int col, GdkEvent *event); - gint (*key_press) (ETable *et, int row, int col, GdkEvent *event); - - void (*set_scroll_adjustments) (ETable *table, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); - - /* Source side drag signals */ - void (* table_drag_begin) (ETable *table, - int row, - int col, - GdkDragContext *context); - void (* table_drag_end) (ETable *table, - int row, - int col, - GdkDragContext *context); - void (* table_drag_data_get) (ETable *table, - int row, - int col, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time); - void (* table_drag_data_delete) (ETable *table, - int row, - int col, - GdkDragContext *context); - - /* Target side drag signals */ - void (* table_drag_leave) (ETable *table, - int row, - int col, - GdkDragContext *context, - guint time); - gboolean (* table_drag_motion) (ETable *table, - int row, - int col, - GdkDragContext *context, - gint x, - gint y, - guint time); - gboolean (* table_drag_drop) (ETable *table, - int row, - int col, - GdkDragContext *context, - gint x, - gint y, - guint time); - void (* table_drag_data_received) (ETable *table, - int row, - int col, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time); -} ETableClass; - -GtkType e_table_get_type (void); - -ETable *e_table_construct (ETable *e_table, ETableHeader *full_header, ETableModel *etm, - const char *spec); -GtkWidget *e_table_new (ETableHeader *full_header, ETableModel *etm, - const char *spec); - -ETable *e_table_construct_from_spec_file (ETable *e_table, - ETableHeader *full_header, - ETableModel *etm, - const char *filename); -GtkWidget *e_table_new_from_spec_file (ETableHeader *full_header, - ETableModel *etm, - const char *filename); - -gchar *e_table_get_specification (ETable *e_table); -void e_table_save_specification (ETable *e_table, gchar *filename); - -void e_table_set_cursor_row (ETable *e_table, - int row); -/* -1 means we don't have the cursor. */ -int e_table_get_cursor_row (ETable *e_table); -void e_table_selected_row_foreach (ETable *e_table, - ETableForeachFunc callback, - gpointer closure); -EPrintable *e_table_get_printable (ETable *e_table); - -gint e_table_get_next_row (ETable *e_table, - gint model_row); -gint e_table_get_prev_row (ETable *e_table, - gint model_row); - -gint e_table_model_to_view_row (ETable *e_table, - gint model_row); -gint e_table_view_to_model_row (ETable *e_table, - gint view_row); - - -/* Drag & drop stuff. */ -/* Target */ -void e_table_drag_get_data (ETable *table, - int row, - int col, - GdkDragContext *context, - GdkAtom target, - guint32 time); - -void e_table_drag_highlight (ETable *table, - int row, - int col); /* col == -1 to highlight entire row. */ -void e_table_drag_unhighlight (ETable *table); - -void e_table_drag_dest_set (ETable *table, - GtkDestDefaults flags, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions); - -void e_table_drag_dest_set_proxy (ETable *table, - GdkWindow *proxy_window, - GdkDragProtocol protocol, - gboolean use_coordinates); - -/* There probably should be functions for setting the targets - * as a GtkTargetList - */ - -void e_table_drag_dest_unset (GtkWidget *widget); - -/* Source side */ - -void e_table_drag_source_set (ETable *table, - GdkModifierType start_button_mask, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions); - -void e_table_drag_source_unset (ETable *table); - -/* There probably should be functions for setting the targets - * as a GtkTargetList - */ - -GdkDragContext *e_table_drag_begin (ETable *table, - int row, - int col, - GtkTargetList *targets, - GdkDragAction actions, - gint button, - GdkEvent *event); - -END_GNOME_DECLS - -#endif /* _E_TABLE_H_ */ - diff --git a/widgets/e-table/e-tree-example-1.c b/widgets/e-table/e-tree-example-1.c deleted file mode 100644 index 308f462f64..0000000000 --- a/widgets/e-table/e-tree-example-1.c +++ /dev/null @@ -1,403 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* This code is GPL. */ -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "e-util/e-cursors.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-cell-tree.h" -#include "e-cell-checkbox.h" -#include "e-table.h" -#include "e-tree-simple.h" -#include "libgnomeprint/gnome-print.h" -#include "libgnomeprint/gnome-print-preview.h" - -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include "tree-expanded.xpm" -#include "tree-unexpanded.xpm" - -GdkPixbuf *tree_expanded_pixbuf; -GdkPixbuf *tree_unexpanded_pixbuf; - -#define COLS 4 - -#define IMPORTANCE_COLUMN 4 -#define COLOR_COLUMN 5 - -/* - * Here we define the initial layout of the table. This is an xml - * format that allows you to change the initial ordering of the - * columns or to do sorting or grouping initially. This specification - * shows all 5 columns, but moves the importance column nearer to the - * front. It also sorts by the "Full Name" column (ascending.) - * Sorting and grouping take the model column as their arguments - * (sorting is specified by the "column" argument to the leaf elemnt. - */ - -#define INITIAL_SPEC "<ETableSpecification> \ - <columns-shown> \ - <column> 0 </column> \ - <column> 4 </column> \ - <column> 1 </column> \ - <column> 2 </column> \ - <column> 3 </column> \ - </columns-shown> \ - <grouping></grouping> \ -</ETableSpecification>" - -/* - * Virtual Column list: - * 0 Subject - * 1 Full Name - * 2 Email - * 3 Date - */ -char *headers [COLS] = { - "Subject", - "Full Name", - "Email", - "Date" -}; - -GtkWidget *e_table; - -/* - * ETreeSimple callbacks - * These are the callbacks that define the behavior of our custom model. - */ - -/* This function returns the value at a particular point in our ETreeModel. */ -static void * -my_value_at (ETreeModel *etm, ETreePath *path, int col, void *model_data) -{ - switch (col) { - case 0: return e_tree_model_node_get_data (etm, path); - case 1: return "Chris Toshok"; - case 2: return "toshok@helixcode.com"; - case 3: return "Jun 07 2000"; - default: return NULL; - } -} - -static GdkPixbuf * -my_icon_at (ETreeModel *etm, ETreePath *path, void *model_data) -{ - if (e_tree_model_node_is_expanded (etm, path)) - return tree_expanded_pixbuf; - else - return tree_unexpanded_pixbuf; -} - -/* This function sets the value at a particular point in our ETreeModel. */ -static void -my_set_value_at (ETreeModel *etm, ETreePath *path, int col, const void *val, void *model_data) -{ - if (col == 0) { - char *str = e_tree_model_node_get_data (etm, path); - g_free (str); - e_tree_model_node_set_data (etm, path, g_strdup(val)); - } -} - -/* This function returns whether a particular cell is editable. */ -static gboolean -my_is_editable (ETreeModel *etm, ETreePath *path, int col, void *model_data) -{ - if (col == 0) - return TRUE; - else - return FALSE; -} - -static void -toggle_root (GtkButton *button, gpointer data) -{ - ETreeModel *e_tree_model = (ETreeModel*)data; - e_tree_model_root_node_set_visible (e_tree_model, !e_tree_model_root_node_is_visible (e_tree_model)); -} - -static void -add_sibling (GtkButton *button, gpointer data) -{ - ETreeModel *e_tree_model = E_TREE_MODEL (data); - int selected_row; - ETreePath *selected_node; - ETreePath *parent_node; - - selected_row = e_table_get_cursor_row (E_TABLE (e_table)); - if (selected_row == -1) - return; - - selected_node = e_tree_model_node_at_row (e_tree_model, selected_row); - g_assert (selected_node); - - parent_node = e_tree_model_node_get_parent (e_tree_model, selected_node); - - e_tree_model_node_insert_before (e_tree_model, parent_node, - selected_node, - g_strdup("User added sibling")); - -} - -static void -add_child (GtkButton *button, gpointer data) -{ - ETreeModel *e_tree_model = E_TREE_MODEL (data); - int selected_row; - ETreePath *selected_node; - - selected_row = e_table_get_cursor_row (E_TABLE (e_table)); - if (selected_row == -1) - return; - - selected_node = e_tree_model_node_at_row (e_tree_model, selected_row); - g_assert (selected_node); - - e_tree_model_node_insert (e_tree_model, selected_node, - 0, - g_strdup("User added child")); -} - -static void -remove_node (GtkButton *button, gpointer data) -{ - ETreeModel *e_tree_model = E_TREE_MODEL (data); - int selected_row; - char *str; - ETreePath *selected_node; - - selected_row = e_table_get_cursor_row (E_TABLE (e_table)); - if (selected_row == -1) - return; - - selected_node = e_tree_model_node_at_row (e_tree_model, selected_row); - g_assert (selected_node); - - if (e_tree_model_node_get_children (e_tree_model, selected_node, NULL) > 0) - return; - - str = (char*)e_tree_model_node_remove (e_tree_model, selected_node); - printf ("removed node %s\n", str); - g_free (str); -} - -static void -expand_all (GtkButton *button, gpointer data) -{ - ETreeModel *e_tree_model = E_TREE_MODEL (data); - int selected_row; - ETreePath *selected_node; - - selected_row = e_table_get_cursor_row (E_TABLE (e_table)); - if (selected_row == -1) - return; - - selected_node = e_tree_model_node_at_row (e_tree_model, selected_row); - g_assert (selected_node); - - e_tree_model_node_set_expanded_recurse (e_tree_model, selected_node, TRUE); -} - -static void -collapse_all (GtkButton *button, gpointer data) -{ - ETreeModel *e_tree_model = E_TREE_MODEL (data); - int selected_row; - ETreePath *selected_node; - - selected_row = e_table_get_cursor_row (E_TABLE (e_table)); - if (selected_row == -1) - return; - - selected_node = e_tree_model_node_at_row (e_tree_model, selected_row); - g_assert (selected_node); - - e_tree_model_node_set_expanded_recurse (e_tree_model, selected_node, FALSE); -} - -static void -print_tree (GtkButton *button, gpointer data) -{ - EPrintable *printable = e_table_get_printable (E_TABLE (e_table)); - GnomePrintContext *gpc; - - gpc = gnome_print_context_new (gnome_printer_new_generic_ps ("tree-out.ps")); - - e_printable_print_page (printable, gpc, 8*72, 10*72, FALSE); - - gnome_print_context_close (gpc); -} - -/* We create a window containing our new tree. */ -static void -create_tree (void) -{ - GtkWidget *window, *frame, *button, *vbox; - ECell *cell_left_just; - ECell *cell_tree; - ETableHeader *e_table_header; - int i, j; - ETreeModel *e_tree_model = NULL; - ETreePath *root_node; - - /* here we create our model. This uses the functions we defined - earlier. */ - e_tree_model = e_tree_simple_new (my_icon_at, - my_value_at, - my_set_value_at, - my_is_editable, - NULL); - - /* create a root node with 5 children */ - root_node = e_tree_model_node_insert (e_tree_model, NULL, - 0, - g_strdup("Root Node")); - - for (i = 0; i < 5; i++){ - ETreePath *n = e_tree_model_node_insert (e_tree_model, - root_node, 0, - g_strdup("First level of children")); - for (j = 0; j < 5; j ++) { - e_tree_model_node_insert (e_tree_model, - n, 0, - g_strdup("Second level of children")); - } - } - - /* - * Next we create a header. The ETableHeader is used in two - * different way. The first is the full_header. This is the - * list of possible columns in the view. The second use is - * completely internal. Many of the ETableHeader functions are - * for that purpose. The only functions we really need are - * e_table_header_new and e_table_header_add_col. - * - * First we create the header. - */ - e_table_header = e_table_header_new (); - - /* - * Next we have to build renderers for all of the columns. - * Since all our columns are text columns, we can simply use - * the same renderer over and over again. If we had different - * types of columns, we could use a different renderer for - * each column. - */ - cell_left_just = e_cell_text_new (E_TABLE_MODEL(e_tree_model), NULL, GTK_JUSTIFY_LEFT); - - /* - * This renderer is used for the tree column (the leftmost one), and - * has as its subcell renderer the text renderer. this means that - * text is displayed to the right of the tree pipes. - */ - cell_tree = e_cell_tree_new (E_TABLE_MODEL(e_tree_model), - tree_expanded_pixbuf, tree_unexpanded_pixbuf, - TRUE, cell_left_just); - - /* - * Next we create a column object for each view column and add - * them to the header. We don't create a column object for - * the importance column since it will not be shown. - */ - for (i = 0; i < COLS; i++) { - /* Create the column. */ - ETableCol *ecol = e_table_col_new ( - i, headers [i], - 80, 20, - i == 0 ? cell_tree - : cell_left_just, - g_str_compare, TRUE); - /* Add it to the header. */ - e_table_header_add_column (e_table_header, ecol, i); - } - - /* - * Here we create a window for our new table. This window - * will get shown and the person will be able to test their - * item. - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - - /* This frame is simply to get a bevel around our table. */ - vbox = gtk_vbox_new (FALSE, 0); - frame = gtk_frame_new (NULL); - - /* - * Here we create the table. We give it the three pieces of - * the table we've created, the header, the model, and the - * initial layout. It does the rest. - */ - e_table = e_table_new (e_table_header, E_TABLE_MODEL(e_tree_model), INITIAL_SPEC); - - if (!e_table) printf ("BAH!"); - - /* Build the gtk widget hierarchy. */ - gtk_container_add (GTK_CONTAINER (frame), e_table); - gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0); - - button = gtk_button_new_with_label ("Toggle Root Node"); - gtk_signal_connect (GTK_OBJECT (button), "clicked", toggle_root, e_tree_model); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - button = gtk_button_new_with_label ("Add Sibling"); - gtk_signal_connect (GTK_OBJECT (button), "clicked", add_sibling, e_tree_model); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - button = gtk_button_new_with_label ("Add Child"); - gtk_signal_connect (GTK_OBJECT (button), "clicked", add_child, e_tree_model); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - button = gtk_button_new_with_label ("Remove Node"); - gtk_signal_connect (GTK_OBJECT (button), "clicked", remove_node, e_tree_model); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - button = gtk_button_new_with_label ("Expand All Below"); - gtk_signal_connect (GTK_OBJECT (button), "clicked", expand_all, e_tree_model); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - button = gtk_button_new_with_label ("Collapse All Below"); - gtk_signal_connect (GTK_OBJECT (button), "clicked", collapse_all, e_tree_model); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - button = gtk_button_new_with_label ("Print Tree"); - gtk_signal_connect (GTK_OBJECT (button), "clicked", print_tree, e_tree_model); - gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - gtk_container_add (GTK_CONTAINER (window), vbox); - - /* Size the initial window. */ - gtk_widget_set_usize (window, 200, 200); - - /* Show it all. */ - gtk_widget_show_all (window); -} - -/* This is the main function which just initializes gnome and call our create_tree function */ - -int -main (int argc, char *argv []) -{ - gnome_init ("TableExample", "TableExample", argc, argv); - e_cursors_init (); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - /* - * Create our pixbuf for expanding/unexpanding - */ - tree_expanded_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)tree_expanded_xpm); - tree_unexpanded_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)tree_unexpanded_xpm); - - create_tree (); - - gtk_main (); - - e_cursors_shutdown (); - return 0; -} - diff --git a/widgets/e-table/e-tree-model.c b/widgets/e-table/e-tree-model.c deleted file mode 100644 index c57bf2d683..0000000000 --- a/widgets/e-table/e-tree-model.c +++ /dev/null @@ -1,760 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-tree-model.c: a Tree Model - * - * Author: - * Chris Toshok (toshok@helixcode.com) - * - * Adapted from the gtree code and ETableModel. - * - * (C) 2000 Helix Code, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include <stdlib.h> -#include "e-util/e-util.h" -#include "e-tree-model.h" - -#define ETM_CLASS(e) ((ETreeModelClass *)((GtkObject *)e)->klass) - -#define PARENT_TYPE E_TABLE_MODEL_TYPE - -static ETableModel *e_tree_model_parent_class; - -typedef struct { - gboolean expanded; - guint visible_descendents; - gpointer node_data; -} ENode; - -enum { - NODE_CHANGED, - NODE_INSERTED, - NODE_REMOVED, - LAST_SIGNAL -}; - -static guint e_tree_model_signals [LAST_SIGNAL] = {0, }; - -static void add_visible_descendents_to_array (ETreeModel *etm, GNode *gnode, int *row, int *count); - - -/* virtual methods */ - -static void -etree_destroy (GtkObject *object) -{ - ETreeModel *etree = E_TREE_MODEL (object); - - /* XXX lots of stuff to free here */ - g_array_free (etree->row_array, TRUE); - - GTK_OBJECT_CLASS (e_tree_model_parent_class)->destroy (object); -} - -static ETreePath* -etree_get_root (ETreeModel *etm) -{ - return etm->root; -} - -static ETreePath* -etree_get_parent (ETreeModel *etm, ETreePath *path) -{ - g_return_val_if_fail (path, NULL); - - return path->parent; -} - -static ETreePath* -etree_get_next (ETreeModel *etm, ETreePath *node) -{ - g_return_val_if_fail (node, NULL); - - return g_node_next_sibling(node); -} - -static ETreePath* -etree_get_prev (ETreeModel *etm, ETreePath *node) -{ - g_return_val_if_fail (node, NULL); - - return g_node_prev_sibling (node); -} - -static guint -etree_get_children (ETreeModel *etm, ETreePath* node, ETreePath ***paths) -{ - guint n_children; - - g_return_val_if_fail (node, 0); - - n_children = g_node_n_children (node); - - if (paths) { - int i; - (*paths) = g_malloc (sizeof (ETreePath*) * n_children); - for (i = 0; i < n_children; i ++) { - (*paths)[i] = g_node_nth_child (node, i); - } - } - - return n_children; -} - -static gboolean -etree_is_expanded (ETreeModel *etm, ETreePath* node) -{ - g_return_val_if_fail (node && node->data, FALSE); - - return ((ENode*)node->data)->expanded; -} - -static gboolean -etree_is_visible (ETreeModel *etm, ETreePath* node) -{ - g_return_val_if_fail (node, FALSE); - - for (node = node->parent; node; node = node->parent) { - if (!((ENode*)node->data)->expanded) - return FALSE; - } - - return TRUE; -} - -static void -etree_set_expanded (ETreeModel *etm, ETreePath* node, gboolean expanded) -{ - GNode *child; - ENode *enode; - int row; - - g_return_if_fail (node && node->data); - - enode = ((ENode*)node->data); - - if (enode->expanded == expanded) - return; - - enode->expanded = expanded; - - /* if the node wasn't visible at present */ - if ((row = e_tree_model_row_of_node (etm, node)) == -1) - return; - - row++; - - if (expanded) { - GNode *parent; - - if (e_tree_model_node_is_visible (etm, node)) { - enode->visible_descendents = 0; - for (child = g_node_first_child (node); child; - child = g_node_next_sibling (child)) { - add_visible_descendents_to_array (etm, child, &row, &enode->visible_descendents); - } - } - /* now iterate back up the tree, adding to our - ancestors' visible descendents */ - - for (parent = node->parent; parent; parent = parent->parent) { - ENode *parent_enode = (ENode*)parent->data; - parent_enode->visible_descendents += enode->visible_descendents; - } - } - else { - int i; - GNode *parent; - - if (e_tree_model_node_is_visible (etm, node)) { - for (i = 0; i < enode->visible_descendents; i ++) { - etm->row_array = g_array_remove_index (etm->row_array, row); - e_table_model_row_deleted (E_TABLE_MODEL (etm), row); - } - } - /* now iterate back up the tree, subtracting from our - ancestors' visible descendents */ - - for (parent = node->parent; parent; parent = parent->parent) { - ENode *parent_enode = (ENode*)parent->data; - - parent_enode->visible_descendents -= enode->visible_descendents; - } - - enode->visible_descendents = 0; - } -} - -/* fairly naive implementation */ -static void -etree_set_expanded_recurse (ETreeModel *etm, ETreePath* node, gboolean expanded) -{ - ETreePath **paths; - guint num_children; - int i; - - e_tree_model_node_set_expanded (etm, node, expanded); - - num_children = e_tree_model_node_get_children (etm, node, &paths); - if (num_children) { - for (i = 0; i < num_children; i ++) { - e_tree_model_node_set_expanded_recurse (etm, paths[i], expanded); - } - - g_free (paths); - } -} - -static ETreePath * -etree_node_at_row (ETreeModel *etree, int row) -{ - g_return_val_if_fail (row < etree->row_array->len, NULL); - - return g_array_index (etree->row_array, GNode*, row); -} - - -/* ETable analogs */ -static void* -etree_value_at (ETreeModel *etm, ETreePath* node, int col) -{ - /* shouldn't be called */ - g_assert (0); - return NULL; -} - -static GdkPixbuf* -etree_icon_at (ETreeModel *etm, ETreePath* node) -{ - /* shouldn't be called */ - g_assert (0); - return NULL; -} - -static void -etree_set_value_at (ETreeModel *etm, ETreePath* node, int col, const void *val) -{ - /* shouldn't be called */ - g_assert (0); -} - -static gboolean -etree_is_editable (ETreeModel *etm, ETreePath* node, int col) -{ - /* shouldn't be called */ - g_assert(0); - return FALSE; -} - - -/* ETable virtual functions we map */ -static int -etable_row_count (ETableModel *etm) -{ - ETreeModel *tree = E_TREE_MODEL (etm); - return tree->row_array->len; -} - -static void * -etable_value_at (ETableModel *etm, int col, int row) -{ - ETreeModel *etree = E_TREE_MODEL(etm); - ETreeModelClass *et_class = ETM_CLASS(etm); - ETreePath* node = e_tree_model_node_at_row (etree, row); - - g_return_val_if_fail (node, NULL); - - if (col == -1) - return node; - else if (col == -2) - return etm; - else - return et_class->value_at (etree, node, col); -} - -static void -etable_set_value_at (ETableModel *etm, int col, int row, const void *val) -{ - ETreeModel *etree = E_TREE_MODEL(etm); - ETreeModelClass *et_class = ETM_CLASS(etm); - ETreePath* node = e_tree_model_node_at_row (etree, row); - - g_return_if_fail (node); - - et_class->set_value_at (etree, node, col, val); -} - -static gboolean -etable_is_cell_editable (ETableModel *etm, int col, int row) -{ - ETreeModel *etree = E_TREE_MODEL(etm); - ETreeModelClass *et_class = ETM_CLASS(etm); - ETreePath* node = e_tree_model_node_at_row (etree, row); - - g_return_val_if_fail (node, FALSE); - - return et_class->is_editable (etree, node, col); -} - - -static void -e_tree_model_class_init (GtkObjectClass *klass) -{ - ETableModelClass *table_class = (ETableModelClass *) klass; - ETreeModelClass *tree_class = (ETreeModelClass *) klass; - - e_tree_model_parent_class = gtk_type_class (PARENT_TYPE); - - klass->destroy = etree_destroy; - - e_tree_model_signals [NODE_CHANGED] = - gtk_signal_new ("node_changed", - GTK_RUN_LAST, - klass->type, - GTK_SIGNAL_OFFSET (ETreeModelClass, node_changed), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, GTK_TYPE_POINTER); - - e_tree_model_signals [NODE_INSERTED] = - gtk_signal_new ("node_inserted", - GTK_RUN_LAST, - klass->type, - GTK_SIGNAL_OFFSET (ETreeModelClass, node_inserted), - gtk_marshal_NONE__POINTER_POINTER, - GTK_TYPE_NONE, 2, GTK_TYPE_POINTER, GTK_TYPE_POINTER); - - e_tree_model_signals [NODE_REMOVED] = - gtk_signal_new ("node_removed", - GTK_RUN_LAST, - klass->type, - GTK_SIGNAL_OFFSET (ETreeModelClass, node_removed), - gtk_marshal_NONE__POINTER_POINTER, - GTK_TYPE_NONE, 2, GTK_TYPE_POINTER, GTK_TYPE_POINTER); - - gtk_object_class_add_signals (klass, e_tree_model_signals, LAST_SIGNAL); - - table_class->row_count = etable_row_count; - table_class->value_at = etable_value_at; - table_class->set_value_at = etable_set_value_at; - table_class->is_cell_editable = etable_is_cell_editable; -#if 0 - /* XX need to pass these through */ - table_class->duplicate_value = etable_duplicate_value; - table_class->free_value = etable_free_value; - table_class->initialize_value = etable_initialize_value; - table_class->value_is_empty = etable_value_is_empty; - table_class->value_to_string = etable_value_to_string; - table_class->thaw = etable_thaw; -#endif - - tree_class->get_root = etree_get_root; - tree_class->get_prev = etree_get_prev; - tree_class->get_next = etree_get_next; - tree_class->get_parent = etree_get_parent; - - tree_class->value_at = etree_value_at; - tree_class->icon_at = etree_icon_at; - tree_class->set_value_at = etree_set_value_at; - tree_class->is_editable = etree_is_editable; - - tree_class->get_children = etree_get_children; - tree_class->is_expanded = etree_is_expanded; - tree_class->is_visible = etree_is_visible; - tree_class->set_expanded = etree_set_expanded; - tree_class->set_expanded_recurse = etree_set_expanded_recurse; - tree_class->node_at_row = etree_node_at_row; -} - -E_MAKE_TYPE(e_tree_model, "ETreeModel", ETreeModel, e_tree_model_class_init, NULL, PARENT_TYPE) - - -/* signals */ -void -e_tree_model_node_changed (ETreeModel *tree_model, ETreePath *node) -{ - g_return_if_fail (tree_model != NULL); - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - gtk_signal_emit (GTK_OBJECT (tree_model), - e_tree_model_signals [NODE_CHANGED]); -} - -void -e_tree_model_node_inserted (ETreeModel *tree_model, - ETreePath *parent_node, - ETreePath *inserted_node) -{ - g_return_if_fail (tree_model != NULL); - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - gtk_signal_emit (GTK_OBJECT (tree_model), - e_tree_model_signals [NODE_INSERTED], - parent_node, inserted_node); -} - -void -e_tree_model_node_removed (ETreeModel *tree_model, ETreePath *parent_node, ETreePath *removed_node) -{ - g_return_if_fail (tree_model != NULL); - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - gtk_signal_emit (GTK_OBJECT (tree_model), - e_tree_model_signals [NODE_REMOVED], - parent_node, removed_node); -} - - -void -e_tree_model_construct (ETreeModel *etree) -{ - etree->root = NULL; - etree->root_visible = TRUE; - etree->row_array = g_array_new (FALSE, FALSE, sizeof(GNode*)); -} - -ETreeModel * -e_tree_model_new () -{ - ETreeModel *et; - - et = gtk_type_new (e_tree_model_get_type ()); - - return et; -} - -ETreePath * -e_tree_model_get_root (ETreeModel *etree) -{ - return ETM_CLASS(etree)->get_root(etree); -} - -ETreePath * -e_tree_model_node_at_row (ETreeModel *etree, int row) -{ - return ETM_CLASS(etree)->node_at_row (etree, row); -} - -GdkPixbuf * -e_tree_model_icon_of_node (ETreeModel *etree, ETreePath *path) -{ - return ETM_CLASS(etree)->icon_at (etree, path); -} - -int -e_tree_model_row_of_node (ETreeModel *etree, ETreePath *node) -{ - int i; - - for (i = 0; i < etree->row_array->len; i ++) - if (g_array_index (etree->row_array, GNode*, i) == node) - return i; - - g_warning ("e_tree_model_row_of_node failed for node %p\n", node); - - return -1; -} - -void -e_tree_model_root_node_set_visible (ETreeModel *etm, gboolean visible) -{ - if (visible != etm->root_visible) { - etm->root_visible = visible; - if (etm->root) { - if (visible) { - etm->row_array = g_array_insert_val (etm->row_array, 0, etm->root); - } - else { - ETreePath *root_path = e_tree_model_get_root (etm); - e_tree_model_node_set_expanded (etm, root_path, TRUE); - etm->row_array = g_array_remove_index (etm->row_array, 0); - } - - e_table_model_changed (E_TABLE_MODEL (etm)); - } - } -} - -gboolean -e_tree_model_root_node_is_visible (ETreeModel *etm) -{ - return etm->root_visible; -} - - -ETreePath * -e_tree_model_node_get_next (ETreeModel *etree, ETreePath *node) -{ - return ETM_CLASS(etree)->get_next(etree, node); -} - -ETreePath * -e_tree_model_node_get_prev (ETreeModel *etree, ETreePath *node) -{ - return ETM_CLASS(etree)->get_prev(etree, node); -} - -guint -e_tree_model_node_depth (ETreeModel *etree, ETreePath *path) -{ - return g_node_depth (path) - 1; -} - -ETreePath * -e_tree_model_node_get_parent (ETreeModel *etree, ETreePath *path) -{ - return ETM_CLASS(etree)->get_parent(etree, path); -} - -gboolean -e_tree_model_node_is_root (ETreeModel *etree, ETreePath *path) -{ - return (e_tree_model_node_depth (etree, path) == 0); -} - -gboolean -e_tree_model_node_is_expandable (ETreeModel *etree, ETreePath *path) -{ - return (e_tree_model_node_get_children (etree, path, NULL) > 0); -} - -gboolean -e_tree_model_node_is_expanded (ETreeModel *etree, ETreePath *path) -{ - return ETM_CLASS(etree)->is_expanded (etree, path); -} - -gboolean -e_tree_model_node_is_visible (ETreeModel *etree, ETreePath *path) -{ - return ETM_CLASS(etree)->is_visible (etree, path); -} - -void -e_tree_model_node_set_expanded (ETreeModel *etree, ETreePath *path, gboolean expanded) -{ - ETM_CLASS(etree)->set_expanded (etree, path, expanded); -} - -void -e_tree_model_node_set_expanded_recurse (ETreeModel *etree, ETreePath *path, gboolean expanded) -{ - ETM_CLASS(etree)->set_expanded_recurse (etree, path, expanded); -} - -guint -e_tree_model_node_get_children (ETreeModel *etree, ETreePath *path, ETreePath ***paths) -{ - return ETM_CLASS(etree)->get_children (etree, path, paths); -} - -guint -e_tree_model_node_num_visible_descendents (ETreeModel *etm, ETreePath *node) -{ - ENode *enode = (ENode*)node->data; - - return enode->visible_descendents; -} - -gpointer -e_tree_model_node_get_data (ETreeModel *etm, ETreePath *node) -{ - ENode *enode; - - g_return_val_if_fail (node && node->data, NULL); - - enode = (ENode*)node->data; - - return enode->node_data; -} - -void -e_tree_model_node_set_data (ETreeModel *etm, ETreePath *node, gpointer node_data) -{ - ENode *enode; - - g_return_if_fail (node && node->data); - - enode = (ENode*)node->data; - - enode->node_data = node_data; -} - -ETreePath* -e_tree_model_node_insert (ETreeModel *tree_model, - ETreePath *parent_path, - int position, - gpointer node_data) -{ - ENode *node; - ETreePath *new_path; - - g_return_val_if_fail (parent_path != NULL || tree_model->root == NULL, NULL); - - node = g_new0 (ENode, 1); - - node->expanded = FALSE; - node->node_data = node_data; - - if (parent_path != NULL) { - - new_path = g_node_new (node); - - g_node_insert (parent_path, position, new_path); - - if (e_tree_model_node_is_visible (tree_model, new_path)) { - int parent_row; - GNode *n; - - /* we need to iterate back up to the root, incrementing the number of visible - descendents */ - for (n = parent_path; n; n = n->parent) { - ENode *parent_enode = (ENode*)n->data; - - parent_enode->visible_descendents ++; - } - - /* finally, insert a row into the table */ - if (position == -1) - position = e_tree_model_node_num_visible_descendents (tree_model, parent_path) - 1; - - parent_row = e_tree_model_row_of_node (tree_model, parent_path); - - tree_model->row_array = g_array_insert_val (tree_model->row_array, - parent_row + position + 1, new_path); - - e_table_model_row_inserted (E_TABLE_MODEL(tree_model), parent_row + position + 1); - } - } - else { - tree_model->root = g_node_new (node); - if (tree_model->root_visible) { - tree_model->row_array = g_array_insert_val (tree_model->row_array, 0, tree_model->root); - e_table_model_row_inserted (E_TABLE_MODEL (tree_model), 0); - } - else { - /* need to mark the new node as expanded or - we'll never see it's children */ - node->expanded = TRUE; - } - new_path = tree_model->root; - } - - return new_path; -} - -ETreePath * -e_tree_model_node_insert_before (ETreeModel *etree, - ETreePath *parent, - ETreePath *sibling, - gpointer node_data) -{ - return e_tree_model_node_insert (etree, parent, - g_node_child_position (parent, sibling), - node_data); -} - -static void -child_remove (GNode *node, gpointer etree) -{ - e_tree_model_node_remove (etree, node); -} - -gpointer -e_tree_model_node_remove (ETreeModel *etree, ETreePath *path) -{ - GNode *parent = path->parent; - ENode *enode = (ENode*)path->data; - gpointer ret = enode->node_data; - - /* remove children */ - g_node_children_foreach (path, G_TRAVERSE_ALL, child_remove, etree); - - /* clean up the display */ - if (parent) { - if (e_tree_model_node_is_visible (etree, path)) { - int row = e_tree_model_row_of_node (etree, path); - e_table_model_row_deleted (E_TABLE_MODEL (etree), row); - etree->row_array = g_array_remove_index (etree->row_array, row); - - /* we need to iterate back up to the root, incrementing the number of visible - descendents */ - for (; parent; parent = parent->parent) { - ENode *parent_enode = (ENode*)parent->data; - - parent_enode->visible_descendents --; - } - } - } - else if (path == etree->root) { - etree->root = NULL; - if (etree->root_visible) { - etree->row_array = g_array_remove_index (etree->row_array, 0); - e_table_model_row_deleted (E_TABLE_MODEL (etree), 0); - } - } - else { - /* XXX invalid path */ - return NULL; - } - - - /* now free up the storage from that path */ - g_node_destroy (path); - g_free (enode); - - return ret; -} - - -static void -add_visible_descendents_to_array (ETreeModel *etm, GNode *gnode, int *row, int *count) -{ - GNode *child; - ENode *enode; - - /* add a row for this node */ - etm->row_array = g_array_insert_val (etm->row_array, (*row), gnode); - e_table_model_row_inserted (E_TABLE_MODEL (etm), (*row)++); - (*count) ++; - - /* then loop over its children, calling this routine for each - of them */ - enode = (ENode*)gnode->data; - if (enode->expanded) { - for (child = g_node_first_child (gnode); child; - child = g_node_next_sibling (child)) { - add_visible_descendents_to_array (etm, child, row, count); - } - } -} - -void -e_tree_model_node_sort (ETreeModel *tree_model, - ETreePath *node, - GCompareFunc compare) -{ - int num_nodes = g_node_n_children (node); - ETreePath **path_array; - int i; - - if (num_nodes == 0) - return; - - path_array = g_new (ETreePath*, num_nodes); - - for (i = 0; i < num_nodes; i ++) { - path_array[i] = g_node_first_child(node); - g_node_unlink (path_array[i]); - } - - qsort (path_array, num_nodes, sizeof(ETreePath*), compare); - - for (i = 0; i < num_nodes; i ++) { - g_node_append (node, path_array[i]); - } - - g_free (path_array); - - e_table_model_changed (E_TABLE_MODEL (tree_model)); -} diff --git a/widgets/e-table/e-tree-model.h b/widgets/e-table/e-tree-model.h deleted file mode 100644 index 403aff9a30..0000000000 --- a/widgets/e-table/e-tree-model.h +++ /dev/null @@ -1,107 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TREE_MODEL_H_ -#define _E_TREE_MODEL_H_ - -#include "e-table-model.h" -#include "gdk-pixbuf/gdk-pixbuf.h" - -#define E_TREE_MODEL_TYPE (e_tree_model_get_type ()) -#define E_TREE_MODEL(o) (GTK_CHECK_CAST ((o), E_TREE_MODEL_TYPE, ETreeModel)) -#define E_TREE_MODEL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TREE_MODEL_TYPE, ETreeModelClass)) -#define E_IS_TREE_MODEL(o) (GTK_CHECK_TYPE ((o), E_TREE_MODEL_TYPE)) -#define E_IS_TREE_MODEL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TREE_MODEL_TYPE)) - -typedef GNode ETreePath; - -typedef struct { - ETableModel base; - GNode *root; - gboolean root_visible; - GArray *row_array; /* used in the mapping between ETable and our tree */ -} ETreeModel; - -typedef struct { - ETableModelClass parent_class; - - /* - * Virtual methods - */ - ETreePath *(*get_root) (ETreeModel *etm); - - ETreePath *(*get_parent) (ETreeModel *etm, ETreePath* node); - ETreePath *(*get_next) (ETreeModel *etm, ETreePath* node); - ETreePath *(*get_prev) (ETreeModel *etm, ETreePath* node); - guint (*get_children) (ETreeModel *etm, ETreePath* node, ETreePath ***paths); - - gboolean (*is_expanded) (ETreeModel *etm, ETreePath* node); - gboolean (*is_visible) (ETreeModel *etm, ETreePath* node); - void (*set_expanded) (ETreeModel *etm, ETreePath* node, gboolean expanded); - void (*set_expanded_recurse) (ETreeModel *etm, ETreePath *node, gboolean expanded); - void (*set_expanded_level) (ETreeModel *etm, ETreePath *node, gboolean expanded, int level); - - GdkPixbuf *(*icon_at) (ETreeModel *etm, ETreePath* node); - ETreePath* (*node_at_row) (ETreeModel *etm, int row); - - /* - * ETable analogs - */ - void *(*value_at) (ETreeModel *etm, ETreePath* node, int col); - void (*set_value_at) (ETreeModel *etm, ETreePath* node, int col, const void *val); - gboolean (*is_editable) (ETreeModel *etm, ETreePath* node, int col); - - - /* - * Signals - */ - void (*node_changed) (ETreeModel *etm, ETreePath *node); - void (*node_inserted) (ETreeModel *etm, ETreePath *parent, ETreePath *inserted_node); - void (*node_removed) (ETreeModel *etm, ETreePath *parent, ETreePath *removed_node); - -} ETreeModelClass; - -GtkType e_tree_model_get_type (void); -void e_tree_model_construct (ETreeModel *etree); -ETreeModel *e_tree_model_new (void); - -/* tree traversal operations */ -ETreePath *e_tree_model_get_root (ETreeModel *etree); -ETreePath *e_tree_model_node_get_parent (ETreeModel *etree, ETreePath *path); -ETreePath *e_tree_model_node_get_next (ETreeModel *etree, ETreePath *path); -ETreePath *e_tree_model_node_get_prev (ETreeModel *etree, ETreePath *path); - -/* node operations */ -ETreePath *e_tree_model_node_insert (ETreeModel *etree, ETreePath *parent, int position, gpointer node_data); -ETreePath *e_tree_model_node_insert_before (ETreeModel *etree, ETreePath *parent, ETreePath *sibling, gpointer node_data); -gpointer e_tree_model_node_remove (ETreeModel *etree, ETreePath *path); - -/* node accessors */ -gboolean e_tree_model_node_is_root (ETreeModel *etree, ETreePath *path); -gboolean e_tree_model_node_is_expandable (ETreeModel *etree, ETreePath *path); -gboolean e_tree_model_node_is_expanded (ETreeModel *etree, ETreePath *path); -gboolean e_tree_model_node_is_visible (ETreeModel *etree, ETreePath *path); -void e_tree_model_node_set_expanded (ETreeModel *etree, ETreePath *path, gboolean expanded); -void e_tree_model_node_set_expanded_recurse (ETreeModel *etree, ETreePath *path, gboolean expanded); -guint e_tree_model_node_get_children (ETreeModel *etree, ETreePath *path, ETreePath ***paths); -guint e_tree_model_node_depth (ETreeModel *etree, ETreePath *path); -guint e_tree_model_node_num_visible_descendents (ETreeModel *etm, ETreePath *node); -gpointer e_tree_model_node_get_data (ETreeModel *etm, ETreePath *node); -void e_tree_model_node_set_data (ETreeModel *etm, ETreePath *node, gpointer node_data); - -/* display oriented routines */ -ETreePath *e_tree_model_node_at_row (ETreeModel *etree, int row); -GdkPixbuf *e_tree_model_icon_of_node (ETreeModel *etree, ETreePath *path); -int e_tree_model_row_of_node (ETreeModel *etree, ETreePath *path); -void e_tree_model_root_node_set_visible (ETreeModel *etree, gboolean visible); -gboolean e_tree_model_root_node_is_visible (ETreeModel *etree); - -/* sort routine, analogous to gtk_ctree_node_sort */ -void e_tree_model_node_sort (ETreeModel *tree_model, ETreePath *node, GCompareFunc compare); - -/* -** Routines for emitting signals on the ETreeModel -*/ -void e_tree_model_node_changed (ETreeModel *tree_model, ETreePath *node); -void e_tree_model_node_inserted (ETreeModel *tree_model, ETreePath *parent_node, ETreePath *inserted_node); -void e_tree_model_node_removed (ETreeModel *tree_model, ETreePath *parent_node, ETreePath *removed_node); - -#endif /* _E_TREE_MODEL_H */ diff --git a/widgets/e-table/e-tree-simple.c b/widgets/e-table/e-tree-simple.c deleted file mode 100644 index e5883e6ae0..0000000000 --- a/widgets/e-table/e-tree-simple.c +++ /dev/null @@ -1,84 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-tree-simple.c: a Tree Model that offers a function pointer - * interface to using ETreeModel, similar to ETableSimple. - * - * Author: - * Chris Toshok (toshok@helixcode.com) - * - * (C) 2000 Helix Code, Inc. */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-util/e-util.h" -#include "e-tree-simple.h" - -#define PARENT_TYPE E_TREE_MODEL_TYPE - -static void * -simple_value_at (ETreeModel *etm, ETreePath *node, int col) -{ - ETreeSimple *simple = E_TREE_SIMPLE(etm); - - return simple->value_at (etm, node, col, simple->model_data); -} - -static GdkPixbuf * -simple_icon_at (ETreeModel *etm, ETreePath *node) -{ - ETreeSimple *simple = E_TREE_SIMPLE(etm); - - return simple->icon_at (etm, node, simple->model_data); -} - -static void -simple_set_value_at (ETreeModel *etm, ETreePath *node, int col, const void *val) -{ - ETreeSimple *simple = E_TREE_SIMPLE(etm); - - simple->set_value_at (etm, node, col, val, simple->model_data); -} - -static gboolean -simple_is_editable (ETreeModel *etm, ETreePath *node, int col) -{ - ETreeSimple *simple = E_TREE_SIMPLE(etm); - - return simple->is_editable (etm, node, col, simple->model_data); -} - -static void -e_tree_simple_class_init (GtkObjectClass *object_class) -{ - ETreeModelClass *model_class = (ETreeModelClass *) object_class; - - model_class->icon_at = simple_icon_at; - model_class->value_at = simple_value_at; - model_class->set_value_at = simple_set_value_at; - model_class->is_editable = simple_is_editable; -} - -E_MAKE_TYPE(e_tree_simple, "ETreeSimple", ETreeSimple, e_tree_simple_class_init, NULL, PARENT_TYPE) - -ETreeModel * -e_tree_simple_new (ETreeSimpleIconAtFn icon_at, - ETreeSimpleValueAtFn value_at, - ETreeSimpleSetValueAtFn set_value_at, - ETreeSimpleIsEditableFn is_editable, - gpointer model_data) -{ - ETreeSimple *etg; - - etg = gtk_type_new (e_tree_simple_get_type ()); - - e_tree_model_construct (E_TREE_MODEL (etg)); - - etg->icon_at = icon_at; - etg->value_at = value_at; - etg->set_value_at = set_value_at; - etg->is_editable = is_editable; - etg->model_data = model_data; - - return (ETreeModel*)etg; -} - diff --git a/widgets/e-table/e-tree-simple.h b/widgets/e-table/e-tree-simple.h deleted file mode 100644 index edda53e82d..0000000000 --- a/widgets/e-table/e-tree-simple.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -#ifndef _E_TREE_SIMPLE_H_ -#define _E_TREE_SIMPLE_H_ - -#include "e-tree-model.h" - -#define E_TREE_SIMPLE_TYPE (e_tree_simple_get_type ()) -#define E_TREE_SIMPLE(o) (GTK_CHECK_CAST ((o), E_TREE_SIMPLE_TYPE, ETreeSimple)) -#define E_TREE_SIMPLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TREE_SIMPLE_TYPE, ETreeSimpleClass)) -#define E_IS_TREE_SIMPLE(o) (GTK_CHECK_TYPE ((o), E_TREE_SIMPLE_TYPE)) -#define E_IS_TREE_SIMPLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TREE_SIMPLE_TYPE)) - - -typedef GdkPixbuf* (*ETreeSimpleIconAtFn) (ETreeModel *etree, ETreePath *path, void *model_data); -typedef void* (*ETreeSimpleValueAtFn) (ETreeModel *etree, ETreePath *path, int col, void *model_data); -typedef void (*ETreeSimpleSetValueAtFn) (ETreeModel *etree, ETreePath *path, int col, const void *val, void *model_data); -typedef gboolean (*ETreeSimpleIsEditableFn) (ETreeModel *etree, ETreePath *path, int col, void *model_data); - -typedef struct { - ETreeModel parent; - - ETreeSimpleIconAtFn icon_at; - ETreeSimpleValueAtFn value_at; - ETreeSimpleSetValueAtFn set_value_at; - ETreeSimpleIsEditableFn is_editable; - - gpointer model_data; -} ETreeSimple; - -typedef struct { - ETreeModelClass parent_class; -} ETreeSimpleClass; - -GtkType e_tree_simple_get_type (void); - -ETreeModel *e_tree_simple_new (ETreeSimpleIconAtFn icon_at, - ETreeSimpleValueAtFn value_at, - ETreeSimpleSetValueAtFn set_value_at, - ETreeSimpleIsEditableFn is_editable, - gpointer model_data); - -#endif /* _E_TREE_SIMPLE_H_ */ diff --git a/widgets/e-table/image1.png b/widgets/e-table/image1.png Binary files differdeleted file mode 100644 index 8326ac241f..0000000000 --- a/widgets/e-table/image1.png +++ /dev/null diff --git a/widgets/e-table/image2.png b/widgets/e-table/image2.png Binary files differdeleted file mode 100644 index e6a4c75dbe..0000000000 --- a/widgets/e-table/image2.png +++ /dev/null diff --git a/widgets/e-table/image3.png b/widgets/e-table/image3.png Binary files differdeleted file mode 100644 index 50e16e8620..0000000000 --- a/widgets/e-table/image3.png +++ /dev/null diff --git a/widgets/e-table/remove-col.xpm b/widgets/e-table/remove-col.xpm deleted file mode 100644 index ff1024f0c9..0000000000 --- a/widgets/e-table/remove-col.xpm +++ /dev/null @@ -1,22 +0,0 @@ -/* XPM */ -static char * remove_col_xpm[] = { -"16 16 3 1", -" c None", -". c #000000", -"+ c #FF0000", -"... ...", -".++. .++.", -".+++. .+++.", -" .+++. .+++. ", -" .+++. .+++. ", -" .+++..+++. ", -" .++++++. ", -" .++++. ", -" .++++. ", -" .++++++. ", -" .+++..+++. ", -" .+++. .+++. ", -" .+++. .+++. ", -".+++. .+++.", -".++. .++.", -"... ..."}; diff --git a/widgets/e-table/sample.table b/widgets/e-table/sample.table deleted file mode 100644 index 45c8ff0691..0000000000 --- a/widgets/e-table/sample.table +++ /dev/null @@ -1,11 +0,0 @@ -Col1 Col2 Address Title Dorks -c1.a c2.a a.a tit-1 DorkA -c1.b c2.b a.b tit-2 DDork -c1.c c2.c a.c tit-1 DorkB -c1.d c2.d a.d tit-2 ADork -c1.e c2.e a.e tit-1 DorkC -c1.f c2.f a.f tit-2 UDork -c1.g c2.g a.g tit-3 Dork--- -j k k tit-1 DorkA - - diff --git a/widgets/e-table/table-test.c b/widgets/e-table/table-test.c deleted file mode 100644 index 62160e7035..0000000000 --- a/widgets/e-table/table-test.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include <config.h> -#include <stdio.h> -#include <string.h> -#include <fcntl.h> -#include <gnome.h> -#include "e-util/e-cursors.h" -#include "table-test.h" - -int -main (int argc, char *argv []) -{ - - if (isatty (0)){ - int fd; - - close (0); - fd = open ("sample.table", O_RDONLY); - if (fd == -1){ - fprintf (stderr, "Could not find sample.table, try feeding a table on stdin"); - exit (1); - } - dup2 (fd, 0); - } - - gnome_init ("TableTest", "TableTest", argc, argv); - e_cursors_init (); - - - table_browser_test (); - multi_cols_test (); - check_test (); - - e_table_test (); - - gtk_main (); - - e_cursors_shutdown (); - return 0; -} diff --git a/widgets/e-table/table-test.h b/widgets/e-table/table-test.h deleted file mode 100644 index ad8cfcc083..0000000000 --- a/widgets/e-table/table-test.h +++ /dev/null @@ -1,4 +0,0 @@ -void table_browser_test (void); -void multi_cols_test (void); -void check_test (void); -void e_table_test (void); diff --git a/widgets/e-table/test-check.c b/widgets/e-table/test-check.c deleted file mode 100644 index 3bb022821e..0000000000 --- a/widgets/e-table/test-check.c +++ /dev/null @@ -1,206 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include <config.h> -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-util/e-cursors.h" -#include "e-util/e-canvas-utils.h" -#include "e-util/e-canvas.h" -#include "e-util/e-util.h" -#include "e-cell-text.h" -#include "e-cell-checkbox.h" - -#include "table-test.h" - -#define LINES 4 - -static struct { - int value; - char *string; -} my_table [LINES] = { - { 0, "Buy food" }, - { 1, "Breathe " }, - { 0, "Cancel gdb session with shrink" }, - { 1, "Make screenshots" }, -}; -/* - * ETableSimple callbacks - */ -static int -col_count (ETableModel *etc, void *data) -{ - return 2; -} - -static int -row_count (ETableModel *etc, void *data) -{ - return LINES; -} - -static void * -value_at (ETableModel *etc, int col, int row, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0) - return GINT_TO_POINTER (my_table [row].value); - else - return my_table [row].string; - -} - -static void -set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0) { - my_table [row].value = GPOINTER_TO_INT (val); - printf ("Value at %d,%d set to %d\n", col, row, GPOINTER_TO_INT (val)); - } else { - my_table [row].string = g_strdup (val); - printf ("Value at %d,%d set to %s\n", col, row, (char *) val); - } -} - -static gboolean -is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -static void * -duplicate_value (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == 0) { - return (void *) value; - } else { - return g_strdup (value); - } -} - -static void -free_value (ETableModel *etc, int col, void *value, void *data) -{ - if (col != 0) { - g_free (value); - } -} - -static void * -initialize_value (ETableModel *etc, int col, void *data) -{ - if (col == 0) - return NULL; - else - return g_strdup (""); -} - -static gboolean -value_is_empty (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == 0) - return value == NULL; - else - return !(value && *(char *)value); -} - -static char * -value_to_string (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == 0) - return g_strdup_printf("%d", (int) value); - else - return g_strdup(value); -} - -static void -set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) -{ - gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); -} - -void -check_test (void) -{ - GtkWidget *canvas, *window; - ETableModel *e_table_model; - ETableHeader *e_table_header; - ETableCol *col_0, *col_1; - ECell *cell_left_just, *cell_image_check; - GdkPixbuf *pixbuf; - GnomeCanvasItem *item; - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - e_table_model = e_table_simple_new ( - col_count, row_count, value_at, - set_value_at, is_cell_editable, - duplicate_value, free_value, - initialize_value, value_is_empty, - value_to_string, - NULL); - - /* - * Header - */ - e_table_header = e_table_header_new (); - - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - cell_image_check = e_cell_checkbox_new (); - pixbuf = gdk_pixbuf_new_from_file ("clip.png"); - col_0 = e_table_col_new_with_pixbuf (0, pixbuf, 0.0, 18, cell_image_check, g_int_compare, TRUE); - gdk_pixbuf_unref (pixbuf); - e_table_header_add_column (e_table_header, col_0, 0); - - col_1 = e_table_col_new (1, "Item Name", 1.0, 20, cell_left_just, g_str_compare, TRUE); - e_table_header_add_column (e_table_header, col_1, 1); - e_table_col_set_arrow (col_1, E_TABLE_COL_ARROW_DOWN); - - /* - * GUI - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - canvas = e_canvas_new (); - - gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate", - GTK_SIGNAL_FUNC (set_canvas_size), NULL); - - gtk_container_add (GTK_CONTAINER (window), canvas); - gtk_widget_show_all (window); - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header, - NULL); - - item = gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_item_get_type (), - "ETableHeader", e_table_header, - "ETableModel", e_table_model, - "drawgrid", TRUE, - "drawfocus", TRUE, -#if 0 - "spreadsheet", TRUE, -#endif - "cursor_mode", E_TABLE_CURSOR_SIMPLE, - NULL); - e_canvas_item_move_absolute (item, 0, 30); -} - diff --git a/widgets/e-table/test-cols.c b/widgets/e-table/test-cols.c deleted file mode 100644 index c47a1d47d7..0000000000 --- a/widgets/e-table/test-cols.c +++ /dev/null @@ -1,250 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include <config.h> -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "e-util/e-canvas-utils.h" -#include "e-util/e-canvas.h" -#include "e-util/e-cursors.h" -#include "e-util/e-util.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-cell-toggle.h" - -#include "table-test.h" - -#define LINES 4 - -static struct { - int value; - char *string; -} my_table [LINES] = { - { 0, "You are not" }, - { 1, "A beautiful and unique " }, - { 0, "Snowflake" }, - { 2, "You are not your wallet" }, -}; -/* - * ETableSimple callbacks - */ -static int -col_count (ETableModel *etc, void *data) -{ - return 2; -} - -static int -row_count (ETableModel *etc, void *data) -{ - return LINES; -} - -static void * -value_at (ETableModel *etc, int col, int row, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0) - return GINT_TO_POINTER (my_table [row].value); - else - return my_table [row].string; - -} - -static void -set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0){ - my_table [row].value = GPOINTER_TO_INT (val); - printf ("Value at %d,%d set to %d\n", col, row, GPOINTER_TO_INT (val)); - } else { - my_table [row].string = g_strdup (val); - printf ("Value at %d,%d set to %s\n", col, row, (char *) val); - } -} - -static gboolean -is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -static void * -duplicate_value (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == 0){ - return (void *)value; - } else { - return g_strdup (value); - } -} - -static void -free_value (ETableModel *etc, int col, void *value, void *data) -{ - if (col != 0){ - g_free (value); - } -} - -static void * -initialize_value (ETableModel *etc, int col, void *data) -{ - if (col == 0) - return NULL; - else - return g_strdup (""); -} - -static gboolean -value_is_empty (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == 0) - return value == NULL; - else - return !(value && *(char *)value); -} - -static char * -value_to_string (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == 0) - return g_strdup_printf("%d", (int) value); - else - return g_strdup(value); -} - -static void -set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) -{ - gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); -} - -void -multi_cols_test (void) -{ - GtkWidget *canvas, *window; - ETableModel *e_table_model; - ETableHeader *e_table_header, *e_table_header_multiple; - ETableCol *col_0, *col_1; - ECell *cell_left_just, *cell_image_toggle; - GnomeCanvasItem *item; - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - e_table_model = e_table_simple_new ( - col_count, row_count, value_at, - set_value_at, is_cell_editable, - duplicate_value, free_value, - initialize_value, value_is_empty, - value_to_string, - NULL); - - /* - * Header - */ - e_table_header = e_table_header_new (); - - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - { - GdkPixbuf **images = g_new (GdkPixbuf *, 3); - int i; - - images [0] = gdk_pixbuf_new_from_file ("image1.png"); - images [1] = gdk_pixbuf_new_from_file ("image2.png"); - images [2] = gdk_pixbuf_new_from_file ("image3.png"); - - cell_image_toggle = e_cell_toggle_new (0, 3, images); - - for (i = 0; i < 3; i++) - gdk_pixbuf_unref (images [i]); - - g_free (images); - } - - col_1 = e_table_col_new (1, "Item Name", 1.0, 20, cell_left_just, g_str_compare, TRUE); - e_table_header_add_column (e_table_header, col_1, 0); - - col_0 = e_table_col_new (0, "A", 0.0, 48, cell_image_toggle, g_int_compare, TRUE); - e_table_header_add_column (e_table_header, col_0, 1); - - /* - * Second test - */ - e_table_header_multiple = e_table_header_new (); - e_table_header_add_column (e_table_header_multiple, col_0, 0); - e_table_header_add_column (e_table_header_multiple, col_1, 1); - e_table_header_add_column (e_table_header_multiple, col_1, 2); - - /* - * GUI - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - canvas = e_canvas_new (); - - gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate", - GTK_SIGNAL_FUNC (set_canvas_size), NULL); - - gtk_container_add (GTK_CONTAINER (window), canvas); - gtk_widget_show_all (window); - - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header, - NULL); - - item = gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_item_get_type (), - "ETableHeader", e_table_header, - "ETableModel", e_table_model, - "drawgrid", TRUE, - "drawfocus", TRUE, - "cursor_mode", E_TABLE_CURSOR_SIMPLE, -#if 0 - "spreadsheet", TRUE, -#endif - NULL); - - e_canvas_item_move_absolute (item, 0, 30); - - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header_multiple, - NULL); - item = gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_item_get_type (), - "ETableHeader", e_table_header_multiple, - "ETableModel", e_table_model, - "drawgrid", TRUE, - "drawfocus", TRUE, -#if 0 - "spreadsheet", TRUE, -#endif - "cursor_mode", E_TABLE_CURSOR_SIMPLE, - NULL); - e_canvas_item_move_absolute (item, 300, 30); -} - - - - - diff --git a/widgets/e-table/test-table.c b/widgets/e-table/test-table.c deleted file mode 100644 index b30b412f08..0000000000 --- a/widgets/e-table/test-table.c +++ /dev/null @@ -1,394 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include <config.h> -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "e-util/e-cursors.h" -#include "e-util/e-canvas.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-table.h" -#include "e-table-config.h" - -#include "table-test.h" - -char buffer [1024]; -char **column_labels; -char ***table_data; -int cols = 0; -int lines = 0; -int lines_alloc = 0; - -static void -parse_headers () -{ - char *p, *s; - int in_value = 0, i; - - fgets (buffer, sizeof (buffer)-1, stdin); - - for (p = buffer; *p; p++){ - if (*p == ' ' || *p == '\t'){ - if (in_value){ - cols++; - in_value = 0; - } - } else - in_value = 1; - } - if (in_value) - cols++; - - if (!cols){ - fprintf (stderr, "No columns in first row\n"); - exit (1); - } - - column_labels = g_new0 (char *, cols); - - p = buffer; - for (i = 0; (s = strtok (p, " \t")) != NULL; i++){ - column_labels [i] = g_strdup (s); - if (strchr (column_labels [i], '\n')) - *strchr (column_labels [i], '\n') = 0; - p = NULL; - } - - printf ("%d headers:\n", cols); - for (i = 0; i < cols; i++){ - printf ("header %d: %s\n", i, column_labels [i]); - } -} - -static char ** -load_line (char *buffer, int cols) -{ - char **line = g_new0 (char *, cols); - char *p; - int i; - - for (i = 0; i < cols; i++){ - p = strtok (buffer, " \t\n"); - if (p == NULL){ - for (; i < cols; i++) - line [i] = g_strdup (""); - return line; - } else - line [i] = g_strdup (p); - buffer = NULL; - } - return line; -} - -static void -append_line (char **line) -{ - if (lines <= lines_alloc){ - lines_alloc = lines + 50; - table_data = g_renew (char **, table_data, lines_alloc); - } - table_data [lines] = line; - lines++; -} - -static void -load_data () -{ - int i; - - { - static int loaded; - - if (loaded) - return; - - loaded = TRUE; - } - - - parse_headers (); - - while (fgets (buffer, sizeof (buffer)-1, stdin) != NULL){ - char **line; - - if (buffer [0] == '\n') - continue; - line = load_line (buffer, cols); - append_line (line); - } - - for (i = 0; i < lines; i++){ - int j; - - printf ("Line %d: ", i); - for (j = 0; j < cols; j++) - printf ("[%s] ", table_data [i][j]); - printf ("\n"); - } -} - -/* - * ETableSimple callbacks - */ -static int -col_count (ETableModel *etc, void *data) -{ - return cols; -} - -static int -row_count (ETableModel *etc, void *data) -{ - return lines; -} - -static void * -value_at (ETableModel *etc, int col, int row, void *data) -{ - g_assert (col < cols); - g_assert (row < lines); - - return (void *) table_data [row][col]; -} - -static void -set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_assert (col < cols); - g_assert (row < lines); - - g_free (table_data [row][col]); - table_data [row][col] = g_strdup (val); - - printf ("Value at %d,%d set to %s\n", col, row, (char *) val); -} - -static gboolean -is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -static void * -duplicate_value (ETableModel *etc, int col, const void *value, void *data) -{ - return g_strdup (value); -} - -static void -free_value (ETableModel *etc, int col, void *value, void *data) -{ - g_free (value); -} - -static void * -initialize_value (ETableModel *etc, int col, void *data) -{ - return g_strdup (""); -} - -static gboolean -value_is_empty (ETableModel *etc, int col, const void *value, void *data) -{ - return !(value && *(char *)value); -} - -static char * -value_to_string (ETableModel *etc, int col, const void *value, void *data) -{ - return g_strdup(value); -} - -static void -set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) -{ - gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); -} - -void -table_browser_test (void) -{ - GtkWidget *canvas, *window; - ETableModel *e_table_model; - ETableHeader *e_table_header; - ECell *cell_left_just; - GnomeCanvasItem *group; - int i; - - load_data (); - - /* - * Data model - */ - e_table_model = e_table_simple_new ( - col_count, row_count, value_at, - set_value_at, is_cell_editable, - duplicate_value, free_value, - initialize_value, value_is_empty, - value_to_string, - NULL); - - /* - * Header - */ - e_table_header = e_table_header_new (); - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - for (i = 0; i < cols; i++){ - ETableCol *ecol = e_table_col_new ( - i, column_labels [i], - 1.0, 20, cell_left_just, - g_str_compare, TRUE); - - e_table_header_add_column (e_table_header, ecol, i); - } - - /* - * Setup GUI - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - canvas = e_canvas_new (); - - gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate", - GTK_SIGNAL_FUNC (set_canvas_size), NULL); - - gtk_container_add (GTK_CONTAINER (window), canvas); - gtk_widget_show_all (window); - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header, - NULL); - - group = gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - gnome_canvas_group_get_type (), - "x", 30.0, - "y", 30.0, - NULL); - - gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (group), - e_table_item_get_type (), - "ETableHeader", e_table_header, - "ETableModel", e_table_model, - "drawgrid", TRUE, - "drawfocus", TRUE, -#if 0 - "spreadsheet", TRUE, -#endif - NULL); -} - -static void -save_spec (GtkWidget *button, ETable *e_table) -{ - e_table_save_specification (e_table, "e-table-test.xml"); -} - -static void -row_selection_test (ETable *table, int row, gboolean selected) -{ - if (selected) - g_print ("Row %d selected\n", row); - else - g_print ("Row %d unselected\n", row); -} - -static void -toggle_grid (void *nothing, ETable *etable) -{ - static gboolean shown; - - gtk_object_get (GTK_OBJECT (etable), "drawgrid", &shown, NULL); - gtk_object_set (GTK_OBJECT (etable), "drawgrid", !shown, NULL); -} - -static void -do_e_table_demo (const char *spec) -{ - GtkWidget *e_table, *window, *frame, *vbox, *button, *bhide; - ECell *cell_left_just; - ETableHeader *full_header; - int i; - - /* - * Data model - */ - static ETableModel *e_table_model = NULL; - - if (e_table_model == NULL) - e_table_model = - e_table_simple_new (col_count, row_count, value_at, - set_value_at, is_cell_editable, - duplicate_value, free_value, - initialize_value, value_is_empty, - value_to_string, - NULL); - - full_header = e_table_header_new (); - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - for (i = 0; i < cols; i++){ - ETableCol *ecol = e_table_col_new ( - i, column_labels [i], - 1.0, 20, cell_left_just, - g_str_compare, TRUE); - - e_table_header_add_column (full_header, ecol, i); - } - - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - frame = gtk_frame_new (NULL); - e_table = e_table_new (full_header, e_table_model, spec); - gtk_signal_connect (GTK_OBJECT(e_table), "row_selection", - GTK_SIGNAL_FUNC(row_selection_test), NULL); - - vbox = gtk_vbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), e_table, TRUE, TRUE, 0); - gtk_container_add (GTK_CONTAINER (frame), vbox); - gtk_container_add (GTK_CONTAINER (window), frame); - - /* - * gadgets - */ - button = gtk_button_new_with_label ("Save spec"); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (save_spec), e_table); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - bhide = gtk_button_new_with_label ("Toggle Grid"); - gtk_signal_connect (GTK_OBJECT (bhide), "clicked", - GTK_SIGNAL_FUNC (toggle_grid), e_table); - gtk_box_pack_start (GTK_BOX (vbox), bhide, FALSE, FALSE, 0); - - gtk_widget_set_usize (window, 200, 200); - gtk_widget_show_all (window); - - if (getenv ("TEST")){ - e_table_do_gui_config (NULL, E_TABLE(e_table)); - } -} - -void -e_table_test (void) -{ - load_data (); - - if (1){/*getenv ("DO")){*/ - do_e_table_demo ("<ETableSpecification> <columns-shown> <column> 0 </column> <column> 1 </column> <column> 2 </column> <column> 3 </column> <column> 4 </column> </columns-shown> <grouping> <leaf column=\"3\" ascending=\"1\"/> </grouping> </ETableSpecification>"); - do_e_table_demo ("<ETableSpecification> <columns-shown> <column> 0 </column> <column> 0 </column> <column> 1 </column> <column> 2 </column> <column> 3 </column> <column> 4 </column> </columns-shown> <grouping> <group column=\"3\" ascending=\"1\"> <group column=\"4\" ascending=\"0\"> <leaf column=\"2\" ascending=\"1\"/> </group> </group> </grouping> </ETableSpecification>"); - } - do_e_table_demo ("<ETableSpecification> <columns-shown> <column> 0 </column> <column> 1 </column> <column> 2 </column> <column> 3 </column> <column> 4 </column> </columns-shown> <grouping> <group column=\"4\" ascending=\"1\"> <leaf column=\"2\" ascending=\"1\"/> </group> </grouping> </ETableSpecification>"); - do_e_table_demo ("<ETableSpecification> <columns-shown> <column> 0 </column> <column> 1 </column> <column> 2 </column> <column> 3 </column> <column> 4 </column> </columns-shown> <grouping> <group column=\"3\" ascending=\"1\"> <leaf column=\"2\" ascending=\"1\"/> </group> </grouping> </ETableSpecification>"); -} diff --git a/widgets/e-table/tree-expanded.xpm b/widgets/e-table/tree-expanded.xpm deleted file mode 100644 index fc748953eb..0000000000 --- a/widgets/e-table/tree-expanded.xpm +++ /dev/null @@ -1,22 +0,0 @@ -/* XPM */ -static char * tree_expanded_xpm[] = { -"16 16 3 1", -" c None", -". c #000000", -"+ c #FFFFFF", -" ", -" ", -" ", -" ", -" ......... ", -" .+++++++. ", -" .+++++++. ", -" .+++++++. ", -" .+.....+. ", -" .+++++++. ", -" .+++++++. ", -" .+++++++. ", -" ......... ", -" ", -" ", -" "}; diff --git a/widgets/e-table/tree-unexpanded.xpm b/widgets/e-table/tree-unexpanded.xpm deleted file mode 100644 index 0dfb12a0a5..0000000000 --- a/widgets/e-table/tree-unexpanded.xpm +++ /dev/null @@ -1,22 +0,0 @@ -/* XPM */ -static char * tree_unexpanded_xpm[] = { -"16 16 3 1", -" c None", -". c #000000", -"+ c #FFFFFF", -" ", -" ", -" ", -" ", -" ......... ", -" .+++++++. ", -" .+++.+++. ", -" .+++.+++. ", -" .+.....+. ", -" .+++.+++. ", -" .+++.+++. ", -" .+++++++. ", -" ......... ", -" ", -" ", -" "}; diff --git a/widgets/e-text/.cvsignore b/widgets/e-text/.cvsignore deleted file mode 100644 index ab703bd5e1..0000000000 --- a/widgets/e-text/.cvsignore +++ /dev/null @@ -1,9 +0,0 @@ -.deps -.libs -.pure -Makefile -Makefile.in -*.lo -*.la -e-text-test -e-entry-test diff --git a/widgets/e-text/Makefile.am b/widgets/e-text/Makefile.am deleted file mode 100644 index b56d735990..0000000000 --- a/widgets/e-text/Makefile.am +++ /dev/null @@ -1,43 +0,0 @@ -INCLUDES = \ - -I$(top_srcdir) \ - $(GNOME_INCLUDEDIR) \ - $(UNICODE_CFLAGS) \ - -DG_LOG_DOMAIN=\"e-text\" - -noinst_LIBRARIES = \ - libetext.a - -libetext_a_SOURCES = \ - e-entry.c \ - e-entry.h \ - e-text-event-processor-emacs-like.c \ - e-text-event-processor-emacs-like.h \ - e-text-event-processor-types.h \ - e-text-event-processor.c \ - e-text-event-processor.h \ - e-text-model.c \ - e-text-model.h \ - e-text.c \ - e-text.h - -noinst_PROGRAMS = \ - e-text-test \ - e-entry-test - -e_text_test_SOURCES = \ - e-text-test.c - -e_text_test_LDADD = \ - libetext.a \ - $(EXTRA_GNOME_LIBS) \ - $(top_builddir)/e-util/libeutil.la - -e_entry_test_SOURCES = \ - e-entry-test.c - -e_entry_test_LDADD = \ - libetext.a \ - $(EXTRA_GNOME_LIBS) \ - $(top_builddir)/e-util/libeutil.la - -e_text_test_LDFLAGS = `gnome-config --libs gdk_pixbuf` diff --git a/widgets/e-text/e-entry-test.c b/widgets/e-text/e-entry-test.c deleted file mode 100644 index 411e8d693c..0000000000 --- a/widgets/e-text/e-entry-test.c +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* test-minicard.c - * - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - - - -#include "config.h" - -#include <gnome.h> -#include "e-entry.h" - -static void destroy_callback(GtkWidget *app, gpointer data) -{ - exit(0); -} - -#if 0 -static void about_callback( GtkWidget *widget, gpointer data ) -{ - - const gchar *authors[] = - { - "Christopher James Lahey <clahey@umich.edu>", - NULL - }; - - GtkWidget *about = - gnome_about_new ( _( "Minicard Test" ), VERSION, - _( "Copyright (C) 2000, Helix Code, Inc." ), - authors, - _( "This should test the minicard canvas item" ), - NULL); - gtk_widget_show (about); -} -#endif - -int main( int argc, char *argv[] ) -{ - GtkWidget *app; - GtkWidget *entry; - - /* bindtextdomain (PACKAGE, GNOMELOCALEDIR); - textdomain (PACKAGE);*/ - - gnome_init( "EEntry Test", VERSION, argc, argv); - app = gnome_app_new("EEntry Test", NULL); - - entry = e_entry_new(); - gtk_object_set(GTK_OBJECT(entry), - "editable", TRUE, - "use_ellipsis", TRUE, - NULL); - gnome_app_set_contents( GNOME_APP( app ), entry ); - - /* Connect the signals */ - gtk_signal_connect( GTK_OBJECT( app ), "destroy", - GTK_SIGNAL_FUNC( destroy_callback ), - ( gpointer ) app ); - - gtk_widget_show_all( app ); - - gtk_main(); - - /* Not reached. */ - return 0; -} diff --git a/widgets/e-text/e-entry.c b/widgets/e-text/e-entry.c deleted file mode 100644 index cbde382c93..0000000000 --- a/widgets/e-text/e-entry.c +++ /dev/null @@ -1,408 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table.c: A graphical view of a Table. - * - * Author: - * Miguel de Icaza (miguel@helixcode.com) - * Chris Lahey (clahey@helixcode.com) - * - * Copyright 1999, Helix Code, Inc - */ -#include <config.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#ifdef HAVE_ALLOCA_H -#include <alloca.h> -#endif -#include <stdio.h> -#include <libgnomeui/gnome-canvas.h> -#include <gtk/gtksignal.h> -#include <gnome-xml/parser.h> -#include "e-util/e-util.h" -#include "e-util/e-canvas.h" -#include "e-entry.h" -#include "e-util/e-canvas-utils.h" - -#define MIN_ENTRY_WIDTH 150 -#define INNER_BORDER 2 - -#define PARENT_TYPE gtk_table_get_type () - -static GtkObjectClass *parent_class; - -enum { - E_ENTRY_CHANGED, - E_ENTRY_ACTIVATE, - E_ENTRY_LAST_SIGNAL -}; - -static guint e_entry_signals[E_ENTRY_LAST_SIGNAL] = { 0 }; - -/* Object argument IDs */ -enum { - ARG_0, - ARG_MODEL, - ARG_EVENT_PROCESSOR, - ARG_TEXT, - ARG_FONT, - ARG_FONTSET, - ARG_FONT_GDK, - ARG_ANCHOR, - ARG_JUSTIFICATION, - ARG_X_OFFSET, - ARG_Y_OFFSET, - ARG_FILL_COLOR, - ARG_FILL_COLOR_GDK, - ARG_FILL_COLOR_RGBA, - ARG_FILL_STIPPLE, - ARG_EDITABLE, - ARG_USE_ELLIPSIS, - ARG_ELLIPSIS, - ARG_LINE_WRAP, - ARG_BREAK_CHARACTERS, - ARG_MAX_LINES, - ARG_WIDTH, - ARG_HEIGHT -}; - -static void -canvas_size_allocate (GtkWidget *widget, GtkAllocation *alloc, - EEntry *e_entry) -{ - gnome_canvas_set_scroll_region ( - e_entry->canvas, - 0, 0, alloc->width, alloc->height); - gtk_object_set (GTK_OBJECT (e_entry->item), - "clip_width", (double) alloc->width, - "clip_height", (double) alloc->height, - NULL); -} - -static void -canvas_size_request (GtkWidget *widget, GtkRequisition *requisition, - EEntry *e_entry) -{ - g_return_if_fail (widget != NULL); - g_return_if_fail (GNOME_IS_CANVAS (widget)); - g_return_if_fail (requisition != NULL); - - requisition->width = MIN_ENTRY_WIDTH + (widget->style->klass->xthickness + INNER_BORDER) * 2; - requisition->height = (widget->style->font->ascent + - widget->style->font->descent + - (widget->style->klass->ythickness + INNER_BORDER) * 2); -} - -static void -e_entry_init (GtkObject *object) -{ - EEntry *e_entry = E_ENTRY (object); - GtkTable *gtk_table = GTK_TABLE (object); - - e_entry->canvas = GNOME_CANVAS(e_canvas_new()); - gtk_signal_connect(GTK_OBJECT(e_entry->canvas), "size_allocate", - GTK_SIGNAL_FUNC(canvas_size_allocate), e_entry); - gtk_signal_connect(GTK_OBJECT(e_entry->canvas), "size_request", - GTK_SIGNAL_FUNC(canvas_size_request), e_entry); - e_entry->item = E_TEXT(gnome_canvas_item_new(gnome_canvas_root(e_entry->canvas), - e_text_get_type(), - "clip", TRUE, - "fill_clip_rectangle", TRUE, - "anchor", GTK_ANCHOR_NW, - "draw_borders", TRUE, - NULL)); - - gtk_table_attach_defaults(gtk_table, GTK_WIDGET(e_entry->canvas), - 0, 1, 0, 1); - gtk_widget_show(GTK_WIDGET(e_entry->canvas)); -} - -EEntry * -e_entry_construct (EEntry *e_entry) -{ - return e_entry; -} - -GtkWidget * -e_entry_new (void) -{ - EEntry *e_entry; - e_entry = gtk_type_new (e_entry_get_type ()); - e_entry = e_entry_construct (e_entry); - - return GTK_WIDGET (e_entry); -} - -static void -et_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - EEntry *ee = E_ENTRY (o); - - switch (arg_id){ - case ARG_MODEL: - gtk_object_get(GTK_OBJECT(ee->item), - "model", >K_VALUE_OBJECT (*arg), - NULL); - break; - - case ARG_EVENT_PROCESSOR: - gtk_object_get(GTK_OBJECT(ee->item), - "event_processor", >K_VALUE_OBJECT (*arg), - NULL); - break; - - case ARG_TEXT: - gtk_object_get(GTK_OBJECT(ee->item), - "text", >K_VALUE_STRING (*arg), - NULL); - break; - - case ARG_FONT_GDK: - gtk_object_get(GTK_OBJECT(ee->item), - "font_gdk", >K_VALUE_BOXED (*arg), - NULL); - break; - - case ARG_JUSTIFICATION: - gtk_object_get(GTK_OBJECT(ee->item), - "justification", >K_VALUE_ENUM (*arg), - NULL); - break; - - case ARG_FILL_COLOR_GDK: - gtk_object_get(GTK_OBJECT(ee->item), - "fill_color_gdk", >K_VALUE_BOXED (*arg), - NULL); - break; - - case ARG_FILL_COLOR_RGBA: - gtk_object_get(GTK_OBJECT(ee->item), - "fill_color_rgba", >K_VALUE_UINT (*arg), - NULL); - break; - - case ARG_FILL_STIPPLE: - gtk_object_get(GTK_OBJECT(ee->item), - "fill_stiple", >K_VALUE_BOXED (*arg), - NULL); - break; - - case ARG_EDITABLE: - gtk_object_get(GTK_OBJECT(ee->item), - "editable", >K_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_USE_ELLIPSIS: - gtk_object_get(GTK_OBJECT(ee->item), - "use_ellipsis", >K_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_ELLIPSIS: - gtk_object_get(GTK_OBJECT(ee->item), - "ellipsis", >K_VALUE_STRING (*arg), - NULL); - break; - - case ARG_LINE_WRAP: - gtk_object_get(GTK_OBJECT(ee->item), - "line_wrap", >K_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_BREAK_CHARACTERS: - gtk_object_get(GTK_OBJECT(ee->item), - "break_characters", >K_VALUE_STRING (*arg), - NULL); - break; - - case ARG_MAX_LINES: - gtk_object_get(GTK_OBJECT(ee->item), - "max_lines", >K_VALUE_INT (*arg), - NULL); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -et_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - EEntry *ee = E_ENTRY (o); - - switch (arg_id){ - case ARG_MODEL: - gtk_object_set(GTK_OBJECT(ee->item), - "model", GTK_VALUE_OBJECT (*arg), - NULL); - break; - - case ARG_EVENT_PROCESSOR: - gtk_object_set(GTK_OBJECT(ee->item), - "event_processor", GTK_VALUE_OBJECT (*arg), - NULL); - break; - - case ARG_TEXT: - gtk_object_set(GTK_OBJECT(ee->item), - "text", GTK_VALUE_STRING (*arg), - NULL); - break; - - case ARG_FONT: - gtk_object_set(GTK_OBJECT(ee->item), - "font", GTK_VALUE_STRING (*arg), - NULL); - break; - - case ARG_FONTSET: - gtk_object_set(GTK_OBJECT(ee->item), - "fontset", GTK_VALUE_STRING (*arg), - NULL); - break; - - case ARG_FONT_GDK: - gtk_object_set(GTK_OBJECT(ee->item), - "font_gdk", GTK_VALUE_BOXED (*arg), - NULL); - break; - - case ARG_JUSTIFICATION: - gtk_object_set(GTK_OBJECT(ee->item), - "justification", GTK_VALUE_ENUM (*arg), - NULL); - break; - - case ARG_FILL_COLOR: - gtk_object_set(GTK_OBJECT(ee->item), - "fill_color", GTK_VALUE_STRING (*arg), - NULL); - break; - - case ARG_FILL_COLOR_GDK: - gtk_object_set(GTK_OBJECT(ee->item), - "fill_color_gdk", GTK_VALUE_BOXED (*arg), - NULL); - break; - - case ARG_FILL_COLOR_RGBA: - gtk_object_set(GTK_OBJECT(ee->item), - "fill_color_rgba", GTK_VALUE_UINT (*arg), - NULL); - break; - - case ARG_FILL_STIPPLE: - gtk_object_set(GTK_OBJECT(ee->item), - "fill_stiple", GTK_VALUE_BOXED (*arg), - NULL); - break; - - case ARG_EDITABLE: - gtk_object_set(GTK_OBJECT(ee->item), - "editable", GTK_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_USE_ELLIPSIS: - gtk_object_set(GTK_OBJECT(ee->item), - "use_ellipsis", GTK_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_ELLIPSIS: - gtk_object_set(GTK_OBJECT(ee->item), - "ellipsis", GTK_VALUE_STRING (*arg), - NULL); - break; - - case ARG_LINE_WRAP: - gtk_object_set(GTK_OBJECT(ee->item), - "line_wrap", GTK_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_BREAK_CHARACTERS: - gtk_object_set(GTK_OBJECT(ee->item), - "break_characters", GTK_VALUE_STRING (*arg), - NULL); - break; - - case ARG_MAX_LINES: - gtk_object_set(GTK_OBJECT(ee->item), - "max_lines", GTK_VALUE_INT (*arg), - NULL); - break; - } -} - -static void -e_entry_class_init (GtkObjectClass *object_class) -{ - EEntryClass *klass = E_ENTRY_CLASS(object_class); - parent_class = gtk_type_class (PARENT_TYPE); - - object_class->set_arg = et_set_arg; - object_class->get_arg = et_get_arg; - - klass->changed = NULL; - klass->activate = NULL; - - e_entry_signals[E_ENTRY_CHANGED] = - gtk_signal_new ("changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EEntryClass, changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_entry_signals[E_ENTRY_ACTIVATE] = - gtk_signal_new ("activate", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EEntryClass, activate), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - - gtk_object_class_add_signals (object_class, e_entry_signals, E_ENTRY_LAST_SIGNAL); - - gtk_object_add_arg_type ("EEntry::model", - GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_MODEL); - gtk_object_add_arg_type ("EEntry::event_processor", - GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_EVENT_PROCESSOR); - gtk_object_add_arg_type ("EEntry::text", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TEXT); - gtk_object_add_arg_type ("EEntry::font", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONT); - gtk_object_add_arg_type ("EEntry::fontset", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONTSET); - gtk_object_add_arg_type ("EEntry::font_gdk", - GTK_TYPE_GDK_FONT, GTK_ARG_READWRITE, ARG_FONT_GDK); - gtk_object_add_arg_type ("EEntry::justification", - GTK_TYPE_JUSTIFICATION, GTK_ARG_READWRITE, ARG_JUSTIFICATION); - gtk_object_add_arg_type ("EEntry::fill_color", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FILL_COLOR); - gtk_object_add_arg_type ("EEntry::fill_color_gdk", - GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_FILL_COLOR_GDK); - gtk_object_add_arg_type ("EEntry::fill_color_rgba", - GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_FILL_COLOR_RGBA); - gtk_object_add_arg_type ("EEntry::fill_stipple", - GTK_TYPE_GDK_WINDOW, GTK_ARG_READWRITE, ARG_FILL_STIPPLE); - gtk_object_add_arg_type ("EEntry::editable", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_EDITABLE); - gtk_object_add_arg_type ("EEntry::use_ellipsis", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_USE_ELLIPSIS); - gtk_object_add_arg_type ("EEntry::ellipsis", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ELLIPSIS); - gtk_object_add_arg_type ("EEntry::line_wrap", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_LINE_WRAP); - gtk_object_add_arg_type ("EEntry::break_characters", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_BREAK_CHARACTERS); - gtk_object_add_arg_type ("EEntry::max_lines", - GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_MAX_LINES); -} - -E_MAKE_TYPE(e_entry, "EEntry", EEntry, e_entry_class_init, e_entry_init, PARENT_TYPE); diff --git a/widgets/e-text/e-entry.h b/widgets/e-text/e-entry.h deleted file mode 100644 index ad349659c3..0000000000 --- a/widgets/e-text/e-entry.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_ENTRY_H_ -#define _E_ENTRY_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gtk/gtktable.h> -#include <gnome-xml/tree.h> -#include "e-text.h" - -BEGIN_GNOME_DECLS - -#define E_ENTRY_TYPE (e_entry_get_type ()) -#define E_ENTRY(o) (GTK_CHECK_CAST ((o), E_ENTRY_TYPE, EEntry)) -#define E_ENTRY_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_ENTRY_TYPE, EEntryClass)) -#define E_IS_ENTRY(o) (GTK_CHECK_TYPE ((o), E_ENTRY_TYPE)) -#define E_IS_ENTRY_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_ENTRY_TYPE)) - -typedef struct { - GtkTable parent; - - GnomeCanvas *canvas; - EText *item; -} EEntry; - -typedef struct { - GtkTableClass parent_class; - - void (* changed) (EEntry *entry); - void (* activate) (EEntry *entry); -} EEntryClass; - -GtkType e_entry_get_type (void); - -EEntry *e_entry_construct (EEntry *e_entry); -GtkWidget *e_entry_new (void); - -END_GNOME_DECLS - -#endif /* _E_ENTRY_H_ */ diff --git a/widgets/e-text/e-text-event-processor-emacs-like.c b/widgets/e-text/e-text-event-processor-emacs-like.c deleted file mode 100644 index be323d028f..0000000000 --- a/widgets/e-text/e-text-event-processor-emacs-like.c +++ /dev/null @@ -1,372 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <gnome.h> -#include "e-text-event-processor-emacs-like.h" -static void e_text_event_processor_emacs_like_init (ETextEventProcessorEmacsLike *card); -static void e_text_event_processor_emacs_like_class_init (ETextEventProcessorEmacsLikeClass *klass); -static gint e_text_event_processor_emacs_like_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event); - -static ETextEventProcessorClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0 -}; - -static const ETextEventProcessorCommand control_keys[26] = -{ - { E_TEP_START_OF_LINE, E_TEP_MOVE, 0, "" }, /* a */ - { E_TEP_BACKWARD_CHARACTER, E_TEP_MOVE, 0, "" }, /* b */ - { E_TEP_SELECTION, E_TEP_COPY, 0, "" }, /* c */ - { E_TEP_FORWARD_CHARACTER, E_TEP_DELETE, 0, "" }, /* d */ - { E_TEP_END_OF_LINE, E_TEP_MOVE, 0, "" }, /* e */ - { E_TEP_FORWARD_CHARACTER, E_TEP_MOVE, 0, "" }, /* f */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* g */ - { E_TEP_BACKWARD_CHARACTER, E_TEP_DELETE, 0, "" }, /* h */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* i */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* j */ - { E_TEP_END_OF_LINE, E_TEP_DELETE, 0, "" }, /* k */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* l */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* m */ - { E_TEP_FORWARD_LINE, E_TEP_MOVE, 0, "" }, /* n */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* o */ - { E_TEP_BACKWARD_LINE, E_TEP_MOVE, 0, "" }, /* p */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* q */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* r */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* s */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* t */ - { E_TEP_START_OF_LINE, E_TEP_DELETE, 0, "" }, /* u */ - { E_TEP_SELECTION, E_TEP_PASTE, 0, "" }, /* v */ - { E_TEP_SELECTION, E_TEP_DELETE, 0, "" }, /* w */ - { E_TEP_SELECTION, E_TEP_DELETE, 0, "" }, /* x */ - { E_TEP_SELECTION, E_TEP_PASTE, 0, "" }, /* y */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" } /* z */ -}; - -static const ETextEventProcessorCommand alt_keys[26] = -{ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* a */ - { E_TEP_BACKWARD_WORD, E_TEP_MOVE, 0, "" }, /* b */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* c */ - { E_TEP_FORWARD_WORD, E_TEP_DELETE, 0, "" }, /* d */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* e */ - { E_TEP_FORWARD_WORD, E_TEP_MOVE, 0, "" }, /* f */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* g */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* h */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* i */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* j */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* k */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* l */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* m */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* n */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* o */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* p */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* q */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* r */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* s */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* t */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* u */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* v */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* w */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* x */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* y */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" } /* z */ - -}; - -GtkType -e_text_event_processor_emacs_like_get_type (void) -{ - static GtkType text_event_processor_emacs_like_type = 0; - - if (!text_event_processor_emacs_like_type) - { - static const GtkTypeInfo text_event_processor_emacs_like_info = - { - "ETextEventProcessorEmacsLike", - sizeof (ETextEventProcessorEmacsLike), - sizeof (ETextEventProcessorEmacsLikeClass), - (GtkClassInitFunc) e_text_event_processor_emacs_like_class_init, - (GtkObjectInitFunc) e_text_event_processor_emacs_like_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - text_event_processor_emacs_like_type = gtk_type_unique (e_text_event_processor_get_type (), &text_event_processor_emacs_like_info); - } - - return text_event_processor_emacs_like_type; -} - -static void -e_text_event_processor_emacs_like_class_init (ETextEventProcessorEmacsLikeClass *klass) -{ - GtkObjectClass *object_class; - ETextEventProcessorClass *processor_class; - - object_class = (GtkObjectClass*) klass; - processor_class = (ETextEventProcessorClass*) klass; - - parent_class = gtk_type_class (e_text_event_processor_get_type ()); - - processor_class->event = e_text_event_processor_emacs_like_event; -} - -static void -e_text_event_processor_emacs_like_init (ETextEventProcessorEmacsLike *tep) -{ -} - -static gint -e_text_event_processor_emacs_like_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event) -{ - ETextEventProcessorCommand command; - ETextEventProcessorEmacsLike *tep_el = E_TEXT_EVENT_PROCESSOR_EMACS_LIKE(tep); - command.action = E_TEP_NOP; - switch (event->type) { - case GDK_BUTTON_PRESS: - if (event->button.button == 1) { - command.action = E_TEP_GRAB; - command.time = event->button.time; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - if (event->button.state & GDK_SHIFT_MASK) - command.action = E_TEP_SELECT; - else - command.action = E_TEP_MOVE; - command.position = E_TEP_VALUE; - command.value = event->button.position; - command.time = event->button.time; - tep_el->mouse_down = TRUE; - } - break; - case GDK_2BUTTON_PRESS: - if (event->button.button == 1) { - command.action = E_TEP_SELECT; - command.position = E_TEP_SELECT_WORD; - command.time = event->button.time; - } - break; - case GDK_3BUTTON_PRESS: - if (event->button.button == 1) { - command.action = E_TEP_SELECT; - command.position = E_TEP_SELECT_ALL; - command.time = event->button.time; - } - break; - case GDK_BUTTON_RELEASE: - if (event->button.button == 1) { - command.action = E_TEP_UNGRAB; - command.time = event->button.time; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - command.time = event->button.time; - tep_el->mouse_down = FALSE; - command.action = E_TEP_NOP; - } else if (event->button.button == 2) { - command.action = E_TEP_MOVE; - command.position = E_TEP_VALUE; - command.value = event->button.position; - command.time = event->button.time; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - - command.action = E_TEP_GET_SELECTION; - command.position = E_TEP_SELECTION; - command.value = 0; - command.time = event->button.time; - } - break; - case GDK_MOTION_NOTIFY: - if (tep_el->mouse_down) { - command.action = E_TEP_SELECT; - command.position = E_TEP_VALUE; - command.time = event->motion.time; - command.value = event->motion.position; - } - break; - case GDK_KEY_PRESS: - { - ETextEventProcessorEventKey key = event->key; - command.time = event->key.time; - if (key.state & GDK_SHIFT_MASK) - command.action = E_TEP_SELECT; - else - command.action = E_TEP_MOVE; - switch(key.keyval) { - case GDK_Home: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_START_OF_BUFFER; - else - command.position = E_TEP_START_OF_LINE; - break; - case GDK_End: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_END_OF_BUFFER; - else - command.position = E_TEP_END_OF_LINE; - break; - case GDK_Page_Up: command.position = E_TEP_BACKWARD_PAGE; break; - case GDK_Page_Down: command.position = E_TEP_FORWARD_PAGE; break; - /* CUA has Ctrl-Up/Ctrl-Down as paragraph up down */ - case GDK_Up: command.position = E_TEP_BACKWARD_LINE; break; - case GDK_Down: command.position = E_TEP_FORWARD_LINE; break; - case GDK_Left: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_BACKWARD_WORD; - else - command.position = E_TEP_BACKWARD_CHARACTER; - break; - case GDK_Right: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_FORWARD_WORD; - else - command.position = E_TEP_FORWARD_CHARACTER; - break; - - case GDK_BackSpace: - command.action = E_TEP_DELETE; - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_BACKWARD_WORD; - else - command.position = E_TEP_BACKWARD_CHARACTER; - break; - case GDK_Clear: - command.action = E_TEP_DELETE; - command.position = E_TEP_END_OF_LINE; - break; - case GDK_Insert: - if (key.state & GDK_SHIFT_MASK) { - command.action = E_TEP_PASTE; - command.position = E_TEP_SELECTION; - } else if (key.state & GDK_CONTROL_MASK) { - command.action = E_TEP_COPY; - command.position = E_TEP_SELECTION; - } else { - /* gtk_toggle_insert(text) -- IMPLEMENT */ - } - break; - case GDK_Delete: - if (key.state & GDK_CONTROL_MASK){ - command.action = E_TEP_DELETE; - command.position = E_TEP_FORWARD_WORD; - } else if (key.state & GDK_SHIFT_MASK) { - command.action = E_TEP_COPY; - command.position = E_TEP_SELECTION; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - - command.action = E_TEP_DELETE; - command.position = E_TEP_SELECTION; - } else { - command.action = E_TEP_DELETE; - command.position = E_TEP_FORWARD_CHARACTER; - } - break; - case GDK_Tab: - /* Don't insert literally */ - command.action = E_TEP_NOP; - command.position = E_TEP_SELECTION; - break; - case GDK_Return: - if (key.state & GDK_CONTROL_MASK) { - command.action = E_TEP_ACTIVATE; - command.position = E_TEP_SELECTION; - } else { - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "\n"; - } - break; - case GDK_Escape: - /* Don't insert literally */ - command.action = E_TEP_NOP; - command.position = E_TEP_SELECTION; - break; - - default: - if (key.state & GDK_CONTROL_MASK) { - if ((key.keyval >= 'A') && (key.keyval <= 'Z')) - key.keyval -= 'A' - 'a'; - - if ((key.keyval >= 'a') && (key.keyval <= 'z')) { - command.position = control_keys[(int) (key.keyval - 'a')].position; - if (control_keys[(int) (key.keyval - 'a')].action != E_TEP_MOVE) - command.action = control_keys[(int) (key.keyval - 'a')].action; - command.value = control_keys[(int) (key.keyval - 'a')].value; - command.string = control_keys[(int) (key.keyval - 'a')].string; - } - - if (key.keyval == 'x' || key.keyval == 'w') { - command.action = E_TEP_COPY; - command.position = E_TEP_SELECTION; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - - command.action = E_TEP_DELETE; - command.position = E_TEP_SELECTION; - } - - break; - } else if (key.state & GDK_MOD1_MASK) { - if ((key.keyval >= 'A') && (key.keyval <= 'Z')) - key.keyval -= 'A' - 'a'; - - if ((key.keyval >= 'a') && (key.keyval <= 'z')) { - command.position = alt_keys[(int) (key.keyval - 'a')].position; - if (alt_keys[(int) (key.keyval - 'a')].action != E_TEP_MOVE) - command.action = alt_keys[(int) (key.keyval - 'a')].action; - command.value = alt_keys[(int) (key.keyval - 'a')].value; - command.string = alt_keys[(int) (key.keyval - 'a')].string; - } - } else if (key.length > 0) { - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = strlen(key.string); - command.string = key.string; - - } else { - command.action = E_TEP_NOP; - } - } - break; - case GDK_KEY_RELEASE: - command.time = event->key.time; - command.action = E_TEP_NOP; - break; - default: - command.action = E_TEP_NOP; - break; - } - } - if (command.action != E_TEP_NOP) { - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - return 1; - } - else - return 0; -} - -ETextEventProcessor * -e_text_event_processor_emacs_like_new (void) -{ - ETextEventProcessorEmacsLike *retval = gtk_type_new (e_text_event_processor_emacs_like_get_type ()); - return E_TEXT_EVENT_PROCESSOR (retval); -} - diff --git a/widgets/e-text/e-text-event-processor-emacs-like.h b/widgets/e-text/e-text-event-processor-emacs-like.h deleted file mode 100644 index 651bb552b3..0000000000 --- a/widgets/e-text/e-text-event-processor-emacs-like.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor-emacs-like.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef __E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_H__ -#define __E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_H__ - -#include <gnome.h> -#include "e-text-event-processor.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ETextEventProcessorEmacsLike - Turns events on a text widget into commands. Uses an emacs-ish interface. - * - */ - -#define E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE (e_text_event_processor_emacs_like_get_type ()) -#define E_TEXT_EVENT_PROCESSOR_EMACS_LIKE(obj) (GTK_CHECK_CAST ((obj), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE, ETextEventProcessorEmacsLike)) -#define E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE, ETextEventProcessorEmacsLikeClass)) -#define E_IS_TEXT_EVENT_PROCESSOR_EMACS_LIKE(obj) (GTK_CHECK_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE)) -#define E_IS_TEXT_EVENT_PROCESSOR_EMACS_LIKE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE)) - - -typedef struct _ETextEventProcessorEmacsLike ETextEventProcessorEmacsLike; -typedef struct _ETextEventProcessorEmacsLikeClass ETextEventProcessorEmacsLikeClass; - -struct _ETextEventProcessorEmacsLike -{ - ETextEventProcessor parent; - - /* object specific fields */ - gboolean mouse_down; -}; - -struct _ETextEventProcessorEmacsLikeClass -{ - ETextEventProcessorClass parent_class; -}; - - -GtkType e_text_event_processor_emacs_like_get_type (void); -ETextEventProcessor *e_text_event_processor_emacs_like_new (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_H__ */ diff --git a/widgets/e-text/e-text-event-processor-types.h b/widgets/e-text/e-text-event-processor-types.h deleted file mode 100644 index 8f2ffbaf39..0000000000 --- a/widgets/e-text/e-text-event-processor-types.h +++ /dev/null @@ -1,140 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#ifndef __E_TEXT_EVENT_PROCESSOR_TYPES_H__ -#define __E_TEXT_EVENT_PROCESSOR_TYPES_H__ - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -#include <gdk/gdktypes.h> - -typedef enum _ETextEventProcessorCommandPosition ETextEventProcessorCommandPosition; -typedef enum _ETextEventProcessorCommandAction ETextEventProcessorCommandAction; -typedef struct _ETextEventProcessorCommand ETextEventProcessorCommand; - -typedef union _ETextEventProcessorEvent ETextEventProcessorEvent; -typedef struct _ETextEventProcessorEventButton ETextEventProcessorEventButton; -typedef struct _ETextEventProcessorEventKey ETextEventProcessorEventKey; -typedef struct _ETextEventProcessorEventMotion ETextEventProcessorEventMotion; - -enum _ETextEventProcessorCommandPosition { - E_TEP_VALUE, - E_TEP_SELECTION, - - E_TEP_START_OF_BUFFER, - E_TEP_END_OF_BUFFER, - - E_TEP_START_OF_LINE, - E_TEP_END_OF_LINE, - - E_TEP_FORWARD_CHARACTER, - E_TEP_BACKWARD_CHARACTER, - - E_TEP_FORWARD_WORD, - E_TEP_BACKWARD_WORD, - - E_TEP_FORWARD_LINE, - E_TEP_BACKWARD_LINE, - - E_TEP_FORWARD_PARAGRAPH, - E_TEP_BACKWARD_PARAGRAPH, - - E_TEP_FORWARD_PAGE, - E_TEP_BACKWARD_PAGE, - - E_TEP_SELECT_WORD, - E_TEP_SELECT_ALL - -}; - -enum _ETextEventProcessorCommandAction { - E_TEP_MOVE, - E_TEP_SELECT, - E_TEP_DELETE, - E_TEP_INSERT, - - E_TEP_COPY, - E_TEP_PASTE, - E_TEP_GET_SELECTION, - E_TEP_SET_SELECT_BY_WORD, - E_TEP_ACTIVATE, - - E_TEP_GRAB, - E_TEP_UNGRAB, - - E_TEP_NOP -}; - -struct _ETextEventProcessorCommand { - ETextEventProcessorCommandPosition position; - ETextEventProcessorCommandAction action; - int value; - char *string; - guint32 time; -}; - -struct _ETextEventProcessorEventButton { - GdkEventType type; - guint32 time; - guint state; - guint button; - gint position; -}; - -struct _ETextEventProcessorEventKey { - GdkEventType type; - guint32 time; - guint state; - guint keyval; - gint length; - gchar *string; -}; - -struct _ETextEventProcessorEventMotion { - GdkEventType type; - guint32 time; - guint state; - gint position; -}; - -union _ETextEventProcessorEvent { - GdkEventType type; - ETextEventProcessorEventButton button; - ETextEventProcessorEventKey key; - ETextEventProcessorEventMotion motion; -}; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TEXT_EVENT_PROCESSOR_TYPES_H__ */ diff --git a/widgets/e-text/e-text-event-processor.c b/widgets/e-text/e-text-event-processor.c deleted file mode 100644 index 47f028ca62..0000000000 --- a/widgets/e-text/e-text-event-processor.c +++ /dev/null @@ -1,103 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <gnome.h> -#include "e-text-event-processor.h" -static void e_text_event_processor_init (ETextEventProcessor *card); -static void e_text_event_processor_class_init (ETextEventProcessorClass *klass); - -static GtkObjectClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0 -}; - -enum { - E_TEP_EVENT, - E_TEP_LAST_SIGNAL -}; - -static guint e_tep_signals[E_TEP_LAST_SIGNAL] = { 0 }; - -GtkType -e_text_event_processor_get_type (void) -{ - static GtkType text_event_processor_type = 0; - - if (!text_event_processor_type) - { - static const GtkTypeInfo text_event_processor_info = - { - "ETextEventProcessor", - sizeof (ETextEventProcessor), - sizeof (ETextEventProcessorClass), - (GtkClassInitFunc) e_text_event_processor_class_init, - (GtkObjectInitFunc) e_text_event_processor_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - text_event_processor_type = gtk_type_unique (gtk_object_get_type (), &text_event_processor_info); - } - - return text_event_processor_type; -} - -static void -e_text_event_processor_class_init (ETextEventProcessorClass *klass) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass*) klass; - - parent_class = gtk_type_class (gtk_object_get_type ()); - - e_tep_signals[E_TEP_EVENT] = - gtk_signal_new ("command", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETextEventProcessorClass, command), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, - GTK_TYPE_POINTER); - - gtk_object_class_add_signals (object_class, e_tep_signals, E_TEP_LAST_SIGNAL); - - klass->event = NULL; - klass->command = NULL; -} - -static void -e_text_event_processor_init (ETextEventProcessor *tep) -{ -} - -gint -e_text_event_processor_handle_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event) -{ - if (E_TEXT_EVENT_PROCESSOR_CLASS(GTK_OBJECT(tep)->klass)->event) { - return E_TEXT_EVENT_PROCESSOR_CLASS(GTK_OBJECT(tep)->klass)->event(tep, event); - } else { - return 0; - } -} diff --git a/widgets/e-text/e-text-event-processor.h b/widgets/e-text/e-text-event-processor.h deleted file mode 100644 index 1fc79f3f70..0000000000 --- a/widgets/e-text/e-text-event-processor.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef __E_TEXT_EVENT_PROCESSOR_H__ -#define __E_TEXT_EVENT_PROCESSOR_H__ - -#include <gnome.h> -#include "e-text-event-processor-types.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ETextEventProcessor - Turns events on a text widget into commands. - * - */ - -#define E_TEXT_EVENT_PROCESSOR_TYPE (e_text_event_processor_get_type ()) -#define E_TEXT_EVENT_PROCESSOR(obj) (GTK_CHECK_CAST ((obj), E_TEXT_EVENT_PROCESSOR_TYPE, ETextEventProcessor)) -#define E_TEXT_EVENT_PROCESSOR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TEXT_EVENT_PROCESSOR_TYPE, ETextEventProcessorClass)) -#define E_IS_TEXT_EVENT_PROCESSOR(obj) (GTK_CHECK_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_TYPE)) -#define E_IS_TEXT_EVENT_PROCESSOR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_TYPE)) - - -typedef struct _ETextEventProcessor ETextEventProcessor; -typedef struct _ETextEventProcessorClass ETextEventProcessorClass; - -struct _ETextEventProcessor -{ - GtkObject parent; - - /* object specific fields */ - -}; - -struct _ETextEventProcessorClass -{ - GtkObjectClass parent_class; - - /* signals */ - void (* command) (ETextEventProcessor *tep, ETextEventProcessorCommand *command); - - /* virtual functions */ - gint (* event) (ETextEventProcessor *tep, ETextEventProcessorEvent *event); -}; - - -GtkType e_text_event_processor_get_type (void); -gint e_text_event_processor_handle_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TEXT_EVENT_PROCESSOR_H__ */ diff --git a/widgets/e-text/e-text-model.c b/widgets/e-text/e-text-model.c deleted file mode 100644 index 6ca650867c..0000000000 --- a/widgets/e-text/e-text-model.c +++ /dev/null @@ -1,244 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ETextModel - Text item model for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey <clahey@umich.edu> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> */ - -#include <config.h> -#include <ctype.h> -#include "e-text-model.h" - -enum { - E_TEXT_MODEL_CHANGED, - E_TEXT_MODEL_LAST_SIGNAL -}; - -static guint e_text_model_signals[E_TEXT_MODEL_LAST_SIGNAL] = { 0 }; - -static void e_text_model_class_init (ETextModelClass *class); -static void e_text_model_init (ETextModel *model); -static void e_text_model_destroy (GtkObject *object); - -static gchar *e_text_model_real_get_text(ETextModel *model); -static void e_text_model_real_set_text(ETextModel *model, gchar *text); -static void e_text_model_real_insert(ETextModel *model, gint postion, gchar *text); -static void e_text_model_real_insert_length(ETextModel *model, gint postion, gchar *text, gint length); -static void e_text_model_real_delete(ETextModel *model, gint postion, gint length); - -static GtkObject *parent_class; - - - -/** - * e_text_model_get_type: - * @void: - * - * Registers the &ETextModel class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &ETextModel class. - **/ -GtkType -e_text_model_get_type (void) -{ - static GtkType model_type = 0; - - if (!model_type) { - GtkTypeInfo model_info = { - "ETextModel", - sizeof (ETextModel), - sizeof (ETextModelClass), - (GtkClassInitFunc) e_text_model_class_init, - (GtkObjectInitFunc) e_text_model_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - model_type = gtk_type_unique (gtk_object_get_type (), &model_info); - } - - return model_type; -} - -/* Class initialization function for the text item */ -static void -e_text_model_class_init (ETextModelClass *klass) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass *) klass; - - parent_class = gtk_type_class (gtk_object_get_type ()); - - e_text_model_signals[E_TEXT_MODEL_CHANGED] = - gtk_signal_new ("changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETextModelClass, changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, e_text_model_signals, E_TEXT_MODEL_LAST_SIGNAL); - - klass->changed = NULL; - klass->get_text = e_text_model_real_get_text; - klass->set_text = e_text_model_real_set_text; - klass->insert = e_text_model_real_insert; - klass->insert_length = e_text_model_real_insert_length; - klass->delete = e_text_model_real_delete; - - object_class->destroy = e_text_model_destroy; -} - -/* Object initialization function for the text item */ -static void -e_text_model_init (ETextModel *model) -{ - model->text = NULL; -} - -/* Destroy handler for the text item */ -static void -e_text_model_destroy (GtkObject *object) -{ - ETextModel *model; - - g_return_if_fail (object != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (object)); - - model = E_TEXT_MODEL (object); - - if (model->text) - g_free (model->text); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -static gchar * -e_text_model_real_get_text(ETextModel *model) -{ - if (model->text) - return model->text; - else - return ""; -} - -static void -e_text_model_real_set_text(ETextModel *model, gchar *text) -{ - if (model->text) - g_free(model->text); - model->text = g_strdup(text); - e_text_model_changed(model); -} - -static void -e_text_model_real_insert(ETextModel *model, gint position, gchar *text) -{ - gchar *temp = g_strdup_printf("%.*s%s%s", position, model->text, text, model->text + position); - if (model->text) - g_free(model->text); - model->text = temp; - e_text_model_changed(model); -} - -static void -e_text_model_real_insert_length(ETextModel *model, gint position, gchar *text, gint length) -{ - gchar *temp = g_strdup_printf("%.*s%.*s%s", position, model->text, length, text, model->text + position); - if (model->text) - g_free(model->text); - model->text = temp; - e_text_model_changed(model); -} - -static void -e_text_model_real_delete(ETextModel *model, gint position, gint length) -{ - memmove(model->text + position, model->text + position + length, strlen(model->text + position + length) + 1); - e_text_model_changed(model); -} - -void -e_text_model_changed(ETextModel *model) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - gtk_signal_emit (GTK_OBJECT (model), - e_text_model_signals [E_TEXT_MODEL_CHANGED]); -} - -gchar * -e_text_model_get_text(ETextModel *model) -{ - g_return_val_if_fail (model != NULL, NULL); - g_return_val_if_fail (E_IS_TEXT_MODEL (model), NULL); - - if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->get_text ) - return E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->get_text(model); - else - return ""; -} - -void -e_text_model_set_text(ETextModel *model, gchar *text) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->set_text ) - E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->set_text(model, text); -} - -void -e_text_model_insert(ETextModel *model, gint position, gchar *text) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert ) - E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert(model, position, text); -} - -void -e_text_model_insert_length(ETextModel *model, gint position, gchar *text, gint length) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert_length ) - E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert_length(model, position, text, length); -} - -void -e_text_model_delete(ETextModel *model, gint position, gint length) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->delete ) - E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->delete(model, position, length); -} - -ETextModel * -e_text_model_new(void) -{ - ETextModel *model = gtk_type_new (e_text_model_get_type ()); - model->text = g_strdup(""); - return model; -} diff --git a/widgets/e-text/e-text-model.h b/widgets/e-text/e-text-model.h deleted file mode 100644 index 5b15ccb117..0000000000 --- a/widgets/e-text/e-text-model.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ETextModel - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey <clahey@umich.edu> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> */ - -#ifndef E_TEXT_MODEL_H -#define E_TEXT_MODEL_H - -#include <gnome.h> - - -BEGIN_GNOME_DECLS - -#define E_TYPE_TEXT_MODEL (e_text_model_get_type ()) -#define E_TEXT_MODEL(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TEXT_MODEL, ETextModel)) -#define E_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TEXT_MODEL, ETextModelClass)) -#define E_IS_TEXT_MODEL(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TEXT_MODEL)) -#define E_IS_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TEXT_MODEL)) - -typedef struct _ETextModel ETextModel; -typedef struct _ETextModelClass ETextModelClass; - -struct _ETextModel { - GtkObject item; - - char *text; /* Text to display */ - int length; -}; - -struct _ETextModelClass { - GtkObjectClass parent_class; - - /* Signal */ - void (* changed) (ETextModel *model); - - /* Virtual methods */ - char *(* get_text) (ETextModel *model); - void (* set_text) (ETextModel *model, gchar *text); - void (* insert) (ETextModel *model, gint position, gchar *text); - void (* insert_length) (ETextModel *model, gint position, gchar *text, gint length); - void (* delete) (ETextModel *model, gint position, gint length); -}; - - -/* Standard Gtk function */ -GtkType e_text_model_get_type (void); -ETextModel *e_text_model_new(void); - -void e_text_model_changed(ETextModel *model); -gchar *e_text_model_get_text(ETextModel *model); -void e_text_model_set_text(ETextModel *model, gchar *text); -void e_text_model_insert(ETextModel *model, gint position, gchar *text); -void e_text_model_insert_length(ETextModel *model, gint position, gchar *text, gint length); -void e_text_model_delete(ETextModel *model, gint position, gint length); - - -END_GNOME_DECLS - -#endif diff --git a/widgets/e-text/e-text-test.c b/widgets/e-text/e-text-test.c deleted file mode 100644 index 12a31cce7e..0000000000 --- a/widgets/e-text/e-text-test.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - ETextTest: E-Text item test program - Copyright (C)2000: Iain Holmes <ih@csd.abdn.ac.uk> - - This code is licensed under the GPL -*/ - -#include "e-text.h" -#include <gnome.h> -#include "e-util/e-canvas.h" -GnomeCanvasItem *rect; - -static void allocate_callback(GtkWidget *canvas, GtkAllocation *allocation, GnomeCanvasItem *item) -{ - double height; - gnome_canvas_item_set( item, - "width", (double) allocation->width, - NULL ); - gtk_object_get(GTK_OBJECT(item), - "height", &height, - NULL); - height = MAX(height, allocation->height); - gnome_canvas_set_scroll_region(GNOME_CANVAS( canvas ), 0, 0, allocation->width, height ); - gnome_canvas_item_set( rect, - "x2", (double) allocation->width, - "y2", (double) height, - NULL ); -} - -static void -reflow (GtkWidget *canvas, GnomeCanvasItem *item) -{ - double height; - gtk_object_get(GTK_OBJECT(item), - "height", &height, - NULL); - height = MAX(height, canvas->allocation.height); - gnome_canvas_set_scroll_region(GNOME_CANVAS( canvas ), 0, 0, canvas->allocation.width, height ); - gnome_canvas_item_set( rect, - "x2", (double) canvas->allocation.width, - "y2", (double) height, - NULL ); -} - -static void -quit_cb (GtkWidget *widget, - gpointer data) -{ - gtk_main_quit (); -} - -static void -change_text_cb (GtkEntry *entry, - EText *text) -{ - gchar *str; - - str = gtk_entry_get_text (entry); - gnome_canvas_item_set (GNOME_CANVAS_ITEM (text), - "text", str, - NULL); -} - -static void -change_font_cb (GtkEntry *entry, - EText *text) -{ - gchar *font; - - font = gtk_entry_get_text (entry); - gnome_canvas_item_set (GNOME_CANVAS_ITEM (text), - "font", font, - NULL); -} - -int -main (int argc, - char **argv) -{ - GtkWidget *window, *canvas, *scroller, *vbox, *text, *font; - GtkWidget *frame; - GnomeCanvasItem *item; - - gnome_init ("ETextTest", "0.0.1", argc, argv); - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "EText Test"); - gtk_signal_connect (GTK_OBJECT (window), "destroy", - GTK_SIGNAL_FUNC (quit_cb), NULL); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - canvas = e_canvas_new (); - gtk_widget_pop_visual (); - gtk_widget_pop_colormap (); - scroller = gtk_scrolled_window_new (NULL, NULL); - vbox = gtk_vbox_new (FALSE, 2); - - gtk_container_add (GTK_CONTAINER (window), vbox); - gtk_box_pack_start (GTK_BOX (vbox), scroller, TRUE, TRUE, 2); - gtk_container_add (GTK_CONTAINER (scroller), canvas); - - frame = gtk_frame_new ("Text"); - text = gtk_entry_new (); - gtk_entry_set_text(GTK_ENTRY(text), "Hello World! This is a really long string to test out the ellipsis stuff."); - gtk_container_add (GTK_CONTAINER (frame), text); - gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); - - frame = gtk_frame_new ("Font"); - font = gtk_entry_new (); - gtk_entry_set_text(GTK_ENTRY(font), "fixed"); - gtk_container_add (GTK_CONTAINER (frame), font); - gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); - - rect = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) 100, - "y2", (double) 100, - "fill_color", "white", - NULL ); - - item = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)), - e_text_get_type (), - "text", "Hello World! This is a really long string to test out the ellipsis stuff.", - "font", "fixed", - "fill_color", "black", - "anchor", GTK_ANCHOR_NW, - "clip", TRUE, - "use_ellipsis", TRUE, - "editable", TRUE, - "line_wrap", TRUE, - "max_lines", 2, - "width", 150.0, - NULL); - - gtk_signal_connect (GTK_OBJECT (text), "activate", - GTK_SIGNAL_FUNC (change_text_cb), item); - gtk_signal_connect (GTK_OBJECT (font), "activate", - GTK_SIGNAL_FUNC (change_font_cb), item); - - gtk_signal_connect( GTK_OBJECT( canvas ), "size_allocate", - GTK_SIGNAL_FUNC( allocate_callback ), - item ); - gtk_signal_connect( GTK_OBJECT( canvas ), "reflow", - GTK_SIGNAL_FUNC( reflow ), - item ); - gnome_canvas_set_scroll_region (GNOME_CANVAS (canvas), 0.0, 0.0, 400.0, 400.0); - gtk_widget_show_all (window); - gtk_main (); - - return 0; -} diff --git a/widgets/e-text/e-text.c b/widgets/e-text/e-text.c deleted file mode 100644 index 30e6452ed0..0000000000 --- a/widgets/e-text/e-text.c +++ /dev/null @@ -1,3365 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* EText - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey <clahey@umich.edu> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> */ - -#include <config.h> -#include <math.h> -#include <ctype.h> -#include "e-text.h" -#include <gdk/gdkx.h> /* for BlackPixel */ -#include <libart_lgpl/art_affine.h> -#include <libart_lgpl/art_rgb.h> -#include <libart_lgpl/art_rgb_bitmap_affine.h> -#include <unicode.h> -#include <gtk/gtkinvisible.h> -#include "e-util/e-canvas.h" -#include "e-util/e-canvas-utils.h" - -#include "e-text-event-processor-emacs-like.h" - -#define BORDER_INDENT 4 - -enum { - E_TEXT_CHANGED, - E_TEXT_ACTIVATE, - E_TEXT_LAST_SIGNAL -}; - -static guint e_text_signals[E_TEXT_LAST_SIGNAL] = { 0 }; - - - -/* This defines a line of text */ -struct line { - char *text; /* Line's text, it is a pointer into the text->text string */ - int length; /* Line's length in characters */ - int width; /* Line's width in pixels */ - int ellipsis_length; /* Length before adding ellipsis */ -}; - - - -/* Object argument IDs */ -enum { - ARG_0, - ARG_MODEL, - ARG_EVENT_PROCESSOR, - ARG_TEXT, - ARG_FONT, - ARG_FONTSET, - ARG_FONT_GDK, - ARG_ANCHOR, - ARG_JUSTIFICATION, - ARG_CLIP_WIDTH, - ARG_CLIP_HEIGHT, - ARG_CLIP, - ARG_FILL_CLIP_RECTANGLE, - ARG_X_OFFSET, - ARG_Y_OFFSET, - ARG_FILL_COLOR, - ARG_FILL_COLOR_GDK, - ARG_FILL_COLOR_RGBA, - ARG_FILL_STIPPLE, - ARG_TEXT_WIDTH, - ARG_TEXT_HEIGHT, - ARG_EDITABLE, - ARG_USE_ELLIPSIS, - ARG_ELLIPSIS, - ARG_LINE_WRAP, - ARG_BREAK_CHARACTERS, - ARG_MAX_LINES, - ARG_WIDTH, - ARG_HEIGHT, - ARG_DRAW_BORDERS, -}; - - -enum { - E_SELECTION_PRIMARY, - E_SELECTION_CLIPBOARD -}; -enum { - TARGET_STRING, - TARGET_TEXT, - TARGET_COMPOUND_TEXT -}; - -static void e_text_class_init (ETextClass *class); -static void e_text_init (EText *text); -static void e_text_destroy (GtkObject *object); -static void e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_text_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); - -static void e_text_reflow (GnomeCanvasItem *item, int flags); -static void e_text_update (GnomeCanvasItem *item, double *affine, - ArtSVP *clip_path, int flags); -static void e_text_realize (GnomeCanvasItem *item); -static void e_text_unrealize (GnomeCanvasItem *item); -static void e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, - int x, int y, int width, int height); -static double e_text_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item); -static void e_text_bounds (GnomeCanvasItem *item, - double *x1, double *y1, double *x2, double *y2); -static void e_text_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf); -static gint e_text_event (GnomeCanvasItem *item, GdkEvent *event); - -static void e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data); - -static void e_text_get_selection(EText *text, GdkAtom selection, guint32 time); -static void e_text_supply_selection (EText *text, guint time, GdkAtom selection, guchar *data, gint length); - -static void e_text_text_model_changed(ETextModel *model, EText *text); - -static void _get_tep(EText *text); - -static GtkWidget *e_text_get_invisible(EText *text); -static void _selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - EText *text); -static void _selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EText *text); -static void _selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - EText *text); - -#if 0 -static ETextSuckFont *e_suck_font (GdkFont *font); -static void e_suck_font_free (ETextSuckFont *suckfont); -#endif - -static void e_text_free_lines(EText *text); - -static void calc_height (EText *text); -static void calc_line_widths (EText *text); -static void split_into_lines (EText *text); - -static GnomeCanvasItemClass *parent_class; -static GdkAtom clipboard_atom = GDK_NONE; - - - -/** - * e_text_get_type: - * @void: - * - * Registers the &EText class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &EText class. - **/ -GtkType -e_text_get_type (void) -{ - static GtkType text_type = 0; - - if (!text_type) { - GtkTypeInfo text_info = { - "EText", - sizeof (EText), - sizeof (ETextClass), - (GtkClassInitFunc) e_text_class_init, - (GtkObjectInitFunc) e_text_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - text_type = gtk_type_unique (gnome_canvas_item_get_type (), &text_info); - } - - return text_type; -} - -/* Class initialization function for the text item */ -static void -e_text_class_init (ETextClass *klass) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - object_class = (GtkObjectClass *) klass; - item_class = (GnomeCanvasItemClass *) klass; - - parent_class = gtk_type_class (gnome_canvas_item_get_type ()); - - e_text_signals[E_TEXT_CHANGED] = - gtk_signal_new ("changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETextClass, changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_text_signals[E_TEXT_ACTIVATE] = - gtk_signal_new ("activate", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETextClass, activate), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, e_text_signals, E_TEXT_LAST_SIGNAL); - - - gtk_object_add_arg_type ("EText::model", - GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_MODEL); - gtk_object_add_arg_type ("EText::event_processor", - GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_EVENT_PROCESSOR); - gtk_object_add_arg_type ("EText::text", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TEXT); - gtk_object_add_arg_type ("EText::font", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONT); - gtk_object_add_arg_type ("EText::fontset", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONTSET); - gtk_object_add_arg_type ("EText::font_gdk", - GTK_TYPE_GDK_FONT, GTK_ARG_READWRITE, ARG_FONT_GDK); - gtk_object_add_arg_type ("EText::anchor", - GTK_TYPE_ANCHOR_TYPE, GTK_ARG_READWRITE, ARG_ANCHOR); - gtk_object_add_arg_type ("EText::justification", - GTK_TYPE_JUSTIFICATION, GTK_ARG_READWRITE, ARG_JUSTIFICATION); - gtk_object_add_arg_type ("EText::clip_width", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_CLIP_WIDTH); - gtk_object_add_arg_type ("EText::clip_height", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_CLIP_HEIGHT); - gtk_object_add_arg_type ("EText::clip", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_CLIP); - gtk_object_add_arg_type ("EText::fill_clip_rectangle", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_FILL_CLIP_RECTANGLE); - gtk_object_add_arg_type ("EText::x_offset", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_X_OFFSET); - gtk_object_add_arg_type ("EText::y_offset", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_Y_OFFSET); - gtk_object_add_arg_type ("EText::fill_color", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FILL_COLOR); - gtk_object_add_arg_type ("EText::fill_color_gdk", - GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_FILL_COLOR_GDK); - gtk_object_add_arg_type ("EText::fill_color_rgba", - GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_FILL_COLOR_RGBA); - gtk_object_add_arg_type ("EText::fill_stipple", - GTK_TYPE_GDK_WINDOW, GTK_ARG_READWRITE, ARG_FILL_STIPPLE); - gtk_object_add_arg_type ("EText::text_width", - GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_TEXT_WIDTH); - gtk_object_add_arg_type ("EText::text_height", - GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_TEXT_HEIGHT); - gtk_object_add_arg_type ("EText::editable", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_EDITABLE); - gtk_object_add_arg_type ("EText::use_ellipsis", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_USE_ELLIPSIS); - gtk_object_add_arg_type ("EText::ellipsis", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ELLIPSIS); - gtk_object_add_arg_type ("EText::line_wrap", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_LINE_WRAP); - gtk_object_add_arg_type ("EText::break_characters", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_BREAK_CHARACTERS); - gtk_object_add_arg_type ("EText::max_lines", - GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_MAX_LINES); - gtk_object_add_arg_type ("EText::width", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("EText::height", - GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_HEIGHT); - gtk_object_add_arg_type ("EText::draw_borders", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_DRAW_BORDERS); - - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); - - - - klass->changed = NULL; - klass->activate = NULL; - - object_class->destroy = e_text_destroy; - object_class->set_arg = e_text_set_arg; - object_class->get_arg = e_text_get_arg; - - item_class->update = e_text_update; - item_class->realize = e_text_realize; - item_class->unrealize = e_text_unrealize; - item_class->draw = e_text_draw; - item_class->point = e_text_point; - item_class->bounds = e_text_bounds; - item_class->render = e_text_render; - item_class->event = e_text_event; -} - -/* Object initialization function for the text item */ -static void -e_text_init (EText *text) -{ - text->text = NULL; - text->model = e_text_model_new(); - gtk_object_ref(GTK_OBJECT(text->model)); - gtk_object_sink(GTK_OBJECT(text->model)); - text->model_changed_signal_id = - gtk_signal_connect(GTK_OBJECT(text->model), - "changed", - GTK_SIGNAL_FUNC(e_text_text_model_changed), - text); - - text->anchor = GTK_ANCHOR_CENTER; - text->justification = GTK_JUSTIFY_LEFT; - text->clip_width = -1.0; - text->clip_height = -1.0; - text->xofs = 0.0; - text->yofs = 0.0; - - text->ellipsis = NULL; - text->use_ellipsis = FALSE; - text->ellipsis_width = 0; - - text->editable = FALSE; - text->editing = FALSE; - text->xofs_edit = 0; - text->yofs_edit = 0; - - text->selection_start = 0; - text->selection_end = 0; - text->select_by_word = FALSE; - - text->timeout_id = 0; - text->timer = NULL; - - text->lastx = 0; - text->lasty = 0; - text->last_state = 0; - - text->scroll_start = 0; - text->show_cursor = TRUE; - text->button_down = FALSE; - - text->tep = NULL; - text->tep_command_id = 0; - - text->has_selection = FALSE; - - text->invisible = NULL; - text->primary_selection = NULL; - text->primary_length = 0; - text->clipboard_selection = NULL; - text->clipboard_length = 0; - - text->pointer_in = FALSE; - text->default_cursor_shown = TRUE; - - text->line_wrap = FALSE; - text->break_characters = NULL; - text->max_lines = -1; - - text->tooltip_timeout = 0; - text->tooltip_count = 0; - - text->dbl_timeout = 0; - text->tpl_timeout = 0; - - e_canvas_item_set_reflow_callback(GNOME_CANVAS_ITEM(text), e_text_reflow); -} - -/* Destroy handler for the text item */ -static void -e_text_destroy (GtkObject *object) -{ - EText *text; - - g_return_if_fail (object != NULL); - g_return_if_fail (E_IS_TEXT (object)); - - text = E_TEXT (object); - - if (text->model_changed_signal_id) - gtk_signal_disconnect(GTK_OBJECT(text->model), - text->model_changed_signal_id); - - if (text->model) - gtk_object_unref(GTK_OBJECT(text->model)); - - if (text->tep_command_id) - gtk_signal_disconnect(GTK_OBJECT(text->tep), - text->tep_command_id); - - if (text->tep) - gtk_object_unref (GTK_OBJECT(text->tep)); - - if (text->invisible) - gtk_object_unref (GTK_OBJECT(text->invisible)); - - if (text->lines) - g_free (text->lines); - - if (text->font) - e_font_unref (text->font); - -#if 0 - if (text->suckfont) - e_suck_font_free (text->suckfont); -#endif - - if (text->stipple) - gdk_bitmap_unref (text->stipple); - - if (text->timeout_id) { - g_source_remove(text->timeout_id); - text->timeout_id = 0; - } - - if (text->timer) { - g_timer_stop(text->timer); - g_timer_destroy(text->timer); - text->timer = NULL; - } - - if ( text->tooltip_timeout ) { - gtk_timeout_remove (text->tooltip_timeout); - text->tooltip_timeout = 0; - } - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -static void -e_text_text_model_changed (ETextModel *model, EText *text) -{ - text->text = e_text_model_get_text(model); - e_text_free_lines(text); - gtk_signal_emit (GTK_OBJECT (text), e_text_signals[E_TEXT_CHANGED]); - text->needs_split_into_lines = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(text)); -} - -static void -get_bounds_item_relative (EText *text, double *px1, double *py1, double *px2, double *py2) -{ - GnomeCanvasItem *item; - double x, y; - double clip_x, clip_y; - int old_height; - - item = GNOME_CANVAS_ITEM (text); - - x = 0; - y = 0; - - clip_x = x; - clip_y = y; - - /* Calculate text dimensions */ - - old_height = text->height; - - if (text->text && text->font) - text->height = (e_font_ascent (text->font) + e_font_descent (text->font)) * text->num_lines; - else - text->height = 0; - - if (old_height != text->height) - e_canvas_item_request_parent_reflow(item); - - /* Anchor text */ - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - x -= text->max_width / 2; - if ( text->clip_width >= 0) - clip_x -= text->clip_width / 2; - else - clip_x -= text->width / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - x -= text->max_width; - if (text->clip_width >= 0) - clip_x -= text->clip_width; - else - clip_x -= text->width; - break; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - y -= text->height / 2; - if ( text->clip_height >= 0 ) - clip_y -= text->clip_height / 2; - else - clip_y -= text->height / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - y -= text->height; - if ( text->clip_height >= 0 ) - clip_y -= text->clip_height; - else - clip_y -= text->height; - break; - } - - /* Bounds */ - - if (text->clip) { - /* maybe do bbox intersection here? */ - *px1 = clip_x; - *py1 = clip_y; - if (text->clip_width >= 0) - *px2 = clip_x + text->clip_width; - else - *px2 = clip_x + text->width; - - if ( text->clip_height >= 0 ) - *py2 = clip_y + text->clip_height; - else - *py2 = clip_y + text->height; - } else { - *px1 = x; - *py1 = y; - *px2 = x + text->max_width; - *py2 = y + text->height; - } -} - -static void -get_bounds (EText *text, double *px1, double *py1, double *px2, double *py2) -{ - GnomeCanvasItem *item; - double wx, wy, clip_width; - - item = GNOME_CANVAS_ITEM (text); - - /* Get canvas pixel coordinates for text position */ - - wx = 0; - wy = 0; - gnome_canvas_item_i2w (item, &wx, &wy); - gnome_canvas_w2c (item->canvas, wx + text->xofs, wy + text->yofs, &text->cx, &text->cy); - - /* Calculate the width and heights */ - calc_height (text); - calc_line_widths (text); - - if (text->clip_width < 0) - clip_width = text->max_width; - else - clip_width = text->clip_width; - - /* Get canvas pixel coordinates for clip rectangle position */ - gnome_canvas_w2c (item->canvas, wx, wy, &text->clip_cx, &text->clip_cy); - text->clip_cwidth = clip_width * item->canvas->pixels_per_unit; - if ( text->clip_height >= 0 ) - text->clip_cheight = text->clip_height * item->canvas->pixels_per_unit; - else - text->clip_cheight = text->height * item->canvas->pixels_per_unit; - - /* Anchor text */ - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - text->cx -= text->max_width / 2; - text->clip_cx -= text->clip_cwidth / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - text->cx -= text->max_width; - text->clip_cx -= text->clip_cwidth; - break; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - text->cy -= text->height / 2; - text->clip_cy -= text->clip_cheight / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - text->cy -= text->height; - text->clip_cy -= text->clip_cheight; - break; - } - - /* Bounds */ - - if (text->clip) { - *px1 = text->clip_cx; - *py1 = text->clip_cy; - *px2 = text->clip_cx + text->clip_cwidth; - *py2 = text->clip_cy + text->clip_cheight; - } else { - *px1 = text->cx; - *py1 = text->cy; - *px2 = text->cx + text->max_width; - *py2 = text->cy + text->height; - } -} - -static void -calc_height (EText *text) -{ - GnomeCanvasItem *item; - int old_height; - - item = GNOME_CANVAS_ITEM (text); - - /* Calculate text dimensions */ - - old_height = text->height; - - /* Make sure the text is split into lines first */ - if (text->text && text->num_lines == 0) - split_into_lines (text); - - if (text->text && text->font) - text->height = (e_font_ascent (text->font) + e_font_descent (text->font)) * text->num_lines; - else - text->height = 0; - - if (old_height != text->height) - e_canvas_item_request_parent_reflow(item); -} - -static void -calc_ellipsis (EText *text) -{ - if (text->font) - text->ellipsis_width = - e_font_utf8_text_width (text->font, E_FONT_PLAIN, - text->ellipsis ? text->ellipsis : "...", - text->ellipsis ? unicode_strlen (text->ellipsis, -1) : 3); -} - -/* Calculates the line widths (in pixels) of the text's splitted lines */ -static void -calc_line_widths (EText *text) -{ - struct line *lines; - int i; - int j; - gdouble clip_width; - - /* Make sure line has been split */ - if (text->text && text->num_lines == 0) - split_into_lines (text); - - lines = text->lines; - text->max_width = 0; - - clip_width = text->clip_width; - if (clip_width >= 0 && text->draw_borders) { - clip_width -= 6; - if (clip_width < 0) - clip_width = 0; - } - - - if (!lines) - return; - - for (i = 0; i < text->num_lines; i++) { - if (lines->length != 0) { - if (text->font) { - lines->width = e_font_utf8_text_width (text->font, E_FONT_PLAIN, - lines->text, lines->length); - lines->ellipsis_length = 0; - } else { - lines->width = 0; - } - - if (text->clip && - text->use_ellipsis && - ! text->editing && - lines->width > clip_width && - clip_width >= 0) { - if (text->font) { - lines->ellipsis_length = 0; - for (j = 0; j < lines->length; j++ ) { - if (e_font_utf8_text_width (text->font, E_FONT_PLAIN, lines->text, j) + text->ellipsis_width - <= clip_width) - lines->ellipsis_length = j; - else - break; - } - } - else - lines->ellipsis_length = 0; - lines->width = e_font_utf8_text_width (text->font, E_FONT_PLAIN, lines->text, lines->ellipsis_length) + - text->ellipsis_width; - } - else - lines->ellipsis_length = lines->length; - - if (lines->width > text->max_width) - text->max_width = lines->width; - } - - lines++; - } -} - -static void -e_text_free_lines(EText *text) -{ - if (text->lines) - g_free (text->lines); - - text->lines = NULL; - text->num_lines = 0; -} - -#define IS_BREAKCHAR(text,c) ((text)->break_characters && unicode_strchr ((text)->break_characters, (c))) -/* Splits the text of the text item into lines */ -static void -split_into_lines (EText *text) -{ - char *p, *cp; - struct line *lines; - int len; - int line_num; - char *laststart; - char *lastend; - char *linestart; - double clip_width; - unicode_char_t unival; - gint charpos; - - /* Free old array of lines */ - e_text_free_lines(text); - - if (!text->text) - return; - - /* First, count the number of lines */ - - lastend = text->text; - laststart = text->text; - linestart = text->text; - - clip_width = text->clip_width; - if (clip_width >= 0 && text->draw_borders) { - clip_width -= 6; - if (clip_width < 0) - clip_width = 0; - } - - cp = text->text; - charpos = 0; - - for (p = unicode_get_utf8 (cp, &unival); (unival && p); charpos++, cp = p, p = unicode_get_utf8 (p, &unival)) { - if (text->line_wrap && (unicode_isspace (unival) || unival == '\n')) { - if (laststart != lastend - && e_font_utf8_text_width(text->font, E_FONT_PLAIN, - linestart, - unicode_index_to_offset (linestart, cp - linestart)) - > clip_width ) { - text->num_lines ++; - linestart = laststart; - laststart = p; - lastend = cp; - } else if (unicode_isspace (unival)) { - laststart = p; - lastend = cp; - } - } else if (text->line_wrap && (IS_BREAKCHAR(text, unival))) { - if ( laststart != lastend - && unicode_index_to_offset (linestart, cp - linestart) != 1 - && e_font_utf8_text_width(text->font, E_FONT_PLAIN, - linestart, - unicode_index_to_offset (linestart, p - linestart)) - > clip_width ) { - text->num_lines ++; - linestart = laststart; - laststart = p; - lastend = p; - } else { - laststart = p; - lastend = p; - } - } - if (unival == '\n') { - text->num_lines ++; - lastend = p; - laststart = p; - linestart = p; - } - } - - /* fixme: */ - if (text->line_wrap) { - if ( p - && laststart != lastend - && e_font_utf8_text_width(text->font, E_FONT_PLAIN, - linestart, - unicode_index_to_offset (linestart, cp - linestart)) - > clip_width ) { - text->num_lines ++; - } - } - - text->num_lines++; - - if ( (!text->editing) && text->max_lines != -1 && text->num_lines > text->max_lines ) { - text->num_lines = text->max_lines; - } - - /* Allocate array of lines and calculate split positions */ - - text->lines = lines = g_new0 (struct line, text->num_lines); - len = 0; - line_num = 1; - lastend = text->text; - laststart = text->text; - - cp = text->text; - for (p = unicode_get_utf8 (cp, &unival); line_num < text->num_lines && unival; cp = p, p = unicode_get_utf8 (p, &unival)) { - gboolean handled = FALSE; - if (len == 0) - lines->text = cp; - if (text->line_wrap && (unicode_isspace (unival) || unival == '\n')) { - if (e_font_utf8_text_width(text->font, E_FONT_PLAIN, - lines->text, - unicode_index_to_offset (lines->text, cp - lines->text)) - > clip_width - && laststart != lastend) { - lines->length = unicode_index_to_offset (lines->text, lastend - lines->text); - lines++; - line_num++; - len = unicode_index_to_offset (laststart, cp - laststart); - lines->text = laststart; - laststart = p; - lastend = cp; - } else if (unicode_isspace (unival)) { - laststart = p; - lastend = cp; - len ++; - } - handled = TRUE; - } else if (text->line_wrap && (IS_BREAKCHAR(text, unival))) { - if (laststart != lastend - && unicode_index_to_offset (lines->text, cp - lines->text) != 1 - && e_font_utf8_text_width(text->font, E_FONT_PLAIN, - lines->text, - unicode_index_to_offset (lines->text, p - lines->text)) - > clip_width ) { - lines->length = unicode_index_to_offset (lines->text, lastend - lines->text); - lines++; - line_num++; - len = unicode_index_to_offset (laststart, p - laststart); - lines->text = laststart; - laststart = p; - lastend = p; - } else { - laststart = p; - lastend = p; - len ++; - } - } - if (line_num >= text->num_lines) - break; - if (unival == '\n') { - lines->length = unicode_index_to_offset (lines->text, cp - lines->text); - lines++; - line_num++; - len = 0; - lastend = p; - laststart = p; - handled = TRUE; - } - if (!handled) - len++; - } - - if ( line_num < text->num_lines && text->line_wrap ) { - if (e_font_utf8_text_width(text->font, E_FONT_PLAIN, - lines->text, - unicode_index_to_offset (lines->text, cp - lines->text)) - > clip_width - && laststart != lastend ) { - lines->length = unicode_index_to_offset (lines->text, lastend - lines->text); - lines++; - line_num++; - len = unicode_index_to_offset (laststart, cp - laststart); - lines->text = laststart; - laststart = p; - lastend = cp; - } - } - - if (len == 0) - lines->text = cp; - lines->length = unicode_strlen (lines->text, -1); -} - -/* Convenience function to set the text's GC's foreground color */ -static void -set_text_gc_foreground (EText *text) -{ - GdkColor c; - - if (!text->gc) - return; - - c.pixel = text->pixel; - gdk_gc_set_foreground (text->gc, &c); -} - -/* Sets the stipple pattern for the text */ -static void -set_stipple (EText *text, GdkBitmap *stipple, int reconfigure) -{ - if (text->stipple && !reconfigure) - gdk_bitmap_unref (text->stipple); - - text->stipple = stipple; - if (stipple && !reconfigure) - gdk_bitmap_ref (stipple); - - if (text->gc) { - if (stipple) { - gdk_gc_set_stipple (text->gc, stipple); - gdk_gc_set_fill (text->gc, GDK_STIPPLED); - } else - gdk_gc_set_fill (text->gc, GDK_SOLID); - } -} - -/* Set_arg handler for the text item */ -static void -e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EText *text; - GdkColor color = { 0, 0, 0, 0, }; - GdkColor *pcolor; - gboolean color_changed; - int have_pixel; - - gboolean needs_update = 0; - gboolean needs_reflow = 0; - - item = GNOME_CANVAS_ITEM (object); - text = E_TEXT (object); - - color_changed = FALSE; - have_pixel = FALSE; - - switch (arg_id) { - case ARG_MODEL: - if ( text->model_changed_signal_id ) - gtk_signal_disconnect(GTK_OBJECT(text->model), - text->model_changed_signal_id); - gtk_object_unref(GTK_OBJECT(text->model)); - text->model = E_TEXT_MODEL(GTK_VALUE_OBJECT (*arg)); - gtk_object_ref(GTK_OBJECT(text->model)); - - text->model_changed_signal_id = - gtk_signal_connect(GTK_OBJECT(text->model), - "changed", - GTK_SIGNAL_FUNC(e_text_text_model_changed), - text); - - e_text_free_lines(text); - text->text = e_text_model_get_text(text->model); - - text->needs_split_into_lines = 1; - needs_reflow = 1; - break; - - case ARG_EVENT_PROCESSOR: - if ( text->tep && text->tep_command_id ) - gtk_signal_disconnect(GTK_OBJECT(text->tep), - text->tep_command_id); - if ( text->tep ) - gtk_object_unref(GTK_OBJECT(text->tep)); - text->tep = E_TEXT_EVENT_PROCESSOR(GTK_VALUE_OBJECT (*arg)); - gtk_object_ref(GTK_OBJECT(text->tep)); - text->tep_command_id = - gtk_signal_connect(GTK_OBJECT(text->tep), - "command", - GTK_SIGNAL_FUNC(e_text_command), - text); - break; - - case ARG_TEXT: - text->num_lines = 1; - e_text_model_set_text(text->model, GTK_VALUE_STRING (*arg)); - break; - - case ARG_FONT: - if (text->font) - e_font_unref (text->font); - - text->font = e_font_from_gdk_name (GTK_VALUE_STRING (*arg)); - -#if 0 - if (item->canvas->aa) { - if (text->suckfont) - e_suck_font_free (text->suckfont); - - text->suckfont = e_suck_font (text->font); - } -#endif - - calc_ellipsis (text); - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else - text->needs_calc_line_widths = 1; - needs_reflow = 1; - break; - - case ARG_FONTSET: - if (text->font) - e_font_unref (text->font); - - text->font = e_font_from_gdk_name (GTK_VALUE_STRING (*arg)); - -#if 0 - if (item->canvas->aa) { - if (text->suckfont) - e_suck_font_free (text->suckfont); - - text->suckfont = e_suck_font (text->font); - } -#endif - - calc_ellipsis (text); - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else - text->needs_calc_line_widths = 1; - needs_reflow = 1; - break; - - case ARG_FONT_GDK: - if (text->font) - e_font_unref (text->font); - - text->font = e_font_from_gdk_font (GTK_VALUE_BOXED (*arg)); - -#if 0 - if (item->canvas->aa) { - if (text->suckfont) - e_suck_font_free (text->suckfont); - - text->suckfont = e_suck_font (text->font); - } -#endif - - calc_ellipsis (text); - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else - text->needs_calc_line_widths = 1; - needs_reflow = 1; - break; - - case ARG_ANCHOR: - text->anchor = GTK_VALUE_ENUM (*arg); - text->needs_recalc_bounds = 1; - needs_update = 1; - break; - - case ARG_JUSTIFICATION: - text->justification = GTK_VALUE_ENUM (*arg); - text->needs_redraw = 1; - needs_update = 1; - break; - - case ARG_CLIP_WIDTH: - text->clip_width = fabs (GTK_VALUE_DOUBLE (*arg)); - calc_ellipsis (text); - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else - text->needs_calc_line_widths = 1; - needs_reflow = 1; - break; - - case ARG_CLIP_HEIGHT: - text->clip_height = fabs (GTK_VALUE_DOUBLE (*arg)); - text->needs_recalc_bounds = 1; - needs_reflow = 1; - break; - - case ARG_CLIP: - text->clip = GTK_VALUE_BOOL (*arg); - calc_ellipsis (text); - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else - text->needs_calc_line_widths = 1; - needs_reflow = 1; - break; - - case ARG_FILL_CLIP_RECTANGLE: - text->fill_clip_rectangle = GTK_VALUE_BOOL (*arg); - needs_update = 1; - break; - - case ARG_X_OFFSET: - text->xofs = GTK_VALUE_DOUBLE (*arg); - text->needs_recalc_bounds = 1; - needs_update = 1; - break; - - case ARG_Y_OFFSET: - text->yofs = GTK_VALUE_DOUBLE (*arg); - text->needs_recalc_bounds = 1; - needs_update = 1; - break; - - case ARG_FILL_COLOR: - if (GTK_VALUE_STRING (*arg)) - gdk_color_parse (GTK_VALUE_STRING (*arg), &color); - - text->rgba = ((color.red & 0xff00) << 16 | - (color.green & 0xff00) << 8 | - (color.blue & 0xff00) | - 0xff); - color_changed = TRUE; - text->needs_redraw = 1; - needs_update = 1; - break; - - case ARG_FILL_COLOR_GDK: - pcolor = GTK_VALUE_BOXED (*arg); - if (pcolor) { - color = *pcolor; - gdk_color_context_query_color (item->canvas->cc, &color); - have_pixel = TRUE; - } - - text->rgba = ((color.red & 0xff00) << 16 | - (color.green & 0xff00) << 8 | - (color.blue & 0xff00) | - 0xff); - color_changed = TRUE; - text->needs_redraw = 1; - needs_update = 1; - break; - - case ARG_FILL_COLOR_RGBA: - text->rgba = GTK_VALUE_UINT (*arg); - color_changed = TRUE; - text->needs_redraw = 1; - needs_update = 1; - break; - - case ARG_FILL_STIPPLE: - set_stipple (text, GTK_VALUE_BOXED (*arg), FALSE); - text->needs_redraw = 1; - needs_update = 1; - break; - - case ARG_EDITABLE: - text->editable = GTK_VALUE_BOOL (*arg); - text->needs_redraw = 1; - needs_update = 1; - break; - - case ARG_USE_ELLIPSIS: - text->use_ellipsis = GTK_VALUE_BOOL (*arg); - text->needs_calc_line_widths = 1; - needs_reflow = 1; - break; - - case ARG_ELLIPSIS: - if (text->ellipsis) - g_free (text->ellipsis); - - text->ellipsis = g_strdup (GTK_VALUE_STRING (*arg)); - calc_ellipsis (text); - text->needs_calc_line_widths = 1; - needs_reflow = 1; - break; - - case ARG_LINE_WRAP: - text->line_wrap = GTK_VALUE_BOOL (*arg); - text->needs_split_into_lines = 1; - needs_reflow = 1; - break; - - case ARG_BREAK_CHARACTERS: - if ( text->break_characters ) { - g_free(text->break_characters); - text->break_characters = NULL; - } - if ( GTK_VALUE_STRING (*arg) ) - text->break_characters = g_strdup( GTK_VALUE_STRING (*arg) ); - text->needs_split_into_lines = 1; - needs_reflow = 1; - break; - - case ARG_MAX_LINES: - text->max_lines = GTK_VALUE_INT (*arg); - text->needs_split_into_lines = 1; - needs_reflow = 1; - break; - - case ARG_WIDTH: - text->clip_width = fabs (GTK_VALUE_DOUBLE (*arg)); - calc_ellipsis (text); - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else - text->needs_calc_line_widths = 1; - needs_reflow = 1; - break; - - case ARG_DRAW_BORDERS: - if (text->draw_borders != GTK_VALUE_BOOL (*arg)) { - text->draw_borders = GTK_VALUE_BOOL (*arg); - text->needs_calc_height = 1; - text->needs_redraw = 1; - needs_reflow = 1; - needs_update = 1; - } - break; - - default: - return; - } - - if (color_changed) { - if (have_pixel) - text->pixel = color.pixel; - else - text->pixel = gnome_canvas_get_color_pixel (item->canvas, text->rgba); - - if (!item->canvas->aa) - set_text_gc_foreground (text); - - } - - if ( needs_reflow ) - e_canvas_item_request_reflow (item); - if ( needs_update ) - gnome_canvas_item_request_update (item); -} - -/* Get_arg handler for the text item */ -static void -e_text_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - EText *text; - GdkColor *color; - - text = E_TEXT (object); - - switch (arg_id) { - case ARG_MODEL: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(text->model); - break; - - case ARG_EVENT_PROCESSOR: - _get_tep(text); - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(text->tep); - break; - - case ARG_TEXT: - GTK_VALUE_STRING (*arg) = g_strdup (text->text); - break; - - /* fixme: */ - case ARG_FONT_GDK: - GTK_VALUE_BOXED (*arg) = text->font; - break; - - case ARG_ANCHOR: - GTK_VALUE_ENUM (*arg) = text->anchor; - break; - - case ARG_JUSTIFICATION: - GTK_VALUE_ENUM (*arg) = text->justification; - break; - - case ARG_CLIP_WIDTH: - GTK_VALUE_DOUBLE (*arg) = text->clip_width; - break; - - case ARG_CLIP_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = text->clip_height; - break; - - case ARG_CLIP: - GTK_VALUE_BOOL (*arg) = text->clip; - break; - - case ARG_FILL_CLIP_RECTANGLE: - GTK_VALUE_BOOL (*arg) = text->fill_clip_rectangle; - break; - - case ARG_X_OFFSET: - GTK_VALUE_DOUBLE (*arg) = text->xofs; - break; - - case ARG_Y_OFFSET: - GTK_VALUE_DOUBLE (*arg) = text->yofs; - break; - - case ARG_FILL_COLOR_GDK: - color = g_new (GdkColor, 1); - color->pixel = text->pixel; - gdk_color_context_query_color (text->item.canvas->cc, color); - GTK_VALUE_BOXED (*arg) = color; - break; - - case ARG_FILL_COLOR_RGBA: - GTK_VALUE_UINT (*arg) = text->rgba; - break; - - case ARG_FILL_STIPPLE: - GTK_VALUE_BOXED (*arg) = text->stipple; - break; - - case ARG_TEXT_WIDTH: - GTK_VALUE_DOUBLE (*arg) = text->max_width / text->item.canvas->pixels_per_unit; - break; - - case ARG_TEXT_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = text->height / text->item.canvas->pixels_per_unit; - break; - - case ARG_EDITABLE: - GTK_VALUE_BOOL (*arg) = text->editable; - break; - - case ARG_USE_ELLIPSIS: - GTK_VALUE_BOOL (*arg) = text->use_ellipsis; - break; - - case ARG_ELLIPSIS: - GTK_VALUE_STRING (*arg) = g_strdup (text->ellipsis); - break; - - case ARG_LINE_WRAP: - GTK_VALUE_BOOL (*arg) = text->line_wrap; - break; - - case ARG_BREAK_CHARACTERS: - GTK_VALUE_STRING (*arg) = g_strdup (text->break_characters); - break; - - case ARG_MAX_LINES: - GTK_VALUE_INT (*arg) = text->max_lines; - break; - - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = text->clip_width; - break; - - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = text->clip && text->clip_height != -1 ? text->clip_height : text->height / text->item.canvas->pixels_per_unit; - break; - - case ARG_DRAW_BORDERS: - GTK_VALUE_BOOL (*arg) = text->draw_borders; - break; - - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -/* Update handler for the text item */ -static void -e_text_reflow (GnomeCanvasItem *item, int flags) -{ - EText *text; - - text = E_TEXT (item); - - if ( text->needs_split_into_lines ) { - split_into_lines(text); - text->needs_split_into_lines = 0; - text->needs_calc_line_widths = 1; - } - if ( text->needs_calc_line_widths ) { - int x; - int i; - struct line *lines; - gdouble clip_width; - calc_line_widths(text); - text->needs_calc_line_widths = 0; - text->needs_calc_height = 1; - text->needs_redraw = 1; - - lines = text->lines; - if ( !lines ) - return; - - for (lines = text->lines, i = 0; i < text->num_lines ; i++, lines ++) { - if (unicode_index_to_offset (text->text, lines->text - text->text) > text->selection_end) { - break; - } - } - lines --; - i--; - x = e_font_utf8_text_width(text->font, E_FONT_PLAIN, - lines->text, - text->selection_end - unicode_index_to_offset (text->text, lines->text - text->text)); - - - if (x < text->xofs_edit) { - text->xofs_edit = x; - } - - clip_width = text->clip_width; - if (clip_width >= 0 && text->draw_borders) { - clip_width -= 6; - if (clip_width < 0) - clip_width = 0; - } - - if (2 + x - clip_width > text->xofs_edit) { - text->xofs_edit = 2 + x - clip_width; - } - - if ((e_font_ascent (text->font) + e_font_descent (text->font)) * i < text->yofs_edit) - text->yofs_edit = (e_font_ascent (text->font) + e_font_descent (text->font)) * i; - - if ((e_font_ascent (text->font) + e_font_descent (text->font)) * (i + 1) - - (text->clip_height != -1 ? text->clip_height : text->height) > text->yofs_edit) - text->yofs_edit = (e_font_ascent (text->font) + e_font_descent (text->font)) * (i + 1) - - (text->clip_height != -1 ? text->clip_height : text->height); - } - if ( text->needs_calc_height ) { - calc_height (text); - gnome_canvas_item_request_update(item); - text->needs_calc_height = 0; - text->needs_recalc_bounds = 1; - } -} - -/* Update handler for the text item */ -static void -e_text_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - EText *text; - double x1, y1, x2, y2; - ArtDRect i_bbox, c_bbox; - int i; - - text = E_TEXT (item); - - if (parent_class->update) - (* parent_class->update) (item, affine, clip_path, flags); - - if ( text->needs_recalc_bounds - || (flags & GNOME_CANVAS_UPDATE_AFFINE)) { - if (!item->canvas->aa) { - set_text_gc_foreground (text); - set_stipple (text, text->stipple, TRUE); - get_bounds (text, &x1, &y1, &x2, &y2); - if ( item->x1 != x1 || - item->x2 != x2 || - item->y1 != y1 || - 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; - text->needs_redraw = 1; - } - } else { - /* aa rendering */ - for (i = 0; i < 6; i++) - text->affine[i] = affine[i]; - get_bounds_item_relative (text, &i_bbox.x0, &i_bbox.y0, &i_bbox.x1, &i_bbox.y1); - art_drect_affine_transform (&c_bbox, &i_bbox, affine); - } - text->needs_recalc_bounds = 0; - } - if ( text->needs_redraw ) { - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); - text->needs_redraw = 0; - } -} - -/* Realize handler for the text item */ -static void -e_text_realize (GnomeCanvasItem *item) -{ - EText *text; - - text = E_TEXT (item); - - if (parent_class->realize) - (* parent_class->realize) (item); - - text->gc = gdk_gc_new (item->canvas->layout.bin_window); - - text->i_cursor = gdk_cursor_new (GDK_XTERM); - text->default_cursor = gdk_cursor_new (GDK_LEFT_PTR); - if (text->font == NULL) { - text->font = e_font_from_gdk_font (GTK_WIDGET(item->canvas)->style->font); - } -} - -/* Unrealize handler for the text item */ -static void -e_text_unrealize (GnomeCanvasItem *item) -{ - EText *text; - - text = E_TEXT (item); - - gdk_gc_unref (text->gc); - text->gc = NULL; - - gdk_cursor_destroy (text->i_cursor); - gdk_cursor_destroy (text->default_cursor); - - if (parent_class->unrealize) - (* parent_class->unrealize) (item); -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static double -get_line_xpos_item_relative (EText *text, struct line *line) -{ - double x; - - x = 0; - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - x -= text->max_width / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - x -= text->max_width; - break; - } - - switch (text->justification) { - case GTK_JUSTIFY_RIGHT: - x += text->max_width - line->width; - break; - - case GTK_JUSTIFY_CENTER: - x += (text->max_width - line->width) * 0.5; - break; - - default: - if (text->draw_borders) - x += BORDER_INDENT; - - /* For GTK_JUSTIFY_LEFT, we don't have to do anything. We do not support - * GTK_JUSTIFY_FILL, yet. - */ - break; - } - - return x; -} - -#if 0 -/* Calculates the y position of the first line of text. */ -static double -get_line_ypos_item_relative (EText *text) -{ - double y; - - y = 0; - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - y -= text->height / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - y -= text->height; - break; - } - - return y; -} -#endif - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static int -get_line_xpos (EText *text, struct line *line) -{ - int x; - - x = text->cx; - - switch (text->justification) { - case GTK_JUSTIFY_RIGHT: - x += text->max_width - line->width; - break; - - case GTK_JUSTIFY_CENTER: - x += (text->max_width - line->width) / 2; - break; - - default: - if (text->draw_borders) - x += BORDER_INDENT; - /* For GTK_JUSTIFY_LEFT, we don't have to do anything. We do not support - * GTK_JUSTIFY_FILL, yet. - */ - break; - } - - - return x; -} - -static void -_get_tep(EText *text) -{ - if (!text->tep) { - text->tep = e_text_event_processor_emacs_like_new(); - gtk_object_ref (GTK_OBJECT (text->tep)); - gtk_object_sink (GTK_OBJECT (text->tep)); - text->tep_command_id = - gtk_signal_connect(GTK_OBJECT(text->tep), - "command", - GTK_SIGNAL_FUNC(e_text_command), - (gpointer) text); - } -} - -/* Draw handler for the text item */ -static void -e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, - int x, int y, int width, int height) -{ - EText *text; - GdkRectangle rect, *clip_rect; - struct line *lines; - int i; - int xpos, ypos; - int start_char, end_char; - int sel_start, sel_end; - GdkRectangle sel_rect; - GdkGC *fg_gc; - GnomeCanvas *canvas; - - text = E_TEXT (item); - canvas = GNOME_CANVAS_ITEM(text)->canvas; - - fg_gc = GTK_WIDGET(canvas)->style->fg_gc[text->has_selection ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE]; - - if (text->draw_borders) { - gdouble thisx = 0, thisy = 0; - gdouble thiswidth, thisheight; - GtkWidget *widget = GTK_WIDGET(item->canvas); - - gtk_object_get(GTK_OBJECT(text), - "width", &thiswidth, - "height", &thisheight, - NULL); - gtk_paint_flat_box (widget->style, drawable, - GTK_WIDGET_STATE(widget), GTK_SHADOW_NONE, - NULL, widget, "entry_bg", - 0, 0, thiswidth, thisheight); - if (text->editing) { - thisx += 1; - thisy += 1; - thiswidth -= 2; - thisheight -= 2; - } - gtk_paint_shadow (widget->style, drawable, - GTK_STATE_NORMAL, GTK_SHADOW_IN, - NULL, widget, "entry", - thisx - x, thisy - y, thiswidth, thisheight); - - if (text->editing) { - gtk_paint_focus (widget->style, drawable, - NULL, widget, "entry", - - x, - y, thiswidth + 1, thisheight + 1); - } - } - - if (!text->text || !text->font) - return; - - lines = text->lines; - if ( !lines ) { - text->needs_split_into_lines = 1; - e_canvas_item_request_reflow (item); - } - - clip_rect = NULL; - if (text->clip) { - rect.x = text->clip_cx - x; - rect.y = text->clip_cy - y; - rect.width = text->clip_cwidth; - rect.height = text->clip_cheight; - - gdk_gc_set_clip_rectangle (text->gc, &rect); - gdk_gc_set_clip_rectangle (fg_gc, &rect); - clip_rect = ▭ - } - ypos = text->cy + e_font_ascent (text->font); - if (text->draw_borders) - ypos += BORDER_INDENT; - - if (text->editing) - ypos -= text->yofs_edit; - - if (text->stipple) - gnome_canvas_set_stipple_origin (item->canvas, text->gc); - - for (i = 0; i < text->num_lines; i++) { - xpos = get_line_xpos (text, lines); - if (text->editing) { - xpos -= text->xofs_edit; - start_char = unicode_index_to_offset (text->text, lines->text - text->text); - end_char = start_char + lines->length; - sel_start = text->selection_start; - sel_end = text->selection_end; - if (sel_start > sel_end ) { - sel_start ^= sel_end; - sel_end ^= sel_start; - sel_start ^= sel_end; - } - if ( sel_start < start_char ) - sel_start = start_char; - if ( sel_end > end_char ) - sel_end = end_char; - if ( sel_start < sel_end ) { - sel_rect.x = xpos - x + e_font_utf8_text_width (text->font, E_FONT_PLAIN, - lines->text, - sel_start - start_char); - sel_rect.y = ypos - y - e_font_ascent (text->font); - sel_rect.width = e_font_utf8_text_width (text->font, E_FONT_PLAIN, - lines->text + unicode_offset_to_index (lines->text, sel_start - start_char), - sel_end - sel_start); - sel_rect.height = e_font_ascent (text->font) + e_font_descent (text->font); - gtk_paint_flat_box(GTK_WIDGET(item->canvas)->style, - drawable, - text->has_selection ? - GTK_STATE_SELECTED : - GTK_STATE_ACTIVE, - GTK_SHADOW_NONE, - clip_rect, - GTK_WIDGET(item->canvas), - "text", - sel_rect.x, - sel_rect.y, - sel_rect.width, - sel_rect.height); - e_font_draw_utf8_text (drawable, - text->font, E_FONT_PLAIN, - text->gc, - xpos - x, - ypos - y, - lines->text, - sel_start - start_char); - e_font_draw_utf8_text (drawable, - text->font, E_FONT_PLAIN, - fg_gc, - xpos - x + e_font_utf8_text_width (text->font, E_FONT_PLAIN, - lines->text, - sel_start - start_char), - ypos - y, - lines->text + unicode_offset_to_index (lines->text, sel_start - start_char), - sel_end - sel_start); - e_font_draw_utf8_text (drawable, - text->font, E_FONT_PLAIN, - text->gc, - xpos - x + e_font_utf8_text_width (text->font, E_FONT_PLAIN, - lines->text, - sel_end - start_char), - ypos - y, - lines->text + unicode_offset_to_index (lines->text, sel_end - start_char), - end_char - sel_end); - } else { - e_font_draw_utf8_text (drawable, - text->font, E_FONT_PLAIN, - text->gc, - xpos - x, - ypos - y, - lines->text, - lines->length); - } - if (text->selection_start == text->selection_end && - text->selection_start >= start_char && - text->selection_start <= end_char && - text->show_cursor) { - gdk_draw_rectangle (drawable, - text->gc, - TRUE, - xpos - x + e_font_utf8_text_width (text->font, E_FONT_PLAIN, - lines->text, - sel_start - start_char), - ypos - y - e_font_ascent (text->font), - 1, - e_font_ascent (text->font) + e_font_descent (text->font)); - } - } else { - if (text->clip && text->use_ellipsis && lines->ellipsis_length < lines->length) { - e_font_draw_utf8_text (drawable, - text->font, E_FONT_PLAIN, - text->gc, - xpos - x, - ypos - y, - lines->text, - lines->ellipsis_length); - e_font_draw_utf8_text (drawable, - text->font, E_FONT_PLAIN, - text->gc, - xpos - x + lines->width - text->ellipsis_width, - ypos - y, - text->ellipsis ? text->ellipsis : "...", - text->ellipsis ? unicode_strlen (text->ellipsis, -1) : 3); - } else - e_font_draw_utf8_text (drawable, - text->font, E_FONT_PLAIN, - text->gc, - xpos - x, - ypos - y, - lines->text, - lines->length); - } - - ypos += e_font_ascent (text->font) + e_font_descent (text->font); - lines++; - } - - if (text->clip) { - gdk_gc_set_clip_rectangle (text->gc, NULL); - gdk_gc_set_clip_rectangle (fg_gc, NULL); - } -} - -/* Render handler for the text item */ -static void -e_text_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf) -{ -#if 0 - EText *text; - guint32 fg_color; - double xpos, ypos; - struct line *lines; - int i, j; - double affine[6]; - int dx, dy; - ArtPoint start_i, start_c; - - text = E_TEXT (item); - - if (!text->text || !text->font || !text->suckfont) - return; - - suckfont = text->suckfont; - - fg_color = text->rgba; - - gnome_canvas_buf_ensure_buf (buf); - - lines = text->lines; - if ( !lines ) - return; - - start_i.y = get_line_ypos_item_relative (text); - - art_affine_scale (affine, item->canvas->pixels_per_unit, item->canvas->pixels_per_unit); - for (i = 0; i < 6; i++) - affine[i] = text->affine[i]; - - for (i = 0; i < text->num_lines; i++) { - if (lines->length != 0) { - start_i.x = get_line_xpos_item_relative (text, lines); - art_affine_point (&start_c, &start_i, text->affine); - xpos = start_c.x; - ypos = start_c.y; - - for (j = 0; j < lines->length; j++) { - ETextSuckChar *ch; - - ch = &suckfont->chars[(unsigned char)((lines->text)[j])]; - - affine[4] = xpos; - affine[5] = ypos; - art_rgb_bitmap_affine ( - buf->buf, - buf->rect.x0, buf->rect.y0, buf->rect.x1, buf->rect.y1, - buf->buf_rowstride, - suckfont->bitmap + (ch->bitmap_offset >> 3), - ch->width, - suckfont->bitmap_height, - suckfont->bitmap_width >> 3, - fg_color, - affine, - ART_FILTER_NEAREST, NULL); - - dx = ch->left_sb + ch->width + ch->right_sb; - xpos += dx * affine[0]; - ypos += dx * affine[1]; - } - } - - dy = text->font->ascent + text->font->descent; - start_i.y += dy; - lines++; - } - - buf->is_bg = 0; -#endif -} - -/* Point handler for the text item */ -static double -e_text_point (GnomeCanvasItem *item, double x, double y, - int cx, int cy, GnomeCanvasItem **actual_item) -{ - EText *text; - int i; - struct line *lines; - int x1, y1, x2, y2; - int font_height; - int dx, dy; - double dist, best; - - text = E_TEXT (item); - - *actual_item = item; - - /* The idea is to build bounding rectangles for each of the lines of - * text (clipped by the clipping rectangle, if it is activated) and see - * whether the point is inside any of these. If it is, we are done. - * Otherwise, calculate the distance to the nearest rectangle. - */ - - if (text->font) - font_height = e_font_ascent (text->font) + e_font_descent (text->font); - else - font_height = 0; - - best = 1.0e36; - - lines = text->lines; - - if (text->fill_clip_rectangle) { - double clip_width; - double clip_height; - - /* Calculate the width and heights */ - calc_height (text); - calc_line_widths (text); - - if (text->clip_width < 0) - clip_width = text->max_width; - else - clip_width = text->clip_width; - - /* Get canvas pixel coordinates for clip rectangle position */ - clip_width = clip_width * item->canvas->pixels_per_unit; - if ( text->clip_height >= 0 ) - clip_height = text->clip_height * item->canvas->pixels_per_unit; - else - clip_height = text->height * item->canvas->pixels_per_unit; - - if (cx >= text->clip_cx && - cx <= text->clip_cx + clip_width && - cy >= text->clip_cy && - cy <= text->clip_cy + clip_height) - return 0; - else - return 1; - } - - for (i = 0; i < text->num_lines; i++) { - /* Compute the coordinates of rectangle for the current line, - * clipping if appropriate. - */ - - x1 = get_line_xpos (text, lines); - y1 = text->cy + i * font_height; - x2 = x1 + lines->width; - y2 = y1 + font_height; - - if (text->clip) { - if (x1 < text->clip_cx) - x1 = text->clip_cx; - - if (y1 < text->clip_cy) - y1 = text->clip_cy; - - if ( text->clip_width >= 0 ) { - if (x2 > (text->clip_cx + text->clip_width)) - x2 = text->clip_cx + text->clip_width; - } - - if ( text->clip_height >= 0 ) { - if (y2 > (text->clip_cy + text->clip_height)) - y2 = text->clip_cy + text->clip_height; - } - - if ((x1 >= x2) || (y1 >= y2)) - continue; - } - - /* Calculate distance from point to rectangle */ - - if (cx < x1) - dx = x1 - cx; - else if (cx >= x2) - dx = cx - x2 + 1; - else - dx = 0; - - if (cy < y1) - dy = y1 - cy; - else if (cy >= y2) - dy = cy - y2 + 1; - else - dy = 0; - - if ((dx == 0) && (dy == 0)) - return 0.0; - - dist = sqrt (dx * dx + dy * dy); - if (dist < best) - best = dist; - - /* Next! */ - - lines++; - } - - return best / item->canvas->pixels_per_unit; -} - -/* Bounds handler for the text item */ -static void -e_text_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2) -{ - EText *text; - double width, height; - - text = E_TEXT (item); - - *x1 = 0; - *y1 = 0; - - if (text->clip) { - width = text->clip_width; - if ( text->clip_height >= 0 ) - height = text->clip_height; - else height = text->height; - } else { - width = text->max_width / item->canvas->pixels_per_unit; - height = text->height / item->canvas->pixels_per_unit; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - *x1 -= width / 2.0; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - *x1 -= width; - break; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - *y1 -= height / 2.0; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - *y1 -= height; - break; - } - - *x2 = *x1 + width; - *y2 = *y1 + height; -} - -static void -_get_xy_from_position (EText *text, gint position, gint *xp, gint *yp) -{ - if ( !text->lines ) - return; - if (xp || yp) { - struct line *lines = NULL; - int x, y; - double xd, yd; - int j; - x = get_line_xpos_item_relative (text, lines); - y = text->yofs; - y -= text->yofs_edit; - for (j = 0, lines = text->lines; j < text->num_lines; lines++, j++) { - if (lines->text > text->text + position) - break; - y += e_font_height (text->font); - } - lines --; - y -= e_font_descent (text->font); - - x += e_font_utf8_text_width (text->font, E_FONT_PLAIN, - lines->text, - position - unicode_index_to_offset (text->text, lines->text - text->text)); - x -= text->xofs_edit; - - xd = x; yd = y; - gnome_canvas_item_i2w (GNOME_CANVAS_ITEM(text), &xd, &yd); - gnome_canvas_w2c (GNOME_CANVAS_ITEM(text)->canvas, xd, yd, &x, &y); - - if (xp) - *xp = x; - if (yp) - *yp = y; - } -} - -static gint -_get_position_from_xy (EText *text, gint x, gint y) -{ - int i, j; - int ypos = text->yofs; - int xpos; - double xd, yd; - char *p; - unicode_char_t unival; - - struct line *lines; - - xd = x; yd = y; - gnome_canvas_c2w (GNOME_CANVAS_ITEM(text)->canvas, xd, yd, &xd, &yd); - gnome_canvas_item_w2i (GNOME_CANVAS_ITEM(text), &xd, &yd); - x = xd; y = yd; - - y += text->yofs_edit; - - if (text->draw_borders) - ypos += BORDER_INDENT; - - j = 0; - while (y > ypos) { - ypos += e_font_height (text->font); - j ++; - } - j--; - if (j >= text->num_lines) - j = text->num_lines - 1; - if (j < 0) - j = 0; - i = 0; - lines = text->lines; - - if ( !lines ) - return 0; - - lines += j; - x += text->xofs_edit; - xpos = get_line_xpos_item_relative (text, lines); - - for (i = 0, p = lines->text; i < lines->length; i++, p = unicode_get_utf8 (p, &unival)) { - int charwidth; - - charwidth = e_font_utf8_text_width (text->font, E_FONT_PLAIN, p, 1); - xpos += charwidth / 2; - if (xpos > x) { - break; - } - xpos += (charwidth + 1) / 2; - } - return unicode_index_to_offset (text->text, p - text->text); -} - -#define SCROLL_WAIT_TIME 30000 - -static gboolean -_blink_scroll_timeout (gpointer data) -{ - EText *text = E_TEXT(data); - gulong current_time; - gboolean scroll = FALSE; - gboolean redraw = FALSE; - - g_timer_elapsed(text->timer, ¤t_time); - - if (text->scroll_start + SCROLL_WAIT_TIME > 1000000) { - if (current_time > text->scroll_start - (1000000 - SCROLL_WAIT_TIME) && - current_time < text->scroll_start) - scroll = TRUE; - } else { - if (current_time > text->scroll_start + SCROLL_WAIT_TIME || - current_time < text->scroll_start) - scroll = TRUE; - } - if (scroll && text->button_down) { - if (text->lastx - text->clip_cx > text->clip_cwidth && - text->xofs_edit < text->max_width - text->clip_cwidth) { - text->xofs_edit += 4; - if (text->xofs_edit > text->max_width - text->clip_cwidth + 1) - text->xofs_edit = text->max_width - text->clip_cwidth + 1; - redraw = TRUE; - } - if (text->lastx - text->clip_cx < 0 && - text->xofs_edit > 0) { - text->xofs_edit -= 4; - if (text->xofs_edit < 0) - text->xofs_edit = 0; - redraw = TRUE; - } - - if (text->lasty - text->clip_cy > text->clip_cheight && - text->yofs_edit < text->height - text->clip_cheight) { - text->yofs_edit += 4; - if (text->yofs_edit > text->height - text->clip_cheight + 1) - text->yofs_edit = text->height - text->clip_cheight + 1; - redraw = TRUE; - } - if (text->lasty - text->clip_cy < 0 && - text->yofs_edit > 0) { - text->yofs_edit -= 4; - if (text->yofs_edit < 0) - text->yofs_edit = 0; - redraw = TRUE; - } - - if (redraw) { - ETextEventProcessorEvent e_tep_event; - e_tep_event.type = GDK_MOTION_NOTIFY; - e_tep_event.motion.state = text->last_state; - e_tep_event.motion.time = 0; - e_tep_event.motion.position = _get_position_from_xy(text, text->lastx, text->lasty); - _get_tep(text); - e_text_event_processor_handle_event (text->tep, - &e_tep_event); - text->scroll_start = current_time; - } - } - - if (!((current_time / 500000) % 2)) { - if (!text->show_cursor) - redraw = TRUE; - text->show_cursor = TRUE; - } else { - if (text->show_cursor) - redraw = TRUE; - text->show_cursor = FALSE; - } - if (redraw) { - text->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); - } - return TRUE; -} - -static gboolean -tooltip_event(GtkWidget *tooltip, GdkEvent *event, EText *text) -{ - gint ret_val = FALSE; - switch (event->type) { - case GDK_LEAVE_NOTIFY: - if (text->tooltip_window) { - gtk_widget_destroy (text->tooltip_window); - text->tooltip_window = NULL; - } - break; - case GDK_BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - if (event->type == GDK_BUTTON_RELEASE) { - if (text->tooltip_window) { - gtk_widget_destroy (text->tooltip_window); - text->tooltip_window = NULL; - } - } - /* Forward events to the text item */ - gtk_signal_emit_by_name (GTK_OBJECT (text), "event", event, - &ret_val); - default: - break; - } - return ret_val; -} - -static gboolean -_do_tooltip (gpointer data) -{ - EText *text = E_TEXT (data); - struct line *lines; - GtkWidget *canvas; - int i; - gdouble max_width; - gboolean cut_off; - double i2c[6]; - ArtPoint origin = {0, 0}; - ArtPoint pixel_origin; - int canvas_x, canvas_y; - GnomeCanvasItem *tooltip_text; - double tooltip_width; - double tooltip_height; - double tooltip_x; - double tooltip_y; -#if 0 - double x1, x2, y1, y2; -#endif - GnomeCanvasItem *rect; - - text->tooltip_count = 0; - - lines = text->lines; - - if (text->tooltip_window || text->editing || (!lines)) { - text->tooltip_timeout = 0; - return FALSE; - } - - cut_off = FALSE; - for ( lines = text->lines, i = 0; i < text->num_lines; lines++, i++ ) { - if (lines->length > lines->ellipsis_length) { - cut_off = TRUE; - break; - } - } - if ( ! cut_off ) { - text->tooltip_timeout = 0; - return FALSE; - } - - gnome_canvas_item_i2c_affine(GNOME_CANVAS_ITEM(text), i2c); - art_affine_point (&pixel_origin, &origin, i2c); - - gdk_window_get_origin (GTK_WIDGET(GNOME_CANVAS_ITEM(text)->canvas)->window, &canvas_x, &canvas_y); - pixel_origin.x += canvas_x; - pixel_origin.y += canvas_y; - pixel_origin.x -= (int) gtk_layout_get_hadjustment(GTK_LAYOUT(GNOME_CANVAS_ITEM(text)->canvas))->value; - pixel_origin.y -= (int) gtk_layout_get_vadjustment(GTK_LAYOUT(GNOME_CANVAS_ITEM(text)->canvas))->value; - - text->tooltip_window = gtk_window_new (GTK_WINDOW_POPUP); - gtk_container_set_border_width (GTK_CONTAINER (text->tooltip_window), 1); - - canvas = e_canvas_new (); - - - - - - - - gtk_container_add (GTK_CONTAINER (text->tooltip_window), canvas); - - /* Get the longest line length */ - max_width = 0.0; - for (lines = text->lines, i = 0; i < text->num_lines; lines++, i++) { - gdouble line_width; - - line_width = e_font_utf8_text_width (text->font, E_FONT_PLAIN, lines->text, lines->length); - max_width = MAX (max_width, line_width); - } - - rect = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)), - gnome_canvas_rect_get_type (), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) max_width + 4, - "y2", (double) text->height + 4, - "fill_color", "yellow", - NULL); - - /* fixme: */ - tooltip_text = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)), - e_text_get_type (), - "anchor", GTK_ANCHOR_NW, - "font_gdk", text->font, - "text", text->text, - "editable", FALSE, - "clip_width", text->max_lines != 1 ? text->clip_width : max_width, - "clip_height", text->max_lines != 1 ? -1 : (double)text->height, - "clip", TRUE, - "line_wrap", text->line_wrap, - "justification", text->justification, - NULL); - - - - if (text->draw_borders) - e_canvas_item_move_absolute(tooltip_text, 1 + BORDER_INDENT, 1 + BORDER_INDENT); - else - e_canvas_item_move_absolute(tooltip_text, 1, 1); - - - calc_height(E_TEXT(tooltip_text)); - calc_line_widths(E_TEXT(tooltip_text)); - gnome_canvas_item_set (tooltip_text, - "clip_height", (double) E_TEXT(tooltip_text)->height, - "clip_width", (double) E_TEXT(tooltip_text)->max_width, - NULL); - tooltip_width = E_TEXT(tooltip_text)->max_width; - tooltip_height = E_TEXT(tooltip_text)->height; - tooltip_x = 0; - tooltip_y = 0; - switch(E_TEXT(tooltip_text)->justification) { - case GTK_JUSTIFY_CENTER: - tooltip_x = - tooltip_width / 2; - break; - case GTK_JUSTIFY_RIGHT: - tooltip_x = tooltip_width / 2; - break; - case GTK_JUSTIFY_FILL: - case GTK_JUSTIFY_LEFT: - tooltip_x = 0; - break; - } - switch(E_TEXT(tooltip_text)->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - tooltip_y -= tooltip_height / 2.0; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - tooltip_y -= tooltip_height; - break; - } - switch(E_TEXT(tooltip_text)->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - tooltip_x -= tooltip_width / 2.0; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - tooltip_x -= tooltip_width; - break; - } -#if 0 - get_bounds(text, &x1, &y1, &x2, &y2); - if ( x1 < tooltip_x ) { - gnome_canvas_item_move(tooltip_text, tooltip_x - x1, 0); - tooltip_x = x1; - } - if ( y1 < tooltip_y ) { - gnome_canvas_item_move(tooltip_text, 0, tooltip_y - y1); - tooltip_y = y1; - } - if ( x2 > tooltip_x + tooltip_width ) - tooltip_width = x2 - tooltip_x; - if ( y2 > tooltip_y + tooltip_height ) - tooltip_height = y2 - tooltip_y; -#endif - - gnome_canvas_item_set(rect, - "x2", (double) tooltip_width + 4 + (text->draw_borders ? BORDER_INDENT * 2 : 0), - "y2", (double) tooltip_height + 4 + (text->draw_borders ? BORDER_INDENT * 2 : 0), - NULL); - - gtk_widget_set_usize (text->tooltip_window, - tooltip_width + 4 + (text->draw_borders ? BORDER_INDENT * 2 : 0), - tooltip_height + 4 + (text->draw_borders ? BORDER_INDENT * 2 : 0)); - gnome_canvas_set_scroll_region (GNOME_CANVAS(canvas), 0.0, 0.0, - tooltip_width + (text->draw_borders ? BORDER_INDENT * 2 : 0), - (double)tooltip_height + (text->draw_borders ? BORDER_INDENT * 2 : 0)); - gtk_widget_show (canvas); - gtk_widget_realize (text->tooltip_window); - gtk_signal_connect (GTK_OBJECT(text->tooltip_window), "event", - GTK_SIGNAL_FUNC(tooltip_event), text); - - gtk_widget_popup (text->tooltip_window, pixel_origin.x - 2 + tooltip_x, pixel_origin.y - 2 + tooltip_y); - - text->tooltip_timeout = 0; - return FALSE; -} - -static gboolean -_click (gpointer data) -{ - *(gint *)data = 0; - return FALSE; -} - -static gint -e_text_event (GnomeCanvasItem *item, GdkEvent *event) -{ - EText *text = E_TEXT(item); - ETextEventProcessorEvent e_tep_event; - - gint return_val = 0; - - e_tep_event.type = event->type; - switch (event->type) { - case GDK_FOCUS_CHANGE: - if (text->editable) { - GdkEventFocus *focus_event; - focus_event = (GdkEventFocus *) event; - if (focus_event->in) { - if(!text->editing) { - text->editing = TRUE; - if ( text->pointer_in ) { - if ( text->default_cursor_shown && (!text->draw_borders)) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->i_cursor); - text->default_cursor_shown = FALSE; - } - } - text->select_by_word = FALSE; - text->xofs_edit = 0; - text->yofs_edit = 0; - if (text->timeout_id == 0) - text->timeout_id = g_timeout_add(10, _blink_scroll_timeout, text); - text->timer = g_timer_new(); - g_timer_elapsed(text->timer, &(text->scroll_start)); - g_timer_start(text->timer); - } - } else { - text->editing = FALSE; - if ( (!text->default_cursor_shown) && (!text->draw_borders) ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->default_cursor); - text->default_cursor_shown = TRUE; - } - if (text->timeout_id) { - g_source_remove(text->timeout_id); - text->timeout_id = 0; - } - if (text->timer) { - g_timer_stop(text->timer); - g_timer_destroy(text->timer); - text->timer = NULL; - } - } - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else - text->needs_calc_line_widths = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(text)); - } - return_val = 0; - break; - case GDK_KEY_PRESS: /* Fall Through */ - case GDK_KEY_RELEASE: - if (text->editing) { - GdkEventKey key = event->key; - e_tep_event.key.time = key.time; - e_tep_event.key.state = key.state; - e_tep_event.key.keyval = key.keyval; - e_tep_event.key.length = key.length; - e_tep_event.key.string = key.string; - _get_tep(text); - return e_text_event_processor_handle_event (text->tep, - &e_tep_event); - } - else - return 0; - break; - case GDK_BUTTON_PRESS: /* Fall Through */ - case GDK_BUTTON_RELEASE: - if (text->tooltip_timeout) { - gtk_timeout_remove (text->tooltip_timeout); - text->tooltip_timeout = 0; - } - if (text->tooltip_window) { - gtk_widget_destroy (text->tooltip_window); - text->tooltip_window = NULL; - } -#if 0 - if ((!text->editing) - && text->editable - && event->type == GDK_BUTTON_RELEASE - && event->button.button == 1) { - GdkEventButton button = event->button; - - e_canvas_item_grab_focus (item); - - e_tep_event.type = GDK_BUTTON_RELEASE; - 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(text, button.x, button.y); - _get_tep(text); - return_val = e_text_event_processor_handle_event (text->tep, - &e_tep_event); - e_tep_event.type = GDK_BUTTON_RELEASE; - } -#else - if ((!text->editing) - && text->editable - && (event->button.button == 1 || - event->button.button == 2)) { - e_canvas_item_grab_focus (item); - } -#endif - /* Create our own double and triple click events, - as gnome-canvas doesn't forward them to us */ - if (event->type == GDK_BUTTON_PRESS) { - if (text->dbl_timeout == 0 && - text->tpl_timeout == 0) { - text->dbl_timeout = gtk_timeout_add (200, - _click, - &(text->dbl_timeout)); - } else { - if (text->tpl_timeout == 0) { - e_tep_event.type = GDK_2BUTTON_PRESS; - text->tpl_timeout = gtk_timeout_add (200, _click, &(text->tpl_timeout)); - } else { - e_tep_event.type = GDK_3BUTTON_PRESS; - } - } - } - - if (text->editing) { - 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(text, button.x, button.y); - _get_tep(text); - return_val = e_text_event_processor_handle_event (text->tep, - &e_tep_event); - if (event->button.button == 1) { - if (event->type == GDK_BUTTON_PRESS) - text->button_down = TRUE; - else - text->button_down = FALSE; - } - text->lastx = button.x; - text->lasty = button.y; - text->last_state = button.state; - } - break; - case GDK_MOTION_NOTIFY: - if (text->editing) { - 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(text, motion.x, motion.y); - _get_tep(text); - return_val = e_text_event_processor_handle_event (text->tep, - &e_tep_event); - text->lastx = motion.x; - text->lasty = motion.y; - text->last_state = motion.state; - } - break; - case GDK_ENTER_NOTIFY: - { - GdkEventCrossing *crossing = (GdkEventCrossing *) event; - double x1, y1, x2, y2; - get_bounds (text, &x1, &y1, &x2, &y2); - if (crossing->x >= x1 && - crossing->y >= y1 && - crossing->x <= x2 && - crossing->y <= y2) { - if ( text->tooltip_count == 0 && text->clip) { - if (!text->tooltip_timeout) - text->tooltip_timeout = gtk_timeout_add (1000, _do_tooltip, text); - } - text->tooltip_count ++; - } - } - - text->pointer_in = TRUE; - if (text->editing || text->draw_borders) { - if ( text->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->i_cursor); - text->default_cursor_shown = FALSE; - } - } - break; - case GDK_LEAVE_NOTIFY: - if (text->tooltip_count > 0) - text->tooltip_count --; - if ( text->tooltip_count == 0 && text->clip) { - if ( text->tooltip_timeout ) { - gtk_timeout_remove (text->tooltip_timeout); - text->tooltip_timeout = 0; - } - } - - text->pointer_in = FALSE; - if (text->editing || text->draw_borders) { - if ( ! text->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->default_cursor); - text->default_cursor_shown = TRUE; - } - } - break; - default: - break; - } - if (return_val) - return return_val; - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS(parent_class)->event(item, event); - else - return 0; -} - -/* fixme: */ - -static int -_get_position(EText *text, ETextEventProcessorCommand *command) -{ - int i; - int length; - int x, y; - unicode_char_t unival; - char *p; - - switch (command->position) { - - case E_TEP_VALUE: - return command->value; - - case E_TEP_SELECTION: - return text->selection_end; - - case E_TEP_START_OF_BUFFER: - return 0; - case E_TEP_END_OF_BUFFER: - return unicode_strlen (text->text, -1); - - case E_TEP_START_OF_LINE: - for (i = text->selection_end - 2; i > 0; i--) { - p = text->text + unicode_offset_to_index (text->text, i); - unicode_get_utf8 (p, &unival); - if (unival == '\n') { - i++; - break; - } - } - return i; - case E_TEP_END_OF_LINE: - length = unicode_strlen(text->text, -1); - for (i = text->selection_end + 1; i < length; i++) { - p = text->text + unicode_offset_to_index (text->text, i); - unicode_get_utf8 (p, &unival); - if (unival == '\n') { - break; - } - } - if (i > length) - i = length; - return i; - - case E_TEP_FORWARD_CHARACTER: - length = unicode_strlen (text->text, -1); - i = text->selection_end + 1; - if (i > length) - i = length; - return i; - case E_TEP_BACKWARD_CHARACTER: - i = text->selection_end - 1; - if (i < 0) - i = 0; - return i; - - case E_TEP_FORWARD_WORD: - length = unicode_strlen (text->text, -1); - for (i = text->selection_end + 1; i < length; i++) { - p = text->text + unicode_offset_to_index (text->text, i); - unicode_get_utf8 (p, &unival); - if (unicode_isspace (unival)) { - break; - } - } - if (i > length) - i = length; - return i; - case E_TEP_BACKWARD_WORD: - for (i = text->selection_end - 2; i > 0; i--) { - p = text->text + unicode_offset_to_index (text->text, i); - unicode_get_utf8 (p, &unival); - if (unicode_isspace (unival)) { - i++; - break; - } - } - if (i < 0) - i = 0; - return i; - - case E_TEP_FORWARD_LINE: - _get_xy_from_position(text, text->selection_end, &x, &y); - y += e_font_height (text->font); - return _get_position_from_xy(text, x, y); - case E_TEP_BACKWARD_LINE: - _get_xy_from_position(text, text->selection_end, &x, &y); - y -= e_font_height (text->font); - return _get_position_from_xy(text, x, y); - - case E_TEP_SELECT_WORD: - for (i = text->selection_end - 2; i > 0; i--) { - p = text->text + unicode_offset_to_index (text->text, i); - unicode_get_utf8 (p, &unival); - if (unicode_isspace (unival)) { - i++; - break; - } - } - if (i < 0) - text->selection_start = 0; - else - text->selection_start = i; - - length = unicode_strlen (text->text, -1); - for (i = text->selection_end + 1; i < length; i++) { - p = text->text + unicode_offset_to_index (text->text, i); - unicode_get_utf8 (p, &unival); - if (unicode_isspace (unival)) { - break; - } - } - if (i > length) - i = length; - return i; - - case E_TEP_SELECT_ALL: - text->selection_start = 0; - length = unicode_strlen (text->text, -1); - return length; - - case E_TEP_FORWARD_PARAGRAPH: - case E_TEP_BACKWARD_PARAGRAPH: - - case E_TEP_FORWARD_PAGE: - case E_TEP_BACKWARD_PAGE: - return text->selection_end; - default: - return text->selection_end; - } -} - -static void -_delete_selection(EText *text) -{ - if ( text->selection_start < text->selection_end ) { - e_text_model_delete(text->model, text->selection_start, text->selection_end - text->selection_start); - text->selection_end = text->selection_start; - } else { - e_text_model_delete(text->model, text->selection_end, text->selection_start - text->selection_end); - text->selection_start = text->selection_end; - } -} - -static void -_insert(EText *text, char *string, int value) -{ - if (value > 0) { - e_text_model_insert_length(text->model, text->selection_start, string, value); - - text->selection_start += value; - text->selection_end = text->selection_start; - } -} - -static void -e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data) -{ - EText *text = E_TEXT(data); - int sel_start, sel_end; - switch (command->action) { - case E_TEP_MOVE: - text->selection_start = _get_position(text, command); - text->selection_end = text->selection_start; - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_SELECT: - text->selection_end = _get_position(text, command); - sel_start = MIN(text->selection_start, text->selection_end); - sel_end = MAX(text->selection_start, text->selection_end); - if (sel_start != sel_end) { - e_text_supply_selection (text, command->time, GDK_SELECTION_PRIMARY, - text->text + unicode_offset_to_index (text->text, sel_start), sel_end - sel_start); - } else if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_DELETE: - if (text->selection_end == text->selection_start) { - text->selection_end = _get_position(text, command); - } - _delete_selection(text); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - - case E_TEP_INSERT: - if (text->selection_end != text->selection_start) { - _delete_selection(text); - } - _insert(text, command->string, command->value); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_COPY: - sel_start = MIN(text->selection_start, text->selection_end); - sel_end = MAX(text->selection_start, text->selection_end); - if (sel_start != sel_end) { - e_text_supply_selection (text, command->time, clipboard_atom, - text->text + unicode_offset_to_index (text->text, sel_start), sel_end - sel_start); - } - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_PASTE: - e_text_get_selection (text, clipboard_atom, command->time); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_GET_SELECTION: - e_text_get_selection (text, GDK_SELECTION_PRIMARY, command->time); - break; - case E_TEP_ACTIVATE: - gtk_signal_emit (GTK_OBJECT (text), e_text_signals[E_TEXT_ACTIVATE]); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_SET_SELECT_BY_WORD: - text->select_by_word = command->value; - break; - case E_TEP_GRAB: - gnome_canvas_item_grab (GNOME_CANVAS_ITEM(text), - GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, - text->i_cursor, - command->time); - break; - case E_TEP_UNGRAB: - gnome_canvas_item_ungrab (GNOME_CANVAS_ITEM(text), command->time); - break; - case E_TEP_NOP: - break; - } - - if (!text->button_down) { - int x; - int i; - struct line *lines = text->lines; - gdouble clip_width; - if ( !lines ) - return; - - for (lines = text->lines, i = 0; i < text->num_lines ; i++, lines ++) { - if (unicode_index_to_offset (text->text, lines->text - text->text) > text->selection_end) { - break; - } - } - lines --; - i --; - x = e_font_utf8_text_width(text->font, E_FONT_PLAIN, - lines->text, - text->selection_end - unicode_index_to_offset (text->text, lines->text - text->text)); - - - if (x < text->xofs_edit) { - text->xofs_edit = x; - } - - clip_width = text->clip_width; - if (clip_width >= 0 && text->draw_borders) { - clip_width -= 6; - if (clip_width < 0) - clip_width = 0; - } - - if (2 + x - clip_width > text->xofs_edit) { - text->xofs_edit = 2 + x - clip_width; - } - - if (e_font_height (text->font) * i < text->yofs_edit) - text->yofs_edit = e_font_height (text->font) * i; - - if (e_font_height (text->font) * (i + 1) - (text->clip_height != -1 ? text->clip_height : text->height) > text->yofs_edit) - text->yofs_edit = e_font_height (text->font) * (i + 1) - (text->clip_height != -1 ? text->clip_height : text->height); - } - - text->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); -} - -static void _invisible_destroy (GtkInvisible *invisible, - EText *text) -{ - text->invisible = NULL; -} - -static GtkWidget *e_text_get_invisible(EText *text) -{ - GtkWidget *invisible; - if (text->invisible) { - invisible = text->invisible; - } else { - invisible = gtk_invisible_new(); - text->invisible = invisible; - - gtk_selection_add_target (invisible, - GDK_SELECTION_PRIMARY, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_PRIMARY); - gtk_selection_add_target (invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_CLIPBOARD); - - gtk_signal_connect (GTK_OBJECT(invisible), "selection_get", - GTK_SIGNAL_FUNC (_selection_get), - text); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_clear_event", - GTK_SIGNAL_FUNC (_selection_clear_event), - text); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_received", - GTK_SIGNAL_FUNC (_selection_received), - text); - - gtk_signal_connect (GTK_OBJECT(invisible), "destroy", - GTK_SIGNAL_FUNC (_invisible_destroy), - text); - } - return invisible; -} - -static void -_selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - EText *text) -{ - if (event->selection == GDK_SELECTION_PRIMARY) { - g_free (text->primary_selection); - text->primary_selection = NULL; - text->primary_length = 0; - - text->has_selection = FALSE; - text->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); - - } else if (event->selection == clipboard_atom) { - g_free (text->clipboard_selection); - text->clipboard_selection = NULL; - text->clipboard_length = 0; - } -} - -static void -_selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EText *text) -{ - switch (info) { - case E_SELECTION_PRIMARY: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, text->primary_selection, text->primary_length); - break; - case E_SELECTION_CLIPBOARD: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, text->clipboard_selection, text->clipboard_length); - break; - } -} - -static void -_selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - EText *text) -{ - if (selection_data->length < 0 || selection_data->type != GDK_SELECTION_TYPE_STRING) { - return; - } else { - ETextEventProcessorCommand command; - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.string = selection_data->data; - command.value = selection_data->length; - command.time = time; - e_text_command(text->tep, &command, text); - } -} - -static void e_text_supply_selection (EText *text, guint time, GdkAtom selection, guchar *data, gint length) -{ - gboolean successful; - GtkWidget *invisible; - - invisible = e_text_get_invisible(text); - - if (selection == GDK_SELECTION_PRIMARY ) { - if (text->primary_selection) { - g_free (text->primary_selection); - } - text->primary_selection = g_strndup(data, length); - text->primary_length = length; - } else if (selection == clipboard_atom) { - if (text->clipboard_selection) { - g_free (text->clipboard_selection); - } - text->clipboard_selection = g_strndup(data, length); - text->clipboard_length = length; - } - - successful = gtk_selection_owner_set (invisible, - selection, - time); - - if (selection == GDK_SELECTION_PRIMARY) - text->has_selection = successful; -} - -static void -e_text_get_selection(EText *text, GdkAtom selection, guint32 time) -{ - GtkWidget *invisible; - invisible = e_text_get_invisible(text); - gtk_selection_convert(invisible, - selection, - GDK_SELECTION_TYPE_STRING, - time); -} - -#if 0 -static void -e_text_real_copy_clipboard (EText *text) -{ - guint32 time; - gint selection_start_pos; - gint selection_end_pos; - - g_return_if_fail (text != NULL); - g_return_if_fail (E_IS_TEXT (text)); - - time = gtk_text_get_event_time (text); - selection_start_pos = MIN (text->selection_start, text->selection_end); - selection_end_pos = MAX (text->selection_start, text->selection_end); - - if (selection_start_pos != selection_end_pos) - { - if (gtk_selection_owner_set (GTK_WIDGET (text->canvas), - clipboard_atom, - time)) - text->clipboard_text = ""; - } -} - -static void -e_text_real_paste_clipboard (EText *text) -{ - guint32 time; - - g_return_if_fail (text != NULL); - g_return_if_fail (E_IS_TEXT (text)); - - time = e_text_get_event_time (text); - if (text->editable) - gtk_selection_convert (GTK_WIDGET(text->widget), - clipboard_atom, - gdk_atom_intern ("COMPOUND_TEXT", FALSE), time); -} -#endif - - -#if 0 -/* Routines for sucking fonts from the X server */ - -static ETextSuckFont * -e_suck_font (GdkFont *font) -{ - ETextSuckFont *suckfont; - int i; - int x, y; - char text[1]; - int lbearing, rbearing, ch_width, ascent, descent; - GdkPixmap *pixmap; - GdkColor black, white; - GdkImage *image; - GdkGC *gc; - guchar *line; - int width, height; - int black_pixel, pixel; - - if (!font) - return NULL; - - suckfont = g_new (ETextSuckFont, 1); - - height = font->ascent + font->descent; - x = 0; - for (i = 0; i < 256; i++) { - text[0] = i; - gdk_text_extents (font, text, 1, - &lbearing, &rbearing, &ch_width, &ascent, &descent); - suckfont->chars[i].left_sb = lbearing; - suckfont->chars[i].right_sb = ch_width - rbearing; - suckfont->chars[i].width = rbearing - lbearing; - suckfont->chars[i].ascent = ascent; - suckfont->chars[i].descent = descent; - suckfont->chars[i].bitmap_offset = x; - x += (ch_width + 31) & -32; - } - - width = x; - - suckfont->bitmap_width = width; - suckfont->bitmap_height = height; - suckfont->ascent = font->ascent; - - pixmap = gdk_pixmap_new (NULL, suckfont->bitmap_width, - suckfont->bitmap_height, 1); - gc = gdk_gc_new (pixmap); - gdk_gc_set_font (gc, font); - - black_pixel = BlackPixel (gdk_display, DefaultScreen (gdk_display)); - black.pixel = black_pixel; - white.pixel = WhitePixel (gdk_display, DefaultScreen (gdk_display)); - gdk_gc_set_foreground (gc, &white); - gdk_draw_rectangle (pixmap, gc, 1, 0, 0, width, height); - - gdk_gc_set_foreground (gc, &black); - for (i = 0; i < 256; i++) { - text[0] = i; - gdk_draw_text (pixmap, font, gc, - suckfont->chars[i].bitmap_offset - suckfont->chars[i].left_sb, - font->ascent, - text, 1); - } - - /* The handling of the image leaves me with distinct unease. But this - * is more or less copied out of gimp/app/text_tool.c, so it _ought_ to - * work. -RLL - */ - - image = gdk_image_get (pixmap, 0, 0, width, height); - suckfont->bitmap = g_malloc0 ((width >> 3) * height); - - line = suckfont->bitmap; - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { - pixel = gdk_image_get_pixel (image, x, y); - if (pixel == black_pixel) - line[x >> 3] |= 128 >> (x & 7); - } - line += width >> 3; - } - - gdk_image_destroy (image); - - /* free the pixmap */ - gdk_pixmap_unref (pixmap); - - /* free the gc */ - gdk_gc_destroy (gc); - - return suckfont; -} - -static void -e_suck_font_free (ETextSuckFont *suckfont) -{ - g_free (suckfont->bitmap); - g_free (suckfont); -} -#endif - - - - - - - diff --git a/widgets/e-text/e-text.h b/widgets/e-text/e-text.h deleted file mode 100644 index 9d992fb58b..0000000000 --- a/widgets/e-text/e-text.h +++ /dev/null @@ -1,227 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* EText - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey <clahey@umich.edu> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> */ - -#ifndef E_TEXT_H -#define E_TEXT_H - -#include <gnome.h> -#include "e-util/e-font.h" -#include "e-text-event-processor.h" -#include "e-text-model.h" - - -BEGIN_GNOME_DECLS - - -/* Text item for the canvas. Text items are positioned by an anchor point and an anchor direction. - * - * A clipping rectangle may be specified for the text. The rectangle is anchored at the text's anchor - * point, and is specified by clipping width and height parameters. If the clipping rectangle is - * enabled, it will clip the text. - * - * In addition, x and y offset values may be specified. These specify an offset from the anchor - * position. If used in conjunction with the clipping rectangle, these could be used to implement - * simple scrolling of the text within the clipping rectangle. - * - * The following object arguments are available: - * - * name type read/write description - * ------------------------------------------------------------------------------------------ - * text string RW The string of the text label - * font string W X logical font descriptor - * fontset string W X logical fontset descriptor - * font_gdk GdkFont* RW Pointer to a GdkFont - * anchor GtkAnchorType RW Anchor side for the text - * justification GtkJustification RW Justification for multiline text - * fill_color string W X color specification for text - * fill_color_gdk GdkColor* RW Pointer to an allocated GdkColor - * fill_stipple GdkBitmap* RW Stipple pattern for filling the text - * clip_width double RW Width of clip rectangle - * clip_height double RW Height of clip rectangle - * clip boolean RW Use clipping rectangle? - * fill_clip_rect boolean RW Whether the text item represents itself as being the size of the clipping rectangle. - * x_offset double RW Horizontal offset distance from anchor position - * y_offset double RW Vertical offset distance from anchor position - * text_width double R Used to query the width of the rendered text - * text_height double R Used to query the rendered height of the text - * width double RW A synonym for clip_width - * height double R A synonym for text_height - * - * These are currently ignored in the AA version: - * editable boolean RW Can this item be edited - * use_ellipsis boolean RW Whether to use ellipsises if text gets cut off. Meaningless if clip == false. - * ellipsis string RW The characters to use as ellipsis. NULL = "...". - * line_wrap boolean RW Line wrap when not editing. - * break_characters string RW List of characters to optionally break on. - * max_lines int RW Number of lines possible when doing line wrap. - * draw_borders boolean RW Whether to draw borders. - */ - -#define E_TYPE_TEXT (e_text_get_type ()) -#define E_TEXT(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TEXT, EText)) -#define E_TEXT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TEXT, ETextClass)) -#define E_IS_TEXT(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TEXT)) -#define E_IS_TEXT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TEXT)) - - -typedef struct _EText EText; -typedef struct _ETextClass ETextClass; - -#if 0 -typedef struct _ETextSuckFont ETextSuckFont; -typedef struct _ETextSuckChar ETextSuckChar; - -struct _ETextSuckChar { - int left_sb; - int right_sb; - int width; - int ascent; - int descent; - int bitmap_offset; /* in pixels */ -}; - -struct _ETextSuckFont { - guchar *bitmap; - gint bitmap_width; - gint bitmap_height; - gint ascent; - ETextSuckChar chars[256]; -}; -#endif - -struct _EText { - GnomeCanvasItem item; - - ETextModel *model; - gint model_changed_signal_id; - - char *text; /* Text to display */ - gpointer lines; /* Text split into lines (private field) */ - int num_lines; /* Number of lines of text */ - -#if 0 - GdkFont *font; /* Font for text */ -#else - EFont *font; -#endif - GtkAnchorType anchor; /* Anchor side for text */ - GtkJustification justification; /* Justification for text */ - - double clip_width; /* Width of optional clip rectangle */ - double clip_height; /* Height of optional clip rectangle */ - - double xofs, yofs; /* Text offset distance from anchor position */ - - gulong pixel; /* Fill color */ - GdkBitmap *stipple; /* Stipple for text */ - GdkGC *gc; /* GC for drawing text */ - - int cx, cy; /* Top-left canvas coordinates for text */ - int clip_cx, clip_cy; /* Top-left canvas coordinates for clip rectangle */ - int clip_cwidth, clip_cheight; /* Size of clip rectangle in pixels */ - int max_width; /* Maximum width of text lines */ - int width; /* Rendered text width in pixels */ - int height; /* Rendered text height in pixels */ - - guint clip : 1; /* Use clip rectangle? */ - guint fill_clip_rectangle : 1; /* Fill the clipping rectangle. */ - - /* Antialiased specific stuff follows */ -#if 0 - ETextSuckFont *suckfont; /* Sucked font */ -#endif - guint32 rgba; /* RGBA color for text */ - double affine[6]; /* The item -> canvas affine */ - - char *ellipsis; /* The ellipsis characters. NULL = "...". */ - double ellipsis_width; /* The width of the ellipsis. */ - gboolean use_ellipsis; /* Whether to use the ellipsis. */ - - gboolean editable; /* Item is editable */ - gboolean editing; /* Item is currently being edited */ - - int xofs_edit; /* Offset because of editing */ - int yofs_edit; /* Offset because of editing */ - - /* This needs to be reworked a bit once we get line wrapping. */ - int selection_start; /* Start of selection */ - int selection_end; /* End of selection */ - gboolean select_by_word; /* Current selection is by word */ - - /* This section is for drag scrolling and blinking cursor. */ - 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 */ - gint tep_command_id; - - GtkWidget *invisible; /* For selection handling */ - gboolean has_selection; /* TRUE if we have the selection */ - gchar *primary_selection; /* Primary selection text */ - gint primary_length; /* Primary selection text length */ - gchar *clipboard_selection; /* Clipboard selection text */ - gint clipboard_length; /* Clipboard selection text length*/ - - guint pointer_in : 1; /* Is the pointer currently over us? */ - guint default_cursor_shown : 1; /* Is the default cursor currently shown? */ - guint draw_borders : 1; /* Draw borders? */ - - guint line_wrap : 1; /* Do line wrap */ - gchar *break_characters; /* Characters to optionally break after */ - - gint max_lines; /* Max number of lines (-1 = infinite) */ - - GdkCursor *default_cursor; /* Default cursor (arrow) */ - GdkCursor *i_cursor; /* I beam cursor */ - - gint tooltip_timeout; /* Timeout for the tooltip */ - GtkWidget *tooltip_window; /* GtkWindow for displaying the tooltip */ - gint tooltip_count; /* GDK_ENTER_NOTIFY count. */ - - guint needs_redraw : 1; /* Needs redraw */ - guint needs_recalc_bounds : 1; /* Need recalc_bounds */ - guint needs_calc_height : 1; /* Need calc_height */ - guint needs_calc_line_widths : 1; /* Needs calc_line_widths */ - guint needs_split_into_lines : 1; /* Needs split_into_lines */ - - gint dbl_timeout; /* Double click timeout */ - gint tpl_timeout; /* Triple click timeout */ -}; - -struct _ETextClass { - GnomeCanvasItemClass parent_class; - - void (* changed) (EText *text); - void (* activate) (EText *text); -}; - - -/* Standard Gtk function */ -GtkType e_text_get_type (void); - - -END_GNOME_DECLS - -#endif diff --git a/widgets/meeting-time-sel/.cvsignore b/widgets/meeting-time-sel/.cvsignore deleted file mode 100644 index 50530fdf4e..0000000000 --- a/widgets/meeting-time-sel/.cvsignore +++ /dev/null @@ -1,8 +0,0 @@ -.deps -.libs -.pure -Makefile -Makefile.in -*.lo -*.la -test-meeting-time-selector diff --git a/widgets/meeting-time-sel/ChangeLog b/widgets/meeting-time-sel/ChangeLog deleted file mode 100644 index 847431e29d..0000000000 --- a/widgets/meeting-time-sel/ChangeLog +++ /dev/null @@ -1,9 +0,0 @@ -2000-06-26 Christopher James Lahey <clahey@helixcode.com> - - * Makefile.am: Added the include path to top_srcdir. - -2000-06-25 Ettore Perazzoli <ettore@helixcode.com> - - * e-meeting-time-sel.c: Specify the #include path for - `e-canvas-utils.h' so that we build with builddir != srcdir. - diff --git a/widgets/meeting-time-sel/LICENSE b/widgets/meeting-time-sel/LICENSE deleted file mode 100644 index 9babf4395f..0000000000 --- a/widgets/meeting-time-sel/LICENSE +++ /dev/null @@ -1 +0,0 @@ -This code is licensed under the terms of the GNU GPL diff --git a/widgets/meeting-time-sel/Makefile.am b/widgets/meeting-time-sel/Makefile.am deleted file mode 100644 index 840c333f1a..0000000000 --- a/widgets/meeting-time-sel/Makefile.am +++ /dev/null @@ -1,36 +0,0 @@ - -INCLUDES = \ - $(GNOME_INCLUDEDIR) \ - -I $(top_srcdir) \ - -DG_LOG_DOMAIN=\"meeting-time-sel\" - -noinst_LIBRARIES = \ - libevolutionmtsel.a - -libevolutionmtsel_a_SOURCES = \ - e-meeting-time-sel.c \ - e-meeting-time-sel.h \ - e-meeting-time-sel-item.c \ - e-meeting-time-sel-item.h \ - e-meeting-time-sel-list-item.c \ - e-meeting-time-sel-list-item.h - -noinst_PROGRAMS = \ - test-meeting-time-selector - -test_meeting_time_selector_SOURCES = \ - test-meeting-time-sel.c - -test_meeting_time_selector_LDADD = \ - libevolutionmtsel.a \ - $(top_builddir)/widgets/e-text/libetext.a \ - $(top_builddir)/e-util/libeutil.la \ - $(EXTRA_GNOME_LIBS) \ - $(GNOMEUI_LIBS) - -test_meeting_time_selector_LDFLAGS = $(GNOME_LIBDIR) - -EXTRA_DIST = \ - e-meeting-time-sel-mail.xpm \ - e-meeting-time-sel-no-mail.xpm - diff --git a/widgets/meeting-time-sel/e-meeting-time-sel-item.c b/widgets/meeting-time-sel/e-meeting-time-sel-item.c deleted file mode 100644 index 54cde8d319..0000000000 --- a/widgets/meeting-time-sel/e-meeting-time-sel-item.c +++ /dev/null @@ -1,978 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@gtk.org> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * EMeetingTimeSelectorItem - A GnomeCanvasItem which is used for both the main - * display canvas and the top display (with the dates, times & All Attendees). - * I didn't make these separate GnomeCanvasItems since they share a lot of - * code. - */ - -#include <config.h> -#include <time.h> -#include "e-meeting-time-sel-item.h" -#include "e-meeting-time-sel.h" - -/* Initially the grid lines were drawn at the bottom of cells, but this didn't - line up well with the GtkEntry widgets, which in the default theme draw a - black shadow line across the top. So I've switched our code to draw the - lines across the top of cells. */ -#define E_MEETING_TIME_SELECTOR_DRAW_GRID_LINES_AT_BOTTOM 0 - -static void e_meeting_time_selector_item_class_init (EMeetingTimeSelectorItemClass *mts_item_class); -static void e_meeting_time_selector_item_init (EMeetingTimeSelectorItem *mts_item); -static void e_meeting_time_selector_item_destroy (GtkObject *object); - -static void e_meeting_time_selector_item_set_arg (GtkObject *o, GtkArg *arg, - guint arg_id); -static void e_meeting_time_selector_item_realize (GnomeCanvasItem *item); -static void e_meeting_time_selector_item_unrealize (GnomeCanvasItem *item); -static void e_meeting_time_selector_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, int flags); -static void e_meeting_time_selector_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - int x, int y, - int width, int height); -static double e_meeting_time_selector_item_point (GnomeCanvasItem *item, - double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item); -static gint e_meeting_time_selector_item_event (GnomeCanvasItem *item, - GdkEvent *event); -static gint e_meeting_time_selector_item_button_press (EMeetingTimeSelectorItem *mts_item, - GdkEvent *event); -static gint e_meeting_time_selector_item_button_release (EMeetingTimeSelectorItem *mts_item, - GdkEvent *event); -static gint e_meeting_time_selector_item_motion_notify (EMeetingTimeSelectorItem *mts_item, - GdkEvent *event); - -static void e_meeting_time_selector_item_paint_day_top (EMeetingTimeSelectorItem *mts_item, - GdkDrawable *drawable, - GDate *date, - int x, int scroll_y, - int width, int height); -static void e_meeting_time_selector_item_paint_all_attendees_busy_periods (EMeetingTimeSelectorItem *mts_item, GdkDrawable *drawable, GDate *date, int x, int y, int width, int height); -static void e_meeting_time_selector_item_paint_day (EMeetingTimeSelectorItem *mts_item, - GdkDrawable *drawable, - GDate *date, - int x, int scroll_y, - int width, int height); -static void e_meeting_time_selector_item_paint_busy_periods (EMeetingTimeSelectorItem *mts_item, GdkDrawable *drawable, GDate *date, int x, int scroll_y, int width, int height); -static gint e_meeting_time_selector_item_find_first_busy_period (EMeetingTimeSelectorItem *mts_item, GDate *date, gint row); -static void e_meeting_time_selector_item_paint_attendee_busy_periods (EMeetingTimeSelectorItem *mts_item, GdkDrawable *drawable, int row, int x, int y, int width, int first_period, EMeetingTimeSelectorBusyType busy_type); - -static EMeetingTimeSelectorPosition e_meeting_time_selector_item_get_drag_position (EMeetingTimeSelectorItem *mts_item, gint x, gint y); -static gboolean e_meeting_time_selector_item_calculate_busy_range (EMeetingTimeSelector *mts, - gint row, - gint x, - gint width, - gint *start_x, - gint *end_x); - -static GnomeCanvasItemClass *parent_class; - -/* The arguments we take */ -enum { - ARG_0, - ARG_MEETING_TIME_SELECTOR -}; - - -GtkType -e_meeting_time_selector_item_get_type (void) -{ - static GtkType e_meeting_time_selector_item_type = 0; - - if (!e_meeting_time_selector_item_type) { - GtkTypeInfo e_meeting_time_selector_item_info = { - "EMeetingTimeSelectorItem", - sizeof (EMeetingTimeSelectorItem), - sizeof (EMeetingTimeSelectorItemClass), - (GtkClassInitFunc) e_meeting_time_selector_item_class_init, - (GtkObjectInitFunc) e_meeting_time_selector_item_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - e_meeting_time_selector_item_type = gtk_type_unique (gnome_canvas_item_get_type (), &e_meeting_time_selector_item_info); - } - - return e_meeting_time_selector_item_type; -} - - -static void -e_meeting_time_selector_item_class_init (EMeetingTimeSelectorItemClass *mts_item_class) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - parent_class = gtk_type_class (gnome_canvas_item_get_type()); - - object_class = (GtkObjectClass *) mts_item_class; - item_class = (GnomeCanvasItemClass *) mts_item_class; - - gtk_object_add_arg_type ("EMeetingTimeSelectorItem::meeting_time_selector", - GTK_TYPE_POINTER, GTK_ARG_WRITABLE, - ARG_MEETING_TIME_SELECTOR); - - object_class->destroy = e_meeting_time_selector_item_destroy; - object_class->set_arg = e_meeting_time_selector_item_set_arg; - - /* GnomeCanvasItem method overrides */ - item_class->realize = e_meeting_time_selector_item_realize; - item_class->unrealize = e_meeting_time_selector_item_unrealize; - item_class->update = e_meeting_time_selector_item_update; - item_class->draw = e_meeting_time_selector_item_draw; - item_class->point = e_meeting_time_selector_item_point; - item_class->event = e_meeting_time_selector_item_event; -} - - -static void -e_meeting_time_selector_item_init (EMeetingTimeSelectorItem *mts_item) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (mts_item); - - mts_item->mts = NULL; - - mts_item->main_gc = NULL; - mts_item->stipple_gc = NULL; - - /* Create the cursors. */ - mts_item->normal_cursor = gdk_cursor_new (GDK_TOP_LEFT_ARROW); - mts_item->resize_cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW); - mts_item->last_cursor_set = NULL; - - item->x1 = 0; - item->y1 = 0; - item->x2 = 0; - item->y2 = 0; -} - - -static void -e_meeting_time_selector_item_destroy (GtkObject *object) -{ - EMeetingTimeSelectorItem *mts_item; - - mts_item = E_MEETING_TIME_SELECTOR_ITEM (object); - - gdk_cursor_destroy (mts_item->normal_cursor); - gdk_cursor_destroy (mts_item->resize_cursor); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (*GTK_OBJECT_CLASS (parent_class)->destroy)(object); -} - - -static void -e_meeting_time_selector_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EMeetingTimeSelectorItem *mts_item; - - item = GNOME_CANVAS_ITEM (o); - mts_item = E_MEETING_TIME_SELECTOR_ITEM (o); - - switch (arg_id){ - case ARG_MEETING_TIME_SELECTOR: - mts_item->mts = GTK_VALUE_POINTER (*arg); - break; - } -} - - -static void -e_meeting_time_selector_item_realize (GnomeCanvasItem *item) -{ - GnomeCanvas *canvas; - GdkWindow *window; - EMeetingTimeSelectorItem *mts_item; - - if (GNOME_CANVAS_ITEM_CLASS (parent_class)->realize) - (*GNOME_CANVAS_ITEM_CLASS (parent_class)->realize)(item); - - mts_item = E_MEETING_TIME_SELECTOR_ITEM (item); - - canvas = item->canvas; - window = GTK_WIDGET (canvas)->window; - - mts_item->main_gc = gdk_gc_new (window); - mts_item->stipple_gc = gdk_gc_new (window); -} - - -static void -e_meeting_time_selector_item_unrealize (GnomeCanvasItem *item) -{ - EMeetingTimeSelectorItem *mts_item; - - mts_item = E_MEETING_TIME_SELECTOR_ITEM (item); - - gdk_gc_unref (mts_item->main_gc); - mts_item->main_gc = NULL; - gdk_gc_unref (mts_item->stipple_gc); - mts_item->stipple_gc = NULL; - - if (GNOME_CANVAS_ITEM_CLASS (parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (parent_class)->unrealize)(item); -} - - -static void -e_meeting_time_selector_item_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - if (GNOME_CANVAS_ITEM_CLASS (parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (parent_class)->update) (item, affine, clip_path, flags); - - /* The grid covers the entire canvas area. */ - item->x1 = 0; - item->y1 = 0; - item->x2 = INT_MAX; - item->y2 = INT_MAX; -} - - -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ - -static void -e_meeting_time_selector_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorItem *mts_item; - EMeetingTimeSelectorAttendee *attendee; - gint day_x, meeting_start_x, meeting_end_x, bar_y, bar_height; - gint row, row_y, start_x, end_x; - GDate date, last_date, current_date; - gboolean is_display_top, show_meeting_time; - GdkGC *gc, *stipple_gc; - - mts_item = E_MEETING_TIME_SELECTOR_ITEM (item); - mts = mts_item->mts; - g_return_if_fail (mts != NULL); - gc = mts_item->main_gc; - stipple_gc = mts_item->stipple_gc; - - is_display_top = (GTK_WIDGET (item->canvas) == mts->display_top) - ? TRUE : FALSE; - - /* Calculate the first and last visible days and positions. */ - e_meeting_time_selector_calculate_day_and_position (mts, x, - &date, &day_x); - e_meeting_time_selector_calculate_day_and_position (mts, x + width, - &last_date, NULL); - - /* For the top display draw the 'All Attendees' row background. */ - if (is_display_top) { - gdk_gc_set_foreground (gc, &mts->all_attendees_bg_color); - gdk_draw_rectangle (drawable, gc, TRUE, - 0, mts->row_height * 2 - y, - width, mts->row_height); - } else { - gdk_gc_set_foreground (gc, &mts->bg_color); - gdk_draw_rectangle (drawable, gc, TRUE, 0, 0, width, height); - } - - /* Calculate the x coordinates of the meeting time. */ - show_meeting_time = e_meeting_time_selector_get_meeting_time_positions (mts, &meeting_start_x, &meeting_end_x); - - /* Draw the meeting time background. */ - if (show_meeting_time - && (meeting_end_x - 1 >= x) && (meeting_start_x + 1 < x + width) - && (meeting_end_x - meeting_start_x > 2)) { - gdk_gc_set_foreground (gc, &mts->meeting_time_bg_color); - if (is_display_top) - gdk_draw_rectangle (drawable, gc, TRUE, - meeting_start_x + 1 - x, mts->row_height * 2 - y, - meeting_end_x - meeting_start_x - 2, mts->row_height); - else - gdk_draw_rectangle (drawable, gc, TRUE, - meeting_start_x + 1 - x, 0, - meeting_end_x - meeting_start_x - 2, height); - } - - /* For the main display draw the stipple background for attendee's - that have no calendar information. */ - if (!is_display_top) { - gdk_gc_set_foreground (gc, &mts->grid_color); - gdk_gc_set_foreground (stipple_gc, &mts->grid_color); - gdk_gc_set_background (stipple_gc, &mts->stipple_bg_color); - gdk_gc_set_stipple (stipple_gc, mts->stipple); - gnome_canvas_set_stipple_origin (item->canvas, stipple_gc); - gdk_gc_set_fill (stipple_gc, GDK_OPAQUE_STIPPLED); - row = y / mts->row_height; - row_y = row * mts->row_height - y; - while (row < mts->attendees->len && row_y < height) { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - if (attendee->has_calendar_info) { - if (e_meeting_time_selector_item_calculate_busy_range (mts, row, x, width, &start_x, &end_x)) { - if (start_x >= width || end_x <= 0) { - gdk_draw_rectangle (drawable, stipple_gc, TRUE, 0, row_y, width, mts->row_height); - } else { - if (start_x >= 0) { - gdk_draw_rectangle (drawable, stipple_gc, TRUE, 0, row_y, start_x, mts->row_height); - gdk_draw_line (drawable, gc, start_x, row_y, start_x, row_y + mts->row_height); - } - if (end_x <= width) { - gdk_draw_rectangle (drawable, stipple_gc, TRUE, end_x, row_y, width - end_x, mts->row_height); - gdk_draw_line (drawable, gc, end_x, row_y, end_x, row_y + mts->row_height); - } - } - } - } else { - gdk_draw_rectangle (drawable, stipple_gc, TRUE, - 0, row_y, - width, mts->row_height); - } - row++; - row_y += mts->row_height; - } - gdk_gc_set_fill (gc, GDK_SOLID); - } - - /* Now paint the visible days one by one. */ - current_date = date; - for (;;) { - /* Currently we use the same GnomeCanvasItem class for the - top display and the main display. We may use separate - classes in future if necessary. */ - if (is_display_top) - e_meeting_time_selector_item_paint_day_top (mts_item, drawable, ¤t_date, day_x, y, width, height); - else - e_meeting_time_selector_item_paint_day (mts_item, drawable, ¤t_date, day_x, y, width, height); - - day_x += mts_item->mts->day_width; - if (g_date_compare (¤t_date, &last_date) == 0) - break; - g_date_add_days (¤t_date, 1); - } - - /* Draw the busy periods. */ - if (is_display_top) - e_meeting_time_selector_item_paint_all_attendees_busy_periods (mts_item, drawable, &date, x, y, width, height); - else - e_meeting_time_selector_item_paint_busy_periods (mts_item, drawable, &date, x, y, width, height); - - - /* Draw the currently-selected meeting time vertical bars. */ - if (show_meeting_time) { - if (is_display_top) { - bar_y = mts->row_height * 2 - y; - bar_height = mts->row_height; - } else { - bar_y = 0; - bar_height = height; - } - - gdk_gc_set_foreground (gc, &mts->grid_color); - - if ((meeting_start_x + 2 >= x) - && (meeting_start_x - 2 < x + width)) { - gdk_draw_rectangle (drawable, gc, TRUE, - meeting_start_x - 2 - x, bar_y, - 5, bar_height); - } - - if ((meeting_end_x + 2 >= x) - && (meeting_end_x - 2 < x + width)) { - gdk_draw_rectangle (drawable, gc, TRUE, - meeting_end_x - 2 - x, bar_y, - 5, bar_height); - } - } -} - - -static void -e_meeting_time_selector_item_paint_day_top (EMeetingTimeSelectorItem *mts_item, - GdkDrawable *drawable, GDate *date, - int x, int scroll_y, - int width, int height) -{ - EMeetingTimeSelector *mts; - GdkGC *gc; - GdkFont *font; - gint y, grid_x; - gchar buffer[128]; - gint hour, hour_x, hour_y; - GdkRectangle clip_rect; - - mts = mts_item->mts; - gc = mts_item->main_gc; - - gdk_gc_set_foreground (gc, &mts->grid_color); - - /* Draw the horizontal lines. */ - y = mts->row_height - 1 - scroll_y; - gdk_draw_line (drawable, gc, x, y, x + mts->day_width - 1, y); - gdk_gc_set_foreground (gc, &mts->grid_shadow_color); - gdk_draw_line (drawable, gc, x, y + 1, x + mts->day_width - 1, y + 1); - gdk_gc_set_foreground (gc, &mts->grid_color); - y += mts->row_height; - gdk_draw_line (drawable, gc, x, y, x + mts->day_width - 1, y); - y += mts->row_height; - gdk_draw_line (drawable, gc, x, y, x + mts->day_width - 1, y); - - - /* Draw the vertical grid lines. */ - for (grid_x = mts->col_width - 1; - grid_x < mts->day_width - mts->col_width; - grid_x += mts->col_width) { - gdk_draw_line (drawable, gc, - x + grid_x, mts->row_height * 2 - 4 - scroll_y, - x + grid_x, height); - } - grid_x = mts->day_width - 2; - gdk_draw_line (drawable, gc, x + grid_x, 0, x + grid_x, height); - grid_x++; - gdk_draw_line (drawable, gc, x + grid_x, 0, x + grid_x, height); - - /* Draw the date. Set a clipping rectangle so we don't draw over the - next day. */ - font = GTK_WIDGET (mts)->style->font; - if (mts->date_format == E_MEETING_TIME_SELECTOR_DATE_FULL) - g_date_strftime (buffer, 128, "%A, %B %d, %Y", date); - else if (mts->date_format == E_MEETING_TIME_SELECTOR_DATE_ABBREVIATED_DAY) - g_date_strftime (buffer, 128, "%a %x", date); - else - g_date_strftime (buffer, 128, "%x", date); - clip_rect.x = x; - clip_rect.y = -scroll_y; - clip_rect.width = mts->day_width - 2; - clip_rect.height = mts->row_height - 2; - gdk_gc_set_clip_rectangle (gc, &clip_rect); - gdk_draw_string (drawable, font, gc, - x + 4, 4 + font->ascent - scroll_y, buffer); - gdk_gc_set_clip_rectangle (gc, NULL); - - /* Draw the hours. */ - hour = mts->first_hour_shown + (mts->zoomed_out ? 3 : 1); - hour_x = x + mts->col_width; - hour_y = mts->row_height + 4 + font->ascent - scroll_y; - while (hour < mts->last_hour_shown) { - gdk_draw_string (drawable, font, gc, - hour_x - (mts->hour_widths[hour] / 2), - hour_y, EMeetingTimeSelectorHours[hour]); - - hour += mts->zoomed_out ? 3 : 1; - hour_x += mts->col_width; - } -} - - -/* This paints the colored bars representing busy periods for the combined - list of attendees. For now we just paint the bars for each attendee of - each other. If we want to speed it up we could optimise it later. */ -static void -e_meeting_time_selector_item_paint_all_attendees_busy_periods (EMeetingTimeSelectorItem *mts_item, GdkDrawable *drawable, GDate *date, int x, int scroll_y, int width, int height) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorBusyType busy_type; - gint row, y; - GdkGC *gc; - gint *first_periods; - - mts = mts_item->mts; - gc = mts_item->main_gc; - - /* Calculate the y coordinate to paint the row at in the drawable. */ - y = 2 * mts->row_height - scroll_y - 1; - - /* Get the first visible busy periods for all the attendees. */ - first_periods = g_new (gint, mts->attendees->len); - for (row = 0; row < mts->attendees->len; row++) { - first_periods[row] = e_meeting_time_selector_item_find_first_busy_period (mts_item, date, row); - } - - for (busy_type = 0; - busy_type < E_MEETING_TIME_SELECTOR_BUSY_LAST; - busy_type++) { - gdk_gc_set_foreground (gc, &mts->busy_colors[busy_type]); - for (row = 0; row < mts->attendees->len; row++) { - if (first_periods[row] == -1) - continue; - e_meeting_time_selector_item_paint_attendee_busy_periods (mts_item, drawable, x, y, width, row, first_periods[row], busy_type); - } - } - - g_free (first_periods); -} - - -static void -e_meeting_time_selector_item_paint_day (EMeetingTimeSelectorItem *mts_item, - GdkDrawable *drawable, GDate *date, - int x, int scroll_y, - int width, int height) -{ - EMeetingTimeSelector *mts; - GdkGC *gc; - gint grid_x, grid_y, attendee_index, unused_y; - - mts = mts_item->mts; - gc = mts_item->main_gc; - - /* Draw the grid lines. The grid lines around unused rows are drawn in - a different color. */ - - /* Draw the horizontal grid lines. */ - attendee_index = scroll_y / mts->row_height; -#if E_MEETING_TIME_SELECTOR_DRAW_GRID_LINES_AT_BOTTOM - for (grid_y = mts->row_height - 1 - (scroll_y % mts->row_height); -#else - for (grid_y = - (scroll_y % mts->row_height); -#endif - grid_y < height; - grid_y += mts->row_height) - { - if (attendee_index <= mts->attendees->len) { - gdk_gc_set_foreground (gc, &mts->grid_color); - gdk_draw_line (drawable, gc, 0, grid_y, - width, grid_y); - } else { - gdk_gc_set_foreground (gc, &mts->grid_unused_color); - gdk_draw_line (drawable, gc, 0, grid_y, - width, grid_y); - } - attendee_index++; - } - - /* Draw the vertical grid lines. */ - unused_y = (mts->attendees->len * mts->row_height) - scroll_y; - if (unused_y >= 0) { - gdk_gc_set_foreground (gc, &mts->grid_color); - for (grid_x = mts->col_width - 1; - grid_x < mts->day_width - mts->col_width; - grid_x += mts->col_width) - { - gdk_draw_line (drawable, gc, - x + grid_x, 0, - x + grid_x, unused_y - 1); - } - gdk_draw_rectangle (drawable, gc, TRUE, - x + mts->day_width - 2, 0, - 2, unused_y); - } - - if (unused_y < height) { - gdk_gc_set_foreground (gc, &mts->grid_unused_color); - for (grid_x = mts->col_width - 1; - grid_x < mts->day_width - mts->col_width; - grid_x += mts->col_width) - { - gdk_draw_line (drawable, gc, - x + grid_x, unused_y, - x + grid_x, height); - } - gdk_draw_rectangle (drawable, gc, TRUE, - x + mts->day_width - 2, unused_y, - 2, height - unused_y); - } - - -} - - -/* This paints the colored bars representing busy periods for the individual - attendees. */ -static void -e_meeting_time_selector_item_paint_busy_periods (EMeetingTimeSelectorItem *mts_item, GdkDrawable *drawable, GDate *date, int x, int scroll_y, int width, int height) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorBusyType busy_type; - gint row, y, first_period; - GdkGC *gc; - - mts = mts_item->mts; - gc = mts_item->main_gc; - - /* Calculate the first visible attendee row. */ - row = scroll_y / mts->row_height; - - /* Calculate the y coordinate to paint the row at in the drawable. */ - y = row * mts->row_height - scroll_y; - - /* Step through the attendees painting the busy periods. */ - while (y < height && row < mts->attendees->len) { - - /* Find the first visible busy period. */ - first_period = e_meeting_time_selector_item_find_first_busy_period (mts_item, date, row); - if (first_period != -1) { - /* Paint the different types of busy periods, in - reverse order of precedence, so the highest - precedences are displayed. */ - for (busy_type = 0; - busy_type < E_MEETING_TIME_SELECTOR_BUSY_LAST; - busy_type++) { - gdk_gc_set_foreground (gc, &mts->busy_colors[busy_type]); - e_meeting_time_selector_item_paint_attendee_busy_periods (mts_item, drawable, x, y, width, row, first_period, busy_type); - } - } - y += mts->row_height; - row++; - } -} - - -/* This subtracts the attendees longest_period_in_days from the given date, - and does a binary search of the attendee's busy periods array to find the - first one which could possible end on the given day or later. - If none are found it returns -1. */ -static gint -e_meeting_time_selector_item_find_first_busy_period (EMeetingTimeSelectorItem *mts_item, GDate *date, gint row) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorAttendee *attendee; - EMeetingTimeSelectorPeriod *period; - gint period_num; - - mts = mts_item->mts; - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - - period_num = e_meeting_time_selector_find_first_busy_period (mts, attendee, date); - if (period_num == -1) - return -1; - - /* Check if the period starts after the end of the current canvas - scroll area. */ - period = &g_array_index (attendee->busy_periods, - EMeetingTimeSelectorPeriod, period_num); - if (g_date_compare (&mts->last_date_shown, &period->start.date) < 0) - return -1; - - return period_num; -} - - -/* This paints the visible busy periods for one attendee which are of a certain - busy type, e.g out of office. It is passed the index of the first visible - busy period of the attendee and continues until it runs off the screen. */ -static void -e_meeting_time_selector_item_paint_attendee_busy_periods (EMeetingTimeSelectorItem *mts_item, GdkDrawable *drawable, int x, int y, int width, int row, int first_period, EMeetingTimeSelectorBusyType busy_type) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorAttendee *attendee; - EMeetingTimeSelectorPeriod *period; - GdkGC *gc; - gint period_num, x1, x2, x2_within_day, x2_within_col; - - mts = mts_item->mts; - gc = mts_item->main_gc; - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - - for (period_num = first_period; - period_num < attendee->busy_periods->len; - period_num++) { - period = &g_array_index (attendee->busy_periods, - EMeetingTimeSelectorPeriod, period_num); - - if (period->busy_type != busy_type) - continue; - - /* Convert the period start and end times to x coordinates. */ - x1 = e_meeting_time_selector_calculate_time_position (mts, &period->start); - /* If the period is off the right of the area being drawn, we - are finished. */ - if (x1 >= x + width) - return; - - x2 = e_meeting_time_selector_calculate_time_position (mts, &period->end); - /* If the period is off the left edge of the area skip it. */ - if (x2 <= x) - continue; - - /* We paint from x1 to x2 - 1, so that for example a time - from 5:00-6:00 is distinct from 6:00-7:00. - We never finish on a grid line separating days, and we only - ever paint on a normal vertical grid line if the period is - only 1 pixel wide. */ - x2_within_day = x2 % mts->day_width; - if (x2_within_day == 0) { - x2 -= 2; - } else if (x2_within_day == mts->day_width - 1) { - x2 -= 1; - } else { - x2_within_col = x2_within_day % mts->col_width; - if (x2_within_col == 0 && x2 > x1 + 1) - x2 -= 1; - } - - /* Paint the rectangle. We leave a gap of 2 pixels at the - top and bottom, remembering that the grid is painted along - the top/bottom line of each row. */ - if (x2 - x1 > 0) { -#if E_MEETING_TIME_SELECTOR_DRAW_GRID_LINES_AT_BOTTOM - gdk_draw_rectangle (drawable, gc, TRUE, - x1 - x, y + 2, - x2 - x1, mts->row_height - 5); -#else - gdk_draw_rectangle (drawable, gc, TRUE, - x1 - x, y + 3, - x2 - x1, mts->row_height - 5); -#endif - } - } -} - - -/* - * CANVAS ITEM ROUTINES - functions to be a GnomeCanvasItem. - */ - -/* This is supposed to return the nearest item the the point and the distance. - Since we are the only item we just return ourself and 0 for the distance. - This is needed so that we get button/motion events. */ -static double -e_meeting_time_selector_item_point (GnomeCanvasItem *item, double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - - -static gint -e_meeting_time_selector_item_event (GnomeCanvasItem *item, GdkEvent *event) -{ - EMeetingTimeSelectorItem *mts_item; - - mts_item = E_MEETING_TIME_SELECTOR_ITEM (item); - - switch (event->type) { - case GDK_BUTTON_PRESS: - return e_meeting_time_selector_item_button_press (mts_item, - event); - case GDK_BUTTON_RELEASE: - return e_meeting_time_selector_item_button_release (mts_item, - event); - case GDK_MOTION_NOTIFY: - return e_meeting_time_selector_item_motion_notify (mts_item, - event); - default: - break; - } - - return FALSE; -} - - -/* This handles all button press events for the item. If the cursor is over - one of the meeting time vertical bars we start a drag. If not we set the - meeting time to the nearest half-hour interval. - Note that GnomeCanvas converts the event coords to world coords, - i.e. relative to the entire canvas scroll area. */ -static gint -e_meeting_time_selector_item_button_press (EMeetingTimeSelectorItem *mts_item, - GdkEvent *event) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorTime start_time, end_time; - EMeetingTimeSelectorPosition position; - GDate *start_date, *end_date; - gint x, y; - - mts = mts_item->mts; - x = (gint) event->button.x; - y = (gint) event->button.y; - - /* Check if we are starting a drag of the vertical meeting time bars.*/ - position = e_meeting_time_selector_item_get_drag_position (mts_item, - x, y); - if (position != E_MEETING_TIME_SELECTOR_POS_NONE) { - if (gnome_canvas_item_grab (GNOME_CANVAS_ITEM (mts_item), - GDK_POINTER_MOTION_MASK - | GDK_BUTTON_RELEASE_MASK, - mts_item->resize_cursor, - event->button.time) == 0 /*Success*/) { - mts->dragging_position = position; - return TRUE; - } - } - - /* Convert the x coordinate into a EMeetingTimeSelectorTime. */ - e_meeting_time_selector_calculate_time (mts, x, &start_time); - start_date = &start_time.date; - end_date = &end_time.date; - - /* Find the nearest half-hour or hour interval, depending on whether - zoomed_out is set. */ - if (mts->zoomed_out) { - start_time.minute = 0; - end_time = start_time; - end_time.hour += 1; - } else { - start_time.minute -= start_time.minute % 30; - end_time = start_time; - end_time.minute += 30; - } - - /* Fix any overflows. */ - e_meeting_time_selector_fix_time_overflows (&end_time); - - /* Set the new meeting time. */ - e_meeting_time_selector_set_meeting_time (mts_item->mts, - g_date_year (start_date), - g_date_month (start_date), - g_date_day (start_date), - start_time.hour, - start_time.minute, - g_date_year (end_date), - g_date_month (end_date), - g_date_day (end_date), - end_time.hour, - end_time.minute); - - - return FALSE; -} - - -/* This handles all button release events for the item. If we were dragging, - we finish the drag. */ -static gint -e_meeting_time_selector_item_button_release (EMeetingTimeSelectorItem *mts_item, - GdkEvent *event) -{ - EMeetingTimeSelector *mts; - - mts = mts_item->mts; - - /* Reset any drag. */ - if (mts->dragging_position != E_MEETING_TIME_SELECTOR_POS_NONE) { - mts->dragging_position = E_MEETING_TIME_SELECTOR_POS_NONE; - e_meeting_time_selector_remove_timeout (mts); - gnome_canvas_item_ungrab (GNOME_CANVAS_ITEM (mts_item), - event->button.time); - } - - return FALSE; -} - - -/* This handles all motion notify events for the item. If button1 is pressed - we check if a drag is in progress. If not, we set the cursor if we are over - the meeting time vertical bars. Note that GnomeCanvas doesn't use motion - hints, which may affect performance. */ -static gint -e_meeting_time_selector_item_motion_notify (EMeetingTimeSelectorItem *mts_item, - GdkEvent *event) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorPosition position; - GdkCursor *cursor; - gint x, y; - - mts = mts_item->mts; - x = (gint) event->motion.x; - y = (gint) event->motion.y; - - if (mts->dragging_position != E_MEETING_TIME_SELECTOR_POS_NONE) { - e_meeting_time_selector_drag_meeting_time (mts, x); - return TRUE; - } - - position = e_meeting_time_selector_item_get_drag_position (mts_item, - x, y); - - /* Determine which cursor should be used. */ - if (position == E_MEETING_TIME_SELECTOR_POS_NONE) - cursor = mts_item->normal_cursor; - else - cursor = mts_item->resize_cursor; - - /* Only set the cursor if it is different to the last one we set. */ - if (mts_item->last_cursor_set != cursor) { - mts_item->last_cursor_set = cursor; - gdk_window_set_cursor (GTK_WIDGET (GNOME_CANVAS_ITEM (mts_item)->canvas)->window, cursor); - } - - return FALSE; -} - - -static EMeetingTimeSelectorPosition -e_meeting_time_selector_item_get_drag_position (EMeetingTimeSelectorItem *mts_item, - gint x, gint y) -{ - EMeetingTimeSelector *mts; - gboolean is_display_top; - gint meeting_start_x, meeting_end_x; - - mts = mts_item->mts; - - is_display_top = (GTK_WIDGET (GNOME_CANVAS_ITEM (mts_item)->canvas) == mts->display_top) ? TRUE : FALSE; - - if (is_display_top && y < mts->row_height * 2) - return E_MEETING_TIME_SELECTOR_POS_NONE; - - if (!e_meeting_time_selector_get_meeting_time_positions (mts, &meeting_start_x, &meeting_end_x)) - return E_MEETING_TIME_SELECTOR_POS_NONE; - - if (x >= meeting_end_x - 2 && x <= meeting_end_x + 2) - return E_MEETING_TIME_SELECTOR_POS_END; - - if (x >= meeting_start_x - 2 && x <= meeting_start_x + 2) - return E_MEETING_TIME_SELECTOR_POS_START; - - return E_MEETING_TIME_SELECTOR_POS_NONE; -} - - -static gboolean -e_meeting_time_selector_item_calculate_busy_range (EMeetingTimeSelector *mts, - gint row, - gint x, - gint width, - gint *start_x, - gint *end_x) -{ - EMeetingTimeSelectorAttendee *attendee; - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - - *start_x = -1; - *end_x = -1; - - if (!g_date_valid (&attendee->busy_periods_start.date) - || !g_date_valid (&attendee->busy_periods_end.date)) - return FALSE; - - *start_x = e_meeting_time_selector_calculate_time_position (mts, &attendee->busy_periods_start) - x - 1; - - *end_x = e_meeting_time_selector_calculate_time_position (mts, &attendee->busy_periods_end) - x; - - return TRUE; -} diff --git a/widgets/meeting-time-sel/e-meeting-time-sel-item.h b/widgets/meeting-time-sel/e-meeting-time-sel-item.h deleted file mode 100644 index d9fe6c6a9b..0000000000 --- a/widgets/meeting-time-sel/e-meeting-time-sel-item.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@gtk.org> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * MeetingTimeSelectorItem - A GnomeCanvasItem which is used for both the main - * display canvas and the top display (with the dates, times & All Attendees). - * I didn't make these separate GnomeCanvasItems since they share a lot of - * code. - */ - -#ifndef _E_MEETING_TIME_SELECTOR_ITEM_H_ -#define _E_MEETING_TIME_SELECTOR_ITEM_H_ - -#include "e-meeting-time-sel.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define E_MEETING_TIME_SELECTOR_ITEM(obj) (GTK_CHECK_CAST((obj), e_meeting_time_selector_item_get_type (), EMeetingTimeSelectorItem)) -#define E_MEETING_TIME_SELECTOR_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), e_meeting_time_selector_item_get_type (), EMeetingTimeSelectorItemClass)) -#define IS_E_MEETING_TIME_SELECTOR_ITEM(o) (GTK_CHECK_TYPE((o), e_meeting_time_selector_item_get_type ())) - - -typedef struct _EMeetingTimeSelectorItem EMeetingTimeSelectorItem; -typedef struct _EMeetingTimeSelectorItemClass EMeetingTimeSelectorItemClass; - -struct _EMeetingTimeSelectorItem -{ - GnomeCanvasItem canvas_item; - - /* The parent EMeetingTimeSelector widget. */ - EMeetingTimeSelector *mts; - - /* This GC is used for most of the drawing. The fg/bg colors are - changed for each bit. */ - GdkGC *main_gc; - GdkGC *stipple_gc; - - /* The normal & resize cursors. */ - GdkCursor *normal_cursor; - GdkCursor *resize_cursor; - - /* This remembers the last cursor set on the window. */ - GdkCursor *last_cursor_set; -}; - - -struct _EMeetingTimeSelectorItemClass -{ - GnomeCanvasItemClass parent_class; -}; - -GtkType e_meeting_time_selector_item_get_type (void); - - -#endif /* _E_MEETING_TIME_SELECTOR_ITEM_H_ */ diff --git a/widgets/meeting-time-sel/e-meeting-time-sel-list-item.c b/widgets/meeting-time-sel/e-meeting-time-sel-list-item.c deleted file mode 100644 index 0c6d5427d5..0000000000 --- a/widgets/meeting-time-sel/e-meeting-time-sel-list-item.c +++ /dev/null @@ -1,393 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@gtk.org> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * EMeetingTimeSelectorListItem - A GnomeCanvasItem covering the entire attendee - * list. It just draws the grid lines between the rows and after the icon - * column. - */ - -#include <config.h> -#include <time.h> -#include "../../e-util/e-canvas.h" -#include "e-meeting-time-sel-list-item.h" -#include "e-meeting-time-sel.h" - -/* This is the size of our icons. */ -#define E_MEETING_TIME_SELECTOR_ICON_WIDTH 19 -#define E_MEETING_TIME_SELECTOR_ICON_HEIGHT 16 - -#include "e-meeting-time-sel-mail.xpm" -#include "e-meeting-time-sel-no-mail.xpm" - -static void e_meeting_time_selector_list_item_class_init (EMeetingTimeSelectorListItemClass *mtsl_item_class); -static void e_meeting_time_selector_list_item_init (EMeetingTimeSelectorListItem *mtsl_item); -static void e_meeting_time_selector_list_item_destroy (GtkObject *object); - -static void e_meeting_time_selector_list_item_set_arg (GtkObject *o, GtkArg *arg, - guint arg_id); -static void e_meeting_time_selector_list_item_realize (GnomeCanvasItem *item); -static void e_meeting_time_selector_list_item_unrealize (GnomeCanvasItem *item); -static void e_meeting_time_selector_list_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, int flags); -static void e_meeting_time_selector_list_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - int x, int y, - int width, int height); -static double e_meeting_time_selector_list_item_point (GnomeCanvasItem *item, - double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item); -static gint e_meeting_time_selector_list_item_event (GnomeCanvasItem *item, - GdkEvent *event); -static gboolean e_meeting_time_selector_list_item_button_press (EMeetingTimeSelectorListItem *mtsl_item, - GdkEvent *event); - - -static GnomeCanvasItemClass *e_meeting_time_selector_list_item_parent_class; - -/* The arguments we take */ -enum { - ARG_0, - ARG_MEETING_TIME_SELECTOR -}; - - -GtkType -e_meeting_time_selector_list_item_get_type (void) -{ - static GtkType e_meeting_time_selector_list_item_type = 0; - - if (!e_meeting_time_selector_list_item_type) { - GtkTypeInfo e_meeting_time_selector_list_item_info = { - "EMeetingTimeSelectorListItem", - sizeof (EMeetingTimeSelectorListItem), - sizeof (EMeetingTimeSelectorListItemClass), - (GtkClassInitFunc) e_meeting_time_selector_list_item_class_init, - (GtkObjectInitFunc) e_meeting_time_selector_list_item_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - e_meeting_time_selector_list_item_type = gtk_type_unique (gnome_canvas_item_get_type (), &e_meeting_time_selector_list_item_info); - } - - return e_meeting_time_selector_list_item_type; -} - - -static void -e_meeting_time_selector_list_item_class_init (EMeetingTimeSelectorListItemClass *mtsl_item_class) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - e_meeting_time_selector_list_item_parent_class = gtk_type_class (gnome_canvas_item_get_type()); - - object_class = (GtkObjectClass *) mtsl_item_class; - item_class = (GnomeCanvasItemClass *) mtsl_item_class; - - gtk_object_add_arg_type ("EMeetingTimeSelectorListItem::meeting_time_selector", - GTK_TYPE_POINTER, GTK_ARG_WRITABLE, - ARG_MEETING_TIME_SELECTOR); - - object_class->destroy = e_meeting_time_selector_list_item_destroy; - object_class->set_arg = e_meeting_time_selector_list_item_set_arg; - - /* GnomeCanvasItem method overrides */ - item_class->realize = e_meeting_time_selector_list_item_realize; - item_class->unrealize = e_meeting_time_selector_list_item_unrealize; - item_class->update = e_meeting_time_selector_list_item_update; - item_class->draw = e_meeting_time_selector_list_item_draw; - item_class->point = e_meeting_time_selector_list_item_point; - item_class->event = e_meeting_time_selector_list_item_event; -} - - -static void -e_meeting_time_selector_list_item_init (EMeetingTimeSelectorListItem *mtsl_item) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (mtsl_item); - GdkColormap *colormap; - - mtsl_item->mts = NULL; - - colormap = gtk_widget_get_default_colormap (); - mtsl_item->mail_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mtsl_item->mail_icon_mask, NULL, e_meeting_time_sel_mail_xpm); - mtsl_item->no_mail_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &mtsl_item->no_mail_icon_mask, NULL, e_meeting_time_sel_no_mail_xpm); - - item->x1 = 0; - item->y1 = 0; - item->x2 = 0; - item->y2 = 0; -} - - -static void -e_meeting_time_selector_list_item_destroy (GtkObject *object) -{ - EMeetingTimeSelectorListItem *mtsl_item; - - mtsl_item = E_MEETING_TIME_SELECTOR_LIST_ITEM (object); - - gdk_pixmap_unref (mtsl_item->mail_icon); - gdk_pixmap_unref (mtsl_item->no_mail_icon); - gdk_bitmap_unref (mtsl_item->mail_icon_mask); - gdk_bitmap_unref (mtsl_item->mail_icon_mask); - - if (GTK_OBJECT_CLASS (e_meeting_time_selector_list_item_parent_class)->destroy) - (*GTK_OBJECT_CLASS (e_meeting_time_selector_list_item_parent_class)->destroy)(object); -} - - -static void -e_meeting_time_selector_list_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EMeetingTimeSelectorListItem *mtsl_item; - - item = GNOME_CANVAS_ITEM (o); - mtsl_item = E_MEETING_TIME_SELECTOR_LIST_ITEM (o); - - switch (arg_id){ - case ARG_MEETING_TIME_SELECTOR: - mtsl_item->mts = GTK_VALUE_POINTER (*arg); - break; - } -} - - -static void -e_meeting_time_selector_list_item_realize (GnomeCanvasItem *item) -{ - GnomeCanvas *canvas; - GdkWindow *window; - EMeetingTimeSelectorListItem *mtsl_item; - - if (GNOME_CANVAS_ITEM_CLASS (e_meeting_time_selector_list_item_parent_class)->realize) - (*GNOME_CANVAS_ITEM_CLASS (e_meeting_time_selector_list_item_parent_class)->realize)(item); - - mtsl_item = E_MEETING_TIME_SELECTOR_LIST_ITEM (item); - - canvas = item->canvas; - window = GTK_WIDGET (canvas)->window; - - mtsl_item->main_gc = gdk_gc_new (window); -} - - -static void -e_meeting_time_selector_list_item_unrealize (GnomeCanvasItem *item) -{ - EMeetingTimeSelectorListItem *mtsl_item; - - mtsl_item = E_MEETING_TIME_SELECTOR_LIST_ITEM (item); - - gdk_gc_unref (mtsl_item->main_gc); - mtsl_item->main_gc = NULL; - - if (GNOME_CANVAS_ITEM_CLASS (e_meeting_time_selector_list_item_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (e_meeting_time_selector_list_item_parent_class)->unrealize)(item); -} - - -static void -e_meeting_time_selector_list_item_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - if (GNOME_CANVAS_ITEM_CLASS (e_meeting_time_selector_list_item_parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (e_meeting_time_selector_list_item_parent_class)->update) (item, affine, clip_path, flags); - - /* The item covers the entire canvas area. */ - item->x1 = 0; - item->y1 = 0; - item->x2 = INT_MAX; - item->y2 = INT_MAX; -} - - -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ - -static void -e_meeting_time_selector_list_item_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - EMeetingTimeSelectorListItem *mtsl_item; - EMeetingTimeSelector *mts; - EMeetingTimeSelectorAttendee *attendee; - GdkGC *gc; - GdkFont *font; - gint row, row_y, icon_x, icon_y; - GdkPixmap *pixmap; - GdkBitmap *mask; - - mtsl_item = E_MEETING_TIME_SELECTOR_LIST_ITEM (item); - mts = mtsl_item->mts; - gc = mtsl_item->main_gc; - - gdk_gc_set_foreground (gc, &mts->attendee_list_bg_color); - gdk_draw_rectangle (drawable, gc, TRUE, 0, 0, width, height); - - gdk_gc_set_foreground (gc, &mts->grid_unused_color); - gdk_draw_line (drawable, gc, 24 - x, 0, 24 - x, height); - - /* Draw the grid line across the top of the row. */ - row = y / mts->row_height; - row_y = row * mts->row_height - y; - while (row_y < height) { - gdk_draw_line (drawable, gc, 0, row_y, width, row_y); - row_y += mts->row_height; - } - - row = y / mts->row_height; - row_y = row * mts->row_height - y; - icon_x = (E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH - E_MEETING_TIME_SELECTOR_ICON_WIDTH + 1) / 2 - x; - icon_y = row_y + (mts->row_height - E_MEETING_TIME_SELECTOR_ICON_HEIGHT + 1) / 2; - while (row < mts->attendees->len && row_y < height) { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - - gdk_gc_set_clip_origin (gc, icon_x, icon_y); - - if (attendee->send_meeting_to) { - pixmap = mtsl_item->mail_icon; - mask = mtsl_item->mail_icon_mask; - } else { - pixmap = mtsl_item->no_mail_icon; - mask = mtsl_item->no_mail_icon_mask; - } - - gdk_gc_set_clip_mask (gc, mask); - gdk_draw_pixmap (drawable, gc, pixmap, 0, 0, - icon_x, icon_y, 24, 24); - - row++; - row_y += mts->row_height; - icon_y += mts->row_height; - } - gdk_gc_set_clip_mask (gc, NULL); - - /* Draw 'Click here to add attendee' on the last dummy row. */ - row_y = mts->attendees->len * mts->row_height; - - font = GTK_WIDGET (mts)->style->font; - gdk_gc_set_foreground (gc, &mts->grid_unused_color); - gdk_draw_string (drawable, font, gc, - E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH - + E_MEETING_TIME_SELECTOR_TEXT_X_PAD - x, - row_y + E_MEETING_TIME_SELECTOR_TEXT_Y_PAD - + font->ascent + 1 - y, - "Click here to add attendee"); -} - - -/* This is supposed to return the nearest item the the point and the distance. - Since we cover the entire canvas we just return ourself and 0 for the - distance. This is needed so that we get button/motion events. */ -static double -e_meeting_time_selector_list_item_point (GnomeCanvasItem *item, - double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - - -static gint -e_meeting_time_selector_list_item_event (GnomeCanvasItem *item, - GdkEvent *event) -{ - EMeetingTimeSelectorListItem *mtsl_item; - - mtsl_item = E_MEETING_TIME_SELECTOR_LIST_ITEM (item); - - switch (event->type) { - case GDK_BUTTON_PRESS: - return e_meeting_time_selector_list_item_button_press (mtsl_item, event); - case GDK_BUTTON_RELEASE: - break; - case GDK_MOTION_NOTIFY: - break; - default: - break; - } - - return FALSE; -} - - -static gboolean -e_meeting_time_selector_list_item_button_press (EMeetingTimeSelectorListItem *mtsl_item, - GdkEvent *event) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorAttendee *attendee; - gint row; - gboolean return_val; - - mts = mtsl_item->mts; - row = event->button.y / mts->row_height; - - g_print ("In e_meeting_time_selector_list_item_button_press: %g,%g row:%i\n", - event->button.x, event->button.y, row); - - if (event->button.x >= E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH) { - if (row < mts->attendees->len) { - attendee = &g_array_index (mts->attendees, EMeetingTimeSelectorAttendee, row); - gtk_signal_emit_by_name (GTK_OBJECT (attendee->text_item), - "event", event, &return_val); - return return_val; - } else { - row = e_meeting_time_selector_attendee_add (mts, "", - NULL); - - /* Scroll down to show the last line.?? */ -#if 0 - adjustment = GTK_LAYOUT (mts->display_main)->vadjustment; - adjustment->value = adjustment->upper - adjustment->page_size; - gtk_adjustment_value_changed (adjustment); -#endif - - attendee = &g_array_index (mts->attendees, EMeetingTimeSelectorAttendee, row); - e_canvas_item_grab_focus (attendee->text_item); - return TRUE; - } - } else { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - - attendee->send_meeting_to = !attendee->send_meeting_to; - - gnome_canvas_request_redraw (GNOME_CANVAS_ITEM (mtsl_item)->canvas, - 0, row * mts->row_height, - E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH, - (row + 1) * mts->row_height); - return TRUE; - } -} - diff --git a/widgets/meeting-time-sel/e-meeting-time-sel-list-item.h b/widgets/meeting-time-sel/e-meeting-time-sel-list-item.h deleted file mode 100644 index 07df052c08..0000000000 --- a/widgets/meeting-time-sel/e-meeting-time-sel-list-item.h +++ /dev/null @@ -1,73 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@gtk.org> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * MeetingTimeSelectorListItem - A GnomeCanvasItem covering the entire attendee - * list. It just draws the grid lines between the rows and after the icon - * column. - */ - -#ifndef _E_MEETING_TIME_SELECTOR_LIST_ITEM_H_ -#define _E_MEETING_TIME_SELECTOR_LIST_ITEM_H_ - -#include "e-meeting-time-sel.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define E_MEETING_TIME_SELECTOR_LIST_ITEM(obj) (GTK_CHECK_CAST((obj), e_meeting_time_selector_list_item_get_type (), EMeetingTimeSelectorListItem)) -#define E_MEETING_TIME_SELECTOR_LIST_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), e_meeting_time_selector_list_item_get_type (), EMeetingTimeSelectorListItemClass)) -#define IS_E_MEETING_TIME_SELECTOR_LIST_ITEM(o) (GTK_CHECK_TYPE((o), e_meeting_time_selector_list_item_get_type ())) - - -typedef struct _EMeetingTimeSelectorListItem EMeetingTimeSelectorListItem; -typedef struct _EMeetingTimeSelectorListItemClass EMeetingTimeSelectorListItemClass; - -struct _EMeetingTimeSelectorListItem -{ - GnomeCanvasItem canvas_item; - - /* The parent EMeetingTimeSelector widget. */ - EMeetingTimeSelector *mts; - - /* This GC is used for most of the drawing. The fg/bg colors are - changed for each bit. */ - GdkGC *main_gc; - - GdkPixmap *mail_icon, *no_mail_icon; - GdkBitmap *mail_icon_mask, *no_mail_icon_mask; -}; - - -struct _EMeetingTimeSelectorListItemClass -{ - GnomeCanvasItemClass parent_class; -}; - -GtkType e_meeting_time_selector_list_item_get_type (void); - - -#endif /* _E_MEETING_TIME_SELECTOR_LIST_ITEM_H_ */ diff --git a/widgets/meeting-time-sel/e-meeting-time-sel-mail.xpm b/widgets/meeting-time-sel/e-meeting-time-sel-mail.xpm deleted file mode 100644 index 5a03c7ea8a..0000000000 --- a/widgets/meeting-time-sel/e-meeting-time-sel-mail.xpm +++ /dev/null @@ -1,135 +0,0 @@ -/* XPM */ -static char * e_meeting_time_sel_mail_xpm[] = { -"19 16 116 2", -" c None", -". c #000000", -"+ c #7B7B78", -"@ c #C7C7C3", -"# c #F1F0EB", -"$ c #BFBFBC", -"% c #5F5E5E", -"& c #E3E3DF", -"* c #F3F3EF", -"= c #F2F2EE", -"- c #F1F1EC", -"; c #F0EFEB", -"> c #D2D2CD", -", c #969592", -"' c #616060", -") c #B5B5B4", -"! c #F8F8F6", -"~ c #F7F7F5", -"{ c #F6F6F3", -"] c #F5F5F2", -"^ c #F4F4F0", -"/ c #F2F1ED", -"( c #F1F0EC", -"_ c #F0EFEA", -": c #EFEEE9", -"< c #4F4F4D", -"[ c #BDBCB8", -"} c #A7A6A3", -"| c #C6C6C4", -"1 c #7C7C7B", -"2 c #525251", -"3 c #DBDBD9", -"4 c #F5F4F1", -"5 c #F4F3F0", -"6 c #F3F2EE", -"7 c #999894", -"8 c #62625F", -"9 c #BCBCB6", -"0 c #EBE9E3", -"a c #838381", -"b c #D7D6D4", -"c c #A8A8A6", -"d c #515150", -"e c #7E7D7C", -"f c #DAD9D5", -"g c #EFEEE8", -"h c #EEEDE7", -"i c #4F4E4C", -"j c #BCBBB6", -"k c #EBE9E2", -"l c #EAE8E1", -"m c #F6F5F2", -"n c #F4F3EF", -"o c #B5B4B1", -"p c #9B9A97", -"q c #646361", -"r c #92918E", -"s c #EEEDE8", -"t c #EDECE6", -"u c #4E4E4C", -"v c #797976", -"w c #797874", -"x c #E9E8E1", -"y c #E8E7DF", -"z c #B4B3AF", -"A c #D0D0CD", -"B c #F2F2ED", -"C c #BFBEBA", -"D c #BEBDB9", -"E c #7A7A77", -"F c #979691", -"G c #EAE9E2", -"H c #959590", -"I c #787773", -"J c #B8B7B0", -"K c #E6E4DC", -"L c #A9A9A6", -"M c #626260", -"N c #ECEBE4", -"O c #EBEAE3", -"P c #E9E7E0", -"Q c #E8E6DF", -"R c #E7E5DD", -"S c #777671", -"T c #93918C", -"U c #BEBDB8", -"V c #989793", -"W c #ECEAE4", -"X c #E8E6DE", -"Y c #E6E4DB", -"Z c #E4E3DA", -"` c #75746F", -" . c #91908A", -".. c #EEECE7", -"+. c #62615F", -"@. c #EBEAE4", -"#. c #E7E6DE", -"$. c #E6E5DC", -"%. c #E5E4DB", -"&. c #E4E2DA", -"*. c #CCCBC4", -"=. c #A3A29D", -"-. c #B6B5B2", -";. c #BCBCB7", -">. c #CDCCC6", -",. c #959490", -"'. c #ECEBE5", -"). c #61615E", -"!. c #E9E8E0", -"~. c #CECDC7", -"{. c #797875", -"]. c #969590", -"^. c #CFCEC8", -"/. c #AEADA8", -"(. c #585754", -"_. c #7B7A76", -" . . . . ", -" . . . . . + @ # $ . ", -" . . . . . % $ & * = - ; > , . ", -". ' ) ! ~ { ] ^ * / ( _ : < [ } . ", -". | 1 2 3 4 5 6 / # _ : 7 8 9 0 . ", -". a b c d e f / # _ g h i j k l . ", -" . m 4 n o p q r s t u v w x y z . ", -" . A * B ( ; C D E u F G H I J K . ", -" . L / ( _ : M t N O l P Q R S T . ", -" . # _ g U V W 0 l P X R Y Z ` .. ", -" . ; g ..+.@.G x y #.$.%.&.*.=.. . ", -" . -.t ;.F G x y #.K >.,.. . . ", -" . '.).G !.Q ~.H . . . ", -" . {.].^./.. . . ", -" . (._.. . ", -" . . "}; diff --git a/widgets/meeting-time-sel/e-meeting-time-sel-no-mail.xpm b/widgets/meeting-time-sel/e-meeting-time-sel-no-mail.xpm deleted file mode 100644 index 747202b3e2..0000000000 --- a/widgets/meeting-time-sel/e-meeting-time-sel-no-mail.xpm +++ /dev/null @@ -1,123 +0,0 @@ -/* XPM */ -static char * e_meeting_time_sel_no_mail_xpm[] = { -"19 16 104 2", -" c None", -". c #000000", -"+ c #7B7B78", -"@ c #C7C7C3", -"# c #F1F0EB", -"$ c #BFBFBC", -"% c #5F5E5E", -"& c #E3E3DF", -"* c #F3F3EF", -"= c #F2F2EE", -"- c #F1F1EC", -"; c #F0EFEB", -"> c #D2D2CD", -", c #969592", -"' c #616060", -") c #B5B5B4", -"! c #F8F8F6", -"~ c #F7F7F5", -"{ c #F6F6F3", -"] c #F5F5F2", -"^ c #F4F4F0", -"/ c #F2F1ED", -"( c #F1F0EC", -"_ c #F0EFEA", -": c #EFEEE9", -"< c #4F4F4D", -"[ c #BDBCB8", -"} c #A7A6A3", -"| c #C6C6C4", -"1 c #7C7C7B", -"2 c #525251", -"3 c #DBDBD9", -"4 c #F5F4F1", -"5 c #F4F3F0", -"6 c #F3F2EE", -"7 c #999894", -"8 c #62625F", -"9 c #BCBCB6", -"0 c #EBE9E3", -"a c #838381", -"b c #D7D6D4", -"c c #A8A8A6", -"d c #515150", -"e c #7E7D7C", -"f c #DAD9D5", -"g c #D16069", -"h c #EEEDE7", -"i c #4F4E4C", -"j c #BCBBB6", -"k c #F6F5F2", -"l c #F4F3EF", -"m c #B5B4B1", -"n c #9B9A97", -"o c #646361", -"p c #92918E", -"q c #9F3C44", -"r c #797976", -"s c #B5444E", -"t c #B4B3AF", -"u c #D0D0CD", -"v c #F2F2ED", -"w c #BFBEBA", -"x c #BEBDB9", -"y c #BB565F", -"z c #812F36", -"A c #E6E4DC", -"B c #A9A9A6", -"C c #626260", -"D c #EDECE6", -"E c #ECEBE4", -"F c #BB555D", -"G c #90353D", -"H c #777671", -"I c #93918C", -"J c #EFEEE8", -"K c #BEBDB8", -"L c #989793", -"M c #ECEAE4", -"N c #E6E4DB", -"O c #E4E3DA", -"P c #75746F", -"Q c #91908A", -"R c #EEECE7", -"S c #62615F", -"T c #EBEAE4", -"U c #EAE9E2", -"V c #BD5A62", -"W c #E4E2DA", -"X c #CCCBC4", -"Y c #A3A29D", -"Z c #B6B5B2", -"` c #BCBCB7", -" . c #979691", -".. c #BC5760", -"+. c #A13C45", -"@. c #ECEBE5", -"#. c #61615E", -"$. c #C0636B", -"%. c #A83F48", -"&. c #797875", -"*. c #969590", -"=. c #CFCEC8", -"-. c #585754", -";. c #7B7A76", -" . . . . ", -" . . . . . + @ # $ . ", -" . . . . . % $ & * = - ; > , . ", -". ' ) ! ~ { ] ^ * / ( _ : < [ } . ", -". | 1 2 3 4 5 6 / # _ : 7 8 9 0 . ", -". a b c d e f / # g g h i j g g . ", -" . k 4 l m n o p g q g r g s g t . ", -" . u * v ( ; w x g s g g y z g A . ", -" . B / ( _ : C D E g s F G g H I . ", -" . # _ J K L M 0 g s s g N O P Q . ", -" . ; J R S T U g V s s g W X Y . . ", -" . Z D ` .U g ..G g g +.g . . ", -" . @.#.U g $.G g . g %.g ", -" . &.*.=.g g g . g g ", -" . -.;.. . ", -" . . "}; diff --git a/widgets/meeting-time-sel/e-meeting-time-sel.c b/widgets/meeting-time-sel/e-meeting-time-sel.c deleted file mode 100644 index 8c1731925d..0000000000 --- a/widgets/meeting-time-sel/e-meeting-time-sel.c +++ /dev/null @@ -1,3271 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@gtk.org> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include <config.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <time.h> -#include <gtk/gtkalignment.h> -#include <gtk/gtkarrow.h> -#include <gtk/gtkbutton.h> -#include <gtk/gtkdrawingarea.h> -#include <gtk/gtkentry.h> -#include <gtk/gtkhbox.h> -#include <gtk/gtkhscrollbar.h> -#include <gtk/gtkhseparator.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkmenu.h> -#include <gtk/gtkradiomenuitem.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkvbox.h> -#include <gtk/gtkvscrollbar.h> -#include <libgnomeui/gnome-dateedit.h> -#include <libgnome/gnome-i18n.h> -#include <libgnomeui/gnome-canvas-widget.h> - -#include "../../e-util/e-canvas.h" -#include "../../e-util/e-canvas-utils.h" -#include "e-meeting-time-sel.h" -#include "e-meeting-time-sel-item.h" -#include "e-meeting-time-sel-list-item.h" - -/* An array of hour strings, "0:00" .. "23:00". */ -const gchar *EMeetingTimeSelectorHours[24] = { - "0:00", "1:00", "2:00", "3:00", "4:00", "5:00", "6:00", "7:00", - "8:00", "9:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", - "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00" -}; - -/* The number of days shown in the entire canvas. */ -#define E_MEETING_TIME_SELECTOR_DAYS_SHOWN 365 - -/* This is the number of pixels between the mouse has to move before the - scroll speed is incremented. */ -#define E_MEETING_TIME_SELECTOR_SCROLL_INCREMENT_WIDTH 10 - -/* This is the maximum scrolling speed. */ -#define E_MEETING_TIME_SELECTOR_MAX_SCROLL_SPEED 4 - - -static void e_meeting_time_selector_class_init (EMeetingTimeSelectorClass * klass); -static void e_meeting_time_selector_init (EMeetingTimeSelector * mts); -static void e_meeting_time_selector_destroy (GtkObject *object); -static void e_meeting_time_selector_alloc_named_color (EMeetingTimeSelector * mts, - const char *name, GdkColor *c); -static void e_meeting_time_selector_add_key_color (EMeetingTimeSelector * mts, - GtkWidget *hbox, - gchar *label_text, - GdkColor *color); -static gint e_meeting_time_selector_expose_key_color (GtkWidget *darea, - GdkEventExpose *event, - GdkColor *color); -static gint e_meeting_time_selector_expose_title_bar (GtkWidget *darea, - GdkEventExpose *event, - gpointer data); -static void e_meeting_time_selector_options_menu_detacher (GtkWidget *widget, - GtkMenu *menu); -static void e_meeting_time_selector_autopick_menu_detacher (GtkWidget *widget, - GtkMenu *menu); -static void e_meeting_time_selector_realize (GtkWidget *widget); -static void e_meeting_time_selector_unrealize (GtkWidget *widget); -static void e_meeting_time_selector_style_set (GtkWidget *widget, - GtkStyle *previous_style); -static gint e_meeting_time_selector_expose_event (GtkWidget *widget, - GdkEventExpose *event); -static void e_meeting_time_selector_draw (GtkWidget *widget, - GdkRectangle *area); -static void e_meeting_time_selector_draw_shadow (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_hadjustment_changed (GtkAdjustment *adjustment, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_vadjustment_changed (GtkAdjustment *adjustment, - EMeetingTimeSelector *mts); - -static void e_meeting_time_selector_on_canvas_realized (GtkWidget *widget, - EMeetingTimeSelector *mts); - -static gint e_meeting_time_selector_compare_period_starts (const void *arg1, - const void *arg2); -#if 0 -static gint e_meeting_time_selector_compare_periods (const void *arg1, - const void *arg2); -#endif -static gint e_meeting_time_selector_compare_times (EMeetingTimeSelectorTime *time1, - EMeetingTimeSelectorTime *time2); -static void e_meeting_time_selector_on_options_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_options_menu_position_callback (GtkMenu *menu, - gint *x, - gint *y, - gpointer user_data); -static void e_meeting_time_selector_on_zoomed_out_toggled (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_working_hours_toggled (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_invite_others_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_update_free_busy (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_autopick_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_autopick_menu_position_callback (GtkMenu *menu, - gint *x, - gint *y, - gpointer user_data); -static void e_meeting_time_selector_on_autopick_option_toggled (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_prev_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_next_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_autopick (EMeetingTimeSelector *mts, - gboolean forward); -static void e_meeting_time_selector_calculate_time_difference (EMeetingTimeSelectorTime *start, - EMeetingTimeSelectorTime *end, - gint *days, - gint *hours, - gint *minutes); -static void e_meeting_time_selector_find_nearest_interval (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *start_time, - EMeetingTimeSelectorTime *end_time, - gint days, gint hours, gint mins); -static void e_meeting_time_selector_find_nearest_interval_backward (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *start_time, - EMeetingTimeSelectorTime *end_time, - gint days, gint hours, gint mins); -static void e_meeting_time_selector_adjust_time (EMeetingTimeSelectorTime *mtstime, - gint days, gint hours, gint minutes); -static EMeetingTimeSelectorPeriod* e_meeting_time_selector_find_time_clash (EMeetingTimeSelector *mts, - EMeetingTimeSelectorAttendee *attendee, - EMeetingTimeSelectorTime *start_time, - EMeetingTimeSelectorTime *end_time); - - -static void e_meeting_time_selector_recalc_grid (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_recalc_date_format (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_save_position (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *mtstime); -static void e_meeting_time_selector_restore_position (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *mtstime); -static void e_meeting_time_selector_on_start_time_changed (GtkWidget *widget, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_end_time_changed (GtkWidget *widget, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_update_date_popup_menus (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_attendees_list_size_allocate (GtkWidget *widget, - GtkAllocation *allocation, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_on_canvas_size_allocate (GtkWidget *widget, - GtkAllocation *allocation, - EMeetingTimeSelector *mts); -static void e_meeting_time_selector_update_main_canvas_scroll_region (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_update_attendees_list_scroll_region (EMeetingTimeSelector *mts); -static gboolean e_meeting_time_selector_timeout_handler (gpointer data); -static void e_meeting_time_selector_update_start_date_edit (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_update_end_date_edit (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_ensure_meeting_time_shown (EMeetingTimeSelector *mts); -static void e_meeting_time_selector_update_dates_shown (EMeetingTimeSelector *mts); - -static void e_meeting_time_selector_update_attendees_list_positions (EMeetingTimeSelector *mts); -static gboolean e_meeting_time_selector_on_text_item_event (GnomeCanvasItem *item, - GdkEvent *event, - EMeetingTimeSelector *mts); -static gint e_meeting_time_selector_find_row_from_text_item (EMeetingTimeSelector *mts, - GnomeCanvasItem *item); - -static GtkTableClass *parent_class; - - -GtkType -e_meeting_time_selector_get_type (void) -{ - static guint e_meeting_time_selector_type = 0; - - if (!e_meeting_time_selector_type) { - GtkTypeInfo e_meeting_time_selector_info = - { - "EMeetingTimeSelector", - sizeof (EMeetingTimeSelector), - sizeof (EMeetingTimeSelectorClass), - (GtkClassInitFunc) e_meeting_time_selector_class_init, - (GtkObjectInitFunc) e_meeting_time_selector_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - e_meeting_time_selector_type = gtk_type_unique (GTK_TYPE_TABLE, - &e_meeting_time_selector_info); - } - return e_meeting_time_selector_type; -} - - -static void -e_meeting_time_selector_class_init (EMeetingTimeSelectorClass * klass) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - parent_class = gtk_type_class (gtk_table_get_type()); - - object_class = (GtkObjectClass *) klass; - widget_class = (GtkWidgetClass *) klass; - - object_class->destroy = e_meeting_time_selector_destroy; - - widget_class->realize = e_meeting_time_selector_realize; - widget_class->unrealize = e_meeting_time_selector_unrealize; - widget_class->style_set = e_meeting_time_selector_style_set; - widget_class->expose_event = e_meeting_time_selector_expose_event; - widget_class->draw = e_meeting_time_selector_draw; -} - - -static void -e_meeting_time_selector_init (EMeetingTimeSelector * mts) -{ - GtkWidget *hbox, *separator, *button, *label, *table; - GtkWidget *alignment, *child_hbox, *arrow, *menuitem; - GSList *group; - GdkVisual *visual; - GdkColormap *colormap; - guint accel_key; - GtkAccelGroup *menu_accel_group; - time_t meeting_start_time; - struct tm *meeting_start_tm; - guchar stipple_bits[] = { - 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, - }; - - /* The shadow is drawn in the border so it must be >= 2 pixels. */ - gtk_container_set_border_width (GTK_CONTAINER (mts), 2); - - mts->accel_group = gtk_accel_group_new (); - - mts->attendees = g_array_new (FALSE, FALSE, - sizeof (EMeetingTimeSelectorAttendee)); - - mts->working_hours_only = TRUE; - mts->day_start_hour = 9; - mts->day_start_minute = 0; - mts->day_end_hour = 18; - mts->day_end_minute = 0; - mts->zoomed_out = FALSE; - mts->dragging_position = E_MEETING_TIME_SELECTOR_POS_NONE; - - /* The default meeting time is the nearest half-hour interval in the - future, in working hours. */ - meeting_start_time = time (NULL); - g_date_clear (&mts->meeting_start_time.date, 1); - g_date_set_time (&mts->meeting_start_time.date, meeting_start_time); - meeting_start_tm = localtime (&meeting_start_time); - mts->meeting_start_time.hour = meeting_start_tm->tm_hour; - mts->meeting_start_time.minute = meeting_start_tm->tm_min; - - e_meeting_time_selector_find_nearest_interval (mts, &mts->meeting_start_time, - &mts->meeting_end_time, - 0, 0, 30); - - e_meeting_time_selector_update_dates_shown (mts); - - mts->meeting_positions_valid = FALSE; - - mts->row_height = 30; - mts->col_width = 50; - mts->day_width = 50 * 24 + 1; - - mts->auto_scroll_timeout_id = 0; - - - mts->attendees_title_bar_vbox = gtk_vbox_new (FALSE, 2); - /* Add some horizontal padding for the shadow around the display. */ - gtk_table_attach (GTK_TABLE (mts), - mts->attendees_title_bar_vbox, - 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 2, 0); - gtk_widget_show (mts->attendees_title_bar_vbox); - - mts->attendees_title_bar = gtk_drawing_area_new (); - gtk_box_pack_end (GTK_BOX (mts->attendees_title_bar_vbox), - mts->attendees_title_bar, FALSE, FALSE, 0); - gtk_widget_show (mts->attendees_title_bar); - gtk_signal_connect (GTK_OBJECT (mts->attendees_title_bar), - "expose_event", - GTK_SIGNAL_FUNC (e_meeting_time_selector_expose_title_bar), mts); - - mts->attendees_list = e_canvas_new (); - /* Add some horizontal padding for the shadow around the display. */ - gtk_table_attach (GTK_TABLE (mts), mts->attendees_list, - 0, 1, 1, 2, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 0); - gtk_widget_show (mts->attendees_list); - gtk_signal_connect (GTK_OBJECT (mts->attendees_list), "realize", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_canvas_realized), mts); - gtk_signal_connect (GTK_OBJECT (mts->attendees_list), "size_allocate", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_attendees_list_size_allocate), mts); - - /* Create the item in the list canvas. */ - gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (mts->attendees_list)->root), - e_meeting_time_selector_list_item_get_type (), - "EMeetingTimeSelectorListItem::meeting_time_selector", mts, - NULL); - - mts->display_top = gnome_canvas_new (); - gnome_canvas_set_scroll_region (GNOME_CANVAS (mts->display_top), - 0, 0, - mts->day_width * E_MEETING_TIME_SELECTOR_DAYS_SHOWN, - mts->row_height * 3); - /* Add some horizontal padding for the shadow around the display. */ - gtk_table_attach (GTK_TABLE (mts), mts->display_top, - 1, 4, 0, 1, GTK_EXPAND | GTK_FILL, 0, 2, 0); - gtk_widget_show (mts->display_top); - gtk_signal_connect (GTK_OBJECT (mts->display_top), "realize", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_canvas_realized), mts); - - mts->display_main = gnome_canvas_new (); - e_meeting_time_selector_update_main_canvas_scroll_region (mts); - /* Add some horizontal padding for the shadow around the display. */ - gtk_table_attach (GTK_TABLE (mts), mts->display_main, - 1, 4, 1, 2, - GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 2, 0); - gtk_widget_show (mts->display_main); - gtk_signal_connect (GTK_OBJECT (mts->display_main), "realize", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_canvas_realized), mts); - gtk_signal_connect (GTK_OBJECT (mts->display_main), "size_allocate", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_canvas_size_allocate), mts); - - mts->hscrollbar = gtk_hscrollbar_new (GTK_LAYOUT (mts->display_main)->hadjustment); - gtk_table_attach (GTK_TABLE (mts), mts->hscrollbar, - 1, 4, 2, 3, GTK_EXPAND | GTK_FILL, 0, 0, 0); - gtk_widget_show (mts->hscrollbar); - - mts->vscrollbar = gtk_vscrollbar_new (GTK_LAYOUT (mts->display_main)->vadjustment); - gtk_table_attach (GTK_TABLE (mts), mts->vscrollbar, - 4, 5, 1, 2, 0, GTK_EXPAND | GTK_FILL, 0, 0); - gtk_widget_show (mts->vscrollbar); - - /* Create the item in the top canvas. */ - gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (mts->display_top)->root), - e_meeting_time_selector_item_get_type (), - "EMeetingTimeSelectorItem::meeting_time_selector", mts, - NULL); - - /* Create the item in the main canvas. */ - gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (mts->display_main)->root), - e_meeting_time_selector_item_get_type (), - "EMeetingTimeSelectorItem::meeting_time_selector", mts, - NULL); - - /* Create the hbox containing the color key. */ - hbox = gtk_hbox_new (FALSE, 2); - gtk_table_attach (GTK_TABLE (mts), hbox, - 1, 4, 3, 4, GTK_FILL, 0, 0, 8); - gtk_widget_show (hbox); - - e_meeting_time_selector_add_key_color (mts, hbox, _("Tentative"), &mts->busy_colors[E_MEETING_TIME_SELECTOR_BUSY_TENTATIVE]); - e_meeting_time_selector_add_key_color (mts, hbox, _("Busy"), &mts->busy_colors[E_MEETING_TIME_SELECTOR_BUSY_BUSY]); - e_meeting_time_selector_add_key_color (mts, hbox, _("Out of Office"), &mts->busy_colors[E_MEETING_TIME_SELECTOR_BUSY_OUT_OF_OFFICE]); - e_meeting_time_selector_add_key_color (mts, hbox, _("No Information"), - NULL); - - separator = gtk_hseparator_new (); - gtk_table_attach (GTK_TABLE (mts), separator, - 0, 5, 4, 5, GTK_FILL, 0, 0, 0); - gtk_widget_show (separator); - - /* Create the Invite Others & Options buttons on the left. */ - hbox = gtk_hbox_new (FALSE, 4); - gtk_table_attach (GTK_TABLE (mts), hbox, - 0, 1, 3, 4, GTK_FILL, 0, 0, 0); - gtk_widget_show (hbox); - - button = gtk_button_new_with_label (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (button)->child), - _("_Invite Others...")); - gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); - gtk_widget_show (button); - gtk_widget_add_accelerator (button, "clicked", mts->accel_group, - accel_key, GDK_MOD1_MASK, 0); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_invite_others_button_clicked), mts); - - mts->options_button = gtk_button_new (); - gtk_box_pack_start (GTK_BOX (hbox), mts->options_button, TRUE, TRUE, 0); - gtk_widget_show (mts->options_button); - - gtk_signal_connect (GTK_OBJECT (mts->options_button), "clicked", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_options_button_clicked), mts); - - child_hbox = gtk_hbox_new (FALSE, 2); - gtk_container_add (GTK_CONTAINER (mts->options_button), child_hbox); - gtk_widget_show (child_hbox); - - label = gtk_label_new (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (label), _("_Options")); - gtk_box_pack_start (GTK_BOX (child_hbox), label, TRUE, TRUE, 0); - gtk_widget_show (label); - gtk_widget_add_accelerator (mts->options_button, "clicked", mts->accel_group, - accel_key, GDK_MOD1_MASK, 0); - - arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT); - gtk_box_pack_start (GTK_BOX (child_hbox), arrow, FALSE, FALSE, 2); - gtk_widget_show (arrow); - - /* Create the Options menu. */ - mts->options_menu = gtk_menu_new (); - gtk_menu_attach_to_widget (GTK_MENU (mts->options_menu), mts->options_button, - e_meeting_time_selector_options_menu_detacher); - menu_accel_group = gtk_menu_ensure_uline_accel_group (GTK_MENU (mts->options_menu)); - - menuitem = gtk_check_menu_item_new_with_label (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("Show _Only Working Hours")); - gtk_menu_append (GTK_MENU (mts->options_menu), menuitem); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), - mts->working_hours_only); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - gtk_signal_connect (GTK_OBJECT (menuitem), "toggled", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_working_hours_toggled), mts); - gtk_widget_show (menuitem); - - menuitem = gtk_check_menu_item_new_with_label (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("Show _Zoomed Out")); - gtk_menu_append (GTK_MENU (mts->options_menu), menuitem); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menuitem), - mts->zoomed_out); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - gtk_signal_connect (GTK_OBJECT (menuitem), "toggled", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_zoomed_out_toggled), mts); - gtk_widget_show (menuitem); - - menuitem = gtk_menu_item_new (); - gtk_menu_append (GTK_MENU (mts->options_menu), menuitem); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - - menuitem = gtk_menu_item_new_with_label (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("_Update Free/Busy")); - gtk_menu_append (GTK_MENU (mts->options_menu), menuitem); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - gtk_signal_connect (GTK_OBJECT (menuitem), "activate", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_update_free_busy), mts); - gtk_widget_show (menuitem); - - /* Create the 3 AutoPick buttons on the left. */ - hbox = gtk_hbox_new (FALSE, 0); - gtk_table_attach (GTK_TABLE (mts), hbox, - 0, 1, 5, 6, GTK_FILL, 0, 0, 0); - gtk_widget_show (hbox); - - button = gtk_button_new_with_label (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (button)->child), - _("_<<")); - gtk_widget_add_accelerator (button, "clicked", mts->accel_group, - accel_key, GDK_MOD1_MASK | GDK_SHIFT_MASK, 0); - gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); - gtk_widget_show (button); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_prev_button_clicked), mts); - - mts->autopick_button = gtk_button_new (); - gtk_box_pack_start (GTK_BOX (hbox), mts->autopick_button, TRUE, TRUE, 0); - gtk_widget_show (mts->autopick_button); - - child_hbox = gtk_hbox_new (FALSE, 2); - gtk_container_add (GTK_CONTAINER (mts->autopick_button), child_hbox); - gtk_widget_show (child_hbox); - - label = gtk_label_new (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (label), _("_Autopick")); - gtk_box_pack_start (GTK_BOX (child_hbox), label, TRUE, TRUE, 0); - gtk_widget_show (label); - gtk_widget_add_accelerator (mts->autopick_button, "clicked", mts->accel_group, - accel_key, GDK_MOD1_MASK, 0); - gtk_signal_connect (GTK_OBJECT (mts->autopick_button), "clicked", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_autopick_button_clicked), mts); - - arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT); - gtk_box_pack_start (GTK_BOX (child_hbox), arrow, FALSE, FALSE, 2); - gtk_widget_show (arrow); - - button = gtk_button_new_with_label (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (button)->child), - _(">_>")); - gtk_widget_add_accelerator (button, "clicked", mts->accel_group, - accel_key, GDK_MOD1_MASK | GDK_SHIFT_MASK, 0); - gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); - gtk_widget_show (button); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_next_button_clicked), mts); - - /* Create the Autopick menu. */ - mts->autopick_menu = gtk_menu_new (); - gtk_menu_attach_to_widget (GTK_MENU (mts->autopick_menu), mts->autopick_button, - e_meeting_time_selector_autopick_menu_detacher); - menu_accel_group = gtk_menu_ensure_uline_accel_group (GTK_MENU (mts->autopick_menu)); - - menuitem = gtk_radio_menu_item_new_with_label (NULL, ""); - mts->autopick_all_item = menuitem; - group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem)); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("_All People and Resources")); - gtk_menu_append (GTK_MENU (mts->autopick_menu), menuitem); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - gtk_signal_connect (GTK_OBJECT (menuitem), "toggled", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_autopick_option_toggled), mts); - gtk_widget_show (menuitem); - - menuitem = gtk_radio_menu_item_new_with_label (group, ""); - mts->autopick_all_people_one_resource_item = menuitem; - group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem)); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("All _People and One Resource")); - gtk_menu_append (GTK_MENU (mts->autopick_menu), menuitem); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - gtk_signal_connect (GTK_OBJECT (menuitem), "toggled", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_autopick_option_toggled), mts); - gtk_widget_show (menuitem); - - menuitem = gtk_radio_menu_item_new_with_label (group, ""); - mts->autopick_required_people_item = menuitem; - group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem)); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("_Required People")); - gtk_menu_append (GTK_MENU (mts->autopick_menu), menuitem); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - gtk_signal_connect (GTK_OBJECT (menuitem), "activate", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_autopick_option_toggled), mts); - gtk_widget_show (menuitem); - - menuitem = gtk_radio_menu_item_new_with_label (group, ""); - mts->autopick_required_people_one_resource_item = menuitem; - group = gtk_radio_menu_item_group (GTK_RADIO_MENU_ITEM (menuitem)); - accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menuitem)->child), _("Required People and _One Resource")); - gtk_menu_append (GTK_MENU (mts->autopick_menu), menuitem); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, 0, 0); - gtk_widget_add_accelerator (menuitem, "activate", menu_accel_group, - accel_key, GDK_MOD1_MASK, 0); - gtk_signal_connect (GTK_OBJECT (menuitem), "activate", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_autopick_option_toggled), mts); - gtk_widget_show (menuitem); - - /* Create the date entry fields on the right. */ - alignment = gtk_alignment_new (0.5, 0.5, 0, 0); - gtk_table_attach (GTK_TABLE (mts), alignment, - 1, 4, 5, 6, GTK_FILL, 0, 0, 0); - gtk_widget_show (alignment); - - table = gtk_table_new (2, 2, FALSE); - gtk_table_set_row_spacings (GTK_TABLE (table), 4); - gtk_container_add (GTK_CONTAINER (alignment), table); - gtk_widget_show (table); - - label = gtk_label_new (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (label), - _("Meeting _start time:")); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_table_attach (GTK_TABLE (table), label, - 0, 1, 0, 1, GTK_FILL, 0, 4, 0); - gtk_widget_show (label); - - mts->start_date_edit = gnome_date_edit_new (0, TRUE, TRUE); - /* I don't like the 'Calendar' label. */ - gtk_widget_hide (GNOME_DATE_EDIT (mts->start_date_edit)->cal_label); - gtk_table_attach (GTK_TABLE (table), mts->start_date_edit, - 1, 2, 0, 1, GTK_FILL, 0, 0, 0); - gtk_widget_show (mts->start_date_edit); - gtk_signal_connect (GTK_OBJECT (mts->start_date_edit), "date_changed", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_start_time_changed), mts); - gtk_signal_connect (GTK_OBJECT (mts->start_date_edit), "time_changed", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_start_time_changed), mts); - gtk_signal_connect (GTK_OBJECT (GNOME_DATE_EDIT (mts->start_date_edit)->date_entry), "activate", GTK_SIGNAL_FUNC (e_meeting_time_selector_on_start_time_changed), mts); - gtk_signal_connect (GTK_OBJECT (GNOME_DATE_EDIT (mts->start_date_edit)->time_entry), "activate", GTK_SIGNAL_FUNC (e_meeting_time_selector_on_start_time_changed), mts); - gtk_widget_add_accelerator (GNOME_DATE_EDIT (mts->start_date_edit)->date_entry, - "grab_focus", mts->accel_group, - accel_key, GDK_MOD1_MASK, 0); - - label = gtk_label_new (""); - accel_key = gtk_label_parse_uline (GTK_LABEL (label), - _("Meeting _end time:")); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_table_attach (GTK_TABLE (table), label, - 0, 1, 1, 2, GTK_FILL, 0, 4, 0); - gtk_widget_show (label); - - mts->end_date_edit = gnome_date_edit_new (0, TRUE, TRUE); - gtk_widget_hide (GNOME_DATE_EDIT (mts->end_date_edit)->cal_label); - gtk_table_attach (GTK_TABLE (table), mts->end_date_edit, - 1, 2, 1, 2, GTK_FILL, 0, 0, 0); - gtk_widget_show (mts->end_date_edit); - gtk_signal_connect (GTK_OBJECT (mts->end_date_edit), "date_changed", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_end_time_changed), mts); - gtk_signal_connect (GTK_OBJECT (mts->end_date_edit), "time_changed", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_end_time_changed), mts); - gtk_signal_connect (GTK_OBJECT (GNOME_DATE_EDIT (mts->end_date_edit)->date_entry), "activate", GTK_SIGNAL_FUNC (e_meeting_time_selector_on_end_time_changed), mts); - gtk_signal_connect (GTK_OBJECT (GNOME_DATE_EDIT (mts->end_date_edit)->time_entry), "activate", GTK_SIGNAL_FUNC (e_meeting_time_selector_on_end_time_changed), mts); - gtk_widget_add_accelerator (GNOME_DATE_EDIT (mts->end_date_edit)->date_entry, - "grab_focus", mts->accel_group, - accel_key, GDK_MOD1_MASK, 0); - - gtk_table_set_col_spacing (GTK_TABLE (mts), 0, 4); - gtk_table_set_row_spacing (GTK_TABLE (mts), 4, 12); - - /* Allocate the colors. */ - visual = gtk_widget_get_visual (GTK_WIDGET (mts)); - colormap = gtk_widget_get_colormap (GTK_WIDGET (mts)); - mts->color_context = gdk_color_context_new (visual, colormap); - e_meeting_time_selector_alloc_named_color (mts, "gray75", &mts->bg_color); - e_meeting_time_selector_alloc_named_color (mts, "gray50", &mts->all_attendees_bg_color); - gdk_color_black (colormap, &mts->grid_color); - gdk_color_white (colormap, &mts->grid_shadow_color); - e_meeting_time_selector_alloc_named_color (mts, "gray50", &mts->grid_unused_color); - gdk_color_white (colormap, &mts->meeting_time_bg_color); - gdk_color_white (colormap, &mts->stipple_bg_color); - gdk_color_white (colormap, &mts->attendee_list_bg_color); - - e_meeting_time_selector_alloc_named_color (mts, "LightSkyBlue2", &mts->busy_colors[E_MEETING_TIME_SELECTOR_BUSY_TENTATIVE]); - e_meeting_time_selector_alloc_named_color (mts, "blue", &mts->busy_colors[E_MEETING_TIME_SELECTOR_BUSY_BUSY]); - e_meeting_time_selector_alloc_named_color (mts, "HotPink3", &mts->busy_colors[E_MEETING_TIME_SELECTOR_BUSY_OUT_OF_OFFICE]); - - /* Create the stipple, for attendees with no data. */ - mts->stipple = gdk_bitmap_create_from_data (NULL, (gchar*)stipple_bits, - 8, 8); - - /* Connect handlers to the adjustments in the main canvas, so we can - scroll the other 2 canvases. */ - gtk_signal_connect (GTK_OBJECT (GTK_LAYOUT (mts->display_main)->hadjustment), "value_changed", GTK_SIGNAL_FUNC (e_meeting_time_selector_hadjustment_changed), mts); - gtk_signal_connect (GTK_OBJECT (GTK_LAYOUT (mts->display_main)->vadjustment), "value_changed", GTK_SIGNAL_FUNC (e_meeting_time_selector_vadjustment_changed), mts); - gtk_signal_connect (GTK_OBJECT (GTK_LAYOUT (mts->display_main)->vadjustment), "changed", GTK_SIGNAL_FUNC (e_meeting_time_selector_vadjustment_changed), mts); - - e_meeting_time_selector_recalc_grid (mts); - e_meeting_time_selector_ensure_meeting_time_shown (mts); - e_meeting_time_selector_update_start_date_edit (mts); - e_meeting_time_selector_update_end_date_edit (mts); - e_meeting_time_selector_update_date_popup_menus (mts); -} - - -/* This adds a color to the color key beneath the main display. If color is - NULL, it displays the No Info stipple instead. */ -static void -e_meeting_time_selector_add_key_color (EMeetingTimeSelector * mts, - GtkWidget *hbox, - gchar *label_text, GdkColor *color) -{ - GtkWidget *child_hbox, *darea, *label; - - child_hbox = gtk_hbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (hbox), child_hbox, TRUE, TRUE, 0); - gtk_widget_show (child_hbox); - - darea = gtk_drawing_area_new (); - gtk_box_pack_start (GTK_BOX (child_hbox), darea, FALSE, FALSE, 0); - gtk_object_set_user_data (GTK_OBJECT (darea), mts); - gtk_widget_set_usize (darea, 14, 14); - gtk_widget_show (darea); - - label = gtk_label_new (label_text); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_box_pack_start (GTK_BOX (child_hbox), label, TRUE, TRUE, 0); - gtk_widget_show (label); - - gtk_signal_connect (GTK_OBJECT (darea), "expose_event", - GTK_SIGNAL_FUNC (e_meeting_time_selector_expose_key_color), - color); -} - - -static gint -e_meeting_time_selector_expose_title_bar (GtkWidget *widget, - GdkEventExpose *event, - gpointer data) -{ - EMeetingTimeSelector * mts; - GdkFont *font; - - mts = E_MEETING_TIME_SELECTOR (data); - - gtk_draw_shadow (widget->style, widget->window, GTK_STATE_NORMAL, - GTK_SHADOW_OUT, 0, 0, - E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH + 1, - widget->allocation.height); - gtk_draw_shadow (widget->style, widget->window, GTK_STATE_NORMAL, - GTK_SHADOW_OUT, - E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH + 1, 0, - widget->allocation.width - E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH - 1, - widget->allocation.height); - - font = widget->style->font; - gdk_draw_string (widget->window, font, - widget->style->fg_gc[GTK_STATE_NORMAL], - E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH + 4, - 4 + font->ascent, _("All Attendees")); - - return FALSE; -} - - -static gint -e_meeting_time_selector_expose_key_color (GtkWidget *darea, - GdkEventExpose *event, - GdkColor *color) -{ - EMeetingTimeSelector * mts; - GdkGC *gc; - gint width, height; - - mts = gtk_object_get_user_data (GTK_OBJECT (darea)); - gc = mts->color_key_gc; - width = darea->allocation.width; - height = darea->allocation.height; - - gtk_draw_shadow (darea->style, darea->window, GTK_STATE_NORMAL, - GTK_SHADOW_IN, 0, 0, width, height); - - if (color) { - gdk_gc_set_foreground (gc, color); - gdk_draw_rectangle (darea->window, gc, TRUE, 1, 1, - width - 2, height - 2); - } else { - gdk_gc_set_foreground (gc, &mts->grid_color); - gdk_gc_set_background (gc, &mts->stipple_bg_color); - gdk_gc_set_stipple (gc, mts->stipple); - gdk_gc_set_fill (gc, GDK_OPAQUE_STIPPLED); - gdk_draw_rectangle (darea->window, gc, TRUE, 1, 1, - width - 2, height - 2); - gdk_gc_set_fill (gc, GDK_SOLID); - } - - return TRUE; -} - - -static void -e_meeting_time_selector_alloc_named_color (EMeetingTimeSelector * mts, - const char *name, GdkColor *c) -{ - int failed; - - g_return_if_fail (name != NULL); - g_return_if_fail (c != NULL); - - gdk_color_parse (name, c); - c->pixel = 0; - c->pixel = gdk_color_context_get_pixel (mts->color_context, - c->red, c->green, c->blue, - &failed); - if (failed) - g_warning ("Failed to allocate color: %s\n", name); -} - - -static void -e_meeting_time_selector_options_menu_detacher (GtkWidget *widget, - GtkMenu *menu) -{ - EMeetingTimeSelector *mts; - - g_return_if_fail (widget != NULL); - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (widget)); - - mts = E_MEETING_TIME_SELECTOR (widget); - g_return_if_fail (mts->options_menu == (GtkWidget*) menu); - - mts->options_menu = NULL; -} - - -static void -e_meeting_time_selector_autopick_menu_detacher (GtkWidget *widget, - GtkMenu *menu) -{ - EMeetingTimeSelector *mts; - - g_return_if_fail (widget != NULL); - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (widget)); - - mts = E_MEETING_TIME_SELECTOR (widget); - g_return_if_fail (mts->autopick_menu == (GtkWidget*) menu); - - mts->autopick_menu = NULL; -} - - -GtkWidget * -e_meeting_time_selector_new (void) -{ - GtkWidget *mts; - - mts = GTK_WIDGET (gtk_type_new (e_meeting_time_selector_get_type ())); - - return mts; -} - - -static void -e_meeting_time_selector_destroy (GtkObject *object) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorAttendee *attendee; - gint row; - - mts = E_MEETING_TIME_SELECTOR (object); - - e_meeting_time_selector_remove_timeout (mts); - - gdk_color_context_free (mts->color_context); - gdk_bitmap_unref (mts->stipple); - - for (row = 0; row < mts->attendees->len; row++) { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - g_free (attendee->name); - g_array_free (attendee->busy_periods, TRUE); - } - - g_array_free (mts->attendees, TRUE); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (*GTK_OBJECT_CLASS (parent_class)->destroy)(object); -} - - -static void -e_meeting_time_selector_realize (GtkWidget *widget) -{ - EMeetingTimeSelector *mts; - - if (GTK_WIDGET_CLASS (parent_class)->realize) - (*GTK_WIDGET_CLASS (parent_class)->realize)(widget); - - mts = E_MEETING_TIME_SELECTOR (widget); - - mts->color_key_gc = gdk_gc_new (widget->window); -} - - -static void -e_meeting_time_selector_unrealize (GtkWidget *widget) -{ - EMeetingTimeSelector *mts; - - mts = E_MEETING_TIME_SELECTOR (widget); - - gdk_gc_unref (mts->color_key_gc); - mts->color_key_gc = NULL; - - if (GTK_WIDGET_CLASS (parent_class)->unrealize) - (*GTK_WIDGET_CLASS (parent_class)->unrealize)(widget); -} - - -static void -e_meeting_time_selector_style_set (GtkWidget *widget, - GtkStyle *previous_style) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorTime saved_time; - GdkFont *font; - gint hour, max_hour_width; - - if (GTK_WIDGET_CLASS (parent_class)->style_set) - (*GTK_WIDGET_CLASS (parent_class)->style_set)(widget, previous_style); - - mts = E_MEETING_TIME_SELECTOR (widget); - font = widget->style->font; - - /* Calculate the widths of the hour strings in the style's font. */ - max_hour_width = 0; - for (hour = 0; hour < 24; hour++) { - mts->hour_widths[hour] = gdk_string_width (font, EMeetingTimeSelectorHours[hour]); - max_hour_width = MAX (max_hour_width, mts->hour_widths[hour]); - } - - mts->row_height = font->ascent + font->descent - + E_MEETING_TIME_SELECTOR_TEXT_Y_PAD * 2 + 1; - mts->col_width = max_hour_width + 4; - - e_meeting_time_selector_save_position (mts, &saved_time); - e_meeting_time_selector_recalc_grid (mts); - e_meeting_time_selector_restore_position (mts, &saved_time); - - gtk_widget_set_usize (mts->display_top, -1, mts->row_height * 3); - gtk_widget_set_usize (mts->attendees_title_bar, -1, mts->row_height); - - GTK_LAYOUT (mts->display_main)->hadjustment->step_increment = mts->col_width; - GTK_LAYOUT (mts->display_main)->vadjustment->step_increment = mts->row_height; -} - - -/* This draws a shadow around the top display and main display. */ -static gint -e_meeting_time_selector_expose_event (GtkWidget *widget, - GdkEventExpose *event) -{ - EMeetingTimeSelector *mts; - - mts = E_MEETING_TIME_SELECTOR (widget); - - e_meeting_time_selector_draw_shadow (mts); - - if (GTK_WIDGET_CLASS (parent_class)->expose_event) - (*GTK_WIDGET_CLASS (parent_class)->expose_event)(widget, event); - - return FALSE; -} - - -static void -e_meeting_time_selector_draw (GtkWidget *widget, - GdkRectangle *area) -{ - EMeetingTimeSelector *mts; - - mts = E_MEETING_TIME_SELECTOR (widget); - - e_meeting_time_selector_draw_shadow (mts); - - if (GTK_WIDGET_CLASS (parent_class)->draw) - (*GTK_WIDGET_CLASS (parent_class)->draw)(widget, area); -} - - -static void -e_meeting_time_selector_draw_shadow (EMeetingTimeSelector *mts) -{ - GtkWidget *widget; - gint x, y, w, h; - - widget = GTK_WIDGET (mts); - - /* Draw the shadow around the attendees title bar and list. */ - x = mts->attendees_title_bar->allocation.x - 2; - y = mts->attendees_title_bar->allocation.y - 2; - w = mts->attendees_title_bar->allocation.width + 4; - h = mts->attendees_title_bar->allocation.height + mts->attendees_list->allocation.height + 4; - - gtk_draw_shadow (widget->style, widget->window, GTK_STATE_NORMAL, - GTK_SHADOW_IN, x, y, w, h); - - /* Draw the shadow around the graphical displays. */ - x = mts->display_top->allocation.x - 2; - y = mts->display_top->allocation.y - 2; - w = mts->display_top->allocation.width + 4; - h = mts->display_top->allocation.height + mts->display_main->allocation.height + 4; - - gtk_draw_shadow (widget->style, widget->window, GTK_STATE_NORMAL, - GTK_SHADOW_IN, x, y, w, h); -} - - -/* When the main canvas scrolls, we scroll the other canvases. */ -static void -e_meeting_time_selector_hadjustment_changed (GtkAdjustment *adjustment, - EMeetingTimeSelector *mts) -{ - GtkAdjustment *adj; - - adj = GTK_LAYOUT (mts->display_top)->hadjustment; - if (adj->value != adjustment->value) { - adj->value = adjustment->value; - gtk_adjustment_value_changed (adj); - } -} - - -static void -e_meeting_time_selector_vadjustment_changed (GtkAdjustment *adjustment, - EMeetingTimeSelector *mts) -{ - GtkAdjustment *adj; - - adj = GTK_LAYOUT (mts->attendees_list)->vadjustment; - if (adj->value != adjustment->value) { - adj->value = adjustment->value; - gtk_adjustment_value_changed (adj); - } -} - - -void -e_meeting_time_selector_get_meeting_time (EMeetingTimeSelector *mts, - gint *start_year, - gint *start_month, - gint *start_day, - gint *start_hour, - gint *start_minute, - gint *end_year, - gint *end_month, - gint *end_day, - gint *end_hour, - gint *end_minute) -{ - *start_year = g_date_year (&mts->meeting_start_time.date); - *start_month = g_date_month (&mts->meeting_start_time.date); - *start_day = g_date_day (&mts->meeting_start_time.date); - *start_hour = mts->meeting_start_time.hour; - *start_minute = mts->meeting_start_time.minute; - - *end_year = g_date_year (&mts->meeting_end_time.date); - *end_month = g_date_month (&mts->meeting_end_time.date); - *end_day = g_date_day (&mts->meeting_end_time.date); - *end_hour = mts->meeting_end_time.hour; - *end_minute = mts->meeting_end_time.minute; -} - - -gboolean -e_meeting_time_selector_set_meeting_time (EMeetingTimeSelector *mts, - gint start_year, - gint start_month, - gint start_day, - gint start_hour, - gint start_minute, - gint end_year, - gint end_month, - gint end_day, - gint end_hour, - gint end_minute) -{ - g_return_val_if_fail (IS_E_MEETING_TIME_SELECTOR (mts), FALSE); - - /* Check the dates are valid. */ - if (!g_date_valid_dmy (start_day, start_month, start_year) - || !g_date_valid_dmy (end_day, end_month, end_year) - || start_hour < 0 || start_hour > 23 - || end_hour < 0 || end_hour > 23 - || start_minute < 0 || start_minute > 59 - || end_minute < 0 || end_minute > 59) - return FALSE; - - g_date_set_dmy (&mts->meeting_start_time.date, start_day, start_month, - start_year); - mts->meeting_start_time.hour = start_hour; - mts->meeting_start_time.minute = start_minute; - g_date_set_dmy (&mts->meeting_end_time.date, end_day, end_month, - end_year); - mts->meeting_end_time.hour = end_hour; - mts->meeting_end_time.minute = end_minute; - - mts->meeting_positions_valid = FALSE; - - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - - /* Set the times in the GnomeDateEdit widgets. */ - e_meeting_time_selector_update_start_date_edit (mts); - e_meeting_time_selector_update_end_date_edit (mts); - - return TRUE; -} - - -void -e_meeting_time_selector_set_working_hours_only (EMeetingTimeSelector *mts, - gboolean working_hours_only) -{ - EMeetingTimeSelectorTime saved_time; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - - if (mts->working_hours_only == working_hours_only) - return; - - mts->working_hours_only = working_hours_only; - - e_meeting_time_selector_save_position (mts, &saved_time); - e_meeting_time_selector_recalc_grid (mts); - e_meeting_time_selector_restore_position (mts, &saved_time); - - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - e_meeting_time_selector_update_date_popup_menus (mts); -} - - -void -e_meeting_time_selector_set_working_hours (EMeetingTimeSelector *mts, - gint day_start_hour, - gint day_start_minute, - gint day_end_hour, - gint day_end_minute) -{ - EMeetingTimeSelectorTime saved_time; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - - if (mts->day_start_hour == day_start_hour - && mts->day_start_minute == day_start_minute - && mts->day_end_hour == day_end_hour - && mts->day_end_minute == day_end_minute) - return; - - mts->day_start_hour = day_start_hour; - mts->day_start_minute = day_start_minute; - mts->day_end_hour = day_end_hour; - mts->day_end_minute = day_end_minute; - - e_meeting_time_selector_save_position (mts, &saved_time); - e_meeting_time_selector_recalc_grid (mts); - e_meeting_time_selector_restore_position (mts, &saved_time); - - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - e_meeting_time_selector_update_date_popup_menus (mts); -} - - -void -e_meeting_time_selector_set_zoomed_out (EMeetingTimeSelector *mts, - gboolean zoomed_out) -{ - EMeetingTimeSelectorTime saved_time; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - - if (mts->zoomed_out == zoomed_out) - return; - - mts->zoomed_out = zoomed_out; - - e_meeting_time_selector_save_position (mts, &saved_time); - e_meeting_time_selector_recalc_grid (mts); - e_meeting_time_selector_restore_position (mts, &saved_time); - - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); -} - - -EMeetingTimeSelectorAutopickOption -e_meeting_time_selector_get_autopick_option (EMeetingTimeSelector *mts) -{ - if (GTK_CHECK_MENU_ITEM (mts->autopick_all_item)->active) - return E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_RESOURCES; - if (GTK_CHECK_MENU_ITEM (mts->autopick_all_people_one_resource_item)->active) - return E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_ONE_RESOURCE; - if (GTK_CHECK_MENU_ITEM (mts->autopick_required_people_item)->active) - return E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE; - return E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE_AND_ONE_RESOURCE; -} - - -void -e_meeting_time_selector_set_autopick_option (EMeetingTimeSelector *mts, - EMeetingTimeSelectorAutopickOption autopick_option) -{ - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - - switch (autopick_option) { - case E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_RESOURCES: - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mts->autopick_all_item), TRUE); - break; - case E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_ONE_RESOURCE: - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mts->autopick_all_people_one_resource_item), TRUE); - break; - case E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE: - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mts->autopick_required_people_item), TRUE); - break; - case E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE_AND_ONE_RESOURCE: - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (mts->autopick_required_people_one_resource_item), TRUE); - break; - } -} - - -/* Adds an attendee to the list, returning the row. The data is meant for - something like an address book id, though if the user edits the name this - will become invalid. We'll probably have to handle address book lookup - ourself. */ -gint -e_meeting_time_selector_attendee_add (EMeetingTimeSelector *mts, - gchar *attendee_name, - gpointer data) -{ - EMeetingTimeSelectorAttendee attendee; - gint list_width, item_width; - GdkFont *font; - - g_return_val_if_fail (IS_E_MEETING_TIME_SELECTOR (mts), -1); - g_return_val_if_fail (attendee_name != NULL, -1); - - attendee.name = g_strdup (attendee_name); - attendee.type = E_MEETING_TIME_SELECTOR_REQUIRED_PERSON; - attendee.has_calendar_info = FALSE; - attendee.send_meeting_to = TRUE; - g_date_clear (&attendee.busy_periods_start.date, 1); - attendee.busy_periods_start.hour = 0; - attendee.busy_periods_start.minute = 0; - g_date_clear (&attendee.busy_periods_end.date, 1); - attendee.busy_periods_end.hour = 0; - attendee.busy_periods_end.minute = 0; - attendee.busy_periods = g_array_new (FALSE, FALSE, - sizeof (EMeetingTimeSelectorPeriod)); - attendee.busy_periods_sorted = TRUE; - attendee.longest_period_in_days = 0; - attendee.data = data; - - /* Add to the list on the left. */ - list_width = GTK_WIDGET (mts->attendees_list)->allocation.width; - item_width = MAX (1, list_width - E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH - E_MEETING_TIME_SELECTOR_TEXT_X_PAD * 2); - font = GTK_WIDGET (mts)->style->font; - attendee.text_item = gnome_canvas_item_new - (GNOME_CANVAS_GROUP (GNOME_CANVAS (mts->attendees_list)->root), - e_text_get_type (), - "font_gdk", font, - "anchor", GTK_ANCHOR_NW, - "clip", TRUE, - "max_lines", 1, - "editable", TRUE, - "text", attendee_name ? attendee_name : "", - "clip_width", (gdouble) item_width, - "clip_height", (gdouble) font->ascent + font->descent, - NULL); - - e_canvas_item_move_absolute(attendee.text_item, - E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH - + E_MEETING_TIME_SELECTOR_TEXT_X_PAD, - mts->attendees->len * mts->row_height + 1 - + E_MEETING_TIME_SELECTOR_TEXT_Y_PAD); -#if 0 - gnome_canvas_item_hide (attendee.text_item); -#endif - - gtk_signal_connect (GTK_OBJECT (attendee.text_item), "event", - GTK_SIGNAL_FUNC (e_meeting_time_selector_on_text_item_event), - mts); - - g_array_append_val (mts->attendees, attendee); - - /* Update the scroll region. */ - e_meeting_time_selector_update_attendees_list_scroll_region (mts); - e_meeting_time_selector_update_main_canvas_scroll_region (mts); - - /* Redraw the canvases. */ - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - - - return mts->attendees->len - 1; -} - - -gint -e_meeting_time_selector_attendee_find_by_name (EMeetingTimeSelector *mts, - gchar *attendee_name, - gint start_row) -{ - EMeetingTimeSelectorAttendee *attendee; - gint row; - - g_return_val_if_fail (IS_E_MEETING_TIME_SELECTOR (mts), -1); - g_return_val_if_fail (start_row >= 0, -1); - g_return_val_if_fail (start_row < mts->attendees->len, -1); - - for (row = start_row; row < mts->attendees->len; row++) { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - if (!strcmp (attendee->name, attendee_name)) - return row; - } - - return -1; -} - - -gint -e_meeting_time_selector_attendee_find_by_data (EMeetingTimeSelector *mts, - gpointer data, - gint start_row) -{ - EMeetingTimeSelectorAttendee *attendee; - gint row; - - g_return_val_if_fail (IS_E_MEETING_TIME_SELECTOR (mts), -1); - g_return_val_if_fail (start_row >= 0, -1); - g_return_val_if_fail (start_row < mts->attendees->len, -1); - - for (row = start_row; row < mts->attendees->len; row++) { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - if (attendee->data == data) - return row; - } - - return -1; -} - - -void -e_meeting_time_selector_attendee_remove (EMeetingTimeSelector *mts, - gint row) -{ - EMeetingTimeSelectorAttendee *attendee; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - g_return_if_fail (row >= 0); - g_return_if_fail (row < mts->attendees->len); - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - - g_free (attendee->name); - g_array_free (attendee->busy_periods, TRUE); - - /* Destroy the GtkEntry in the list. */ - gtk_object_destroy (GTK_OBJECT (attendee->text_item)); - - g_array_remove_index (mts->attendees, row); - - /* Update the positions of all the other GtkEntry widgets. */ - e_meeting_time_selector_update_attendees_list_positions (mts); - - e_meeting_time_selector_update_attendees_list_scroll_region (mts); - e_meeting_time_selector_update_main_canvas_scroll_region (mts); - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); -} - - -void -e_meeting_time_selector_attendee_set_type (EMeetingTimeSelector *mts, - gint row, - EMeetingTimeSelectorAttendeeType type) -{ - EMeetingTimeSelectorAttendee *attendee; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - g_return_if_fail (row >= 0); - g_return_if_fail (row < mts->attendees->len); - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - attendee->type = type; -} - - -void -e_meeting_time_selector_attendee_set_has_calendar_info (EMeetingTimeSelector *mts, - gint row, - gboolean has_calendar_info) -{ - EMeetingTimeSelectorAttendee *attendee; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - g_return_if_fail (row >= 0); - g_return_if_fail (row < mts->attendees->len); - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - attendee->has_calendar_info = has_calendar_info; -} - - -void -e_meeting_time_selector_attendee_set_send_meeting_to (EMeetingTimeSelector *mts, - gint row, - gboolean send_meeting_to) -{ - EMeetingTimeSelectorAttendee *attendee; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - g_return_if_fail (row >= 0); - g_return_if_fail (row < mts->attendees->len); - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - attendee->send_meeting_to = send_meeting_to; -} - - -gboolean -e_meeting_time_selector_attendee_set_busy_range (EMeetingTimeSelector *mts, - gint row, - gint start_year, - gint start_month, - gint start_day, - gint start_hour, - gint start_minute, - gint end_year, - gint end_month, - gint end_day, - gint end_hour, - gint end_minute) -{ - EMeetingTimeSelectorAttendee *attendee; - - g_return_val_if_fail (IS_E_MEETING_TIME_SELECTOR (mts), FALSE); - g_return_val_if_fail (row >= 0, FALSE); - g_return_val_if_fail (row < mts->attendees->len, FALSE); - - /* Check the dates are valid. */ - if (!g_date_valid_dmy (start_day, start_month, start_year)) - return FALSE; - if (!g_date_valid_dmy (end_day, end_month, end_year)) - return FALSE; - if (start_hour < 0 || start_hour > 23) - return FALSE; - if (end_hour < 0 || end_hour > 23) - return FALSE; - if (start_minute < 0 || start_minute > 59) - return FALSE; - if (end_minute < 0 || end_minute > 59) - return FALSE; - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - - g_date_clear (&attendee->busy_periods_start.date, 1); - g_date_clear (&attendee->busy_periods_end.date, 1); - g_date_set_dmy (&attendee->busy_periods_start.date, - start_day, start_month, start_year); - g_date_set_dmy (&attendee->busy_periods_end.date, - end_day, end_month, end_year); - attendee->busy_periods_start.hour = start_hour; - attendee->busy_periods_start.minute = start_minute; - attendee->busy_periods_end.hour = end_hour; - attendee->busy_periods_end.minute = end_minute; - - return TRUE; -} - - -/* Clears all busy times for the given attendee. */ -void -e_meeting_time_selector_attendee_clear_busy_periods (EMeetingTimeSelector *mts, - gint row) -{ - EMeetingTimeSelectorAttendee *attendee; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - g_return_if_fail (row >= 0); - g_return_if_fail (row < mts->attendees->len); - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - - g_array_set_size (attendee->busy_periods, 0); - attendee->busy_periods_sorted = TRUE; - attendee->longest_period_in_days = 0; -} - - -/* Adds one busy time for the given attendee. It returns FALSE if the date - or time is invalid. Months and days count from 1. */ -gboolean -e_meeting_time_selector_attendee_add_busy_period (EMeetingTimeSelector *mts, - gint row, - gint start_year, - gint start_month, - gint start_day, - gint start_hour, - gint start_minute, - gint end_year, - gint end_month, - gint end_day, - gint end_hour, - gint end_minute, - EMeetingTimeSelectorBusyType busy_type) -{ - EMeetingTimeSelectorAttendee *attendee; - EMeetingTimeSelectorPeriod period; - gint period_in_days; - - g_return_val_if_fail (IS_E_MEETING_TIME_SELECTOR (mts), FALSE); - g_return_val_if_fail (row >= 0, FALSE); - g_return_val_if_fail (row < mts->attendees->len, FALSE); - g_return_val_if_fail (busy_type >= 0, FALSE); - g_return_val_if_fail (busy_type < E_MEETING_TIME_SELECTOR_BUSY_LAST, FALSE); - - /* Check the dates are valid. */ - if (!g_date_valid_dmy (start_day, start_month, start_year)) - return FALSE; - if (!g_date_valid_dmy (end_day, end_month, end_year)) - return FALSE; - if (start_hour < 0 || start_hour > 23) - return FALSE; - if (end_hour < 0 || end_hour > 23) - return FALSE; - if (start_minute < 0 || start_minute > 59) - return FALSE; - if (end_minute < 0 || end_minute > 59) - return FALSE; - - g_date_clear (&period.start.date, 1); - g_date_clear (&period.end.date, 1); - g_date_set_dmy (&period.start.date, start_day, start_month, start_year); - g_date_set_dmy (&period.end.date, end_day, end_month, end_year); - period.start.hour = start_hour; - period.start.minute = start_minute; - period.end.hour = end_hour; - period.end.minute = end_minute; - period.busy_type = busy_type; - - /* Check that the start time is before or equal to the end time. */ - if (e_meeting_time_selector_compare_times (&period.start, &period.end) > 0) - return FALSE; - - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - g_array_append_val (attendee->busy_periods, period); - attendee->has_calendar_info = TRUE; - attendee->busy_periods_sorted = FALSE; - - period_in_days = g_date_julian (&period.end.date) - g_date_julian (&period.start.date) + 1; - attendee->longest_period_in_days = MAX (attendee->longest_period_in_days, period_in_days); - - return TRUE; -} - - -void -e_meeting_time_selector_attendee_ensure_periods_sorted (EMeetingTimeSelector *mts, - EMeetingTimeSelectorAttendee *attendee) -{ - if (attendee->busy_periods_sorted) - return; - - qsort (attendee->busy_periods->data, attendee->busy_periods->len, - sizeof (EMeetingTimeSelectorPeriod), - e_meeting_time_selector_compare_period_starts); - attendee->busy_periods_sorted = TRUE; -} - - -/* This compares two time periods, using their end times. */ -static gint -e_meeting_time_selector_compare_period_starts (const void *arg1, - const void *arg2) -{ - EMeetingTimeSelectorPeriod *period1, *period2; - - period1 = (EMeetingTimeSelectorPeriod *) arg1; - period2 = (EMeetingTimeSelectorPeriod *) arg2; - - return e_meeting_time_selector_compare_times (&period1->start, - &period2->start); -} - - -/* This compares two time periods, using start and end times, mainly to see if - they overlap at all. If they overlap it returns 0. Or -1 if arg1 < arg2. - Or 1 if arg1 > arg2. */ -/* Currently unused. */ -#if 0 -static gint -e_meeting_time_selector_compare_periods (const void *arg1, - const void *arg2) -{ - EMeetingTimeSelectorPeriod *period1, *period2; - - period1 = (EMeetingTimeSelectorPeriod *) arg1; - period2 = (EMeetingTimeSelectorPeriod *) arg2; - - /* If period 2 starts after period 1 ends, return 1. */ - if (e_meeting_time_selector_compare_times (&period2->start, &period1->end) >= 0) - return 1; - - /* If period 1 starts after period 2 ends, return -1. */ - if (e_meeting_time_selector_compare_times (&period1->start, &period2->end) >= 0) - return -1; - - /* They must overlap so return 0. */ - return 0; -} -#endif - - -static gint -e_meeting_time_selector_compare_times (EMeetingTimeSelectorTime *time1, - EMeetingTimeSelectorTime *time2) -{ - gint day_comparison; - - day_comparison = g_date_compare (&time1->date, - &time2->date); - if (day_comparison != 0) - return day_comparison; - - if (time1->hour < time2->hour) - return -1; - if (time1->hour > time2->hour) - return 1; - - if (time1->minute < time2->minute) - return -1; - if (time1->minute > time2->minute) - return 1; - - /* The start times are exactly the same. */ - return 0; -} - - -/* - * DEBUGGING ROUTINES - functions to output various bits of data. - */ - -#ifdef E_MEETING_TIME_SELECTOR_DEBUG - -/* Debugging function to dump information on all attendees. */ -void -e_meeting_time_selector_dump (EMeetingTimeSelector *mts) -{ - EMeetingTimeSelectorAttendee *attendee; - EMeetingTimeSelectorPeriod *period; - gint row, period_num; - gchar buffer[128]; - - g_return_if_fail (IS_E_MEETING_TIME_SELECTOR (mts)); - - g_print ("\n\nAttendee Information:\n"); - - for (row = 0; row < mts->attendees->len; row++) { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - g_print ("Attendee: %s\n", attendee->name); - g_print (" Longest Busy Period: %i days\n", - attendee->longest_period_in_days); - - e_meeting_time_selector_attendee_ensure_periods_sorted (mts, attendee); -#if 1 - for (period_num = 0; - period_num < attendee->busy_periods->len; - period_num++) { - period = &g_array_index (attendee->busy_periods, - EMeetingTimeSelectorPeriod, - period_num); - - g_date_strftime (buffer, 128, "%A, %B %d, %Y", - &period->start.date); - g_print (" Start: %s %i:%02i\n", buffer, - period->start.hour, period->start.minute); - - g_date_strftime (buffer, 128, "%A, %B %d, %Y", - &period->end.date); - g_print (" End : %s %i:%02i\n", buffer, - period->end.hour, period->end.minute); - } -#endif - } - -} - - -/* This formats a EMeetingTimeSelectorTime in a string and returns it. - Note that it uses a static buffer. */ -gchar* -e_meeting_time_selector_dump_time (EMeetingTimeSelectorTime *mtstime) -{ - static gchar buffer[128]; - - gchar buffer2[128]; - - g_date_strftime (buffer, 128, "%A, %B %d, %Y", &mtstime->date); - sprintf (buffer2, " at %i:%02i", (gint) mtstime->hour, - (gint) mtstime->minute); - strcat (buffer, buffer2); - - return buffer; -} - - -/* This formats a GDate in a string and returns it. - Note that it uses a static buffer. */ -gchar* -e_meeting_time_selector_dump_date (GDate *date) -{ - static gchar buffer[128]; - - g_date_strftime (buffer, 128, "%A, %B %d, %Y", date); - return buffer; -} - -#endif /* E_MEETING_TIME_SELECTOR_DEBUG */ - - -static void -e_meeting_time_selector_on_invite_others_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - - -} - - -static void -e_meeting_time_selector_on_options_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - gtk_menu_popup (GTK_MENU (mts->options_menu), NULL, NULL, - e_meeting_time_selector_options_menu_position_callback, - mts, 1, GDK_CURRENT_TIME); -} - - -static void -e_meeting_time_selector_options_menu_position_callback (GtkMenu *menu, - gint *x, - gint *y, - gpointer user_data) -{ - EMeetingTimeSelector *mts; - GtkRequisition menu_requisition; - gint max_x, max_y; - - mts = E_MEETING_TIME_SELECTOR (user_data); - - /* Calculate our preferred position. */ - gdk_window_get_origin (mts->options_button->window, x, y); - *y += mts->options_button->allocation.height; - - /* Now make sure we are on the screen. */ - gtk_widget_size_request (mts->options_menu, &menu_requisition); - max_x = MAX (0, gdk_screen_width () - menu_requisition.width); - max_y = MAX (0, gdk_screen_height () - menu_requisition.height); - *x = CLAMP (*x, 0, max_x); - *y = CLAMP (*y, 0, max_y); -} - - -static void -e_meeting_time_selector_on_update_free_busy (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - - /* Make sure the menu pops down, which doesn't happen by default if - keyboard accelerators are used. */ - if (GTK_WIDGET_VISIBLE (mts->options_menu)) - gtk_menu_popdown (GTK_MENU (mts->options_menu)); -} - - -static void -e_meeting_time_selector_on_autopick_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - gtk_menu_popup (GTK_MENU (mts->autopick_menu), NULL, NULL, - e_meeting_time_selector_autopick_menu_position_callback, - mts, 1, GDK_CURRENT_TIME); -} - - -static void -e_meeting_time_selector_autopick_menu_position_callback (GtkMenu *menu, - gint *x, - gint *y, - gpointer user_data) -{ - EMeetingTimeSelector *mts; - GtkRequisition menu_requisition; - gint max_x, max_y; - - mts = E_MEETING_TIME_SELECTOR (user_data); - - /* Calculate our preferred position. */ - gdk_window_get_origin (mts->autopick_button->window, x, y); - *y += mts->autopick_button->allocation.height; - - /* Now make sure we are on the screen. */ - gtk_widget_size_request (mts->autopick_menu, &menu_requisition); - max_x = MAX (0, gdk_screen_width () - menu_requisition.width); - max_y = MAX (0, gdk_screen_height () - menu_requisition.height); - *x = CLAMP (*x, 0, max_x); - *y = CLAMP (*y, 0, max_y); -} - - -static void -e_meeting_time_selector_on_autopick_option_toggled (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - /* Make sure the menu pops down, which doesn't happen by default if - keyboard accelerators are used. */ - if (GTK_WIDGET_VISIBLE (mts->autopick_menu)) - gtk_menu_popdown (GTK_MENU (mts->autopick_menu)); -} - - -static void -e_meeting_time_selector_on_prev_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - e_meeting_time_selector_autopick (mts, FALSE); -} - - -static void -e_meeting_time_selector_on_next_button_clicked (GtkWidget *button, - EMeetingTimeSelector *mts) -{ - e_meeting_time_selector_autopick (mts, TRUE); -} - - -/* This tries to find the previous or next meeting time for which all - attendees will be available. */ -static void -e_meeting_time_selector_autopick (EMeetingTimeSelector *mts, - gboolean forward) -{ - EMeetingTimeSelectorTime start_time, end_time, *resource_free; - EMeetingTimeSelectorAttendee *attendee; - EMeetingTimeSelectorPeriod *period; - EMeetingTimeSelectorAutopickOption autopick_option; - gint duration_days, duration_hours, duration_minutes, row; - gboolean meeting_time_ok, skip_optional = FALSE; - gboolean need_one_resource = FALSE, found_resource; - - /* Get the current meeting duration in days + hours + minutes. */ - e_meeting_time_selector_calculate_time_difference (&mts->meeting_start_time, &mts->meeting_end_time, &duration_days, &duration_hours, &duration_minutes); - - /* Find the first appropriate start time. */ - start_time = mts->meeting_start_time; - if (forward) - e_meeting_time_selector_find_nearest_interval (mts, &start_time, &end_time, duration_days, duration_hours, duration_minutes); - else - e_meeting_time_selector_find_nearest_interval_backward (mts, &start_time, &end_time, duration_days, duration_hours, duration_minutes); - - /* Determine if we can skip optional people and if we only need one - resource based on the autopick option. */ - autopick_option = e_meeting_time_selector_get_autopick_option (mts); - if (autopick_option == E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE - || autopick_option == E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE_AND_ONE_RESOURCE) - skip_optional = TRUE; - if (autopick_option == E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_ONE_RESOURCE - || autopick_option == E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE_AND_ONE_RESOURCE) - need_one_resource = TRUE; - - /* Keep moving forward or backward until we find a possible meeting - time. */ - for (;;) { - meeting_time_ok = TRUE; - found_resource = FALSE; - resource_free = NULL; - - /* Step through each attendee, checking if the meeting time - intersects one of the attendees busy periods. */ - for (row = 0; row < mts->attendees->len; row++) { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, - row); - - /* Skip optional people if they don't matter. */ - if (skip_optional && attendee->type == E_MEETING_TIME_SELECTOR_OPTIONAL_PERSON) - continue; - - period = e_meeting_time_selector_find_time_clash (mts, attendee, &start_time, &end_time); - - if (need_one_resource && attendee->type == E_MEETING_TIME_SELECTOR_RESOURCE) { - if (period) { - /* We want to remember the closest - prev/next time that one resource is - available, in case we don't find any - free resources. */ - if (forward) { - if (!resource_free || e_meeting_time_selector_compare_times (resource_free, &period->end) > 0) - resource_free = &period->end; - } else { - if (!resource_free || e_meeting_time_selector_compare_times (resource_free, &period->start) < 0) - resource_free = &period->start; - } - - } else { - found_resource = TRUE; - } - } else if (period) { - /* Skip the period which clashed. */ - if (forward) { - start_time = period->end; - } else { - start_time = period->start; - e_meeting_time_selector_adjust_time (&start_time, -duration_days, -duration_hours, -duration_minutes); - } - meeting_time_ok = FALSE; - break; - } - } - - /* Check that we found one resource if necessary. If not, skip - to the closest time that a resource is free. Note that if - there are no resources, resource_free will never get set, - so we assume the meeting time is OK. */ - if (meeting_time_ok && need_one_resource && !found_resource - && resource_free) { - if (forward) { - start_time = *resource_free; - } else { - start_time = *resource_free; - e_meeting_time_selector_adjust_time (&start_time, -duration_days, -duration_hours, -duration_minutes); - } - meeting_time_ok = FALSE; - } - - if (meeting_time_ok) { - mts->meeting_start_time = start_time; - mts->meeting_end_time = end_time; - mts->meeting_positions_valid = FALSE; - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - - /* Make sure the time is shown. */ - e_meeting_time_selector_ensure_meeting_time_shown (mts); - - /* Set the times in the GnomeDateEdit widgets. */ - e_meeting_time_selector_update_start_date_edit (mts); - e_meeting_time_selector_update_end_date_edit (mts); - return; - } - - /* Move forward to the next possible interval. */ - if (forward) - e_meeting_time_selector_find_nearest_interval (mts, &start_time, &end_time, duration_days, duration_hours, duration_minutes); - else - e_meeting_time_selector_find_nearest_interval_backward (mts, &start_time, &end_time, duration_days, duration_hours, duration_minutes); - } -} - - -static void -e_meeting_time_selector_calculate_time_difference (EMeetingTimeSelectorTime *start, - EMeetingTimeSelectorTime *end, - gint *days, - gint *hours, - gint *minutes) -{ - *days = g_date_julian (&end->date) - g_date_julian (&start->date); - *hours = end->hour - start->hour; - *minutes = end->minute - start->minute; - if (*minutes < 0) { - *minutes += 60; - *hours = *hours - 1; - } - if (*hours < 0) { - *hours += 24; - *days = *days - 1; - } -} - - -/* This moves the given time forward to the next suitable start of a meeting. - If zoomed_out is set, this means every hour. If not every half-hour. */ -static void -e_meeting_time_selector_find_nearest_interval (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *start_time, - EMeetingTimeSelectorTime *end_time, - gint days, gint hours, gint mins) -{ - gint minutes_shown; - gboolean set_to_start_of_working_day = FALSE; - - if (mts->zoomed_out) { - start_time->hour++; - start_time->minute = 0; - } else { - start_time->minute += 30; - start_time->minute -= start_time->minute % 30; - } - e_meeting_time_selector_fix_time_overflows (start_time); - - *end_time = *start_time; - e_meeting_time_selector_adjust_time (end_time, days, hours, mins); - - /* Check if the interval is less than a day as seen in the display. - If it isn't we don't worry about the working day. */ - if (!mts->working_hours_only || days > 0) - return; - minutes_shown = (mts->day_end_hour - mts->day_start_hour) * 60; - minutes_shown += mts->day_end_minute - mts->day_start_minute; - if (hours * 60 + mins > minutes_shown) - return; - - /* If the meeting time finishes past the end of the working day, move - onto the start of the next working day. If the meeting time starts - before the working day, move it on as well. */ - if (start_time->hour > mts->day_end_hour - || (start_time->hour == mts->day_end_hour - && start_time->minute > mts->day_end_minute) - || end_time->hour > mts->day_end_hour - || (end_time->hour == mts->day_end_hour - && end_time->minute > mts->day_end_minute)) { - g_date_add_days (&start_time->date, 1); - set_to_start_of_working_day = TRUE; - } else if (start_time->hour < mts->day_start_hour - || (start_time->hour == mts->day_start_hour - && start_time->minute < mts->day_start_minute)) { - set_to_start_of_working_day = TRUE; - } - - if (set_to_start_of_working_day) { - start_time->hour = mts->day_start_hour; - start_time->minute = mts->day_start_minute; - - if (mts->zoomed_out) { - if (start_time->minute > 0) { - start_time->hour++; - start_time->minute = 0; - } - } else { - start_time->minute += 29; - start_time->minute -= start_time->minute % 30; - } - e_meeting_time_selector_fix_time_overflows (start_time); - - *end_time = *start_time; - e_meeting_time_selector_adjust_time (end_time, days, hours, mins); - } -} - - -/* This moves the given time backward to the next suitable start of a meeting. - If zoomed_out is set, this means every hour. If not every half-hour. */ -static void -e_meeting_time_selector_find_nearest_interval_backward (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *start_time, - EMeetingTimeSelectorTime *end_time, - gint days, gint hours, gint mins) -{ - gint new_hour, minutes_shown; - gboolean set_to_end_of_working_day = FALSE; - - new_hour = start_time->hour; - if (mts->zoomed_out) { - if (start_time->minute == 0) - new_hour--; - start_time->minute = 0; - } else { - if (start_time->minute == 0) { - start_time->minute = 30; - new_hour--; - } else if (start_time->minute <= 30) - start_time->minute = 0; - else - start_time->minute = 30; - } - if (new_hour < 0) { - new_hour += 24; - g_date_subtract_days (&start_time->date, 1); - } - start_time->hour = new_hour; - - *end_time = *start_time; - e_meeting_time_selector_adjust_time (end_time, days, hours, mins); - - /* Check if the interval is less than a day as seen in the display. - If it isn't we don't worry about the working day. */ - if (!mts->working_hours_only || days > 0) - return; - minutes_shown = (mts->day_end_hour - mts->day_start_hour) * 60; - minutes_shown += mts->day_end_minute - mts->day_start_minute; - if (hours * 60 + mins > minutes_shown) - return; - - /* If the meeting time finishes past the end of the working day, move - back to the end of the working day. If the meeting time starts - before the working day, move it back to the end of the previous - working day. */ - if (start_time->hour > mts->day_end_hour - || (start_time->hour == mts->day_end_hour - && start_time->minute > mts->day_end_minute) - || end_time->hour > mts->day_end_hour - || (end_time->hour == mts->day_end_hour - && end_time->minute > mts->day_end_minute)) { - set_to_end_of_working_day = TRUE; - } else if (start_time->hour < mts->day_start_hour - || (start_time->hour == mts->day_start_hour - && start_time->minute < mts->day_start_minute)) { - g_date_subtract_days (&end_time->date, 1); - set_to_end_of_working_day = TRUE; - } - - if (set_to_end_of_working_day) { - end_time->hour = mts->day_end_hour; - end_time->minute = mts->day_end_minute; - *start_time = *end_time; - e_meeting_time_selector_adjust_time (start_time, -days, -hours, -mins); - - if (mts->zoomed_out) { - start_time->minute = 0; - } else { - start_time->minute -= start_time->minute % 30; - } - - *end_time = *start_time; - e_meeting_time_selector_adjust_time (end_time, days, hours, mins); - } -} - - -/* This adds on the given days, hours & minutes to a EMeetingTimeSelectorTime. - It is used to calculate the end of a period given a start & duration. - Days, hours & minutes can be negative, to move backwards, but they should - be within normal ranges, e.g. hours should be between -23 and 23. */ -static void -e_meeting_time_selector_adjust_time (EMeetingTimeSelectorTime *mtstime, - gint days, gint hours, gint minutes) -{ - gint new_hours, new_minutes; - - /* We have to handle negative values for hous and minutes here, since - EMeetingTimeSelectorTime uses guint8s to store them. */ - new_minutes = mtstime->minute + minutes; - if (new_minutes < 0) { - new_minutes += 60; - hours -= 1; - } - - new_hours = mtstime->hour + hours; - if (new_hours < 0) { - new_hours += 24; - days -= 1; - } - - g_date_add_days (&mtstime->date, days); - mtstime->hour = new_hours; - mtstime->minute = new_minutes; - - e_meeting_time_selector_fix_time_overflows (mtstime); -} - - -/* This looks for any busy period of the given attendee which clashes with - the start and end time. It uses a binary search. */ -static EMeetingTimeSelectorPeriod* -e_meeting_time_selector_find_time_clash (EMeetingTimeSelector *mts, - EMeetingTimeSelectorAttendee *attendee, - EMeetingTimeSelectorTime *start_time, - EMeetingTimeSelectorTime *end_time) -{ - EMeetingTimeSelectorPeriod *period; - gint period_num; - - period_num = e_meeting_time_selector_find_first_busy_period (mts, attendee, &start_time->date); - - if (period_num == -1) - return NULL; - - /* Step forward through the busy periods until we find a clash or we - go past the end_time. */ - while (period_num < attendee->busy_periods->len) { - period = &g_array_index (attendee->busy_periods, - EMeetingTimeSelectorPeriod, - period_num); - - /* If the period starts at or after the end time, there is no - clash and we are finished. The busy periods are sorted by - their start times, so all the rest will be later. */ - if (e_meeting_time_selector_compare_times (&period->start, - end_time) >= 0) - return NULL; - - /* If the period ends after the start time, we have found a - clash. From the above test we already know the busy period - isn't completely after the meeting time. */ - if (e_meeting_time_selector_compare_times (&period->end, - start_time) > 0) { - return period; - } - - period_num++; - } - - return NULL; -} - - -/* This subtracts the attendees longest_period_in_days from the given date, - and does a binary search of the attendee's busy periods array to find the - first one which could possible end on the given day or later. - If none are found it returns -1. */ -gint -e_meeting_time_selector_find_first_busy_period (EMeetingTimeSelector *mts, - EMeetingTimeSelectorAttendee *attendee, - GDate *date) -{ - EMeetingTimeSelectorPeriod *period; - gint lower, upper, middle = 0, cmp = 0; - GDate tmp_date; - - /* Make sure the busy periods have been sorted. */ - e_meeting_time_selector_attendee_ensure_periods_sorted (mts, attendee); - - /* Calculate the first day which could have a busy period which - continues onto our given date. */ - tmp_date = *date; - g_date_subtract_days (&tmp_date, attendee->longest_period_in_days); - - /* We want the first busy period which starts on tmp_date. */ - lower = 0; - upper = attendee->busy_periods->len; - - if (upper == 0) - return -1; - - while (lower < upper) { - middle = (lower + upper) >> 1; - - period = &g_array_index (attendee->busy_periods, - EMeetingTimeSelectorPeriod, middle); - - cmp = g_date_compare (&tmp_date, &period->start.date); - - if (cmp == 0) - break; - else if (cmp < 0) - upper = middle; - else - lower = middle + 1; - } - - /* There may be several busy periods on the same day so we step - backwards to the first one. */ - if (cmp == 0) { - while (middle > 0) { - period = &g_array_index (attendee->busy_periods, - EMeetingTimeSelectorPeriod, middle - 1); - if (g_date_compare (&tmp_date, &period->start.date) != 0) - break; - middle--; - } - } else if (cmp > 0) { - /* This means we couldn't find a period on the given day, and - the last one we looked at was before it, so if there are - any more periods after this one we return it. */ - middle++; - if (attendee->busy_periods->len <= middle) - return -1; - } - - return middle; -} - - -static void -e_meeting_time_selector_on_zoomed_out_toggled (GtkWidget *menuitem, - EMeetingTimeSelector *mts) -{ - /* Make sure the menu pops down, which doesn't happen by default if - keyboard accelerators are used. */ - if (GTK_WIDGET_VISIBLE (mts->options_menu)) - gtk_menu_popdown (GTK_MENU (mts->options_menu)); - - e_meeting_time_selector_set_zoomed_out (mts, GTK_CHECK_MENU_ITEM (menuitem)->active); -} - - -static void -e_meeting_time_selector_on_working_hours_toggled (GtkWidget *menuitem, - EMeetingTimeSelector *mts) -{ - /* Make sure the menu pops down, which doesn't happen by default if - keyboard accelerators are used. */ - if (GTK_WIDGET_VISIBLE (mts->options_menu)) - gtk_menu_popdown (GTK_MENU (mts->options_menu)); - - e_meeting_time_selector_set_working_hours_only (mts, GTK_CHECK_MENU_ITEM (menuitem)->active); -} - - -/* This recalculates day_width, first_hour_shown and last_hour_shown. */ -static void -e_meeting_time_selector_recalc_grid (EMeetingTimeSelector *mts) -{ - if (mts->working_hours_only) { - mts->first_hour_shown = mts->day_start_hour; - mts->last_hour_shown = mts->day_end_hour; - if (mts->day_end_minute != 0) - mts->last_hour_shown += 1; - } else { - mts->first_hour_shown = 0; - mts->last_hour_shown = 24; - } - - /* In the brief view we use the nearest hours divisible by 3. */ - if (mts->zoomed_out) { - mts->first_hour_shown -= mts->first_hour_shown % 3; - mts->last_hour_shown += 2; - mts->last_hour_shown -= mts->last_hour_shown % 3; - } - - mts->day_width = mts->col_width * (mts->last_hour_shown - mts->first_hour_shown); - if (mts->zoomed_out) - mts->day_width /= 3; - - /* Add one pixel for the extra vertical grid line. */ - mts->day_width++; - - gnome_canvas_set_scroll_region (GNOME_CANVAS (mts->display_top), - 0, 0, - mts->day_width * E_MEETING_TIME_SELECTOR_DAYS_SHOWN, - mts->row_height * 3); - e_meeting_time_selector_update_main_canvas_scroll_region (mts); - - e_meeting_time_selector_recalc_date_format (mts); - mts->meeting_positions_valid = FALSE; -} - - -/* This saves the first visible time in the given EMeetingTimeSelectorTime. */ -static void -e_meeting_time_selector_save_position (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *mtstime) -{ - gint scroll_x, scroll_y; - - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (mts->display_main), - &scroll_x, &scroll_y); - e_meeting_time_selector_calculate_time (mts, scroll_x, mtstime); -} - - -/* This restores a saved position. */ -static void -e_meeting_time_selector_restore_position (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *mtstime) -{ - gint scroll_x, scroll_y, new_scroll_x; - - new_scroll_x = e_meeting_time_selector_calculate_time_position (mts, - mtstime); - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (mts->display_main), - &scroll_x, &scroll_y); - gnome_canvas_scroll_to (GNOME_CANVAS (mts->display_main), - new_scroll_x, scroll_y); -} - - -/* This returns the x pixel coords of the meeting time in the entire scroll - region. It recalculates them if they have been marked as invalid. - If it returns FALSE then no meeting time is set or the meeting time is - not visible in the current scroll area. */ -gboolean -e_meeting_time_selector_get_meeting_time_positions (EMeetingTimeSelector *mts, - gint *start_x, - gint *end_x) -{ - if (mts->meeting_positions_valid) { - if (mts->meeting_positions_in_scroll_area) { - *start_x = mts->meeting_start_x; - *end_x = mts->meeting_end_x; - return TRUE; - } else { - return FALSE; - } - } - - mts->meeting_positions_valid = TRUE; - - /* Check if the days aren't in our current range. */ - if (g_date_compare (&mts->meeting_start_time.date, &mts->last_date_shown) > 0 - || g_date_compare (&mts->meeting_end_time.date, &mts->first_date_shown) < 0) { - mts->meeting_positions_in_scroll_area = FALSE; - return FALSE; - } - - mts->meeting_positions_in_scroll_area = TRUE; - *start_x = mts->meeting_start_x = e_meeting_time_selector_calculate_time_position (mts, &mts->meeting_start_time); - *end_x = mts->meeting_end_x = e_meeting_time_selector_calculate_time_position (mts, &mts->meeting_end_time); - - return TRUE; -} - - -/* This recalculates the date format to used, by computing the width of the - longest date strings in the widget's font and seeing if they fit. */ -static void -e_meeting_time_selector_recalc_date_format (EMeetingTimeSelector *mts) -{ - GDate date; - gint max_date_width, base_width, max_weekday_width, max_month_width; - gint weekday, month; - gchar buffer[128]; - GdkFont *font; - - font = GTK_WIDGET (mts)->style->font; - - /* Check if we will be able to display the full date strings. */ - mts->date_format = E_MEETING_TIME_SELECTOR_DATE_SHORT; - g_date_clear (&date, 1); - g_date_set_dmy (&date, 20, 1, 2000); - - /* Calculate the maximum date width we can fit into the display. */ - max_date_width = mts->day_width - 2; - - /* First compute the width of the date string without the day or - month names. */ - g_date_strftime (buffer, 128, ", %d, %Y", &date); - base_width = gdk_string_width (font, buffer); - - /* If that doesn't fit just return. We have to use the short format. - If that doesn't fit it will just be clipped. */ - if (gdk_string_width (font, buffer) > max_date_width) - return; - - /* Now find the biggest weekday name. We start on any day and just - go through seven days. */ - max_weekday_width = 0; - for (weekday = 1; weekday <= 7; weekday++) { - g_date_strftime (buffer, 128, "%A", &date); - max_weekday_width = MAX (max_weekday_width, - gdk_string_width (font, buffer)); - g_date_add_days (&date, 1); - } - - /* Now find the biggest month name. */ - max_month_width = 0; - for (month = 1; month <= 12; month++) { - g_date_set_month (&date, month); - g_date_strftime (buffer, 128, "%B", &date); - max_month_width = MAX (max_month_width, - gdk_string_width (font, buffer)); - } - - /* See if we can use the full date. */ - if (base_width + max_month_width + max_weekday_width <= max_date_width) { - mts->date_format = E_MEETING_TIME_SELECTOR_DATE_FULL; - return; - } - - /* Now try it with abbreviated weekday names. */ - g_date_strftime (buffer, 128, " %x", &date); - base_width = gdk_string_width (font, buffer); - - max_weekday_width = 0; - for (weekday = 1; weekday <= 7; weekday++) { - g_date_strftime (buffer, 128, "%a", &date); - max_weekday_width = MAX (max_weekday_width, - gdk_string_width (font, buffer)); - g_date_add_days (&date, 1); - } - - if (base_width + max_weekday_width <= max_date_width) - mts->date_format = E_MEETING_TIME_SELECTOR_DATE_ABBREVIATED_DAY; -} - - -/* Turn off the background of the canvas windows. This reduces flicker - considerably when scrolling. (Why isn't it in GnomeCanvas?). */ -static void -e_meeting_time_selector_on_canvas_realized (GtkWidget *widget, - EMeetingTimeSelector *mts) -{ - gdk_window_set_back_pixmap (GTK_LAYOUT (widget)->bin_window, - NULL, FALSE); -} - - -/* This is called when the meeting start time GnomeDateEdit is changed, - either via the "date_changed". "time_changed" or "activate" signals on one - of the GtkEntry widgets. So don't use the widget parameter since it may be - one of the child GtkEntry widgets. */ -static void -e_meeting_time_selector_on_start_time_changed (GtkWidget *widget, - EMeetingTimeSelector *mts) -{ - gint duration_days, duration_hours, duration_minutes; - EMeetingTimeSelectorTime mtstime; - time_t newtime; - struct tm *newtime_tm; - - newtime = gnome_date_edit_get_date (GNOME_DATE_EDIT (mts->start_date_edit)); - newtime_tm = localtime (&newtime); - g_date_clear (&mtstime.date, 1); - g_date_set_time (&mtstime.date, newtime); - mtstime.hour = newtime_tm->tm_hour; - mtstime.minute = newtime_tm->tm_min; - - /* If the time hasn't changed, just return. */ - if (e_meeting_time_selector_compare_times (&mtstime, &mts->meeting_start_time) == 0) - return; - - /* Calculate the current meeting duration. */ - e_meeting_time_selector_calculate_time_difference (&mts->meeting_start_time, &mts->meeting_end_time, &duration_days, &duration_hours, &duration_minutes); - - /* Set the new start time. */ - mts->meeting_start_time = mtstime; - - /* Update the end time so the meeting duration stays the same. */ - mts->meeting_end_time = mts->meeting_start_time; - e_meeting_time_selector_adjust_time (&mts->meeting_end_time, duration_days, duration_hours, duration_minutes); - e_meeting_time_selector_update_end_date_edit (mts); - - mts->meeting_positions_valid = FALSE; - e_meeting_time_selector_ensure_meeting_time_shown (mts); - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); -} - - -/* This is called when the meeting end time GnomeDateEdit is changed, - either via the "date_changed", "time_changed" or "activate" signals on one - of the GtkEntry widgets. So don't use the widget parameter since it may be - one of the child GtkEntry widgets. */ -static void -e_meeting_time_selector_on_end_time_changed (GtkWidget *widget, - EMeetingTimeSelector *mts) -{ - EMeetingTimeSelectorTime mtstime; - time_t newtime; - struct tm *newtime_tm; - - newtime = gnome_date_edit_get_date (GNOME_DATE_EDIT (mts->end_date_edit)); - newtime_tm = localtime (&newtime); - g_date_clear (&mtstime.date, 1); - g_date_set_time (&mtstime.date, newtime); - mtstime.hour = newtime_tm->tm_hour; - mtstime.minute = newtime_tm->tm_min; - - /* If the time hasn't changed, just return. */ - if (e_meeting_time_selector_compare_times (&mtstime, &mts->meeting_end_time) == 0) - return; - - /* Set the new end time. */ - mts->meeting_end_time = mtstime; - - /* If the start time is after the end time, set it to the same time. */ - if (e_meeting_time_selector_compare_times (&mtstime, &mts->meeting_start_time) < 0) { - /* We set it first, before updating the widget, so the signal - handler will just return. */ - mts->meeting_start_time = mtstime; - e_meeting_time_selector_update_start_date_edit (mts); - } - - mts->meeting_positions_valid = FALSE; - e_meeting_time_selector_ensure_meeting_time_shown (mts); - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); -} - - -/* This updates the ranges shown in the GnomeDateEdit popup menus, according - to working_hours_only etc. */ -static void -e_meeting_time_selector_update_date_popup_menus (EMeetingTimeSelector *mts) -{ - GnomeDateEdit *start_edit, *end_edit; - gint low_hour, high_hour; - - start_edit = GNOME_DATE_EDIT (mts->start_date_edit); - end_edit = GNOME_DATE_EDIT (mts->end_date_edit); - - if (mts->working_hours_only) { - low_hour = mts->day_start_hour; - high_hour = mts->day_end_hour; - } else { - low_hour = 0; - high_hour = 23; - } - - gnome_date_edit_set_popup_range (start_edit, low_hour, high_hour); - gnome_date_edit_set_popup_range (end_edit, low_hour, high_hour); -} - - -static void -e_meeting_time_selector_on_canvas_size_allocate (GtkWidget *widget, - GtkAllocation *allocation, - EMeetingTimeSelector *mts) -{ - e_meeting_time_selector_update_main_canvas_scroll_region (mts); - - e_meeting_time_selector_ensure_meeting_time_shown (mts); -} - - -static void -e_meeting_time_selector_on_attendees_list_size_allocate (GtkWidget *widget, - GtkAllocation *allocation, - EMeetingTimeSelector *mts) -{ - e_meeting_time_selector_update_attendees_list_scroll_region (mts); - e_meeting_time_selector_update_attendees_list_positions (mts); -} - - -/* This updates the list canvas scroll region according to the number of - attendees. If the total height needed is less than the height of the canvas, - we must use the height of the canvas, or it causes problems. */ -static void -e_meeting_time_selector_update_attendees_list_scroll_region (EMeetingTimeSelector *mts) -{ - gint height, canvas_width, canvas_height; - - height = mts->row_height * mts->attendees->len; - canvas_width = GTK_WIDGET (mts->attendees_list)->allocation.width; - canvas_height = GTK_WIDGET (mts->attendees_list)->allocation.height; - - height = MAX (height, canvas_height); - - gnome_canvas_set_scroll_region (GNOME_CANVAS (mts->attendees_list), - 0, 0, - canvas_width, - height); -} - - -/* This updates the canvas scroll regions according to the number of attendees. - If the total height needed is less than the height of the canvas, we must - use the height of the canvas, or it causes problems. */ -static void -e_meeting_time_selector_update_main_canvas_scroll_region (EMeetingTimeSelector *mts) -{ - gint height, canvas_height, list_width; - - height = mts->row_height * (mts->attendees->len + 1); - canvas_height = GTK_WIDGET (mts->display_main)->allocation.height; - list_width = GTK_WIDGET (mts->attendees_list)->allocation.width; - - height = MAX (height, canvas_height); - - gnome_canvas_set_scroll_region (GNOME_CANVAS (mts->attendees_list), - 0, 0, - list_width, - height); - gnome_canvas_set_scroll_region (GNOME_CANVAS (mts->display_main), - 0, 0, - mts->day_width * E_MEETING_TIME_SELECTOR_DAYS_SHOWN, - height); -} - - -/* This changes the meeting time based on the given x coordinate and whether - we are dragging the start or end bar. It returns the new position, which - will be swapped if the start bar is dragged past the end bar or vice versa. - It make sure the meeting time is never dragged outside the visible canvas - area. */ -void -e_meeting_time_selector_drag_meeting_time (EMeetingTimeSelector *mts, - gint x) -{ - EMeetingTimeSelectorTime first_time, last_time, drag_time, *time_to_set; - gint scroll_x, scroll_y, canvas_width; - gboolean set_both_times = FALSE; - - /* Get the x coords of visible part of the canvas. */ - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (mts->display_main), - &scroll_x, &scroll_y); - canvas_width = mts->display_main->allocation.width; - - /* Save the x coordinate for the timeout handler. */ - mts->last_drag_x = (x < scroll_x) ? x - scroll_x - : x - scroll_x - canvas_width + 1; - - /* Check if the mouse is off the edge of the canvas. */ - if (x < scroll_x || x > scroll_x + canvas_width) { - /* If we haven't added a timeout function, add one. */ - if (mts->auto_scroll_timeout_id == 0) { - mts->auto_scroll_timeout_id = g_timeout_add (60, e_meeting_time_selector_timeout_handler, mts); - mts->scroll_count = 0; - - /* Call the handler to start scrolling now. */ - e_meeting_time_selector_timeout_handler (mts); - return; - } - } else { - e_meeting_time_selector_remove_timeout (mts); - } - - /* Calculate the minimum & maximum times we can use, based on the - scroll offsets and whether zoomed_out is set. */ - e_meeting_time_selector_calculate_time (mts, scroll_x, &first_time); - e_meeting_time_selector_calculate_time (mts, scroll_x + canvas_width - 1, - &last_time); - if (mts->zoomed_out) { - if (first_time.minute > 30) - first_time.hour++; - first_time.minute = 0; - last_time.minute = 0; - } else { - first_time.minute += 15; - first_time.minute -= first_time.minute % 30; - last_time.minute -= last_time.minute % 30; - } - e_meeting_time_selector_fix_time_overflows (&first_time); - e_meeting_time_selector_fix_time_overflows (&last_time); - - /* Calculate the time from x coordinate. */ - e_meeting_time_selector_calculate_time (mts, x, &drag_time); - - /* Calculate the nearest half-hour or hour, depending on whether - zoomed_out is set. */ - if (mts->zoomed_out) { - if (drag_time.minute > 30) - drag_time.hour++; - drag_time.minute = 0; - } else { - drag_time.minute += 15; - drag_time.minute -= drag_time.minute % 30; - } - e_meeting_time_selector_fix_time_overflows (&drag_time); - - /* Now make sure we are between first_time & last_time. */ - if (e_meeting_time_selector_compare_times (&drag_time, &first_time) < 0) - drag_time = first_time; - if (e_meeting_time_selector_compare_times (&drag_time, &last_time) > 0) - drag_time = last_time; - - /* Set the meeting start or end time to drag_time. */ - if (mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - time_to_set = &mts->meeting_start_time; - else - time_to_set = &mts->meeting_end_time; - - /* If the time is unchanged, just return. */ - if (e_meeting_time_selector_compare_times (time_to_set, &drag_time) == 0) - return; - - *time_to_set = drag_time; - - /* Check if the start time and end time need to be switched. */ - if (e_meeting_time_selector_compare_times (&mts->meeting_start_time, - &mts->meeting_end_time) > 0) { - drag_time = mts->meeting_start_time; - mts->meeting_start_time = mts->meeting_end_time; - mts->meeting_end_time = drag_time; - - if (mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - mts->dragging_position = E_MEETING_TIME_SELECTOR_POS_END; - else - mts->dragging_position = E_MEETING_TIME_SELECTOR_POS_START; - - set_both_times = TRUE; - } - - /* Mark the calculated positions as invalid. */ - mts->meeting_positions_valid = FALSE; - - /* Redraw the canvases. */ - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - - /* Set the times in the GnomeDateEdit widgets. */ - if (set_both_times - || mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - e_meeting_time_selector_update_start_date_edit (mts); - - if (set_both_times - || mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_END) - e_meeting_time_selector_update_end_date_edit (mts); -} - - -/* This is the timeout function which handles auto-scrolling when the user is - dragging one of the meeting time vertical bars outside the left or right - edge of the canvas. */ -static gboolean -e_meeting_time_selector_timeout_handler (gpointer data) -{ - EMeetingTimeSelector *mts; - EMeetingTimeSelectorTime drag_time, *time_to_set; - gint scroll_x, max_scroll_x, scroll_y, canvas_width; - gint scroll_speed, scroll_offset; - gboolean set_both_times = FALSE; - - mts = E_MEETING_TIME_SELECTOR (data); - - GDK_THREADS_ENTER (); - - /* Return if we don't need to scroll yet. */ - if (mts->scroll_count-- > 0) { - GDK_THREADS_LEAVE (); - return TRUE; - } - - /* Get the x coords of visible part of the canvas. */ - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (mts->display_main), - &scroll_x, &scroll_y); - canvas_width = mts->display_main->allocation.width; - - /* Calculate the scroll delay, between 0 and MAX_SCROLL_SPEED. */ - scroll_speed = abs (mts->last_drag_x / E_MEETING_TIME_SELECTOR_SCROLL_INCREMENT_WIDTH); - scroll_speed = MIN (scroll_speed, - E_MEETING_TIME_SELECTOR_MAX_SCROLL_SPEED); - - /* Reset the scroll count. */ - mts->scroll_count = E_MEETING_TIME_SELECTOR_MAX_SCROLL_SPEED - scroll_speed; - - /* Calculate how much we need to scroll. */ - if (mts->last_drag_x >= 0) - scroll_offset = mts->col_width; - else - scroll_offset = -mts->col_width; - - scroll_x += scroll_offset; - max_scroll_x = (mts->day_width * E_MEETING_TIME_SELECTOR_DAYS_SHOWN) - - canvas_width; - scroll_x = CLAMP (scroll_x, 0, max_scroll_x); - - /* Calculate the minimum or maximum visible time in the canvas, which - we will now set the dragged time to. */ - if (scroll_offset > 0) { - e_meeting_time_selector_calculate_time (mts, - scroll_x + canvas_width - 1, - &drag_time); - if (mts->zoomed_out) { - drag_time.minute = 0; - } else { - drag_time.minute -= drag_time.minute % 30; - } - } else { - e_meeting_time_selector_calculate_time (mts, scroll_x, - &drag_time); - if (mts->zoomed_out) { - if (drag_time.minute > 30) - drag_time.hour++; - drag_time.minute = 0; - } else { - drag_time.minute += 15; - drag_time.minute -= drag_time.minute % 30; - } - } - e_meeting_time_selector_fix_time_overflows (&drag_time); - - /* Set the meeting start or end time to drag_time. */ - if (mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - time_to_set = &mts->meeting_start_time; - else - time_to_set = &mts->meeting_end_time; - - /* If the time is unchanged, just return. */ - if (e_meeting_time_selector_compare_times (time_to_set, &drag_time) == 0) { - GDK_THREADS_LEAVE (); - return TRUE; - } - - *time_to_set = drag_time; - - /* Check if the start time and end time need to be switched. */ - if (e_meeting_time_selector_compare_times (&mts->meeting_start_time, &mts->meeting_end_time) > 0) { - drag_time = mts->meeting_start_time; - mts->meeting_start_time = mts->meeting_end_time; - mts->meeting_end_time = drag_time; - - if (mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - mts->dragging_position = E_MEETING_TIME_SELECTOR_POS_END; - else - mts->dragging_position = E_MEETING_TIME_SELECTOR_POS_START; - - set_both_times = TRUE; - } - - /* Mark the calculated positions as invalid. */ - mts->meeting_positions_valid = FALSE; - - /* Set the times in the GnomeDateEdit widgets. */ - if (set_both_times - || mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_START) - e_meeting_time_selector_update_start_date_edit (mts); - - if (set_both_times - || mts->dragging_position == E_MEETING_TIME_SELECTOR_POS_END) - e_meeting_time_selector_update_end_date_edit (mts); - - /* Redraw the canvases. We freeze and thaw the layouts so that they - get redrawn completely. Otherwise the pixels get scrolled left or - right which is not good for us (since our vertical bars have been - moved) and causes flicker. */ - gtk_layout_freeze (GTK_LAYOUT (mts->display_main)); - gtk_layout_freeze (GTK_LAYOUT (mts->display_top)); - gnome_canvas_scroll_to (GNOME_CANVAS (mts->display_main), - scroll_x, scroll_y); - gnome_canvas_scroll_to (GNOME_CANVAS (mts->display_top), - scroll_x, scroll_y); - gtk_layout_thaw (GTK_LAYOUT (mts->display_main)); - gtk_layout_thaw (GTK_LAYOUT (mts->display_top)); - - GDK_THREADS_LEAVE (); - return TRUE; -} - - -/* This removes our auto-scroll timeout function, if we have one installed. */ -void -e_meeting_time_selector_remove_timeout (EMeetingTimeSelector *mts) -{ - if (mts->auto_scroll_timeout_id) { - g_source_remove (mts->auto_scroll_timeout_id); - mts->auto_scroll_timeout_id = 0; - } -} - - -/* This updates the GnomeDateEdit widget displaying the meeting start time. */ -static void -e_meeting_time_selector_update_start_date_edit (EMeetingTimeSelector *mts) -{ - struct tm start_tm; - time_t start_time_t; - - g_date_to_struct_tm (&mts->meeting_start_time.date, &start_tm); - start_tm.tm_hour = mts->meeting_start_time.hour; - start_tm.tm_min = mts->meeting_start_time.minute; - start_time_t = mktime (&start_tm); - gnome_date_edit_set_time (GNOME_DATE_EDIT (mts->start_date_edit), - start_time_t); -} - - -/* This updates the GnomeDateEdit widget displaying the meeting end time. */ -static void -e_meeting_time_selector_update_end_date_edit (EMeetingTimeSelector *mts) -{ - struct tm end_tm; - time_t end_time_t; - - g_date_to_struct_tm (&mts->meeting_end_time.date, &end_tm); - end_tm.tm_hour = mts->meeting_end_time.hour; - end_tm.tm_min = mts->meeting_end_time.minute; - end_time_t = mktime (&end_tm); - gnome_date_edit_set_time (GNOME_DATE_EDIT (mts->end_date_edit), - end_time_t); -} - - -/* This ensures that the meeting time is shown on screen, by scrolling the - canvas and possibly by changing the range of dates shown in the canvas. */ -static void -e_meeting_time_selector_ensure_meeting_time_shown (EMeetingTimeSelector *mts) -{ - gint start_x, end_x, scroll_x, scroll_y, canvas_width; - gint new_scroll_x; - gboolean fits_in_canvas; - - /* Check if we need to change the range of dates shown. */ - if (g_date_compare (&mts->meeting_start_time.date, - &mts->first_date_shown) < 0 - || g_date_compare (&mts->meeting_end_time.date, - &mts->last_date_shown) > 0) { - e_meeting_time_selector_update_dates_shown (mts); - gtk_widget_queue_draw (mts->display_top); - gtk_widget_queue_draw (mts->display_main); - } - - /* If all of the meeting time is visible, just return. */ - e_meeting_time_selector_get_meeting_time_positions (mts, &start_x, - &end_x); - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (mts->display_main), - &scroll_x, &scroll_y); - canvas_width = mts->display_main->allocation.width; - if (start_x > scroll_x && end_x <= scroll_x + canvas_width) - return; - - fits_in_canvas = end_x - start_x < canvas_width ? TRUE : FALSE; - - /* If the meeting is not entirely visible, either center it if it is - smaller than the canvas, or show the start of it if it is big. */ - if (fits_in_canvas) { - new_scroll_x = (start_x + end_x - canvas_width) / 2; - } else { - new_scroll_x = start_x; - } - gnome_canvas_scroll_to (GNOME_CANVAS (mts->display_main), - new_scroll_x, scroll_y); -} - - -/* This updates the range of dates shown in the canvas, to make sure that the - currently selected meeting time is in the range. */ -static void -e_meeting_time_selector_update_dates_shown (EMeetingTimeSelector *mts) -{ - mts->first_date_shown = mts->meeting_start_time.date; - g_date_subtract_days (&mts->first_date_shown, 60); - - mts->last_date_shown = mts->first_date_shown; - g_date_add_days (&mts->last_date_shown, E_MEETING_TIME_SELECTOR_DAYS_SHOWN - 1); -} - - -/* This checks if the time's hour is over 24 or its minute is over 60 and if - so it updates the day/hour appropriately. Note that hours and minutes are - stored in guint8's so they can't overflow by much. */ -void -e_meeting_time_selector_fix_time_overflows (EMeetingTimeSelectorTime *mtstime) -{ - gint hours_to_add, days_to_add; - - hours_to_add = mtstime->minute / 60; - if (hours_to_add > 0) { - mtstime->minute -= hours_to_add * 60; - mtstime->hour += hours_to_add; - } - - days_to_add = mtstime->hour / 24; - if (days_to_add > 0) { - mtstime->hour -= days_to_add * 24; - g_date_add_days (&mtstime->date, days_to_add); - } -} - - -static void -e_meeting_time_selector_update_attendees_list_positions (EMeetingTimeSelector *mts) -{ - EMeetingTimeSelectorAttendee *attendee; - gint list_width, item_width; - gint row; - GdkFont *font; - - list_width = GTK_WIDGET (mts->attendees_list)->allocation.width; - item_width = MAX (1, list_width - E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH - E_MEETING_TIME_SELECTOR_TEXT_X_PAD * 2); - font = GTK_WIDGET (mts)->style->font; - for (row = 0; row < mts->attendees->len; row++) { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - - gnome_canvas_item_set - (attendee->text_item, - "font_gdk", font, - "y", (gdouble) (row * mts->row_height + 1 - + E_MEETING_TIME_SELECTOR_TEXT_Y_PAD), - "clip_width", (gdouble) item_width, - "clip_height", (gdouble) (font->ascent - + font->descent), - NULL); - - gnome_canvas_item_show (attendee->text_item); - } - -} - - -/* - * CONVERSION ROUTINES - functions to convert between different coordinate - * spaces and dates. - */ - -/* This takes an x pixel coordinate within the entire canvas scroll region and - returns the date in which it falls. If day_position is not NULL it also - returns the x coordinate within the date, relative to the visible part of - the canvas. It is used when painting the days in the item_draw function. - Note that it must handle negative x coordinates in case we are dragging off - the edge of the canvas. */ -void -e_meeting_time_selector_calculate_day_and_position (EMeetingTimeSelector *mts, - gint x, - GDate *date, - gint *day_position) -{ - gint days_from_first_shown; - - *date = mts->first_date_shown; - - if (x >= 0) { - days_from_first_shown = x / mts->day_width; - g_date_add_days (date, days_from_first_shown); - if (day_position) - *day_position = - x % mts->day_width; - } else { - days_from_first_shown = -x / mts->day_width + 1; - g_date_subtract_days (date, days_from_first_shown); - if (day_position) - *day_position = -mts->day_width - x % mts->day_width; - } -} - - -/* This takes an x pixel coordinate within a day, and converts it to hours - and minutes, depending on working_hours_only and zoomed_out. */ -void -e_meeting_time_selector_convert_day_position_to_hours_and_mins (EMeetingTimeSelector *mts, gint day_position, guint8 *hours, guint8 *minutes) -{ - if (mts->zoomed_out) - day_position *= 3; - - /* Calculate the hours & minutes from the first displayed. */ - *hours = day_position / mts->col_width; - *minutes = (day_position % mts->col_width) * 60 / mts->col_width; - - /* Now add on the first hour shown. */ - *hours += mts->first_hour_shown; -} - - -/* This takes an x pixel coordinate within the entire canvas scroll region and - returns the time in which it falls. Note that it won't be extremely - accurate since hours may only be a few pixels wide in the display. - With zoomed_out set each pixel may represent 5 minutes or more, depending - on how small the font is. */ -void -e_meeting_time_selector_calculate_time (EMeetingTimeSelector *mts, - gint x, - EMeetingTimeSelectorTime *time) -{ - gint day_position; - - /* First get the day and the x position within the day. */ - e_meeting_time_selector_calculate_day_and_position (mts, x, &time->date, - NULL); - - /* Now convert the day_position into an hour and minute. */ - if (x >= 0) - day_position = x % mts->day_width; - else - day_position = mts->day_width + x % mts->day_width; - - e_meeting_time_selector_convert_day_position_to_hours_and_mins (mts, day_position, &time->hour, &time->minute); -} - - -/* This takes a EMeetingTimeSelectorTime and calculates the x pixel coordinate - within the entire canvas scroll region. It is used to draw the selected - meeting time and all the busy periods. */ -gint -e_meeting_time_selector_calculate_time_position (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *mtstime) -{ - gint x, date_offset, day_offset; - - /* Calculate the number of days since the first date shown in the - entire canvas scroll region. */ - date_offset = g_date_julian (&mtstime->date) - g_date_julian (&mts->first_date_shown); - - /* Calculate the x pixel coordinate of the start of the day. */ - x = date_offset * mts->day_width; - - /* Add on the hours and minutes, depending on whether zoomed_out and - working_hours_only are set. */ - day_offset = (mtstime->hour - mts->first_hour_shown) * 60 - + mtstime->minute; - /* The day width includes an extra vertical grid line so subtract 1. */ - day_offset *= (mts->day_width - 1); - day_offset /= (mts->last_hour_shown - mts->first_hour_shown) * 60; - - /* Clamp the day_offset in case the time isn't actually visible. */ - x += CLAMP (day_offset, 0, mts->day_width); - - return x; -} - - -static gboolean -e_meeting_time_selector_on_text_item_event (GnomeCanvasItem *item, - GdkEvent *event, - EMeetingTimeSelector *mts) -{ - EMeetingTimeSelectorAttendee *attendee; - gint row, min; - ETextEventProcessor *event_processor = NULL; - ETextEventProcessorCommand command; - GtkAdjustment *adj; - gchar *text; - gboolean empty = FALSE; - - switch (event->type) { - case GDK_KEY_PRESS: - if (event && event->key.keyval == GDK_Return) { - row = e_meeting_time_selector_find_row_from_text_item (mts, item); - g_return_val_if_fail (row != -1, FALSE); - - if (row == mts->attendees->len - 1) - row = e_meeting_time_selector_attendee_add (mts, "", NULL); - else - row++; - - /* Make sure the item is visible. */ - adj = GTK_LAYOUT (mts->display_main)->vadjustment; - min = ((row + 1) * mts->row_height) - adj->page_size; - if (adj->value < min) { - adj->value = min; - gtk_adjustment_value_changed (adj); - } - - attendee = &g_array_index (mts->attendees, EMeetingTimeSelectorAttendee, row); - e_canvas_item_grab_focus (attendee->text_item); - - /* Try to move the cursor to the end of the text. */ - gtk_object_get (GTK_OBJECT (attendee->text_item), - "event_processor", &event_processor, - NULL); - if (event_processor) { - command.action = E_TEP_MOVE; - command.position = E_TEP_END_OF_BUFFER; - gtk_signal_emit_by_name (GTK_OBJECT (event_processor), - "command", &command); - } - - /* Stop the signal last or we will also stop any - other events getting to the EText item. */ - gtk_signal_emit_stop_by_name (GTK_OBJECT (item), - "event"); - return TRUE; - } - break; - case GDK_FOCUS_CHANGE: - if (!event->focus_change.in) { - gtk_object_get (GTK_OBJECT (item), - "text", &text, - NULL); - if (!text || !text[0]) - empty = TRUE; - g_free (text); - - if (empty) { - row = e_meeting_time_selector_find_row_from_text_item (mts, item); - g_return_val_if_fail (row != -1, FALSE); - e_meeting_time_selector_attendee_remove (mts, - row); - } - } - break; - default: - break; - } - - return FALSE; -} - - -static gint -e_meeting_time_selector_find_row_from_text_item (EMeetingTimeSelector *mts, - GnomeCanvasItem *item) -{ - EMeetingTimeSelectorAttendee *attendee; - gint row; - - for (row = 0; row < mts->attendees->len; row++) { - attendee = &g_array_index (mts->attendees, - EMeetingTimeSelectorAttendee, row); - if (attendee->text_item == item) - return row; - } - - return -1; -} - diff --git a/widgets/meeting-time-sel/e-meeting-time-sel.h b/widgets/meeting-time-sel/e-meeting-time-sel.h deleted file mode 100644 index a2ad4b9cd5..0000000000 --- a/widgets/meeting-time-sel/e-meeting-time-sel.h +++ /dev/null @@ -1,518 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@gtk.org> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_MEETING_TIME_SELECTOR_H_ -#define _E_MEETING_TIME_SELECTOR_H_ - -#include <gtk/gtktable.h> -#include <libgnomeui/gnome-canvas.h> -#include "../e-text/e-text.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EMeetingTimeSelector displays a list of attendees for a meeting and a - * graphical summary of the times which they are free and busy, allowing the - * user to select an appropriate time for a meeting. - */ - -/* Define this to include the debugging functions. */ -#undef E_MEETING_TIME_SELECTOR_DEBUG - -/* This is the width of the icon column in the attendees list. */ -#define E_MEETING_TIME_SELECTOR_ICON_COLUMN_WIDTH 24 - -#define E_MEETING_TIME_SELECTOR_TEXT_Y_PAD 3 -#define E_MEETING_TIME_SELECTOR_TEXT_X_PAD 2 - -/* These specify the type of attendee. Either a person or a resource (e.g. a - meeting room). These are used for the Autopick options, where the user can - ask for a time when, for example, all people and one resource are free. - The default is E_MEETING_TIME_SELECTOR_REQUIRED_PERSON. */ -typedef enum -{ - E_MEETING_TIME_SELECTOR_REQUIRED_PERSON, - E_MEETING_TIME_SELECTOR_OPTIONAL_PERSON, - E_MEETING_TIME_SELECTOR_RESOURCE -} EMeetingTimeSelectorAttendeeType; - - -/* These are used to specify whether an attendee is free or busy at a - particular time. We'll probably replace this with a global calendar type. - These should be ordered in increasing order of preference. Higher precedence - busy periods will be painted over lower precedence ones. These are also - used as for loop counters, so they should start at 0 and be ordered. */ -typedef enum -{ - E_MEETING_TIME_SELECTOR_BUSY_TENTATIVE = 0, - E_MEETING_TIME_SELECTOR_BUSY_OUT_OF_OFFICE = 1, - E_MEETING_TIME_SELECTOR_BUSY_BUSY = 2, - - E_MEETING_TIME_SELECTOR_BUSY_LAST = 3 -} EMeetingTimeSelectorBusyType; - - -/* This is used to specify the format used when displaying the dates. - The full format is like 'Sunday, September 12, 1999'. The abbreviated format - is like 'Sun 12/9/99'. The short format is like '12/9/99'. The actual - format used is determined in e_meeting_time_selector_style_set(), once we - know the font being used. */ -typedef enum -{ - E_MEETING_TIME_SELECTOR_DATE_FULL, - E_MEETING_TIME_SELECTOR_DATE_ABBREVIATED_DAY, - E_MEETING_TIME_SELECTOR_DATE_SHORT -} EMeetingTimeSelectorDateFormat; - - -/* This is used to specify a position regarding the vertical bars around the - current meeting time, so we know which one is being dragged. */ -typedef enum -{ - E_MEETING_TIME_SELECTOR_POS_NONE, - E_MEETING_TIME_SELECTOR_POS_START, - E_MEETING_TIME_SELECTOR_POS_END -} EMeetingTimeSelectorPosition; - - -/* This is used to specify the autopick option, which determines how we choose - the previous/next appropriate meeting time. */ -typedef enum -{ - E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_RESOURCES, - E_MEETING_TIME_SELECTOR_ALL_PEOPLE_AND_ONE_RESOURCE, - E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE, - E_MEETING_TIME_SELECTOR_REQUIRED_PEOPLE_AND_ONE_RESOURCE -} EMeetingTimeSelectorAutopickOption; - - -/* This is our representation of a time. We use a GDate to store the day, - and guint8s for the hours and minutes. */ -typedef struct _EMeetingTimeSelectorTime EMeetingTimeSelectorTime; -struct _EMeetingTimeSelectorTime -{ - GDate date; - guint8 hour; - guint8 minute; -}; - - -/* This represents a busy period. */ -typedef struct _EMeetingTimeSelectorPeriod EMeetingTimeSelectorPeriod; -struct _EMeetingTimeSelectorPeriod -{ - EMeetingTimeSelectorTime start; - EMeetingTimeSelectorTime end; - EMeetingTimeSelectorBusyType busy_type; -}; - - -/* This contains information on one attendee. */ -typedef struct _EMeetingTimeSelectorAttendee EMeetingTimeSelectorAttendee; -struct _EMeetingTimeSelectorAttendee -{ - gchar *name; - - /* The type of attendee, e.g. a person or a resource. */ - EMeetingTimeSelectorAttendeeType type; - - /* This is TRUE if the attendee has calendar information available. - It is set to TRUE when a busy period is added, but can also be set - to TRUE explicitly to indicate that the attendee has calendar - information available, but no current busy periods. If it is FALSE - then a diagonal stipple pattern is used to fill the entire row in - the main graphical display. */ - gboolean has_calendar_info; - - /* This is TRUE if the meeting request is sent to this attendee. */ - gboolean send_meeting_to; - - /* This is the period for which free/busy data for the attendee is - available. */ - EMeetingTimeSelectorTime busy_periods_start; - EMeetingTimeSelectorTime busy_periods_end; - - /* This is an array of EMeetingTimeSelectorPeriod elements. When it is - updated busy_periods_sorted is set to FALSE, and if a function - needs them sorted, it should call this to re-sort them if needed: - e_meeting_time_selector_attendee_ensure_periods_sorted(). Note that - they are sorted by the start times. */ - GArray *busy_periods; - gboolean busy_periods_sorted; - - /* This holds the length of the longest busy period in days, rounded - up. It is used to determine where to start looking in the - busy_periods array. If we didn't use this we'd have to go through - most of the busy_periods array every time we wanted to paint part - of the display. */ - gint longest_period_in_days; - - /* This is the canvas text item where the name is edited. */ - GnomeCanvasItem *text_item; - - /* This is supposed to be something like an address book id. */ - gpointer data; -}; - -/* An array of hour strings, "0:00" .. "23:00". */ -extern const gchar *EMeetingTimeSelectorHours[24]; - - -#define E_MEETING_TIME_SELECTOR(obj) GTK_CHECK_CAST (obj, e_meeting_time_selector_get_type (), EMeetingTimeSelector) -#define E_MEETING_TIME_SELECTOR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_meeting_time_selector_get_type (), EMeetingTimeSelectorClass) -#define IS_E_MEETING_TIME_SELECTOR(obj) GTK_CHECK_TYPE (obj, e_meeting_time_selector_get_type ()) - - -typedef struct _EMeetingTimeSelector EMeetingTimeSelector; -typedef struct _EMeetingTimeSelectorClass EMeetingTimeSelectorClass; - -struct _EMeetingTimeSelector -{ - /* We subclass a GtkTable which makes it easy to add extra widgets - if neccesary. */ - GtkTable table; - - /* - * User Interface stuff - widgets, colors etc. - */ - - /* This contains our keyboard accelerators, which need to be added to - the toplevel window. */ - GtkAccelGroup *accel_group; - - /* The vbox in the top-left corner, containing the 'All Attendees' - title bar packed at the end. Extra widgets can be added here - with PACK_START if necessary. */ - GtkWidget *attendees_title_bar_vbox; - - /* The 'All Attendees' title bar above the list of attendees. */ - GtkWidget *attendees_title_bar; - - /* The list of attendees. */ - GtkWidget *attendees_list; - - /* The canvas displaying the dates, times, and the summary - 'All Attendees' free/busy display. */ - GtkWidget *display_top; - - /* The canvas containing the free/busy displays of individual - attendees. This is separate from display_top since it also scrolls - vertically. */ - GtkWidget *display_main; - - /* This is the 'Options' button & menu. */ - GtkWidget *options_button; - GtkWidget *options_menu; - - /* This is the 'Autopick' button, menu & radio menu items. */ - GtkWidget *autopick_button; - GtkWidget *autopick_menu; - GtkWidget *autopick_all_item; - GtkWidget *autopick_all_people_one_resource_item; - GtkWidget *autopick_required_people_item; - GtkWidget *autopick_required_people_one_resource_item; - - /* The horizontal scrollbar which scrolls display_top & display_main.*/ - GtkWidget *hscrollbar; - - /* The vertical scrollbar which scrolls attendees & display_main. */ - GtkWidget *vscrollbar; - - /* The 2 GnomeDateEdit widgets for the meeting start & end times. */ - GtkWidget *start_date_edit; - GtkWidget *end_date_edit; - - /* Colors. */ - GdkColorContext *color_context; - GdkColor bg_color; - GdkColor all_attendees_bg_color; - GdkColor meeting_time_bg_color; - GdkColor stipple_bg_color; - GdkColor attendee_list_bg_color; - GdkColor grid_color; - GdkColor grid_shadow_color; - GdkColor grid_unused_color; - GdkColor busy_colors[E_MEETING_TIME_SELECTOR_BUSY_LAST]; - - /* The stipple used for attendees with no data. */ - GdkPixmap *stipple; - - /* GC for drawing the color key. */ - GdkGC *color_key_gc; - - /* Width of the hours strings (e.g. "1:00") in the current font. */ - gint hour_widths[24]; - - /* Whether we are using the full, abbreviated or short date format. */ - EMeetingTimeSelectorDateFormat date_format; - - - /* - * Attendee Data. - */ - - /* This is an array of EMeetingTimeSelectorAttendee elements. */ - GArray *attendees; - - - /* - * Option Settings. - */ - - /* If this is TRUE we only show hours between day_start_hour and - day_end_hour, defaults to TRUE (9am-6pm). */ - gboolean working_hours_only; - gint day_start_hour; - gint day_start_minute; - gint day_end_hour; - gint day_end_minute; - - /* If TRUE, view is compressed, with one cell for every 3 hours rather - than every hour. Defaults to FALSE. */ - gboolean zoomed_out; - - - /* - * Internal Data. - */ - - /* These are the first & last dates shown in the current scroll area. - We show E_MEETING_TIME_SELECTOR_DAYS_SHOWN days at a time. */ - GDate first_date_shown; - GDate last_date_shown; - - /* This is the current selection of the meeting time. */ - EMeetingTimeSelectorTime meeting_start_time; - EMeetingTimeSelectorTime meeting_end_time; - - /* These are the x pixel coordinates in the entire scroll region of - the start and end times. Set to meeting_positions_valid to FALSE to - invalidate. They will then be recomputed when needed. Always access - with e_meeting_time_selector_get_meeting_time_positions(). */ - gint meeting_positions_valid; - gint meeting_positions_in_scroll_area; - gint meeting_start_x; - gint meeting_end_x; - - /* These are the width and height of the cells, including the grid - lines which are displayed on the right and top or bottom of cells.*/ - gint row_height; - gint col_width; - - /* This is the width of a day in the display, which depends on - col_width, working_hours_only and zoomed_out. */ - gint day_width; - - /* These are the first and last hour of each day we display, depending - on working_hours_only and zoomed_out. */ - gint first_hour_shown; - gint last_hour_shown; - - /* The id of the source function for auto-scroll timeouts. */ - guint auto_scroll_timeout_id; - - /* This specifies if we are dragging one of the vertical bars around - the meeting time. */ - EMeetingTimeSelectorPosition dragging_position; - - /* The last x coordinate of the mouse, relative to either the left or - right edge of the canvas. Used in the auto_scroll_timeout function - to determine which way to scroll and how fast. */ - gint last_drag_x; - - /* This is used to determine the delay between scrolls. */ - gint scroll_count; -}; - - -struct _EMeetingTimeSelectorClass -{ - GtkTableClass parent_class; -}; - - -/* - * PUBLIC INTERFACE - note that this interface will probably change, when I - * know where the data is coming from. This is mainly just for testing for now. - */ - -GtkType e_meeting_time_selector_get_type (void); -GtkWidget* e_meeting_time_selector_new (void); - -/* This returns the currently selected meeting time. - Note that months are 1-12 and days are 1-31. The start time is guaranteed to - be before or equal to the end time. You may want to check if they are equal - if that if it is a problem. */ -void e_meeting_time_selector_get_meeting_time (EMeetingTimeSelector *mts, - gint *start_year, - gint *start_month, - gint *start_day, - gint *start_hour, - gint *start_minute, - gint *end_year, - gint *end_month, - gint *end_day, - gint *end_hour, - gint *end_minute); - -/* This sets the meeting time, returning TRUE if it is valid. */ -gboolean e_meeting_time_selector_set_meeting_time (EMeetingTimeSelector *mts, - gint start_year, - gint start_month, - gint start_day, - gint start_hour, - gint start_minute, - gint end_year, - gint end_month, - gint end_day, - gint end_hour, - gint end_minute); - -void e_meeting_time_selector_set_working_hours_only (EMeetingTimeSelector *mts, - gboolean working_hours_only); -void e_meeting_time_selector_set_working_hours (EMeetingTimeSelector *mts, - gint day_start_hour, - gint day_start_minute, - gint day_end_hour, - gint day_end_minute); - -void e_meeting_time_selector_set_zoomed_out (EMeetingTimeSelector *mts, - gboolean zoomed_out); - -EMeetingTimeSelectorAutopickOption e_meeting_time_selector_get_autopick_option (EMeetingTimeSelector *mts); -void e_meeting_time_selector_set_autopick_option (EMeetingTimeSelector *mts, - EMeetingTimeSelectorAutopickOption autopick_option); - -/* Adds an attendee to the list, returning the row. The data is meant for - something like an address book id, though if the user edits the name this - will become invalid. We'll probably have to handle address book lookup - ourself. */ -gint e_meeting_time_selector_attendee_add (EMeetingTimeSelector *mts, - gchar *attendee_name, - gpointer data); -gint e_meeting_time_selector_attendee_find_by_name (EMeetingTimeSelector *mts, - gchar *attendee_name, - gint start_row); -gint e_meeting_time_selector_attendee_find_by_data (EMeetingTimeSelector *mts, - gpointer data, - gint start_row); -void e_meeting_time_selector_attendee_remove (EMeetingTimeSelector *mts, - gint row); - -void e_meeting_time_selector_attendee_set_type (EMeetingTimeSelector *mts, - gint row, - EMeetingTimeSelectorAttendeeType type); -void e_meeting_time_selector_attendee_set_has_calendar_info (EMeetingTimeSelector *mts, - gint row, - gboolean has_calendar_info); -void e_meeting_time_selector_attendee_set_send_meeting_to (EMeetingTimeSelector *mts, - gint row, - gboolean send_meeting_to); - -gboolean e_meeting_time_selector_attendee_set_busy_range (EMeetingTimeSelector *mts, - gint row, - gint start_year, - gint start_month, - gint start_day, - gint start_hour, - gint start_minute, - gint end_year, - gint end_month, - gint end_day, - gint end_hour, - gint end_minute); - - -/* Clears all busy times for the given attendee. */ -void e_meeting_time_selector_attendee_clear_busy_periods (EMeetingTimeSelector *mts, - gint row); -/* Adds one busy time for the given attendee. */ -gboolean e_meeting_time_selector_attendee_add_busy_period (EMeetingTimeSelector *mts, - gint row, - gint start_year, - gint start_month, - gint start_day, - gint start_hour, - gint start_minute, - gint end_year, - gint end_month, - gint end_day, - gint end_hour, - gint end_minute, - EMeetingTimeSelectorBusyType busy_type); - - - -/* - * INTERNAL ROUTINES - functions to communicate with the canvas items within - * the EMeetingTimeSelector. - */ - -/* This returns the x pixel coordinates of the meeting start and end times, - in the entire canvas scroll area. If it returns FALSE, then the meeting - time isn't in the current scroll area (which shouldn't really happen). */ -gboolean e_meeting_time_selector_get_meeting_time_positions (EMeetingTimeSelector *mts, - gint *start_x, - gint *end_x); - -void e_meeting_time_selector_drag_meeting_time (EMeetingTimeSelector *mts, - gint x); - -void e_meeting_time_selector_remove_timeout (EMeetingTimeSelector *mts); - -void e_meeting_time_selector_fix_time_overflows (EMeetingTimeSelectorTime *mtstime); - -gint e_meeting_time_selector_find_first_busy_period (EMeetingTimeSelector *mts, - EMeetingTimeSelectorAttendee *attendee, - GDate *date); - -/* Makes sure the busy periods are sorted, so we can do binary searches. */ -void e_meeting_time_selector_attendee_ensure_periods_sorted (EMeetingTimeSelector *mts, - EMeetingTimeSelectorAttendee *attendee); - -void e_meeting_time_selector_calculate_day_and_position (EMeetingTimeSelector *mts, - gint x, - GDate *date, - gint *day_position); -void e_meeting_time_selector_convert_day_position_to_hours_and_mins (EMeetingTimeSelector *mts, gint day_position, guint8 *hours, guint8 *minutes); -void e_meeting_time_selector_calculate_time (EMeetingTimeSelector *mts, - gint x, - EMeetingTimeSelectorTime *time); -gint e_meeting_time_selector_calculate_time_position (EMeetingTimeSelector *mts, - EMeetingTimeSelectorTime *mtstime); - -/* Debugging function to dump information on all attendees. */ -#ifdef E_MEETING_TIME_SELECTOR_DEBUG -void e_meeting_time_selector_dump (EMeetingTimeSelector *mts); -gchar* e_meeting_time_selector_dump_time (EMeetingTimeSelectorTime *mtstime); -gchar* e_meeting_time_selector_dump_date (GDate *date); -#endif /* E_MEETING_TIME_SELECTOR_DEBUG */ - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_MEETING_TIME_SELECTOR_H_ */ diff --git a/widgets/meeting-time-sel/test-meeting-time-sel.c b/widgets/meeting-time-sel/test-meeting-time-sel.c deleted file mode 100644 index 33c15ff19b..0000000000 --- a/widgets/meeting-time-sel/test-meeting-time-sel.c +++ /dev/null @@ -1,242 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@gtk.org> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#include <config.h> -#include <gnome.h> -#include "e-meeting-time-sel.h" - -void add_random_attendee_test_data (EMeetingTimeSelector *mts); -void add_simple_attendee_test_data (EMeetingTimeSelector *mts); -gint get_random_int (gint max); - -int -main (int argc, char *argv[]) -{ - GtkWidget *window, *mts; - gint i; - - gnome_init ("test-meeting-time-selector", "0.1", argc, argv); - - gtk_widget_push_visual (gdk_imlib_get_visual ()); - gtk_widget_push_colormap (gdk_imlib_get_colormap ()); - - window = gnome_dialog_new ("Plan a Meeting", "Make Meeting", - GNOME_STOCK_BUTTON_CLOSE, NULL); - gtk_window_set_default_size (GTK_WINDOW (window), 600, 400); - gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, FALSE); - - mts = e_meeting_time_selector_new (); - gtk_container_add (GTK_CONTAINER (GNOME_DIALOG (window)->vbox), mts); - gtk_window_add_accel_group (GTK_WINDOW (window), - E_MEETING_TIME_SELECTOR (mts)->accel_group); - gtk_widget_show (mts); - - gtk_widget_pop_visual (); - gtk_widget_pop_colormap (); - - i = 0; -#if 1 - for (i = 0; i < 20; i++) { - add_random_attendee_test_data (E_MEETING_TIME_SELECTOR (mts)); - } - - if (!e_meeting_time_selector_attendee_set_busy_range (E_MEETING_TIME_SELECTOR (mts), 3, - 2000, 5, 1, 14, 0, - 2000, 11, 1, 11, 30)) - g_print ("Error setting busy range\n"); - -#else - for (i = 0; i < 1; i++) { - add_simple_attendee_test_data (E_MEETING_TIME_SELECTOR (mts)); - } -#endif - -#if 0 - e_meeting_time_selector_dump (E_MEETING_TIME_SELECTOR (mts)); -#endif - - gnome_dialog_run (GNOME_DIALOG (window)); - - gtk_main (); - return 0; -} - - -/* Adds an attendee and a lot of random busy periods. The periods start 60 - days before the current date and extend over 365 days, to match the range - that EMeetingTimeSelector currently displays. We generate a time_t and an - interval and then convert them into a struct tm which provides everything - we need. */ -void -add_random_attendee_test_data (EMeetingTimeSelector *mts) -{ - gchar buffer[128], *name; - gint row, num_periods, busy_period, random_num, duration; - EMeetingTimeSelectorAttendeeType type; - EMeetingTimeSelectorBusyType busy_type; - time_t range_start; - time_t period_start; - time_t period_end; - struct tm *tmp_tm; - struct tm tm1; - struct tm tm2; - - /* Determine the type of attendee. */ - random_num = get_random_int (10); - if (random_num < 4) { - type = E_MEETING_TIME_SELECTOR_REQUIRED_PERSON; - name = "Req. Attendee"; - } else if (random_num < 7) { - type = E_MEETING_TIME_SELECTOR_OPTIONAL_PERSON; - name = "Opt. Attendee"; - } else { - type = E_MEETING_TIME_SELECTOR_RESOURCE; - name = "Resource"; - } - - sprintf (buffer, "%s %i", name, mts->attendees->len + 1); - row = e_meeting_time_selector_attendee_add (mts, buffer, NULL); - e_meeting_time_selector_attendee_set_type (mts, row, type); - - /* Don't send the meeting request to some attendees. */ - if (get_random_int (10) <= 2) - e_meeting_time_selector_attendee_set_send_meeting_to (mts, row, - FALSE); - - /* Some attendees have no calendar information. */ - if (get_random_int (10) == 2) - return; - - range_start = time (NULL) - 61 * 24 * 60 * 60; - num_periods = get_random_int (1000); -#if 0 - g_print ("num_periods: %i\n", num_periods); -#endif - for (busy_period = 0; busy_period < num_periods; busy_period++) { - - period_start = range_start + get_random_int (365 * 24 * 60 * 60); - - /* Make busy periods mainly 30 mins to a few hours, with a - couple of week/fortnight periods as well. */ - random_num = get_random_int (10000); - if (random_num < 2000) - duration = 30; - else if (random_num < 5000) - duration = 60; - else if (random_num < 7500) - duration = 90; - else if (random_num < 9995) - duration = 120; - else if (random_num < 9998) - duration = 60 * 24 * 7; - else - duration = 60 * 24 * 14; -#if 0 - g_print ("random_num: %i, duration: %i\n", - random_num, duration); -#endif - period_end = period_start + duration * 60; - - tmp_tm = localtime (&period_start); - tm1 = *tmp_tm; - tmp_tm = localtime (&period_end); - tm2 = *tmp_tm; - - /* A hack to avoid daylight-saving time problems. */ - if (tm2.tm_hour == tm1.tm_hour && tm2.tm_min < tm1.tm_min) - tm2.tm_hour++; - - busy_type = get_random_int (E_MEETING_TIME_SELECTOR_BUSY_LAST); - - if (!e_meeting_time_selector_attendee_add_busy_period (mts, row, tm1.tm_year + 1900, tm1.tm_mon + 1, tm1.tm_mday, tm1.tm_hour, tm1.tm_min, tm2.tm_year + 1900, tm2.tm_mon + 1, tm2.tm_mday, tm2.tm_hour, tm2.tm_min, busy_type)) - { - g_print ("Invalid busy period %i/%i/%i %i:%i to %i/%i/%i %i:%i\n", tm1.tm_year + 1900, tm1.tm_mon + 1, tm1.tm_mday, tm1.tm_hour, tm1.tm_min, tm2.tm_year + 1900, tm2.tm_mon + 1, tm2.tm_mday, tm2.tm_hour, tm2.tm_min); - g_print ("random_num: %i, duration: %i\n", - random_num, duration); - } - } -} - - -/* Returns a random integer between 0 and max - 1. */ -gint -get_random_int (gint max) -{ - gint random_num; - - random_num = (int) (max * (rand () / (RAND_MAX + 1.0))); -#if 0 - g_print ("Random num (%i): %i\n", max, random_num); -#endif - return random_num; -} - - -void -add_simple_attendee_test_data (EMeetingTimeSelector *mts) -{ - gint row; - - row = e_meeting_time_selector_attendee_add (mts, "John Smith", NULL); - if (!e_meeting_time_selector_attendee_add_busy_period (mts, row, - 1999, 11, 7, 14, 30, - 1999, 11, 7, 16, 30, - E_MEETING_TIME_SELECTOR_BUSY_BUSY)) - g_warning ("Invalid busy period"); - - e_meeting_time_selector_attendee_add_busy_period (mts, row, - 1999, 11, 7, 10, 30, - 1999, 11, 7, 11, 30, - E_MEETING_TIME_SELECTOR_BUSY_OUT_OF_OFFICE); - e_meeting_time_selector_attendee_add_busy_period (mts, row, - 1999, 11, 4, 10, 30, - 1999, 11, 7, 11, 30, - E_MEETING_TIME_SELECTOR_BUSY_BUSY); - row = e_meeting_time_selector_attendee_add (mts, "Dave Jones", NULL); - e_meeting_time_selector_attendee_add_busy_period (mts, row, - 1999, 11, 7, 15, 30, - 1999, 11, 7, 18, 30, - E_MEETING_TIME_SELECTOR_BUSY_TENTATIVE); - e_meeting_time_selector_attendee_add_busy_period (mts, row, - 1999, 11, 7, 11, 00, - 1999, 11, 7, 12, 00, - E_MEETING_TIME_SELECTOR_BUSY_BUSY); - - row = e_meeting_time_selector_attendee_add (mts, "Andrew Carlisle", NULL); - e_meeting_time_selector_attendee_set_send_meeting_to (mts, row, FALSE); - - row = e_meeting_time_selector_attendee_add (mts, "Michael Cain", NULL); - e_meeting_time_selector_attendee_add_busy_period (mts, row, - 1999, 11, 7, 15, 30, - 1999, 11, 7, 18, 30, - E_MEETING_TIME_SELECTOR_BUSY_TENTATIVE); - e_meeting_time_selector_attendee_add_busy_period (mts, row, - 1999, 11, 7, 12, 30, - 1999, 11, 7, 13, 30, - E_MEETING_TIME_SELECTOR_BUSY_OUT_OF_OFFICE); - e_meeting_time_selector_attendee_add_busy_period (mts, row, - 1999, 11, 7, 11, 00, - 1999, 11, 7, 12, 00, - E_MEETING_TIME_SELECTOR_BUSY_TENTATIVE); -} diff --git a/widgets/misc/.cvsignore b/widgets/misc/.cvsignore deleted file mode 100644 index 411f0fc219..0000000000 --- a/widgets/misc/.cvsignore +++ /dev/null @@ -1,9 +0,0 @@ -.deps -.libs -.pure -Makefile -Makefile.in -*.lo -*.la -test-title-bar -test-calendar diff --git a/widgets/misc/ChangeLog b/widgets/misc/ChangeLog deleted file mode 100644 index 279e7fc9bc..0000000000 --- a/widgets/misc/ChangeLog +++ /dev/null @@ -1,50 +0,0 @@ -2000-08-10 Christopher James Lahey <clahey@helixcode.com> - - * e-calendar-item.c, e-calendar.c: Fixed some warnings. - -2000-07-25 Damon Chaplin <damon@helixcode.com> - - * e-calendar-item.h: - * e-calendar.[hc]: new widget and canvas item to replace GtkCalendar. - Not quite finished yet. - -2000-07-21 Ettore Perazzoli <ettore@helixcode.com> - - * e-title-bar.c (e_title_bar_set_title): We have a `EClippedLabel', - not a `GtkLabel' here: use the right function to change the text. - -2000-07-12 Christopher James Lahey <clahey@helixcode.com> - - * e-scroll-frame.c: Tried rearranging the casts to try for a more - correct computation. - -2000-07-08 Dan Winship <danw@helixcode.com> - - * e-scroll-frame.c (e_scroll_frame_add): comment out true but - confused warning about non-scrollable widgets until Chris and/or - Federico fix this correctly. - (e_scroll_frame_size_allocate): If the available space for the - child is less than the width/height of the frame, give the child - an allocation of 0 rather than some small negative number cast to - unsigned. - -2000-07-05 Dan Winship <danw@helixcode.com> - - * Makefile.am (INCLUDES): Set G_LOG_DOMAIN=__FILE__ rather than - "e-title-bar" in all three widgets. - -2000-06-13 Anders Carlsson <andersca@gnu.org> - - * e-scroll-frame.c (e_scroll_frame_button_press): Control does - horizontal scrolling, a la gimp. - -2000-06-11 Anders Carlsson <andersca@gnu.org> - - * e-scroll-frame.c (e_scroll_frame_button_press): Add support - for mouse wheel scrolling in EScrollFrame. - -2000-06-10 Ettore Perazzoli <ettore@helixcode.com> - - * e-title-bar.c (close_button_realize_cb): Unref the pixmap and - the mask. - diff --git a/widgets/misc/Makefile.am b/widgets/misc/Makefile.am deleted file mode 100644 index e2872e7006..0000000000 --- a/widgets/misc/Makefile.am +++ /dev/null @@ -1,42 +0,0 @@ -# FIXME we use the EClippedLabel widget from EShortcutBar. Probably -# it should be moved somewhere else. - -INCLUDES = \ - -I$(top_srcdir) \ - -I$(top_srcdir)/widgets/shortcut-bar \ - $(EXTRA_GNOME_CFLAGS) \ - -DG_LOG_DOMAIN=__FILE__ - -noinst_LIBRARIES = \ - libemiscwidgets.a - -libemiscwidgets_a_SOURCES = \ - e-calendar.c \ - e-calendar.h \ - e-calendar-item.c \ - e-calendar-item.h \ - e-clipped-label.c \ - e-clipped-label.h \ - e-scroll-frame.c \ - e-scroll-frame.h \ - e-title-bar.c \ - e-title-bar.h - -noinst_PROGRAMS = \ - test-title-bar \ - test-calendar - -test_title_bar_SOURCES = \ - test-title-bar.c - -test_title_bar_LDADD = \ - ./libemiscwidgets.a \ - $(EXTRA_GNOME_LIBS) - -test_calendar_SOURCES = \ - test-calendar.c - -test_calendar_LDADD = \ - ./libemiscwidgets.a \ - ../../e-util/libeutil.la \ - $(EXTRA_GNOME_LIBS) diff --git a/widgets/misc/e-calendar-item.c b/widgets/misc/e-calendar-item.c deleted file mode 100644 index e51754d786..0000000000 --- a/widgets/misc/e-calendar-item.c +++ /dev/null @@ -1,1615 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 2000, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * ECalendarItem - canvas item displaying a calendar. - */ - -#include <config.h> -#include <time.h> -#include <glib.h> -#include <libgnome/gnome-defs.h> -#include <libgnome/gnome-i18n.h> -#include <e-util/e-util.h> -#include "e-calendar-item.h" - - -/* The minimum padding around the numbers in each cell/day. */ -#define E_CALENDAR_ITEM_MIN_CELL_XPAD 4 -#define E_CALENDAR_ITEM_MIN_CELL_YPAD 0 - - -/* These are the padding sizes between various pieces of the calendar. */ -/* FIXME: Use decent names eventually. */ -#define E_CALENDAR_ITEM_XPAD1 4 -#define E_CALENDAR_ITEM_XPAD2 2 -#define E_CALENDAR_ITEM_XPAD3 2 -#define E_CALENDAR_ITEM_XPAD4 4 - -#define E_CALENDAR_ITEM_YPAD3 1 -#define E_CALENDAR_ITEM_YPAD4 0 -#define E_CALENDAR_ITEM_YPAD5 1 -#define E_CALENDAR_ITEM_YPAD6 2 - -#define E_CALENDAR_ITEM_XPAD11 16 -#define E_CALENDAR_ITEM_XPAD12 2 -#define E_CALENDAR_ITEM_XPAD13 1 -#define E_CALENDAR_ITEM_XPAD14 1 -#define E_CALENDAR_ITEM_XPAD15 2 -#define E_CALENDAR_ITEM_XPAD16 16 - -/* The number of rows & columns of days in each month. */ -#define E_CALENDAR_ROWS_PER_MONTH 6 -#define E_CALENDAR_COLS_PER_MONTH 7 - - -static void e_calendar_item_class_init (ECalendarItemClass *class); -static void e_calendar_item_init (ECalendarItem *calitem); - -static void e_calendar_item_get_arg (GtkObject *o, - GtkArg *arg, - guint arg_id); -static void e_calendar_item_set_arg (GtkObject *o, - GtkArg *arg, - guint arg_id); -static void e_calendar_item_realize (GnomeCanvasItem *item); -static void e_calendar_item_unrealize (GnomeCanvasItem *item); -static void e_calendar_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - int flags); -static void e_calendar_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - int x, - int y, - int width, - int height); -static void e_calendar_item_draw_month (ECalendarItem *calitem, - GdkDrawable *drawable, - int x, - int y, - int width, - int height, - int row, - int col); -static void e_calendar_item_draw_day_numbers (ECalendarItem *calitem, - GdkDrawable *drawable, - int width, - int height, - int row, - int col, - int year, - int month, - int start_weekday, - gint cells_x, - gint cells_y); -static double e_calendar_item_point (GnomeCanvasItem *item, - double x, - double y, - int cx, - int cy, - GnomeCanvasItem **actual_item); -static gint e_calendar_item_event (GnomeCanvasItem *item, - GdkEvent *event); -static gboolean e_calendar_item_button_press (ECalendarItem *calitem, - GdkEvent *event); -static gboolean e_calendar_item_button_release (ECalendarItem *calitem, - GdkEvent *event); -static gboolean e_calendar_item_motion (ECalendarItem *calitem, - GdkEvent *event); - -static gboolean e_calendar_item_convert_position_to_day (ECalendarItem *calitem, - gint x, - gint y, - gint *month, - gint *day, - gboolean *entire_week); -static void e_calendar_item_get_month_info (ECalendarItem *calitem, - gint row, - gint col, - gint *first_valid_day, - gint *last_valid_day); -static void e_calendar_item_recalc_sizes(ECalendarItem *calitem); - -static gint e_calendar_item_get_week_number (ECalendarItem *calitem, - gint day, - gint month, - gint year); - -static void e_calendar_item_get_day_style (ECalendarItem *calitem, - gint year, - gint month, - gint day, - gboolean today, - gboolean current_month, - gboolean selected, - GdkColor **bg_color, - GdkColor **fg_color, - GdkColor **box_color, - gboolean *bold); - -static GnomeCanvasItemClass *parent_class; - -/* Our arguments. */ -enum { - ARG_0, - ARG_YEAR, - ARG_MONTH, - ARG_X1, - ARG_Y1, - ARG_X2, - ARG_Y2, - ARG_FONT, - ARG_WEEK_NUMBER_FONT, - ARG_ROW_HEIGHT, - ARG_COLUMN_WIDTH, - ARG_MINIMUM_ROWS, - ARG_MINIMUM_COLUMNS, - ARG_MAXIMUM_ROWS, - ARG_MAXIMUM_COLUMNS, - ARG_WEEK_START_DAY, - ARG_SHOW_WEEK_NUMBERS -}; - - -E_MAKE_TYPE (e_calendar_item, "ECalendarItem", ECalendarItem, - e_calendar_item_class_init, e_calendar_item_init, - GNOME_TYPE_CANVAS_ITEM) - - -static void -e_calendar_item_class_init (ECalendarItemClass *class) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - parent_class = gtk_type_class (gnome_canvas_item_get_type()); - - object_class = (GtkObjectClass *) class; - item_class = (GnomeCanvasItemClass *) class; - - gtk_object_add_arg_type ("ECalendarItem::year", - GTK_TYPE_INT, GTK_ARG_READWRITE, - ARG_YEAR); - gtk_object_add_arg_type ("ECalendarItem::month", - GTK_TYPE_INT, GTK_ARG_READWRITE, - ARG_MONTH); - gtk_object_add_arg_type ("ECalendarItem::x1", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, - ARG_X1); - gtk_object_add_arg_type ("ECalendarItem::y1", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, - ARG_Y1); - gtk_object_add_arg_type ("ECalendarItem::x2", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, - ARG_X2); - gtk_object_add_arg_type ("ECalendarItem::y2", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, - ARG_Y2); - gtk_object_add_arg_type ("ECalendarItem::font", - GTK_TYPE_GDK_FONT, GTK_ARG_READWRITE, - ARG_FONT); - gtk_object_add_arg_type ("ECalendarItem::week_number_font", - GTK_TYPE_GDK_FONT, GTK_ARG_READWRITE, - ARG_WEEK_NUMBER_FONT); - gtk_object_add_arg_type ("ECalendarItem::row_height", - GTK_TYPE_DOUBLE, GTK_ARG_READABLE, - ARG_ROW_HEIGHT); - gtk_object_add_arg_type ("ECalendarItem::column_width", - GTK_TYPE_DOUBLE, GTK_ARG_READABLE, - ARG_COLUMN_WIDTH); - gtk_object_add_arg_type ("ECalendarItem::mininum_rows", - GTK_TYPE_INT, GTK_ARG_READWRITE, - ARG_MINIMUM_ROWS); - gtk_object_add_arg_type ("ECalendarItem::minimum_columns", - GTK_TYPE_INT, GTK_ARG_READWRITE, - ARG_MINIMUM_COLUMNS); - gtk_object_add_arg_type ("ECalendarItem::maximum_rows", - GTK_TYPE_INT, GTK_ARG_READWRITE, - ARG_MAXIMUM_ROWS); - gtk_object_add_arg_type ("ECalendarItem::maximum_columns", - GTK_TYPE_INT, GTK_ARG_READWRITE, - ARG_MAXIMUM_COLUMNS); - gtk_object_add_arg_type ("ECalendarItem::week_start_day", - GTK_TYPE_INT, GTK_ARG_READWRITE, - ARG_WEEK_START_DAY); - gtk_object_add_arg_type ("ECalendarItem::show_week_numbers", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, - ARG_SHOW_WEEK_NUMBERS); - - object_class->get_arg = e_calendar_item_get_arg; - object_class->set_arg = e_calendar_item_set_arg; - - /* GnomeCanvasItem method overrides */ - item_class->realize = e_calendar_item_realize; - item_class->unrealize = e_calendar_item_unrealize; - item_class->update = e_calendar_item_update; - item_class->draw = e_calendar_item_draw; - item_class->point = e_calendar_item_point; - item_class->event = e_calendar_item_event; -} - - -static void -e_calendar_item_init (ECalendarItem *calitem) -{ - struct tm *tmp_tm; - time_t t; - - /* Set the default time to the current month. */ - t = time (NULL); - tmp_tm = localtime (&t); - calitem->year = tmp_tm->tm_year + 1900; - calitem->month = tmp_tm->tm_mon; - - calitem->min_cols = 1; - calitem->min_rows = 1; - calitem->show_week_numbers = FALSE; - calitem->week_start_day = 0; - calitem->expand = TRUE; - - calitem->x1 = 0.0; - calitem->y1 = 0.0; - calitem->x2 = 0.0; - calitem->y2 = 0.0; - - calitem->selection_start_month_offset = -1; - - /* Translators: These are the first characters of each day of the - week, 'M' for 'Monday', 'T' for Tuesday etc. */ - calitem->days = _("MTWTFSS"); -} - - -static void -e_calendar_item_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ECalendarItem *calitem; - - item = GNOME_CANVAS_ITEM (o); - calitem = E_CALENDAR_ITEM (o); - - switch (arg_id) { - case ARG_YEAR: - GTK_VALUE_INT (*arg) = calitem->year; - break; - case ARG_MONTH: - GTK_VALUE_INT (*arg) = calitem->month; - break; - case ARG_X1: - GTK_VALUE_DOUBLE (*arg) = calitem->x1; - break; - case ARG_Y1: - GTK_VALUE_DOUBLE (*arg) = calitem->y1; - break; - case ARG_X2: - GTK_VALUE_DOUBLE (*arg) = calitem->x2; - break; - case ARG_Y2: - GTK_VALUE_DOUBLE (*arg) = calitem->y2; - break; - case ARG_FONT: - GTK_VALUE_BOXED (*arg) = calitem->font; - break; - case ARG_WEEK_NUMBER_FONT: - GTK_VALUE_BOXED (*arg) = calitem->week_number_font; - break; - case ARG_ROW_HEIGHT: - e_calendar_item_recalc_sizes (calitem); - GTK_VALUE_DOUBLE (*arg) = calitem->min_month_height; - break; - case ARG_COLUMN_WIDTH: - e_calendar_item_recalc_sizes (calitem); - GTK_VALUE_DOUBLE (*arg) = calitem->min_month_width; - break; - case ARG_MINIMUM_ROWS: - GTK_VALUE_INT (*arg) = calitem->min_rows; - break; - case ARG_MINIMUM_COLUMNS: - GTK_VALUE_INT (*arg) = calitem->min_cols; - break; - case ARG_MAXIMUM_ROWS: - GTK_VALUE_INT (*arg) = calitem->max_rows; - break; - case ARG_MAXIMUM_COLUMNS: - GTK_VALUE_INT (*arg) = calitem->max_cols; - break; - case ARG_WEEK_START_DAY: - GTK_VALUE_INT (*arg) = calitem->week_start_day; - break; - case ARG_SHOW_WEEK_NUMBERS: - GTK_VALUE_BOOL (*arg) = calitem->show_week_numbers; - break; - } -} - - -static void -e_calendar_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ECalendarItem *calitem; - GdkFont *font; - gboolean need_reshape = FALSE; - gdouble dvalue; - gint ivalue; - gboolean bvalue; - - item = GNOME_CANVAS_ITEM (o); - calitem = E_CALENDAR_ITEM (o); - - switch (arg_id){ - case ARG_YEAR: - ivalue = GTK_VALUE_INT (*arg); - if (calitem->year != ivalue) { - calitem->year = ivalue; - need_reshape = TRUE; - } - break; - case ARG_MONTH: - ivalue = GTK_VALUE_INT (*arg); - if (calitem->month != ivalue) { - calitem->month = ivalue; - need_reshape = TRUE; - } - break; - case ARG_X1: - dvalue = GTK_VALUE_DOUBLE (*arg); - if (calitem->x1 != dvalue) { - calitem->x1 = dvalue; - need_reshape = TRUE; - } - break; - case ARG_Y1: - dvalue = GTK_VALUE_DOUBLE (*arg); - if (calitem->y1 != dvalue) { - calitem->y1 = dvalue; - need_reshape = TRUE; - } - break; - case ARG_X2: - dvalue = GTK_VALUE_DOUBLE (*arg); - if (calitem->x2 != dvalue) { - calitem->x2 = dvalue; - need_reshape = TRUE; - } - break; - case ARG_Y2: - dvalue = GTK_VALUE_DOUBLE (*arg); - if (calitem->y2 != dvalue) { - calitem->y2 = dvalue; - need_reshape = TRUE; - } - break; - case ARG_FONT: - font = GTK_VALUE_BOXED (*arg); - if (calitem->font != font) { - if (calitem->font) - gdk_font_unref (calitem->font); - calitem->font = font; - if (font) - gdk_font_ref (font); - need_reshape = TRUE; - } - break; - case ARG_WEEK_NUMBER_FONT: - font = GTK_VALUE_BOXED (*arg); - if (calitem->week_number_font != font) { - if (calitem->week_number_font) - gdk_font_unref (calitem->week_number_font); - calitem->week_number_font = font; - if (font) - gdk_font_ref (font); - need_reshape = TRUE; - } - break; - case ARG_MINIMUM_ROWS: - ivalue = GTK_VALUE_INT (*arg); - ivalue = MAX (1, ivalue); - if (calitem->min_rows != ivalue) { - calitem->min_rows = ivalue; - need_reshape = TRUE; - } - break; - case ARG_MINIMUM_COLUMNS: - ivalue = GTK_VALUE_INT (*arg); - ivalue = MAX (1, ivalue); - if (calitem->min_cols != ivalue) { - calitem->min_cols = ivalue; - need_reshape = TRUE; - } - break; - case ARG_MAXIMUM_ROWS: - ivalue = GTK_VALUE_INT (*arg); - if (calitem->max_rows != ivalue) { - calitem->max_rows = ivalue; - need_reshape = TRUE; - } - break; - case ARG_MAXIMUM_COLUMNS: - ivalue = GTK_VALUE_INT (*arg); - if (calitem->max_cols != ivalue) { - calitem->max_cols = ivalue; - need_reshape = TRUE; - } - break; - case ARG_WEEK_START_DAY: - ivalue = GTK_VALUE_INT (*arg); - if (calitem->week_start_day != ivalue) { - calitem->week_start_day = ivalue; - need_reshape = TRUE; - } - break; - case ARG_SHOW_WEEK_NUMBERS: - bvalue = GTK_VALUE_BOOL (*arg); - if (calitem->show_week_numbers != bvalue) { - calitem->show_week_numbers = bvalue; - need_reshape = TRUE; - } - break; - default: - g_warning ("Invalid arg"); - } - - /* FIXME: finish. */ - if (need_reshape) { - gnome_canvas_item_request_update (item); - } -} - - -static void -e_calendar_item_realize (GnomeCanvasItem *item) -{ - ECalendarItem *calitem; - GdkColormap *colormap; - gboolean success[E_CALENDAR_COLOR_LAST]; - gint nfailed; - - calitem = E_CALENDAR_ITEM (item); - - colormap = gtk_widget_get_colormap (GTK_WIDGET (item->canvas)); - - calitem->colors[E_CALENDAR_COLOR_SELECTION].red = 65535; - calitem->colors[E_CALENDAR_COLOR_SELECTION].green = 65535; - calitem->colors[E_CALENDAR_COLOR_SELECTION].blue = 65535; - - calitem->colors[E_CALENDAR_COLOR_HIGHLIGHT].red = 56000; - calitem->colors[E_CALENDAR_COLOR_HIGHLIGHT].green = 57000; - calitem->colors[E_CALENDAR_COLOR_HIGHLIGHT].blue = 57000; - - calitem->colors[E_CALENDAR_COLOR_TODAY].red = 65535; - calitem->colors[E_CALENDAR_COLOR_TODAY].green = 0; - calitem->colors[E_CALENDAR_COLOR_TODAY].blue = 0; - - nfailed = gdk_colormap_alloc_colors (colormap, calitem->colors, - E_CALENDAR_COLOR_LAST, FALSE, - TRUE, success); - if (nfailed) - g_warning ("Failed to allocate all colors"); -} - - -static void -e_calendar_item_unrealize (GnomeCanvasItem *item) -{ - ECalendarItem *calitem; - GdkColormap *colormap; - gint i; - - calitem = E_CALENDAR_ITEM (item); - - colormap = gtk_widget_get_colormap (GTK_WIDGET (item->canvas)); - - for (i = 0; i < E_CALENDAR_COLOR_LAST; i++) - gdk_colors_free (colormap, &calitem->colors[i].pixel, 1, 0); -} - - -static void -e_calendar_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - int flags) -{ - ECalendarItem *calitem; - GtkStyle *style; - GdkFont *font; - gint char_height, width, height, space, space_per_cal, space_per_cell; - gint xthickness, ythickness; - - if (GNOME_CANVAS_ITEM_CLASS (parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (parent_class)->update) (item, affine, clip_path, flags); - - calitem = E_CALENDAR_ITEM (item); - style = GTK_WIDGET (item->canvas)->style; - xthickness = style->klass->xthickness; - ythickness = style->klass->ythickness; - - item->x1 = calitem->x1; - item->y1 = calitem->y1; - item->x2 = calitem->x2 >= calitem->x1 ? calitem->x2 : calitem->x1; - item->y2 = calitem->y2 >= calitem->y1 ? calitem->y2 : calitem->y1; - - /* - * Calculate the new layout of the calendar. - */ - - /* Make sure the minimum row width & cell height and the widths of - all the digits and characters are up to date. */ - e_calendar_item_recalc_sizes (calitem); - - /* Calculate how many rows & cols we can fit in. */ - width = item->x2 - item->x1; - height = item->y2 - item->y1; - - width -= xthickness * 2; - height -= ythickness * 2; - - calitem->rows = height / calitem->min_month_height; - calitem->rows = MAX (calitem->rows, calitem->min_rows); - if (calitem->max_rows > 0) - calitem->rows = MIN (calitem->rows, calitem->max_rows); - calitem->cols = width / calitem->min_month_width; - calitem->cols = MAX (calitem->cols, calitem->min_cols); - if (calitem->max_cols > 0) - calitem->cols = MIN (calitem->cols, calitem->max_cols); - - /* Split up the empty space according to the configuration. - If the calendar is set to expand, we divide the space between the - cells and the spaces around the calendar, otherwise we place the - calendars in the center of the available area. */ - - font = calitem->font; - if (!font) - font = style->font; - char_height = font->ascent + font->descent; - - calitem->month_width = calitem->min_month_width; - calitem->month_height = calitem->min_month_height; - calitem->cell_width = calitem->max_digit_width * 2 - + E_CALENDAR_ITEM_MIN_CELL_XPAD; - calitem->cell_height = char_height - + E_CALENDAR_ITEM_MIN_CELL_YPAD; - calitem->month_tpad = 0; - calitem->month_bpad = 0; - calitem->month_lpad = 0; - calitem->month_rpad = 0; - - space = height - calitem->rows * calitem->month_height; - if (space > 0) { - space_per_cal = space / calitem->rows; - calitem->month_height += space_per_cal; - - if (calitem->expand) { - space_per_cell = space_per_cal / E_CALENDAR_ROWS_PER_MONTH; - calitem->cell_height += space_per_cell; - space_per_cal -= space_per_cell * E_CALENDAR_ROWS_PER_MONTH; - } - - calitem->month_tpad = space_per_cal / 2; - calitem->month_bpad = space_per_cal - calitem->month_tpad; - } - - space = width - calitem->cols * calitem->month_width; - if (space > 0) { - space_per_cal = space / calitem->cols; - calitem->month_width += space_per_cal; - space -= space_per_cal * calitem->cols; - - if (calitem->expand) { - space_per_cell = space_per_cal / E_CALENDAR_COLS_PER_MONTH; - calitem->cell_width += space_per_cell; - space_per_cal -= space_per_cell * E_CALENDAR_COLS_PER_MONTH; - } - - calitem->month_lpad = space_per_cal / 2; - calitem->month_rpad = space_per_cal - calitem->month_lpad; - } - - space = MAX (0, space); - calitem->x_offset = space / 2; - - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, - item->x2, item->y2); -} - - -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ - -static void -e_calendar_item_draw (GnomeCanvasItem *canvas_item, - GdkDrawable *drawable, - int x, - int y, - int width, - int height) -{ - ECalendarItem *calitem; - GtkStyle *style; - GdkFont *font; - GdkGC *base_gc, *bg_gc; - gint char_height, row, col, row_y, bar_height, col_x, ythickness; - -#if 0 - g_print ("In e_calendar_item_draw %i,%i %ix%i\n", - x, y, width, height); -#endif - calitem = E_CALENDAR_ITEM (canvas_item); - style = GTK_WIDGET (canvas_item->canvas)->style; - font = calitem->font; - if (!font) - font = style->font; - char_height = font->ascent + font->descent; - ythickness = style->klass->ythickness; - base_gc = style->base_gc[GTK_STATE_NORMAL]; - bg_gc = style->bg_gc[GTK_STATE_NORMAL]; - - /* Clear the entire background. */ - gdk_draw_rectangle (drawable, base_gc, TRUE, - calitem->x1 - x, calitem->y1 - y, - calitem->x2 - calitem->x1, - calitem->y2 - calitem->y1); - - /* Draw the shadow around the entire item. - FIXME: must also leave room for the 'Today' & 'None' buttons etc. */ - gtk_draw_shadow (style, drawable, - GTK_STATE_NORMAL, GTK_SHADOW_OUT, - calitem->x1 - x, calitem->y1 - y, - calitem->x2 - calitem->x1, calitem->y2 - calitem->y1); - - row_y = canvas_item->y1 + ythickness; - bar_height = ythickness * 2 + E_CALENDAR_ITEM_YPAD1 + char_height - + E_CALENDAR_ITEM_YPAD2; - - for (row = 0; row < calitem->rows; row++) { - /* Draw the background for the title bars and the shadow around - it, and the vertical lines between columns. */ - - gdk_draw_rectangle (drawable, bg_gc, TRUE, - calitem->x1 - x, row_y - y, - calitem->x2 - calitem->x1, bar_height); - - gtk_draw_shadow (style, drawable, - GTK_STATE_NORMAL, GTK_SHADOW_OUT, - calitem->x1 - x, row_y - y, - calitem->x2 - calitem->x1, bar_height); - - - for (col = 0; col < calitem->cols; col++) { - if (col != 0) { - col_x = calitem->x1 + calitem->x_offset - + calitem->month_width * col; - gtk_draw_vline (style, drawable, - GTK_STATE_NORMAL, - row_y + ythickness + 1 - y, - row_y + bar_height - - ythickness - 2 - y, - col_x - 1 - x); - } - - - e_calendar_item_draw_month (calitem, drawable, x, y, - width, height, row, col); - } - - row_y += calitem->month_height; - } -} - - -static void -e_calendar_item_draw_month (ECalendarItem *calitem, - GdkDrawable *drawable, - int x, - int y, - int width, - int height, - int row, - int col) -{ - GnomeCanvasItem *item; - GtkWidget *widget; - GtkStyle *style; - GdkFont *font; - GdkGC *fg_gc, *bg_gc; - struct tm tmp_tm; - GdkRectangle clip_rect; - gint char_height, xthickness, ythickness, start_weekday; - gint year, month, month_x, month_y, min_x, max_x, text_x, text_y; - gint day, day_index, cells_x, cells_y, min_cell_width, text_width; - gchar buffer[64]; - -#if 0 - g_print ("In e_calendar_item_draw_month: %i,%i %ix%i\n", - x, y, width, height); -#endif - item = GNOME_CANVAS_ITEM (calitem); - widget = GTK_WIDGET (item->canvas); - style = widget->style; - font = calitem->font; - if (!font) - font = style->font; - char_height = font->ascent + font->descent; - xthickness = style->klass->xthickness; - ythickness = style->klass->ythickness; - fg_gc = style->fg_gc[GTK_STATE_NORMAL]; - bg_gc = style->bg_gc[GTK_STATE_NORMAL]; - - /* Calculate the top-left position of the entire month display. */ - month_x = item->x1 + xthickness + calitem->x_offset - + col * calitem->month_width - x; - month_y = item->y1 + ythickness + row * calitem->month_height - y; - - /* Just return if the month is outside the given area. */ - if (month_x >= width || month_x + calitem->month_width <= 0 - || month_y >= height || month_y + calitem->month_height <= 0) - return; - - - /* Draw the month name & year, with clipping. Note that the top row - needs extra space around it for the buttons. */ - if (row == 0 && col == 0) - min_x = E_CALENDAR_ITEM_XPAD11; - else - min_x = E_CALENDAR_ITEM_XPAD14 + E_CALENDAR_ITEM_XPAD15; - - if (row == 0 && col == calitem->cols - 1) - max_x = calitem->month_width - E_CALENDAR_ITEM_XPAD16; - else - max_x = calitem->month_width - E_CALENDAR_ITEM_XPAD12 - - E_CALENDAR_ITEM_XPAD13; - - text_y = month_y + style->klass->ythickness - + E_CALENDAR_ITEM_YPAD1; - clip_rect.x = month_x + min_x; - clip_rect.y = text_y; - clip_rect.width = max_x - min_x; - clip_rect.height = char_height; - gdk_gc_set_clip_rectangle (fg_gc, &clip_rect); - - memset (&tmp_tm, 0, sizeof (tmp_tm)); - month = calitem->month + row * calitem->cols + col; - year = calitem->year + month / 12; - month %= 12; - tmp_tm.tm_year = year - 1900; - tmp_tm.tm_mon = month; - tmp_tm.tm_mday = 1; - tmp_tm.tm_isdst = -1; - mktime (&tmp_tm); - strftime (buffer, 64, "%B %Y", &tmp_tm); - start_weekday = (tmp_tm.tm_wday + 6) % 7; - - /* Ideally we place the text centered in the month, but we won't go - to the left of the minimum x position. */ - text_width = gdk_string_width (font, buffer); - text_x = (calitem->month_width - text_width) / 2; - text_x = MAX (min_x, text_x); - - gdk_draw_string (drawable, font, fg_gc, - month_x + text_x, text_y + font->ascent, buffer); - - gdk_gc_set_clip_rectangle (fg_gc, NULL); - - - /* Draw the day initials across the top of the month. */ - min_cell_width = calitem->max_digit_width * 2 - + E_CALENDAR_ITEM_MIN_CELL_XPAD; - - cells_x = month_x + E_CALENDAR_ITEM_XPAD1 + calitem->month_lpad - + E_CALENDAR_ITEM_XPAD3; - if (calitem->show_week_numbers) - cells_x += calitem->max_week_number_digit_width * 2 - + E_CALENDAR_ITEM_XPAD2 + 1; - text_x = cells_x + calitem->cell_width - - (calitem->cell_width - min_cell_width) / 2; - text_x -= E_CALENDAR_ITEM_MIN_CELL_XPAD / 2; - text_y = month_y + ythickness * 2 + E_CALENDAR_ITEM_YPAD1 - + char_height + E_CALENDAR_ITEM_YPAD2 + E_CALENDAR_ITEM_YPAD3 - + calitem->month_tpad; - - cells_y = text_y + char_height + E_CALENDAR_ITEM_YPAD4 + 1 - + E_CALENDAR_ITEM_YPAD5; - - text_y += font->ascent; - day_index = calitem->week_start_day; - for (day = 0; day < 7; day++) { - gdk_draw_text (drawable, font, fg_gc, - text_x - calitem->day_widths[day_index], text_y, - &calitem->days[day_index], 1); - text_x += calitem->cell_width; - day_index++; - if (day_index == 7) - day_index = 0; - } - - - /* Draw the horizontal line beneath the day initials. */ - gdk_draw_line (drawable, fg_gc, - cells_x - E_CALENDAR_ITEM_XPAD3, - cells_y - E_CALENDAR_ITEM_YPAD5, - cells_x + E_CALENDAR_COLS_PER_MONTH * calitem->cell_width - 1, - cells_y - E_CALENDAR_ITEM_YPAD5); - - e_calendar_item_draw_day_numbers (calitem, drawable, width, height, - row, col, year, month, start_weekday, - cells_x, cells_y); - - /* Draw the vertical line after the week number. */ - if (calitem->show_week_numbers) { - gdk_draw_line (drawable, fg_gc, - cells_x - E_CALENDAR_ITEM_XPAD3, - cells_y, - cells_x - E_CALENDAR_ITEM_XPAD3, - cells_y + E_CALENDAR_ROWS_PER_MONTH * calitem->cell_height - 1); - } -} - - -static void -e_calendar_item_draw_day_numbers (ECalendarItem *calitem, - GdkDrawable *drawable, - int width, - int height, - int row, - int col, - int year, - int month, - int start_weekday, - gint cells_x, - gint cells_y) -{ - GnomeCanvasItem *item; - GtkWidget *widget; - GtkStyle *style; - GdkFont *font, *wkfont; - GdkGC *fg_gc; - GdkColor *bg_color, *fg_color, *box_color; - struct tm *today_tm; - time_t t; - gint char_height, min_cell_width, min_cell_height; - gint day_num, drow, dcol, day_x, day_y; - gint text_x, text_y; - gint num_chars, digit; - gint week_num, mon, days_from_week_start; - gint years[3], months[3], days_in_month[3]; - gboolean bold, today, draw_day, finished = FALSE, selected; - gint today_year, today_month, today_mday, month_offset, day_offset; - gchar buffer[2]; - - item = GNOME_CANVAS_ITEM (calitem); - widget = GTK_WIDGET (item->canvas); - style = widget->style; - font = calitem->font; - if (!font) - font = style->font; - wkfont = calitem->week_number_font; - if (!wkfont) - wkfont = font; - fg_gc = style->fg_gc[GTK_STATE_NORMAL]; - char_height = font->ascent + font->descent; - - min_cell_width = calitem->max_digit_width * 2 - + E_CALENDAR_ITEM_MIN_CELL_XPAD; - min_cell_height = char_height + E_CALENDAR_ITEM_MIN_CELL_YPAD; - - /* Calculate the number of days in the previous, current, and next - months. Note that g_date uses 1 to 12 for months. */ - years[0] = years[1] = years[2] = year; - months[0] = month - 1; - months[1] = month; - months[2] = month + 1; - if (months[0] == -1) { - months[0] = 11; - years[0]--; - } - if (months[2] == 12) { - months[2] = 0; - years[2]++; - } - - days_in_month[0] = g_date_days_in_month (months[0] + 1, years[0]); - days_in_month[1] = g_date_days_in_month (months[1] + 1, years[1]); - days_in_month[2] = g_date_days_in_month (months[2] + 1, years[2]); - - /* Mon 0 is the previous month, which we may show the end of. Mon 1 is - the current month, and mon 2 is the next month. */ - mon = 0; - - day_num = days_in_month[0]; - days_from_week_start = (start_weekday + 7 - calitem->week_start_day) - % 7; - /* For the top-left month we show the end of the previous month, and - if the new month starts on the first day of the week we show a - complete week from the previous month. */ - if (days_from_week_start == 0) { - if (row == 0 && col == 0) { - day_num -= 6; - } else { - mon++; - day_num = 1; - } - } else { - day_num -= days_from_week_start - 1; - } - - /* Get today's date, so we can highlight it. */ - t = time (NULL); - today_tm = localtime (&t); - today_year = today_tm->tm_year + 1900; - today_month = today_tm->tm_mon; - today_mday = today_tm->tm_mday; - - /* We usually skip the last days of the previous month (mon = 0), - except for the top-left month displayed. */ - draw_day = (mon == 1 || (row == 0 && col == 0)); - - month_offset = row * calitem->cols + col; - day_offset = 0; - - for (drow = 0; drow < 6; drow++) { - /* Draw the week number. */ - if (calitem->show_week_numbers) { - week_num = e_calendar_item_get_week_number (calitem, - day_num, - months[mon], - years[mon]); - - text_x = cells_x - E_CALENDAR_ITEM_XPAD3 - 1 - - E_CALENDAR_ITEM_XPAD2; - text_y = cells_y + drow * calitem->cell_height + - + (calitem->cell_height - min_cell_height + 1) / 2; - - num_chars = 0; - if (week_num >= 10) { - digit = week_num / 10; - text_x -= calitem->week_number_digit_widths[digit]; - buffer[num_chars++] = digit + '0'; - } - - digit = week_num % 10; - text_x -= calitem->week_number_digit_widths[digit]; - buffer[num_chars++] = digit + '0'; - - gdk_draw_text (drawable, wkfont, fg_gc, - text_x, text_y + font->ascent, - buffer, num_chars); - } - - for (dcol = 0; dcol < 7; dcol++) { - if (draw_day) { - day_x = cells_x + dcol * calitem->cell_width; - day_y = cells_y + drow * calitem->cell_height; - - today = years[mon] == today_year - && months[mon] == today_month - && day_num == today_mday; - - selected = calitem->selection_start_month_offset != -1 - && (calitem->selection_start_month_offset < month_offset - || (calitem->selection_start_month_offset == month_offset - && calitem->selection_start_day_offset <= day_offset)) - && (calitem->selection_end_month_offset > month_offset - || (calitem->selection_end_month_offset == month_offset - && calitem->selection_end_day_offset >= day_offset)); - - /* Get the colors & style to use for the day.*/ - e_calendar_item_get_day_style (calitem, - years[mon], - months[mon], - day_num, - today, - mon == 1, - selected, - &bg_color, - &fg_color, - &box_color, - &bold); - - /* Draw the background, if set. */ - if (bg_color) { - gdk_gc_set_foreground (fg_gc, bg_color); - gdk_draw_rectangle (drawable, fg_gc, - TRUE, - day_x, day_y, - calitem->cell_width, - calitem->cell_height); - } - - /* Draw the box, if set. */ - if (box_color) { - gdk_gc_set_foreground (fg_gc, box_color); - gdk_draw_rectangle (drawable, fg_gc, - FALSE, - day_x, day_y, - calitem->cell_width - 1, - calitem->cell_height - 1); - } - - /* Draw the 1- or 2-digit day number. */ - day_x += calitem->cell_width - (calitem->cell_width - min_cell_width) / 2; - day_x -= E_CALENDAR_ITEM_MIN_CELL_XPAD / 2; - day_y += (calitem->cell_height - min_cell_height + 1) / 2; - day_y += E_CALENDAR_ITEM_MIN_CELL_YPAD / 2; - - num_chars = 0; - if (day_num >= 10) { - digit = day_num / 10; - day_x -= calitem->digit_widths[digit]; - buffer[num_chars++] = digit + '0'; - } - - digit = day_num % 10; - day_x -= calitem->digit_widths[digit]; - buffer[num_chars++] = digit + '0'; - - if (fg_color) { - gdk_gc_set_foreground (fg_gc, - fg_color); - } else { - gdk_gc_set_foreground (fg_gc, - &style->fg[GTK_STATE_NORMAL]); - } - - gdk_draw_text (drawable, font, fg_gc, - day_x, - day_y + font->ascent, - buffer, num_chars); - /* We use a stupid technique for bold. Just - draw it again 1 pixel to the left. */ - if (bold) - gdk_draw_text (drawable, font, fg_gc, - day_x - 1, - day_y + font->ascent, - buffer, num_chars); - } - - /* See if we've reached the end of a month. */ - if (day_num == days_in_month[mon]) { - mon++; - /* We only draw the start of the next month - for the bottom-right month displayed. */ - if (mon == 2 && (row != calitem->rows - 1 - || col != calitem->cols - 1)) { - /* Set a flag so we exit the loop. */ - finished = TRUE; - break; - } - day_num = 1; - draw_day = TRUE; - } else { - day_num++; - } - - day_offset++; - } - - /* Exit the loop if the flag is set. */ - if (finished) - break; - } - - /* Reset the foreground color. */ - gdk_gc_set_foreground (fg_gc, &style->fg[GTK_STATE_NORMAL]); -} - - -static gint -e_calendar_item_get_week_number (ECalendarItem *calitem, - gint day, - gint month, - gint year) -{ - GDate tmp_date; - gint weekday, yearday, offset, week_num; - - /* FIXME: check what happens at year boundaries. */ - - g_date_clear (&tmp_date, 1); - g_date_set_dmy (&tmp_date, day, month + 1, year); - - /* This results in a value of 0 (Monday) - 6 (Sunday). */ - weekday = g_date_weekday (&tmp_date) - 1; - - /* Calculate the offset from the start of the week. */ - offset = (calitem->week_start_day + 7 - weekday) % 7; - - /* Calculate the day of the year, from 0 to 365. */ - yearday = g_date_day_of_year (&tmp_date) - 1; - - /* If the week starts on or after 29th December, it is week 1 of the - next year, since there are 4 days in the next year. */ - g_date_subtract_days (&tmp_date, offset); - if (g_date_month (&tmp_date) == 12 && g_date_day (&tmp_date) >= 29) - return 1; - - /* Calculate the week number, from 0. */ - week_num = (yearday - offset) / 7; - - /* If the first week starts on or after Jan 5th, then we need to add - 1 since the previous week will really be the first week. */ - if ((yearday - offset) % 7 >= 4) - week_num++; - - /* Add 1 so week numbers are from 1 to 53. */ - return week_num + 1; -} - - - -/* This is supposed to return the nearest item the the point and the distance. - Since we are the only item we just return ourself and 0 for the distance. - This is needed so that we get button/motion events. */ -static double -e_calendar_item_point (GnomeCanvasItem *item, double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - - -static gint -e_calendar_item_event (GnomeCanvasItem *item, GdkEvent *event) -{ - ECalendarItem *calitem; - - calitem = E_CALENDAR_ITEM (item); - - switch (event->type) { - case GDK_BUTTON_PRESS: - return e_calendar_item_button_press (calitem, event); - case GDK_BUTTON_RELEASE: - return e_calendar_item_button_release (calitem, event); - case GDK_MOTION_NOTIFY: - return e_calendar_item_motion (calitem, event); - default: - break; - } - - return FALSE; -} - - - -/* This checks if any fonts have changed, and if so it recalculates the - layout of the item. */ -static void -e_calendar_item_recalc_sizes (ECalendarItem *calitem) -{ - GnomeCanvasItem *canvas_item; - GtkStyle *style; - GdkFont *font, *wkfont; - gchar *digits = "0123456789"; - gint day, digit, max_digit_width, max_week_number_digit_width; - gint char_height, width, min_cell_width, min_cell_height; - - canvas_item = GNOME_CANVAS_ITEM (calitem); - style = GTK_WIDGET (canvas_item->canvas)->style; - - font = calitem->font; - if (!font) - font = style->font; - wkfont = calitem->week_number_font; - if (!wkfont) - wkfont = font; - char_height = font->ascent + font->descent; - - /* If both fonts are the same, just return. */ - if (font == calitem->old_font - && wkfont == calitem->old_week_number_font) - return; - - calitem->old_font = font; - calitem->old_week_number_font = wkfont; - - for (day = 0; day < 7; day++) - calitem->day_widths[day] = gdk_char_width (font, - calitem->days[day]); - - max_digit_width = 0; - max_week_number_digit_width = 0; - for (digit = 0; digit < 10; digit++) { - width = gdk_char_width (font, digits[digit]); - calitem->digit_widths[digit] = width; - max_digit_width = MAX (max_digit_width, width); - - if (wkfont) { - width = gdk_char_width (wkfont, digits[digit]); - calitem->week_number_digit_widths[digit] = width; - max_week_number_digit_width = MAX (max_week_number_digit_width, width); - } else { - calitem->week_number_digit_widths[digit] = width; - max_week_number_digit_width = max_digit_width; - } - } - calitem->max_digit_width = max_digit_width; - calitem->max_week_number_digit_width = max_week_number_digit_width; - - - min_cell_width = max_digit_width * 2 + E_CALENDAR_ITEM_MIN_CELL_XPAD; - min_cell_height = char_height + E_CALENDAR_ITEM_MIN_CELL_YPAD; - - calitem->min_month_width = E_CALENDAR_ITEM_XPAD1 - + E_CALENDAR_ITEM_XPAD3 + min_cell_width * 7 - + E_CALENDAR_ITEM_XPAD4; - if (calitem->show_week_numbers) - calitem->min_month_width += max_week_number_digit_width * 2 - + E_CALENDAR_ITEM_XPAD2 + 1; - - calitem->min_month_height = style->klass->ythickness * 2 - + E_CALENDAR_ITEM_YPAD1 + char_height - + E_CALENDAR_ITEM_YPAD2 + 1 + E_CALENDAR_ITEM_YPAD3 - + char_height + E_CALENDAR_ITEM_YPAD4 + 1 - + E_CALENDAR_ITEM_YPAD5 + min_cell_height * 6 - + E_CALENDAR_ITEM_YPAD6; -} - - -static void -e_calendar_item_get_day_style (ECalendarItem *calitem, - gint year, - gint month, - gint day, - gboolean today, - gboolean current_month, - gboolean selected, - GdkColor **bg_color, - GdkColor **fg_color, - GdkColor **box_color, - gboolean *bold) -{ - *bg_color = NULL; - *fg_color = NULL; - *box_color = NULL; - *bold = FALSE; - - if (today) - *box_color = &calitem->colors[E_CALENDAR_COLOR_TODAY]; - - if (!current_month) - *fg_color = &calitem->colors[E_CALENDAR_COLOR_HIGHLIGHT]; - - if (selected) { - *fg_color = &calitem->colors[E_CALENDAR_COLOR_SELECTION]; - *bg_color = &calitem->colors[E_CALENDAR_COLOR_HIGHLIGHT]; - } -} - - - -static gboolean -e_calendar_item_button_press (ECalendarItem *calitem, - GdkEvent *event) -{ - gint month, day; - gboolean all_week; - - g_print ("In e_calendar_item_button_press\n"); - - if (e_calendar_item_convert_position_to_day (calitem, - event->button.x, - event->button.y, - &month, &day, &all_week)) { - g_print (" Pressed month: %i day: %i\n", month, day); - - calitem->selection_start_month_offset = month; - calitem->selection_start_day_offset = day; - calitem->selection_end_month_offset = month; - calitem->selection_end_day_offset = day; - calitem->selecting = TRUE; - calitem->selection_dragging_end = TRUE; - - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (calitem)); - - return TRUE; - } - - return FALSE; -} - - -static gboolean -e_calendar_item_button_release (ECalendarItem *calitem, - GdkEvent *event) -{ - gint month, day; - gboolean all_week; - - g_print ("In e_calendar_item_button_release\n"); - - calitem->selecting = FALSE; - - if (e_calendar_item_convert_position_to_day (calitem, - event->button.x, - event->button.y, - &month, &day, &all_week)) - g_print (" Released month: %i day: %i\n", month, day); - - return FALSE; -} - - -static gboolean -e_calendar_item_motion (ECalendarItem *calitem, - GdkEvent *event) -{ - gint month, day; - gboolean all_week; - - if (!calitem->selecting) - return FALSE; - - if (e_calendar_item_convert_position_to_day (calitem, - event->button.x, - event->button.y, - &month, &day, &all_week)) { - if (calitem->selection_dragging_end) { - if (calitem->selection_end_month_offset == month - && calitem->selection_end_day_offset == day) - return FALSE; - calitem->selection_end_month_offset = month; - calitem->selection_end_day_offset = day; - } else { - if (calitem->selection_start_month_offset == month - && calitem->selection_start_day_offset == day) - return FALSE; - calitem->selection_start_month_offset = month; - calitem->selection_start_day_offset = day; - } - - if (calitem->selection_start_month_offset > calitem->selection_end_month_offset - || (calitem->selection_start_month_offset == calitem->selection_end_month_offset - && calitem->selection_start_day_offset > calitem->selection_end_day_offset)) { - month = calitem->selection_start_month_offset; - day = calitem->selection_start_day_offset; - calitem->selection_start_month_offset = calitem->selection_end_month_offset; - calitem->selection_end_month_offset = month; - calitem->selection_start_day_offset = calitem->selection_end_day_offset; - calitem->selection_end_day_offset = day; - - calitem->selection_dragging_end = !calitem->selection_dragging_end; - } - - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (calitem)); - } - - return FALSE; -} - - - - -/* Converts a position within the item to a month & day. - The month returned is 0 for the top-left month displayed. - If the position is over a week number the first day of the week is returned - and entire_week is set to TRUE. */ -static gboolean -e_calendar_item_convert_position_to_day (ECalendarItem *calitem, - gint event_x, - gint event_y, - gint *month, - gint *day, - gboolean *entire_week) -{ - GnomeCanvasItem *item; - GtkWidget *widget; - GtkStyle *style; - gint xthickness, ythickness, char_height; - gint x, y, row, col, cells_x, cells_y, day_row, day_col; - gint first_valid_day, last_valid_day; - - item = GNOME_CANVAS_ITEM (calitem); - widget = GTK_WIDGET (item->canvas); - style = widget->style; - char_height = style->font->ascent + style->font->descent; - xthickness = style->klass->xthickness; - ythickness = style->klass->ythickness; - - x = event_x - xthickness - calitem->x_offset; - y = event_y - ythickness; - - if (x < 0 || y < 0) - return FALSE; - - row = y / calitem->month_height; - col = x / calitem->month_width; - - if (row < 0 || row >= calitem->rows - || col < 0 || col >= calitem->cols) - return FALSE; - - x = x % calitem->month_width; - y = y % calitem->month_height; - - cells_x = E_CALENDAR_ITEM_XPAD1 + calitem->month_lpad - + E_CALENDAR_ITEM_XPAD3; - if (calitem->show_week_numbers) - cells_x += calitem->max_week_number_digit_width * 2 - + E_CALENDAR_ITEM_XPAD2 + 1; - cells_y = ythickness * 2 + E_CALENDAR_ITEM_YPAD1 - + char_height + E_CALENDAR_ITEM_YPAD2 + E_CALENDAR_ITEM_YPAD3 - + calitem->month_tpad - + char_height + E_CALENDAR_ITEM_YPAD4 + 1 - + E_CALENDAR_ITEM_YPAD5; - - x -= cells_x; - y -= cells_y; - - if (x < 0 || y < 0) - return FALSE; - - day_row = y / calitem->cell_height; - day_col = x / calitem->cell_width; - - if (day_row < 0 || day_row >= E_CALENDAR_ROWS_PER_MONTH - || day_col < 0 || day_col >= E_CALENDAR_COLS_PER_MONTH) - return FALSE; - - *month = row * calitem->cols + col; - *day = day_row * E_CALENDAR_COLS_PER_MONTH + day_col; - *entire_week = FALSE; - - e_calendar_item_get_month_info (calitem, row, col, - &first_valid_day, &last_valid_day); - if (*day < first_valid_day || *day > last_valid_day) - return FALSE; - - return TRUE; -} - - -static void -e_calendar_item_get_month_info (ECalendarItem *calitem, - gint row, - gint col, - gint *first_valid_day, - gint *last_valid_day) -{ - gint year, month, days_in_month, start_weekday, first_day_of_month; - struct tm tmp_tm = { 0 }; - - month = calitem->month + row * calitem->cols + col; - year = calitem->year + month / 12; - month = month % 12; - days_in_month = g_date_days_in_month (month + 1, year); - - tmp_tm.tm_year = year - 1900; - tmp_tm.tm_mon = month; - tmp_tm.tm_mday = 1; - tmp_tm.tm_isdst = -1; - mktime (&tmp_tm); - - /* Convert to 0 (Monday) to 6 (Sunday). */ - start_weekday = (tmp_tm.tm_wday + 6) % 7; - - first_day_of_month = (start_weekday + 7 - calitem->week_start_day) % 7; - - if (row == 0 && col == 0) - *first_valid_day = 0; - else - *first_valid_day = first_day_of_month; - - if (row == calitem->rows - 1 && col == calitem->cols - 1) - *last_valid_day = E_CALENDAR_ROWS_PER_MONTH * E_CALENDAR_COLS_PER_MONTH - 1; - else - *last_valid_day = first_day_of_month + days_in_month - 1; -} - - - - - - - - - - - - - - - - - - - - - - -#if 0 - -static gint -e_calendar_button_press (GtkWidget *widget, - GdkEventButton *event) -{ - ECalendar *cal; - gint day; - - cal = E_CALENDAR (widget); - - g_print ("In e_calendar_button_press\n"); - - day = e_calendar_convert_position_to_day (cal, event->x, event->y); - - cal->selection_start_day = day; - cal->selection_end_day = day; - cal->selection_dragging_end = TRUE; - - gtk_widget_queue_draw (widget); - - return FALSE; -} - - -static gint -e_calendar_button_release (GtkWidget *widget, - GdkEventButton *event) -{ - g_print ("In e_calendar_button_release\n"); - - return FALSE; -} - - -static gint -e_calendar_motion (GtkWidget *widget, - GdkEventMotion *event) -{ - ECalendar *cal; - gint x, y, day; - - cal = E_CALENDAR (widget); - - g_print ("In e_calendar_motion\n"); - - x = event->x; - y = event->y; - - if (event->is_hint || event->window != widget->window) - gtk_widget_get_pointer (widget, &x, &y); - - day = e_calendar_convert_position_to_day (cal, event->x, event->y); - - if (cal->selection_dragging_end) - cal->selection_end_day = day; - else - cal->selection_start_day = day; - - if (cal->selection_start_day > cal->selection_end_day) { - day = cal->selection_start_day; - cal->selection_start_day = cal->selection_end_day; - cal->selection_end_day = day; - cal->selection_dragging_end = !cal->selection_dragging_end; - } - - gtk_widget_queue_draw (widget); - - return FALSE; -} -#endif diff --git a/widgets/misc/e-calendar-item.h b/widgets/misc/e-calendar-item.h deleted file mode 100644 index a59ca6d407..0000000000 --- a/widgets/misc/e-calendar-item.h +++ /dev/null @@ -1,151 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 2000, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_CALENDAR_ITEM_H_ -#define _E_CALENDAR_ITEM_H_ - -#include <libgnomeui/gnome-canvas.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * ECalendarItem - canvas item displaying a calendar. - */ - -#define E_CALENDAR_ITEM_YPAD1 1 -#define E_CALENDAR_ITEM_YPAD2 1 - -/* These index our colors array. */ -typedef enum -{ - E_CALENDAR_COLOR_SELECTION, - E_CALENDAR_COLOR_HIGHLIGHT, - E_CALENDAR_COLOR_TODAY, - - E_CALENDAR_COLOR_LAST -} ECalendarColors; - - -#define E_CALENDAR_ITEM(obj) (GTK_CHECK_CAST((obj), \ - e_calendar_item_get_type (), ECalendarItem)) -#define E_CALENDAR_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k),\ - e_calendar_item_get_type ())) -#define E_IS_CALENDAR_ITEM(o) (GTK_CHECK_TYPE((o), \ - e_calendar_item_get_type ())) - -typedef struct { - GnomeCanvasItem canvas_item; - - /* The year & month of the first calendar being displayed. */ - gint year; - gint month; /* 0 to 11 */ - - /* Bounds of item. */ - gdouble x1, y1, x2, y2; - - /* The minimum & maximum number of rows & columns of months. */ - gint min_rows; - gint min_cols; - gint max_rows; - gint max_cols; - - /* The number of rows & columns of months. */ - gint rows; - gint cols; - - /* Whether we show week nubers. */ - gboolean show_week_numbers; - - /* The first day of the week, 0 (Monday) to 6 (Sunday). */ - gint week_start_day; - - /* Whether the cells expand to fill extra space. */ - gboolean expand; - - /* The minimum size of each month, based on the fonts used. */ - gint min_month_width; - gint min_month_height; - - /* The actual size of each month, after dividing extra space. */ - gint month_width; - gint month_height; - - /* The offset to the left edge of the first calendar. */ - gint x_offset; - - /* The padding around each calendar month. */ - gint month_lpad, month_rpad; - gint month_tpad, month_bpad; - - /* The size of each cell. */ - gint cell_width; - gint cell_height; - - - /* The current selection. The month offsets are from 0, which is the - top-left calendar month view. The day offsets are from 0, which is - the top-left cell in the month view (which may be empty). */ - gint selection_start_month_offset; - gint selection_start_day_offset; - gint selection_end_month_offset; - gint selection_end_day_offset; - gboolean selecting; - gboolean selection_dragging_end; - - /* The first character of each day of the week, e.g. 'MTWTFSS'. */ - gchar *days; - - /* Widths of the day characters. */ - gint day_widths[7]; - - /* Widths of the digits, '0' .. '9'. */ - gint digit_widths[10]; - gint max_digit_width; - gint week_number_digit_widths[10]; - gint max_week_number_digit_width; - - /* Fonts for drawing text. If font isn't set it uses the font from the - canvas widget. If week_number_font isn't set it uses font. */ - GdkFont *font, *old_font; - GdkFont *week_number_font, *old_week_number_font; - - /* Colors for drawing. */ - GdkColor colors[E_CALENDAR_COLOR_LAST]; -} ECalendarItem; - -typedef struct { - GnomeCanvasItemClass parent_class; - -} ECalendarItemClass; - - -GtkType e_calendar_item_get_type (void); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_CALENDAR_ITEM_H_ */ diff --git a/widgets/misc/e-calendar.c b/widgets/misc/e-calendar.c deleted file mode 100644 index ec85e3471f..0000000000 --- a/widgets/misc/e-calendar.c +++ /dev/null @@ -1,486 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 2000, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * ECalendar - displays a table of monthly calendars, allowing highlighting - * and selection of one or more days. Like GtkCalendar with more features. - * Most of the functionality is in the ECalendarItem canvas item, though - * we also add GnomeCanvasWidget buttons to go to the previous/next month and - * to got to the current day. - */ - -#include <config.h> -#include <e-util/e-util.h> -#include "e-calendar.h" - -#define E_CALENDAR_SMALL_FONT \ - "-adobe-utopia-regular-r-normal-*-*-100-*-*-p-*-iso8859-*" -#define E_CALENDAR_SMALL_FONT_FALLBACK \ - "-adobe-helvetica-medium-r-normal-*-*-80-*-*-p-*-iso8859-*" - -#define E_CALENDAR_BUTTON_X_PAD 2 -#define E_CALENDAR_BUTTON_Y_PAD 0 - -static void e_calendar_class_init (ECalendarClass *class); -static void e_calendar_init (ECalendar *cal); -static void e_calendar_destroy (GtkObject *object); -static void e_calendar_realize (GtkWidget *widget); -static void e_calendar_style_set (GtkWidget *widget, - GtkStyle *previous_style); -static void e_calendar_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void e_calendar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static gint e_calendar_expose (GtkWidget *widget, - GdkEventExpose *event); -static void e_calendar_draw (GtkWidget *widget, - GdkRectangle *area); -#if 0 -static gint e_calendar_button_press (GtkWidget *widget, - GdkEventButton *event); -static gint e_calendar_button_release (GtkWidget *widget, - GdkEventButton *event); -#endif -static gint e_calendar_focus_in (GtkWidget *widget, - GdkEventFocus *event); -static gint e_calendar_focus_out (GtkWidget *widget, - GdkEventFocus *event); -static gint e_calendar_key_press (GtkWidget *widget, - GdkEventKey *event); - -static void e_calendar_paint (ECalendar *cal, - GdkRectangle *area); - -static void e_calendar_on_prev_clicked (ECalendar *cal); -static void e_calendar_on_next_clicked (ECalendar *cal); - -static GnomeCanvasClass *parent_class; -static GtkLayoutClass *grandparent_class; - -E_MAKE_TYPE (e_calendar, "ECalendar", ECalendar, - e_calendar_class_init, e_calendar_init, E_CANVAS_TYPE) - - -static void -e_calendar_class_init (ECalendarClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - - parent_class = gtk_type_class (E_CANVAS_TYPE); - grandparent_class = gtk_type_class (GTK_TYPE_LAYOUT); - - object_class->destroy = e_calendar_destroy; - - widget_class->realize = e_calendar_realize; - widget_class->style_set = e_calendar_style_set; - widget_class->size_request = e_calendar_size_request; - widget_class->size_allocate = e_calendar_size_allocate; - widget_class->expose_event = e_calendar_expose; - widget_class->draw = e_calendar_draw; -#if 0 - widget_class->button_press_event = e_calendar_button_press; - widget_class->button_release_event = e_calendar_button_release; -#endif - widget_class->focus_in_event = e_calendar_focus_in; - widget_class->focus_out_event = e_calendar_focus_out; - widget_class->key_press_event = e_calendar_key_press; -} - - -static void -e_calendar_init (ECalendar *cal) -{ - GnomeCanvasGroup *canvas_group; - GdkFont *small_font; - GtkWidget *button, *arrow; - - /* Create the small font. */ - small_font = gdk_font_load (E_CALENDAR_SMALL_FONT); - if (!small_font) - small_font = gdk_font_load (E_CALENDAR_SMALL_FONT_FALLBACK); - if (!small_font) - g_warning ("Couldn't load font"); - - canvas_group = GNOME_CANVAS_GROUP (GNOME_CANVAS (cal)->root); - - cal->calitem = E_CALENDAR_ITEM (gnome_canvas_item_new (canvas_group, - e_calendar_item_get_type (), - "week_number_font", small_font, - "week_start_day", 6, - NULL)); - -#if 0 - "show_week_numbers", TRUE, - "minimum_columns", 5, - "maximum_columns", 5, -#endif - - if (small_font) - gdk_font_unref (small_font); - - - button = gtk_button_new (); - /* FIXME: The buttons doesn't display properly if we do this. */ - /*gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);*/ - gtk_widget_show (button); - gtk_signal_connect_object (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (e_calendar_on_prev_clicked), - GTK_OBJECT (cal)); - arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_OUT); - gtk_widget_show (arrow); - gtk_container_add (GTK_CONTAINER (button), arrow); - cal->prev_item = gnome_canvas_item_new (canvas_group, - gnome_canvas_widget_get_type (), - "widget", button, - NULL); - - button = gtk_button_new (); - /*gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);*/ - gtk_widget_show (button); - gtk_signal_connect_object (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (e_calendar_on_next_clicked), - GTK_OBJECT (cal)); - arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_OUT); - gtk_widget_show (arrow); - gtk_container_add (GTK_CONTAINER (button), arrow); - cal->next_item = gnome_canvas_item_new (canvas_group, - gnome_canvas_widget_get_type (), - "widget", button, - NULL); - - cal->min_rows = 1; - cal->min_cols = 1; - cal->max_rows = -1; - cal->max_cols = -1; -} - - -/** - * e_calendar_new: - * @Returns: a new #ECalendar. - * - * Creates a new #ECalendar. - **/ -GtkWidget * -e_calendar_new (void) -{ - GtkWidget *cal; - - cal = gtk_type_new (e_calendar_get_type ()); - - return cal; -} - - -static void -e_calendar_destroy (GtkObject *object) -{ - ECalendar *cal; - - g_return_if_fail (object != NULL); - g_return_if_fail (E_IS_CALENDAR (object)); - - cal = E_CALENDAR (object); - - - -} - - -static void -e_calendar_realize (GtkWidget *widget) -{ - (*GTK_WIDGET_CLASS (parent_class)->realize) (widget); -} - - -static void -e_calendar_style_set (GtkWidget *widget, - GtkStyle *previous_style) -{ -} - - -static void -e_calendar_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - ECalendar *cal; - GtkStyle *style; - gdouble col_width, row_height; - gint width, height; - - cal = E_CALENDAR (widget); - style = GTK_WIDGET (cal)->style; - - gtk_object_get (GTK_OBJECT (cal->calitem), - "row_height", &row_height, - "column_width", &col_width, - NULL); - - height = row_height * cal->min_rows; - width = col_width * cal->min_cols; - - /* FIXME: Add on space for line & button if shown. */ - - requisition->width = width + style->klass->xthickness * 2; - requisition->height = height + style->klass->ythickness * 2; -} - - -static void -e_calendar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - ECalendar *cal; - GdkFont *font; - gdouble old_x2, old_y2, new_x2, new_y2; - gdouble xthickness, ythickness, button_size; - - cal = E_CALENDAR (widget); - font = widget->style->font; - xthickness = widget->style->klass->xthickness; - ythickness = widget->style->klass->ythickness; - - (*GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation); - - /* Set the scroll region to its allocated size, if changed. */ - gnome_canvas_get_scroll_region (GNOME_CANVAS (cal), - NULL, NULL, &old_x2, &old_y2); - new_x2 = widget->allocation.width - 1; - new_y2 = widget->allocation.height - 1; - if (old_x2 != new_x2 || old_y2 != new_y2) - gnome_canvas_set_scroll_region (GNOME_CANVAS (cal), - 0, 0, new_x2, new_y2); - - /* FIXME: Take off space for line & buttons if shown. */ - gnome_canvas_item_set (GNOME_CANVAS_ITEM (cal->calitem), - "x1", 0.0, - "y1", 0.0, - "x2", new_x2, - "y2", new_y2, - NULL); - - button_size = font->ascent + font->descent + E_CALENDAR_ITEM_YPAD1 - + E_CALENDAR_ITEM_YPAD2 - E_CALENDAR_BUTTON_Y_PAD * 2; - - gnome_canvas_item_set (cal->prev_item, - "x", xthickness * 2 + E_CALENDAR_BUTTON_X_PAD, - "y", ythickness * 2 + E_CALENDAR_BUTTON_Y_PAD, - "width", button_size, - "height", button_size, - NULL); - - gnome_canvas_item_set (cal->next_item, - "x", new_x2 + 1 - xthickness * 2 - - E_CALENDAR_BUTTON_X_PAD - button_size, - "y", ythickness * 2 + E_CALENDAR_BUTTON_Y_PAD, - "width", button_size, - "height", button_size, - NULL); -} - - -static gint -e_calendar_expose (GtkWidget *widget, - GdkEventExpose *event) -{ - ECalendar *cal; - - cal = E_CALENDAR (widget); - - (*GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event); - - e_calendar_paint (cal, &event->area); - - return FALSE; -} - - -static void -e_calendar_draw (GtkWidget *widget, - GdkRectangle *area) -{ - ECalendar *cal; - - cal = E_CALENDAR (widget); - - (*GTK_WIDGET_CLASS (parent_class)->draw) (widget, area); - - (*GTK_WIDGET_CLASS (grandparent_class)->draw) (widget, area); - - e_calendar_paint (cal, area); -} - - -static void -e_calendar_paint (ECalendar *cal, - GdkRectangle *area) -{ -#if 0 - g_print ("In e_calendar_paint: %i,%i %ix%i\n", area->x, area->y, - area->width, area->height); -#endif -} - - -/* FIXME These aren't used? */ - -#if 0 -static gint -e_calendar_button_press (GtkWidget *widget, - GdkEventButton *event) -{ - ECalendar *cal; - - cal = E_CALENDAR (widget); - - g_print ("In e_calendar_button_press\n"); - - return FALSE; -} - - -static gint -e_calendar_button_release (GtkWidget *widget, - GdkEventButton *event) -{ - g_print ("In e_calendar_button_release\n"); - - return FALSE; -} -#endif - - -static gint -e_calendar_focus_in (GtkWidget *widget, - GdkEventFocus *event) -{ - return FALSE; -} - - -static gint -e_calendar_focus_out (GtkWidget *widget, - GdkEventFocus *event) -{ - return FALSE; -} - - -static gint -e_calendar_key_press (GtkWidget *widget, - GdkEventKey *event) -{ - return FALSE; -} - - -void -e_calendar_set_minimum_size (ECalendar *cal, - gint rows, - gint cols) -{ - g_return_if_fail (E_IS_CALENDAR (cal)); - - cal->min_rows = rows; - cal->min_cols = cols; - - gnome_canvas_item_set (GNOME_CANVAS_ITEM (cal->calitem), - "minimum_rows", rows, - "minimum_columns", cols, - NULL); - - gtk_widget_queue_resize (GTK_WIDGET (cal)); -} - - -void -e_calendar_set_maximum_size (ECalendar *cal, - gint rows, - gint cols) -{ - g_return_if_fail (E_IS_CALENDAR (cal)); - - cal->max_rows = rows; - cal->max_cols = cols; - - gnome_canvas_item_set (GNOME_CANVAS_ITEM (cal->calitem), - "maximum_rows", rows, - "maximum_columns", cols, - NULL); - - gtk_widget_queue_resize (GTK_WIDGET (cal)); -} - - -static void -e_calendar_on_prev_clicked (ECalendar *cal) -{ - gint year, month; - - gtk_object_get (GTK_OBJECT (cal->calitem), - "year", &year, - "month", &month, - NULL); - - month--; - if (month == -1) { - year--; - month = 11; - } - - gnome_canvas_item_set (GNOME_CANVAS_ITEM (cal->calitem), - "year", year, - "month", month, - NULL); -} - - -static void -e_calendar_on_next_clicked (ECalendar *cal) -{ - gint year, month; - - gtk_object_get (GTK_OBJECT (cal->calitem), - "year", &year, - "month", &month, - NULL); - - month++; - if (month == 12) { - year++; - month = 0; - } - - gnome_canvas_item_set (GNOME_CANVAS_ITEM (cal->calitem), - "year", year, - "month", month, - NULL); -} - diff --git a/widgets/misc/e-calendar.h b/widgets/misc/e-calendar.h deleted file mode 100644 index b0e9c1f985..0000000000 --- a/widgets/misc/e-calendar.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 2000, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_CALENDAR_H_ -#define _E_CALENDAR_H_ - -#include <gtk/gtkwidget.h> -#include "e-util/e-canvas.h" -#include "e-calendar-item.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * ECalendar - displays a table of monthly calendars, allowing highlighting - * and selection of one or more days. Like GtkCalendar with more features. - * Most of the functionality is in the ECalendarItem canvas item, though - * we also add GnomeCanvasWidget buttons to go to the previous/next month and - * to got to the current day. - */ - -#define E_CALENDAR(obj) GTK_CHECK_CAST (obj, e_calendar_get_type (), ECalendar) -#define E_CALENDAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_calendar_get_type (), ECalendarClass) -#define E_IS_CALENDAR(obj) GTK_CHECK_TYPE (obj, e_calendar_get_type ()) - - -typedef struct _ECalendar ECalendar; -typedef struct _ECalendarClass ECalendarClass; - -struct _ECalendar -{ - ECanvas canvas; - - ECalendarItem *calitem; - - GnomeCanvasItem *prev_item, *next_item; - - gint min_rows; - gint min_cols; - - gint max_rows; - gint max_cols; -}; - -struct _ECalendarClass -{ - ECanvasClass parent_class; -}; - - -GtkType e_calendar_get_type (void); -GtkWidget* e_calendar_new (void); - -void e_calendar_set_minimum_size (ECalendar *cal, - gint rows, - gint cols); -void e_calendar_set_maximum_size (ECalendar *cal, - gint rows, - gint cols); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_CALENDAR_H_ */ diff --git a/widgets/misc/e-canvas-utils.c b/widgets/misc/e-canvas-utils.c deleted file mode 100644 index ac61545b5f..0000000000 --- a/widgets/misc/e-canvas-utils.c +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-canvas-utils.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include "e-canvas-utils.h" - -void -e_canvas_item_move_absolute (GnomeCanvasItem *item, double dx, double dy) -{ - double translate[6]; - - g_return_if_fail (item != NULL); - g_return_if_fail (GNOME_IS_CANVAS_ITEM (item)); - - art_affine_translate (translate, dx, dy); - - gnome_canvas_item_affine_absolute (item, translate); -} - -void -e_canvas_item_show_area (GnomeCanvasItem *item, double x1, double y1, double x2, double y2) -{ - GtkAdjustment *h, *v; - double dx = 0, dy = 0; - - g_return_if_fail (item != NULL); - g_return_if_fail (GNOME_IS_CANVAS_ITEM (item)); - - gnome_canvas_item_i2w(item, &x1, &y1); - gnome_canvas_item_i2w(item, &x2, &y2); - - h = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas)); - v = gtk_layout_get_vadjustment(GTK_LAYOUT(item->canvas)); - - if (x2 > h->value + h->page_size) - dx = (x2 - (h->value + h->page_size)); - if (y2 > v->value + v->page_size) - dy = (y2 - (v->value + v->page_size)); - - if (x1 < h->value + dx) - dx = (x1 - h->value); - if (y1 < v->value + dy) - dy = (y1 - v->value); - - if (dx) - gtk_adjustment_set_value(h, h->value + dx); - if (dy) - gtk_adjustment_set_value(v, v->value + dy); -} diff --git a/widgets/misc/e-canvas-utils.h b/widgets/misc/e-canvas-utils.h deleted file mode 100644 index a940ea393c..0000000000 --- a/widgets/misc/e-canvas-utils.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-canvas-utils.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef __E_CANVAS_UTILS__ -#define __E_CANVAS_UTILS__ - -#include <gnome.h> -void e_canvas_item_move_absolute (GnomeCanvasItem *item, double dx, double dy); -void e_canvas_item_show_area (GnomeCanvasItem *item, double x1, double y1, double x2, double y2); - -#endif /* __E_CANVAS_UTILS__ */ diff --git a/widgets/misc/e-canvas-vbox.c b/widgets/misc/e-canvas-vbox.c deleted file mode 100644 index 2d389a83e6..0000000000 --- a/widgets/misc/e-canvas-vbox.c +++ /dev/null @@ -1,321 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-canvas-vbox.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <config.h> -#include <gnome.h> -#include <math.h> -#include "e-canvas-vbox.h" -#include <e-util/e-canvas-utils.h> -#include <e-util/e-canvas.h> -#include <e-util/e-util.h> - -static void e_canvas_vbox_init (ECanvasVbox *CanvasVbox); -static void e_canvas_vbox_class_init (ECanvasVboxClass *klass); -static void e_canvas_vbox_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); -static void e_canvas_vbox_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_canvas_vbox_destroy (GtkObject *object); - -static gint e_canvas_vbox_event (GnomeCanvasItem *item, GdkEvent *event); -static void e_canvas_vbox_realize (GnomeCanvasItem *item); - -static void e_canvas_vbox_reflow (GnomeCanvasItem *item, int flags); - -static void e_canvas_vbox_real_add_item(ECanvasVbox *e_canvas_vbox, GnomeCanvasItem *item); -static void e_canvas_vbox_resize_children (GnomeCanvasItem *item); - -static GnomeCanvasGroupClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0, - ARG_WIDTH, - ARG_HEIGHT, - ARG_SPACING, -}; - -GtkType -e_canvas_vbox_get_type (void) -{ - static GtkType type = 0; - - if (!type) - { - static const GtkTypeInfo info = - { - "ECanvasVbox", - sizeof (ECanvasVbox), - sizeof (ECanvasVboxClass), - (GtkClassInitFunc) e_canvas_vbox_class_init, - (GtkObjectInitFunc) e_canvas_vbox_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - type = gtk_type_unique (gnome_canvas_group_get_type (), &info); - } - - return type; -} - -static void -e_canvas_vbox_class_init (ECanvasVboxClass *klass) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - object_class = (GtkObjectClass*) klass; - item_class = (GnomeCanvasItemClass *) klass; - - parent_class = gtk_type_class (gnome_canvas_group_get_type ()); - - gtk_object_add_arg_type ("ECanvasVbox::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ECanvasVbox::height", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_HEIGHT); - gtk_object_add_arg_type ("ECanvasVbox::spacing", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_SPACING); - - klass->add_item = e_canvas_vbox_real_add_item; - - object_class->set_arg = e_canvas_vbox_set_arg; - object_class->get_arg = e_canvas_vbox_get_arg; - object_class->destroy = e_canvas_vbox_destroy; - - /* GnomeCanvasItem method overrides */ - item_class->event = e_canvas_vbox_event; - item_class->realize = e_canvas_vbox_realize; -} - -static void -e_canvas_vbox_init (ECanvasVbox *vbox) -{ - vbox->items = NULL; - - vbox->width = 10; - vbox->height = 10; - vbox->spacing = 0; - - e_canvas_item_set_reflow_callback(GNOME_CANVAS_ITEM(vbox), e_canvas_vbox_reflow); -} - -static void -e_canvas_vbox_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ECanvasVbox *e_canvas_vbox; - - item = GNOME_CANVAS_ITEM (o); - e_canvas_vbox = E_CANVAS_VBOX (o); - - switch (arg_id){ - case ARG_WIDTH: - e_canvas_vbox->width = GTK_VALUE_DOUBLE (*arg); - e_canvas_vbox_resize_children(item); - e_canvas_item_request_reflow(item); - break; - case ARG_SPACING: - e_canvas_vbox->spacing = GTK_VALUE_DOUBLE (*arg); - e_canvas_item_request_reflow(item); - break; - } -} - -static void -e_canvas_vbox_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ECanvasVbox *e_canvas_vbox; - - e_canvas_vbox = E_CANVAS_VBOX (object); - - switch (arg_id) { - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = e_canvas_vbox->width; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = e_canvas_vbox->height; - break; - case ARG_SPACING: - GTK_VALUE_DOUBLE (*arg) = e_canvas_vbox->spacing; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -e_canvas_vbox_destroy (GtkObject *object) -{ - ECanvasVbox *vbox = E_CANVAS_VBOX(object); - - g_list_foreach(vbox->items, (GFunc) gtk_object_unref, NULL); - g_list_free(vbox->items); - vbox->items = NULL; - - GTK_OBJECT_CLASS(parent_class)->destroy (object); -} - -static gint -e_canvas_vbox_event (GnomeCanvasItem *item, GdkEvent *event) -{ - gint return_val = TRUE; - - switch (event->type) { - case GDK_KEY_PRESS: - switch (event->key.keyval) { - case GDK_Tab: - case GDK_KP_Tab: - case GDK_ISO_Left_Tab: - case GDK_Left: - case GDK_KP_Left: - case GDK_Right: - case GDK_KP_Right: - case GDK_Down: - case GDK_KP_Down: - case GDK_Up: - case GDK_KP_Up: - case GDK_Return: - case GDK_KP_Enter: - return_val = TRUE; - break; - default: - return_val = FALSE; - break; - } - break; - default: - return_val = FALSE; - break; - } - if (!return_val) { - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS (parent_class)->event (item, event); - } - return return_val; - -} - -static void -e_canvas_vbox_realize (GnomeCanvasItem *item) -{ - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) - (* GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) (item); - - e_canvas_vbox_resize_children(item); - e_canvas_item_request_reflow(item); -} - -static void -e_canvas_vbox_remove_item (GnomeCanvasItem *item, ECanvasVbox *vbox) -{ - vbox->items = g_list_remove(vbox->items, item); - gtk_object_unref(GTK_OBJECT(vbox)); -} - -static void -e_canvas_vbox_real_add_item(ECanvasVbox *e_canvas_vbox, GnomeCanvasItem *item) -{ - e_canvas_vbox->items = g_list_append(e_canvas_vbox->items, item); - gtk_object_ref(GTK_OBJECT(item)); - gtk_object_ref(GTK_OBJECT(e_canvas_vbox)); - gtk_signal_connect(GTK_OBJECT(item), "destroy", - GTK_SIGNAL_FUNC(e_canvas_vbox_remove_item), e_canvas_vbox); - if ( GTK_OBJECT_FLAGS( e_canvas_vbox ) & GNOME_CANVAS_ITEM_REALIZED ) { - gnome_canvas_item_set(item, - "width", (double) e_canvas_vbox->width, - NULL); - e_canvas_item_request_reflow(item); - } - -} - -static void -e_canvas_vbox_resize_children (GnomeCanvasItem *item) -{ - GList *list; - ECanvasVbox *e_canvas_vbox; - - e_canvas_vbox = E_CANVAS_VBOX (item); - for ( list = e_canvas_vbox->items; list; list = list->next ) { - GnomeCanvasItem *child = GNOME_CANVAS_ITEM(list->data); - gnome_canvas_item_set(child, - "width", (double) e_canvas_vbox->width, - NULL); - } -} - -static void -e_canvas_vbox_reflow( GnomeCanvasItem *item, int flags ) -{ - ECanvasVbox *e_canvas_vbox = E_CANVAS_VBOX(item); - if ( GTK_OBJECT_FLAGS( e_canvas_vbox ) & GNOME_CANVAS_ITEM_REALIZED ) { - - gdouble old_height; - gdouble running_height; - - old_height = e_canvas_vbox->height; - - running_height = 0; - - if (e_canvas_vbox->items == NULL) { - } else { - GList *list; - gdouble item_height; - - list = e_canvas_vbox->items; - gtk_object_get (GTK_OBJECT(list->data), - "height", &item_height, - NULL); - e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data), - (double) 0, - (double) running_height); - running_height += item_height; - list = g_list_next(list); - - for( ; list; list = g_list_next(list)) { - running_height += e_canvas_vbox->spacing; - - gtk_object_get (GTK_OBJECT(list->data), - "height", &item_height, - NULL); - - e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data), - (double) 0, - (double) running_height); - - running_height += item_height; - } - - } - e_canvas_vbox->height = running_height; - if (old_height != e_canvas_vbox->height) - e_canvas_item_request_parent_reflow(item); - } -} - -void -e_canvas_vbox_add_item(ECanvasVbox *e_canvas_vbox, GnomeCanvasItem *item) -{ - if (E_CANVAS_VBOX_CLASS(GTK_OBJECT(e_canvas_vbox)->klass)->add_item) - (E_CANVAS_VBOX_CLASS(GTK_OBJECT(e_canvas_vbox)->klass)->add_item) (e_canvas_vbox, item); -} diff --git a/widgets/misc/e-canvas-vbox.h b/widgets/misc/e-canvas-vbox.h deleted file mode 100644 index c45baa0b0a..0000000000 --- a/widgets/misc/e-canvas-vbox.h +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-canvas-vbox.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef __E_CANVAS_VBOX_H__ -#define __E_CANVAS_VBOX_H__ - -#include <gnome.h> - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ECanvasVbox - A canvas item container. - * - * The following arguments are available: - * - * name type read/write description - * -------------------------------------------------------------------------------- - * width double RW width of the CanvasVbox - * height double R height of the CanvasVbox - * spacing double RW Spacing between items. - */ - -#define E_CANVAS_VBOX_TYPE (e_canvas_vbox_get_type ()) -#define E_CANVAS_VBOX(obj) (GTK_CHECK_CAST ((obj), E_CANVAS_VBOX_TYPE, ECanvasVbox)) -#define E_CANVAS_VBOX_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_CANVAS_VBOX_TYPE, ECanvasVboxClass)) -#define E_IS_CANVAS_VBOX(obj) (GTK_CHECK_TYPE ((obj), E_CANVAS_VBOX_TYPE)) -#define E_IS_CANVAS_VBOX_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_CANVAS_VBOX_TYPE)) - - -typedef struct _ECanvasVbox ECanvasVbox; -typedef struct _ECanvasVboxClass ECanvasVboxClass; - -struct _ECanvasVbox -{ - GnomeCanvasGroup parent; - - /* item specific fields */ - GList *items; /* Of type GnomeCanvasItem */ - - double width; - double height; - double spacing; -}; - -struct _ECanvasVboxClass -{ - GnomeCanvasGroupClass parent_class; - - /* Virtual methods. */ - void (* add_item) (ECanvasVbox *CanvasVbox, GnomeCanvasItem *item); -}; - -/* - * To be added to a CanvasVbox, an item must have the argument "width" as - * a Read/Write argument and "height" as a Read Only argument. It - * should also do an ECanvas parent CanvasVbox request if its size - * changes. - */ -void e_canvas_vbox_add_item(ECanvasVbox *e_canvas_vbox, GnomeCanvasItem *item); -GtkType e_canvas_vbox_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_CANVAS_VBOX_H__ */ diff --git a/widgets/misc/e-canvas.c b/widgets/misc/e-canvas.c deleted file mode 100644 index fb67bf0379..0000000000 --- a/widgets/misc/e-canvas.c +++ /dev/null @@ -1,696 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-canvas.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <gnome.h> -#include "e-canvas.h" -static void e_canvas_init (ECanvas *card); -static void e_canvas_destroy (GtkObject *object); -static void e_canvas_class_init (ECanvasClass *klass); -static void e_canvas_realize (GtkWidget *widget); -static void e_canvas_unrealize (GtkWidget *widget); -static gint e_canvas_key (GtkWidget *widget, - GdkEventKey *event); - -static gint e_canvas_focus_in (GtkWidget *widget, - GdkEventFocus *event); -static gint e_canvas_focus_out (GtkWidget *widget, - GdkEventFocus *event); - -static int emit_event (GnomeCanvas *canvas, GdkEvent *event); - -static GnomeCanvasClass *parent_class = NULL; - -enum { - REFLOW, - LAST_SIGNAL -}; - -static guint e_canvas_signals [LAST_SIGNAL] = { 0, }; - -GtkType -e_canvas_get_type (void) -{ - static GtkType canvas_type = 0; - - if (!canvas_type) - { - static const GtkTypeInfo canvas_info = - { - "ECanvas", - sizeof (ECanvas), - sizeof (ECanvasClass), - (GtkClassInitFunc) e_canvas_class_init, - (GtkObjectInitFunc) e_canvas_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - canvas_type = gtk_type_unique (gnome_canvas_get_type (), &canvas_info); - } - - return canvas_type; -} - -static void -e_canvas_class_init (ECanvasClass *klass) -{ - GtkObjectClass *object_class; - GnomeCanvasClass *canvas_class; - GtkWidgetClass *widget_class; - - object_class = (GtkObjectClass*) klass; - canvas_class = (GnomeCanvasClass *) klass; - widget_class = (GtkWidgetClass *) klass; - - parent_class = gtk_type_class (gnome_canvas_get_type ()); - - object_class->destroy = e_canvas_destroy; - - widget_class->key_press_event = e_canvas_key; - widget_class->key_release_event = e_canvas_key; - widget_class->focus_in_event = e_canvas_focus_in; - widget_class->focus_out_event = e_canvas_focus_out; - widget_class->realize = e_canvas_realize; - widget_class->unrealize = e_canvas_unrealize; - - klass->reflow = NULL; - - e_canvas_signals [REFLOW] = - gtk_signal_new ("reflow", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ECanvasClass, reflow), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, e_canvas_signals, LAST_SIGNAL); -} - -static void -e_canvas_init (ECanvas *canvas) -{ - canvas->selection = NULL; - canvas->cursor = NULL; - canvas->ic = NULL; - canvas->ic_attr = NULL; -} - -static void -e_canvas_destroy (GtkObject *object) -{ - ECanvas *canvas = E_CANVAS(object); - if (canvas->idle_id) - g_source_remove(canvas->idle_id); - if ((GTK_OBJECT_CLASS (parent_class))->destroy) - (*(GTK_OBJECT_CLASS (parent_class))->destroy) (object); -} - -GtkWidget * -e_canvas_new () -{ - return GTK_WIDGET (gtk_type_new (e_canvas_get_type ())); -} - - -/* Returns whether the item is an inferior of or is equal to the parent. */ -static int -is_descendant (GnomeCanvasItem *item, GnomeCanvasItem *parent) -{ - for (; item; item = item->parent) - if (item == parent) - return TRUE; - - return FALSE; -} - -/* Emits an event for an item in the canvas, be it the current item, grabbed - * item, or focused item, as appropriate. - */ -static int -emit_event (GnomeCanvas *canvas, GdkEvent *event) -{ - /*GdkEvent ev;*/ - gint finished; - GnomeCanvasItem *item; - GnomeCanvasItem *parent; - guint mask; - - /* Perform checks for grabbed items */ - - if (canvas->grabbed_item && !is_descendant (canvas->current_item, canvas->grabbed_item)) - return FALSE; - - if (canvas->grabbed_item) { - switch (event->type) { - case GDK_ENTER_NOTIFY: - mask = GDK_ENTER_NOTIFY_MASK; - break; - - case GDK_LEAVE_NOTIFY: - mask = GDK_LEAVE_NOTIFY_MASK; - break; - - case GDK_MOTION_NOTIFY: - mask = GDK_POINTER_MOTION_MASK; - break; - - case GDK_BUTTON_PRESS: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - mask = GDK_BUTTON_PRESS_MASK; - break; - - case GDK_BUTTON_RELEASE: - mask = GDK_BUTTON_RELEASE_MASK; - break; - - case GDK_KEY_PRESS: - mask = GDK_KEY_PRESS_MASK; - break; - - case GDK_KEY_RELEASE: - mask = GDK_KEY_RELEASE_MASK; - break; - - default: - mask = 0; - break; - } - - if (!(mask & canvas->grabbed_event_mask)) - return FALSE; - } - - /* Convert to world coordinates -- we have two cases because of diferent - * offsets of the fields in the event structures. - */ - - /*ev = *event;*/ - - switch (event->type) { - case GDK_ENTER_NOTIFY: - case GDK_LEAVE_NOTIFY: - gnome_canvas_window_to_world (canvas, - event->crossing.x, - event->crossing.y, - &(event->crossing.x), - &(event->crossing.y)); - break; - - case GDK_MOTION_NOTIFY: - case GDK_BUTTON_PRESS: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - gnome_canvas_window_to_world (canvas, - event->motion.x, - event->motion.y, - &(event->motion.x), - &(event->motion.y)); - break; - - default: - break; - } - - /* Choose where we send the event */ - - item = canvas->current_item; - - if (canvas->focused_item - && ((event->type == GDK_KEY_PRESS) || (event->type == GDK_KEY_RELEASE) || (event->type == GDK_FOCUS_CHANGE))) - item = canvas->focused_item; - - /* The event is propagated up the hierarchy (for if someone connected to - * a group instead of a leaf event), and emission is stopped if a - * handler returns TRUE, just like for GtkWidget events. - */ - - finished = FALSE; - - while (item && !finished) { - gtk_object_ref (GTK_OBJECT (item)); - - gtk_signal_emit_by_name (GTK_OBJECT (item), "event", - event, - &finished); - - if (GTK_OBJECT_DESTROYED (item)) - finished = TRUE; - - parent = item->parent; - gtk_object_unref (GTK_OBJECT (item)); - - item = parent; - } - - return finished; -} - -/* Key event handler for the canvas */ -static gint -e_canvas_key (GtkWidget *widget, GdkEventKey *event) -{ - GnomeCanvas *canvas; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GNOME_IS_CANVAS (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - canvas = GNOME_CANVAS (widget); - - return emit_event (canvas, (GdkEvent *) event); -} - - -/** - * e_canvas_item_grab_focus: - * @item: A canvas item. - * - * Makes the specified item take the keyboard focus, so all keyboard events will - * be sent to it. If the canvas widget itself did not have the focus, it grabs - * it as well. - **/ -void -e_canvas_item_grab_focus (GnomeCanvasItem *item) -{ - GnomeCanvasItem *focused_item; - GdkEvent ev; - - g_return_if_fail (item != NULL); - g_return_if_fail (GNOME_IS_CANVAS_ITEM (item)); - g_return_if_fail (GTK_WIDGET_CAN_FOCUS (GTK_WIDGET (item->canvas))); - - focused_item = item->canvas->focused_item; - - if (focused_item) { - ev.focus_change.type = GDK_FOCUS_CHANGE; - ev.focus_change.window = GTK_LAYOUT (item->canvas)->bin_window; - ev.focus_change.send_event = FALSE; - ev.focus_change.in = FALSE; - - emit_event (item->canvas, &ev); - } - - item->canvas->focused_item = item; - - if (!GTK_WIDGET_HAS_FOCUS (GTK_WIDGET(item->canvas))) { - gtk_widget_grab_focus (GTK_WIDGET (item->canvas)); - } - - if (focused_item) { - ev.focus_change.type = GDK_FOCUS_CHANGE; - ev.focus_change.window = GTK_LAYOUT (item->canvas)->bin_window; - ev.focus_change.send_event = FALSE; - ev.focus_change.in = TRUE; - - emit_event (item->canvas, &ev); - } -} - -/* Focus in handler for the canvas */ -static gint -e_canvas_focus_in (GtkWidget *widget, GdkEventFocus *event) -{ - GnomeCanvas *canvas; - ECanvas *ecanvas; - - canvas = GNOME_CANVAS (widget); - ecanvas = E_CANVAS (widget); - - GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS); - - if (ecanvas->ic) - gdk_im_begin (ecanvas->ic, canvas->layout.bin_window); - - if (canvas->focused_item) - return emit_event (canvas, (GdkEvent *) event); - else - return FALSE; -} - -/* Focus out handler for the canvas */ -static gint -e_canvas_focus_out (GtkWidget *widget, GdkEventFocus *event) -{ - GnomeCanvas *canvas; - ECanvas *ecanvas; - - canvas = GNOME_CANVAS (widget); - ecanvas = E_CANVAS (widget); - - GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS); - - if (ecanvas->ic) - gdk_im_end (); - - if (canvas->focused_item) - return emit_event (canvas, (GdkEvent *) event); - else - return FALSE; -} - -static void -e_canvas_realize (GtkWidget *widget) -{ - ECanvas *ecanvas = E_CANVAS (widget); - - if (GTK_WIDGET_CLASS (parent_class)->realize) - (* GTK_WIDGET_CLASS (parent_class)->realize) (widget); - - gdk_window_set_back_pixmap (GTK_LAYOUT (widget)->bin_window, NULL, FALSE); - - if (gdk_im_ready () && (ecanvas->ic_attr = gdk_ic_attr_new ()) != NULL) { - GdkEventMask mask; - GdkICAttr *attr = ecanvas->ic_attr; - GdkICAttributesType attrmask = GDK_IC_ALL_REQ; - GdkIMStyle style; - GdkIMStyle supported_style = GDK_IM_PREEDIT_NONE | - GDK_IM_PREEDIT_NOTHING | - GDK_IM_STATUS_NONE | - GDK_IM_STATUS_NOTHING; - - attr->style = style = gdk_im_decide_style (supported_style); - attr->client_window = ecanvas->parent.layout.bin_window; - - ecanvas->ic = gdk_ic_new (attr, attrmask); - if (ecanvas->ic != NULL) { - mask = gdk_window_get_events (attr->client_window); - mask |= gdk_ic_get_events (ecanvas->ic); - gdk_window_set_events (attr->client_window, mask); - - if (GTK_WIDGET_HAS_FOCUS (widget)) - gdk_im_begin (ecanvas->ic, attr->client_window); - } else - g_warning ("Can't create input context."); - } - -} - -static void -e_canvas_unrealize (GtkWidget *widget) -{ - ECanvas * ecanvas = E_CANVAS (widget); - if (ecanvas->ic) { - gdk_ic_destroy (ecanvas->ic); - ecanvas->ic = NULL; - } - if (ecanvas->ic_attr) { - gdk_ic_attr_destroy (ecanvas->ic_attr); - ecanvas->ic_attr = NULL; - } - if (GTK_WIDGET_CLASS (parent_class)->unrealize) - (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); -} - -static void -e_canvas_item_invoke_reflow (GnomeCanvasItem *item, int flags) -{ - GnomeCanvasGroup *group; - GList *list; - GnomeCanvasItem *child; - - if (GNOME_IS_CANVAS_GROUP (item)) { - group = GNOME_CANVAS_GROUP (item); - for (list = group->item_list; list; list = list->next) { - child = GNOME_CANVAS_ITEM (list->data); - if (child->object.flags & E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW) - e_canvas_item_invoke_reflow (child, flags); - } - } - - if (item->object.flags & E_CANVAS_ITEM_NEEDS_REFLOW) { - ECanvasItemReflowFunc func; - func = gtk_object_get_data (GTK_OBJECT (item), - "ECanvasItem::reflow_callback"); - if (func) - func (item, flags); - } - - item->object.flags &= ~E_CANVAS_ITEM_NEEDS_REFLOW; - item->object.flags &= ~E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW; -} - -static void -do_reflow (ECanvas *canvas) -{ - if (GNOME_CANVAS(canvas)->root->object.flags & E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW) - e_canvas_item_invoke_reflow (GNOME_CANVAS(canvas)->root, 0); -} - -/* Idle handler for the e-canvas. It deals with pending reflows. */ -static gint -idle_handler (gpointer data) -{ - ECanvas *canvas; - - GDK_THREADS_ENTER(); - - canvas = E_CANVAS (data); - do_reflow (canvas); - - /* Reset idle id */ - canvas->idle_id = 0; - - gtk_signal_emit (GTK_OBJECT (canvas), - e_canvas_signals [REFLOW]); - - GDK_THREADS_LEAVE(); - - return FALSE; -} - -/* Convenience function to add an idle handler to a canvas */ -static void -add_idle (ECanvas *canvas) -{ - if (canvas->idle_id != 0) - return; - - canvas->idle_id = g_idle_add_full (G_PRIORITY_HIGH_IDLE, idle_handler, (gpointer) canvas, NULL); -} - -static void -e_canvas_item_descendent_needs_reflow (GnomeCanvasItem *item) -{ - if (item->object.flags & E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW) - return; - - item->object.flags |= E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW; - if (item->parent) - e_canvas_item_descendent_needs_reflow(item->parent); -} - -void -e_canvas_item_request_reflow (GnomeCanvasItem *item) -{ - if (item->object.flags & GNOME_CANVAS_ITEM_REALIZED) { - item->object.flags |= E_CANVAS_ITEM_NEEDS_REFLOW; - e_canvas_item_descendent_needs_reflow(item); - add_idle(E_CANVAS(item->canvas)); - } -} - -void -e_canvas_item_request_parent_reflow (GnomeCanvasItem *item) -{ - g_return_if_fail(item != NULL); - g_return_if_fail(GNOME_IS_CANVAS_ITEM(item)); - e_canvas_item_request_reflow(item->parent); -} - -void -e_canvas_item_set_reflow_callback (GnomeCanvasItem *item, ECanvasItemReflowFunc func) -{ - gtk_object_set_data(GTK_OBJECT(item), "ECanvasItem::reflow_callback", (gpointer) func); -} - - -void -e_canvas_item_set_selection_callback (GnomeCanvasItem *item, ECanvasItemSelectionFunc func) -{ - gtk_object_set_data(GTK_OBJECT(item), "ECanvasItem::selection_callback", (gpointer) func); -} - -void -e_canvas_item_set_selection_compare_callback (GnomeCanvasItem *item, ECanvasItemSelectionCompareFunc func) -{ - gtk_object_set_data(GTK_OBJECT(item), "ECanvasItem::selection_compare_callback", (gpointer) func); -} - -void -e_canvas_item_set_cursor (GnomeCanvasItem *item, gpointer id) -{ - GList *list; - int flags; - ECanvas *canvas; - ECanvasSelectionInfo *info; - ECanvasItemSelectionFunc func; - - g_return_if_fail(item != NULL); - g_return_if_fail(GNOME_IS_CANVAS_ITEM(item)); - g_return_if_fail(item->canvas != NULL); - g_return_if_fail(E_IS_CANVAS(item->canvas)); - - canvas = E_CANVAS(item->canvas); - flags = E_CANVAS_ITEM_SELECTION_DELETE_DATA; - - for (list = canvas->selection; list; list = g_list_next(list)) { - info = list->data; - - func = gtk_object_get_data(GTK_OBJECT(info->item), "ECanvasItem::selection_callback"); - if (func) - func(info->item, flags, info->id); - g_message ("ECANVAS: free info (2): item %p, id %p", - info->item, info->id); - gtk_object_unref (GTK_OBJECT (info->item)); - g_free(info); - } - g_list_free(canvas->selection); - - canvas->selection = NULL; - - gnome_canvas_item_grab_focus(item); - - info = g_new(ECanvasSelectionInfo, 1); - info->item = item; - gtk_object_ref (GTK_OBJECT (info->item)); - info->id = id; - g_message ("ECANVAS: new info item %p, id %p", item, id); - - flags = E_CANVAS_ITEM_SELECTION_SELECT | E_CANVAS_ITEM_SELECTION_CURSOR; - func = gtk_object_get_data(GTK_OBJECT(item), "ECanvasItem::selection_callback"); - if (func) - func(item, flags, id); - - canvas->selection = g_list_prepend(canvas->selection, info); - canvas->cursor = info; -} - -void -e_canvas_item_set_cursor_end (GnomeCanvasItem *item, gpointer id) -{ -} - -void -e_canvas_item_add_selection (GnomeCanvasItem *item, gpointer id) -{ - int flags; - ECanvas *canvas; - ECanvasSelectionInfo *info; - ECanvasItemSelectionFunc func; - GList *list; - - g_return_if_fail(item != NULL); - g_return_if_fail(GNOME_IS_CANVAS_ITEM(item)); - g_return_if_fail(item->canvas != NULL); - g_return_if_fail(E_IS_CANVAS(item->canvas)); - - flags = E_CANVAS_ITEM_SELECTION_SELECT; - canvas = E_CANVAS(item->canvas); - - if (canvas->cursor) { - func = gtk_object_get_data(GTK_OBJECT(canvas->cursor->item), "ECanvasItem::selection_callback"); - if (func) - func(canvas->cursor->item, flags, canvas->cursor->id); - } - - gnome_canvas_item_grab_focus(item); - - flags = E_CANVAS_ITEM_SELECTION_SELECT | E_CANVAS_ITEM_SELECTION_CURSOR; - - for (list = canvas->selection; list; list = g_list_next(list)) { - ECanvasSelectionInfo *search; - search = list->data; - - if (search->item == item) { - ECanvasItemSelectionCompareFunc compare_func; - compare_func = gtk_object_get_data(GTK_OBJECT(search->item), "ECanvasItem::selection_compare_callback"); - - if (compare_func(search->item, search->id, id, 0) == 0) { - canvas->cursor = search; - func = gtk_object_get_data(GTK_OBJECT(item), "ECanvasItem::selection_callback"); - if (func) - func(item, flags, search->id); - return; - } - } - } - - info = g_new(ECanvasSelectionInfo, 1); - info->item = item; - gtk_object_ref (GTK_OBJECT (info->item)); - info->id = id; - g_message ("ECANVAS: new info (2): item %p, id %p", item, id); - - func = gtk_object_get_data(GTK_OBJECT(item), "ECanvasItem::selection_callback"); - if (func) - func(item, flags, id); - - canvas->selection = g_list_prepend(canvas->selection, info); - canvas->cursor = info; -} - -void -e_canvas_item_remove_selection (GnomeCanvasItem *item, gpointer id) -{ - int flags; - ECanvas *canvas; - ECanvasSelectionInfo *info; - GList *list; - - g_return_if_fail(item != NULL); - g_return_if_fail(GNOME_IS_CANVAS_ITEM(item)); - g_return_if_fail(item->canvas != NULL); - g_return_if_fail(E_IS_CANVAS(item->canvas)); - - flags = E_CANVAS_ITEM_SELECTION_DELETE_DATA; - canvas = E_CANVAS(item->canvas); - - for (list = canvas->selection; list; list = g_list_next(list)) { - info = list->data; - - if (info->item == item) { - ECanvasItemSelectionCompareFunc compare_func; - compare_func = gtk_object_get_data(GTK_OBJECT(info->item), "ECanvasItem::selection_compare_callback"); - - if (compare_func(info->item, info->id, id, 0) == 0) { - ECanvasItemSelectionFunc func; - func = gtk_object_get_data(GTK_OBJECT(info->item), "ECanvasItem::selection_callback"); - if (func) - func(info->item, flags, info->id); - canvas->selection = g_list_remove_link(canvas->selection, list); - - if (canvas->cursor == info) - canvas->cursor = NULL; - - g_message ("ECANVAS: removing info: item %p, info %p", - info->item, info->id); - gtk_object_unref (GTK_OBJECT (info->item)); - g_free(info); - g_list_free_1(list); - break; - } - } - } -} diff --git a/widgets/misc/e-canvas.h b/widgets/misc/e-canvas.h deleted file mode 100644 index b13a9dd2ab..0000000000 --- a/widgets/misc/e-canvas.h +++ /dev/null @@ -1,121 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-canvas.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef __E_CANVAS_H__ -#define __E_CANVAS_H__ - -#include <gnome.h> - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ECanvas - A class derived from canvas for the purpose of adding - * evolution specific canvas hacks. - */ - -#define E_CANVAS_TYPE (e_canvas_get_type ()) -#define E_CANVAS(obj) (GTK_CHECK_CAST ((obj), E_CANVAS_TYPE, ECanvas)) -#define E_CANVAS_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_CANVAS_TYPE, ECanvasClass)) -#define E_IS_CANVAS(obj) (GTK_CHECK_TYPE ((obj), E_CANVAS_TYPE)) -#define E_IS_CANVAS_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_CANVAS_TYPE)) - -typedef void (*ECanvasItemReflowFunc) (GnomeCanvasItem *item, - gint flags); - -typedef void (*ECanvasItemSelectionFunc) (GnomeCanvasItem *item, - gint flags, - gpointer user_data); -/* Returns the same as strcmp does. */ -typedef gint (*ECanvasItemSelectionCompareFunc) (GnomeCanvasItem *item, - gpointer data1, - gpointer data2, - gint flags); - - -typedef struct _ECanvas ECanvas; -typedef struct _ECanvasClass ECanvasClass; - -/* Object flags for items */ -enum { - E_CANVAS_ITEM_NEEDS_REFLOW = 1 << 13, - E_CANVAS_ITEM_DESCENDENT_NEEDS_REFLOW = 1 << 14 -}; - -enum { - E_CANVAS_ITEM_SELECTION_SELECT = 1 << 0, /* TRUE = select. FALSE = unselect. */ - E_CANVAS_ITEM_SELECTION_CURSOR = 1 << 1, /* TRUE = has become cursor. FALSE = not cursor. */ - E_CANVAS_ITEM_SELECTION_DELETE_DATA = 1 << 2, -}; - -typedef struct { - GnomeCanvasItem *item; - gpointer id; -} ECanvasSelectionInfo; - -struct _ECanvas -{ - GnomeCanvas parent; - - int idle_id; - GList *selection; - ECanvasSelectionInfo *cursor; - - /* Input context for dead key support */ - GdkIC *ic; - GdkICAttr *ic_attr; -}; - -struct _ECanvasClass -{ - GnomeCanvasClass parent_class; - void (* reflow) (ECanvas *canvas); -}; - - -GtkType e_canvas_get_type (void); -GtkWidget *e_canvas_new (void); - -/* Used to send all of the keystroke events to a specific item as well as - * GDK_FOCUS_CHANGE events. - */ -void e_canvas_item_grab_focus (GnomeCanvasItem *item); - -void e_canvas_item_request_reflow (GnomeCanvasItem *item); -void e_canvas_item_request_parent_reflow (GnomeCanvasItem *item); -void e_canvas_item_set_reflow_callback (GnomeCanvasItem *item, ECanvasItemReflowFunc func); - -void e_canvas_item_set_selection_callback (GnomeCanvasItem *item, ECanvasItemSelectionFunc func); -void e_canvas_item_set_selection_compare_callback (GnomeCanvasItem *item, ECanvasItemSelectionCompareFunc func); - -void e_canvas_item_set_cursor (GnomeCanvasItem *item, gpointer id); -void e_canvas_item_add_selection (GnomeCanvasItem *item, gpointer id); -void e_canvas_item_remove_selection (GnomeCanvasItem *item, gpointer id); - -/* Not implemented yet. */ -void e_canvas_item_set_cursor_end (GnomeCanvasItem *item, gpointer id); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_CANVAS_H__ */ diff --git a/widgets/misc/e-clipped-label.c b/widgets/misc/e-clipped-label.c deleted file mode 100644 index 6f6fc9731d..0000000000 --- a/widgets/misc/e-clipped-label.c +++ /dev/null @@ -1,378 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * This is similar to GtkLabel but clips itself and displays '...' if it - * can't fit inside its allocated area. The intended use is for inside buttons - * that are a fixed size. The GtkLabel would normally display only the middle - * part of the text, which doesn't look very good. This only supports one line - * of text (so no wrapping/justification), without underlined characters. - */ - -#include <math.h> - -#include <gdk/gdki18n.h> -#include <libgnome/gnome-defs.h> -#include <libgnome/gnome-i18n.h> - -#include "e-clipped-label.h" - - -static void e_clipped_label_class_init (EClippedLabelClass *class); -static void e_clipped_label_init (EClippedLabel *label); -static void e_clipped_label_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void e_clipped_label_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static gint e_clipped_label_expose (GtkWidget *widget, - GdkEventExpose *event); -static void e_clipped_label_recalc_chars_displayed (EClippedLabel *label); -static void e_clipped_label_destroy (GtkObject *object); - - -static GtkMiscClass *parent_class; - -/* This is the string to draw when the label is clipped, e.g. '...'. */ -static gchar *e_clipped_label_ellipsis; - -/* Flags used in chars_displayed field. Must be negative. */ -#define E_CLIPPED_LABEL_NEED_RECALC -1 -#define E_CLIPPED_LABEL_SHOW_ENTIRE_LABEL -2 - - -GtkType -e_clipped_label_get_type (void) -{ - static GtkType e_clipped_label_type = 0; - - if (!e_clipped_label_type){ - GtkTypeInfo e_clipped_label_info = { - "EClippedLabel", - sizeof (EClippedLabel), - sizeof (EClippedLabelClass), - (GtkClassInitFunc) e_clipped_label_class_init, - (GtkObjectInitFunc) e_clipped_label_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - parent_class = gtk_type_class (GTK_TYPE_MISC); - e_clipped_label_type = gtk_type_unique (GTK_TYPE_MISC, - &e_clipped_label_info); - } - - return e_clipped_label_type; -} - - -static void -e_clipped_label_class_init (EClippedLabelClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - - /* Method override */ - widget_class->size_request = e_clipped_label_size_request; - widget_class->size_allocate = e_clipped_label_size_allocate; - widget_class->expose_event = e_clipped_label_expose; - - object_class->destroy = e_clipped_label_destroy; - - e_clipped_label_ellipsis = _("..."); -} - - -static void -e_clipped_label_init (EClippedLabel *label) -{ - GTK_WIDGET_SET_FLAGS (label, GTK_NO_WINDOW); - - label->label = NULL; - label->label_wc = NULL; - label->chars_displayed = E_CLIPPED_LABEL_NEED_RECALC; -} - - -/** - * e_clipped_label_new: - * - * @text: The label text. - * @Returns: A new #EClippedLabel. - * - * Creates a new #EClippedLabel with the given text. - **/ -GtkWidget * -e_clipped_label_new (const gchar *text) -{ - GtkWidget *label; - - label = GTK_WIDGET (gtk_type_new (e_clipped_label_get_type ())); - - if (text && *text) - e_clipped_label_set_text (E_CLIPPED_LABEL (label), text); - - return label; -} - - -static void -e_clipped_label_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - EClippedLabel *label; - GdkFont *font; - - g_return_if_fail (E_IS_CLIPPED_LABEL (widget)); - g_return_if_fail (requisition != NULL); - - label = E_CLIPPED_LABEL (widget); - font = widget->style->font; - - requisition->width = 0; - requisition->height = font->ascent + font->descent - + 2 * GTK_MISC (widget)->ypad; -} - - -static void -e_clipped_label_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - EClippedLabel *label; - - label = E_CLIPPED_LABEL (widget); - - widget->allocation = *allocation; - - /* Flag that we need to recalculate how many characters to display. */ - label->chars_displayed = E_CLIPPED_LABEL_NEED_RECALC; -} - - -static gint -e_clipped_label_expose (GtkWidget *widget, - GdkEventExpose *event) -{ - EClippedLabel *label; - GtkMisc *misc; - gint x, y; - GdkFont *font; - gchar *tmp_str, tmp_ch; - - g_return_val_if_fail (E_IS_CLIPPED_LABEL (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - label = E_CLIPPED_LABEL (widget); - misc = GTK_MISC (widget); - font = widget->style->font; - - /* If the label isn't visible or has no text, just return. */ - if (!GTK_WIDGET_VISIBLE (widget) || !GTK_WIDGET_MAPPED (widget) - || !label->label || (*label->label == '\0')) - return TRUE; - - /* Recalculate the number of characters displayed, if necessary. */ - if (label->chars_displayed == E_CLIPPED_LABEL_NEED_RECALC) - e_clipped_label_recalc_chars_displayed (label); - - /* - * GC Clipping - */ - gdk_gc_set_clip_rectangle (widget->style->white_gc, - &event->area); - gdk_gc_set_clip_rectangle (widget->style->fg_gc[widget->state], - &event->area); - - y = floor (widget->allocation.y + (gint)misc->ypad - + (((gint)widget->allocation.height - 2 * (gint)misc->ypad - - (gint)font->ascent - font->descent) - * misc->yalign) + 0.5) + font->ascent; - - if (label->chars_displayed == E_CLIPPED_LABEL_SHOW_ENTIRE_LABEL) { - x = floor (widget->allocation.x + (gint)misc->xpad - + (((gint)widget->allocation.width - - (gint)label->label_width - 2 * (gint)misc->xpad) - * misc->xalign) + 0.5); - - gtk_paint_string (widget->style, widget->window, widget->state, - &event->area, widget, "label", - x, y, label->label); - } else { - x = widget->allocation.x + (gint)misc->xpad; - - tmp_ch = label->label_wc[label->chars_displayed]; - label->label_wc[label->chars_displayed] = '\0'; - tmp_str = gdk_wcstombs (label->label_wc); - if (tmp_str) { - gtk_paint_string (widget->style, widget->window, - widget->state, &event->area, - widget, "label", - x, y, tmp_str); - g_free (tmp_str); - } - label->label_wc[label->chars_displayed] = tmp_ch; - - x = widget->allocation.x + (gint)misc->xpad - + label->ellipsis_x; - gtk_paint_string (widget->style, widget->window, widget->state, - &event->area, widget, "label", - x, y, e_clipped_label_ellipsis); - } - - gdk_gc_set_clip_mask (widget->style->white_gc, NULL); - gdk_gc_set_clip_mask (widget->style->fg_gc[widget->state], NULL); - - return TRUE; -} - - -static void -e_clipped_label_destroy (GtkObject *object) -{ - EClippedLabel *label; - - g_return_if_fail (E_IS_CLIPPED_LABEL (object)); - - label = E_CLIPPED_LABEL(object); - - g_free (label->label); - g_free (label->label_wc); -} - - -/** - * e_clipped_label_get_text: - * - * @label: An #EClippedLabel. - * @Return: The label text. - * - * Returns the label text, or NULL. - **/ -gchar* -e_clipped_label_get_text (EClippedLabel *label) -{ - g_return_val_if_fail (E_IS_CLIPPED_LABEL (label), NULL); - - return label->label; -} - - -/** - * e_clipped_label_set_text: - * - * @label: An #EClippedLabel. - * @text: The new label text. - * - * Sets the label text. - **/ -void -e_clipped_label_set_text (EClippedLabel *label, - const gchar *text) -{ - gint len; - - g_return_if_fail (E_IS_CLIPPED_LABEL (label)); - - if (label->label != text || !label->label || !text - || strcmp (label->label, text)) { - g_free (label->label); - g_free (label->label_wc); - label->label = NULL; - label->label_wc = NULL; - - if (text) { - label->label = g_strdup (text); - len = strlen (text); - label->label_wc = g_new (GdkWChar, len + 1); - label->wc_len = gdk_mbstowcs (label->label_wc, - label->label, len + 1); - label->label_wc[label->wc_len] = '\0'; - } - - /* Reset the number of characters displayed, so it is - recalculated when needed. */ - label->chars_displayed = E_CLIPPED_LABEL_NEED_RECALC; - - /* We don't queue a resize, since the label should not affect - the widget size, but we queue a draw. */ - gtk_widget_queue_draw (GTK_WIDGET (label)); - } -} - - -static void -e_clipped_label_recalc_chars_displayed (EClippedLabel *label) -{ - GdkFont *font; - gint max_width, width, ch, last_width; - - font = GTK_WIDGET (label)->style->font; - - max_width = GTK_WIDGET (label)->allocation.width - - 2 * GTK_MISC (label)->xpad; - - if (!label->label) { - label->chars_displayed = 0; - return; - } - - /* See if the entire label fits in the allocated width. */ - label->label_width = gdk_string_width (font, label->label); - if (label->label_width <= max_width) { - label->chars_displayed = E_CLIPPED_LABEL_SHOW_ENTIRE_LABEL; - return; - } - - /* Calculate the width of the ellipsis string. */ - max_width -= gdk_string_measure (font, e_clipped_label_ellipsis); - - if (max_width <= 0) { - label->chars_displayed = 0; - label->ellipsis_x = 0; - return; - } - - /* Step through the wide-char label, adding on the widths of the - characters, until we can't fit any more in. */ - width = last_width = 0; - for (ch = 0; ch < label->wc_len; ch++) { - width += gdk_char_width_wc (font, label->label_wc[ch]); - - if (width > max_width) { - label->chars_displayed = ch; - label->ellipsis_x = last_width; - return; - } - - last_width = width; - } - - g_warning ("Clipped label width not exceeded as expected"); - label->chars_displayed = E_CLIPPED_LABEL_SHOW_ENTIRE_LABEL; -} - diff --git a/widgets/misc/e-clipped-label.h b/widgets/misc/e-clipped-label.h deleted file mode 100644 index a21ceadeca..0000000000 --- a/widgets/misc/e-clipped-label.h +++ /dev/null @@ -1,90 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * This is similar to GtkLabel but clips itself and displays '...' if it - * can't fit inside its allocated area. The intended use is for inside buttons - * that are a fixed size. The GtkLabel would normally display only the middle - * part of the text, which doesn't look very good. This only supports one line - * of text (so no wrapping/justification), without underlined characters. - */ -#ifndef _E_CLIPPED_LABEL_H_ -#define _E_CLIPPED_LABEL_H_ - -#include <gtk/gtkmisc.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define E_CLIPPED_LABEL(obj) GTK_CHECK_CAST (obj, e_clipped_label_get_type (), EClippedLabel) -#define E_CLIPPED_LABEL_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_clipped_label_get_type (), EClippedLabelClass) -#define E_IS_CLIPPED_LABEL(obj) GTK_CHECK_TYPE (obj, e_clipped_label_get_type ()) - - -typedef struct _EClippedLabel EClippedLabel; -typedef struct _EClippedLabelClass EClippedLabelClass; - -struct _EClippedLabel -{ - GtkMisc misc; - - gchar *label; - GdkWChar *label_wc; - - /* This is the number of wide characters in the label. */ - gint wc_len; - - /* This is the width of the entire label string, in pixels. */ - gint label_width; - - /* This is the number of characters we can fit in, or - E_CLIPPED_LABEL_NEED_RECALC if it needs to be recalculated, or - E_CLIPPED_LABEL_SHOW_ENTIRE_LABEL to show the entire label. */ - gint chars_displayed; - - /* This is the x position to display the ellipsis string, e.g. '...', - relative to the start of the label. */ - gint ellipsis_x; -}; - -struct _EClippedLabelClass -{ - GtkMiscClass parent_class; -}; - - -GtkType e_clipped_label_get_type (void); -GtkWidget* e_clipped_label_new (const gchar *text); - -gchar* e_clipped_label_get_text (EClippedLabel *label); -void e_clipped_label_set_text (EClippedLabel *label, - const gchar *text); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_CLIPPED_LABEL_H_ */ diff --git a/widgets/misc/e-colors.c b/widgets/misc/e-colors.c deleted file mode 100644 index ba86538dab..0000000000 --- a/widgets/misc/e-colors.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * color.c: Color allocation on the Gnumeric spreadsheet - * - * Author: - * Miguel de Icaza (miguel@kernel.org) - * - * We keep our own color context, as the color allocation might take place - * before any of our Canvases are realized. - */ -#include <config.h> -#include <gnome.h> -#include "color.h" - -static int color_inited; -static GdkColorContext *gnumeric_color_context; - -/* Public colors: shared by all of our items in Gnumeric */ -GdkColor gs_white, gs_black, gs_light_gray, gs_dark_gray, gs_red, gs_lavender; - -int -color_alloc (gushort red, gushort green, gushort blue) -{ - int failed; - - if (!color_inited) - color_init (); - - return gdk_color_context_get_pixel (gnumeric_color_context, - red, green, blue, &failed); -} - -void -color_alloc_gdk (GdkColor *c) -{ - int failed; - - g_return_if_fail (c != NULL); - - c->pixel = gdk_color_context_get_pixel (gnumeric_color_context, c->red, c->green, c->blue, &failed); -} - -void -color_alloc_name (const char *name, GdkColor *c) -{ - int failed; - - g_return_if_fail (name != NULL); - g_return_if_fail (c != NULL); - - gdk_color_parse (name, c); - c->pixel = 0; - c->pixel = gdk_color_context_get_pixel (gnumeric_color_context, c->red, c->green, c->blue, &failed); -} - -void -color_init (void) -{ - GdkColormap *colormap = gtk_widget_get_default_colormap (); - - /* Initialize the color context */ - gnumeric_color_context = gdk_color_context_new ( - gtk_widget_get_default_visual (), colormap); - - /* Allocate the default colors */ - gdk_color_white (colormap, &gs_white); - gdk_color_black (colormap, &gs_black); - - color_alloc_name ("gray78", &gs_light_gray); - color_alloc_name ("gray20", &gs_dark_gray); - color_alloc_name ("red", &gs_red); - color_alloc_name ("lavender",&gs_lavender); - - color_inited = 1; -} diff --git a/widgets/misc/e-colors.h b/widgets/misc/e-colors.h deleted file mode 100644 index 4a2cb74c73..0000000000 --- a/widgets/misc/e-colors.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef GNUMERIC_COLOR_H -#define GNUMERIC_COLOR_H - -void color_init (void); - -/* Return the pixel value for the given red, green and blue */ -int color_alloc (gushort red, gushort green, gushort blue); -void color_alloc_name (const char *name, GdkColor *color); -void color_alloc_gdk (GdkColor *color); - -/* Colors used by any GnumericSheet item */ -extern GdkColor gs_white, gs_light_gray, gs_dark_gray, gs_black, gs_red, gs_lavender; - -#endif /* GNUMERIC_COLOR_H */ diff --git a/widgets/misc/e-cursors.c b/widgets/misc/e-cursors.c deleted file mode 100644 index 597c3c1787..0000000000 --- a/widgets/misc/e-cursors.c +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef GNUMERIC_CURSORS_H -#define GNUMERIC_CURSORS_H - -typedef enum { - GNUMERIC_CURSOR_FAT_CROSS, - GNUMERIC_CURSOR_THIN_CROSS, - GNUMERIC_CURSOR_ARROW, - GNUMERIC_CURSOR_MOVE, - GNUMERIC_CURSOR_ZOOM_IN, - GNUMERIC_CURSOR_ZOOM_OUT, - GNUMERIC_CURSOR_SIZE_X, - GNUMERIC_CURSOR_SIZE_Y, - GNUMERIC_CURSOR_SIZE_TL, - GNUMERIC_CURSOR_SIZE_TR, - GNUMERIC_CURSOR_PRESS, - GNUMERIC_CURSOR_HAND_OPEN, - GNUMERIC_CURSOR_HAND_CLOSED, - GNUMERIC_CURSOR_NUM_CURSORS -} CursorType; - -void cursors_init (void); -void cursors_shutdown (void); - -#define cursor_set(win, c) \ -G_STMT_START { \ - if (win) \ - gdk_window_set_cursor (win, cursor_get (c)); \ -} G_STMT_END - -#define cursor_set_widget(w, c) \ -G_STMT_START { \ - if (GTK_WIDGET (w)->window) \ - gdk_window_set_cursor (GTK_WIDGET (w)->window, cursor_get (c)); \ -} G_STMT_END - -GdkCursor *cursor_get (CursorType type); - -#endif /* GNUMERIC_CURSORS_H */ diff --git a/widgets/misc/e-cursors.h b/widgets/misc/e-cursors.h deleted file mode 100644 index 597c3c1787..0000000000 --- a/widgets/misc/e-cursors.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef GNUMERIC_CURSORS_H -#define GNUMERIC_CURSORS_H - -typedef enum { - GNUMERIC_CURSOR_FAT_CROSS, - GNUMERIC_CURSOR_THIN_CROSS, - GNUMERIC_CURSOR_ARROW, - GNUMERIC_CURSOR_MOVE, - GNUMERIC_CURSOR_ZOOM_IN, - GNUMERIC_CURSOR_ZOOM_OUT, - GNUMERIC_CURSOR_SIZE_X, - GNUMERIC_CURSOR_SIZE_Y, - GNUMERIC_CURSOR_SIZE_TL, - GNUMERIC_CURSOR_SIZE_TR, - GNUMERIC_CURSOR_PRESS, - GNUMERIC_CURSOR_HAND_OPEN, - GNUMERIC_CURSOR_HAND_CLOSED, - GNUMERIC_CURSOR_NUM_CURSORS -} CursorType; - -void cursors_init (void); -void cursors_shutdown (void); - -#define cursor_set(win, c) \ -G_STMT_START { \ - if (win) \ - gdk_window_set_cursor (win, cursor_get (c)); \ -} G_STMT_END - -#define cursor_set_widget(w, c) \ -G_STMT_START { \ - if (GTK_WIDGET (w)->window) \ - gdk_window_set_cursor (GTK_WIDGET (w)->window, cursor_get (c)); \ -} G_STMT_END - -GdkCursor *cursor_get (CursorType type); - -#endif /* GNUMERIC_CURSORS_H */ diff --git a/widgets/misc/e-gui-utils.c b/widgets/misc/e-gui-utils.c deleted file mode 100644 index 2e31eb101b..0000000000 --- a/widgets/misc/e-gui-utils.c +++ /dev/null @@ -1,219 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * GUI utility functions - * - * Author: - * Miguel de Icaza (miguel@helixcode.com) - * - * (C) 1999 Miguel de Icaza - * (C) 2000 Helix Code, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include <libgnomeui/gnome-messagebox.h> -#include <libgnomeui/gnome-stock.h> -#include <gnome.h> -#include "e-gui-utils.h" -#include <gdk-pixbuf/gdk-pixbuf.h> -#include <gdk-pixbuf/gnome-canvas-pixbuf.h> - -void -e_notice (GtkWindow *window, const char *type, const char *format, ...) -{ - GtkWidget *dialog; - va_list args; - char *str; - - va_start (args, format); - str = g_strdup_vprintf (format, args); - dialog = gnome_message_box_new (str, type, GNOME_STOCK_BUTTON_OK, NULL); - va_end (args); - g_free (str); - - if (window) - gnome_dialog_set_parent (GNOME_DIALOG (dialog), window); - - gnome_dialog_run (GNOME_DIALOG (dialog)); -} - -static void -kill_popup_menu (GtkWidget *widget, GtkMenu *menu) -{ - g_return_if_fail (menu != NULL); - g_return_if_fail (GTK_IS_MENU (menu)); - - gtk_object_unref (GTK_OBJECT (menu)); -} - -void -e_auto_kill_popup_menu_on_hide (GtkMenu *menu) -{ - g_return_if_fail (menu != NULL); - g_return_if_fail (GTK_IS_MENU (menu)); - - gtk_signal_connect (GTK_OBJECT (menu), "hide", - GTK_SIGNAL_FUNC (kill_popup_menu), menu); -} - -void -e_popup_menu (GtkMenu *menu, GdkEventButton *event) -{ - g_return_if_fail (menu != NULL); - g_return_if_fail (GTK_IS_MENU (menu)); - - e_auto_kill_popup_menu_on_hide (menu); - gtk_menu_popup (menu, NULL, NULL, 0, NULL, event->button, event->time); -} - -GtkWidget *e_create_image_widget(gchar *name, - gchar *string1, gchar *string2, - gint int1, gint int2) -{ - char *filename; - GdkPixbuf *pixbuf; - double width, height; - GtkWidget *canvas, *alignment; - if (string1) { - if (*string1 == '/') - filename = g_strdup(string1); - else - filename = g_concat_dir_and_file(EVOLUTION_IMAGES, string1); - pixbuf = gdk_pixbuf_new_from_file(filename); - width = gdk_pixbuf_get_width(pixbuf); - height = gdk_pixbuf_get_height(pixbuf); - - canvas = gnome_canvas_new_aa(); - GTK_OBJECT_UNSET_FLAGS(GTK_WIDGET(canvas), GTK_CAN_FOCUS); - gnome_canvas_item_new(gnome_canvas_root(GNOME_CANVAS(canvas)), - gnome_canvas_pixbuf_get_type(), - - "pixbuf", pixbuf, - NULL); - - alignment = gtk_widget_new(gtk_alignment_get_type(), - "child", canvas, - "xalign", (double) 0, - "yalign", (double) 0, - "xscale", (double) 0, - "yscale", (double) 0, - NULL); - - gtk_widget_set_usize(canvas, width, height); - - gdk_pixbuf_unref(pixbuf); - - gtk_widget_show(canvas); - gtk_widget_show(alignment); - g_free(filename); - - return alignment; - } else - return NULL; -} - -typedef struct { - GtkCallback callback; - gpointer closure; -} CallbackClosure; - -static void -e_container_foreach_leaf_callback(GtkWidget *widget, CallbackClosure *callback_closure) -{ - if (GTK_IS_CONTAINER(widget)) { - e_container_foreach_leaf(GTK_CONTAINER(widget), callback_closure->callback, callback_closure->closure); - } else { - (*callback_closure->callback) (widget, callback_closure->closure); - } -} - -void -e_container_foreach_leaf(GtkContainer *container, - GtkCallback callback, - gpointer closure) -{ - CallbackClosure callback_closure; - callback_closure.callback = callback; - callback_closure.closure = closure; - gtk_container_foreach(container, (GtkCallback) e_container_foreach_leaf_callback, &callback_closure); -} - -static void -e_container_change_tab_order_destroy_notify(gpointer data) -{ - GList *list = data; - g_list_foreach(list, (GFunc) gtk_object_unref, NULL); - g_list_free(list); -} - - -static gint -e_container_change_tab_order_callback(GtkContainer *container, - GtkDirectionType direction, - GList *children) -{ - GtkWidget *focus_child; - GtkWidget *child; - - if (direction != GTK_DIR_TAB_FORWARD && - direction != GTK_DIR_TAB_BACKWARD) - return FALSE; - - focus_child = container->focus_child; - - if (direction == GTK_DIR_TAB_BACKWARD) { - children = g_list_last(children); - } - - while (children) { - child = children->data; - if (direction == GTK_DIR_TAB_FORWARD) - children = children->next; - else - children = children->prev; - - if (!child) - continue; - - if (focus_child) { - if (focus_child == child) { - focus_child = NULL; - - if (GTK_WIDGET_DRAWABLE (child) && - GTK_IS_CONTAINER (child) && - !GTK_WIDGET_HAS_FOCUS (child)) - if (gtk_container_focus (GTK_CONTAINER (child), direction)) { - gtk_signal_emit_stop_by_name(GTK_OBJECT(container), "focus"); - return TRUE; - } - } - } - else if (GTK_WIDGET_DRAWABLE (child)) { - if (GTK_IS_CONTAINER (child)) { - if (gtk_container_focus (GTK_CONTAINER (child), direction)) { - gtk_signal_emit_stop_by_name(GTK_OBJECT(container), "focus"); - return TRUE; - } - } - else if (GTK_WIDGET_CAN_FOCUS (child)) { - gtk_widget_grab_focus (child); - gtk_signal_emit_stop_by_name(GTK_OBJECT(container), "focus"); - return TRUE; - } - } - } - - return FALSE; -} - -gint -e_container_change_tab_order(GtkContainer *container, GList *widgets) -{ - GList *list; - list = g_list_copy(widgets); - g_list_foreach(list, (GFunc) gtk_object_ref, NULL); - return gtk_signal_connect_full(GTK_OBJECT(container), "focus", - GTK_SIGNAL_FUNC(e_container_change_tab_order_callback), - NULL, list, - e_container_change_tab_order_destroy_notify, - FALSE, FALSE); -} diff --git a/widgets/misc/e-gui-utils.h b/widgets/misc/e-gui-utils.h deleted file mode 100644 index 1d47a7b514..0000000000 --- a/widgets/misc/e-gui-utils.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef E_GUI_UTILS_H -#define E_GUI_UTILS_H - -#include <gtk/gtkmenu.h> -#include <gtk/gtkwindow.h> - -#include <libgnomeui/gnome-messagebox.h> - -void e_popup_menu (GtkMenu *menu, GdkEventButton *event); -void e_auto_kill_popup_menu_on_hide (GtkMenu *menu); -void e_notice (GtkWindow *window, const char *type, const char *format, ...); -GtkWidget *e_create_image_widget (gchar *name, gchar *string1, gchar *string2, gint int1, gint int2); -void e_container_foreach_leaf (GtkContainer *container, - GtkCallback callback, - gpointer closure); -gint e_container_change_tab_order (GtkContainer *container, - GList *widgets); - -#endif /* E_GUI_UTILS_H */ diff --git a/widgets/misc/e-popup-menu.c b/widgets/misc/e-popup-menu.c deleted file mode 100644 index 3fb382ae20..0000000000 --- a/widgets/misc/e-popup-menu.c +++ /dev/null @@ -1,114 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-popup-menu.c: popup menu display -nnn * - * Author: - * Miguel de Icaza (miguel@kernel.org) - * Jody Goldberg (jgoldberg@home.com) - * - * (C) 2000 Helix Code, Inc. - */ -#include <config.h> -#include <gnome.h> -#include "e-popup-menu.h" -#include "e-gui-utils.h" - -/* - * Creates an item with an optional icon - */ -static GtkWidget * -make_item (GtkMenu *menu, const char *name, const char *pixname) -{ - GtkWidget *label, *item; - guint label_accel; - - if (*name == '\0') - return gtk_menu_item_new (); - - /* - * Ugh. This needs to go into Gtk+ - */ - label = gtk_accel_label_new (""); - label_accel = gtk_label_parse_uline (GTK_LABEL (label), name); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_widget_show (label); - - item = gtk_pixmap_menu_item_new (); - gtk_container_add (GTK_CONTAINER (item), label); - - if (label_accel != GDK_VoidSymbol){ - gtk_widget_add_accelerator ( - item, - "activate_item", - gtk_menu_ensure_uline_accel_group (GTK_MENU (menu)), - label_accel, 0, - GTK_ACCEL_LOCKED); - } - - if (pixname){ - GtkWidget *pixmap = gnome_stock_pixmap_widget (item, pixname); - - gtk_widget_show (pixmap); - gtk_pixmap_menu_item_set_pixmap ( - GTK_PIXMAP_MENU_ITEM (item), pixmap); - } - - return item; -} - -GtkMenu * -e_popup_menu_create (EPopupMenu *menu_list, int disable_mask, int hide_mask, void *closure) -{ - GtkMenu *menu = GTK_MENU (gtk_menu_new ()); - int i; - gboolean last_item_seperator = TRUE; - gint last_non_seperator = -1; - - for (i = 0; menu_list[i].name; i++) { - if (strcmp("", menu_list[i].name) && !(menu_list [i].disable_mask & hide_mask)) { - last_non_seperator = i; - } - } - - for (i = 0; i <= last_non_seperator; i++) { - GtkWidget *item; - gboolean seperator; - - seperator = !strcmp("", menu_list[i].name); - - if ((!(seperator && last_item_seperator)) && !(menu_list [i].disable_mask & hide_mask)) { - - item = make_item (menu, menu_list [i].name, - menu_list [i].pixname); - - if (menu_list [i].fn) - gtk_signal_connect ( - GTK_OBJECT (item), "activate", - GTK_SIGNAL_FUNC (menu_list [i].fn), - closure); - - if (menu_list [i].disable_mask & disable_mask) - gtk_widget_set_sensitive (item, FALSE); - - gtk_widget_show (item); - gtk_menu_append (menu, item); - } - last_item_seperator = seperator; - } - - return menu; -} - -void -e_popup_menu_run (EPopupMenu *menu_list, GdkEventButton *event, int disable_mask, int hide_mask, void *closure) -{ - GtkMenu *menu; - - g_return_if_fail (menu_list != NULL); - g_return_if_fail (event != NULL); - - menu = e_popup_menu_create (menu_list, disable_mask, hide_mask, closure); - - e_popup_menu (menu, event); -} - diff --git a/widgets/misc/e-popup-menu.h b/widgets/misc/e-popup-menu.h deleted file mode 100644 index ed54a632a5..0000000000 --- a/widgets/misc/e-popup-menu.h +++ /dev/null @@ -1,25 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef E_POPUP_MENU_H -#define E_POPUP_MENU_H - -#include <gtk/gtkwidget.h> - -typedef struct { - char const * const name; - char const * const pixname; - void (*fn)(GtkWidget *widget, void *closure); - int disable_mask; -} EPopupMenu; - -GtkMenu *e_popup_menu_create (EPopupMenu *menu_list, - int disable_mask, - int hide_mask, - void *closure); - -void e_popup_menu_run (EPopupMenu *menu_list, - GdkEventButton *event, - int disable_mask, - int hide_mask, - void *closure); - -#endif /* E_POPUP_MENU_H */ diff --git a/widgets/misc/e-printable.c b/widgets/misc/e-printable.c deleted file mode 100644 index ed982469b8..0000000000 --- a/widgets/misc/e-printable.c +++ /dev/null @@ -1,207 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-printable.c: an object printer. - * - * Author: - * Christopher James Lahey <clahey@helixcode.com> - * - * (C) 2000 Helix Code, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-util.h" -#include "e-printable.h" - -#define EP_CLASS(e) ((EPrintableClass *)((GtkObject *)e)->klass) - -#define PARENT_TYPE gtk_object_get_type () - - -static GtkObjectClass *e_printable_parent_class; - -enum { - PRINT_PAGE, - DATA_LEFT, - RESET, - HEIGHT, - WILL_FIT, - LAST_SIGNAL -}; - -static guint e_printable_signals [LAST_SIGNAL] = { 0, }; - -static void -e_printable_class_init (GtkObjectClass *object_class) -{ - EPrintableClass *klass = E_PRINTABLE_CLASS(object_class); - e_printable_parent_class = gtk_type_class (PARENT_TYPE); - - e_printable_signals [PRINT_PAGE] = - gtk_signal_new ("print_page", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EPrintableClass, print_page), - e_marshal_NONE__OBJECT_DOUBLE_DOUBLE_BOOL, - GTK_TYPE_NONE, 4, GTK_TYPE_OBJECT, GTK_TYPE_DOUBLE, GTK_TYPE_DOUBLE, GTK_TYPE_BOOL); - - e_printable_signals [DATA_LEFT] = - gtk_signal_new ("data_left", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EPrintableClass, data_left), - gtk_marshal_BOOL__NONE, - GTK_TYPE_BOOL, 0, GTK_TYPE_NONE); - - e_printable_signals [RESET] = - gtk_signal_new ("reset", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EPrintableClass, reset), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0, GTK_TYPE_NONE); - - e_printable_signals [HEIGHT] = - gtk_signal_new ("height", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EPrintableClass, height), - e_marshal_DOUBLE__OBJECT_DOUBLE_DOUBLE_BOOL, - GTK_TYPE_DOUBLE, 4, GTK_TYPE_OBJECT, GTK_TYPE_DOUBLE, GTK_TYPE_DOUBLE, GTK_TYPE_BOOL); - - e_printable_signals [WILL_FIT] = - gtk_signal_new ("will_fit", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EPrintableClass, will_fit), - e_marshal_BOOL__OBJECT_DOUBLE_DOUBLE_BOOL, - GTK_TYPE_BOOL, 4, GTK_TYPE_OBJECT, GTK_TYPE_DOUBLE, GTK_TYPE_DOUBLE, GTK_TYPE_BOOL); - - gtk_object_class_add_signals (object_class, e_printable_signals, LAST_SIGNAL); - - klass->print_page = NULL; - klass->data_left = NULL; - klass->reset = NULL; - klass->height = NULL; - klass->will_fit = NULL; -} - - -guint -e_printable_get_type (void) -{ - static guint type = 0; - - if (!type) - { - GtkTypeInfo info = - { - "EPrintable", - sizeof (EPrintable), - sizeof (EPrintableClass), - (GtkClassInitFunc) e_printable_class_init, - NULL, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - type = gtk_type_unique (gtk_object_get_type (), &info); - } - - return type; -} - -EPrintable * -e_printable_new(void) -{ - return E_PRINTABLE(gtk_type_new(e_printable_get_type())); -} - -void -e_printable_print_page (EPrintable *e_printable, - GnomePrintContext *context, - gdouble width, - gdouble height, - gboolean quantized) -{ - g_return_if_fail (e_printable != NULL); - g_return_if_fail (E_IS_PRINTABLE (e_printable)); - - gtk_signal_emit (GTK_OBJECT (e_printable), - e_printable_signals [PRINT_PAGE], - context, - width, - height, - quantized); -} - -gboolean -e_printable_data_left (EPrintable *e_printable) -{ - gboolean ret_val; - - g_return_val_if_fail (e_printable != NULL, FALSE); - g_return_val_if_fail (E_IS_PRINTABLE (e_printable), FALSE); - - gtk_signal_emit (GTK_OBJECT (e_printable), - e_printable_signals [DATA_LEFT], - &ret_val); - - return ret_val; -} - -void -e_printable_reset (EPrintable *e_printable) -{ - g_return_if_fail (e_printable != NULL); - g_return_if_fail (E_IS_PRINTABLE (e_printable)); - - gtk_signal_emit (GTK_OBJECT (e_printable), - e_printable_signals [RESET]); -} - -gdouble -e_printable_height (EPrintable *e_printable, - GnomePrintContext *context, - gdouble width, - gdouble max_height, - gboolean quantized) -{ - gdouble ret_val; - - g_return_val_if_fail (e_printable != NULL, -1); - g_return_val_if_fail (E_IS_PRINTABLE (e_printable), -1); - - gtk_signal_emit (GTK_OBJECT (e_printable), - e_printable_signals [HEIGHT], - context, - width, - max_height, - quantized, - &ret_val); - - return ret_val; -} - -gboolean -e_printable_will_fit (EPrintable *e_printable, - GnomePrintContext *context, - gdouble width, - gdouble max_height, - gboolean quantized) -{ - gboolean ret_val; - - g_return_val_if_fail (e_printable != NULL, -1); - g_return_val_if_fail (E_IS_PRINTABLE (e_printable), -1); - - gtk_signal_emit (GTK_OBJECT (e_printable), - e_printable_signals [WILL_FIT], - context, - width, - max_height, - quantized, - &ret_val); - - return ret_val; -} diff --git a/widgets/misc/e-printable.h b/widgets/misc/e-printable.h deleted file mode 100644 index 18e6ec8472..0000000000 --- a/widgets/misc/e-printable.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-printable.h: an object printer. - * - * Author: - * Christopher James Lahey <clahey@helixcode.com> - * - * (C) 2000 Helix Code, Inc. - */ -#ifndef _E_PRINTABLE_H_ -#define _E_PRINTABLE_H_ - -#include <gtk/gtkobject.h> -#include <libgnomeprint/gnome-print.h> - -#define E_PRINTABLE_TYPE (e_printable_get_type ()) -#define E_PRINTABLE(o) (GTK_CHECK_CAST ((o), E_PRINTABLE_TYPE, EPrintable)) -#define E_PRINTABLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_PRINTABLE_TYPE, EPrintableClass)) -#define E_IS_PRINTABLE(o) (GTK_CHECK_TYPE ((o), E_PRINTABLE_TYPE)) -#define E_IS_PRINTABLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_PRINTABLE_TYPE)) - -typedef struct { - GtkObject base; -} EPrintable; - -typedef struct { - GtkObjectClass parent_class; - - /* - * Signals - */ - - void (*print_page) (EPrintable *etm, GnomePrintContext *context, gdouble width, gdouble height, gboolean quantized); - gboolean (*data_left) (EPrintable *etm); - void (*reset) (EPrintable *etm); - gdouble (*height) (EPrintable *etm, GnomePrintContext *context, gdouble width, gdouble max_height, gboolean quantized); - - /* e_printable_will_fit (ep, ...) should be equal in value to - * (e_printable_print_page (ep, ...), - * !e_printable_data_left(ep)) except that the latter has the - * side effect of doing the printing and advancing the - * position of the printable. - */ - - gboolean (*will_fit) (EPrintable *etm, GnomePrintContext *context, gdouble width, gdouble max_height, gboolean quantized); -} EPrintableClass; - -GtkType e_printable_get_type (void); - -EPrintable *e_printable_new (void); - -/* - * Routines for emitting signals on the e_table */ -void e_printable_print_page (EPrintable *e_printable, - GnomePrintContext *context, - gdouble width, - gdouble height, - gboolean quantized); -gboolean e_printable_data_left (EPrintable *e_printable); -void e_printable_reset (EPrintable *e_printable); -gdouble e_printable_height (EPrintable *e_printable, - GnomePrintContext *context, - gdouble width, - gdouble max_height, - gboolean quantized); -gboolean e_printable_will_fit (EPrintable *e_printable, - GnomePrintContext *context, - gdouble width, - gdouble max_height, - gboolean quantized); - -#endif /* _E_PRINTABLE_H_ */ diff --git a/widgets/misc/e-reflow.c b/widgets/misc/e-reflow.c deleted file mode 100644 index 0e9c8b92b1..0000000000 --- a/widgets/misc/e-reflow.c +++ /dev/null @@ -1,859 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-reflow.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <config.h> -#include <gnome.h> -#include <math.h> -#include "e-reflow.h" -#include "e-text.h" -#include <e-util/e-canvas-utils.h> -#include <e-util/e-canvas.h> -#include <e-util/e-util.h> - -static void e_reflow_init (EReflow *reflow); -static void e_reflow_class_init (EReflowClass *klass); -static void e_reflow_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); -static void e_reflow_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_reflow_destroy (GtkObject *object); -static gboolean e_reflow_event (GnomeCanvasItem *item, GdkEvent *event); -static void e_reflow_realize (GnomeCanvasItem *item); -static void e_reflow_unrealize (GnomeCanvasItem *item); -static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable, - int x, int y, int width, int height); -static void e_reflow_update (GnomeCanvasItem *item, double affine[6], ArtSVP *clip_path, gint flags); -static double e_reflow_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual_item); -static void e_reflow_reflow (GnomeCanvasItem *item, int flags); -static void e_reflow_real_add_item(EReflow *e_reflow, GnomeCanvasItem *item); -static void set_empty(EReflow *e_reflow); - -static void e_reflow_resize_children (GnomeCanvasItem *item); - -#define E_REFLOW_DIVIDER_WIDTH 2 -#define E_REFLOW_BORDER_WIDTH 7 -#define E_REFLOW_FULL_GUTTER (E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH * 2) - -static GnomeCanvasGroupClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0, - ARG_MINIMUM_WIDTH, - ARG_WIDTH, - ARG_HEIGHT, - ARG_EMPTY_MESSAGE, -}; - -GtkType -e_reflow_get_type (void) -{ - static GtkType reflow_type = 0; - - if (!reflow_type) - { - static const GtkTypeInfo reflow_info = - { - "EReflow", - sizeof (EReflow), - sizeof (EReflowClass), - (GtkClassInitFunc) e_reflow_class_init, - (GtkObjectInitFunc) e_reflow_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - reflow_type = gtk_type_unique (gnome_canvas_group_get_type (), &reflow_info); - } - - return reflow_type; -} - -static void -e_reflow_class_init (EReflowClass *klass) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - object_class = (GtkObjectClass*) klass; - item_class = (GnomeCanvasItemClass *) klass; - - parent_class = gtk_type_class (gnome_canvas_group_get_type ()); - - gtk_object_add_arg_type ("EReflow::minimum_width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_MINIMUM_WIDTH); - gtk_object_add_arg_type ("EReflow::width", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_WIDTH); - gtk_object_add_arg_type ("EReflow::height", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_HEIGHT); - gtk_object_add_arg_type ("EReflow::empty_message", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_EMPTY_MESSAGE); - - klass->add_item = e_reflow_real_add_item; - - object_class->set_arg = e_reflow_set_arg; - object_class->get_arg = e_reflow_get_arg; - object_class->destroy = e_reflow_destroy; - - /* GnomeCanvasItem method overrides */ - item_class->event = e_reflow_event; - item_class->realize = e_reflow_realize; - item_class->unrealize = e_reflow_unrealize; - item_class->draw = e_reflow_draw; - item_class->update = e_reflow_update; - item_class->point = e_reflow_point; -} - -static void -e_reflow_init (EReflow *reflow) -{ - reflow->items = NULL; - reflow->columns = NULL; - reflow->column_width = 150; - - reflow->minimum_width = 10; - reflow->width = 10; - reflow->height = 10; - reflow->idle = 0; - - reflow->empty_message = NULL; - reflow->empty_text = NULL; - - reflow->column_drag = FALSE; - - reflow->need_height_update = FALSE; - reflow->need_column_resize = FALSE; - - reflow->default_cursor_shown = TRUE; - reflow->arrow_cursor = NULL; - reflow->default_cursor = NULL; - - e_canvas_item_set_reflow_callback(GNOME_CANVAS_ITEM(reflow), e_reflow_reflow); -} - -static void -e_reflow_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EReflow *e_reflow; - - item = GNOME_CANVAS_ITEM (o); - e_reflow = E_REFLOW (o); - - switch (arg_id){ - case ARG_HEIGHT: - e_reflow->height = GTK_VALUE_DOUBLE (*arg); - e_canvas_item_request_reflow(item); - break; - case ARG_MINIMUM_WIDTH: - e_reflow->minimum_width = GTK_VALUE_DOUBLE (*arg); - if (GNOME_CANVAS_ITEM_REALIZED & GTK_OBJECT_FLAGS(o)) - set_empty(e_reflow); - e_canvas_item_request_reflow(item); - break; - case ARG_EMPTY_MESSAGE: - g_free(e_reflow->empty_message); - e_reflow->empty_message = g_strdup(GTK_VALUE_STRING (*arg)); - if (GNOME_CANVAS_ITEM_REALIZED & GTK_OBJECT_FLAGS(o)) - set_empty(e_reflow); - } -} - -static void -e_reflow_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - EReflow *e_reflow; - - e_reflow = E_REFLOW (object); - - switch (arg_id) { - case ARG_MINIMUM_WIDTH: - GTK_VALUE_DOUBLE (*arg) = e_reflow->minimum_width; - break; - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = e_reflow->width; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = e_reflow->height; - break; - case ARG_EMPTY_MESSAGE: - GTK_VALUE_STRING (*arg) = g_strdup(e_reflow->empty_message); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -e_reflow_destroy (GtkObject *object) -{ - EReflow *reflow = E_REFLOW(object); - - g_list_foreach(reflow->items, (GFunc) gtk_object_unref, NULL); - g_list_free(reflow->items); - reflow->items = NULL; - - g_free(reflow->empty_message); - - GTK_OBJECT_CLASS(parent_class)->destroy (object); -} - -static void -e_reflow_realize (GnomeCanvasItem *item) -{ - EReflow *e_reflow; - GnomeCanvasGroup *group; - GList *list; - GtkAdjustment *adjustment; - - e_reflow = E_REFLOW (item); - group = GNOME_CANVAS_GROUP( item ); - - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) - (* GNOME_CANVAS_ITEM_CLASS(parent_class)->realize) (item); - - e_reflow->arrow_cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW); - e_reflow->default_cursor = gdk_cursor_new (GDK_LEFT_PTR); - - for(list = e_reflow->items; list; list = g_list_next(list)) { - GnomeCanvasItem *item = GNOME_CANVAS_ITEM(list->data); - gnome_canvas_item_set(item, - "width", (double) e_reflow->column_width, - NULL); - } - - set_empty(e_reflow); - - e_canvas_item_request_reflow(item); - - adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas)); - adjustment->step_increment = (e_reflow->column_width + E_REFLOW_FULL_GUTTER) / 2; - adjustment->page_increment = adjustment->page_size - adjustment->step_increment; - gtk_adjustment_changed(adjustment); - - if (!item->canvas->aa) { - } -} - -static void -e_reflow_unrealize (GnomeCanvasItem *item) -{ - EReflow *e_reflow; - - e_reflow = E_REFLOW (item); - - if (!item->canvas->aa) - { - } - - gdk_cursor_destroy (e_reflow->arrow_cursor); - gdk_cursor_destroy (e_reflow->default_cursor); - e_reflow->arrow_cursor = NULL; - e_reflow->default_cursor = NULL; - - g_list_free (e_reflow->columns); - e_reflow->columns = NULL; - - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) - (* GNOME_CANVAS_ITEM_CLASS(parent_class)->unrealize) (item); -} - -static gint -e_reflow_pick_line (EReflow *e_reflow, double x) -{ - x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH; - x /= e_reflow->column_width + E_REFLOW_FULL_GUTTER; - return x; -} - -static gboolean -e_reflow_event (GnomeCanvasItem *item, GdkEvent *event) -{ - EReflow *e_reflow; - - e_reflow = E_REFLOW (item); - - switch( event->type ) - { - case GDK_KEY_PRESS: - if (event->key.keyval == GDK_Tab || - event->key.keyval == GDK_KP_Tab || - event->key.keyval == GDK_ISO_Left_Tab) { - GList *list; - for (list = e_reflow->items; list; list = list->next) { - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (list->data); - EFocus has_focus; - gtk_object_get(GTK_OBJECT(item), - "has_focus", &has_focus, - NULL); - if (has_focus) { - if (event->key.state & GDK_SHIFT_MASK) - list = list->prev; - else - list = list->next; - if (list) { - item = GNOME_CANVAS_ITEM(list->data); - gnome_canvas_item_set(item, - "has_focus", (event->key.state & GDK_SHIFT_MASK) ? E_FOCUS_END : E_FOCUS_START, - NULL); - return 1; - } else { - return 0; - } - } - } - } - break; - case GDK_BUTTON_PRESS: - switch(event->button.button) - { - case 1: - { - GdkEventButton *button = (GdkEventButton *) event; - double n_x, max_x; - n_x = button->x; - n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH; - n_x = fmod(n_x,(e_reflow->column_width + E_REFLOW_FULL_GUTTER)); - - max_x = E_REFLOW_BORDER_WIDTH; - max_x += (e_reflow->column_width + E_REFLOW_FULL_GUTTER) * e_reflow->column_count; - if ( button->y >= E_REFLOW_BORDER_WIDTH && button->y <= e_reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER && max_x > button->x ) { - e_reflow->which_column_dragged = e_reflow_pick_line(e_reflow, button->x); - e_reflow->start_x = e_reflow->which_column_dragged * (e_reflow->column_width + E_REFLOW_FULL_GUTTER) - E_REFLOW_DIVIDER_WIDTH / 2; - e_reflow->temp_column_width = e_reflow->column_width; - e_reflow->column_drag = TRUE; - - gnome_canvas_item_grab (item, - GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, - e_reflow->arrow_cursor, - button->time); - - e_reflow->previous_temp_column_width = -1; - e_reflow->need_column_resize = TRUE; - gnome_canvas_item_request_update(item); - return TRUE; - } - } - break; - case 4: - { - GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas)); - gdouble new_value = adjustment->value; - new_value -= adjustment->step_increment; - gtk_adjustment_set_value(adjustment, new_value); - } - break; - case 5: - { - GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas)); - gdouble new_value = adjustment->value; - new_value += adjustment->step_increment; - if ( new_value > adjustment->upper - adjustment->page_size ) - new_value = adjustment->upper - adjustment->page_size; - gtk_adjustment_set_value(adjustment, new_value); - } - break; - } - break; - case GDK_BUTTON_RELEASE: - if (e_reflow->column_drag) { - gdouble old_width = e_reflow->column_width; - GdkEventButton *button = (GdkEventButton *) event; - GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas)); - e_reflow->temp_column_width = e_reflow->column_width + - (button->x - e_reflow->start_x)/(e_reflow->which_column_dragged - e_reflow_pick_line(e_reflow, adjustment->value)); - if ( e_reflow->temp_column_width < 50 ) - e_reflow->temp_column_width = 50; - e_reflow->column_drag = FALSE; - if ( old_width != e_reflow->temp_column_width ) { - gtk_adjustment_set_value(adjustment, adjustment->value + e_reflow_pick_line(e_reflow, adjustment->value) * (e_reflow->temp_column_width - e_reflow->column_width)); - e_reflow->column_width = e_reflow->temp_column_width; - adjustment->step_increment = (e_reflow->column_width + E_REFLOW_FULL_GUTTER) / 2; - adjustment->page_increment = adjustment->page_size - adjustment->step_increment; - gtk_adjustment_changed(adjustment); - e_reflow_resize_children(item); - e_canvas_item_request_reflow(item); - } - e_reflow->need_column_resize = TRUE; - gnome_canvas_item_request_update(item); - gnome_canvas_item_ungrab (item, button->time); - return TRUE; - } - break; - case GDK_MOTION_NOTIFY: - if (e_reflow->column_drag) { - double old_width = e_reflow->temp_column_width; - GdkEventMotion *motion = (GdkEventMotion *) event; - GtkAdjustment *adjustment = gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas)); - e_reflow->temp_column_width = e_reflow->column_width + - (motion->x - e_reflow->start_x)/(e_reflow->which_column_dragged - e_reflow_pick_line(e_reflow, adjustment->value)); - if (e_reflow->temp_column_width < 50) - e_reflow->temp_column_width = 50; - if (old_width != e_reflow->temp_column_width) { - e_reflow->need_column_resize = TRUE; - gnome_canvas_item_request_update(item); - } - return TRUE; - } else { - GdkEventMotion *motion = (GdkEventMotion *) event; - double n_x, max_x; - - n_x = motion->x; - n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH; - n_x = fmod(n_x,(e_reflow->column_width + E_REFLOW_FULL_GUTTER)); - - max_x = E_REFLOW_BORDER_WIDTH; - max_x += (e_reflow->column_width + E_REFLOW_FULL_GUTTER) * e_reflow->column_count; - - if ( motion->y >= E_REFLOW_BORDER_WIDTH && motion->y <= e_reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER && max_x > motion->x) { - if ( e_reflow->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, e_reflow->arrow_cursor); - e_reflow->default_cursor_shown = FALSE; - } - } else - if ( ! e_reflow->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, e_reflow->default_cursor); - e_reflow->default_cursor_shown = TRUE; - } - - } - break; - case GDK_ENTER_NOTIFY: - if (!e_reflow->column_drag) { - GdkEventCrossing *crossing = (GdkEventCrossing *) event; - double n_x, max_x; - n_x = crossing->x; - n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH; - n_x = fmod(n_x,(e_reflow->column_width + E_REFLOW_FULL_GUTTER)); - - max_x = E_REFLOW_BORDER_WIDTH; - max_x += (e_reflow->column_width + E_REFLOW_FULL_GUTTER) * e_reflow->column_count; - if ( crossing->y >= E_REFLOW_BORDER_WIDTH && crossing->y <= e_reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER && max_x > crossing->x) { - if ( e_reflow->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, e_reflow->arrow_cursor); - e_reflow->default_cursor_shown = FALSE; - } - } - } - break; - case GDK_LEAVE_NOTIFY: - if (!e_reflow->column_drag) { - GdkEventCrossing *crossing = (GdkEventCrossing *) event; - double n_x; - n_x = crossing->x; - n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH; - n_x = fmod(n_x,(e_reflow->column_width + E_REFLOW_FULL_GUTTER)); - if ( !( crossing->y >= E_REFLOW_BORDER_WIDTH && crossing->y <= e_reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER ) ) { - if ( ! e_reflow->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, e_reflow->default_cursor); - e_reflow->default_cursor_shown = TRUE; - } - } - } - break; - default: - break; - } - - if (GNOME_CANVAS_ITEM_CLASS( parent_class )->event) - return (* GNOME_CANVAS_ITEM_CLASS( parent_class )->event) (item, event); - else - return 0; -} - -static void -e_reflow_real_add_item(EReflow *e_reflow, GnomeCanvasItem *item) -{ - e_reflow->items = g_list_append(e_reflow->items, item); - gtk_object_ref(GTK_OBJECT(item)); - if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) { - gnome_canvas_item_set(item, - "width", (double) e_reflow->column_width, - NULL); - e_reflow_post_add_item(e_reflow, item); - e_canvas_item_request_reflow(item); - } - -} - -static void e_reflow_draw (GnomeCanvasItem *item, GdkDrawable *drawable, - int x, int y, int width, int height) -{ - int x_rect, y_rect, width_rect, height_rect; - gdouble running_width; - EReflow *e_reflow = E_REFLOW(item); - int i; - double column_width; - - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->draw) - GNOME_CANVAS_ITEM_CLASS(parent_class)->draw (item, drawable, x, y, width, height); - column_width = e_reflow->column_width; - running_width = E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH; - x_rect = running_width; - y_rect = E_REFLOW_BORDER_WIDTH; - width_rect = E_REFLOW_DIVIDER_WIDTH; - height_rect = e_reflow->height - (E_REFLOW_BORDER_WIDTH * 2); - - /* Compute first column to draw. */ - i = x; - i /= column_width + E_REFLOW_FULL_GUTTER; - running_width += i * (column_width + E_REFLOW_FULL_GUTTER); - - for ( ; i < e_reflow->column_count; i++) { - if ( running_width > x + width ) - break; - x_rect = running_width; - gtk_paint_flat_box(GTK_WIDGET(item->canvas)->style, - drawable, - GTK_STATE_ACTIVE, - GTK_SHADOW_NONE, - NULL, - GTK_WIDGET(item->canvas), - "reflow", - x_rect - x, - y_rect - y, - width_rect, - height_rect); - running_width += E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH; - } - if (e_reflow->column_drag) { - int start_line = e_reflow_pick_line(e_reflow, - gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas))->value); - i = x - start_line * (column_width + E_REFLOW_FULL_GUTTER); - running_width = start_line * (column_width + E_REFLOW_FULL_GUTTER); - column_width = e_reflow->temp_column_width; - running_width -= start_line * (column_width + E_REFLOW_FULL_GUTTER); - i += start_line * (column_width + E_REFLOW_FULL_GUTTER); - running_width += E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH; - x_rect = running_width; - y_rect = E_REFLOW_BORDER_WIDTH; - width_rect = E_REFLOW_DIVIDER_WIDTH; - height_rect = e_reflow->height - (E_REFLOW_BORDER_WIDTH * 2); - - /* Compute first column to draw. */ - i /= column_width + E_REFLOW_FULL_GUTTER; - running_width += i * (column_width + E_REFLOW_FULL_GUTTER); - - for ( ; i < e_reflow->column_count; i++) { - if ( running_width > x + width ) - break; - x_rect = running_width; - gdk_draw_rectangle(drawable, - GTK_WIDGET(item->canvas)->style->fg_gc[GTK_STATE_NORMAL], - TRUE, - x_rect - x, - y_rect - y, - width_rect - 1, - height_rect - 1); - running_width += E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH; - } - } -} - -static void -e_reflow_update (GnomeCanvasItem *item, double affine[6], ArtSVP *clip_path, gint flags) -{ - EReflow *e_reflow; - double x0, x1, y0, y1; - - e_reflow = E_REFLOW (item); - - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->update) - GNOME_CANVAS_ITEM_CLASS(parent_class)->update (item, affine, clip_path, flags); - - x0 = item->x1; - y0 = item->y1; - x1 = item->x2; - y1 = item->y2; - if ( x1 < x0 + e_reflow->width ) - x1 = x0 + e_reflow->width; - if ( y1 < y0 + e_reflow->height ) - y1 = y0 + e_reflow->height; - item->x2 = x1; - item->y2 = y1; - - if (e_reflow->need_height_update) { - x0 = item->x1; - y0 = item->y1; - x1 = item->x2; - y1 = item->y2; - if ( x0 > 0 ) - x0 = 0; - if ( y0 > 0 ) - y0 = 0; - if ( x1 < E_REFLOW(item)->width ) - x1 = E_REFLOW(item)->width; - if ( x1 < E_REFLOW(item)->height ) - x1 = E_REFLOW(item)->height; - - gnome_canvas_request_redraw(item->canvas, x0, y0, x1, y1); - e_reflow->need_height_update = FALSE; - } else if (e_reflow->need_column_resize) { - int x_rect, y_rect, width_rect, height_rect; - int start_line = e_reflow_pick_line(e_reflow, - gtk_layout_get_hadjustment(GTK_LAYOUT(item->canvas))->value); - gdouble running_width; - int i; - double column_width; - - if ( e_reflow->previous_temp_column_width != -1 ) { - running_width = start_line * (e_reflow->column_width + E_REFLOW_FULL_GUTTER); - column_width = e_reflow->previous_temp_column_width; - running_width -= start_line * (column_width + E_REFLOW_FULL_GUTTER); - running_width += E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH; - y_rect = E_REFLOW_BORDER_WIDTH; - width_rect = E_REFLOW_DIVIDER_WIDTH; - height_rect = e_reflow->height - (E_REFLOW_BORDER_WIDTH * 2); - - for ( i = 0; i < e_reflow->column_count; i++) { - x_rect = running_width; - gnome_canvas_request_redraw(item->canvas, x_rect, y_rect, x_rect + width_rect, y_rect + height_rect); - running_width += E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH; - } - } - - if ( e_reflow->temp_column_width != -1 ) { - running_width = start_line * (e_reflow->column_width + E_REFLOW_FULL_GUTTER); - column_width = e_reflow->temp_column_width; - running_width -= start_line * (column_width + E_REFLOW_FULL_GUTTER); - running_width += E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH; - y_rect = E_REFLOW_BORDER_WIDTH; - width_rect = E_REFLOW_DIVIDER_WIDTH; - height_rect = e_reflow->height - (E_REFLOW_BORDER_WIDTH * 2); - - for ( i = 0; i < e_reflow->column_count; i++) { - x_rect = running_width; - gnome_canvas_request_redraw(item->canvas, x_rect, y_rect, x_rect + width_rect, y_rect + height_rect); - running_width += E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH; - } - } - - e_reflow->previous_temp_column_width = e_reflow->temp_column_width; - e_reflow->need_column_resize = FALSE; - } -} - -static void -e_reflow_resize_children (GnomeCanvasItem *item) -{ - GList *list; - EReflow *e_reflow; - - e_reflow = E_REFLOW (item); - for ( list = e_reflow->items; list; list = list->next ) { - GnomeCanvasItem *child = GNOME_CANVAS_ITEM(list->data); - gnome_canvas_item_set(child, - "width", (double) e_reflow->column_width, - NULL); - } -} - -static double -e_reflow_point (GnomeCanvasItem *item, - double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - double distance = 1; - - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->point) - distance = GNOME_CANVAS_ITEM_CLASS(parent_class)->point (item, x, y, cx, cy, actual_item); - if (*actual_item) - return 0; - - *actual_item = item; - return 0; -#if 0 - if (y >= E_REFLOW_BORDER_WIDTH && y <= e_reflow->height - E_REFLOW_BORDER_WIDTH) { - float n_x; - n_x = x; - n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH; - n_x = fmod(n_x, (e_reflow->column_width + E_REFLOW_FULL_GUTTER)); - if (n_x < E_REFLOW_FULL_GUTTER) { - *actual_item = item; - return 0; - } - } - return distance; -#endif -} - -static void -_reflow( EReflow *e_reflow ) -{ - gdouble running_height; - GList *list; - double item_height; - - if (e_reflow->columns) { - g_list_free (e_reflow->columns); - e_reflow->columns = NULL; - } - - e_reflow->column_count = 0; - - if (e_reflow->items == NULL) { - e_reflow->columns = NULL; - e_reflow->column_count = 0; - return; - } - - list = e_reflow->items; - - gtk_object_get (GTK_OBJECT(list->data), - "height", &item_height, - NULL); - running_height = E_REFLOW_BORDER_WIDTH + item_height + E_REFLOW_BORDER_WIDTH; - e_reflow->columns = g_list_append (e_reflow->columns, list); - e_reflow->column_count = 1; - - list = g_list_next(list); - - for ( ; list; list = g_list_next(list)) { - gtk_object_get (GTK_OBJECT(list->data), - "height", &item_height, - NULL); - if (running_height + item_height + E_REFLOW_BORDER_WIDTH > e_reflow->height) { - running_height = E_REFLOW_BORDER_WIDTH + item_height + E_REFLOW_BORDER_WIDTH; - e_reflow->columns = g_list_append (e_reflow->columns, list); - e_reflow->column_count ++; - } else { - running_height += item_height + E_REFLOW_BORDER_WIDTH; - } - } -} - -static void -set_empty(EReflow *e_reflow) -{ - if (e_reflow->items == NULL) { - if (e_reflow->empty_text) { - if (e_reflow->empty_message) { - gnome_canvas_item_set(e_reflow->empty_text, - "width", e_reflow->minimum_width, - "text", e_reflow->empty_message, - NULL); - e_canvas_item_move_absolute(e_reflow->empty_text, - e_reflow->minimum_width / 2, - 0); - } else { - gtk_object_destroy(GTK_OBJECT(e_reflow->empty_text)); - e_reflow->empty_text = NULL; - } - } else { - if (e_reflow->empty_message) - e_reflow->empty_text = - gnome_canvas_item_new(GNOME_CANVAS_GROUP(e_reflow), - e_text_get_type(), - "anchor", GTK_ANCHOR_N, - "width", e_reflow->minimum_width, - "clip", TRUE, - "use_ellipsis", TRUE, - "font_gdk", GTK_WIDGET(GNOME_CANVAS_ITEM(e_reflow)->canvas)->style->font, - "fill_color", "black", - "justification", GTK_JUSTIFY_CENTER, - "text", e_reflow->empty_message, - NULL); - e_canvas_item_move_absolute(e_reflow->empty_text, - e_reflow->minimum_width / 2, - 0); - } - } else { - if (e_reflow->empty_text) { - gtk_object_destroy(GTK_OBJECT(e_reflow->empty_text)); - e_reflow->empty_text = NULL; - } - } -} - -static void -e_reflow_reflow( GnomeCanvasItem *item, int flags ) -{ - EReflow *e_reflow = E_REFLOW(item); - if ( GTK_OBJECT_FLAGS( e_reflow ) & GNOME_CANVAS_ITEM_REALIZED ) { - - gdouble old_width; - gdouble running_width; - - _reflow (e_reflow); - - old_width = e_reflow->width; - - running_width = E_REFLOW_BORDER_WIDTH; - - if (e_reflow->items == NULL) { - } else { - GList *list; - GList *next_column; - gdouble item_height; - gdouble running_height; - - running_height = E_REFLOW_BORDER_WIDTH; - - list = e_reflow->items; - gtk_object_get (GTK_OBJECT(list->data), - "height", &item_height, - NULL); - e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data), - (double) running_width, - (double) running_height); - running_height += item_height + E_REFLOW_BORDER_WIDTH; - next_column = g_list_next(e_reflow->columns); - list = g_list_next(list); - - for( ; list; list = g_list_next(list)) { - gtk_object_get (GTK_OBJECT(list->data), - "height", &item_height, - NULL); - - if (next_column && (next_column->data == list)) { - next_column = g_list_next (next_column); - running_height = E_REFLOW_BORDER_WIDTH; - running_width += e_reflow->column_width + E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH; - } - e_canvas_item_move_absolute(GNOME_CANVAS_ITEM(list->data), - (double) running_width, - (double) running_height); - - running_height += item_height + E_REFLOW_BORDER_WIDTH; - } - - } - e_reflow->width = running_width + e_reflow->column_width + E_REFLOW_BORDER_WIDTH; - if ( e_reflow->width < e_reflow->minimum_width ) - e_reflow->width = e_reflow->minimum_width; - if (old_width != e_reflow->width) - e_canvas_item_request_parent_reflow(item); - } -} - -void -e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item) -{ - if (E_REFLOW_CLASS(GTK_OBJECT(e_reflow)->klass)->add_item) - (E_REFLOW_CLASS(GTK_OBJECT(e_reflow)->klass)->add_item) (e_reflow, item); -} - -void -e_reflow_post_add_item(EReflow *e_reflow, GnomeCanvasItem *item) -{ - set_empty(e_reflow); -} diff --git a/widgets/misc/e-reflow.h b/widgets/misc/e-reflow.h deleted file mode 100644 index eb66b094a5..0000000000 --- a/widgets/misc/e-reflow.h +++ /dev/null @@ -1,112 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-reflow.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef __E_REFLOW_H__ -#define __E_REFLOW_H__ - -#include <gnome.h> - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* EReflow - A canvas item container. - * - * The following arguments are available: - * - * name type read/write description - * -------------------------------------------------------------------------------- - * minimum_width double RW minimum width of the reflow. width >= minimum_width - * width double R width of the reflow - * height double RW height of the reflow - */ - -#define E_REFLOW_TYPE (e_reflow_get_type ()) -#define E_REFLOW(obj) (GTK_CHECK_CAST ((obj), E_REFLOW_TYPE, EReflow)) -#define E_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_REFLOW_TYPE, EReflowClass)) -#define E_IS_REFLOW(obj) (GTK_CHECK_TYPE ((obj), E_REFLOW_TYPE)) -#define E_IS_REFLOW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_REFLOW_TYPE)) - - -typedef struct _EReflow EReflow; -typedef struct _EReflowClass EReflowClass; - -struct _EReflow -{ - GnomeCanvasGroup parent; - - /* item specific fields */ - GList *items; /* Of type GnomeCanvasItem */ - GList *columns; /* Of type GList of type GnomeCanvasItem (points into items) */ - gint column_count; /* Number of columnns */ - - GnomeCanvasItem *empty_text; - gchar *empty_message; - - double minimum_width; - double width; - double height; - - double column_width; - - int idle; - - /* These are all for when the column is being dragged. */ - gboolean column_drag; - gdouble start_x; - gint which_column_dragged; - double temp_column_width; - double previous_temp_column_width; - - guint need_height_update : 1; - guint need_column_resize : 1; - - guint default_cursor_shown : 1; - GdkCursor *arrow_cursor; - GdkCursor *default_cursor; -}; - -struct _EReflowClass -{ - GnomeCanvasGroupClass parent_class; - - /* Virtual methods. */ - void (* add_item) (EReflow *reflow, GnomeCanvasItem *item); -}; - -/* - * To be added to a reflow, an item must have the argument "width" as - * a Read/Write argument and "height" as a Read Only argument. It - * should also do an ECanvas parent reflow request if its size - * changes. - */ -void e_reflow_add_item(EReflow *e_reflow, GnomeCanvasItem *item); -GtkType e_reflow_get_type (void); - -/* Internal usage only: */ -void e_reflow_post_add_item(EReflow *e_reflow, GnomeCanvasItem *item); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_REFLOW_H__ */ diff --git a/widgets/misc/e-scroll-frame.c b/widgets/misc/e-scroll-frame.c deleted file mode 100644 index 8105b9dee8..0000000000 --- a/widgets/misc/e-scroll-frame.c +++ /dev/null @@ -1,1250 +0,0 @@ -/* GTK - The GIMP Toolkit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -/* EScrollFrame based on GtkScrolledWindow. - * - * Modifications by Federico Mena <federico@helixcode.com> - */ - -#include <config.h> -#include <gtk/gtkhscrollbar.h> -#include <gtk/gtkvscrollbar.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkviewport.h> -#include "e-scroll-frame.h" - - -/* scrolled window policy and size requisition handling: - * - * gtk size requisition works as follows: - * a widget upon size-request reports the width and height that it finds - * to be best suited to display its contents, including children. - * the width and/or height reported from a widget upon size requisition - * may be overidden by the user by specifying a width and/or height - * other than 0 through gtk_widget_set_usize(). - * - * a scrolled window needs (for imlementing all three policy types) to - * request its width and height based on two different rationales. - * 1) the user wants the scrolled window to just fit into the space - * that it gets allocated for a specifc dimension. - * 1.1) this does not apply if the user specified a concrete value - * value for that specific dimension by either specifying usize for the - * scrolled window or for its child. - * 2) the user wants the scrolled window to take as much space up as - * is desired by the child for a specifc dimension (i.e. POLICY_NEVER). - * - * also, kinda obvious: - * 3) a user would certainly not have choosen a scrolled window as a container - * for the child, if the resulting allocation takes up more space than the - * child would have allocated without the scrolled window. - * - * conclusions: - * A) from 1) follows: the scrolled window shouldn't request more space for a - * specifc dimension than is required at minimum. - * B) from 1.1) follows: the requisition may be overidden by usize of the scrolled - * window (done automatically) or by usize of the child (needs to be checked). - * C) from 2) follows: for POLICY_NEVER, the scrolled window simply reports the - * child's dimension. - * D) from 3) follows: the scrolled window child's minimum width and minimum height - * under A) at least correspond to the space taken up by its scrollbars. - */ - -/* Object argument IDs */ -enum { - ARG_0, - ARG_HADJUSTMENT, - ARG_VADJUSTMENT, - ARG_HSCROLLBAR_POLICY, - ARG_VSCROLLBAR_POLICY, - ARG_FRAME_PLACEMENT, - ARG_SHADOW_TYPE, - ARG_SCROLLBAR_SPACING -}; - -/* Private part of the EScrollFrame structure */ -typedef struct { - /* Horizontal and vertical scrollbars */ - GtkWidget *hsb; - GtkWidget *vsb; - - /* Space between scrollbars and frame */ - guint sb_spacing; - - /* Allocation for frame */ - guint frame_x; - guint frame_y; - guint frame_w; - guint frame_h; - - /* Scrollbar policy */ - guint hsb_policy : 2; - guint vsb_policy : 2; - - /* Whether scrollbars are visible */ - guint hsb_visible : 1; - guint vsb_visible : 1; - - /* Placement of frame wrt scrollbars */ - guint frame_placement : 2; - - /* Shadow type for frame */ - guint shadow_type : 3; -} ScrollFramePrivate; - - -static void e_scroll_frame_class_init (EScrollFrameClass *class); -static void e_scroll_frame_init (EScrollFrame *sf); -static void e_scroll_frame_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_scroll_frame_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_scroll_frame_destroy (GtkObject *object); -static void e_scroll_frame_finalize (GtkObject *object); - -static void e_scroll_frame_map (GtkWidget *widget); -static void e_scroll_frame_unmap (GtkWidget *widget); -static void e_scroll_frame_draw (GtkWidget *widget, GdkRectangle *area); -static void e_scroll_frame_size_request (GtkWidget *widget, GtkRequisition *requisition); -static void e_scroll_frame_size_allocate (GtkWidget *widget, GtkAllocation *allocation); -static gint e_scroll_frame_expose (GtkWidget *widget, GdkEventExpose *event); -static gint e_scroll_frame_button_press (GtkWidget *widget, GdkEventButton *event); -static void e_scroll_frame_add (GtkContainer *container, GtkWidget *widget); -static void e_scroll_frame_remove (GtkContainer *container, GtkWidget *widget); -static void e_scroll_frame_forall (GtkContainer *container, gboolean include_internals, - GtkCallback callback, gpointer callback_data); - -static GtkBinClass *parent_class; - - -/** - * e_scroll_frame_get_type: - * @void: - * - * Registers the #EScrollFrame class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the #EScrollFrame class. - **/ -GtkType -e_scroll_frame_get_type (void) -{ - static GtkType scroll_frame_type = 0; - - if (!scroll_frame_type) { - static const GtkTypeInfo scroll_frame_info = { - "EScrollFrame", - sizeof (EScrollFrame), - sizeof (EScrollFrameClass), - (GtkClassInitFunc) e_scroll_frame_class_init, - (GtkObjectInitFunc) e_scroll_frame_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - scroll_frame_type = gtk_type_unique (GTK_TYPE_BIN, &scroll_frame_info); - } - - return scroll_frame_type; -} - -/* Class initialization function for the scroll frame widget */ -static void -e_scroll_frame_class_init (EScrollFrameClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - GtkContainerClass *container_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - container_class = (GtkContainerClass *) class; - - parent_class = gtk_type_class (GTK_TYPE_BIN); - - gtk_object_add_arg_type ("EScrollFrame::hadjustment", - GTK_TYPE_ADJUSTMENT, - GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT, - ARG_HADJUSTMENT); - gtk_object_add_arg_type ("EScrollFrame::vadjustment", - GTK_TYPE_ADJUSTMENT, - GTK_ARG_READWRITE | GTK_ARG_CONSTRUCT, - ARG_VADJUSTMENT); - gtk_object_add_arg_type ("EScrollFrame::hscrollbar_policy", - GTK_TYPE_POLICY_TYPE, - GTK_ARG_READWRITE, - ARG_HSCROLLBAR_POLICY); - gtk_object_add_arg_type ("EScrollFrame::vscrollbar_policy", - GTK_TYPE_POLICY_TYPE, - GTK_ARG_READWRITE, - ARG_VSCROLLBAR_POLICY); - gtk_object_add_arg_type ("EScrollFrame::frame_placement", - GTK_TYPE_CORNER_TYPE, - GTK_ARG_READWRITE, - ARG_FRAME_PLACEMENT); - gtk_object_add_arg_type ("EScrollFrame::shadow_type", - GTK_TYPE_SHADOW_TYPE, - GTK_ARG_READWRITE, - ARG_SHADOW_TYPE); - gtk_object_add_arg_type ("EScrollFrame::scrollbar_spacing", - GTK_TYPE_UINT, - GTK_ARG_READWRITE, - ARG_SCROLLBAR_SPACING); - - object_class->set_arg = e_scroll_frame_set_arg; - object_class->get_arg = e_scroll_frame_get_arg; - object_class->destroy = e_scroll_frame_destroy; - object_class->finalize = e_scroll_frame_finalize; - - widget_class->map = e_scroll_frame_map; - widget_class->unmap = e_scroll_frame_unmap; - widget_class->draw = e_scroll_frame_draw; - widget_class->size_request = e_scroll_frame_size_request; - widget_class->size_allocate = e_scroll_frame_size_allocate; - widget_class->expose_event = e_scroll_frame_expose; - widget_class->button_press_event = e_scroll_frame_button_press; - - container_class->add = e_scroll_frame_add; - container_class->remove = e_scroll_frame_remove; - container_class->forall = e_scroll_frame_forall; -} - -/* Object initialization function for the scroll frame widget */ -static void -e_scroll_frame_init (EScrollFrame *sf) -{ - ScrollFramePrivate *priv; - - priv = g_new0 (ScrollFramePrivate, 1); - sf->priv = priv; - - GTK_WIDGET_SET_FLAGS (sf, GTK_NO_WINDOW); - - gtk_container_set_resize_mode (GTK_CONTAINER (sf), GTK_RESIZE_QUEUE); - - priv->sb_spacing = 3; - priv->hsb_policy = GTK_POLICY_ALWAYS; - priv->vsb_policy = GTK_POLICY_ALWAYS; - priv->frame_placement = GTK_CORNER_TOP_LEFT; - priv->shadow_type = GTK_SHADOW_NONE; -} - -/* Set_arg handler for the scroll frame widget */ -static void -e_scroll_frame_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - EScrollFrame *sf; - ScrollFramePrivate *priv; - - sf = E_SCROLL_FRAME (object); - priv = sf->priv; - - switch (arg_id) { - case ARG_HADJUSTMENT: - e_scroll_frame_set_hadjustment (sf, GTK_VALUE_POINTER (*arg)); - break; - - case ARG_VADJUSTMENT: - e_scroll_frame_set_vadjustment (sf, GTK_VALUE_POINTER (*arg)); - break; - - case ARG_HSCROLLBAR_POLICY: - e_scroll_frame_set_policy (sf, GTK_VALUE_ENUM (*arg), priv->vsb_policy); - break; - - case ARG_VSCROLLBAR_POLICY: - e_scroll_frame_set_policy (sf, priv->hsb_policy, GTK_VALUE_ENUM (*arg)); - break; - - case ARG_FRAME_PLACEMENT: - e_scroll_frame_set_placement (sf, GTK_VALUE_ENUM (*arg)); - break; - - case ARG_SHADOW_TYPE: - e_scroll_frame_set_shadow_type (sf, GTK_VALUE_ENUM (*arg)); - break; - - case ARG_SCROLLBAR_SPACING: - e_scroll_frame_set_scrollbar_spacing (sf, GTK_VALUE_UINT (*arg)); - break; - - default: - break; - } -} - -/* Get_arg handler for the scroll frame widget */ -static void -e_scroll_frame_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - EScrollFrame *sf; - ScrollFramePrivate *priv; - - sf = E_SCROLL_FRAME (object); - priv = sf->priv; - - switch (arg_id) { - case ARG_HADJUSTMENT: - GTK_VALUE_POINTER (*arg) = e_scroll_frame_get_hadjustment (sf); - break; - - case ARG_VADJUSTMENT: - GTK_VALUE_POINTER (*arg) = e_scroll_frame_get_vadjustment (sf); - break; - - case ARG_HSCROLLBAR_POLICY: - GTK_VALUE_ENUM (*arg) = priv->hsb_policy; - break; - - case ARG_VSCROLLBAR_POLICY: - GTK_VALUE_ENUM (*arg) = priv->vsb_policy; - break; - - case ARG_FRAME_PLACEMENT: - GTK_VALUE_ENUM (*arg) = priv->frame_placement; - break; - - case ARG_SHADOW_TYPE: - GTK_VALUE_ENUM (*arg) = priv->shadow_type; - break; - - case ARG_SCROLLBAR_SPACING: - GTK_VALUE_UINT (*arg) = priv->sb_spacing; - break; - - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -/* Destroy handler for the scroll frame widget */ -static void -e_scroll_frame_destroy (GtkObject *object) -{ - EScrollFrame *sf; - ScrollFramePrivate *priv; - - g_return_if_fail (object != NULL); - g_return_if_fail (E_IS_SCROLL_FRAME (object)); - - sf = E_SCROLL_FRAME (object); - priv = sf->priv; - - gtk_widget_unparent (priv->hsb); - gtk_widget_unparent (priv->vsb); - gtk_widget_destroy (priv->hsb); - gtk_widget_destroy (priv->vsb); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -/* Finalize handler for the scroll frame widget */ -static void -e_scroll_frame_finalize (GtkObject *object) -{ - EScrollFrame *sf; - ScrollFramePrivate *priv; - - sf = E_SCROLL_FRAME (object); - priv = sf->priv; - - gtk_widget_unref (priv->hsb); - gtk_widget_unref (priv->vsb); - - g_free (priv); - - if (GTK_OBJECT_CLASS (parent_class)->finalize) - (* GTK_OBJECT_CLASS (parent_class)->finalize) (object); -} - -/* Map handler for the scroll frame widget */ -static void -e_scroll_frame_map (GtkWidget *widget) -{ - EScrollFrame *sf; - ScrollFramePrivate *priv; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_SCROLL_FRAME (widget)); - - sf = E_SCROLL_FRAME (widget); - priv = sf->priv; - - /* chain parent class handler to map self and child */ - if (GTK_WIDGET_CLASS (parent_class)->map) - (* GTK_WIDGET_CLASS (parent_class)->map) (widget); - - if (GTK_WIDGET_VISIBLE (priv->hsb) && !GTK_WIDGET_MAPPED (priv->hsb)) - gtk_widget_map (priv->hsb); - - if (GTK_WIDGET_VISIBLE (priv->vsb) && !GTK_WIDGET_MAPPED (priv->vsb)) - gtk_widget_map (priv->vsb); -} - -/* Unmap handler for the scroll frame widget */ -static void -e_scroll_frame_unmap (GtkWidget *widget) -{ - EScrollFrame *sf; - ScrollFramePrivate *priv; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_SCROLL_FRAME (widget)); - - sf = E_SCROLL_FRAME (widget); - priv = sf->priv; - - /* chain parent class handler to unmap self and child */ - if (GTK_WIDGET_CLASS (parent_class)->unmap) - (* GTK_WIDGET_CLASS (parent_class)->unmap) (widget); - - if (GTK_WIDGET_MAPPED (priv->hsb)) - gtk_widget_unmap (priv->hsb); - - if (GTK_WIDGET_MAPPED (priv->vsb)) - gtk_widget_unmap (priv->vsb); -} - -/* Draws the shadow of a scroll frame widget */ -static void -draw_shadow (EScrollFrame *sf, GdkRectangle *area) -{ - ScrollFramePrivate *priv; - - g_assert (area != NULL); - - priv = sf->priv; - - gtk_paint_shadow (GTK_WIDGET (sf)->style, - GTK_WIDGET (sf)->window, - GTK_STATE_NORMAL, priv->shadow_type, - area, GTK_WIDGET (sf), - "scroll_frame", - priv->frame_x, priv->frame_y, - priv->frame_w, priv->frame_h); -} - -/* Draw handler for the scroll frame widget */ -static void -e_scroll_frame_draw (GtkWidget *widget, GdkRectangle *area) -{ - EScrollFrame *sf; - ScrollFramePrivate *priv; - GtkBin *bin; - GdkRectangle child_area; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_SCROLL_FRAME (widget)); - g_return_if_fail (area != NULL); - - sf = E_SCROLL_FRAME (widget); - priv = sf->priv; - bin = GTK_BIN (widget); - - if (GTK_WIDGET_DRAWABLE (widget)) - draw_shadow (sf, area); - - if (bin->child && GTK_WIDGET_VISIBLE (bin->child) - && gtk_widget_intersect (bin->child, area, &child_area)) - gtk_widget_draw (bin->child, &child_area); - - if (GTK_WIDGET_VISIBLE (priv->hsb) - && gtk_widget_intersect (priv->hsb, area, &child_area)) - gtk_widget_draw (priv->hsb, &child_area); - - if (GTK_WIDGET_VISIBLE (priv->vsb) - && gtk_widget_intersect (priv->vsb, area, &child_area)) - gtk_widget_draw (priv->vsb, &child_area); -} - -/* Forall handler for the scroll frame widget */ -static void -e_scroll_frame_forall (GtkContainer *container, gboolean include_internals, - GtkCallback callback, gpointer callback_data) -{ - EScrollFrame *sf; - ScrollFramePrivate *priv; - - g_return_if_fail (container != NULL); - g_return_if_fail (E_IS_SCROLL_FRAME (container)); - g_return_if_fail (callback != NULL); - - sf = E_SCROLL_FRAME (container); - priv = sf->priv; - - if (GTK_CONTAINER_CLASS (parent_class)->forall) - (* GTK_CONTAINER_CLASS (parent_class)->forall) ( - container, include_internals, - callback, callback_data); - - if (include_internals) { - if (priv->vsb) - (* callback) (priv->vsb, callback_data); - - if (priv->hsb) - (* callback) (priv->hsb, callback_data); - } -} - -/* Size_request handler for the scroll frame widget */ -static void -e_scroll_frame_size_request (GtkWidget *widget, GtkRequisition *requisition) -{ - EScrollFrame *sf; - ScrollFramePrivate *priv; - GtkBin *bin; - gint extra_width; - gint extra_height; - GtkRequisition hsb_requisition; - GtkRequisition vsb_requisition; - GtkRequisition child_requisition; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_SCROLL_FRAME (widget)); - g_return_if_fail (requisition != NULL); - - sf = E_SCROLL_FRAME (widget); - priv = sf->priv; - bin = GTK_BIN (widget); - - extra_width = 0; - extra_height = 0; - - requisition->width = GTK_CONTAINER (widget)->border_width * 2; - requisition->height = GTK_CONTAINER (widget)->border_width * 2; - - if (priv->shadow_type != GTK_SHADOW_NONE) { - requisition->width += 2 * widget->style->klass->xthickness; - requisition->height += 2 * widget->style->klass->ythickness; - } - - gtk_widget_size_request (priv->hsb, &hsb_requisition); - gtk_widget_size_request (priv->vsb, &vsb_requisition); - - if (bin->child && GTK_WIDGET_VISIBLE (bin->child)) { - static guint quark_aux_info; - - if (!quark_aux_info) - quark_aux_info = g_quark_from_static_string ("gtk-aux-info"); - - gtk_widget_size_request (bin->child, &child_requisition); - - if (priv->hsb_policy == GTK_POLICY_NEVER) - requisition->width += child_requisition.width; - else { - GtkWidgetAuxInfo *aux_info; - - aux_info = gtk_object_get_data_by_id (GTK_OBJECT (bin->child), - quark_aux_info); - if (aux_info && aux_info->width > 0) { - requisition->width += aux_info->width; - extra_width = -1; - } else - requisition->width += vsb_requisition.width; - } - - if (priv->vsb_policy == GTK_POLICY_NEVER) - requisition->height += child_requisition.height; - else { - GtkWidgetAuxInfo *aux_info; - - aux_info = gtk_object_get_data_by_id (GTK_OBJECT (bin->child), - quark_aux_info); - if (aux_info && aux_info->height > 0) { - requisition->height += aux_info->height; - extra_height = -1; - } else - requisition->height += hsb_requisition.height; - } - } - - if (priv->hsb_policy == GTK_POLICY_AUTOMATIC || GTK_WIDGET_VISIBLE (priv->hsb)) { - requisition->width = MAX (requisition->width, hsb_requisition.width); - if (!extra_height || GTK_WIDGET_VISIBLE (priv->hsb)) - extra_height = priv->sb_spacing + hsb_requisition.height; - } - - if (priv->vsb_policy == GTK_POLICY_AUTOMATIC || GTK_WIDGET_VISIBLE (priv->vsb)) { - requisition->height = MAX (requisition->height, vsb_requisition.height); - if (!extra_width || GTK_WIDGET_VISIBLE (priv->vsb)) - extra_width = priv->sb_spacing + vsb_requisition.width; - } - - requisition->width += MAX (0, extra_width); - requisition->height += MAX (0, extra_height); -} - -/* Computes the relative allocation for the scroll frame widget */ -static void -compute_relative_allocation (GtkWidget *widget, GtkAllocation *allocation) -{ - EScrollFrame *sf; - ScrollFramePrivate *priv; - - g_assert (widget != NULL); - g_assert (E_IS_SCROLL_FRAME (widget)); - g_assert (allocation != NULL); - - sf = E_SCROLL_FRAME (widget); - priv = sf->priv; - - allocation->x = GTK_CONTAINER (widget)->border_width; - allocation->y = GTK_CONTAINER (widget)->border_width; - allocation->width = MAX (1, ((gint)widget->allocation.width) - (gint) allocation->x * 2); - allocation->height = MAX (1, ((gint)widget->allocation.height) - (gint) allocation->y * 2); - - if (priv->vsb_visible) { - GtkRequisition vsb_requisition; - - gtk_widget_get_child_requisition (priv->vsb, &vsb_requisition); - - if (priv->frame_placement == GTK_CORNER_TOP_RIGHT - || priv->frame_placement == GTK_CORNER_BOTTOM_RIGHT) - allocation->x += vsb_requisition.width + priv->sb_spacing; - - allocation->width = MAX (1, ((gint) allocation->width) - - (gint) (vsb_requisition.width + priv->sb_spacing)); - } - - if (priv->hsb_visible) { - GtkRequisition hsb_requisition; - - gtk_widget_get_child_requisition (priv->hsb, &hsb_requisition); - - if (priv->frame_placement == GTK_CORNER_BOTTOM_LEFT - || priv->frame_placement == GTK_CORNER_BOTTOM_RIGHT) - allocation->y += hsb_requisition.height + priv->sb_spacing; - - allocation->height = MAX (1, ((gint) allocation->height) - - (gint) (hsb_requisition.height + priv->sb_spacing)); - } -} - -/* Size_allocate handler for the scroll frame widget */ -static void -e_scroll_frame_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - EScrollFrame *sf; - ScrollFramePrivate *priv; - GtkBin *bin; - GtkAllocation relative_allocation; - GtkAllocation child_allocation; - gint xthickness, ythickness; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_SCROLL_FRAME (widget)); - g_return_if_fail (allocation != NULL); - - sf = E_SCROLL_FRAME (widget); - priv = sf->priv; - bin = GTK_BIN (widget); - - widget->allocation = *allocation; - - if (priv->hsb_policy == GTK_POLICY_ALWAYS) - priv->hsb_visible = TRUE; - else if (priv->hsb_policy == GTK_POLICY_NEVER) - priv->hsb_visible = FALSE; - - if (priv->vsb_policy == GTK_POLICY_ALWAYS) - priv->vsb_visible = TRUE; - else if (priv->vsb_policy == GTK_POLICY_NEVER) - priv->vsb_visible = FALSE; - - if (priv->shadow_type == GTK_SHADOW_NONE) { - xthickness = 0; - ythickness = 0; - } else { - xthickness = widget->style->klass->xthickness; - ythickness = widget->style->klass->ythickness; - } - - if (bin->child && GTK_WIDGET_VISIBLE (bin->child)) { - gboolean previous_hvis; - gboolean previous_vvis; - guint count = 0; - - do { - compute_relative_allocation (widget, &relative_allocation); - - priv->frame_x = relative_allocation.x + allocation->x; - priv->frame_y = relative_allocation.y + allocation->y; - priv->frame_w = relative_allocation.width; - priv->frame_h = relative_allocation.height; - - child_allocation.x = priv->frame_x + xthickness; - child_allocation.y = priv->frame_y + ythickness; - child_allocation.width = MAX ((gint)priv->frame_w - 2 * xthickness, 0); - child_allocation.height = MAX ((gint)priv->frame_h - 2 * ythickness, 0); - - previous_hvis = priv->hsb_visible; - previous_vvis = priv->vsb_visible; - - gtk_widget_size_allocate (bin->child, &child_allocation); - - /* If, after the first iteration, the hscrollbar and the - * vscrollbar flip visiblity, then we need both. - */ - if (count - && previous_hvis != priv->hsb_visible - && previous_vvis != priv->vsb_visible) { - priv->hsb_visible = TRUE; - priv->vsb_visible = TRUE; - - /* a new resize is already queued at this point, - * so we will immediatedly get reinvoked - */ - return; - } - - count++; - } while (previous_hvis != priv->hsb_visible - || previous_vvis != priv->vsb_visible); - } else - compute_relative_allocation (widget, &relative_allocation); - - if (priv->hsb_visible) { - GtkRequisition hscrollbar_requisition; - - gtk_widget_get_child_requisition (priv->hsb, &hscrollbar_requisition); - - if (!GTK_WIDGET_VISIBLE (priv->hsb)) - gtk_widget_show (priv->hsb); - - child_allocation.x = relative_allocation.x; - if (priv->frame_placement == GTK_CORNER_TOP_LEFT - || priv->frame_placement == GTK_CORNER_TOP_RIGHT) - child_allocation.y = (relative_allocation.y - + relative_allocation.height - + priv->sb_spacing); - else - child_allocation.y = GTK_CONTAINER (sf)->border_width; - - child_allocation.width = relative_allocation.width; - child_allocation.height = hscrollbar_requisition.height; - child_allocation.x += allocation->x; - child_allocation.y += allocation->y; - - gtk_widget_size_allocate (priv->hsb, &child_allocation); - } else if (GTK_WIDGET_VISIBLE (priv->hsb)) - gtk_widget_hide (priv->hsb); - - if (priv->vsb_visible) { - GtkRequisition vscrollbar_requisition; - - if (!GTK_WIDGET_VISIBLE (priv->vsb)) - gtk_widget_show (priv->vsb); - - gtk_widget_get_child_requisition (priv->vsb, &vscrollbar_requisition); - - if (priv->frame_placement == GTK_CORNER_TOP_LEFT - || priv->frame_placement == GTK_CORNER_BOTTOM_LEFT) - child_allocation.x = (relative_allocation.x - + relative_allocation.width - + priv->sb_spacing); - else - child_allocation.x = GTK_CONTAINER (sf)->border_width; - - child_allocation.y = relative_allocation.y; - child_allocation.width = vscrollbar_requisition.width; - child_allocation.height = relative_allocation.height; - child_allocation.x += allocation->x; - child_allocation.y += allocation->y; - - gtk_widget_size_allocate (priv->vsb, &child_allocation); - } else if (GTK_WIDGET_VISIBLE (priv->vsb)) - gtk_widget_hide (priv->vsb); -} - -/* Button press handler for the scroll framw diget */ -static gint -e_scroll_frame_button_press (GtkWidget *widget, GdkEventButton *event) -{ - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_SCROLL_FRAME (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - /* This is to handle mouse wheel scrolling */ - if (event->button == 4 || event->button == 5) { - GtkAdjustment *adj; - gfloat new_value; - - gtk_object_get (GTK_OBJECT (widget), - (event->state & GDK_CONTROL_MASK) ? - "hadjustment" : "vadjustment", - &adj, - NULL); - new_value = adj->value + ((event->button == 4) ? - -adj->page_increment / 2: - adj->page_increment / 2); - new_value = CLAMP (new_value, adj->lower, adj->upper - adj->page_size); - gtk_adjustment_set_value (adj, new_value); - - return TRUE; - } - - return FALSE; -} - -/* Expose handler for the scroll frame widget */ -static gint -e_scroll_frame_expose (GtkWidget *widget, GdkEventExpose *event) -{ - EScrollFrame *sf; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_SCROLL_FRAME (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - sf = E_SCROLL_FRAME (widget); - - if (GTK_WIDGET_DRAWABLE (widget)) - draw_shadow (sf, &event->area); - - if (GTK_WIDGET_CLASS (parent_class)->expose_event) - (* GTK_WIDGET_CLASS (parent_class)->expose_event) (widget, event); - - return FALSE; -} - -/* Add handler for the scroll frame widget */ -static void -e_scroll_frame_add (GtkContainer *container, GtkWidget *child) -{ - EScrollFrame *sf; - ScrollFramePrivate *priv; - GtkBin *bin; - - sf = E_SCROLL_FRAME (container); - priv = sf->priv; - bin = GTK_BIN (container); - g_return_if_fail (bin->child == NULL); - - bin->child = child; - gtk_widget_set_parent (child, GTK_WIDGET (bin)); - - /* this is a temporary message */ - if (!gtk_widget_set_scroll_adjustments (child, - gtk_range_get_adjustment (GTK_RANGE (priv->hsb)), - gtk_range_get_adjustment (GTK_RANGE (priv->vsb)))) -#if 0 - g_warning ("e_scroll_frame_add(): cannot add non scrollable widget " - "use e_scroll_frame_add_with_viewport() instead"); -#else - ; -#endif - - if (GTK_WIDGET_REALIZED (child->parent)) - gtk_widget_realize (child); - - if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child)) { - if (GTK_WIDGET_MAPPED (child->parent)) - gtk_widget_map (child); - - gtk_widget_queue_resize (child); - } -} - -/* Remove method for the scroll frame widget */ -static void -e_scroll_frame_remove (GtkContainer *container, GtkWidget *child) -{ - g_return_if_fail (container != NULL); - g_return_if_fail (E_IS_SCROLL_FRAME (container)); - g_return_if_fail (child != NULL); - g_return_if_fail (GTK_BIN (container)->child == child); - - gtk_widget_set_scroll_adjustments (child, NULL, NULL); - - /* chain parent class handler to remove child */ - if (GTK_CONTAINER_CLASS (parent_class)->remove) - (* GTK_CONTAINER_CLASS (parent_class)->remove) (container, child); -} - -/** - * e_scroll_frame_new: - * @hadj: If non-NULL, the adjustment to use for horizontal scrolling. - * @vadj: If non-NULL, the adjustment to use for vertical scrolling. - * - * Creates a new scroll frame widget. - * - * Return value: The newly-created scroll frame widget. - **/ -GtkWidget * -e_scroll_frame_new (GtkAdjustment *hadj, GtkAdjustment *vadj) -{ - if (hadj) - g_return_val_if_fail (GTK_IS_ADJUSTMENT (hadj), NULL); - - if (vadj) - g_return_val_if_fail (GTK_IS_ADJUSTMENT (vadj), NULL); - - return gtk_widget_new (E_TYPE_SCROLL_FRAME, - "hadjustment", hadj, - "vadjustment", vadj, - NULL); -} - -/* Callback used when one of the scroll frame widget's adjustments changes */ -static void -adjustment_changed (GtkAdjustment *adj, gpointer data) -{ - EScrollFrame *sf; - ScrollFramePrivate *priv; - - g_return_if_fail (adj != NULL); - g_return_if_fail (GTK_IS_ADJUSTMENT (adj)); - g_return_if_fail (data != NULL); - - sf = E_SCROLL_FRAME (data); - priv = sf->priv; - - if (adj == gtk_range_get_adjustment (GTK_RANGE (priv->hsb))) { - if (priv->hsb_policy == GTK_POLICY_AUTOMATIC) { - gboolean visible; - - visible = priv->hsb_visible; - priv->hsb_visible = (adj->upper - adj->lower > adj->page_size); - if (priv->hsb_visible != visible) - gtk_widget_queue_resize (GTK_WIDGET (sf)); - } - } else if (adj == gtk_range_get_adjustment (GTK_RANGE (priv->vsb))) { - if (priv->vsb_policy == GTK_POLICY_AUTOMATIC) { - gboolean visible; - - visible = priv->vsb_visible; - priv->vsb_visible = (adj->upper - adj->lower > adj->page_size); - if (priv->vsb_visible != visible) - gtk_widget_queue_resize (GTK_WIDGET (sf)); - } - } -} - -/** - * e_scroll_frame_set_hadjustment: - * @sf: A scroll frame widget. - * @adj: An adjustment. - * - * Sets the adjustment to be used for horizontal scrolling in a scroll frame - * widget. - **/ -void -e_scroll_frame_set_hadjustment (EScrollFrame *sf, GtkAdjustment *adj) -{ - ScrollFramePrivate *priv; - - g_return_if_fail (sf != NULL); - g_return_if_fail (E_IS_SCROLL_FRAME (sf)); - - priv = sf->priv; - - if (adj) - g_return_if_fail (GTK_IS_ADJUSTMENT (adj)); - else - adj = GTK_ADJUSTMENT (gtk_object_new (GTK_TYPE_ADJUSTMENT, NULL)); - - if (!priv->hsb) { - gtk_widget_push_composite_child (); - priv->hsb = gtk_hscrollbar_new (adj); - gtk_widget_set_composite_name (priv->hsb, "hscrollbar"); - gtk_widget_pop_composite_child (); - - gtk_widget_set_parent (priv->hsb, GTK_WIDGET (sf)); - gtk_widget_ref (priv->hsb); - gtk_widget_show (priv->hsb); - } else { - GtkAdjustment *old_adj; - - old_adj = gtk_range_get_adjustment (GTK_RANGE (priv->hsb)); - if (old_adj == adj) - return; - - gtk_signal_disconnect_by_func (GTK_OBJECT (old_adj), - GTK_SIGNAL_FUNC (adjustment_changed), - sf); - gtk_range_set_adjustment (GTK_RANGE (priv->hsb), adj); - } - - adj = gtk_range_get_adjustment (GTK_RANGE (priv->hsb)); - gtk_signal_connect (GTK_OBJECT (adj), - "changed", - GTK_SIGNAL_FUNC (adjustment_changed), - sf); - adjustment_changed (adj, sf); - - if (GTK_BIN (sf)->child) - gtk_widget_set_scroll_adjustments ( - GTK_BIN (sf)->child, - gtk_range_get_adjustment (GTK_RANGE (priv->hsb)), - gtk_range_get_adjustment (GTK_RANGE (priv->vsb))); -} - -/** - * e_scroll_frame_set_vadjustment: - * @sf: A scroll frame widget. - * @adj: An adjustment. - * - * Sets the adjustment to be used for vertical scrolling in a scroll frame - * widget. - **/ -void -e_scroll_frame_set_vadjustment (EScrollFrame *sf, GtkAdjustment *adj) -{ - ScrollFramePrivate *priv; - - g_return_if_fail (sf != NULL); - g_return_if_fail (E_IS_SCROLL_FRAME (sf)); - - priv = sf->priv; - - if (adj) - g_return_if_fail (GTK_IS_ADJUSTMENT (adj)); - else - adj = GTK_ADJUSTMENT (gtk_object_new (GTK_TYPE_ADJUSTMENT, NULL)); - - if (!priv->vsb) { - gtk_widget_push_composite_child (); - priv->vsb = gtk_vscrollbar_new (adj); - gtk_widget_set_composite_name (priv->vsb, "vscrollbar"); - gtk_widget_pop_composite_child (); - - gtk_widget_set_parent (priv->vsb, GTK_WIDGET (sf)); - gtk_widget_ref (priv->vsb); - gtk_widget_show (priv->vsb); - } else { - GtkAdjustment *old_adj; - - old_adj = gtk_range_get_adjustment (GTK_RANGE (priv->vsb)); - if (old_adj == adj) - return; - - gtk_signal_disconnect_by_func (GTK_OBJECT (old_adj), - GTK_SIGNAL_FUNC (adjustment_changed), - sf); - gtk_range_set_adjustment (GTK_RANGE (priv->vsb), adj); - } - - adj = gtk_range_get_adjustment (GTK_RANGE (priv->vsb)); - gtk_signal_connect (GTK_OBJECT (adj), - "changed", - GTK_SIGNAL_FUNC (adjustment_changed), - sf); - adjustment_changed (adj, sf); - - if (GTK_BIN (sf)->child) - gtk_widget_set_scroll_adjustments ( - GTK_BIN (sf)->child, - gtk_range_get_adjustment (GTK_RANGE (priv->hsb)), - gtk_range_get_adjustment (GTK_RANGE (priv->vsb))); -} - -/** - * e_scroll_frame_get_hadjustment: - * @sf: A scroll frame widget. - * - * Queries the horizontal adjustment of a scroll frame widget. - * - * Return value: The horizontal adjustment of the scroll frame, or NULL if none. - **/ -GtkAdjustment * -e_scroll_frame_get_hadjustment (EScrollFrame *sf) -{ - ScrollFramePrivate *priv; - - g_return_val_if_fail (sf != NULL, NULL); - g_return_val_if_fail (E_IS_SCROLL_FRAME (sf), NULL); - - priv = sf->priv; - - return priv->hsb ? gtk_range_get_adjustment (GTK_RANGE (priv->hsb)) : NULL; -} - -/** - * e_scroll_frame_get_vadjustment: - * @sf: A scroll frame widget. - * - * Queries the vertical adjustment of a scroll frame widget. - * - * Return value: The vertical adjustment of the scroll frame, or NULL if none. - **/ -GtkAdjustment * -e_scroll_frame_get_vadjustment (EScrollFrame *sf) -{ - ScrollFramePrivate *priv; - - g_return_val_if_fail (sf != NULL, NULL); - g_return_val_if_fail (E_IS_SCROLL_FRAME (sf), NULL); - - priv = sf->priv; - - return priv->vsb ? gtk_range_get_adjustment (GTK_RANGE (priv->vsb)) : NULL; -} - -/** - * e_scroll_frame_set_policy: - * @sf: A scroll frame widget. - * @hsb_policy: Policy for the horizontal scrollbar. - * @vsb_policy: Policy for the vertical scrollbar. - * - * Sets the scrollbar policies of a scroll frame widget. These determine when - * the scrollbars are to be shown or hidden. - **/ -void -e_scroll_frame_set_policy (EScrollFrame *sf, - GtkPolicyType hsb_policy, - GtkPolicyType vsb_policy) -{ - ScrollFramePrivate *priv; - - g_return_if_fail (sf != NULL); - g_return_if_fail (E_IS_SCROLL_FRAME (sf)); - - priv = sf->priv; - - if (priv->hsb_policy == hsb_policy && priv->vsb_policy == vsb_policy) - return; - - priv->hsb_policy = hsb_policy; - priv->vsb_policy = vsb_policy; - - gtk_widget_queue_resize (GTK_WIDGET (sf)); -} - -/** - * e_scroll_frame_set_placement: - * @sf: A scroll frame widget. - * @frame_placement: Placement for the frame. - * - * Sets the placement of a scroll frame widget's frame with respect to its - * scrollbars. - **/ -void -e_scroll_frame_set_placement (EScrollFrame *sf, GtkCornerType frame_placement) -{ - ScrollFramePrivate *priv; - - g_return_if_fail (sf != NULL); - g_return_if_fail (E_IS_SCROLL_FRAME (sf)); - - priv = sf->priv; - - if (priv->frame_placement == frame_placement) - return; - - priv->frame_placement = frame_placement; - gtk_widget_queue_resize (GTK_WIDGET (sf)); -} - -/** - * e_scroll_frame_set_shadow_type: - * @sf: A scroll frame widget. - * @shadow_type: A shadow type. - * - * Sets the shadow type of a scroll frame widget. You can use this when you - * insert a child that does not paint a frame on its own. - **/ -void -e_scroll_frame_set_shadow_type (EScrollFrame *sf, GtkShadowType shadow_type) -{ - ScrollFramePrivate *priv; - - g_return_if_fail (sf != NULL); - g_return_if_fail (E_IS_SCROLL_FRAME (sf)); - g_return_if_fail (shadow_type >= GTK_SHADOW_NONE && shadow_type <= GTK_SHADOW_ETCHED_OUT); - - priv = sf->priv; - - if (priv->shadow_type == shadow_type) - return; - - priv->shadow_type = shadow_type; - gtk_widget_queue_resize (GTK_WIDGET (sf)); -} - -/** - * e_scroll_frame_set_scrollbar_spacing: - * @sf: A scroll frame widget. - * @spacing: Desired spacing in pixels. - * - * Sets the spacing between the frame and the scrollbars of a scroll frame - * widget. - **/ -void -e_scroll_frame_set_scrollbar_spacing (EScrollFrame *sf, guint spacing) -{ - ScrollFramePrivate *priv; - - g_return_if_fail (sf != NULL); - g_return_if_fail (E_IS_SCROLL_FRAME (sf)); - - priv = sf->priv; - - if (priv->sb_spacing == spacing) - return; - - priv->sb_spacing = spacing; - gtk_widget_queue_resize (GTK_WIDGET (sf)); -} - -/** - * e_scroll_frame_add_with_viewport: - * @sf: A scroll frame widget. - * @child: A widget. - * - * Creates a #GtkViewport and puts the specified child inside it, thus allowing - * the viewport to be scrolled by the scroll frame widget. This is meant to be - * used only when a child does not support the scrolling interface. - **/ -void -e_scroll_frame_add_with_viewport (EScrollFrame *sf, GtkWidget *child) -{ - ScrollFramePrivate *priv; - GtkBin *bin; - GtkWidget *viewport; - - g_return_if_fail (sf != NULL); - g_return_if_fail (E_IS_SCROLL_FRAME (sf)); - g_return_if_fail (child != NULL); - g_return_if_fail (GTK_IS_WIDGET (child)); - g_return_if_fail (child->parent == NULL); - - priv = sf->priv; - bin = GTK_BIN (sf); - - if (bin->child != NULL) { - g_return_if_fail (GTK_IS_VIEWPORT (bin->child)); - g_return_if_fail (GTK_BIN (bin->child)->child == NULL); - - viewport = bin->child; - } else { - viewport = gtk_viewport_new (e_scroll_frame_get_hadjustment (sf), - e_scroll_frame_get_vadjustment (sf)); - gtk_container_add (GTK_CONTAINER (sf), viewport); - } - - gtk_widget_show (viewport); - gtk_container_add (GTK_CONTAINER (viewport), child); -} diff --git a/widgets/misc/e-scroll-frame.h b/widgets/misc/e-scroll-frame.h deleted file mode 100644 index 4bdeee3e1d..0000000000 --- a/widgets/misc/e-scroll-frame.h +++ /dev/null @@ -1,95 +0,0 @@ -/* GTK - The GIMP Toolkit - * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald - * - * 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -/* EScrollFrame based on GtkScrolledWindow. - * - * Modifications by Federico Mena <federico@helixcode.com> - */ - -#ifndef __E_SCROLL_FRAME_H__ -#define __E_SCROLL_FRAME_H__ - - -#include <gdk/gdk.h> -#include <gtk/gtkbin.h> - - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define E_TYPE_SCROLL_FRAME (e_scroll_frame_get_type ()) -#define E_SCROLL_FRAME(obj) (GTK_CHECK_CAST ((obj), E_TYPE_SCROLL_FRAME, EScrollFrame)) -#define E_SCROLL_FRAME_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_SCROLL_FRAME, \ - EScrollFrameClass)) -#define E_IS_SCROLL_FRAME(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_SCROLL_FRAME)) -#define E_IS_SCROLL_FRAME_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_SCROLL_FRAME)) - - -typedef struct _EScrollFrame EScrollFrame; -typedef struct _EScrollFrameClass EScrollFrameClass; - -struct _EScrollFrame -{ - GtkBin bin; - - /* Private data */ - gpointer priv; -}; - -struct _EScrollFrameClass -{ - GtkBinClass parent_class; -}; - - -GtkType e_scroll_frame_get_type (void); -GtkWidget *e_scroll_frame_new (GtkAdjustment *hadj, GtkAdjustment *vadj); - -void e_scroll_frame_set_hadjustment (EScrollFrame *sf, GtkAdjustment *adj); -void e_scroll_frame_set_vadjustment (EScrollFrame *sf, GtkAdjustment *adj); - -GtkAdjustment *e_scroll_frame_get_hadjustment (EScrollFrame *sf); -GtkAdjustment *e_scroll_frame_get_vadjustment (EScrollFrame *sf); - -void e_scroll_frame_set_policy (EScrollFrame *sf, - GtkPolicyType hsb_policy, - GtkPolicyType vsb_policy); - -void e_scroll_frame_set_placement (EScrollFrame *sf, GtkCornerType frame_placement); -void e_scroll_frame_set_shadow_type (EScrollFrame *sf, GtkShadowType shadow_type); -void e_scroll_frame_set_scrollbar_spacing (EScrollFrame *sf, guint spacing); - -void e_scroll_frame_add_with_viewport (EScrollFrame *sf, GtkWidget *child); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_SCROLL_FRAME_H__ */ diff --git a/widgets/misc/e-title-bar.c b/widgets/misc/e-title-bar.c deleted file mode 100644 index 30c4a42c88..0000000000 --- a/widgets/misc/e-title-bar.c +++ /dev/null @@ -1,271 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-title-bar.c - * - * Copyright (C) 2000 Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Ettore Perazzoli - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtkbox.h> -#include <gtk/gtkbutton.h> -#include <gtk/gtkhbox.h> -#include <gtk/gtklabel.h> -#include <gtk/gtkpixmap.h> -#include <gtk/gtksignal.h> -#include <gtk/gtktypeutils.h> - -#include "e-util/e-util.h" -#include "e-clipped-label.h" - -#include "e-title-bar.h" - - -enum { - TITLE_BUTTON_PRESS_EVENT, - CLOSE_BUTTON_CLICKED, - LAST_SIGNAL -}; -static guint signals[LAST_SIGNAL] = { 0 }; - - -static char *close_button_xpm[] = { - "12 12 2 1", - " c none", - ". c #000000000000", - " ", - " .. .. ", - " ... ... ", - " ... ... ", - " ...... ", - " .... ", - " .... ", - " ...... ", - " ... ... ", - " ... ... ", - " .. .. ", - " " -}; - -#define PARENT_TYPE GTK_TYPE_FRAME -static GtkFrameClass *parent_class = NULL; - -struct _ETitleBarPrivate { - GtkWidget *label; - GtkWidget *close_button; - GtkWidget *close_button_gtk_pixmap; -}; - - -/* Child signal callbacks. */ - -static void -close_button_realize_cb (GtkWidget *widget, - gpointer data) -{ - GdkPixmap *close_button_pixmap; - GdkBitmap *close_button_mask; - ETitleBar *title_bar; - ETitleBarPrivate *priv; - - title_bar = E_TITLE_BAR (data); - priv = title_bar->priv; - - if (priv->close_button_gtk_pixmap != NULL) - return; - - close_button_pixmap = gdk_pixmap_create_from_xpm_d (GTK_WIDGET (priv->close_button)->window, - &close_button_mask, - NULL, close_button_xpm); - priv->close_button_gtk_pixmap = gtk_pixmap_new (close_button_pixmap, close_button_mask); - - gtk_container_add (GTK_CONTAINER (priv->close_button), priv->close_button_gtk_pixmap); - gtk_widget_show (priv->close_button_gtk_pixmap); - - gdk_pixmap_unref (close_button_pixmap); - gdk_bitmap_unref (close_button_mask); -} - -static void -close_button_clicked_cb (GtkButton *button, - gpointer data) -{ - ETitleBar *title_bar; - - title_bar = E_TITLE_BAR (data); - - gtk_signal_emit (GTK_OBJECT (title_bar), signals[CLOSE_BUTTON_CLICKED]); -} - -static void -label_button_press_event_cb (GtkWidget *widget, - GdkEventButton *event, - gpointer data) -{ - ETitleBar *title_bar; - - title_bar = E_TITLE_BAR (data); - - gtk_signal_emit (GTK_OBJECT (title_bar), signals[TITLE_BUTTON_PRESS_EVENT], event); -} - - -/* GtkObject methods. */ - -static void -destroy (GtkObject *object) -{ - ETitleBar *title_bar; - ETitleBarPrivate *priv; - - title_bar = E_TITLE_BAR (object); - priv = title_bar->priv; - - g_free (priv); - - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - - -static void -class_init (ETitleBarClass *klass) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass*) klass; - object_class->destroy = destroy; - - parent_class = gtk_type_class (gtk_frame_get_type ()); - - signals[TITLE_BUTTON_PRESS_EVENT] = - gtk_signal_new ("title_button_press_event", - GTK_RUN_FIRST, - object_class->type, - GTK_SIGNAL_OFFSET (ETitleBarClass, title_button_press_event), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, - GTK_TYPE_GDK_EVENT); - - signals[CLOSE_BUTTON_CLICKED] = - gtk_signal_new ("close_button_clicked", - GTK_RUN_FIRST, - object_class->type, - GTK_SIGNAL_OFFSET (ETitleBarClass, close_button_clicked), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); -} - -static void -init (ETitleBar *title_bar) -{ - ETitleBarPrivate *priv; - - priv = g_new (ETitleBarPrivate, 1); - - priv->label = NULL; - priv->close_button = NULL; - priv->close_button_gtk_pixmap = NULL; - - title_bar->priv = priv; -} - - -void -e_title_bar_construct (ETitleBar *title_bar, - const char *title) -{ - ETitleBarPrivate *priv; - GtkWidget *hbox; - - g_return_if_fail (title_bar != NULL); - g_return_if_fail (E_IS_TITLE_BAR (title_bar)); - - priv = title_bar->priv; - - priv->label = e_clipped_label_new (title); - gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.5); - gtk_widget_show (priv->label); - - priv->close_button = gtk_button_new (); - GTK_WIDGET_UNSET_FLAGS (priv->close_button, GTK_CAN_FOCUS); - gtk_container_set_border_width (GTK_CONTAINER (priv->close_button), 1); - gtk_button_set_relief (GTK_BUTTON (priv->close_button), GTK_RELIEF_NONE); - gtk_widget_show (priv->close_button); - - hbox = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), priv->label, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (hbox), priv->close_button, FALSE, TRUE, 1); - gtk_widget_show (hbox); - - gtk_container_add (GTK_CONTAINER (title_bar), hbox); - - gtk_signal_connect (GTK_OBJECT (priv->close_button), "realize", - GTK_SIGNAL_FUNC (close_button_realize_cb), title_bar); - gtk_signal_connect (GTK_OBJECT (priv->close_button), "clicked", - GTK_SIGNAL_FUNC (close_button_clicked_cb), title_bar); - gtk_signal_connect (GTK_OBJECT (priv->label), "button_press_event", - GTK_SIGNAL_FUNC (label_button_press_event_cb), title_bar); -} - -GtkWidget * -e_title_bar_new (const char *title) -{ - ETitleBar *title_bar; - - title_bar = gtk_type_new (e_title_bar_get_type ()); - - e_title_bar_construct (title_bar, title); - - return GTK_WIDGET (title_bar); -} - - -void -e_title_bar_set_title (ETitleBar *title_bar, - const char *title) -{ - g_return_if_fail (title_bar != NULL); - g_return_if_fail (E_IS_TITLE_BAR (title_bar)); - - e_clipped_label_set_text (E_CLIPPED_LABEL (title_bar->priv->label), title); -} - -void -e_title_bar_show_close_button (ETitleBar *title_bar, - gboolean show) -{ - ETitleBarPrivate *priv; - - g_return_if_fail (title_bar != NULL); - g_return_if_fail (E_IS_TITLE_BAR (title_bar)); - - priv = title_bar->priv; - - if (show) - gtk_widget_show (priv->close_button); - else - gtk_widget_hide (priv->close_button); -} - - -E_MAKE_TYPE (e_title_bar, "ETitleBar", ETitleBar, class_init, init, PARENT_TYPE) diff --git a/widgets/misc/e-title-bar.h b/widgets/misc/e-title-bar.h deleted file mode 100644 index ce7d23b07b..0000000000 --- a/widgets/misc/e-title-bar.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-title-bar.h - * - * Copyright (C) 2000 Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Ettore Perazzoli - */ - -#ifndef __E_TITLE_BAR_H__ -#define __E_TITLE_BAR_H__ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtkframe.h> - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -#define E_TYPE_TITLE_BAR (e_title_bar_get_type ()) -#define E_TITLE_BAR(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TITLE_BAR, ETitleBar)) -#define E_TITLE_BAR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TITLE_BAR, ETitleBarClass)) -#define E_IS_TITLE_BAR(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TITLE_BAR)) -#define E_IS_TITLE_BAR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TYPE_TITLE_BAR)) - - -typedef struct _ETitleBar ETitleBar; -typedef struct _ETitleBarPrivate ETitleBarPrivate; -typedef struct _ETitleBarClass ETitleBarClass; - -struct _ETitleBar { - GtkFrame parent; - - ETitleBarPrivate *priv; -}; - -struct _ETitleBarClass { - GtkFrameClass parent_class; - - /* Signals. */ - - void (* title_button_press_event) (ETitleBar *title_bar, GdkEventButton *event); - void (* close_button_clicked) (ETitleBar *title_bar); -}; - - -GtkType e_title_bar_get_type (void); -void e_title_bar_construct (ETitleBar *title_bar, - const char *title); -GtkWidget *e_title_bar_new (const char *title); - -void e_title_bar_set_title (ETitleBar *title_bar, - const char *title); -void e_title_bar_show_close_button (ETitleBar *title_bar, - gboolean show); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __E_TITLE_BAR_H__ */ diff --git a/widgets/misc/pixmaps/cursor_cross.xpm b/widgets/misc/pixmaps/cursor_cross.xpm deleted file mode 100644 index cf9d0aca33..0000000000 --- a/widgets/misc/pixmaps/cursor_cross.xpm +++ /dev/null @@ -1,38 +0,0 @@ -/* XPM */ -static char * cursor_cross_xpm[] = { -"32 32 3 1", -" c None", -". c #000000", -"+ c #FFFFFF", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ....... ", -" .+++++.. ", -" .+++++.. ", -" .+++++.. ", -" .+++++.. ", -" ......+++++...... ", -" .+++++++++++++++.. ", -" .+++++++++++++++.. ", -" .+++++++++++++++.. ", -" .+++++++++++++++.. ", -" .+++++++++++++++.. ", -" ......+++++....... ", -" .....+++++....... ", -" .+++++.. ", -" .+++++.. ", -" .+++++.. ", -" ........ ", -" ....... ", -" ", -" ", -" ", -" ", -" ", -" ", -" "}; diff --git a/widgets/misc/pixmaps/cursor_hand_closed.xpm b/widgets/misc/pixmaps/cursor_hand_closed.xpm deleted file mode 100644 index 61a6de4b88..0000000000 --- a/widgets/misc/pixmaps/cursor_hand_closed.xpm +++ /dev/null @@ -1,38 +0,0 @@ -/* XPM */ -static char * cursor_hand_closed_xpm[] = { -"32 32 3 1", -" c None", -". c #000000", -"+ c #FFFFFF", -" ", -" ", -" ", -" ", -" ", -" .. ", -" ..++... ", -" .+++++++.. ", -" .+++++++++. ", -" ...+++++++++. ", -" .++.+++++++++. ", -" .++++++++++++. ", -" .+++++++++++. ", -" .++++++++++. ", -" .+++++++++. ", -" .+++++++. ", -" .++++++. ", -" .++++++. ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" "}; diff --git a/widgets/misc/pixmaps/cursor_hand_open.xpm b/widgets/misc/pixmaps/cursor_hand_open.xpm deleted file mode 100644 index 048acc8054..0000000000 --- a/widgets/misc/pixmaps/cursor_hand_open.xpm +++ /dev/null @@ -1,38 +0,0 @@ -/* XPM */ -static char * cursor_hand_open_xpm[] = { -"32 32 3 1", -" c None", -". c #000000", -"+ c #FFFFFF", -" ", -" ", -" .. ", -" .. .++... ", -" .++..++.++. ", -" .++..++.++. . ", -" .++.++.++..+. ", -" .++.++.++.++. ", -" .. .+++++++.++. ", -" .++..++++++++++. ", -" .+++.+++++++++. ", -" .++++++++++++. ", -" .+++++++++++. ", -" .++++++++++. ", -" .+++++++++. ", -" .+++++++. ", -" .++++++. ", -" .++++++. ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" ", -" "}; diff --git a/widgets/misc/pixmaps/cursor_zoom_in.xpm b/widgets/misc/pixmaps/cursor_zoom_in.xpm deleted file mode 100644 index 1caf9e3e2a..0000000000 --- a/widgets/misc/pixmaps/cursor_zoom_in.xpm +++ /dev/null @@ -1,37 +0,0 @@ -/* XPM */ -static char * cursor_zoom_in_xpm[] = { -"32 32 2 1", -" c None", -". c #000000", -" ", -" ", -" ", -" ", -" ", -" ", -" ...... ", -" .. .. ", -" .. .. ", -" . . ", -" . ... . ", -" . ... . ", -" . ....... . ", -" . ....... . ", -" . ... . ", -" . ... .. ", -" .. . . ", -" .. . . . ", -" ........ . . ", -" ..... . . . ", -" . . . ", -" . . . ", -" . . . ", -" . . . ", -" . . ", -" . . ", -" .. ", -" ", -" ", -" ", -" ", -" "}; diff --git a/widgets/misc/pixmaps/cursor_zoom_out.xpm b/widgets/misc/pixmaps/cursor_zoom_out.xpm deleted file mode 100644 index af1b698521..0000000000 --- a/widgets/misc/pixmaps/cursor_zoom_out.xpm +++ /dev/null @@ -1,37 +0,0 @@ -/* XPM */ -static char * cursor_zoom_out_xpm[] = { -"32 32 2 1", -" c None", -". c #000000", -" ", -" ", -" ", -" ", -" ", -" ", -" ...... ", -" .. .. ", -" .. .. ", -" . . ", -" . . ", -" . . ", -" . ....... . ", -" . ....... . ", -" . . ", -" . .. ", -" .. . . ", -" .. . . . ", -" ........ . . ", -" ..... . . . ", -" . . . ", -" . . . ", -" . . . ", -" . . . ", -" . . ", -" . . ", -" .. ", -" ", -" ", -" ", -" ", -" "}; diff --git a/widgets/misc/test-calendar.c b/widgets/misc/test-calendar.c deleted file mode 100644 index 6463a21ce3..0000000000 --- a/widgets/misc/test-calendar.c +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 2000, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * test-calendar - tests the ECalendar widget. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gnome.h> - -#include "e-calendar.h" - -static void -delete_event_cb (GtkWidget *widget, - GdkEventAny *event, - gpointer data) -{ - gtk_main_quit (); -} - -int -main (int argc, char **argv) -{ - GtkWidget *app; - GtkWidget *cal; - GtkWidget *vbox; - - gnome_init ("test-calendar", "0.0", argc, argv); - - app = gnome_app_new ("Test", "Test"); - gtk_window_set_default_size (GTK_WINDOW (app), 400, 400); - gtk_window_set_policy (GTK_WINDOW (app), FALSE, TRUE, FALSE); - - gtk_signal_connect (GTK_OBJECT (app), "delete_event", - GTK_SIGNAL_FUNC (delete_event_cb), NULL); - - cal = e_calendar_new (); - gtk_widget_show (cal); - - vbox = gtk_vbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), cal, TRUE, TRUE, 0); - gtk_widget_show (vbox); - - gnome_app_set_contents (GNOME_APP (app), vbox); - gtk_widget_show (app); - - gtk_main (); - - return 0; -} diff --git a/widgets/misc/test-title-bar.c b/widgets/misc/test-title-bar.c deleted file mode 100644 index fdca1ae0db..0000000000 --- a/widgets/misc/test-title-bar.c +++ /dev/null @@ -1,73 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-title-bar.c - * - * Copyright (C) 2000 Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Ettore Perazzoli - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gnome.h> - -#include "e-title-bar.h" - -static void -delete_event_cb (GtkWidget *widget, - GdkEventAny *event, - gpointer data) -{ - gtk_main_quit (); -} - -int -main (int argc, char **argv) -{ - GtkWidget *app; - GtkWidget *title_bar; - GtkWidget *text; - GtkWidget *vbox; - - gnome_init ("test-title-bar", "0.0", argc, argv); - - app = gnome_app_new ("Test", "Test"); - gtk_window_set_default_size (GTK_WINDOW (app), 400, 400); - gtk_window_set_policy (GTK_WINDOW (app), FALSE, TRUE, FALSE); - - gtk_signal_connect (GTK_OBJECT (app), "delete_event", GTK_SIGNAL_FUNC (delete_event_cb), NULL); - - title_bar = e_title_bar_new ("This is a very annoyingly long title bar"); - gtk_widget_show (title_bar); - - text = gtk_text_new (NULL, NULL); - gtk_widget_show (text); - - vbox = gtk_vbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), title_bar, FALSE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (vbox), text, TRUE, TRUE, 0); - gtk_widget_show (vbox); - - gnome_app_set_contents (GNOME_APP (app), vbox); - gtk_widget_show (app); - - gtk_main (); - - return 0; -} diff --git a/widgets/shortcut-bar/.cvsignore b/widgets/shortcut-bar/.cvsignore deleted file mode 100644 index d59175edcd..0000000000 --- a/widgets/shortcut-bar/.cvsignore +++ /dev/null @@ -1,8 +0,0 @@ -*.o -libshortcut-bar.a -Makefile -Makefile.in -.deps -.libs -.pure -test-shortcut-bar diff --git a/widgets/shortcut-bar/ChangeLog b/widgets/shortcut-bar/ChangeLog deleted file mode 100644 index 3ca816c467..0000000000 --- a/widgets/shortcut-bar/ChangeLog +++ /dev/null @@ -1,276 +0,0 @@ -2000-08-16 Larry Ewing <lewing@helixcode.com> - - * e-icon-bar.c (e_icon_bar_init): remove COLOR_TEXT references. - -2000-08-16 Larry Ewing <lewing@helixcode.com> - - * e-icon-bar.h (enum): get rid of COLOR_TEXT. - (struct _EIconBarItem): add pixbuf member to hold unmodified - pixbuf. - - * e-icon-bar.c (e_icon_bar_style_set): update the image and the - colors based on the new style. - (e_icon_bar_add_item): store the full alpha pixbuf so that we can - update the background color if the style changes. Use the style - colors where appropriate. - (e_icon_bar_on_editing_stopped): revert to style colors. - (e_icon_bar_on_editing_started): use style fg instead of - COLOR_TEXT. - - * e-shortcut-bar.c (e_shortcut_bar_add_group): add an #ifndef - E_USE_STYLES around the call to e_shortcut_bar_set_canvas_style to - allow people to test out the style stuff that is in progress. - -2000-07-16 Damon Chaplin <damon@helixcode.com> - - * e-shortcut-model.[hc]: new files implementing a simple model for - the shortcuts, so we can have multiple views. - - * Makefile.am (libshortcut_bar_a_SOURCES): added e-shortcut-model.[hc] - - * e-shortcut-bar.h: updated to use the model. - - * e-icon-bar.c (e_icon_bar_item_pressed): set mouse_over_item_num as - well as pressed_item_num to fix bug. - -2000-07-10 Ettore Perazzoli <ettore@helixcode.com> - - * e-group-bar.c (e_group_bar_add): Set `group_bar'. - -2000-06-19 Damon Chaplin <damon@helixcode.com> - - * e-icon-bar-bg-item.c: - * e-icon-bar.c: - * e-icon-bar.h: - * e-vscrolled-bar.c: added support for scroll-wheels. - -2000-06-02 Christopher James Lahey <clahey@helixcode.com> - - * e-icon-bar.c: Free all the item data. - -2000-06-01 Ettore Perazzoli <ettore@helixcode.com> - - * e-shortcut-bar.c (e_shortcut_bar_get_view_type): New function. - -2000-05-25 Ettore Perazzoli <ettore@helixcode.com> - - * e-shortcut-bar.c (e_shortcut_bar_load_image): Leak plug: free - pathname returned from `gnome_pixmap_file()'. - - * Makefile.am: Add `-I$(top_srcdir)'. - -2000-05-24 Christopher James Lahey <clahey@helixcode.com> - - * Makefile.am: Added libepaned.a. - - * test-shortcut-bar.c: Switched from GtkPaned to EPaned. - -2000-05-18 Damon Chaplin <damon@helixcode.com> - - * e-shortcut-bar.[hc]: new signals "added_item", "removed_item", - "added_group", "removed_group". Note that the removed signals are - emitted just before the item/group is actually removed. - - * test-shortcut-bar.c: updated to test the new signals, and ref'ed - the pixbufs in the icon callback. - -2000-05-16 Ettore Perazzoli <ettore@helixcode.com> - - * e-clipped-label.c: Moved to $(top_srcdir)/widgets/misc. - * e-clipped-label.h: Likewise. - * Makefile.am: Updated accordingly. - -2000-05-07 Larry Ewing <lewing@helixcode.com> - - * e-icon-bar.h (struct _EIconBarItem): remove the no longer needed - flatened_alpha member. - - * e-icon-bar.c (flatten_alpha): using ~rgb can cause visual - artifacts. - (e_icon_bar_add_item): fixup refcounting of the flattend pixbuf, - the canvas item should hold the reference not us. Stop using - item.flattened_alpha since it no longer exists. - (e_icon_bar_remove_item): remove the unref since destroying the - item will take care of that for us. - - * e-shortcut-bar.c (e_shortcut_bar_add_item): make sure to unref - the image we get back, the icon bar will hold any references it - needs. - (e_shortcut_bar_get_image_from_url): ref the default image each - time we return it so that references are counted correctly. - -2000-05-04 Ettore Perazzoli <ettore@helixcode.com> - - * e-shortcut-bar.h (E_TYPE_SHORTCUT_BAR): New #define. - -2000-05-04 Ettore Perazzoli <ettore@helixcode.com> - - * e-icon-bar-bg-item.c (e_icon_bar_bg_item_draw): Initialize - `shadow' to placate compiler. - - * e-icon-bar.c (e_icon_bar_add_item): @text made const-safe. - - * e-shortcut-bar.c (e_shortcut_bar_add_group): @group_name made - const-safe. - (e_shortcut_bar_add_item): @item_url and @item_name made - const-safe. - (e_shortcut_bar_get_image_from_url): @item_url made const-safe. - (e_shortcut_bar_load_image): @filename made const-safe. - -2000-05-04 Ettore Perazzoli <ettore@helixcode.com> - - * test-shortcut-bar.c (icon_callback): Adapted to the new - `EShortcutBarIconCallback' typedef: get a @data parameter and get - a const-safe @url. - - * e-shortcut-bar.c (e_shortcut_bar_set_icon_callback): New param - @data. Set `icon_callback_data' to it. - (e_shortcut_bar_get_image_from_url): Pass the callback data to the - callback. - - * e-shortcut-bar.h: Changed `EShortcutBarIconCallback' to get a - const-safe @url parameter and a new @data parameter as a closure. - New member `data' in `EShortcutBar'. - -2000-05-02 Matt Loper <matt@helixcode.com> - - * Makefile.am: set G_LOG_DOMAIN. - -2000-04-16 Damon Chaplin <damon@helixcode.com> - - * test-shortcut-bar.c: added buttons to test moving/reordering groups. - - * e-shortcut-bar.c (e_shortcut_bar_on_drag_end): new function to free - the dragged name & URL when the drag is finished. - - * e-group-bar.c (e_group_bar_get_increment): fixed bug when distance - was 0. Should just return 0. - (e_group_bar_set_current_group_num): added animate option and finished. - (e_group_bar_unmap): called e_group_bar_stop_all_animation(). - (e_group_bar_reorder_group): finished. - - * e-icon-bar-text-item.[hc]: removed, since we now use EText. - -2000-04-15 Miguel de Icaza <miguel@gnu.org> - - * e-group-bar.c (e_group_bar_realize): Do not use the parent - thingie, because it might be like anything. And anything can be - like any visual, and we dont like want any visual here. - - * e-shortcut-bar.c - (e_shortcut_bar_add_group): Apply some loving action when it comes - to visuals and colormaps. Yes, we got one of those machines - --again--. Sigh. This is what you get when you have been away - from the Indy. The whole thing is breaking left and right. - - Hopefully, Gtk 1.4 fixes all of this, by always running in the - slowest visual it can find. - -2000-04-11 Larry Ewing <lewing@helixcode.com> - - * e-icon-bar.c (flatten_alpha): update for - new gdk-pixbuf. - -2000-03-31 Damon Chaplin <damon@helixcode.com> - - * e-shortcut-bar.[hc]: added support for a - callback function to set the icons. - - * test-shortcut-bar.c: updated to use the - callback function. - -2000-03-30 Dan Winship <danw@helixcode.com> - - * e-shortcut-bar.c: Sort of use the new - pixmaps. This code needs to be restructured, but Damon is - rumored to already be doing it. - -2000-03-27 Miguel de Icaza <miguel@gnu.org> - - * e-icon-bar.c (flatten_alpha): New function, - used to flatten the images we get and composite them with the - background. - (e_icon_bar_add_item): One happy tigert comming. - -2000-03-21 Christopher James Lahey <clahey@helixcode.com> - - * e-icon-bar.c: Updated to fix a few bugs. - -2000-02-28 NotZed <NotZed@HelixCode.com> - - * Makefile.am (test_shortcut_bar_LDADD): - Fixed references to eutil. - -2000-02-20 Damon Chaplin <damon@helixcode.com> - - * Makefile.am: added libetext.a and libeutil.a - to test_shortcut_bar_LDADD, and got rid of e-icon-bar-text-item.[hc]. - I'll delete these soon. - - * e-icon-bar.c: changed to be a subclass of - ECanvas and to use EText instead of EIconBarTextItem. Also set - "width_set" & "height_set" of the GnomeCanvasPixbuf items so they - work in the "Small Icon" view. - - * e-vscrolled-bar.c: use map/unmap instead of - show/hide for the up & down buttons to avoid queueing resizes. - Otherwise the scrolling starts off a bit jerky. - - * test-shortcut-bar.c: output a message when the - main label is resized, just for info. - - * *.[hc]: updated my email address. - -2000-02-07 Damon Chaplin <damon@helixcode.com> - - * e-group-bar.c (e_group_bar_draw): finished. - - * e-icon-bar.c (e_icon_bar_item_released): - check that an item was pressed. - -2000-01-26 bertrand <bertrand@helixcode.com> - - * e-icon-bar.c (e_icon_bar_recalc_item_positions): - don't set the x_set and y_set - arguments as don't exist in gdk-pixbuf - anymore. - -2000-01-17 Chrsitopher James Lahey <clahey@helixcode.com> - - * Makefile.am: Added gnomecanvaspixbuf to the - list of libraries used. - -2000-01-09 Miguel de Icaza <miguel@gnu.org> - - * e-icon-bar.c (e_icon_bar_init): Turn on anti-aliasing. - -2000-01-08 Miguel de Icaza <miguel@gnu.org> - - * e-icon-bar.c (e_icon_bar_add_item): Use - GdkPixbuf here. - (e_icon_bar_get_item_image): ditto and initialize image. - - * e-shortcut-bar.c (e_shortcut_bar_add_item): - Use gdk-pixbuf. - -2000-01-14 Christopher James Lahey <clahey@helixcode.com> - - * e-shortcut-bar.c (e_shortcut_bar_add_item): - Use e_bar_set_item_data. - - Drop item_url; Require image argument; Require user data - argument. - -2000-01-09 Miguel de Icaza <miguel@gnu.org> - - * e-icon-bar.c (e_icon_bar_init): Turn on anti-aliasing. - -2000-01-08 Miguel de Icaza <miguel@gnu.org> - - * e-icon-bar.c (e_icon_bar_add_item): Use - GdkPixbuf here. - (e_icon_bar_get_item_image): ditto and initialize image. - - * e-shortcut-bar.c (e_shortcut_bar_add_item): - Use gdk-pixbuf. - diff --git a/widgets/shortcut-bar/LICENSE b/widgets/shortcut-bar/LICENSE deleted file mode 100644 index f58649ad9b..0000000000 --- a/widgets/shortcut-bar/LICENSE +++ /dev/null @@ -1 +0,0 @@ -This code is licensed under the terms of the GNU GPL
\ No newline at end of file diff --git a/widgets/shortcut-bar/Makefile.am b/widgets/shortcut-bar/Makefile.am deleted file mode 100644 index 9f17d684b6..0000000000 --- a/widgets/shortcut-bar/Makefile.am +++ /dev/null @@ -1,38 +0,0 @@ - -noinst_LIBRARIES = libshortcut-bar.a -noinst_PROGRAMS = test-shortcut-bar - -INCLUDES = \ - -I$(top_srcdir) \ - -I$(top_srcdir)/widgets/misc \ - -DEVOLUTION_VERSION=\""$(VERSION)"\" \ - $(EXTRA_GNOME_CFLAGS) \ - -DG_LOG_DOMAIN=\"shortcut-bar\" - -libshortcut_bar_a_SOURCES = \ - e-group-bar.c \ - e-group-bar.h \ - e-icon-bar-bg-item.c \ - e-icon-bar-bg-item.h \ - e-icon-bar.c \ - e-icon-bar.h \ - e-shortcut-bar.c \ - e-shortcut-bar.h \ - e-shortcut-model.c \ - e-shortcut-model.h \ - e-vscrolled-bar.c \ - e-vscrolled-bar.h - -test_shortcut_bar_SOURCES = \ - test-shortcut-bar.c - -test_shortcut_bar_LDADD = \ - ./libshortcut-bar.a \ - $(top_builddir)/widgets/e-paned/libepaned.a \ - ../e-text/libetext.a \ - ../misc/libemiscwidgets.a \ - ../../e-util/libeutil.la \ - $(EXTRA_GNOME_LIBS) - -test_shortcut_bar_LDFLAGS = \ - `gnome-config --libs gdk_pixbuf gnomecanvaspixbuf` diff --git a/widgets/shortcut-bar/e-group-bar.c b/widgets/shortcut-bar/e-group-bar.c deleted file mode 100644 index dd78fe6243..0000000000 --- a/widgets/shortcut-bar/e-group-bar.c +++ /dev/null @@ -1,1546 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * EGroupBar displays a vertical bar with a number of Groups, which are viewed - * one at a time by selecting the Group's button. When a different Group is - * selected, it slides into view, and the old Group slides out. - * It is typically used on the left of the main application window so users - * can easily access particular features. - * - * It is implemented like GtkNotebook, i.e. the main widgets are the children - * of the EGroupBar and the button widgets are treated specially like the - * GtkNotebook tab labels. - */ - -#include <config.h> -#include <math.h> -#include <gnome.h> -#include "e-group-bar.h" - -#define E_GROUP_BAR_SCROLL_TIMEOUT 10 -#define E_GROUP_BAR_MIN_STEP_SIZE 4 - -#define E_GROUP_BAR_AUTO_SHOW_TIMEOUT 300 - - -static void e_group_bar_class_init (EGroupBarClass *class); -static void e_group_bar_init (EGroupBar *group_bar); -static void e_group_bar_destroy (GtkObject *object); -static void e_group_bar_realize (GtkWidget *widget); -static void e_group_bar_unrealize (GtkWidget *widget); -static void e_group_bar_map (GtkWidget *widget); -static void e_group_bar_unmap (GtkWidget *widget); -static void e_group_bar_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void e_group_bar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static gint e_group_bar_expose (GtkWidget *widget, - GdkEventExpose *event); -static void e_group_bar_draw (GtkWidget *widget, - GdkRectangle *area); -static void e_group_bar_add (GtkContainer *container, - GtkWidget *widget); -static void e_group_bar_remove (GtkContainer *container, - GtkWidget *widget); -static void e_group_bar_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); - -static void e_group_bar_create_group_button_window (EGroupBar *group_bar, - gint group_num); -static void e_group_bar_create_group_child_window (EGroupBar *group_bar, - gint group_num); -static gint e_group_bar_get_group_button_position (EGroupBar *group_bar, - gint group_num); -static gint e_group_bar_sum_button_heights (EGroupBar *group_bar, - gint first, - gint last); -static gint e_group_bar_get_child_height (EGroupBar *group_bar); -static gint e_group_bar_get_group_child_position (EGroupBar *group_bar, - gint group_num); - -static void e_group_bar_on_button_clicked (GtkWidget *group_button, - EGroupBar *group_bar); -static gint e_group_bar_find_button (EGroupBar *group_bar, - GtkWidget *group_button); -static void e_group_bar_start_animation (EGroupBar *group_bar, - gint group_num); -static gboolean e_group_bar_timeout_handler (gpointer data); -static gint e_group_bar_get_increment (EGroupBar *group_bar, - gint window_y, - gint window_target_y); -static gboolean e_group_bar_on_button_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - EGroupBar *group_bar); -static void e_group_bar_on_button_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time, - EGroupBar *group_bar); -static gboolean e_group_bar_auto_show (gpointer data); -static void e_group_bar_stop_all_animation (EGroupBar *group_bar); - - -static GtkContainerClass *parent_class; - - -GtkType -e_group_bar_get_type (void) -{ - static GtkType e_group_bar_type = 0; - - if (!e_group_bar_type){ - GtkTypeInfo e_group_bar_info = { - "EGroupBar", - sizeof (EGroupBar), - sizeof (EGroupBarClass), - (GtkClassInitFunc) e_group_bar_class_init, - (GtkObjectInitFunc) e_group_bar_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - parent_class = gtk_type_class (GTK_TYPE_CONTAINER); - e_group_bar_type = gtk_type_unique (GTK_TYPE_CONTAINER, - &e_group_bar_info); - } - - return e_group_bar_type; -} - - -static void -e_group_bar_class_init (EGroupBarClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - GtkContainerClass *container_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - container_class = (GtkContainerClass *) class; - - /* Method override */ - object_class->destroy = e_group_bar_destroy; - - widget_class->realize = e_group_bar_realize; - widget_class->unrealize = e_group_bar_unrealize; - widget_class->map = e_group_bar_map; - widget_class->unmap = e_group_bar_unmap; - widget_class->size_request = e_group_bar_size_request; - widget_class->size_allocate = e_group_bar_size_allocate; - widget_class->expose_event = e_group_bar_expose; - widget_class->draw = e_group_bar_draw; - - container_class->add = e_group_bar_add; - container_class->remove = e_group_bar_remove; - container_class->forall = e_group_bar_forall; -} - - -static void -e_group_bar_init (EGroupBar *group_bar) -{ - - GTK_WIDGET_UNSET_FLAGS (group_bar, GTK_NO_WINDOW); - - /* We don't want child resizes to propagate up to the parent. */ - gtk_container_set_resize_mode (GTK_CONTAINER (group_bar), - GTK_RESIZE_QUEUE); - - group_bar->children = g_array_new (FALSE, FALSE, - sizeof (EGroupBarChild)); - - group_bar->current_group_num = -1; - group_bar->buttons_homogeneous = TRUE; - group_bar->max_button_height = 0; - group_bar->animation_timeout_id = 0; -} - - -/** - * e_group_bar_new: - * @Returns: a new #EGroupBar. - * - * Creates a new #EGroupBar. - **/ -GtkWidget * -e_group_bar_new (void) -{ - GtkWidget *group_bar; - - group_bar = GTK_WIDGET (gtk_type_new (e_group_bar_get_type ())); - - return group_bar; -} - - -static void -e_group_bar_destroy (GtkObject *object) -{ - EGroupBar *group_bar; - - group_bar = E_GROUP_BAR (object); - - e_group_bar_stop_all_animation (group_bar); - - /* The parent GtkContainer class will automatically destroy all the - child widgets, but it calls gtk_container_foreach() so we must not - destroy our children array until after. */ - GTK_OBJECT_CLASS (parent_class)->destroy (object); - - g_array_free (group_bar->children, TRUE); -} - - -static void -e_group_bar_realize (GtkWidget *widget) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - GdkWindowAttr attributes; - gint attributes_mask; - gint border_width, group_num; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_GROUP_BAR (widget)); - - group_bar = E_GROUP_BAR (widget); - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); - - border_width = GTK_CONTAINER (group_bar)->border_width; - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = widget->allocation.x + border_width; - attributes.y = widget->allocation.y + border_width; - attributes.width = widget->allocation.width - 2 * border_width; - attributes.height = widget->allocation.height - 2 * border_width; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = gtk_widget_get_events (widget); - attributes.event_mask |= (GDK_EXPOSURE_MASK); - - attributes_mask = GDK_WA_X | GDK_WA_Y - | GDK_WA_VISUAL | GDK_WA_COLORMAP; - - widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), - &attributes, attributes_mask); - gdk_window_set_user_data (widget->window, widget); - - widget->style = gtk_style_attach (widget->style, widget->window); - gtk_style_set_background (widget->style, widget->window, - GTK_STATE_NORMAL); - - gdk_window_set_back_pixmap (widget->window, NULL, FALSE); - - /* Create windows for all the buttons & group canvases. */ - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - e_group_bar_create_group_button_window (group_bar, group_num); - e_group_bar_create_group_child_window (group_bar, group_num); - } -} - - -static void -e_group_bar_unrealize (GtkWidget *widget) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - gint group_num; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_GROUP_BAR (widget)); - - group_bar = E_GROUP_BAR (widget); - - /* Destroy the windows for all the buttons & group canvases. */ - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (group->button_window) { - gdk_window_set_user_data (group->button_window, NULL); - gdk_window_destroy (group->button_window); - group->button_window = NULL; - } - if (group->child_window) { - gdk_window_set_user_data (group->child_window, NULL); - gdk_window_destroy (group->child_window); - group->child_window = NULL; - } - } - - if (GTK_WIDGET_CLASS (parent_class)->unrealize) - (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); -} - - -static void -e_group_bar_map (GtkWidget *widget) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - gint group_num; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_GROUP_BAR (widget)); - - group_bar = E_GROUP_BAR (widget); - - GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); - - /* We do this in reverse order, and lower all the child windows, so - the stacking order ends up correct. */ - for (group_num = group_bar->children->len - 1; - group_num >= 0; - group_num--) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (group->button_window) { - gdk_window_show (group->button_window); - } - - if (group->button - && GTK_WIDGET_VISIBLE (group->button) - && !GTK_WIDGET_MAPPED (group->button)) { - gtk_widget_map (group->button); - } - - if (group->child_window) { - gdk_window_show (group->child_window); - gdk_window_lower (group->child_window); - } - - if (group->child - && GTK_WIDGET_VISIBLE (group->child) - && !GTK_WIDGET_MAPPED (group->child)) - gtk_widget_map (group->child); - } - - gdk_window_show (widget->window); -} - - -static void -e_group_bar_unmap (GtkWidget *widget) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - gint group_num; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_GROUP_BAR (widget)); - - group_bar = E_GROUP_BAR (widget); - - e_group_bar_stop_all_animation (group_bar); - - GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); - - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (group->button_window) { - gdk_window_hide (group->button_window); - } - - if (group->button - && GTK_WIDGET_MAPPED (group->button)) - gtk_widget_unmap (group->button); - - if (group->child_window) { - gdk_window_hide (group->child_window); - } - - if (group->child - && GTK_WIDGET_MAPPED (group->child)) - gtk_widget_unmap (group->child); - } - - gdk_window_hide (widget->window); -} - - -static void -e_group_bar_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - gint group_num, max_child_height; - GtkRequisition child_requisition; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_GROUP_BAR (widget)); - g_return_if_fail (requisition != NULL); - - group_bar = E_GROUP_BAR (widget); - - /* We set the requisition width to the largest requested width of the - child widgets. The requisition height is set to the sum of all the - button heights plus the height of the largest child. */ - requisition->width = 0; - requisition->height = 0; - - /* We have to call size_request on all children, even though we don't - use the results, since some widgets like GtkLabel depend on it. */ - group_bar->max_button_height = 0; - max_child_height = 0; - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (group->button) { - gtk_widget_size_request (group->button, - &child_requisition); - group->button_height = child_requisition.height; - } else { - group->button_height = 0; - } - - group_bar->max_button_height = MAX (group_bar->max_button_height, group->button_height); - requisition->height += child_requisition.height; - - if (group->child) { - gtk_widget_size_request (group->child, - &child_requisition); - max_child_height = MAX (max_child_height, - child_requisition.height); - requisition->width = MAX (requisition->width, - child_requisition.width); - } - } - - requisition->height += max_child_height; - - /* Add on the standard container border widths. */ - requisition->width += GTK_CONTAINER (widget)->border_width * 2; - requisition->height += GTK_CONTAINER (widget)->border_width * 2; -} - - -static void -e_group_bar_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - gint group_num, border_width, width, height, child_height, y; - GtkAllocation button_allocation, child_allocation; - - group_bar = E_GROUP_BAR (widget); - - /* All child & button windows and widgets use the same width as the - group bar minus the border width. */ - border_width = GTK_CONTAINER (widget)->border_width; - width = allocation->width - border_width * 2; - height = allocation->height - border_width * 2; - - widget->allocation = *allocation; - if (GTK_WIDGET_REALIZED (widget)) - gdk_window_move_resize (widget->window, - allocation->x + border_width, - allocation->y + border_width, - width, height); - - /* All the child widgets use the same height. */ - child_height = e_group_bar_get_child_height (group_bar); - - /* The buttons are always in the top-left of the button windows, and - all have the same width. The height is calculated for each group. */ - button_allocation.x = 0; - button_allocation.y = 0; - button_allocation.width = width; - - /* The child widgets are always in the top-left of the child windows, - and all have the same width and height. */ - child_allocation.x = 0; - child_allocation.y = 0; - child_allocation.width = width; - child_allocation.height = child_height; - - /* Step through the groups, placing the windows as necessary, and - allocating the areas for the child widgets. Note that if a button - or child window is in the middle of an animation, we just resize it - and update the target position, and let the animation continue. */ - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - /* Calculate the y position of the button, which depends on - the currently selected group and the button heights. */ - y = e_group_bar_get_group_button_position (group_bar, group_num); - button_allocation.height = group_bar->buttons_homogeneous ? group_bar->max_button_height : group->button_height; - - if (GTK_WIDGET_REALIZED (group->button)) { - if (group->button_window_in_animation) { - gdk_window_resize (group->button_window, - width, button_allocation.height); - group->button_window_target_y = y; - } else { - gdk_window_move_resize (group->button_window, - 0, y, width, button_allocation.height); - } - } - gtk_widget_size_allocate (group->button, &button_allocation); - - if (GTK_WIDGET_REALIZED (group->child)) { - if (group->child_window_in_animation) { - gdk_window_resize (group->child_window, - width, child_height); - group->child_window_target_y = y + button_allocation.height; - } else { - gdk_window_move_resize (group->child_window, - 0, y + button_allocation.height, - width, child_height); - } - } - gtk_widget_size_allocate (group->child, &child_allocation); - } -} - - -static gint -e_group_bar_expose (GtkWidget *widget, - GdkEventExpose *event) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - GdkEventExpose child_event; - gint group_num; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_GROUP_BAR (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - if (GTK_WIDGET_DRAWABLE (widget)) { - group_bar = E_GROUP_BAR (widget); - - child_event = *event; - - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (event->window == group->button_window - && GTK_WIDGET_DRAWABLE (group->button) - && GTK_WIDGET_NO_WINDOW (group->button) - && gtk_widget_intersect (group->button, &event->area, &child_event.area)) - gtk_widget_event (group->button, (GdkEvent*) &child_event); - - if (event->window == group->child_window - && GTK_WIDGET_DRAWABLE (group->child) - && GTK_WIDGET_NO_WINDOW (group->child) - && gtk_widget_intersect (group->child, &event->area, &child_event.area)) - gtk_widget_event (group->child, (GdkEvent*) &child_event); - } - } - - return FALSE; -} - - -static void -e_group_bar_draw (GtkWidget *widget, - GdkRectangle *area) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - gint group_num; - GdkRectangle child_area; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_GROUP_BAR (widget)); - - if (GTK_WIDGET_DRAWABLE (widget)) { - group_bar = E_GROUP_BAR (widget); - - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (GTK_WIDGET_DRAWABLE (group->button) - && gtk_widget_intersect (group->button, area, &child_area)) - gtk_widget_draw (group->button, &child_area); - - if (GTK_WIDGET_DRAWABLE (group->child) - && gtk_widget_intersect (group->child, area, &child_area)) - gtk_widget_draw (group->child, &child_area); - } - } -} - - -static void -e_group_bar_add (GtkContainer *container, - GtkWidget *widget) -{ - EGroupBar *group_bar; - GtkWidget *button; - gchar buffer[32]; - - g_return_if_fail (container != NULL); - g_return_if_fail (E_IS_GROUP_BAR (container)); - g_return_if_fail (widget != NULL); - - group_bar = E_GROUP_BAR (container); - - g_snprintf (buffer, sizeof (buffer), _("Group %i"), - group_bar->children->len + 1); - button = gtk_button_new_with_label (buffer); - gtk_widget_show (button); - - e_group_bar_add_group (group_bar, widget, button, -1); -} - - -static void -e_group_bar_remove (GtkContainer *container, - GtkWidget *widget) -{ - EGroupBar *group_bar; - gint group_num; - - g_return_if_fail (container != NULL); - g_return_if_fail (E_IS_GROUP_BAR (container)); - g_return_if_fail (widget != NULL); - - group_bar = E_GROUP_BAR (container); - - group_num = e_group_bar_get_group_num (group_bar, widget); - e_group_bar_remove_group (group_bar, group_num); -} - - -static void -e_group_bar_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - gint group_num; - GList *tmp_list; - - g_return_if_fail (container != NULL); - g_return_if_fail (E_IS_GROUP_BAR (container)); - g_return_if_fail (callback != NULL); - - group_bar = E_GROUP_BAR (container); - - /* Note that drag-and-drop does not check the Z-order of widgets, so - we have to iterate through them from top to bottom, or it will - not work properly. We also have to use temporary lists so widgets - can be safely destroyed while iterating. */ - - if (include_internals) { - tmp_list = NULL; - for (group_num = group_bar->children->len - 1; - group_num >= 0; - group_num--) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (group->button) - tmp_list = g_list_prepend (tmp_list, - group->button); - } - - g_list_foreach (tmp_list, (GFunc) callback, callback_data); - g_list_free (tmp_list); - } - - tmp_list = NULL; - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (group->child) - tmp_list = g_list_prepend (tmp_list, group->child); - } - g_list_foreach (tmp_list, (GFunc) callback, callback_data); - g_list_free (tmp_list); -} - - -static void -e_group_bar_create_group_button_window (EGroupBar *group_bar, - gint group_num) -{ - EGroupBarChild *group; - GtkWidget *widget; - GdkWindowAttr attributes; - gint attributes_mask; - gint y, height, border_width; - - widget = GTK_WIDGET (group_bar); - - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - y = e_group_bar_get_group_button_position (group_bar, group_num); - height = group_bar->buttons_homogeneous ? group_bar->max_button_height - : group->button_height; - border_width = GTK_CONTAINER (group_bar)->border_width; - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = 0; - attributes.y = y; - attributes.width = widget->allocation.width - 2 * border_width; - attributes.height = height; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = gtk_widget_get_events (widget); - attributes.event_mask |= (GDK_EXPOSURE_MASK); - - attributes_mask = GDK_WA_X | GDK_WA_Y - | GDK_WA_VISUAL | GDK_WA_COLORMAP; - - group->button_window = gdk_window_new (widget->window, &attributes, - attributes_mask); - gdk_window_set_user_data (group->button_window, widget); - - gtk_widget_set_parent_window (group->button, - group->button_window); - gdk_window_set_back_pixmap (group->button_window, NULL, TRUE); -} - - -static void -e_group_bar_create_group_child_window (EGroupBar *group_bar, - gint group_num) -{ - EGroupBarChild *group; - GtkWidget *widget; - GdkWindowAttr attributes; - gint attributes_mask; - gint y, height, border_width; - - widget = GTK_WIDGET (group_bar); - - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - y = e_group_bar_get_group_button_position (group_bar, group_num); - y += group_bar->buttons_homogeneous ? group_bar->max_button_height - : group->button_height; - height = e_group_bar_get_child_height (group_bar); - border_width = GTK_CONTAINER (group_bar)->border_width; - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = 0; - attributes.y = y; - attributes.width = widget->allocation.width - 2 * border_width; - attributes.height = height; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = gtk_widget_get_events (widget); - attributes.event_mask |= (GDK_EXPOSURE_MASK); - - attributes_mask = GDK_WA_X | GDK_WA_Y - | GDK_WA_VISUAL | GDK_WA_COLORMAP; - - group->child_window = gdk_window_new (widget->window, &attributes, - attributes_mask); - gdk_window_set_user_data (group->child_window, widget); - - gtk_widget_set_parent_window (GTK_WIDGET (group->child), - group->child_window); - gdk_window_set_back_pixmap (group->child_window, NULL, TRUE); -} - - -/* This returns the y position of a group's button within the EGroupBar window. - */ -static gint -e_group_bar_get_group_button_position (EGroupBar *group_bar, - gint group_num) -{ - gint border_width, window_height, y; - - border_width = GTK_CONTAINER (group_bar)->border_width; - window_height = GTK_WIDGET (group_bar)->allocation.height - 2 * border_width; - - if (group_num <= group_bar->current_group_num) - y = e_group_bar_sum_button_heights (group_bar, 0, group_num - 1); - else - y = window_height - e_group_bar_sum_button_heights (group_bar, group_num, group_bar->children->len - 1); - - return y; -} - - -/* This returns the sum of all the buttons from first to last inclusive. */ -static gint -e_group_bar_sum_button_heights (EGroupBar *group_bar, gint first, gint last) -{ - EGroupBarChild *group; - gint height, group_num; - - height = 0; - - if (group_bar->buttons_homogeneous) - return (last - first + 1) * group_bar->max_button_height; - - for (group_num = first; group_num <= last; group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - height += group->button_height; - } - - return height; -} - - -static gint -e_group_bar_get_group_child_position (EGroupBar *group_bar, - gint group_num) -{ - EGroupBarChild *group; - gint y; - - y = e_group_bar_get_group_button_position (group_bar, group_num); - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - y += group_bar->buttons_homogeneous ? group_bar->max_button_height - : group->button_height; - - return y; -} - - -static gint -e_group_bar_get_child_height (EGroupBar *group_bar) -{ - EGroupBarChild *group; - gint group_num; - - /* Start with the allocated height of the EGroupBar, less the border.*/ - group_bar->child_height = GTK_WIDGET (group_bar)->allocation.height; - group_bar->child_height -= 2 * GTK_CONTAINER (group_bar)->border_width; - - /* Now subtract the heights of all the buttons. */ - if (group_bar->buttons_homogeneous) { - group_bar->child_height -= group_bar->children->len * group_bar->max_button_height; - } else { - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - group_bar->child_height -= group->button_height; - } - } - - return group_bar->child_height; -} - - -/* - * Insertion, reordering and deletion of items. - */ - -/** - * e_group_bar_add_group: - * @group_bar: an #EGroupBar. - * @child: the child widget to add. - * @button: the button used to show the child widget. - * @position: the new group's position, or -1 to place it last. - * @Returns: the position of the new group. - * - * Adds a new group to a #EGroupBar at the given position. - **/ -gint -e_group_bar_add_group (EGroupBar *group_bar, - GtkWidget *child, - GtkWidget *button, - gint position) -{ - EGroupBarChild *group, empty_group, *tmp_group; - gint group_num, tmp_group_num; - - g_return_val_if_fail (group_bar != NULL, -1); - g_return_val_if_fail (E_IS_GROUP_BAR (group_bar), -1); - g_return_val_if_fail (child != NULL, -1); - g_return_val_if_fail (button != NULL, -1); - g_return_val_if_fail (GTK_IS_BUTTON (button), -1); - - /* Append an empty group to the children array and get a pointer to - it, so we can use it like a normal group. */ - group_num = group_bar->children->len; - g_array_append_val (group_bar->children, empty_group); - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - /* Initialize the group. */ - group->button = button; - group->button_window = NULL; - group->child = child; - group->child_window = NULL; - group->button_window_in_animation = FALSE; - group->child_window_in_animation = FALSE; - group->button_window_target_y = 0; - group->child_window_target_y = 0; - - /* If we don't have a current group, set it to the first one. */ - if (group_bar->current_group_num == -1) - group_bar->current_group_num = 0; - - /* If the EGroupBar widget is realize, we need to create the child - windows to put the button & child in. */ - if (GTK_WIDGET_REALIZED (group_bar)) { - e_group_bar_create_group_button_window (group_bar, group_num); - e_group_bar_create_group_child_window (group_bar, group_num); - - /* We need to lower all the child windows of the previous - groups, in reverse order, to keep the stacking order - correct. */ - for (tmp_group_num = group_num - 1; - tmp_group_num >= 0; - tmp_group_num--) { - tmp_group = &g_array_index (group_bar->children, - EGroupBarChild, - tmp_group_num); - gdk_window_lower (group->child_window); - } - } - - gtk_widget_set_parent (group->button, GTK_WIDGET (group_bar)); - gtk_widget_set_parent (group->child, GTK_WIDGET (group_bar)); - - if (GTK_WIDGET_REALIZED (group_bar)) { - gtk_widget_realize (group->button); - gtk_widget_realize (group->child); - } - - if (GTK_WIDGET_VISIBLE (group_bar) - && GTK_WIDGET_MAPPED (group_bar)) { - if (group->button - && GTK_WIDGET_VISIBLE (group->button) - && !GTK_WIDGET_MAPPED (group->button)) { - gtk_widget_map (group->button); - gtk_widget_queue_resize (group->button); - } - if (group->child - && GTK_WIDGET_VISIBLE (group->child) - && !GTK_WIDGET_MAPPED (group->child)) { - gtk_widget_map (group->child); - gtk_widget_queue_resize (group->child); - } - } - - gtk_signal_connect (GTK_OBJECT (group->button), "clicked", - GTK_SIGNAL_FUNC (e_group_bar_on_button_clicked), - group_bar); - - gtk_signal_connect (GTK_OBJECT (group->button), "drag_motion", - GTK_SIGNAL_FUNC (e_group_bar_on_button_drag_motion), - group_bar); - gtk_signal_connect (GTK_OBJECT (group->button), "drag_leave", - GTK_SIGNAL_FUNC (e_group_bar_on_button_drag_leave), - group_bar); - - return group_num; -} - - -/** - * e_group_bar_reorder_group: - * @group_bar: an #EGroupBar. - * @group_num: the index of the group to move. - * @new_position: the new position of the group. - * - * Moves a group to a new position within the #EGroupBar. - **/ -void -e_group_bar_reorder_group (EGroupBar *group_bar, - gint group_num, - gint new_position) -{ - EGroupBarChild group, *tmp_group; - gint tmp_group_num; - - g_return_if_fail (E_IS_GROUP_BAR (group_bar)); - g_return_if_fail (group_num >= 0); - g_return_if_fail (group_num < group_bar->children->len); - - e_group_bar_stop_all_animation (group_bar); - - /* Copy the group. */ - group = g_array_index (group_bar->children, - EGroupBarChild, group_num); - - /* Remove the group from its current position. */ - g_array_remove_index (group_bar->children, group_num); - - /* Copy the group into its new position. */ - g_array_insert_val (group_bar->children, new_position, group); - - /* We need to lower the groups' windows so they are in the correct - z-order. We can skip unaffected windows. */ - for (tmp_group_num = MAX (group_num, new_position); - tmp_group_num >= 0; - tmp_group_num--) { - tmp_group = &g_array_index (group_bar->children, - EGroupBarChild, tmp_group_num); - gdk_window_lower (tmp_group->child_window); - } - - /* Queue a resize so the groups get layed out properly. */ - gtk_widget_queue_resize (GTK_WIDGET (group_bar)); -} - - -/** - * e_group_bar_remove_group: - * @group_bar: an #EGroupBar. - * @group_num: the index of the group to remove. - * - * Removes a group from an #EGroupBar. - **/ -void -e_group_bar_remove_group (EGroupBar *group_bar, - gint group_num) -{ - EGroupBarChild *group; - - g_return_if_fail (E_IS_GROUP_BAR (group_bar)); - g_return_if_fail (group_num >= 0); - g_return_if_fail (group_num < group_bar->children->len); - - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - /* Stop any animation. */ - e_group_bar_stop_all_animation (group_bar); - - gtk_widget_unparent (group->child); - if (group->button) - gtk_widget_unparent (group->button); - - if (group->button_window) { - gdk_window_set_user_data (group->button_window, NULL); - gdk_window_destroy (group->button_window); - } - if (group->child_window) { - gdk_window_set_user_data (group->child_window, NULL); - gdk_window_destroy (group->child_window); - } - - g_array_remove_index (group_bar->children, group_num); - - /* Make sure the current group is valid. */ - if (group_bar->current_group_num >= group_bar->children->len) - group_bar->current_group_num = group_bar->children->len - 1; - - gtk_widget_queue_resize (GTK_WIDGET (group_bar)); -} - - -/* - * Getting & setting the current group. - */ - -/** - * e_group_bar_get_current_group_num: - * @group_bar: an #EGroupBar. - * @Returns: the index of the group currently displayed. - * - * Returns the index of the group currently displayed. - **/ -gint -e_group_bar_get_current_group_num (EGroupBar *group_bar) -{ - g_return_val_if_fail (E_IS_GROUP_BAR (group_bar), -1); - - return group_bar->current_group_num; -} - - -/** - * e_group_bar_set_current_group_num: - * @group_bar: an #EGroupBar. - * @animate: if TRUE, and the #EGroupBar is visible, the group will slide into - * position, as if the group's button was pressed. - * @Returns: the index of the group to display. - * - * Sets the group to display. - **/ -void -e_group_bar_set_current_group_num (EGroupBar *group_bar, - gint group_num, - gboolean animate) -{ - g_return_if_fail (E_IS_GROUP_BAR (group_bar)); - - /* If that already is the current group, just return. */ - if (group_bar->current_group_num == group_num) - return; - - if (GTK_WIDGET_VISIBLE (group_bar)) { - if (animate) { - e_group_bar_start_animation (group_bar, group_num); - } else { - group_bar->current_group_num = group_num; - e_group_bar_stop_all_animation (group_bar); - gtk_widget_queue_resize (GTK_WIDGET (group_bar)); - } - } else { - /* The positions will be sorted out when the widget's size is - allocated. */ - group_bar->current_group_num = group_num; - } -} - - -/* - * Getting groups and group numbers. - */ - -/** - * e_group_bar_get_nth_group: - * @group_bar: an #EGroupBar. - * @group_num: the index of the group to get. - * @Returns: the child widget at the given index. - * - * Returns the child widget at the given index. - **/ -GtkWidget* -e_group_bar_get_nth_group (EGroupBar *group_bar, - gint group_num) -{ - EGroupBarChild *group; - - g_return_val_if_fail (E_IS_GROUP_BAR (group_bar), NULL); - g_return_val_if_fail (group_num >= 0, NULL); - g_return_val_if_fail (group_num < group_bar->children->len, NULL); - - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - return group->child; -} - - -/** - * e_group_bar_get_group_num: - * @group_bar: an #EGroupBar. - * @child: the child widget to find. - * @Returns: the index of the group containing the given widget. - * - * Returns the index of the group containing the given child widget. - **/ -gint -e_group_bar_get_group_num (EGroupBar *group_bar, - GtkWidget *child) -{ - EGroupBarChild *group; - gint group_num; - - g_return_val_if_fail (E_IS_GROUP_BAR (group_bar), -1); - g_return_val_if_fail (child != NULL, -1); - - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (group->child == child) - return group_num; - } - - return -1; -} - - -/** - * e_group_bar_set_group_button_label: - * @group_bar: an #EGroupBar. - * @group_num: the index of the group. - * @label: the label widget to place in the group's button. - * - * Sets the label widget for the given group's button, replacing any existing - * widget in the button. - **/ -void -e_group_bar_set_group_button_label (EGroupBar *group_bar, - gint group_num, - GtkWidget *label) -{ - EGroupBarChild *group; - GtkWidget *button_child; - - g_return_if_fail (E_IS_GROUP_BAR (group_bar)); - g_return_if_fail (group_num >= 0); - g_return_if_fail (group_num < group_bar->children->len); - - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - button_child = GTK_BIN (group->button)->child; - if (button_child) { - gtk_container_remove (GTK_CONTAINER (group->button), - button_child); - } - - if (label) - gtk_container_add (GTK_CONTAINER (group->button), label); -} - - -/* - * Getting & setting the EGroupBar options. - */ - -/** - * e_group_bar_get_buttons_homogeneous: - * @group_bar: an #EGroupBar. - * @Returns: TRUE if the buttons are homoegeneous. - * - * Returns TRUE if the buttons are homogeneous (i.e. all have the same height). - **/ -gboolean -e_group_bar_get_buttons_homogeneous (EGroupBar *group_bar) -{ - g_return_val_if_fail (E_IS_GROUP_BAR (group_bar), TRUE); - - return group_bar->buttons_homogeneous; -} - - -/** - * e_group_bar_set_buttons_homogeneous: - * @group_bar: an #EGroupBar. - * @homogeneous: TRUE if the buttons should be homoegeneous. - * - * Specifies whether the buttons should be homogeneous. When set to TRUE all - * the group buttons will be set to the same height (equal to the largest - * requested height). When set to FALSE the buttons will use their own - * individual requested heights. - **/ -void -e_group_bar_set_buttons_homogeneous (EGroupBar *group_bar, - gboolean homogeneous) -{ - g_return_if_fail (E_IS_GROUP_BAR (group_bar)); - - /* Just return if the setting hasn't changed. */ - if (group_bar->buttons_homogeneous == homogeneous) - return; - - group_bar->buttons_homogeneous = homogeneous; - - /* Update the position & sizes of the buttons. */ - gtk_widget_queue_resize (GTK_WIDGET (group_bar)); -} - - -static void -e_group_bar_on_button_clicked (GtkWidget *group_button, - EGroupBar *group_bar) -{ - gint group_num; - - /* Determine which group button was clicked. */ - group_num = e_group_bar_find_button (group_bar, group_button); - - if (group_num != -1) - e_group_bar_start_animation (group_bar, group_num); -} - - -/* This returns the group containing the given button, or -1 if not found. */ -static gint -e_group_bar_find_button (EGroupBar *group_bar, - GtkWidget *group_button) -{ - EGroupBarChild *group; - gint group_num; - - /* Determine which group button was clicked. */ - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - if (group->button == group_button) - return group_num; - } - - return -1; -} - - -static void -e_group_bar_start_animation (EGroupBar *group_bar, - gint group_num) -{ - EGroupBarChild *group, *old_group; - gint old_group_num, step; - - old_group_num = group_bar->current_group_num; - - /* Return if it is already the current group. */ - if (old_group_num == group_num) - return; - - group_bar->current_group_num = group_num; - - /* Calculate the target y position of the new current group button - and child, and map the child. */ - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - group->button_window_target_y = e_group_bar_get_group_button_position (group_bar, group_num); - group->button_window_in_animation = TRUE; - - group->child_window_target_y = e_group_bar_get_group_child_position (group_bar, group_num); - group->child_window_in_animation = TRUE; - - /* Calculate the target y position of the current group button and - child. */ - old_group = &g_array_index (group_bar->children, - EGroupBarChild, old_group_num); - old_group->button_window_target_y = e_group_bar_get_group_button_position (group_bar, old_group_num); - old_group->button_window_in_animation = TRUE; - - old_group->child_window_target_y = e_group_bar_get_group_child_position (group_bar, old_group_num); - old_group->child_window_in_animation = TRUE; - - /* We also need to animate the buttons in between the old group and the - new group. */ - step = (old_group_num < group_num) ? 1 : -1; - old_group_num += step; - while (old_group_num != group_num) { - old_group = &g_array_index (group_bar->children, - EGroupBarChild, old_group_num); - old_group->button_window_target_y = e_group_bar_get_group_button_position (group_bar, old_group_num); - old_group->button_window_in_animation = TRUE; - - old_group->child_window_target_y = e_group_bar_get_group_child_position (group_bar, old_group_num); - old_group->child_window_in_animation = TRUE; - - old_group_num += step; - } - - /* Add a timeout handler if we haven't already got one. */ - if (group_bar->animation_timeout_id == 0) { - group_bar->animation_timeout_id = g_timeout_add (E_GROUP_BAR_SCROLL_TIMEOUT, e_group_bar_timeout_handler, group_bar); - } -} - - -static gboolean -e_group_bar_timeout_handler (gpointer data) -{ - EGroupBar *group_bar; - EGroupBarChild *group; - gint group_num, button_window_y, child_window_y; - gboolean finished = TRUE; - - g_return_val_if_fail (E_IS_GROUP_BAR (data), FALSE); - - group_bar = E_GROUP_BAR (data); - - GDK_THREADS_ENTER (); - - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - - if (group->button_window_in_animation) { - gdk_window_get_position (group->button_window, NULL, - &button_window_y); - button_window_y += e_group_bar_get_increment (group_bar, button_window_y, group->button_window_target_y); - if (button_window_y == group->button_window_target_y) - group->button_window_in_animation = FALSE; - else - finished = FALSE; - gdk_window_move (group->button_window, - 0, button_window_y); - } - if (group->child_window_in_animation) { - gdk_window_get_position (group->child_window, NULL, - &child_window_y); - child_window_y += e_group_bar_get_increment (group_bar, child_window_y, group->child_window_target_y); - if (child_window_y == group->child_window_target_y) - group->child_window_in_animation = FALSE; - else - finished = FALSE; - gdk_window_move (group->child_window, - 0, child_window_y); - } - - } - - if (finished) - group_bar->animation_timeout_id = 0; - - GDK_THREADS_LEAVE (); - - return !finished; -} - - -static gint -e_group_bar_get_increment (EGroupBar *group_bar, - gint window_y, - gint window_target_y) -{ - gdouble percentage; - gint distance, total_distance, step; - - total_distance = group_bar->child_height; - distance = MIN (abs (window_target_y - window_y), total_distance); - - if (distance == 0) - return 0; - - /* Convert the distance into an angle between -PI/2 and PI/2, so we can - then do a cosine of it. */ - percentage = cos (M_PI * ((gdouble)distance / (gdouble)total_distance) - M_PI / 2); - - /* Now multiply by our maximum step size to get the step size. */ - step = percentage * total_distance / 6; - - /* Add it to the minimum step size, but don't go too far. */ - step = step + E_GROUP_BAR_MIN_STEP_SIZE; - step = MIN (step, distance); - - if (window_target_y > window_y) - return step; - else - return -step; -} - - -static gboolean -e_group_bar_on_button_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - EGroupBar *group_bar) -{ - gint group_num; - - if (!group_bar->auto_show_timeout_id) { - group_num = e_group_bar_find_button (group_bar, widget); - if (group_num != -1) { - group_bar->auto_show_timeout_id = gtk_timeout_add (E_GROUP_BAR_AUTO_SHOW_TIMEOUT, e_group_bar_auto_show, group_bar); - group_bar->auto_show_group_num = group_num; - } - } - return TRUE; -} - - -static void -e_group_bar_on_button_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time, - EGroupBar *group_bar) -{ - if (group_bar->auto_show_timeout_id) { - gtk_timeout_remove (group_bar->auto_show_timeout_id); - group_bar->auto_show_timeout_id = 0; - } -} - - -static gboolean -e_group_bar_auto_show (gpointer data) -{ - EGroupBar *group_bar; - - g_return_val_if_fail (E_IS_GROUP_BAR (data), FALSE); - - group_bar = E_GROUP_BAR (data); - - GDK_THREADS_ENTER (); - - e_group_bar_start_animation (group_bar, - group_bar->auto_show_group_num); - - group_bar->auto_show_timeout_id = 0; - - GDK_THREADS_LEAVE (); - - return FALSE; -} - - -/* This removes all timeouts and sets all 'in_animation' flags to FALSE. */ -static void -e_group_bar_stop_all_animation (EGroupBar *group_bar) -{ - EGroupBarChild *group; - gint group_num; - - if (group_bar->animation_timeout_id) { - g_source_remove (group_bar->animation_timeout_id); - group_bar->animation_timeout_id = 0; - } - if (group_bar->auto_show_timeout_id) { - g_source_remove (group_bar->auto_show_timeout_id); - group_bar->auto_show_timeout_id = 0; - } - - for (group_num = 0; - group_num < group_bar->children->len; - group_num++) { - group = &g_array_index (group_bar->children, - EGroupBarChild, group_num); - group->button_window_in_animation = FALSE; - group->child_window_in_animation = FALSE; - } -} - diff --git a/widgets/shortcut-bar/e-group-bar.h b/widgets/shortcut-bar/e-group-bar.h deleted file mode 100644 index 62751174bb..0000000000 --- a/widgets/shortcut-bar/e-group-bar.h +++ /dev/null @@ -1,172 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_GROUP_BAR_H_ -#define _E_GROUP_BAR_H_ - -#include <gtk/gtkcontainer.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EGroupBar displays a vertical bar with a number of Groups, which are viewed - * one at a time by selecting the Group's button. When a different Group is - * selected, it slides into view, and the old Group slides out. - * It is typically used on the left of the main application window so users - * can easily access particular features. - * - * It is implemented like GtkNotebook, i.e. the main widgets are the children - * of the EGroupBar and the button widgets are treated specially like the - * GtkNotebook tab labels. - */ - -/* This contains information on one item. */ -typedef struct _EGroupBarChild EGroupBarChild; -struct _EGroupBarChild -{ - /* This is the button used to select the group, and the window we use - to move it around easily. */ - GtkWidget *button; - GdkWindow *button_window; - gint button_height; - - /* This is the child widget, which can be any widget added by the - application, and the window we use to move it around easily. */ - GtkWidget *child; - GdkWindow *child_window; - - /* These are TRUE if we are currently animating the windows. */ - gboolean button_window_in_animation; - gboolean child_window_in_animation; - - /* These are the target y positions that the windows should eventually - move to, used for animation. If we get a size_allocate we just - update these and the animation can continue as normal. - When a child window reaches its target position, it is unmapped if - if it is not the current group (i.e. it has slid off screen). */ - gint button_window_target_y; - gint child_window_target_y; -}; - - -#define E_GROUP_BAR(obj) GTK_CHECK_CAST (obj, e_group_bar_get_type (), EGroupBar) -#define E_GROUP_BAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_group_bar_get_type (), EGroupBarClass) -#define E_IS_GROUP_BAR(obj) GTK_CHECK_TYPE (obj, e_group_bar_get_type ()) - - -typedef struct _EGroupBar EGroupBar; -typedef struct _EGroupBarClass EGroupBarClass; - -struct _EGroupBar -{ - GtkContainer container; - - /* This is an array of EGroupBarChild elements. */ - GArray *children; - - /* This is the group currently shown. */ - gint current_group_num; - - /* This is TRUE if all the buttons are allocated the same height. */ - gboolean buttons_homogeneous; - - /* This is the biggest requested height of all the buttons, which we - use for all buttons when buttons_homogeneous is set. */ - gint max_button_height; - - /* This is the height of all the child windows & widgets. */ - gint child_height; - - /* The id of the source function for animation timeouts. If this is - not 0 then we are in the middle of an animation. */ - guint animation_timeout_id; - - /* The id of the source function for automatically showing groups when - the user drags over the group button, and the group to show. */ - guint auto_show_timeout_id; - gint auto_show_group_num; -}; - -struct _EGroupBarClass -{ - GtkContainerClass parent_class; -}; - - -GtkType e_group_bar_get_type (void); -GtkWidget* e_group_bar_new (void); - -/* - * Insertion, reordering and deletion of items. - */ - -/* Adds a new group at the given position. If position is -1 it adds it as - the last group. It returns the group number. */ -gint e_group_bar_add_group (EGroupBar *group_bar, - GtkWidget *child, - GtkWidget *button, - gint position); -void e_group_bar_reorder_group (EGroupBar *group_bar, - gint group_num, - gint new_position); -void e_group_bar_remove_group (EGroupBar *group_bar, - gint group_num); - -/* - * Getting & setting the current group. - */ -gint e_group_bar_get_current_group_num (EGroupBar *group_bar); -void e_group_bar_set_current_group_num (EGroupBar *group_bar, - gint group_num, - gboolean animate); - -/* - * Getting groups and group numbers. - */ -GtkWidget* e_group_bar_get_nth_group (EGroupBar *group_bar, - gint group_num); -gint e_group_bar_get_group_num (EGroupBar *group_bar, - GtkWidget *child); - -/* - * Setting the group button label. - */ -void e_group_bar_set_group_button_label (EGroupBar *group_bar, - gint group_num, - GtkWidget *label); - -/* - * Getting & setting the EGroupBar options. - */ -gboolean e_group_bar_get_buttons_homogeneous (EGroupBar *group_bar); -void e_group_bar_set_buttons_homogeneous (EGroupBar *group_bar, - gboolean homogeneous); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_GROUP_BAR_H_ */ diff --git a/widgets/shortcut-bar/e-icon-bar-bg-item.c b/widgets/shortcut-bar/e-icon-bar-bg-item.c deleted file mode 100644 index 5154a38267..0000000000 --- a/widgets/shortcut-bar/e-icon-bar-bg-item.c +++ /dev/null @@ -1,366 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * EIconBarBgItem - A GnomeCanvasItem which covers the entire EIconBar. - * It paints the rectangles around items when the mouse moves over them, and - * the lines between items when dragging. - */ - -#include <config.h> -#include "e-icon-bar-bg-item.h" -#include "e-icon-bar.h" - -/* This is the size of the border around the icons, for the shadow. */ -#define E_ICON_BAR_LARGE_ICON_SHADOW_BORDER 2 -#define E_ICON_BAR_SMALL_ICON_SHADOW_BORDER 2 - -/* These are for the horzontal bar when dragging. */ -#define E_ICON_BAR_BG_ITEM_BAR_HEIGHT 1 -#define E_ICON_BAR_BG_ITEM_BAR_OFFSET 2 -#define E_ICON_BAR_BG_ITEM_LARGE_ARROW_HEIGHT 8 -#define E_ICON_BAR_BG_ITEM_SMALL_ARROW_HEIGHT 4 - -static void e_icon_bar_bg_item_class_init (EIconBarBgItemClass *class); -static void e_icon_bar_bg_item_init (EIconBarBgItem *ibitem); - -static void e_icon_bar_bg_item_set_arg (GtkObject *o, GtkArg *arg, - guint arg_id); -static void e_icon_bar_bg_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, int flags); -static void e_icon_bar_bg_item_draw (GnomeCanvasItem *item, - GdkDrawable *drawable, - int x, int y, - int width, int height); -static double e_icon_bar_bg_item_point (GnomeCanvasItem *item, - double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item); -static gint e_icon_bar_bg_item_event (GnomeCanvasItem *item, - GdkEvent *event); -static gint e_icon_bar_bg_item_button_press (EIconBarBgItem *ibitem, - GdkEvent *event); -static gint e_icon_bar_bg_item_button_release (EIconBarBgItem *ibitem, - GdkEvent *event); -static gint e_icon_bar_bg_item_motion_notify (EIconBarBgItem *ibitem, - GdkEvent *event); - -static GnomeCanvasItemClass *parent_class; - -/* The arguments we take */ -enum { - ARG_0, - ARG_ICON_BAR -}; - - -GtkType -e_icon_bar_bg_item_get_type (void) -{ - static GtkType e_icon_bar_bg_item_type = 0; - - if (!e_icon_bar_bg_item_type) { - GtkTypeInfo e_icon_bar_bg_item_info = { - "EIconBarBgItem", - sizeof (EIconBarBgItem), - sizeof (EIconBarBgItemClass), - (GtkClassInitFunc) e_icon_bar_bg_item_class_init, - (GtkObjectInitFunc) e_icon_bar_bg_item_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - e_icon_bar_bg_item_type = gtk_type_unique (gnome_canvas_item_get_type (), &e_icon_bar_bg_item_info); - } - - return e_icon_bar_bg_item_type; -} - - -static void -e_icon_bar_bg_item_class_init (EIconBarBgItemClass *class) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - parent_class = gtk_type_class (gnome_canvas_item_get_type()); - - object_class = (GtkObjectClass *) class; - item_class = (GnomeCanvasItemClass *) class; - - gtk_object_add_arg_type ("EIconBarBgItem::icon_bar", - GTK_TYPE_POINTER, GTK_ARG_WRITABLE, - ARG_ICON_BAR); - - object_class->set_arg = e_icon_bar_bg_item_set_arg; - - /* GnomeCanvasItem method overrides */ - item_class->update = e_icon_bar_bg_item_update; - item_class->draw = e_icon_bar_bg_item_draw; - item_class->point = e_icon_bar_bg_item_point; - item_class->event = e_icon_bar_bg_item_event; -} - - -static void -e_icon_bar_bg_item_init (EIconBarBgItem *ibitem) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (ibitem); - - ibitem->icon_bar = NULL; - - item->x1 = 0; - item->y1 = 0; - item->x2 = 0; - item->y2 = 0; -} - - -static void -e_icon_bar_bg_item_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EIconBarBgItem *ibitem; - - item = GNOME_CANVAS_ITEM (o); - ibitem = E_ICON_BAR_BG_ITEM (o); - - switch (arg_id){ - case ARG_ICON_BAR: - ibitem->icon_bar = GTK_VALUE_POINTER (*arg); - break; - } -} - - -static void -e_icon_bar_bg_item_update (GnomeCanvasItem *item, - double *affine, - ArtSVP *clip_path, - int flags) -{ - if (GNOME_CANVAS_ITEM_CLASS (parent_class)->update) - (* GNOME_CANVAS_ITEM_CLASS (parent_class)->update) (item, affine, clip_path, flags); - - /* The grid covers the entire canvas area. */ - item->x1 = 0; - item->y1 = 0; - item->x2 = INT_MAX; - item->y2 = INT_MAX; -} - - -/* - * DRAWING ROUTINES - functions to paint the canvas item. - */ - -static void -e_icon_bar_bg_item_draw (GnomeCanvasItem *canvas_item, GdkDrawable *drawable, - int x, int y, int width, int height) -{ - EIconBar *icon_bar; - EIconBarItem *item; - EIconBarBgItem *ibitem; - GtkStyle *style; - GdkGC *gc; - GtkShadowType shadow; - gint item_num, border, bar_x, bar_y, bar_w, i, arrow_height; - - ibitem = E_ICON_BAR_BG_ITEM (canvas_item); - icon_bar = ibitem->icon_bar; - g_return_if_fail (icon_bar != NULL); - style = GTK_WIDGET (icon_bar)->style; - shadow = GTK_SHADOW_NONE; - - /* Draw the highlight around the current highlight item. */ - item_num = -1; - if (icon_bar->editing_item_num == -1) { - if (icon_bar->pressed_item_num != -1) { - item_num = icon_bar->pressed_item_num; - if (icon_bar->pressed_item_num == icon_bar->mouse_over_item_num) - shadow = GTK_SHADOW_IN; - else - shadow = GTK_SHADOW_OUT; - } else if (icon_bar->mouse_over_item_num != -1) { - item_num = icon_bar->mouse_over_item_num; - shadow = GTK_SHADOW_OUT; - } - } - - if (item_num != -1) { - item = &g_array_index (icon_bar->items, EIconBarItem, - item_num); - - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) - border = E_ICON_BAR_LARGE_ICON_SHADOW_BORDER; - else - border = E_ICON_BAR_SMALL_ICON_SHADOW_BORDER; - - gtk_draw_shadow (style, drawable, GTK_STATE_NORMAL, shadow, - icon_bar->icon_x - border - x, - item->icon_y - border - y, - icon_bar->icon_w + border * 2 - 1, - icon_bar->icon_h + border * 2 - 1); - } - - /* Draw the bar between items when dragging, if needed. */ - if (icon_bar->in_drag && icon_bar->dragging_before_item_num != -1) { - if (icon_bar->dragging_before_item_num < icon_bar->items->len) { - item = &g_array_index (icon_bar->items, EIconBarItem, - icon_bar->dragging_before_item_num); - bar_y = 0; - } else { - /* We need to draw the bar after the last item. */ - item = &g_array_index (icon_bar->items, EIconBarItem, - icon_bar->items->len - 1); - bar_y = item->item_height + icon_bar->spacing; - } - - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) { - bar_y += item->icon_y; - } else { - bar_y += MIN (item->icon_y, item->text_y); - } - bar_y -= y + icon_bar->spacing / 2; - - bar_x = E_ICON_BAR_BG_ITEM_BAR_OFFSET - x; - bar_w = GTK_WIDGET (icon_bar)->allocation.width - 2 * E_ICON_BAR_BG_ITEM_BAR_OFFSET - 1; - - gc = GTK_WIDGET (icon_bar)->style->fg_gc[GTK_STATE_NORMAL]; - - /* Draw the horizontal bar. */ - gdk_draw_rectangle (drawable, gc, TRUE, - bar_x, bar_y, - bar_w, E_ICON_BAR_BG_ITEM_BAR_HEIGHT); - - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) - arrow_height = E_ICON_BAR_BG_ITEM_LARGE_ARROW_HEIGHT / 2; - else - arrow_height = E_ICON_BAR_BG_ITEM_SMALL_ARROW_HEIGHT / 2; - - /* Draw the arrows at the end of the lines. We use - gdk_draw_line() to draw a series of vertical lines, since - gdk_draw_polygon() produces odd results. */ - i = 0; - while (arrow_height > 0) { - gdk_draw_line (drawable, gc, - bar_x + i, - bar_y - arrow_height, - bar_x + i, - bar_y + arrow_height); - gdk_draw_line (drawable, gc, - bar_x + bar_w - i - 1, - bar_y - arrow_height, - bar_x + bar_w - i - 1, - bar_y + arrow_height); - arrow_height--; - i++; - } - } -} - - -/* This is supposed to return the nearest item the the point and the distance. - Since we are the only item we just return ourself and 0 for the distance. - This is needed so that we get button/motion events. */ -static double -e_icon_bar_bg_item_point (GnomeCanvasItem *item, double x, double y, - int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - - -static gint -e_icon_bar_bg_item_event (GnomeCanvasItem *item, GdkEvent *event) -{ - EIconBarBgItem *ibitem; - - ibitem = E_ICON_BAR_BG_ITEM (item); - - switch (event->type) { - case GDK_BUTTON_PRESS: - return e_icon_bar_bg_item_button_press (ibitem, event); - case GDK_BUTTON_RELEASE: - return e_icon_bar_bg_item_button_release (ibitem, event); - case GDK_MOTION_NOTIFY: - return e_icon_bar_bg_item_motion_notify (ibitem, event); - default: - break; - } - - return FALSE; -} - - -static gint -e_icon_bar_bg_item_button_press (EIconBarBgItem *ibitem, - GdkEvent *event) -{ - gint item_num; - - if (event->button.button == 4 || event->button.button == 5) - return FALSE; - - item_num = e_icon_bar_find_item_at_position (ibitem->icon_bar, - event->button.x, - event->button.y, - NULL); - e_icon_bar_item_pressed (ibitem->icon_bar, item_num, event); - return TRUE; -} - - -static gint -e_icon_bar_bg_item_button_release (EIconBarBgItem *ibitem, - GdkEvent *event) -{ - gint item_num; - - item_num = e_icon_bar_find_item_at_position (ibitem->icon_bar, - event->button.x, - event->button.y, - NULL); - e_icon_bar_item_released (ibitem->icon_bar, item_num, event); - return TRUE; -} - - -static gint -e_icon_bar_bg_item_motion_notify (EIconBarBgItem *ibitem, - GdkEvent *event) -{ - gint item_num; - - item_num = e_icon_bar_find_item_at_position (ibitem->icon_bar, - event->motion.x, - event->motion.y, - NULL); - e_icon_bar_item_motion (ibitem->icon_bar, item_num, event); - return TRUE; -} diff --git a/widgets/shortcut-bar/e-icon-bar-bg-item.h b/widgets/shortcut-bar/e-icon-bar-bg-item.h deleted file mode 100644 index f8fa14f299..0000000000 --- a/widgets/shortcut-bar/e-icon-bar-bg-item.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * EIconBarBgItem - A GnomeCanvasItem which covers the entire EIconBar. - * It paints the rectangles around items when the mouse moves over them, and - * the lines between items when dragging. - */ - -#ifndef _E_ICON_BAR_BG_ITEM_H_ -#define _E_ICON_BAR_BG_ITEM_H_ - -#include <libgnomeui/gnome-canvas.h> - -#include "e-icon-bar.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define E_ICON_BAR_BG_ITEM(obj) (GTK_CHECK_CAST((obj), e_icon_bar_bg_item_get_type (), EIconBarBgItem)) -#define E_ICON_BAR_BG_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST ((k), e_icon_bar_bg_item_get_type (), EIconBarBgItemClass)) -#define E_IS_ICON_BAR_BG_ITEM(o) (GTK_CHECK_TYPE((o), e_icon_bar_bg_item_get_type ())) - - -typedef struct _EIconBarBgItem EIconBarBgItem; -typedef struct _EIconBarBgItemClass EIconBarBgItemClass; - -struct _EIconBarBgItem -{ - GnomeCanvasItem canvas_item; - - /* The parent EIconBar widget. */ - EIconBar *icon_bar; -}; - - -struct _EIconBarBgItemClass -{ - GnomeCanvasItemClass parent_class; -}; - -GtkType e_icon_bar_bg_item_get_type (void); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_ICON_BAR_BG_ITEM_H_ */ diff --git a/widgets/shortcut-bar/e-icon-bar.c b/widgets/shortcut-bar/e-icon-bar.c deleted file mode 100644 index af5b23a6b3..0000000000 --- a/widgets/shortcut-bar/e-icon-bar.c +++ /dev/null @@ -1,1643 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * EIconBar is a subclass of ECanvas for displaying a vertical column of - * icons and descriptions. It provides 2 views - large icons and small icons. - */ - -#include <config.h> -#include <gtk/gtkmain.h> -#include <gtk/gtksignal.h> -#include <gdk-pixbuf/gnome-canvas-pixbuf.h> -#include "e-icon-bar.h" -#include "e-icon-bar-bg-item.h" -#include "../e-text/e-text.h" -#include "e-util/e-canvas-utils.h" - -/* These are the offsets of the icons & text in both views. Note that the - shadow around icons is drawn in the space between items (as is the - horizontal bar when dragging). */ -#define E_ICON_BAR_LARGE_ICON_SPACING 8 /* Spacing between items. */ -#define E_ICON_BAR_LARGE_ICON_WIDTH 48 -#define E_ICON_BAR_LARGE_ICON_HEIGHT 48 -#define E_ICON_BAR_LARGE_ICON_TEXT_X 4 -#define E_ICON_BAR_LARGE_ICON_TEXT_Y (E_ICON_BAR_LARGE_ICON_HEIGHT + 4) - -#define E_ICON_BAR_SMALL_ICON_SPACING 4 /* Spacing between items. */ -#define E_ICON_BAR_SMALL_ICON_WIDTH 24 -#define E_ICON_BAR_SMALL_ICON_HEIGHT 24 -#define E_ICON_BAR_SMALL_ICON_X 4 -#define E_ICON_BAR_SMALL_ICON_TEXT_X (E_ICON_BAR_SMALL_ICON_WIDTH + 6) - -/* The space we leave at the top or bottom of the bar when position an item - while it is being edited. This is used since the EIconBar may be in a - EScrolledBar which may show buttons at the top or bottom. */ -#define E_ICON_BAR_V_SPACE 22 - -/* The number of pixels the mouse has to be moved with the button down before - we start a drag. */ -#define E_ICON_BAR_DRAG_START_OFFSET 4 - -/* This is the area at the top & bottom of the bar where we auto-scroll if the - mouse goes into during a drag-and-drop operation. */ -#define E_ICON_BAR_DRAG_AUTO_SCROLL_OFFSET 16 - -/* This is the time between each auto-scroll, when dragging. */ -#define E_ICON_BAR_SCROLL_TIMEOUT 30 - -/* This is the number of timeouts we skip before we start scrolling. */ -#define E_ICON_BAR_SCROLL_DELAY 12 - - -static void e_icon_bar_class_init (EIconBarClass *class); -static void e_icon_bar_init (EIconBar *icon_bar); -static void e_icon_bar_destroy (GtkObject *object); -static void e_icon_bar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static gint e_icon_bar_leave_notify_event (GtkWidget *widget, - GdkEventCrossing *event); -static gint e_icon_bar_focus_in (GtkWidget *widget, - GdkEventFocus *event); -static gint e_icon_bar_focus_out (GtkWidget *widget, - GdkEventFocus *event); -static gint e_icon_bar_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time); -static void e_icon_bar_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time); -static void e_icon_bar_set_dragging_before_item (EIconBar *icon_bar, - gint before_item); -static gboolean e_icon_bar_timeout_handler (gpointer data); - -static void e_icon_bar_recalc_common_positions (EIconBar *icon_bar); -static gint e_icon_bar_recalc_item_positions (EIconBar *icon_bar); -static void e_icon_bar_reflow (ECanvas *canvas); -static gint e_icon_bar_find_item (EIconBar *icon_bar, - GnomeCanvasItem *text_item); -static gboolean e_icon_bar_on_item_event (GnomeCanvasItem *item, - GdkEvent *event, - EIconBar *icon_bar); - -static gboolean e_icon_bar_large_icons_intersects (EIconBar *icon_bar, - EIconBarItem *item, - gint x, - gint y); -static gboolean e_icon_bar_large_icons_is_before (EIconBar *icon_bar, - EIconBarItem *item, - gint x, - gint y); -static gboolean e_icon_bar_small_icons_intersects (EIconBar *icon_bar, - EIconBarItem *item, - gint x, - gint y); -static gboolean e_icon_bar_small_icons_is_before (EIconBar *icon_bar, - EIconBarItem *item, - gint x, - gint y); -static void e_icon_bar_on_editing_started (EIconBar *icon_bar, - GnomeCanvasItem *item); -static void e_icon_bar_on_editing_stopped (EIconBar *icon_bar, - GnomeCanvasItem *item); -static void e_icon_bar_ensure_edited_item_visible (EIconBar *icon_bar); -static void e_icon_bar_update_highlight (EIconBar *icon_bar); -static void e_icon_bar_vadjustment_value_changed (GtkAdjustment *adjustment, - EIconBar *icon_bar); -static void e_icon_bar_style_set (GtkWidget *widget, GtkStyle *previous_style); - -enum -{ - ITEM_SELECTED, - ITEM_DRAGGED, - LAST_SIGNAL -}; - -static guint e_icon_bar_signals[LAST_SIGNAL] = {0}; - -static ECanvasClass *parent_class; - - -GtkType -e_icon_bar_get_type (void) -{ - static GtkType e_icon_bar_type = 0; - - if (!e_icon_bar_type){ - GtkTypeInfo e_icon_bar_info = { - "EIconBar", - sizeof (EIconBar), - sizeof (EIconBarClass), - (GtkClassInitFunc) e_icon_bar_class_init, - (GtkObjectInitFunc) e_icon_bar_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - parent_class = gtk_type_class (e_canvas_get_type ()); - e_icon_bar_type = gtk_type_unique (e_canvas_get_type (), - &e_icon_bar_info); - } - - return e_icon_bar_type; -} - - -static void -e_icon_bar_class_init (EIconBarClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - ECanvasClass *ecanvas_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - ecanvas_class = E_CANVAS_CLASS( class ); - - e_icon_bar_signals[ITEM_SELECTED] = - gtk_signal_new ("item_selected", - GTK_RUN_LAST | GTK_RUN_ACTION, - object_class->type, - GTK_SIGNAL_OFFSET (EIconBarClass, - selected_item), - gtk_marshal_NONE__POINTER_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_GDK_EVENT, - GTK_TYPE_INT); - e_icon_bar_signals[ITEM_DRAGGED] = - gtk_signal_new ("item_dragged", - GTK_RUN_LAST | GTK_RUN_ACTION, - object_class->type, - GTK_SIGNAL_OFFSET (EIconBarClass, - dragged_item), - gtk_marshal_NONE__POINTER_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_GDK_EVENT, - GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, e_icon_bar_signals, - LAST_SIGNAL); - - /* Method override */ - object_class->destroy = e_icon_bar_destroy; - - widget_class->size_allocate = e_icon_bar_size_allocate; - widget_class->leave_notify_event = e_icon_bar_leave_notify_event; - widget_class->focus_in_event = e_icon_bar_focus_in; - widget_class->focus_out_event = e_icon_bar_focus_out; - widget_class->drag_motion = e_icon_bar_drag_motion; - widget_class->drag_leave = e_icon_bar_drag_leave; - widget_class->style_set = e_icon_bar_style_set; - - ecanvas_class->reflow = e_icon_bar_reflow; - - class->selected_item = NULL; -} - - -static void -e_icon_bar_init (EIconBar *icon_bar) -{ - GdkColormap *colormap; - gboolean success[E_ICON_BAR_COLOR_LAST]; - gint nfailed; - - icon_bar->view_type = E_ICON_BAR_LARGE_ICONS; - icon_bar->items = g_array_new (FALSE, FALSE, sizeof (EIconBarItem)); - icon_bar->pressed_item_num = -1; - icon_bar->mouse_over_item_num = -1; - icon_bar->editing_item_num = -1; - icon_bar->edit_rect_item = NULL; - icon_bar->in_drag = FALSE; - icon_bar->dragging_before_item_num = -1; - icon_bar->icon_x = 0; - icon_bar->icon_w = 0; - icon_bar->icon_h = 0; - icon_bar->text_x = 0; - icon_bar->text_w = 5; - icon_bar->auto_scroll_timeout_id = 0; - icon_bar->vadjustment_value_changed_id = 0; - - /* Create the background item in the canvas, which handles selections - and drag-and-drop. */ - gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (icon_bar)->root), - e_icon_bar_bg_item_get_type (), - "EIconBarBgItem::icon_bar", icon_bar, - NULL); - - colormap = gtk_widget_get_colormap (GTK_WIDGET (icon_bar)); - - icon_bar->colors[E_ICON_BAR_COLOR_EDITING_TEXT].red = 0; - icon_bar->colors[E_ICON_BAR_COLOR_EDITING_TEXT].green = 0; - icon_bar->colors[E_ICON_BAR_COLOR_EDITING_TEXT].blue = 0; - - icon_bar->colors[E_ICON_BAR_COLOR_EDITING_RECT].red = 65535; - icon_bar->colors[E_ICON_BAR_COLOR_EDITING_RECT].green = 65535; - icon_bar->colors[E_ICON_BAR_COLOR_EDITING_RECT].blue = 65535; - - icon_bar->colors[E_ICON_BAR_COLOR_EDITING_RECT_OUTLINE].red = 0; - icon_bar->colors[E_ICON_BAR_COLOR_EDITING_RECT_OUTLINE].green = 0; - icon_bar->colors[E_ICON_BAR_COLOR_EDITING_RECT_OUTLINE].blue = 0; - - nfailed = gdk_colormap_alloc_colors (colormap, icon_bar->colors, - E_ICON_BAR_COLOR_LAST, FALSE, - TRUE, success); - if (nfailed) - g_warning ("Failed to allocate all colors"); -} - - -/** - * e_icon_bar_new: - * @Returns: A new #EIconBar. - * - * Creates a new #EIconBar. - **/ -GtkWidget * -e_icon_bar_new (void) -{ - GtkWidget *icon_bar; - - icon_bar = GTK_WIDGET (gtk_type_new (e_icon_bar_get_type ())); - - return icon_bar; -} - - -static void -e_icon_bar_destroy (GtkObject *object) -{ - EIconBar *icon_bar; - int item_num; - EIconBarItem *item; - - icon_bar = E_ICON_BAR (object); - - for (item_num = 0; item_num < icon_bar->items->len; item_num++) { - item = &g_array_index (icon_bar->items, - EIconBarItem, item_num); - if (item->destroy) - item->destroy (item->data); - } - - g_array_free (icon_bar->items, TRUE); - - if (icon_bar->auto_scroll_timeout_id != 0) { - gtk_timeout_remove (icon_bar->auto_scroll_timeout_id); - icon_bar->auto_scroll_timeout_id = 0; - } - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - - -static void -e_icon_bar_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - EIconBar *icon_bar; - gint canvas_width, canvas_height, height; -#if 0 - g_print ("In e_icon_bar_size_allocate\n"); -#endif - icon_bar = E_ICON_BAR (widget); - - GTK_WIDGET_CLASS (parent_class)->size_allocate (widget, allocation); - - canvas_width = GTK_WIDGET (icon_bar)->allocation.width; - canvas_height = GTK_WIDGET (icon_bar)->allocation.height; - - /* Reset the y position and widths of all the items to the width of - the canvas, and reset the button labels, so they fit. */ - e_icon_bar_recalc_common_positions (icon_bar); - height = e_icon_bar_recalc_item_positions (icon_bar); - - gnome_canvas_set_scroll_region (GNOME_CANVAS (widget), - 0, 0, canvas_width, - MAX (height, canvas_height - 1)); - - /* If we are editing an item, make sure it is visible. */ - e_icon_bar_ensure_edited_item_visible (icon_bar); - - GTK_LAYOUT (widget)->vadjustment->step_increment = 16; - if (icon_bar->vadjustment_value_changed_id == 0) - icon_bar->vadjustment_value_changed_id = gtk_signal_connect (GTK_OBJECT (GTK_LAYOUT (widget)->vadjustment), "value_changed", GTK_SIGNAL_FUNC (e_icon_bar_vadjustment_value_changed), icon_bar); - - e_icon_bar_update_highlight (icon_bar); -} - - -/* This sets all the item positions which are the same for all items in the - group. */ -static void -e_icon_bar_recalc_common_positions (EIconBar *icon_bar) -{ - gint canvas_width; - - canvas_width = GTK_WIDGET (icon_bar)->allocation.width; - - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) { - icon_bar->icon_x = (canvas_width - E_ICON_BAR_LARGE_ICON_WIDTH) / 2; - icon_bar->icon_w = E_ICON_BAR_LARGE_ICON_WIDTH; - icon_bar->icon_h = E_ICON_BAR_LARGE_ICON_HEIGHT; - - icon_bar->text_x = E_ICON_BAR_LARGE_ICON_TEXT_X; - icon_bar->text_w = MAX (canvas_width - (E_ICON_BAR_LARGE_ICON_TEXT_X * 2), 5); - - icon_bar->spacing = E_ICON_BAR_LARGE_ICON_SPACING; - } else { - icon_bar->icon_x = E_ICON_BAR_SMALL_ICON_X; - icon_bar->icon_w = E_ICON_BAR_SMALL_ICON_WIDTH; - icon_bar->icon_h = E_ICON_BAR_SMALL_ICON_HEIGHT; - - icon_bar->text_x = E_ICON_BAR_SMALL_ICON_TEXT_X; - icon_bar->text_w = MAX (canvas_width - E_ICON_BAR_SMALL_ICON_TEXT_X, 5); - - icon_bar->spacing = E_ICON_BAR_SMALL_ICON_SPACING; - } -} - - -/* This recalculates the positions of all the items, according to the current - view type and the height of the text items. */ -static gint -e_icon_bar_recalc_item_positions (EIconBar *icon_bar) -{ - EIconBarItem *item; - gint y, item_num, text_h; - gdouble x1, y1, x2, y2, text_x; - GtkJustification justify; - GtkAnchorType anchor; - gint max_lines; - GdkFont *font; - gboolean line_wrap; - - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) { - justify = GTK_JUSTIFY_CENTER; - anchor = GTK_ANCHOR_N; - max_lines = 2; - text_x = icon_bar->text_x + (icon_bar->text_w / 2); - line_wrap = TRUE; - - /* - * Fixme: incorrect - */ - font = GTK_WIDGET (icon_bar)->style->font; - text_h = font->ascent + font->descent; - } else { - justify = GTK_JUSTIFY_LEFT; - anchor = GTK_ANCHOR_NW; - max_lines = 1; - text_x = icon_bar->text_x; - font = GTK_WIDGET (icon_bar)->style->font; - text_h = font->ascent + font->descent; - line_wrap = FALSE; - } - - /* Now step through the items, setting the y positions. */ - y = icon_bar->spacing; - for (item_num = 0; item_num < icon_bar->items->len; item_num++) { - item = &g_array_index (icon_bar->items, - EIconBarItem, item_num); - - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) { - item->icon_y = y; - item->text_y = y + E_ICON_BAR_LARGE_ICON_TEXT_Y; - } else { - item->text_height = text_h; - item->item_height = MAX (text_h, E_ICON_BAR_SMALL_ICON_HEIGHT); - item->icon_y = y + (item->item_height - E_ICON_BAR_SMALL_ICON_HEIGHT) / 2; - item->text_y = y + (item->item_height - item->text_height) / 2; - } - - gnome_canvas_item_set (item->text, - "clip_width", (gdouble) (icon_bar->text_w), - "justification", justify, - "anchor", anchor, - "max_lines", max_lines, - "line_wrap", line_wrap, - NULL); - e_canvas_item_move_absolute(item->text, - text_x, item->text_y); - - /* Get the text item's height. */ - gnome_canvas_item_get_bounds (item->text, &x1, &y1, &x2, &y2); - item->text_x = x1; - item->text_width = x2 - x1; - item->text_height = y2 - y1; - - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) { - item->item_height = E_ICON_BAR_LARGE_ICON_TEXT_Y - + item->text_height; - } - - gnome_canvas_item_set (item->image, - "GnomeCanvasPixbuf::x", (gdouble)icon_bar->icon_x, - "GnomeCanvasPixbuf::y", (gdouble)item->icon_y, - "GnomeCanvasPixbuf::width_set", TRUE, - "GnomeCanvasPixbuf::height_set", TRUE, - "GnomeCanvasPixbuf::width", (gdouble)icon_bar->icon_w, - "GnomeCanvasPixbuf::height", (gdouble)icon_bar->icon_h, - NULL); - - y += item->item_height + icon_bar->spacing; - } - - return y; -} - - -static gint -e_icon_bar_leave_notify_event (GtkWidget *widget, GdkEventCrossing *event) -{ - EIconBar *icon_bar; - - icon_bar = E_ICON_BAR (widget); - - GTK_WIDGET_CLASS (parent_class)->leave_notify_event (widget, event); - - /* Make sure no items are highlighted. */ - e_icon_bar_item_motion (icon_bar, -1, NULL); - - return FALSE; -} - - -static gint -e_icon_bar_focus_in (GtkWidget *widget, - GdkEventFocus *event) -{ - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_ICON_BAR (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - GTK_WIDGET_CLASS (parent_class)->focus_in_event (widget, event); - GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS); - return FALSE; -} - - -static gint -e_icon_bar_focus_out (GtkWidget *widget, - GdkEventFocus *event) -{ - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (E_IS_ICON_BAR (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - GTK_WIDGET_CLASS (parent_class)->focus_out_event (widget, event); - GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS); - return FALSE; -} - - -/** - * e_icon_bar_set_view_type: - * @icon_bar: An #EIconBar. - * @view_type: The new view type, %E_ICON_BAR_LARGE_ICONS or - * %E_ICON_BAR_SMALL_ICONS. - * - * Sets the view type of the #EIconBar. - **/ -void -e_icon_bar_set_view_type (EIconBar *icon_bar, - EIconBarViewType view_type) -{ - g_return_if_fail (E_IS_ICON_BAR (icon_bar)); - - if (icon_bar->view_type == view_type) - return; - - icon_bar->view_type = view_type; - - /* Queue a resize of the canvas, so everything is put in the right - positions based on the new view type. */ - gtk_widget_queue_resize (GTK_WIDGET (icon_bar)); -} - -static GdkPixbuf * -flatten_alpha (GdkPixbuf *image, guint rgb) -{ - if (!image || !gdk_pixbuf_get_has_alpha (image)) - return NULL; - - - return gdk_pixbuf_composite_color_simple ( - image, - gdk_pixbuf_get_width (image), - gdk_pixbuf_get_height (image), - GDK_INTERP_NEAREST, - 255, - 32, - rgb, rgb); -} - -/* - * Creates a 24-bits RGB value from a GdkColor - */ -static guint -rgb_from_gdk_color (GdkColor *color) -{ - guint a = - (((color->red >> 8) << 16) | - ((color->green >> 8) << 8) | - ((color->blue >> 8))); - - return a; -} - -static void -e_icon_bar_style_set (GtkWidget *widget, GtkStyle *previous_style) { - EIconBar *icon_bar; - EIconBarItem *item; - gint item_num; - GdkPixbuf *flattened; - GtkStyle *style = widget->style; - GdkColormap *colormap; - - colormap = gtk_widget_get_colormap (widget); - gdk_color_alloc (colormap, &style->fg [GTK_STATE_NORMAL]); - - icon_bar = E_ICON_BAR (widget); - - for (item_num = 0; item_num < icon_bar->items->len; item_num++) { - - item = &g_array_index (icon_bar->items, - EIconBarItem, item_num); - - flattened = flatten_alpha (item->pixbuf, - rgb_from_gdk_color (&style->bg [GTK_STATE_NORMAL])); - - gnome_canvas_item_set(item->image, - "GnomeCanvasPixbuf::pixbuf", flattened ? flattened : item->pixbuf, - NULL); - gnome_canvas_item_set (item->text, - "font_gdk", style->font, - "fill_color_gdk", &style->fg [GTK_STATE_NORMAL], - NULL); - - if (flattened) - /* the canvas item holds the reference now */ - gdk_pixbuf_unref (flattened); - - } - - e_icon_bar_recalc_item_positions (icon_bar); -} - - -/** - * e_icon_bar_add_item: - * @icon_bar: An #EIconBar. - * @image: the new item's icon. - * @text: the new item's text. - * @position: the position to place the new item, or -1 to place it last. - * - * Adds an item to the #EIconBar at the given position. - **/ -gint -e_icon_bar_add_item (EIconBar *icon_bar, - GdkPixbuf *image, - const gchar *text, - gint position) -{ - EIconBarItem item; - GtkJustification justify; - GtkAnchorType anchor; - gint max_lines, retval; - GtkStyle *style; - GdkFont *font; - gdouble text_x, clip_height; - GdkPixbuf *flattened = NULL; - - g_return_val_if_fail (E_IS_ICON_BAR (icon_bar), -1); - g_return_val_if_fail (text != NULL, -1); - g_return_val_if_fail (position >= -1, -1); - g_return_val_if_fail (position <= (gint)icon_bar->items->len, -1); - - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) { - justify = GTK_JUSTIFY_CENTER; - anchor = GTK_ANCHOR_N; - max_lines = 2; - text_x = icon_bar->text_x + (icon_bar->text_w / 2); - } else { - justify = GTK_JUSTIFY_LEFT; - anchor = GTK_ANCHOR_NW; - max_lines = 1; - text_x = icon_bar->text_x; - } - - gtk_widget_ensure_style (GTK_WIDGET (icon_bar)); - style = GTK_WIDGET (icon_bar)->style; - font = style->font; - clip_height = max_lines * (font->ascent + font->descent); - item.text = gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (icon_bar)->root), - e_text_get_type (), - "font_gdk", font, - "fill_color_gdk", &style->fg [GTK_STATE_NORMAL], - "use_ellipsis", TRUE, - "anchor", anchor, - "editable", TRUE, - "justification", justify, - "line_wrap", TRUE, - "max_lines", max_lines, - "clip", TRUE, - "clip_width", (gdouble) (icon_bar->text_w), - "clip_height", clip_height, - "text", text, - NULL); - e_canvas_item_move_absolute(item.text, - text_x, 0); - - gtk_signal_connect (GTK_OBJECT (item.text), "event", - GTK_SIGNAL_FUNC (e_icon_bar_on_item_event), - icon_bar); - - item.pixbuf = image; - gdk_pixbuf_ref (image); - - flattened = flatten_alpha (image, - rgb_from_gdk_color (&style->bg [GTK_STATE_NORMAL])); - - item.image = gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (icon_bar)->root), - gnome_canvas_pixbuf_get_type (), - "GnomeCanvasPixbuf::pixbuf", flattened ? flattened : image, - "GnomeCanvasPixbuf::width", (gdouble) icon_bar->icon_w, - "GnomeCanvasPixbuf::height", (gdouble) icon_bar->icon_h, - NULL); - - - if (flattened) - /* the canvas item holds the reference now */ - gdk_pixbuf_unref (flattened); - - gtk_signal_connect (GTK_OBJECT (item.image), "event", - GTK_SIGNAL_FUNC (e_icon_bar_on_item_event), - icon_bar); - - item.data = NULL; - item.destroy = NULL; - - if (position == -1) { - g_array_append_val (icon_bar->items, item); - retval = icon_bar->items->len - 1; - } else { - g_array_insert_val (icon_bar->items, position, item); - retval = position; - - /* FIXME: Should possibly update other indices. */ - if (icon_bar->dragged_item_num >= position) - icon_bar->dragged_item_num++; - } - - gtk_widget_queue_resize (GTK_WIDGET (icon_bar)); - - return retval; -} - - -/** - * e_icon_bar_reorder_item: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item to move. - * @new_position: The new position of the item, which is used after the item - * has been removed from its current position. If @new_position is -1, the item - * is placed last. - * - * Moves an item to a new position within the #EIconBar. - **/ -void -e_icon_bar_reorder_item (EIconBar *icon_bar, - gint item_num, - gint new_position) -{ - EIconBarItem tmp_item; - - g_return_if_fail (E_IS_ICON_BAR (icon_bar)); - g_return_if_fail (item_num >= 0); - g_return_if_fail (item_num < icon_bar->items->len); - g_return_if_fail (new_position >= -1); - g_return_if_fail (new_position < icon_bar->items->len); - - tmp_item = g_array_index (icon_bar->items, EIconBarItem, item_num); - g_array_remove_index (icon_bar->items, item_num); - - if (new_position == -1) - g_array_append_val (icon_bar->items, tmp_item); - else - g_array_insert_val (icon_bar->items, new_position, tmp_item); - - gtk_widget_queue_resize (GTK_WIDGET (icon_bar)); -} - - -/** - * e_icon_bar_remove_item: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item to remove. - * - * Removes an item from the #EIconBar. - **/ -void -e_icon_bar_remove_item (EIconBar *icon_bar, - gint item_num) -{ - EIconBarItem *item; - - g_return_if_fail (E_IS_ICON_BAR (icon_bar)); - g_return_if_fail (item_num >= 0); - g_return_if_fail (item_num < icon_bar->items->len); - - item = &g_array_index (icon_bar->items, EIconBarItem, item_num); - - if (item->destroy) - item->destroy (item->data); - - gtk_object_destroy (GTK_OBJECT (item->text)); - gtk_object_destroy (GTK_OBJECT (item->image)); - gdk_pixbuf_unref (item->pixbuf); - - g_array_remove_index (icon_bar->items, item_num); - - gtk_widget_queue_resize (GTK_WIDGET (icon_bar)); -} - - -/** - * e_icon_bar_get_item_image: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item. - * @Returns: The icon of the given item. - * - * Returns the icon used for the given item. - **/ -GdkPixbuf * -e_icon_bar_get_item_image (EIconBar *icon_bar, - gint item_num) -{ - EIconBarItem *item; - GdkPixbuf *image = NULL; - - g_return_val_if_fail (E_IS_ICON_BAR (icon_bar), NULL); - g_return_val_if_fail (item_num >= 0, NULL); - g_return_val_if_fail (item_num < icon_bar->items->len, NULL); - - item = &g_array_index (icon_bar->items, EIconBarItem, item_num); - gtk_object_get (GTK_OBJECT (item->image), - "GnomeCanvasPixbuf::pixbuf", &image, - NULL); - return image; -} - - -/** - * e_icon_bar_set_item_image: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item. - * @image: The new icon to use for the given item. - * - * Sets the icon to use for the given item. - **/ -void -e_icon_bar_set_item_image (EIconBar *icon_bar, - gint item_num, - GdkPixbuf *image) -{ - EIconBarItem *item; - - g_return_if_fail (E_IS_ICON_BAR (icon_bar)); - g_return_if_fail (item_num >= 0); - g_return_if_fail (item_num < icon_bar->items->len); - - item = &g_array_index (icon_bar->items, EIconBarItem, item_num); - gnome_canvas_item_set (item->image, - "GnomeCanvasPixbuf::pixbuf", image, - NULL); -} - - -/** - * e_icon_bar_get_item_text: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item. - * @Returns: The text of the given item. - * - * Returns the text of the given item. This should be freed when no longer - * needed. - **/ -gchar* -e_icon_bar_get_item_text (EIconBar *icon_bar, - gint item_num) -{ - EIconBarItem *item; - gchar *text; - - g_return_val_if_fail (E_IS_ICON_BAR (icon_bar), NULL); - g_return_val_if_fail (item_num >= 0, NULL); - g_return_val_if_fail (item_num < icon_bar->items->len, NULL); - - item = &g_array_index (icon_bar->items, EIconBarItem, item_num); - gtk_object_get (GTK_OBJECT (item->text), - "EText::text", &text, - NULL); - - return text; -} - - -/** - * e_icon_bar_set_item_text: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item. - * @text: The new text for the given item. - * - * Sets the text of the given item. - **/ -void -e_icon_bar_set_item_text (EIconBar *icon_bar, - gint item_num, - gchar *text) -{ - EIconBarItem *item; - - g_return_if_fail (E_IS_ICON_BAR (icon_bar)); - g_return_if_fail (item_num >= 0); - g_return_if_fail (item_num < icon_bar->items->len); - - item = &g_array_index (icon_bar->items, EIconBarItem, item_num); - gnome_canvas_item_set (item->text, - "EText::text", text, - NULL); -} - - -/** - * e_icon_bar_get_item_data: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item. - * @Returns: The user data associated with the given item. - * - * Returns the user data associated with the given item. - **/ -gpointer -e_icon_bar_get_item_data (EIconBar *icon_bar, - gint item_num) -{ - EIconBarItem *item; - - g_return_val_if_fail (E_IS_ICON_BAR (icon_bar), NULL); - g_return_val_if_fail (item_num >= 0, NULL); - g_return_val_if_fail (item_num < icon_bar->items->len, NULL); - - item = &g_array_index (icon_bar->items, EIconBarItem, item_num); - return item->data; -} - - -/** - * e_icon_bar_set_item_data: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item. - * @data: The user data to set for the given item. - * - * Sets the user data of the given item. - **/ -void -e_icon_bar_set_item_data (EIconBar *icon_bar, - gint item_num, - gpointer data) -{ - e_icon_bar_set_item_data_full (icon_bar, item_num, data, NULL); -} - - -/** - * e_icon_bar_set_item_data_full: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item. - * @data: The user data to set for the given item. - * @destroy: The function to free @data when the item is destroyed. - * - * Sets the user data of the given item, and the function to free the data - * when the item is destroyed. - **/ -void -e_icon_bar_set_item_data_full (EIconBar *icon_bar, - gint item_num, - gpointer data, - GtkDestroyNotify destroy) -{ - EIconBarItem *item; - - g_return_if_fail (E_IS_ICON_BAR (icon_bar)); - g_return_if_fail (item_num >= 0); - g_return_if_fail (item_num < icon_bar->items->len); - - item = &g_array_index (icon_bar->items, EIconBarItem, item_num); - - if (item->destroy) - item->destroy (item->data); - - item->data = data; - item->destroy = destroy; -} - - -static void -e_icon_bar_reflow (ECanvas *canvas) -{ -#if 0 - g_print ("In e_icon_bar_on_canvas_reflow\n"); - gtk_widget_queue_resize (GTK_WIDGET (canvas)); -#endif -} - - -/* This returns the index of the given item, or -1 if it isn't found. */ -static gint -e_icon_bar_find_item (EIconBar *icon_bar, - GnomeCanvasItem *canvas_item) -{ - EIconBarItem *item; - gint item_num; - - for (item_num = 0; item_num < icon_bar->items->len; item_num++) { - item = &g_array_index (icon_bar->items, - EIconBarItem, item_num); - - if (item->text == canvas_item || item->image == canvas_item) { - return item_num; - } - } - - return -1; -} - - -/* When an item has a grab, it will get all events, so we need to use the - position to find the real item. */ -static gboolean -e_icon_bar_on_item_event (GnomeCanvasItem *item, - GdkEvent *event, - EIconBar *icon_bar) -{ - gint item_num; - - switch (event->type) { - case GDK_BUTTON_PRESS: - if (event->button.button == 4 || event->button.button == 5) - return FALSE; - - item_num = e_icon_bar_find_item_at_position (icon_bar, - event->button.x, - event->button.y, - NULL); - /* If the item is not being edited, we handle the event and - stop the signal so the text editing isn't started. */ - if (icon_bar->editing_item_num == -1 - || icon_bar->editing_item_num != item_num) { - e_icon_bar_item_pressed (icon_bar, item_num, event); - gtk_signal_emit_stop_by_name (GTK_OBJECT (item), - "event"); - return TRUE; - } - break; - case GDK_BUTTON_RELEASE: - item_num = e_icon_bar_find_item_at_position (icon_bar, - event->button.x, - event->button.y, - NULL); - /* If the item is not being edited, we handle the event and - stop the signal so the text editing isn't started. */ - if (icon_bar->editing_item_num == -1 - || icon_bar->editing_item_num != item_num) { - e_icon_bar_item_released (icon_bar, item_num, event); - gtk_signal_emit_stop_by_name (GTK_OBJECT (item), - "event"); - return TRUE; - } - break; - case GDK_MOTION_NOTIFY: - item_num = e_icon_bar_find_item_at_position (icon_bar, - event->motion.x, - event->motion.y, - NULL); - e_icon_bar_item_motion (icon_bar, item_num, event); - return TRUE; - case GDK_FOCUS_CHANGE: - if (event->focus_change.in) - e_icon_bar_on_editing_started (icon_bar, item); - else - e_icon_bar_on_editing_stopped (icon_bar, item); - - return FALSE; - default: - break; - } - - return FALSE; -} - - -void -e_icon_bar_item_pressed (EIconBar *icon_bar, - gint item_num, - GdkEvent *event) -{ - gint button; - - /* If we are editing an item, and a different item (or anywhere outside - an item) is clicked, stop the edit. If the item being edited is - clicked we just return, since the user may be selecting text. */ - if (icon_bar->editing_item_num != -1) { - if (icon_bar->editing_item_num != item_num) { - e_icon_bar_stop_editing_item (icon_bar, TRUE); - } - return; - } - - button = event->button.button; - - if (button == 1 && item_num != -1) { - icon_bar->mouse_over_item_num = item_num; - icon_bar->pressed_item_num = item_num; - icon_bar->pressed_x = event->button.x; - icon_bar->pressed_y = event->button.y; - gtk_widget_queue_draw (GTK_WIDGET (icon_bar)); - } else if (button == 3) { - gtk_signal_emit (GTK_OBJECT (icon_bar), - e_icon_bar_signals[ITEM_SELECTED], - event, item_num); - } -} - - -void -e_icon_bar_item_released (EIconBar *icon_bar, - gint item_num, - GdkEvent *event) -{ - gint button; - - /* If we are editing an item, just return. */ - if (icon_bar->editing_item_num != -1) - return; - - button = event->button.button; - - if (button == 1) { - if (icon_bar->pressed_item_num != -1 - && icon_bar->pressed_item_num == icon_bar->mouse_over_item_num) { - gtk_signal_emit (GTK_OBJECT (icon_bar), - e_icon_bar_signals[ITEM_SELECTED], - event, item_num); - } - - icon_bar->pressed_item_num = -1; - gtk_widget_queue_draw (GTK_WIDGET (icon_bar)); - } -} - - -void -e_icon_bar_item_motion (EIconBar *icon_bar, - gint item_num, - GdkEvent *event) -{ - gboolean need_redraw = TRUE; - - if (event && event->motion.state & GDK_BUTTON1_MASK - && icon_bar->pressed_item_num != -1) { - if (abs (event->motion.x - icon_bar->pressed_x) > E_ICON_BAR_DRAG_START_OFFSET - || abs (event->motion.y - icon_bar->pressed_y) > E_ICON_BAR_DRAG_START_OFFSET) { - icon_bar->dragged_item_num = icon_bar->pressed_item_num; - gtk_signal_emit (GTK_OBJECT (icon_bar), - e_icon_bar_signals[ITEM_DRAGGED], - event, icon_bar->dragged_item_num); - - /* Don't show the button as pressed while dragging. */ - icon_bar->pressed_item_num = -1; - gtk_widget_queue_draw (GTK_WIDGET (icon_bar)); - } - - return; - } - - if (icon_bar->mouse_over_item_num == item_num) - return; - - /* If we are editing an item, items aren't highlighted so we don't - need a redraw. Also if an item is pressed, we only need a redraw if - item_num or the old mouse_over_item_num is the pressed item. */ - if (icon_bar->editing_item_num != -1) { - need_redraw = FALSE; - } else if (icon_bar->pressed_item_num != -1) { - if (icon_bar->pressed_item_num != item_num - && icon_bar->pressed_item_num != icon_bar->mouse_over_item_num) - need_redraw = FALSE; - } - - icon_bar->mouse_over_item_num = item_num; - - if (need_redraw) - gtk_widget_queue_draw (GTK_WIDGET (icon_bar)); -} - - -/* This returns the index of the item at the given position on the EIconBar, - or -1 if no item is found. If before_item is not NULL, it returns the - item which the mouse is before, or -1 (for dragging). */ -gint -e_icon_bar_find_item_at_position (EIconBar *icon_bar, - gint x, - gint y, - gint *before_item) -{ - EIconBarItem *item = NULL; - gint item_num; - - if (before_item) - *before_item = -1; - - for (item_num = 0; item_num < icon_bar->items->len; item_num++) { - item = &g_array_index (icon_bar->items, - EIconBarItem, item_num); - - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) { - if (e_icon_bar_large_icons_intersects (icon_bar, item, - x, y)) - return item_num; - - if (before_item - && e_icon_bar_large_icons_is_before (icon_bar, - item, x, y)) { - *before_item = item_num; - return -1; - } - } else { - if (e_icon_bar_small_icons_intersects (icon_bar, item, - x, y)) - return item_num; - - if (before_item - && e_icon_bar_small_icons_is_before (icon_bar, - item, x, y)) { - *before_item = item_num; - return -1; - } - - } - - } - - /* If the mouse is below all the items, but inside the items' width, - and before_item is not NULL, we set it to the number of items, so - the dropped item would be added at the end. Note that this assumes - that the item variable points to the last item in the EIconBar. */ - if (before_item) { - if (icon_bar->view_type == E_ICON_BAR_LARGE_ICONS) { - if (x < icon_bar->text_x - || x >= icon_bar->text_x + icon_bar->text_w) - return -1; - - if (item == NULL - || y > item->icon_y + item->item_height) - *before_item = icon_bar->items->len; - } else { - if (x < icon_bar->icon_x - || x >= icon_bar->text_x + icon_bar->text_w) - return -1; - - if (item == NULL) { - *before_item = icon_bar->items->len; - } else { - gint max_y; - max_y = MAX (item->icon_y + icon_bar->icon_h, - item->text_y + item->text_height); - if (y > max_y) - *before_item = icon_bar->items->len; - } - } - } - - return -1; -} - - -static gboolean -e_icon_bar_large_icons_intersects (EIconBar *icon_bar, - EIconBarItem *item, - gint x, - gint y) -{ - if (y < item->icon_y || y >= item->text_y + item->text_height) - return FALSE; - - if (y < item->icon_y + icon_bar->icon_h) { - if (x < icon_bar->icon_x - || x >= icon_bar->icon_x + icon_bar->icon_w) - return FALSE; - } else { - if (x < item->text_x - || x >= item->text_x + item->text_width) - return FALSE; - } - - return TRUE; -} - - -static gboolean -e_icon_bar_large_icons_is_before (EIconBar *icon_bar, - EIconBarItem *item, - gint x, - gint y) -{ - if (y < item->icon_y - icon_bar->spacing - || y >= item->icon_y) - return FALSE; - - if (x < icon_bar->text_x || x >= icon_bar->text_x + icon_bar->text_w) - return FALSE; - - return TRUE; -} - - -static gboolean -e_icon_bar_small_icons_intersects (EIconBar *icon_bar, - EIconBarItem *item, - gint x, - gint y) -{ - gint min_y, max_y; - - min_y = MIN (item->icon_y, item->text_y); - max_y = MAX (item->icon_y + icon_bar->icon_h, - item->text_y + item->text_height); - - if (y < min_y || y >= max_y) - return FALSE; - - if (x < icon_bar->icon_x || x >= item->text_x + item->text_width) - return FALSE; - - return TRUE; -} - - -static gboolean -e_icon_bar_small_icons_is_before (EIconBar *icon_bar, - EIconBarItem *item, - gint x, - gint y) -{ - gint min_y, max_y; - - max_y = MIN (item->icon_y, item->text_y); - min_y = max_y - icon_bar->spacing; - - if (y < min_y || y >= max_y) - return FALSE; - - if (x < icon_bar->icon_x || x >= icon_bar->text_x + icon_bar->text_w) - return FALSE; - - return TRUE; -} - - -/** - * e_icon_bar_start_editing_item: - * @icon_bar: An #EIconBar. - * @item_num: The index of the item. - * - * Turns the item into an editable text field so the user can rename it. - * Editing is stopped automatically when the user hits 'Return' or clicks - * outside the item. It can also be stopped explicitly by calling - * e_icon_bar_stop_editing_item(). - **/ -void -e_icon_bar_start_editing_item (EIconBar *icon_bar, - gint item_num) -{ - EIconBarItem *item; - - g_return_if_fail (E_IS_ICON_BAR (icon_bar)); - g_return_if_fail (item_num >= 0); - g_return_if_fail (item_num < icon_bar->items->len); - - item = &g_array_index (icon_bar->items, - EIconBarItem, item_num); - e_canvas_item_grab_focus (item->text); -} - - -/** - * e_icon_bar_stop_editing_item: - * @icon_bar: An #EIconBar. - * @accept: TRUE if the changes should be accepted, FALSE if the text should be - * changed back to its state before the editing started. - * - * Stops the editing of the items, if any were being edited. - **/ -void -e_icon_bar_stop_editing_item (EIconBar *icon_bar, - gboolean accept) -{ - EIconBarItem *item; - GtkWidget *toplevel; - - g_return_if_fail (E_IS_ICON_BAR (icon_bar)); - - if (icon_bar->editing_item_num != -1) { - item = &g_array_index (icon_bar->items, EIconBarItem, - icon_bar->editing_item_num); - - toplevel = gtk_widget_get_toplevel (GTK_WIDGET (icon_bar)); - if (toplevel && GTK_IS_WINDOW (toplevel)) - gtk_window_set_focus (GTK_WINDOW (toplevel), NULL); - } -} - - -static void -e_icon_bar_on_editing_started (EIconBar *icon_bar, - GnomeCanvasItem *item) -{ - gint item_num; - gdouble x1, y1, x2, y2; - - item_num = e_icon_bar_find_item (icon_bar, item); - g_return_if_fail (item_num != -1); - - /* Turn off any highlighted item. */ - e_icon_bar_item_motion (icon_bar, -1, NULL); - - icon_bar->editing_item_num = item_num; - - e_icon_bar_ensure_edited_item_visible (icon_bar); - - /* Set the fg & bg colors. */ - gnome_canvas_item_set (item, - "fill_color_gdk", &icon_bar->colors[E_ICON_BAR_COLOR_EDITING_TEXT], - NULL); - - /* Create the edit rect if necessary. */ - if (!icon_bar->edit_rect_item) { - icon_bar->edit_rect_item = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (icon_bar)->root), - gnome_canvas_rect_get_type(), - "fill_color_gdk", &icon_bar->colors[E_ICON_BAR_COLOR_EDITING_RECT], - "outline_color_gdk", &icon_bar->colors[E_ICON_BAR_COLOR_EDITING_RECT_OUTLINE], - NULL); - } - - gnome_canvas_item_get_bounds (item, &x1, &y1, &x2, &y2); - gnome_canvas_item_set (icon_bar->edit_rect_item, - "x1", x1 - 1, - "y1", y1 - 1, - "x2", x2 + 1, - "y2", y2 + 1, - NULL); - gnome_canvas_item_show (icon_bar->edit_rect_item); - - /* Make sure the text item is on top. */ - gnome_canvas_item_raise_to_top (item); -} - - -static void -e_icon_bar_on_editing_stopped (EIconBar *icon_bar, - GnomeCanvasItem *item) -{ - gint item_num; - - item_num = e_icon_bar_find_item (icon_bar, item); - g_return_if_fail (item_num != -1); - - icon_bar->editing_item_num = -1; - - e_icon_bar_update_highlight (icon_bar); - - /* Reset the fg & bg colors. */ - gnome_canvas_item_set (item, - "fill_color_gdk", &(GTK_WIDGET(icon_bar)->style->fg [GTK_STATE_NORMAL]), - NULL); - - if (icon_bar->edit_rect_item) { - gnome_canvas_item_hide (icon_bar->edit_rect_item); - } -} - - -static void -e_icon_bar_ensure_edited_item_visible (EIconBar *icon_bar) -{ - EIconBarItem *item; - gint scroll_x, scroll_y, min_scroll_y, max_scroll_y, new_scroll_y; - - if (icon_bar->editing_item_num == -1) - return; - - item = &g_array_index (icon_bar->items, - EIconBarItem, icon_bar->editing_item_num); - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (icon_bar), - &scroll_x, &scroll_y); - - /* The minimum scroll y position is with the text right on the bottom - of the display. */ - min_scroll_y = item->text_y + item->text_height + E_ICON_BAR_V_SPACE - - GTK_WIDGET (icon_bar)->allocation.height; - /* The maximum scroll y position is with the text at the top. */ - max_scroll_y = item->text_y - E_ICON_BAR_V_SPACE; - - new_scroll_y = MAX (scroll_y, min_scroll_y); - new_scroll_y = MIN (new_scroll_y, max_scroll_y); - - if (new_scroll_y != scroll_y) - gnome_canvas_scroll_to (GNOME_CANVAS (icon_bar), - scroll_x, new_scroll_y); -} - - -/* This gets the mouse position and updates the highlight if necessary. - It is called after items are added/deleted/scrolled/edited. */ -static void -e_icon_bar_update_highlight (EIconBar *icon_bar) -{ - GtkWidget *widget; - gint x, y, item_num; - - widget = GTK_WIDGET (icon_bar); - - if (!widget->window) - return; - - gdk_window_get_pointer (widget->window, &x, &y, NULL); - - if (x < 0 || y < 0 - || x > widget->allocation.width || y > widget->allocation.height) - return; - - x += icon_bar->canvas.parent.layout.hadjustment->value; - y += icon_bar->canvas.parent.layout.vadjustment->value; - item_num = e_icon_bar_find_item_at_position (icon_bar, x, y, NULL); - e_icon_bar_item_motion (icon_bar, item_num, NULL); -} - - -static gint -e_icon_bar_drag_motion (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time) -{ - EIconBar *icon_bar; - gint item_num, before_item, scroll_x, scroll_y; - - g_return_val_if_fail (E_IS_ICON_BAR (widget), FALSE); - - icon_bar = E_ICON_BAR (widget); - - icon_bar->in_drag = TRUE; - - /* Check if the mouse is over or between items, and if so highlight. */ - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (icon_bar), - &scroll_x, &scroll_y); - item_num = e_icon_bar_find_item_at_position (icon_bar, - x + scroll_x, - y + scroll_y, - &before_item); - e_icon_bar_item_motion (icon_bar, item_num, NULL); - e_icon_bar_set_dragging_before_item (icon_bar, before_item); - - /* Check if the mouse is at the top or bottom of the bar, and if it is - scroll up/down. */ - if (y < E_ICON_BAR_DRAG_AUTO_SCROLL_OFFSET) - icon_bar->scrolling_up = TRUE; - else if (y >= widget->allocation.height - E_ICON_BAR_DRAG_AUTO_SCROLL_OFFSET) - icon_bar->scrolling_up = FALSE; - else { - if (icon_bar->auto_scroll_timeout_id != 0) { - gtk_timeout_remove (icon_bar->auto_scroll_timeout_id); - icon_bar->auto_scroll_timeout_id = 0; - } - return FALSE; - } - - if (icon_bar->auto_scroll_timeout_id == 0) { - icon_bar->auto_scroll_timeout_id = g_timeout_add (E_ICON_BAR_SCROLL_TIMEOUT, e_icon_bar_timeout_handler, icon_bar); - icon_bar->auto_scroll_delay = E_ICON_BAR_SCROLL_DELAY; - } - - return FALSE; -} - - -static void -e_icon_bar_drag_leave (GtkWidget *widget, - GdkDragContext *context, - guint time) -{ - EIconBar *icon_bar; - - g_return_if_fail (E_IS_ICON_BAR (widget)); - - icon_bar = E_ICON_BAR (widget); - - icon_bar->in_drag = FALSE; - - if (icon_bar->auto_scroll_timeout_id != 0) { - gtk_timeout_remove (icon_bar->auto_scroll_timeout_id); - icon_bar->auto_scroll_timeout_id = 0; - } - - if (icon_bar->mouse_over_item_num != -1) { - icon_bar->mouse_over_item_num = -1; - gtk_widget_queue_draw (GTK_WIDGET (icon_bar)); - } -} - - -static void -e_icon_bar_set_dragging_before_item (EIconBar *icon_bar, - gint before_item) -{ - if (icon_bar->dragging_before_item_num == before_item) - return; - - icon_bar->dragging_before_item_num = before_item; - - gtk_widget_queue_draw (GTK_WIDGET (icon_bar)); -} - - -static gboolean -e_icon_bar_timeout_handler (gpointer data) -{ - EIconBar *icon_bar; - gint scroll_x, scroll_y, new_scroll_y; - GtkAdjustment *adj; - - g_return_val_if_fail (E_IS_ICON_BAR (data), FALSE); - - icon_bar = E_ICON_BAR (data); - - GDK_THREADS_ENTER (); - - if (icon_bar->auto_scroll_delay > 0) { - icon_bar->auto_scroll_delay--; - GDK_THREADS_LEAVE (); - return TRUE; - } - - gnome_canvas_get_scroll_offsets (GNOME_CANVAS (icon_bar), - &scroll_x, &scroll_y); - - adj = GTK_LAYOUT (icon_bar)->vadjustment; - - if (icon_bar->scrolling_up) - new_scroll_y = MAX (scroll_y - adj->step_increment, 0); - else - new_scroll_y = MIN (scroll_y + adj->step_increment, - adj->upper - adj->page_size); - - if (new_scroll_y != scroll_y) - gnome_canvas_scroll_to (GNOME_CANVAS (icon_bar), - scroll_x, new_scroll_y); - - GDK_THREADS_LEAVE (); - return TRUE; -} - - -static void -e_icon_bar_vadjustment_value_changed (GtkAdjustment *adjustment, - EIconBar *icon_bar) -{ - e_icon_bar_update_highlight (icon_bar); -} - diff --git a/widgets/shortcut-bar/e-icon-bar.h b/widgets/shortcut-bar/e-icon-bar.h deleted file mode 100644 index 90d9f5a2cf..0000000000 --- a/widgets/shortcut-bar/e-icon-bar.h +++ /dev/null @@ -1,246 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_ICON_BAR_H_ -#define _E_ICON_BAR_H_ - -#include <gdk_imlib.h> -#include <gdk-pixbuf/gdk-pixbuf.h> -#include "../../e-util/e-canvas.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EIconBar is a subclass of GnomeCanvas for displaying a vertical column of - * icons and descriptions. It provides 2 views - large icons and small icons. - */ - - -/* This contains information on one item. */ -typedef struct _EIconBarItem EIconBarItem; -struct _EIconBarItem -{ - GnomeCanvasItem *text; - GnomeCanvasItem *image; - - /* This holds the original pixbuf so that we can blend - to the background if the style changes */ - GdkPixbuf *pixbuf; - - /* This is user data attached to the item, e.g. a URL. */ - gpointer data; - GtkDestroyNotify destroy; - - /* This is the height of the item. */ - gint item_height; - - /* This is the actual x, width and height of the text, rather than - the maximum allowed area. */ - gint text_x; - gint text_width; - gint text_height; - - gint icon_y, text_y; -}; - - -/* These are the view types. Defaults to LARGE_ICONS. */ -typedef enum -{ - E_ICON_BAR_LARGE_ICONS, - E_ICON_BAR_SMALL_ICONS -} EIconBarViewType; - - -/* These index our colors array. */ -typedef enum -{ - E_ICON_BAR_COLOR_EDITING_TEXT, - E_ICON_BAR_COLOR_EDITING_RECT, - E_ICON_BAR_COLOR_EDITING_RECT_OUTLINE, - - E_ICON_BAR_COLOR_LAST -} EIconBarColors; - - -#define E_ICON_BAR(obj) GTK_CHECK_CAST (obj, e_icon_bar_get_type (), EIconBar) -#define E_ICON_BAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_icon_bar_get_type (), EIconBarClass) -#define E_IS_ICON_BAR(obj) GTK_CHECK_TYPE (obj, e_icon_bar_get_type ()) - - -typedef struct _EIconBar EIconBar; -typedef struct _EIconBarClass EIconBarClass; - -struct _EIconBar -{ - ECanvas canvas; - - /* This specifies if we are using large icons or small icons. */ - EIconBarViewType view_type; - - /* This is an array of EIconBarItem elements. */ - GArray *items; - - /* This is the index of the item which has been pressed, or -1. - It will be shown as pressed in while the mouse is over it. */ - gint pressed_item_num; - - /* This is the coordinates of where the button was pressed. If the - mouse moves a certain distance with the button still pressed, we - start a drag. */ - gint pressed_x; - gint pressed_y; - - /* This is the index of the item the mouse is currently over, or -1. - It will be highlighted unless one of the items is pressed. */ - gint mouse_over_item_num; - - /* This is the item that we are currently editing, or -1. */ - gint editing_item_num; - - /* This is a GnomeCanvasRect which is placed around the edited item. */ - GnomeCanvasItem *edit_rect_item; - - /* This is the index of the item which is being dragged, or -1. - If the drag results in a move it will be deleted. */ - gint dragged_item_num; - - /* This is TRUE if we are dragging over this EIconBar. */ - gboolean in_drag; - - /* This is used in drag-and-drop to indicate the item which the mouse - is currently before, e.g. if it is 1 then a dropped item would be - inserted between items 0 and 1. It ranges from 0 to the number of - items, or is -1 when the mouse is not dragging between items. */ - gint dragging_before_item_num; - - /* These are the common positions of all the items in the EIconBar. */ - gint icon_x, icon_w, icon_h, text_x, text_w, spacing; - - /* This is the source id of our auto-scroll timeout handler, used when - in the middle of drag-and-drop operations. */ - gint auto_scroll_timeout_id; - gint auto_scroll_delay; - gboolean scrolling_up; - - /* Colors for drawing. */ - GdkColor colors[E_ICON_BAR_COLOR_LAST]; - - /* Signal connection id for "value_changed" signal of vadjustment. */ - guint vadjustment_value_changed_id; -}; - -struct _EIconBarClass -{ - ECanvasClass parent_class; - - void (*selected_item) (EIconBar *icon_bar, - GdkEvent *event, - gint item_num); - void (*dragged_item) (EIconBar *icon_bar, - GdkEvent *event, - gint item_num); -}; - - -GtkType e_icon_bar_get_type (void); -GtkWidget* e_icon_bar_new (void); - -/* Sets the view type. */ -void e_icon_bar_set_view_type (EIconBar *icon_bar, - EIconBarViewType view_type); - -/* Adds a new item to a group at the given position. If position is -1 it is - added at the end. It returns the index of the item. */ -gint e_icon_bar_add_item (EIconBar *icon_bar, - GdkPixbuf *image, - const gchar *text, - gint position); - -/* Reorders an item. Note that position refers to the new position to add the - item after removing it from its current position. If position is -1 it is - moved to the end of the bar. */ -void e_icon_bar_reorder_item (EIconBar *icon_bar, - gint item_num, - gint new_position); -void e_icon_bar_remove_item (EIconBar *icon_bar, - gint item_num); - -GdkPixbuf * e_icon_bar_get_item_image (EIconBar *icon_bar, - gint item_num); -void e_icon_bar_set_item_image (EIconBar *icon_bar, - gint item_num, - GdkPixbuf *image); - -gchar* e_icon_bar_get_item_text (EIconBar *icon_bar, - gint item_num); -void e_icon_bar_set_item_text (EIconBar *icon_bar, - gint item_num, - gchar *text); - -gpointer e_icon_bar_get_item_data (EIconBar *icon_bar, - gint item_num); -void e_icon_bar_set_item_data (EIconBar *icon_bar, - gint item_num, - gpointer data); -void e_icon_bar_set_item_data_full (EIconBar *icon_bar, - gint item_num, - gpointer data, - GtkDestroyNotify destroy); - -void e_icon_bar_start_editing_item (EIconBar *icon_bar, - gint item_num); -void e_icon_bar_stop_editing_item (EIconBar *icon_bar, - gboolean accept); - - - -/* - * INTERNAL FUNCTIONS - for use by EIconBarBgItem. - */ - -/* This returns the index of the item at the given position on the EIconBar, - or -1 if no item is found. If before_item is not NULL, it returns the - item which the mouse is before, or -1 (this is used for dragging). */ -gint e_icon_bar_find_item_at_position (EIconBar *icon_bar, - gint x, - gint y, - gint *before_item); - -void e_icon_bar_item_pressed (EIconBar *icon_bar, - gint item_num, - GdkEvent *event); -void e_icon_bar_item_released (EIconBar *icon_bar, - gint item_num, - GdkEvent *event); -void e_icon_bar_item_motion (EIconBar *icon_bar, - gint item_num, - GdkEvent *event); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_ICON_BAR_H_ */ diff --git a/widgets/shortcut-bar/e-shortcut-bar.c b/widgets/shortcut-bar/e-shortcut-bar.c deleted file mode 100644 index a7d7f76aba..0000000000 --- a/widgets/shortcut-bar/e-shortcut-bar.c +++ /dev/null @@ -1,757 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * EShortcutBar displays a vertical bar with a number of Groups, each of which - * contains any number of icons. It is used on the left of the main application - * window so users can easily access items such as folders and files. - * - * The architecture is a bit complicated. EShortcutBar is a sublass of - * EGroupBar (which supports a number of groups with buttons to slide them - * into view). EShortcutBar places an EIconBar widget in each group page, - * which displays an icon and name for each shortcut. - */ - -#include <config.h> -#include <string.h> -#include <e-util/e-util.h> -#include "e-shortcut-bar.h" -#include "e-clipped-label.h" -#include "e-vscrolled-bar.h" - -/* Drag and Drop stuff. */ -enum { - TARGET_SHORTCUT -}; -static GtkTargetEntry target_table[] = { - { "E-SHORTCUT", 0, TARGET_SHORTCUT } -}; -static guint n_targets = sizeof(target_table) / sizeof(target_table[0]); - -gboolean e_shortcut_bar_default_icon_loaded = FALSE; -GdkPixbuf *e_shortcut_bar_default_icon = NULL; -gchar *e_shortcut_bar_default_icon_filename = "gnome-folder.png"; - -static void e_shortcut_bar_class_init (EShortcutBarClass *class); -static void e_shortcut_bar_init (EShortcutBar *shortcut_bar); -static void e_shortcut_bar_destroy (GtkObject *object); - -static void e_shortcut_bar_disconnect_model (EShortcutBar *shortcut_bar); - -static void e_shortcut_bar_on_model_destroyed (EShortcutModel *model, - EShortcutBar *shortcut_bar); -static void e_shortcut_bar_on_group_added (EShortcutModel *model, - gint group_num, - gchar *group_name, - EShortcutBar *shortcut_bar); -static void e_shortcut_bar_on_group_removed (EShortcutModel *model, - gint group_num, - EShortcutBar *shortcut_bar); -static void e_shortcut_bar_on_item_added (EShortcutModel *model, - gint group_num, - gint item_num, - gchar *item_url, - gchar *item_name, - EShortcutBar *shortcut_bar); -static void e_shortcut_bar_on_item_removed (EShortcutModel *model, - gint group_num, - gint item_num, - EShortcutBar *shortcut_bar); - -static gint e_shortcut_bar_add_group (EShortcutBar *shortcut_bar, - gint position, - const gchar *group_name); -static void e_shortcut_bar_remove_group (EShortcutBar *shortcut_bar, - gint group_num); -static gint e_shortcut_bar_add_item (EShortcutBar *shortcut_bar, - gint group_num, - gint position, - const gchar *item_url, - const gchar *item_name); -static void e_shortcut_bar_remove_item (EShortcutBar *shortcut_bar, - gint group_num, - gint item_num); - - -static void e_shortcut_bar_set_canvas_style (EShortcutBar *shortcut_bar, - GtkWidget *canvas); -static void e_shortcut_bar_item_selected (EIconBar *icon_bar, - GdkEvent *event, - gint item_num, - EShortcutBar *shortcut_bar); -static void e_shortcut_bar_item_dragged (EIconBar *icon_bar, - GdkEvent *event, - gint item_num, - EShortcutBar *shortcut_bar); -static void e_shortcut_bar_on_drag_data_get (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - EShortcutBar *shortcut_bar); -static void e_shortcut_bar_on_drag_data_received(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *data, - guint info, - guint time, - EShortcutBar *shortcut_bar); -static void e_shortcut_bar_on_drag_data_delete (GtkWidget *widget, - GdkDragContext *context, - EShortcutBar *shortcut_bar); -static void e_shortcut_bar_on_drag_end (GtkWidget *widget, - GdkDragContext *context, - EShortcutBar *shortcut_bar); -static void e_shortcut_bar_stop_editing (GtkWidget *button, - EShortcutBar *shortcut_bar); -static GdkPixbuf* e_shortcut_bar_get_image_from_url (EShortcutBar *shortcut_bar, - const gchar *item_url); -static GdkPixbuf* e_shortcut_bar_load_image (const gchar *filename); - - -enum -{ - ITEM_SELECTED, - LAST_SIGNAL -}; - -static guint e_shortcut_bar_signals[LAST_SIGNAL] = {0}; - -static EGroupBarClass *parent_class; - - -E_MAKE_TYPE(e_shortcut_bar, "EShortcutBar", EShortcutBar, - e_shortcut_bar_class_init, e_shortcut_bar_init, - e_group_bar_get_type()) - - -static void -e_shortcut_bar_class_init (EShortcutBarClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - parent_class = gtk_type_class (e_group_bar_get_type ()); - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - - e_shortcut_bar_signals[ITEM_SELECTED] = - gtk_signal_new ("item_selected", - GTK_RUN_LAST | GTK_RUN_ACTION, - object_class->type, - GTK_SIGNAL_OFFSET (EShortcutBarClass, - selected_item), - gtk_marshal_NONE__POINTER_INT_INT, - GTK_TYPE_NONE, 3, GTK_TYPE_GDK_EVENT, - GTK_TYPE_INT, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, e_shortcut_bar_signals, - LAST_SIGNAL); - - /* Method override */ - object_class->destroy = e_shortcut_bar_destroy; -} - - -static void -e_shortcut_bar_init (EShortcutBar *shortcut_bar) -{ - shortcut_bar->groups = g_array_new (FALSE, FALSE, - sizeof (EShortcutBarGroup)); - - shortcut_bar->dragged_url = NULL; - shortcut_bar->dragged_name = NULL; -} - - -GtkWidget * -e_shortcut_bar_new (void) -{ - GtkWidget *shortcut_bar; - - shortcut_bar = GTK_WIDGET (gtk_type_new (e_shortcut_bar_get_type ())); - - return shortcut_bar; -} - - -static void -e_shortcut_bar_destroy (GtkObject *object) -{ - EShortcutBar *shortcut_bar; - - shortcut_bar = E_SHORTCUT_BAR (object); - - g_array_free (shortcut_bar->groups, TRUE); - - g_free (shortcut_bar->dragged_url); - g_free (shortcut_bar->dragged_name); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - - -void -e_shortcut_bar_set_model (EShortcutBar *shortcut_bar, - EShortcutModel *model) -{ - gint num_groups, group_num, num_items, item_num; - gchar *group_name, *item_url, *item_name; - - /* Disconnect any existing model. */ - e_shortcut_bar_disconnect_model (shortcut_bar); - - shortcut_bar->model = model; - - if (!model) - return; - - gtk_signal_connect (GTK_OBJECT (model), "destroy", - GTK_SIGNAL_FUNC (e_shortcut_bar_on_model_destroyed), - shortcut_bar); - gtk_signal_connect (GTK_OBJECT (model), "group_added", - GTK_SIGNAL_FUNC (e_shortcut_bar_on_group_added), - shortcut_bar); - gtk_signal_connect (GTK_OBJECT (model), "group_removed", - GTK_SIGNAL_FUNC (e_shortcut_bar_on_group_removed), - shortcut_bar); - gtk_signal_connect (GTK_OBJECT (model), "item_added", - GTK_SIGNAL_FUNC (e_shortcut_bar_on_item_added), - shortcut_bar); - gtk_signal_connect (GTK_OBJECT (model), "item_removed", - GTK_SIGNAL_FUNC (e_shortcut_bar_on_item_removed), - shortcut_bar); - - /* Add any items already in the model. */ - num_groups = e_shortcut_model_get_num_groups (model); - for (group_num = 0; group_num < num_groups; group_num++) { - group_name = e_shortcut_model_get_group_name (model, - group_num); - e_shortcut_bar_add_group (shortcut_bar, group_num, group_name); - g_free (group_name); - - num_items = e_shortcut_model_get_num_items (model, group_num); - for (item_num = 0; item_num < num_items; item_num++) { - e_shortcut_model_get_item_info (model, group_num, - item_num, &item_url, - &item_name); - e_shortcut_bar_add_item (shortcut_bar, group_num, - item_num, item_url, - item_name); - g_free (item_url); - g_free (item_name); - } - } -} - - -static void -e_shortcut_bar_disconnect_model (EShortcutBar *shortcut_bar) -{ - /* Remove all the current groups. */ - while (shortcut_bar->groups->len) - e_shortcut_bar_remove_group (shortcut_bar, 0); - - if (shortcut_bar->model) { - /* Disconnect all the signals in one go. */ - gtk_signal_disconnect_by_data (GTK_OBJECT (shortcut_bar->model), shortcut_bar); - shortcut_bar->model = NULL; - } -} - - -static void -e_shortcut_bar_on_model_destroyed (EShortcutModel *model, - EShortcutBar *shortcut_bar) -{ - e_shortcut_bar_disconnect_model (shortcut_bar); -} - - -static void -e_shortcut_bar_on_group_added (EShortcutModel *model, - gint group_num, - gchar *group_name, - EShortcutBar *shortcut_bar) -{ - e_shortcut_bar_add_group (shortcut_bar, group_num, group_name); -} - - -static void -e_shortcut_bar_on_group_removed (EShortcutModel *model, - gint group_num, - EShortcutBar *shortcut_bar) -{ - e_shortcut_bar_remove_group (shortcut_bar, group_num); -} - - -static void -e_shortcut_bar_on_item_added (EShortcutModel *model, - gint group_num, - gint item_num, - gchar *item_url, - gchar *item_name, - EShortcutBar *shortcut_bar) -{ - e_shortcut_bar_add_item (shortcut_bar, group_num, item_num, - item_url, item_name); -} - - -static void -e_shortcut_bar_on_item_removed (EShortcutModel *model, - gint group_num, - gint item_num, - EShortcutBar *shortcut_bar) -{ - e_shortcut_bar_remove_item (shortcut_bar, group_num, item_num); -} - - - -static gint -e_shortcut_bar_add_group (EShortcutBar *shortcut_bar, - gint position, - const gchar *group_name) -{ - EShortcutBarGroup *group, tmp_group; - gint group_num; - GtkWidget *button, *label; - - g_return_val_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar), -1); - g_return_val_if_fail (group_name != NULL, -1); - - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - gtk_widget_push_visual (gdk_rgb_get_visual ()); - - group_num = position; - g_array_insert_val (shortcut_bar->groups, group_num, tmp_group); - - group = &g_array_index (shortcut_bar->groups, - EShortcutBarGroup, group_num); - - group->vscrolled_bar = e_vscrolled_bar_new (NULL); - gtk_widget_show (group->vscrolled_bar); - gtk_signal_connect ( - GTK_OBJECT (E_VSCROLLED_BAR (group->vscrolled_bar)->up_button), - "pressed", GTK_SIGNAL_FUNC (e_shortcut_bar_stop_editing), shortcut_bar); - gtk_signal_connect ( - GTK_OBJECT (E_VSCROLLED_BAR (group->vscrolled_bar)->down_button), - "pressed", GTK_SIGNAL_FUNC (e_shortcut_bar_stop_editing), shortcut_bar); - - group->icon_bar = e_icon_bar_new (); - gtk_widget_show (group->icon_bar); - gtk_container_add (GTK_CONTAINER (group->vscrolled_bar), - group->icon_bar); - gtk_signal_connect (GTK_OBJECT (group->icon_bar), "item_selected", - GTK_SIGNAL_FUNC (e_shortcut_bar_item_selected), - shortcut_bar); - gtk_signal_connect (GTK_OBJECT (group->icon_bar), "item_dragged", - GTK_SIGNAL_FUNC (e_shortcut_bar_item_dragged), - shortcut_bar); - gtk_signal_connect (GTK_OBJECT (group->icon_bar), "drag_data_get", - GTK_SIGNAL_FUNC (e_shortcut_bar_on_drag_data_get), - shortcut_bar); - gtk_signal_connect (GTK_OBJECT (group->icon_bar), "drag_data_received", - GTK_SIGNAL_FUNC (e_shortcut_bar_on_drag_data_received), - shortcut_bar); - gtk_signal_connect (GTK_OBJECT (group->icon_bar), "drag_data_delete", - GTK_SIGNAL_FUNC (e_shortcut_bar_on_drag_data_delete), - shortcut_bar); - gtk_signal_connect (GTK_OBJECT (group->icon_bar), "drag_end", - GTK_SIGNAL_FUNC (e_shortcut_bar_on_drag_end), - shortcut_bar); - -#ifndef E_USE_STYLES - e_shortcut_bar_set_canvas_style (shortcut_bar, group->icon_bar); -#endif - - button = gtk_button_new (); - label = e_clipped_label_new (group_name); - gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5); - gtk_widget_show (label); - gtk_container_add (GTK_CONTAINER (button), label); - gtk_widget_show (button); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (e_shortcut_bar_stop_editing), - shortcut_bar); - - gtk_drag_dest_set (GTK_WIDGET (group->icon_bar), - GTK_DEST_DEFAULT_ALL, - target_table, n_targets, - GDK_ACTION_COPY | GDK_ACTION_MOVE); - gtk_drag_dest_set (GTK_WIDGET (button), - GTK_DEST_DEFAULT_ALL, - target_table, n_targets, - GDK_ACTION_COPY | GDK_ACTION_MOVE); - - e_group_bar_add_group (E_GROUP_BAR (shortcut_bar), - group->vscrolled_bar, button, -1); - - gtk_widget_pop_visual (); - gtk_widget_pop_colormap (); - - return group_num; -} - - -static void -e_shortcut_bar_remove_group (EShortcutBar *shortcut_bar, - gint group_num) -{ - e_group_bar_remove_group (E_GROUP_BAR (shortcut_bar), group_num); - g_array_remove_index (shortcut_bar->groups, group_num); -} - - -static gint -e_shortcut_bar_add_item (EShortcutBar *shortcut_bar, - gint group_num, - gint position, - const gchar *item_url, - const gchar *item_name) -{ - EShortcutBarGroup *group; - GdkPixbuf *image; - gint item_num; - - g_return_val_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar), -1); - g_return_val_if_fail (group_num >= 0, -1); - g_return_val_if_fail (group_num < shortcut_bar->groups->len, -1); - g_return_val_if_fail (item_url != NULL, -1); - g_return_val_if_fail (item_name != NULL, -1); - - image = e_shortcut_bar_get_image_from_url (shortcut_bar, item_url); - group = &g_array_index (shortcut_bar->groups, - EShortcutBarGroup, group_num); - - item_num = e_icon_bar_add_item (E_ICON_BAR (group->icon_bar), - image, item_name, position); - gdk_pixbuf_unref (image); - e_icon_bar_set_item_data_full (E_ICON_BAR (group->icon_bar), item_num, - g_strdup (item_url), g_free); - - return item_num; -} - - -static void -e_shortcut_bar_remove_item (EShortcutBar *shortcut_bar, - gint group_num, - gint item_num) -{ - EShortcutBarGroup *group; - - g_return_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar)); - g_return_if_fail (group_num >= 0); - g_return_if_fail (group_num < shortcut_bar->groups->len); - - group = &g_array_index (shortcut_bar->groups, - EShortcutBarGroup, group_num); - - e_icon_bar_remove_item (E_ICON_BAR (group->icon_bar), item_num); -} - - -static void -e_shortcut_bar_set_canvas_style (EShortcutBar *shortcut_bar, - GtkWidget *canvas) -{ - GtkRcStyle *rc_style; - - rc_style = gtk_rc_style_new (); - - rc_style->color_flags[GTK_STATE_NORMAL] = GTK_RC_FG | GTK_RC_BG; - rc_style->fg[GTK_STATE_NORMAL].red = 65535; - rc_style->fg[GTK_STATE_NORMAL].green = 65535; - rc_style->fg[GTK_STATE_NORMAL].blue = 65535; - - rc_style->bg[GTK_STATE_NORMAL].red = 32512; - rc_style->bg[GTK_STATE_NORMAL].green = 32512; - rc_style->bg[GTK_STATE_NORMAL].blue = 32512; - - gtk_widget_modify_style (GTK_WIDGET (canvas), rc_style); - gtk_rc_style_unref (rc_style); -} - - -void -e_shortcut_bar_set_view_type (EShortcutBar *shortcut_bar, - gint group_num, - EIconBarViewType view_type) -{ - EShortcutBarGroup *group; - - g_return_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar)); - g_return_if_fail (group_num >= 0); - g_return_if_fail (group_num < shortcut_bar->groups->len); - - group = &g_array_index (shortcut_bar->groups, - EShortcutBarGroup, group_num); - - e_icon_bar_set_view_type (E_ICON_BAR (group->icon_bar), view_type); -} - - -EIconBarViewType -e_shortcut_bar_get_view_type (EShortcutBar *shortcut_bar, - gint group_num) -{ - EShortcutBarGroup *group; - - g_return_val_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar), E_ICON_BAR_SMALL_ICONS); - g_return_val_if_fail (group_num >= 0, E_ICON_BAR_SMALL_ICONS); - g_return_val_if_fail (group_num < shortcut_bar->groups->len, E_ICON_BAR_SMALL_ICONS); - - group = &g_array_index (shortcut_bar->groups, - EShortcutBarGroup, group_num); - - return E_ICON_BAR (group->icon_bar)->view_type; -} - - -static void -e_shortcut_bar_item_selected (EIconBar *icon_bar, - GdkEvent *event, - gint item_num, - EShortcutBar *shortcut_bar) -{ - gint group_num; - - group_num = e_group_bar_get_group_num (E_GROUP_BAR (shortcut_bar), - GTK_WIDGET (icon_bar)->parent); - - gtk_signal_emit (GTK_OBJECT (shortcut_bar), - e_shortcut_bar_signals[ITEM_SELECTED], - event, group_num, item_num); -} - - -static void -e_shortcut_bar_item_dragged (EIconBar *icon_bar, - GdkEvent *event, - gint item_num, - EShortcutBar *shortcut_bar) -{ - GtkTargetList *target_list; - gint group_num; - - group_num = e_group_bar_get_group_num (E_GROUP_BAR (shortcut_bar), - GTK_WIDGET (icon_bar)->parent); - - shortcut_bar->dragged_url = g_strdup (e_icon_bar_get_item_data (icon_bar, item_num)); - shortcut_bar->dragged_name = e_icon_bar_get_item_text (icon_bar, item_num); - - target_list = gtk_target_list_new (target_table, n_targets); - gtk_drag_begin (GTK_WIDGET (icon_bar), target_list, - GDK_ACTION_COPY | GDK_ACTION_MOVE, - 1, event); - gtk_target_list_unref (target_list); -} - - -static void -e_shortcut_bar_on_drag_data_get (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - EShortcutBar *shortcut_bar) -{ - gchar *data; - - if (info == TARGET_SHORTCUT) { - data = g_strdup_printf ("%s%c%s", shortcut_bar->dragged_name, - '\0', shortcut_bar->dragged_url); - gtk_selection_data_set (selection_data, selection_data->target, - 8, data, - strlen (shortcut_bar->dragged_name) - + strlen (shortcut_bar->dragged_url) - + 2); - g_free (data); - } -} - - -static void -e_shortcut_bar_on_drag_data_received (GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *data, - guint info, - guint time, - EShortcutBar *shortcut_bar) -{ - gchar *item_name, *item_url; - EIconBar *icon_bar; - gint position, group_num; - - icon_bar = E_ICON_BAR (widget); - position = icon_bar->dragging_before_item_num; - - if ((data->length >= 0) && (data->format == 8) - && position != -1) { - item_name = data->data; - item_url = item_name + strlen (item_name) + 1; - - group_num = e_group_bar_get_group_num (E_GROUP_BAR (shortcut_bar), - GTK_WIDGET (icon_bar)->parent); - - e_shortcut_model_add_item (shortcut_bar->model, group_num, - position, item_url, item_name); - - gtk_drag_finish (context, TRUE, TRUE, time); - return; - } - - gtk_drag_finish (context, FALSE, FALSE, time); -} - - -static void -e_shortcut_bar_on_drag_data_delete (GtkWidget *widget, - GdkDragContext *context, - EShortcutBar *shortcut_bar) -{ - EIconBar *icon_bar; - gint group_num; - - icon_bar = E_ICON_BAR (widget); - - group_num = e_group_bar_get_group_num (E_GROUP_BAR (shortcut_bar), - widget->parent); - - e_shortcut_model_remove_item (shortcut_bar->model, group_num, - icon_bar->dragged_item_num); -} - - -static void -e_shortcut_bar_on_drag_end (GtkWidget *widget, - GdkDragContext *context, - EShortcutBar *shortcut_bar) -{ - g_free (shortcut_bar->dragged_name); - shortcut_bar->dragged_name = NULL; - - g_free (shortcut_bar->dragged_url); - shortcut_bar->dragged_url = NULL; -} - - -void -e_shortcut_bar_start_editing_item (EShortcutBar *shortcut_bar, - gint group_num, - gint item_num) -{ - EShortcutBarGroup *group; - - g_return_if_fail (E_IS_SHORTCUT_BAR (shortcut_bar)); - g_return_if_fail (group_num >= 0); - g_return_if_fail (group_num < shortcut_bar->groups->len); - - group = &g_array_index (shortcut_bar->groups, - EShortcutBarGroup, group_num); - - e_icon_bar_start_editing_item (E_ICON_BAR (group->icon_bar), item_num); -} - - -/* We stop editing any item when a scroll button is pressed. */ -static void -e_shortcut_bar_stop_editing (GtkWidget *button, - EShortcutBar *shortcut_bar) -{ - EShortcutBarGroup *group; - gint group_num; - - for (group_num = 0; - group_num < shortcut_bar->groups->len; - group_num++) { - group = &g_array_index (shortcut_bar->groups, - EShortcutBarGroup, group_num); - e_icon_bar_stop_editing_item (E_ICON_BAR (group->icon_bar), - TRUE); - } -} - - -/* Sets the callback which is called to return the icon to use for a particular - URL. */ -void -e_shortcut_bar_set_icon_callback (EShortcutBar *shortcut_bar, - EShortcutBarIconCallback cb, - gpointer data) -{ - shortcut_bar->icon_callback = cb; - shortcut_bar->icon_callback_data = data; -} - - -static GdkPixbuf * -e_shortcut_bar_get_image_from_url (EShortcutBar *shortcut_bar, - const gchar *item_url) -{ - GdkPixbuf *icon = NULL; - - if (shortcut_bar->icon_callback) - icon = (*shortcut_bar->icon_callback) (shortcut_bar, - item_url, - shortcut_bar->icon_callback_data); - - if (!icon) { - if (!e_shortcut_bar_default_icon_loaded) { - e_shortcut_bar_default_icon_loaded = TRUE; - e_shortcut_bar_default_icon = e_shortcut_bar_load_image (e_shortcut_bar_default_icon_filename); - } - icon = e_shortcut_bar_default_icon; - /* ref the default icon each time we return it */ - gdk_pixbuf_ref (icon); - } - - return icon; -} - - -static GdkPixbuf * -e_shortcut_bar_load_image (const gchar *filename) -{ - gchar *pathname; - GdkPixbuf *image = NULL; - - pathname = gnome_pixmap_file (filename); - if (pathname) - image = gdk_pixbuf_new_from_file (pathname); - else - g_warning ("Couldn't find pixmap: %s", filename); - - g_free (pathname); - - return image; -} diff --git a/widgets/shortcut-bar/e-shortcut-bar.h b/widgets/shortcut-bar/e-shortcut-bar.h deleted file mode 100644 index 573303d290..0000000000 --- a/widgets/shortcut-bar/e-shortcut-bar.h +++ /dev/null @@ -1,128 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_SHORTCUT_BAR_H_ -#define _E_SHORTCUT_BAR_H_ - -#include "e-group-bar.h" -#include "e-icon-bar.h" -#include "e-shortcut-model.h" - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EShortcutBar displays a vertical bar with a number of Groups, each of which - * contains any number of icons. It is used on the left of the main application - * window so users can easily access items such as folders and files. - */ - -typedef struct _EShortcutBar EShortcutBar; -typedef struct _EShortcutBarClass EShortcutBarClass; - - -typedef GdkPixbuf* (*EShortcutBarIconCallback) (EShortcutBar *shortcut_bar, - const gchar *url, - gpointer data); - -/* This contains information on one group. */ -typedef struct _EShortcutBarGroup EShortcutBarGroup; -struct _EShortcutBarGroup -{ - /* This is the EVScrolledBar which scrolls the group. */ - GtkWidget *vscrolled_bar; - - /* This is the icon bar containing the child items. */ - GtkWidget *icon_bar; -}; - - -#define E_TYPE_SHORTCUT_BAR (e_shortcut_bar_get_type ()) -#define E_SHORTCUT_BAR(obj) GTK_CHECK_CAST (obj, e_shortcut_bar_get_type (), EShortcutBar) -#define E_SHORTCUT_BAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_shortcut_bar_get_type (), EShortcutBarClass) -#define E_IS_SHORTCUT_BAR(obj) GTK_CHECK_TYPE (obj, e_shortcut_bar_get_type ()) - - -struct _EShortcutBar -{ - EGroupBar group_bar; - - /* This is the underlying model. */ - EShortcutModel *model; - - /* This is an array of EShortcutBarGroup elements. */ - GArray *groups; - - /* The callback which the application sets to return the icon to use - for a given URL. */ - EShortcutBarIconCallback icon_callback; - - /* Closure for the callback. */ - gpointer icon_callback_data; - - gchar *dragged_url; - gchar *dragged_name; -}; - -struct _EShortcutBarClass -{ - EGroupBarClass parent_class; - - void (*selected_item) (EShortcutBar *shortcut_bar, - GdkEvent *event, - gint group_num, - gint item_num); -}; - - -GtkType e_shortcut_bar_get_type (void); -GtkWidget* e_shortcut_bar_new (void); - -/* Sets the underlying model. */ -void e_shortcut_bar_set_model (EShortcutBar *shortcut_bar, - EShortcutModel *shortcut_model); - -/* Sets/gets the view type for the group. */ -void e_shortcut_bar_set_view_type (EShortcutBar *shortcut_bar, - gint group_num, - EIconBarViewType view_type); -EIconBarViewType e_shortcut_bar_get_view_type (EShortcutBar *shortcut_bar, - gint group_num); - -void e_shortcut_bar_start_editing_item (EShortcutBar *shortcut_bar, - gint group_num, - gint item_num); - -/* Sets the callback which is called to return the icon to use for a particular - URL. This callback must be set before any items are added. If the callback - returns NULL the default icon is used. */ -void e_shortcut_bar_set_icon_callback (EShortcutBar *shortcut_bar, - EShortcutBarIconCallback cb, - gpointer data); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_SHORTCUT_BAR_H_ */ diff --git a/widgets/shortcut-bar/e-shortcut-model.c b/widgets/shortcut-bar/e-shortcut-model.c deleted file mode 100644 index 61cfe54a4b..0000000000 --- a/widgets/shortcut-bar/e-shortcut-model.c +++ /dev/null @@ -1,556 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * EShortcutModel keeps track of a number of groups of shortcuts. - * Each shortcut has a URL and a short textual name. - * It is used as the model of the EShortcutBar. - */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include <e-util/e-util.h> -#include "e-shortcut-model.h" - -/* This contains information on one item. */ -typedef struct _EShortcutModelItem EShortcutModelItem; -struct _EShortcutModelItem -{ - gchar *name; - gchar *url; -}; - - -/* This contains information on one group. */ -typedef struct _EShortcutModelGroup EShortcutModelGroup; -struct _EShortcutModelGroup -{ - gchar *name; - - /* An array of EShortcutModelItem. */ - GArray *items; -}; - -#define ESM_CLASS(e) ((EShortcutModelClass *)((GtkObject *)e)->klass) - - -static void e_shortcut_model_class_init (EShortcutModelClass *class); -static void e_shortcut_model_init (EShortcutModel *shortcut_model); -static void e_shortcut_model_destroy (GtkObject *object); -static void e_shortcut_model_free_group (EShortcutModel *shortcut_model, - gint group_num); - -static void e_shortcut_model_real_add_group (EShortcutModel *shortcut_model, - gint position, - const gchar *group_name); -static void e_shortcut_model_real_remove_group (EShortcutModel *shortcut_model, - gint group_num); -static void e_shortcut_model_real_add_item (EShortcutModel *shortcut_model, - gint group_num, - gint position, - const gchar *item_url, - const gchar *item_name); -static void e_shortcut_model_real_remove_item (EShortcutModel *shortcut_model, - gint group_num, - gint item_num); - -static void e_shortcut_model_marshal1 (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args); -static void e_shortcut_model_marshal2 (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args); - -static gint e_shortcut_model_real_get_num_groups(EShortcutModel *shortcut_model); -static gint e_shortcut_model_real_get_num_items (EShortcutModel *shortcut_model, - gint group_num); -static gchar* e_shortcut_model_real_get_group_name (EShortcutModel *shortcut_model, - gint group_num); -static void e_shortcut_model_real_get_item_info (EShortcutModel *shortcut_model, - gint group_num, - gint item_num, - gchar **item_url, - gchar **item_name); - -enum -{ - GROUP_ADDED, - GROUP_REMOVED, - ITEM_ADDED, - ITEM_REMOVED, - - LAST_SIGNAL -}; - -static guint e_shortcut_model_signals[LAST_SIGNAL] = {0}; - -static GtkObjectClass *parent_class; - - -E_MAKE_TYPE(e_shortcut_model, "EShortcutModel", EShortcutModel, - e_shortcut_model_class_init, e_shortcut_model_init, - GTK_TYPE_OBJECT) - - -static void -e_shortcut_model_class_init (EShortcutModelClass *class) -{ - GtkObjectClass *object_class; - - parent_class = gtk_type_class (GTK_TYPE_OBJECT); - - object_class = (GtkObjectClass *) class; - - e_shortcut_model_signals[GROUP_ADDED] = - gtk_signal_new ("group_added", - GTK_RUN_FIRST | GTK_RUN_ACTION, - object_class->type, - GTK_SIGNAL_OFFSET (EShortcutModelClass, - group_added), - e_shortcut_model_marshal1, - GTK_TYPE_NONE, 2, - GTK_TYPE_INT, GTK_TYPE_STRING); - - e_shortcut_model_signals[GROUP_REMOVED] = - gtk_signal_new ("group_removed", - GTK_RUN_FIRST | GTK_RUN_ACTION, - object_class->type, - GTK_SIGNAL_OFFSET (EShortcutModelClass, - group_removed), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, - GTK_TYPE_INT); - - e_shortcut_model_signals[ITEM_ADDED] = - gtk_signal_new ("item_added", - GTK_RUN_FIRST | GTK_RUN_ACTION, - object_class->type, - GTK_SIGNAL_OFFSET (EShortcutModelClass, - item_added), - e_shortcut_model_marshal2, - GTK_TYPE_NONE, 4, - GTK_TYPE_INT, GTK_TYPE_INT, - GTK_TYPE_STRING, GTK_TYPE_STRING); - - e_shortcut_model_signals[ITEM_REMOVED] = - gtk_signal_new ("item_removed", - GTK_RUN_FIRST | GTK_RUN_ACTION, - object_class->type, - GTK_SIGNAL_OFFSET (EShortcutModelClass, - item_removed), - gtk_marshal_NONE__INT_INT, - GTK_TYPE_NONE, 2, - GTK_TYPE_INT, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, e_shortcut_model_signals, - LAST_SIGNAL); - - /* Method override */ - object_class->destroy = e_shortcut_model_destroy; - - class->group_added = e_shortcut_model_real_add_group; - class->group_removed = e_shortcut_model_real_remove_group; - class->item_added = e_shortcut_model_real_add_item; - class->item_removed = e_shortcut_model_real_remove_item; - - class->get_num_groups = e_shortcut_model_real_get_num_groups; - class->get_num_items = e_shortcut_model_real_get_num_items; - class->get_group_name = e_shortcut_model_real_get_group_name; - class->get_item_info = e_shortcut_model_real_get_item_info; -} - - -static void -e_shortcut_model_init (EShortcutModel *shortcut_model) -{ - shortcut_model->groups = g_array_new (FALSE, FALSE, - sizeof (EShortcutModelGroup)); -} - - -EShortcutModel * -e_shortcut_model_new (void) -{ - EShortcutModel *shortcut_model; - - shortcut_model = E_SHORTCUT_MODEL (gtk_type_new (e_shortcut_model_get_type ())); - - return shortcut_model; -} - - -static void -e_shortcut_model_destroy (GtkObject *object) -{ - EShortcutModel *shortcut_model; - gint num_groups, group_num; - - shortcut_model = E_SHORTCUT_MODEL (object); - - num_groups = shortcut_model->groups->len; - for (group_num = 0; group_num < num_groups; group_num++) - e_shortcut_model_free_group (shortcut_model, group_num); - - g_array_free (shortcut_model->groups, TRUE); - shortcut_model->groups = NULL; - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - - -static void -e_shortcut_model_free_group (EShortcutModel *shortcut_model, - gint group_num) -{ - EShortcutModelGroup *group; - EShortcutModelItem *item; - gint item_num; - - group = &g_array_index (shortcut_model->groups, - EShortcutModelGroup, group_num); - - g_free (group->name); - - for (item_num = 0; item_num < group->items->len; item_num++) { - item = &g_array_index (group->items, - EShortcutModelItem, item_num); - g_free (item->name); - g_free (item->url); - } -} - - -gint -e_shortcut_model_add_group (EShortcutModel *shortcut_model, - gint position, - const gchar *group_name) -{ - g_return_val_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model), -1); - g_return_val_if_fail (group_name != NULL, -1); - - if (position == -1 || position > shortcut_model->groups->len) - position = shortcut_model->groups->len; - - gtk_signal_emit (GTK_OBJECT (shortcut_model), - e_shortcut_model_signals[GROUP_ADDED], - position, group_name); - - return position; -} - - -static void -e_shortcut_model_real_add_group (EShortcutModel *shortcut_model, - gint group_num, - const gchar *group_name) -{ - EShortcutModelGroup *group, tmp_group; - - g_return_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model)); - g_return_if_fail (group_num >= 0); - g_return_if_fail (group_num <= shortcut_model->groups->len); - g_return_if_fail (group_name != NULL); - - g_array_insert_val (shortcut_model->groups, group_num, tmp_group); - - group = &g_array_index (shortcut_model->groups, - EShortcutModelGroup, group_num); - - group->name = g_strdup (group_name); - group->items = g_array_new (FALSE, FALSE, - sizeof (EShortcutModelItem)); -} - - -void -e_shortcut_model_remove_group (EShortcutModel *shortcut_model, - gint group_num) -{ - g_return_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model)); - g_return_if_fail (group_num >= 0); - g_return_if_fail (group_num < shortcut_model->groups->len); - - gtk_signal_emit (GTK_OBJECT (shortcut_model), - e_shortcut_model_signals[GROUP_REMOVED], - group_num); -} - - -static void -e_shortcut_model_real_remove_group (EShortcutModel *shortcut_model, - gint group_num) -{ - g_return_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model)); - g_return_if_fail (group_num >= 0); - g_return_if_fail (group_num < shortcut_model->groups->len); - - e_shortcut_model_free_group (shortcut_model, group_num); - g_array_remove_index (shortcut_model->groups, group_num); -} - - -gint -e_shortcut_model_add_item (EShortcutModel *shortcut_model, - gint group_num, - gint position, - const gchar *item_url, - const gchar *item_name) -{ - EShortcutModelGroup *group; - - g_return_val_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model), -1); - g_return_val_if_fail (group_num >= 0, -1); - g_return_val_if_fail (group_num < shortcut_model->groups->len, -1); - g_return_val_if_fail (item_url != NULL, -1); - g_return_val_if_fail (item_name != NULL, -1); - - group = &g_array_index (shortcut_model->groups, - EShortcutModelGroup, group_num); - - if (position == -1 || position > group->items->len) - position = group->items->len; - - gtk_signal_emit (GTK_OBJECT (shortcut_model), - e_shortcut_model_signals[ITEM_ADDED], - group_num, position, item_url, item_name); - - return position; -} - - -static void -e_shortcut_model_real_add_item (EShortcutModel *shortcut_model, - gint group_num, - gint item_num, - const gchar *item_url, - const gchar *item_name) -{ - EShortcutModelGroup *group; - EShortcutModelItem *item, tmp_item; - - g_return_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model)); - g_return_if_fail (group_num >= 0); - g_return_if_fail (group_num < shortcut_model->groups->len); - g_return_if_fail (item_url != NULL); - g_return_if_fail (item_name != NULL); - - group = &g_array_index (shortcut_model->groups, - EShortcutModelGroup, group_num); - - g_return_if_fail (item_num >= 0); - g_return_if_fail (item_num <= group->items->len); - - g_array_insert_val (group->items, item_num, tmp_item); - - item = &g_array_index (group->items, - EShortcutModelItem, item_num); - - item->name = g_strdup (item_name); - item->url = g_strdup (item_url); -} - - -void -e_shortcut_model_remove_item (EShortcutModel *shortcut_model, - gint group_num, - gint item_num) -{ - gtk_signal_emit (GTK_OBJECT (shortcut_model), - e_shortcut_model_signals[ITEM_REMOVED], - group_num, item_num); -} - - -static void -e_shortcut_model_real_remove_item (EShortcutModel *shortcut_model, - gint group_num, - gint item_num) -{ - EShortcutModelGroup *group; - EShortcutModelItem *item; - - g_return_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model)); - g_return_if_fail (group_num >= 0); - g_return_if_fail (group_num < shortcut_model->groups->len); - - group = &g_array_index (shortcut_model->groups, - EShortcutModelGroup, group_num); - - g_return_if_fail (item_num >= 0); - g_return_if_fail (item_num < group->items->len); - - item = &g_array_index (group->items, - EShortcutModelItem, item_num); - - g_free (item->name); - g_free (item->url); - - g_array_remove_index (group->items, item_num); -} - - -static void -e_shortcut_model_marshal1 (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args) -{ - void (*rfunc) (GtkObject*, gint, gpointer, gpointer); - rfunc = (void (*) (GtkObject*, gint, gpointer, gpointer)) func; - (*rfunc) (object, GTK_VALUE_INT (args[0]), GTK_VALUE_STRING (args[1]), - func_data); -} - - -static void -e_shortcut_model_marshal2 (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args) -{ - void (*rfunc) (GtkObject*, gint, gint, gpointer, gpointer, gpointer); - rfunc = (void (*) (GtkObject*, gint, gint, gpointer, gpointer, - gpointer)) func; - (*rfunc) (object, GTK_VALUE_INT (args[0]), GTK_VALUE_INT (args[1]), - GTK_VALUE_STRING (args[2]), GTK_VALUE_STRING (args[3]), - func_data); -} - - -gint -e_shortcut_model_get_num_groups (EShortcutModel *shortcut_model) -{ - g_return_val_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model), 0); - - return ESM_CLASS (shortcut_model)->get_num_groups (shortcut_model); -} - - -static gint -e_shortcut_model_real_get_num_groups (EShortcutModel *shortcut_model) -{ - return shortcut_model->groups->len; -} - - -gint -e_shortcut_model_get_num_items (EShortcutModel *shortcut_model, - gint group_num) -{ - g_return_val_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model), 0); - - return ESM_CLASS (shortcut_model)->get_num_items (shortcut_model, - group_num); -} - - -static gint -e_shortcut_model_real_get_num_items (EShortcutModel *shortcut_model, - gint group_num) -{ - EShortcutModelGroup *group; - - g_return_val_if_fail (group_num >= 0, 0); - g_return_val_if_fail (group_num < shortcut_model->groups->len, 0); - - group = &g_array_index (shortcut_model->groups, - EShortcutModelGroup, group_num); - - return group->items->len; -} - - -gchar* -e_shortcut_model_get_group_name (EShortcutModel *shortcut_model, - gint group_num) -{ - g_return_val_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model), NULL); - - return ESM_CLASS (shortcut_model)->get_group_name (shortcut_model, - group_num); -} - - -static gchar* -e_shortcut_model_real_get_group_name (EShortcutModel *shortcut_model, - gint group_num) -{ - EShortcutModelGroup *group; - - g_return_val_if_fail (group_num >= 0, NULL); - g_return_val_if_fail (group_num < shortcut_model->groups->len, NULL); - - group = &g_array_index (shortcut_model->groups, - EShortcutModelGroup, group_num); - - return g_strdup (group->name); -} - - -void -e_shortcut_model_get_item_info (EShortcutModel *shortcut_model, - gint group_num, - gint item_num, - gchar **item_url, - gchar **item_name) -{ - g_return_if_fail (E_IS_SHORTCUT_MODEL (shortcut_model)); - - ESM_CLASS (shortcut_model)->get_item_info (shortcut_model, - group_num, item_num, - item_url, item_name); -} - - -static void -e_shortcut_model_real_get_item_info (EShortcutModel *shortcut_model, - gint group_num, - gint item_num, - gchar **item_url, - gchar **item_name) -{ - EShortcutModelGroup *group; - EShortcutModelItem *item; - - g_return_if_fail (group_num >= 0); - g_return_if_fail (group_num < shortcut_model->groups->len); - - group = &g_array_index (shortcut_model->groups, - EShortcutModelGroup, group_num); - - g_return_if_fail (item_num >= 0); - g_return_if_fail (item_num < group->items->len); - - item = &g_array_index (group->items, - EShortcutModelItem, item_num); - - if (item_url) - *item_url = g_strdup (item->url); - - if (item_name) - *item_name = g_strdup (item->name); -} - diff --git a/widgets/shortcut-bar/e-shortcut-model.h b/widgets/shortcut-bar/e-shortcut-model.h deleted file mode 100644 index 402874ef09..0000000000 --- a/widgets/shortcut-bar/e-shortcut-model.h +++ /dev/null @@ -1,139 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_SHORTCUT_MODEL_H_ -#define _E_SHORTCUT_MODEL_H_ - -#include <gtk/gtkobject.h> - - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EShortcutModel keeps track of a number of groups of shortcuts. - * Each shortcut has a URL and a short textual name. - * It is used as the model of the EShortcutBar. - */ - -typedef struct _EShortcutModel EShortcutModel; -typedef struct _EShortcutModelClass EShortcutModelClass; - - -#define E_TYPE_SHORTCUT_MODEL (e_shortcut_model_get_type ()) -#define E_SHORTCUT_MODEL(obj) GTK_CHECK_CAST (obj, e_shortcut_model_get_type (), EShortcutModel) -#define E_SHORTCUT_MODEL_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_shortcut_model_get_type (), EShortcutModelClass) -#define E_IS_SHORTCUT_MODEL(obj) GTK_CHECK_TYPE (obj, e_shortcut_model_get_type ()) - - -struct _EShortcutModel -{ - GtkObject object; - - /* This is a private array of EShortcutModelGroup elements. */ - GArray *groups; -}; - -struct _EShortcutModelClass -{ - GtkObjectClass parent_class; - - /* - * Signals - These act like virtual functions as well as notification - * signals. The class function is run first and does the actual action. - */ - void (*group_added) (EShortcutModel *shortcut_model, - gint group_num, - const gchar *group_name); - void (*group_removed) (EShortcutModel *shortcut_model, - gint group_num); - - void (*item_added) (EShortcutModel *shortcut_model, - gint group_num, - gint item_num, - const gchar *item_url, - const gchar *item_name); - void (*item_removed) (EShortcutModel *shortcut_model, - gint group_num, - gint item_num); - - /* - * Virtual methods. - */ - gint (*get_num_groups) (EShortcutModel *shortcut_model); - gint (*get_num_items) (EShortcutModel *shortcut_model, - gint group_num); - /* This returns a copy of the group name. */ - gchar* (*get_group_name) (EShortcutModel *shortcut_model, - gint group_num); - /* This returns a copy of the item url and name. */ - void (*get_item_info) (EShortcutModel *shortcut_model, - gint group_num, - gint item_num, - gchar **item_url, - gchar **item_name); -}; - - -GtkType e_shortcut_model_get_type (void); -EShortcutModel* e_shortcut_model_new (void); - -/* Adds a new group at the given position, or last if position is -1. - It returns the index of the new group. */ -gint e_shortcut_model_add_group (EShortcutModel *shortcut_model, - gint position, - const gchar *group_name); -void e_shortcut_model_remove_group (EShortcutModel *shortcut_model, - gint group_num); - -/* Adds a new item to a group at the given position, or last if position is -1. - It returns the index of the new item within the group. */ -gint e_shortcut_model_add_item (EShortcutModel *shortcut_model, - gint group_num, - gint position, - const gchar *item_url, - const gchar *item_name); - -void e_shortcut_model_remove_item (EShortcutModel *shortcut_model, - gint group_num, - gint item_num); - -gint e_shortcut_model_get_num_groups(EShortcutModel *shortcut_model); -gint e_shortcut_model_get_num_items (EShortcutModel *shortcut_model, - gint group_num); -/* The group_name should be freed after use. */ -gchar* e_shortcut_model_get_group_name(EShortcutModel *shortcut_model, - gint group_num); -/* The item_url and item_name should be freed after use. */ -void e_shortcut_model_get_item_info (EShortcutModel *shortcut_model, - gint group_num, - gint item_num, - gchar **item_url, - gchar **item_name); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_SHORTCUT_MODEL_H_ */ diff --git a/widgets/shortcut-bar/e-vscrolled-bar.c b/widgets/shortcut-bar/e-vscrolled-bar.c deleted file mode 100644 index decfffc3e4..0000000000 --- a/widgets/shortcut-bar/e-vscrolled-bar.c +++ /dev/null @@ -1,708 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * EVScrolledBar is like GtkScrolledWindow but only scrolls the child widget - * vertically. It is intended for scrolling narrow vertical bars. - */ - -#include <config.h> -#include <gtk/gtkarrow.h> -#include <gtk/gtkbutton.h> -#include <gtk/gtksignal.h> -#include "e-vscrolled-bar.h" - -/* These are the offsets of the up & down buttons from the right and top/bottom - of the widget. */ -#define E_VSCROLLED_BAR_BUTTON_X_OFFSET 2 -#define E_VSCROLLED_BAR_BUTTON_Y_OFFSET 2 - -/* This is the time between scrolls. */ -#define E_VSCROLLED_BAR_SCROLL_TIMEOUT 20 - -static void e_vscrolled_bar_class_init (EVScrolledBarClass *class); -static void e_vscrolled_bar_init (EVScrolledBar *vscrolled_bar); -static void e_vscrolled_bar_destroy (GtkObject *object); -static void e_vscrolled_bar_finalize (GtkObject *object); -static void e_vscrolled_bar_map (GtkWidget *widget); -static void e_vscrolled_bar_unmap (GtkWidget *widget); -static void e_vscrolled_bar_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void e_vscrolled_bar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static void e_vscrolled_bar_draw (GtkWidget *widget, - GdkRectangle *area); -static gint e_vscrolled_bar_button_press (GtkWidget *widget, - GdkEventButton *event); -static void e_vscrolled_bar_add (GtkContainer *container, - GtkWidget *child); -static void e_vscrolled_bar_remove (GtkContainer *container, - GtkWidget *child); -static void e_vscrolled_bar_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); -static void e_vscrolled_bar_adjustment_changed (GtkAdjustment *adjustment, - gpointer data); -static void e_vscrolled_bar_button_pressed (GtkWidget *button, - EVScrolledBar *vscrolled_bar); -static void e_vscrolled_bar_button_released (GtkWidget *button, - EVScrolledBar *vscrolled_bar); -static void e_vscrolled_bar_button_clicked (GtkWidget *button, - EVScrolledBar *vscrolled_bar); -static gboolean e_vscrolled_bar_timeout_handler (gpointer data); - - -static GtkBinClass *parent_class; - - -GtkType -e_vscrolled_bar_get_type (void) -{ - static GtkType e_vscrolled_bar_type = 0; - - if (!e_vscrolled_bar_type) { - GtkTypeInfo e_vscrolled_bar_info = { - "EVScrolledBar", - sizeof (EVScrolledBar), - sizeof (EVScrolledBarClass), - (GtkClassInitFunc) e_vscrolled_bar_class_init, - (GtkObjectInitFunc) e_vscrolled_bar_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - parent_class = gtk_type_class (GTK_TYPE_BIN); - e_vscrolled_bar_type = gtk_type_unique (GTK_TYPE_BIN, - &e_vscrolled_bar_info); - } - - return e_vscrolled_bar_type; -} - - -static void -e_vscrolled_bar_class_init (EVScrolledBarClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - GtkContainerClass *container_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - container_class = (GtkContainerClass *) class; - - /* Method override */ - object_class->destroy = e_vscrolled_bar_destroy; - object_class->finalize = e_vscrolled_bar_finalize; - - widget_class->map = e_vscrolled_bar_map; - widget_class->unmap = e_vscrolled_bar_unmap; - widget_class->size_request = e_vscrolled_bar_size_request; - widget_class->size_allocate = e_vscrolled_bar_size_allocate; - widget_class->draw = e_vscrolled_bar_draw; - widget_class->button_press_event = e_vscrolled_bar_button_press; - - container_class->add = e_vscrolled_bar_add; - container_class->remove = e_vscrolled_bar_remove; - container_class->forall = e_vscrolled_bar_forall; -} - - -static void -e_vscrolled_bar_init (EVScrolledBar *vscrolled_bar) -{ - GtkWidget *arrow; - - GTK_WIDGET_SET_FLAGS (vscrolled_bar, GTK_NO_WINDOW); - - gtk_container_set_resize_mode (GTK_CONTAINER (vscrolled_bar), - GTK_RESIZE_QUEUE); - - gtk_widget_push_composite_child (); - - vscrolled_bar->up_button = gtk_button_new (); - gtk_widget_set_composite_name (vscrolled_bar->up_button, - "up_button"); - gtk_widget_set_parent (vscrolled_bar->up_button, - GTK_WIDGET (vscrolled_bar)); - arrow = gtk_arrow_new (GTK_ARROW_UP, GTK_SHADOW_OUT); - gtk_misc_set_padding (GTK_MISC (arrow), 1, 1); - gtk_widget_show (arrow); - gtk_container_add (GTK_CONTAINER (vscrolled_bar->up_button), arrow); - gtk_widget_show (vscrolled_bar->up_button); - gtk_signal_connect_after (GTK_OBJECT (vscrolled_bar->up_button), "pressed", GTK_SIGNAL_FUNC (e_vscrolled_bar_button_pressed), vscrolled_bar); - gtk_signal_connect_after (GTK_OBJECT (vscrolled_bar->up_button), "released", GTK_SIGNAL_FUNC (e_vscrolled_bar_button_released), vscrolled_bar); - gtk_signal_connect (GTK_OBJECT (vscrolled_bar->up_button), "clicked", GTK_SIGNAL_FUNC (e_vscrolled_bar_button_clicked), vscrolled_bar); - - vscrolled_bar->down_button = gtk_button_new (); - gtk_widget_set_composite_name (vscrolled_bar->up_button, - "down_button"); - gtk_widget_set_parent (vscrolled_bar->down_button, - GTK_WIDGET (vscrolled_bar)); - arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT); - gtk_misc_set_padding (GTK_MISC (arrow), 1, 1); - gtk_widget_show (arrow); - gtk_container_add (GTK_CONTAINER (vscrolled_bar->down_button), arrow); - gtk_widget_show (vscrolled_bar->down_button); - gtk_signal_connect_after (GTK_OBJECT (vscrolled_bar->down_button), "pressed", GTK_SIGNAL_FUNC (e_vscrolled_bar_button_pressed), vscrolled_bar); - gtk_signal_connect_after (GTK_OBJECT (vscrolled_bar->down_button), "released", GTK_SIGNAL_FUNC (e_vscrolled_bar_button_released), vscrolled_bar); - gtk_signal_connect (GTK_OBJECT (vscrolled_bar->down_button), "clicked", GTK_SIGNAL_FUNC (e_vscrolled_bar_button_clicked), vscrolled_bar); - - gtk_widget_pop_composite_child (); - - vscrolled_bar->adjustment = NULL; - vscrolled_bar->timeout_id = 0; - vscrolled_bar->scrolling_up = FALSE; - vscrolled_bar->min_distance = -1.0; - vscrolled_bar->button_pressed = FALSE; -} - - -/** - * e_vscrolled_bar_new: - * - * @adjustment: The #GtkAdjustment to use for scrolling, or NULL. - * @Return: A new #EVScrolledBar. - * - * Creates a new #EVScrolledBar with the given adjustment. - **/ -GtkWidget * -e_vscrolled_bar_new (GtkAdjustment *adjustment) -{ - GtkWidget *vscrolled_bar; - - vscrolled_bar = GTK_WIDGET (gtk_type_new (e_vscrolled_bar_get_type ())); - e_vscrolled_bar_set_adjustment (E_VSCROLLED_BAR (vscrolled_bar), - adjustment); - - return vscrolled_bar; -} - - -static void -e_vscrolled_bar_destroy (GtkObject *object) -{ - EVScrolledBar *vscrolled_bar; - - vscrolled_bar = E_VSCROLLED_BAR (object); - - if (vscrolled_bar->timeout_id) { - g_source_remove (vscrolled_bar->timeout_id); - vscrolled_bar->timeout_id = 0; - } - - gtk_widget_unparent (vscrolled_bar->up_button); - gtk_widget_unparent (vscrolled_bar->down_button); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - - -static void -e_vscrolled_bar_finalize (GtkObject *object) -{ - EVScrolledBar *vscrolled_bar; - - vscrolled_bar = E_VSCROLLED_BAR (object); - - gtk_object_unref (GTK_OBJECT (vscrolled_bar->adjustment)); - - GTK_OBJECT_CLASS (parent_class)->finalize (object); -} - - -static void -e_vscrolled_bar_map (GtkWidget *widget) -{ - EVScrolledBar *vscrolled_bar; - GtkAdjustment *adjustment; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_VSCROLLED_BAR (widget)); - - vscrolled_bar = E_VSCROLLED_BAR (widget); - - /* chain parent class handler to map self and child */ - GTK_WIDGET_CLASS (parent_class)->map (widget); - - adjustment = vscrolled_bar->adjustment; - - if (GTK_WIDGET_VISIBLE (vscrolled_bar->up_button) - && adjustment->value != adjustment->lower - && !GTK_WIDGET_MAPPED (vscrolled_bar->up_button)) - gtk_widget_map (vscrolled_bar->up_button); - - if (GTK_WIDGET_VISIBLE (vscrolled_bar->down_button) - && adjustment->value < adjustment->upper - adjustment->page_size - && !GTK_WIDGET_MAPPED (vscrolled_bar->down_button)) - gtk_widget_map (vscrolled_bar->down_button); -} - - -static void -e_vscrolled_bar_unmap (GtkWidget *widget) -{ - EVScrolledBar *vscrolled_bar; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_VSCROLLED_BAR (widget)); - - vscrolled_bar = E_VSCROLLED_BAR (widget); - - /* chain parent class handler to unmap self and child */ - GTK_WIDGET_CLASS (parent_class)->unmap (widget); - - if (GTK_WIDGET_MAPPED (vscrolled_bar->up_button)) - gtk_widget_unmap (vscrolled_bar->up_button); - - if (GTK_WIDGET_MAPPED (vscrolled_bar->down_button)) - gtk_widget_unmap (vscrolled_bar->down_button); -} - - -static void -e_vscrolled_bar_size_request (GtkWidget *widget, - GtkRequisition *requisition) -{ - EVScrolledBar *vscrolled_bar; - GtkBin *bin; - GtkRequisition child_requisition; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_VSCROLLED_BAR (widget)); - g_return_if_fail (requisition != NULL); - - vscrolled_bar = E_VSCROLLED_BAR (widget); - bin = GTK_BIN (widget); - - requisition->width = 0; - requisition->height = 0; - - /* We just return the requisition of the child widget, plus the - border width. */ - if (bin->child && GTK_WIDGET_VISIBLE (bin->child)) { - gtk_widget_size_request (bin->child, &child_requisition); - *requisition = child_requisition; - } - - /* We remember the requested heights of the up & down buttons. */ - gtk_widget_size_request (vscrolled_bar->up_button, - &child_requisition); - vscrolled_bar->up_button_width = child_requisition.width; - vscrolled_bar->up_button_height = child_requisition.height; - - gtk_widget_size_request (vscrolled_bar->down_button, - &child_requisition); - vscrolled_bar->down_button_width = child_requisition.width; - vscrolled_bar->down_button_height = child_requisition.height; - - /* Add on the standard container border widths. */ - requisition->width += GTK_CONTAINER (widget)->border_width * 2; - requisition->height += GTK_CONTAINER (widget)->border_width * 2; -} - - -static void -e_vscrolled_bar_size_allocate (GtkWidget *widget, - GtkAllocation *allocation) -{ - EVScrolledBar *vscrolled_bar; - GtkBin *bin; - GtkAllocation button_allocation, child_allocation; - gint border_width; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_VSCROLLED_BAR (widget)); - g_return_if_fail (allocation != NULL); - - vscrolled_bar = E_VSCROLLED_BAR (widget); - bin = GTK_BIN (widget); - - widget->allocation = *allocation; - - border_width = GTK_CONTAINER (widget)->border_width; - - child_allocation.x = border_width; - child_allocation.y = border_width; - child_allocation.width = allocation->width - 2 * border_width; - child_allocation.height = allocation->height - 2 * border_width; - gtk_widget_size_allocate (bin->child, &child_allocation); - - button_allocation.x = allocation->width - border_width - - vscrolled_bar->up_button_width - - E_VSCROLLED_BAR_BUTTON_X_OFFSET; - button_allocation.y = border_width + E_VSCROLLED_BAR_BUTTON_Y_OFFSET; - button_allocation.width = vscrolled_bar->up_button_width; - button_allocation.height = vscrolled_bar->up_button_height; - gtk_widget_size_allocate (vscrolled_bar->up_button, - &button_allocation); - - button_allocation.x = allocation->width - border_width - - vscrolled_bar->down_button_width - - E_VSCROLLED_BAR_BUTTON_X_OFFSET; - button_allocation.y = allocation->height - border_width - - vscrolled_bar->down_button_height - - E_VSCROLLED_BAR_BUTTON_Y_OFFSET; - button_allocation.width = vscrolled_bar->down_button_width; - button_allocation.height = vscrolled_bar->down_button_height; - gtk_widget_size_allocate (vscrolled_bar->down_button, - &button_allocation); -} - - -static void -e_vscrolled_bar_draw (GtkWidget *widget, - GdkRectangle *area) -{ - EVScrolledBar *vscrolled_bar; - GtkBin *bin; - GdkRectangle child_area; - - g_return_if_fail (widget != NULL); - g_return_if_fail (E_IS_VSCROLLED_BAR (widget)); - g_return_if_fail (area != NULL); - - vscrolled_bar = E_VSCROLLED_BAR (widget); - bin = GTK_BIN (widget); - - if (bin->child && GTK_WIDGET_VISIBLE (bin->child) && - gtk_widget_intersect (bin->child, area, &child_area)) - gtk_widget_draw (bin->child, &child_area); - - if (GTK_WIDGET_DRAWABLE (vscrolled_bar->up_button) && - gtk_widget_intersect (vscrolled_bar->up_button, area, &child_area)) - gtk_widget_draw (vscrolled_bar->up_button, &child_area); - - if (GTK_WIDGET_DRAWABLE (vscrolled_bar->down_button) && - gtk_widget_intersect (vscrolled_bar->down_button, area, &child_area)) - gtk_widget_draw (vscrolled_bar->down_button, &child_area); -} - - -static gint -e_vscrolled_bar_button_press (GtkWidget *widget, - GdkEventButton *event) -{ - EVScrolledBar *vscrolled_bar; - GtkAdjustment *adjustment; - gfloat new_value, step; - - vscrolled_bar = E_VSCROLLED_BAR (widget); - adjustment = vscrolled_bar->adjustment; - - step = adjustment->page_size; - - if (event->button == 4) { - new_value = adjustment->value - step; - if (new_value <= adjustment->lower) { - new_value = adjustment->lower; - } - } else if (event->button == 5) { - new_value = adjustment->value + step; - if (new_value >= adjustment->upper - adjustment->page_size) { - new_value = adjustment->upper - adjustment->page_size; - } - } else - return FALSE; - - if (adjustment->value != new_value) { - adjustment->value = new_value; - gtk_signal_emit_by_name (GTK_OBJECT (adjustment), - "value_changed"); - return TRUE; - } - - return FALSE; -} - - -static void -e_vscrolled_bar_add (GtkContainer *container, - GtkWidget *child) -{ - EVScrolledBar *vscrolled_bar; - GtkBin *bin; - - g_return_if_fail (container != NULL); - g_return_if_fail (E_IS_VSCROLLED_BAR (container)); - - vscrolled_bar = E_VSCROLLED_BAR (container); - bin = GTK_BIN (container); - - g_return_if_fail (bin->child == NULL); - - bin->child = child; - gtk_widget_set_parent (child, GTK_WIDGET (bin)); - - gtk_widget_set_scroll_adjustments (child, NULL, - vscrolled_bar->adjustment); - - if (GTK_WIDGET_REALIZED (child->parent)) - gtk_widget_realize (child); - - if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child)) { - if (GTK_WIDGET_MAPPED (child->parent)) - gtk_widget_map (child); - - gtk_widget_queue_resize (child); - } -} - - -static void -e_vscrolled_bar_remove (GtkContainer *container, - GtkWidget *child) -{ - g_return_if_fail (container != NULL); - g_return_if_fail (E_IS_VSCROLLED_BAR (container)); - g_return_if_fail (child != NULL); - g_return_if_fail (GTK_BIN (container)->child == child); - - gtk_widget_set_scroll_adjustments (child, NULL, NULL); - - /* chain parent class handler to remove child */ - GTK_CONTAINER_CLASS (parent_class)->remove (container, child); -} - - -static void -e_vscrolled_bar_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data) -{ - g_return_if_fail (container != NULL); - g_return_if_fail (E_IS_VSCROLLED_BAR (container)); - g_return_if_fail (callback != NULL); - - GTK_CONTAINER_CLASS (parent_class)->forall (container, - include_internals, - callback, - callback_data); - if (include_internals) { - EVScrolledBar *vscrolled_bar; - - vscrolled_bar = E_VSCROLLED_BAR (container); - - if (vscrolled_bar->up_button) - callback (vscrolled_bar->up_button, callback_data); - if (vscrolled_bar->down_button) - callback (vscrolled_bar->down_button, callback_data); - } -} - - -/** - * e_vscrolled_bar_get_adjustment: - * - * @vscrolled_bar: An #EVScrolledBar. - * @Return: The #GtkAdjustment used for scrolling @vscrolled_bar. - * - * Returns the #GtkAdjustment used for scrolling the #EVscrolledBar. - **/ -GtkAdjustment* -e_vscrolled_bar_get_adjustment (EVScrolledBar *vscrolled_bar) -{ - g_return_val_if_fail (vscrolled_bar != NULL, NULL); - g_return_val_if_fail (E_IS_VSCROLLED_BAR (vscrolled_bar), NULL); - - return vscrolled_bar->adjustment; -} - - -/** - * e_vscrolled_bar_set_adjustment: - * - * @vscrolled_bar: An #EVScrolledBar. - * @adjustment: The #GtkAdjustment to use for scrolling @vscrolled_bar. - * - * Sets the #GtkAdjustment to use for scrolling the #EVscrolledBar. - **/ -void -e_vscrolled_bar_set_adjustment (EVScrolledBar *vscrolled_bar, - GtkAdjustment *adjustment) -{ - g_return_if_fail (vscrolled_bar != NULL); - g_return_if_fail (E_IS_VSCROLLED_BAR (vscrolled_bar)); - - if (adjustment) - g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment)); - else - adjustment = (GtkAdjustment*) gtk_object_new (GTK_TYPE_ADJUSTMENT, NULL); - - if (vscrolled_bar->adjustment == adjustment) - return; - - if (vscrolled_bar->adjustment) { - gtk_signal_disconnect_by_func (GTK_OBJECT (vscrolled_bar->adjustment), - GTK_SIGNAL_FUNC (e_vscrolled_bar_adjustment_changed), - vscrolled_bar); - gtk_object_unref (GTK_OBJECT (vscrolled_bar->adjustment)); - } - - vscrolled_bar->adjustment = adjustment; - gtk_object_ref (GTK_OBJECT (vscrolled_bar->adjustment)); - gtk_object_sink (GTK_OBJECT (vscrolled_bar->adjustment)); - - /* I've used connect_after here to avoid a problem when using a - GnomeCanvas as the child widget. When just using connect it would - leave a blank space when one of the buttons is hidden. We want - the GtkLayout to handle the scrolling before we hide any buttons. */ - gtk_signal_connect_after (GTK_OBJECT (adjustment), "changed", - GTK_SIGNAL_FUNC (e_vscrolled_bar_adjustment_changed), - vscrolled_bar); - gtk_signal_connect_after (GTK_OBJECT (adjustment), "value_changed", - GTK_SIGNAL_FUNC (e_vscrolled_bar_adjustment_changed), - vscrolled_bar); - - e_vscrolled_bar_adjustment_changed (adjustment, vscrolled_bar); - - if (GTK_BIN (vscrolled_bar)->child) - gtk_widget_set_scroll_adjustments (GTK_BIN (vscrolled_bar)->child, NULL, adjustment); -} - - -static void -e_vscrolled_bar_adjustment_changed (GtkAdjustment *adjustment, - gpointer data) -{ - EVScrolledBar *vscrolled_bar; - - g_return_if_fail (adjustment != NULL); - g_return_if_fail (data != NULL); -#if 0 - g_print ("Adjustment changed to: %g\n", adjustment->value); -#endif - vscrolled_bar = E_VSCROLLED_BAR (data); - - if (!GTK_WIDGET_MAPPED (vscrolled_bar)) - return; - - /* If the adjustment value is not 0, show the up button. */ - if (adjustment->value != adjustment->lower) { - gtk_widget_map (vscrolled_bar->up_button); - gdk_window_raise (vscrolled_bar->up_button->window); - } else { - gtk_widget_unmap (vscrolled_bar->up_button); - } - - /* If the adjustment value is less than the maximum value, show the - down button. */ - if (adjustment->value < adjustment->upper - adjustment->page_size) { - gtk_widget_map (vscrolled_bar->down_button); - gdk_window_raise (vscrolled_bar->down_button->window); - } else { - gtk_widget_unmap (vscrolled_bar->down_button); - } -} - - -static void -e_vscrolled_bar_button_pressed (GtkWidget *button, - EVScrolledBar *vscrolled_bar) -{ - if (vscrolled_bar->timeout_id != 0) - g_source_remove (vscrolled_bar->timeout_id); - - vscrolled_bar->timeout_id = g_timeout_add (E_VSCROLLED_BAR_SCROLL_TIMEOUT, e_vscrolled_bar_timeout_handler, vscrolled_bar); - vscrolled_bar->scrolling_up = (button == vscrolled_bar->up_button) ? TRUE : FALSE; - vscrolled_bar->min_distance = vscrolled_bar->adjustment->page_size / 4; - vscrolled_bar->button_pressed = TRUE; - - e_vscrolled_bar_timeout_handler (vscrolled_bar); -} - - -static void -e_vscrolled_bar_button_released (GtkWidget *button, - EVScrolledBar *vscrolled_bar) -{ - vscrolled_bar->button_pressed = FALSE; -} - - -/* This will be called when the user hits the space key to activate the button. - It will also be called just before button_released() is called, but since - we already handle that we simply return if the button is pressed. */ -static void -e_vscrolled_bar_button_clicked (GtkWidget *button, - EVScrolledBar *vscrolled_bar) -{ - if (vscrolled_bar->button_pressed) - return; - - /* We act as if the button is pressed and released immediately. */ - e_vscrolled_bar_button_pressed (button, vscrolled_bar); - vscrolled_bar->button_pressed = FALSE; -} - - -static gboolean -e_vscrolled_bar_timeout_handler (gpointer data) -{ - EVScrolledBar *vscrolled_bar; - GtkAdjustment *adjustment; - gfloat new_value; - gboolean retval = TRUE; - - vscrolled_bar = E_VSCROLLED_BAR (data); - adjustment = vscrolled_bar->adjustment; - - GDK_THREADS_ENTER (); - - /* Check if the user has released the button and we have already - scrolled the minimum distance. */ - if (vscrolled_bar->button_pressed == FALSE - && vscrolled_bar->min_distance <= 0) { - GDK_THREADS_LEAVE (); - return FALSE; - } - - vscrolled_bar->min_distance -= adjustment->step_increment; - - if (vscrolled_bar->scrolling_up) { - new_value = adjustment->value - adjustment->step_increment; - if (new_value <= adjustment->lower) { - new_value = adjustment->lower; - retval = FALSE; - } - } else { - new_value = adjustment->value + adjustment->step_increment; - if (new_value >= adjustment->upper - adjustment->page_size) { - new_value = adjustment->upper - adjustment->page_size; - retval = FALSE; - } - } - - if (adjustment->value != new_value) { - adjustment->value = new_value; - gtk_signal_emit_by_name (GTK_OBJECT (adjustment), - "value_changed"); - } - - GDK_THREADS_LEAVE (); - return retval; -} diff --git a/widgets/shortcut-bar/e-vscrolled-bar.h b/widgets/shortcut-bar/e-vscrolled-bar.h deleted file mode 100644 index 0f4c8bfcec..0000000000 --- a/widgets/shortcut-bar/e-vscrolled-bar.h +++ /dev/null @@ -1,97 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ -#ifndef _E_VSCROLLED_BAR_H_ -#define _E_VSCROLLED_BAR_H_ - -#include <gtk/gtkbin.h> -#include <gtk/gtkadjustment.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * EVScrolledBar is like GtkScrolledWindow but only scrolls the child widget - * vertically. It is intended for scrolling narrow vertical bars. - */ - - -#define E_VSCROLLED_BAR(obj) GTK_CHECK_CAST (obj, e_vscrolled_bar_get_type (), EVScrolledBar) -#define E_VSCROLLED_BAR_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_vscrolled_bar_get_type (), EVScrolledBarClass) -#define E_IS_VSCROLLED_BAR(obj) GTK_CHECK_TYPE (obj, e_vscrolled_bar_get_type ()) - - -typedef struct _EVScrolledBar EVScrolledBar; -typedef struct _EVScrolledBarClass EVScrolledBarClass; - -struct _EVScrolledBar -{ - GtkBin bin; - - GtkWidget *up_button; - GtkWidget *down_button; - - GtkAdjustment *adjustment; - - gint up_button_width; - gint up_button_height; - gint down_button_width; - gint down_button_height; - - /* The GTK+ event source ID of our timeout handler. */ - gint timeout_id; - - /* TRUE if we are scrolling up, FALSE if scrolling down. */ - gboolean scrolling_up; - - /* The minimum distance left to scroll. If the user just clicks a - button we scroll a minimum amount. This is reduced after each - scroll. */ - gfloat min_distance; - - /* TRUE if the button is still pressed. When the up/down button is - released, this gets set to FALSE, and we scroll until the minimum - distance falls below 0. */ - gboolean button_pressed; -}; - -struct _EVScrolledBarClass -{ - GtkBinClass parent_class; -}; - - -GtkType e_vscrolled_bar_get_type (void); -GtkWidget* e_vscrolled_bar_new (GtkAdjustment *adjustment); - -GtkAdjustment* e_vscrolled_bar_get_adjustment (EVScrolledBar *vscrolled_bar); -void e_vscrolled_bar_set_adjustment (EVScrolledBar *vscrolled_bar, - GtkAdjustment *adjustment); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_VSCROLLED_BAR_H_ */ diff --git a/widgets/shortcut-bar/test-shortcut-bar.c b/widgets/shortcut-bar/test-shortcut-bar.c deleted file mode 100644 index 9197fdf16e..0000000000 --- a/widgets/shortcut-bar/test-shortcut-bar.c +++ /dev/null @@ -1,606 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * Author : - * Damon Chaplin <damon@helixcode.com> - * - * Copyright 1999, Helix Code, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - * This tests the ShortcutBar widget. - */ - -#include <gnome.h> - -#include "e-shortcut-bar.h" - -#include <widgets/e-paned/e-hpaned.h> - -#define NUM_SHORTCUT_TYPES 5 -gchar *shortcut_types[NUM_SHORTCUT_TYPES] = { - "folder:", "file:", "calendar:", "todo:", "contacts:" -}; -gchar *icon_filenames[NUM_SHORTCUT_TYPES] = { - "gnome-balsa2.png", "gnome-folder.png", "gnome-calendar.png", - "gnome-cromagnon.png", "gnome-ccthemes.png" -}; -GdkPixbuf *icon_pixbufs[NUM_SHORTCUT_TYPES]; - -GtkWidget *main_label; - -static GdkPixbuf *icon_callback (EShortcutBar *shortcut_bar, - const gchar *url, - gpointer data); - -static void on_main_label_size_allocate (GtkWidget *widget, - GtkAllocation *allocation, - gpointer data); -static void quit (GtkWidget *window, GdkEvent *event, gpointer data); -static void add_test_groups (EShortcutBar *shortcut_bar); -static void add_test_group (EShortcutBar *shortcut_bar, gint i, - gchar *group_name); -static gint get_random_int (gint max); - -static void on_shortcut_bar_item_selected (EShortcutBar *shortcut_bar, - GdkEvent *event, - gint group_num, - gint item_num); -static void show_standard_popup (EShortcutBar *shortcut_bar, - GdkEvent *event, - gint group_num); -static void show_context_popup (EShortcutBar *shortcut_bar, - GdkEvent *event, - gint group_num, - gint item_num); - -static void set_large_icons (GtkWidget *menuitem, - EShortcutBar *shortcut_bar); -static void set_small_icons (GtkWidget *menuitem, - EShortcutBar *shortcut_bar); -static void remove_group (GtkWidget *menuitem, - EShortcutBar *shortcut_bar); - -static void rename_item (GtkWidget *menuitem, - EShortcutBar *shortcut_bar); -static void remove_item (GtkWidget *menuitem, - EShortcutBar *shortcut_bar); -static void on_set_group_button_clicked (GtkWidget *button, - EShortcutBar *shortcut_bar); -static void on_set_group_button_no_animation_clicked (GtkWidget *button, - EShortcutBar *shortcut_bar); -static void on_item_added (EShortcutModel *shortcut_model, - gint group_num, - gint item_num); -static void on_item_removed (EShortcutModel *shortcut_model, - gint group_num, - gint item_num); -static void on_group_added (EShortcutModel *shortcut_model, - gint group_num); -static void on_group_removed (EShortcutModel *shortcut_model, - gint group_num); - -int -main (int argc, char *argv[]) -{ - GtkWidget *window, *hpaned, *shortcut_bar, *vbox, *button; - EShortcutModel *shortcut_model; - gchar *pathname; - gint i; - - gnome_init ("test-shortcut-bar", "0.1", argc, argv); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - window = gnome_app_new ("TestShortcutBar", "TestShortCutBar"); - gtk_window_set_default_size (GTK_WINDOW (window), 600, 400); - gtk_window_set_policy (GTK_WINDOW (window), FALSE, TRUE, FALSE); - - gtk_signal_connect (GTK_OBJECT (window), "delete-event", - GTK_SIGNAL_FUNC (quit), NULL); - - hpaned = e_hpaned_new (); - gnome_app_set_contents (GNOME_APP (window), hpaned); - gtk_widget_show (hpaned); - - shortcut_model = e_shortcut_model_new (); - - shortcut_bar = e_shortcut_bar_new (); - e_shortcut_bar_set_model (E_SHORTCUT_BAR (shortcut_bar), - shortcut_model); - e_paned_pack1 (E_PANED (hpaned), shortcut_bar, FALSE, TRUE); - gtk_widget_show (shortcut_bar); - e_shortcut_bar_set_icon_callback (E_SHORTCUT_BAR (shortcut_bar), - icon_callback, - NULL); - - gtk_signal_connect (GTK_OBJECT (shortcut_model), "item_added", - GTK_SIGNAL_FUNC (on_item_added), NULL); - gtk_signal_connect (GTK_OBJECT (shortcut_model), "item_removed", - GTK_SIGNAL_FUNC (on_item_removed), NULL); - gtk_signal_connect (GTK_OBJECT (shortcut_model), "group_added", - GTK_SIGNAL_FUNC (on_group_added), NULL); - gtk_signal_connect (GTK_OBJECT (shortcut_model), "group_removed", - GTK_SIGNAL_FUNC (on_group_removed), NULL); - -#if 0 - gtk_container_set_border_width (GTK_CONTAINER (shortcut_bar), 4); -#endif - - e_paned_set_position (E_PANED (hpaned), 100); - /*e_paned_set_gutter_size (E_PANED (hpaned), 12);*/ - - vbox = gtk_vbox_new (FALSE, 0); - e_paned_pack2 (E_PANED (hpaned), vbox, TRUE, TRUE); - gtk_widget_show (vbox); - - - main_label = gtk_label_new ("Main Application Window Goes Here"); - gtk_box_pack_start (GTK_BOX (vbox), main_label, TRUE, TRUE, 0); - gtk_widget_show (main_label); - gtk_signal_connect (GTK_OBJECT (main_label), "size_allocate", - GTK_SIGNAL_FUNC (on_main_label_size_allocate), - NULL); - - button = gtk_button_new_with_label ("Set current group to 3rd"); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - gtk_widget_show (button); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (on_set_group_button_clicked), - shortcut_bar); - - button = gtk_button_new_with_label ("Set current group to 5th (no animation)"); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - gtk_widget_show (button); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (on_set_group_button_no_animation_clicked), - shortcut_bar); - - - gtk_widget_pop_visual (); - gtk_widget_pop_colormap (); - - /* Load our default icons. */ - for (i = 0; i < NUM_SHORTCUT_TYPES; i++) { - pathname = gnome_pixmap_file (icon_filenames[i]); - if (pathname) - icon_pixbufs[i] = gdk_pixbuf_new_from_file (pathname); - else - icon_pixbufs[i] = NULL; - } - - add_test_groups (E_SHORTCUT_BAR (shortcut_bar)); - - gtk_signal_connect (GTK_OBJECT (shortcut_bar), "item_selected", - GTK_SIGNAL_FUNC (on_shortcut_bar_item_selected), - NULL); - - gtk_widget_show (window); - gtk_main (); - return 0; -} - - -static GdkPixbuf* -icon_callback (EShortcutBar *shortcut_bar, - const gchar *url, - gpointer data) -{ - gint i; - - for (i = 0; i < NUM_SHORTCUT_TYPES; i++) { - if (!strncmp (url, shortcut_types[i], - strlen (shortcut_types[i]))) { - gdk_pixbuf_ref (icon_pixbufs[i]); - return icon_pixbufs[i]; - } - } - - return NULL; -} - -static void -on_main_label_size_allocate (GtkWidget *widget, - GtkAllocation *allocation, - gpointer data) -{ - g_print ("In on_main_label_size_allocate\n"); -} - -static void -quit (GtkWidget *window, GdkEvent *event, gpointer data) -{ - gtk_widget_destroy (window); - gtk_exit (0); -} - - -static void -add_test_groups (EShortcutBar *shortcut_bar) -{ - add_test_group (shortcut_bar, 1, "Shortcuts"); - add_test_group (shortcut_bar, 2, "My Shortcuts"); - add_test_group (shortcut_bar, 3, "Longer Shortcuts"); - add_test_group (shortcut_bar, 4, "Very Long Shortcuts"); - add_test_group (shortcut_bar, 5, "Incredibly Long Shortcuts"); -} - - -static void -add_test_group (EShortcutBar *shortcut_bar, gint i, gchar *group_name) -{ - gint group_num, item_num, num_items; - gchar buffer[128]; - gint shortcut_type, j; - - group_num = e_shortcut_model_add_group (shortcut_bar->model, -1, - group_name); - - if (group_num % 2) - e_shortcut_bar_set_view_type (shortcut_bar, group_num, - E_ICON_BAR_SMALL_ICONS); - - num_items = get_random_int (5) + 3; - for (j = 1; j <= num_items; j++) { - if (j == 1) - sprintf (buffer, "A very long shortcut with proper words so I can test the wrapping and ellipsis behaviour"); - else if (j == 2) - sprintf (buffer, "A very long shortcut with averylongworkinthemiddlesoIcantestthewrappingandellipsisbehaviour"); - else - sprintf (buffer, "Item %i:%i\n", i, j); - - shortcut_type = get_random_int (NUM_SHORTCUT_TYPES); - item_num = e_shortcut_model_add_item (shortcut_bar->model, - group_num, -1, - shortcut_types[shortcut_type], - buffer); - } -} - - -/* Returns a random integer between 0 and max - 1. */ -static gint -get_random_int (gint max) -{ - gint random_num; - - random_num = (int) (max * (rand () / (RAND_MAX + 1.0))); -#if 0 - g_print ("Random num (%i): %i\n", max, random_num); -#endif - return random_num; -} - - -static void -on_shortcut_bar_item_selected (EShortcutBar *shortcut_bar, - GdkEvent *event, gint group_num, gint item_num) -{ - gchar buffer[256]; - - if (event->button.button == 1) { - sprintf (buffer, "Item Selected - %i:%i", - group_num + 1, item_num + 1); - gtk_label_set_text (GTK_LABEL (main_label), buffer); - } else if (event->button.button == 3) { - if (item_num == -1) - show_standard_popup (shortcut_bar, event, group_num); - else - show_context_popup (shortcut_bar, event, group_num, - item_num); - } -} - - -static void -show_standard_popup (EShortcutBar *shortcut_bar, - GdkEvent *event, - gint group_num) -{ - GtkWidget *menu, *menuitem; - - /* We don't have any commands if there aren't any groups yet. */ - if (group_num == -1) - return; - - menu = gtk_menu_new (); - - menuitem = gtk_menu_item_new_with_label ("Large Icons"); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - gtk_signal_connect (GTK_OBJECT (menuitem), "activate", - GTK_SIGNAL_FUNC (set_large_icons), shortcut_bar); - - menuitem = gtk_menu_item_new_with_label ("Small Icons"); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - gtk_signal_connect (GTK_OBJECT (menuitem), "activate", - GTK_SIGNAL_FUNC (set_small_icons), shortcut_bar); - - menuitem = gtk_menu_item_new (); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new_with_label ("Add New Group"); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new_with_label ("Remove Group"); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - gtk_signal_connect (GTK_OBJECT (menuitem), "activate", - GTK_SIGNAL_FUNC (remove_group), shortcut_bar); - - menuitem = gtk_menu_item_new_with_label ("Rename Group"); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new (); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new_with_label ("Add Shortcut..."); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new (); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new_with_label ("Hide Shortcut Bar"); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - /* Save the group num so we can get it in the callbacks. */ - gtk_object_set_data (GTK_OBJECT (menu), "group_num", - GINT_TO_POINTER (group_num)); - - /* FIXME: Destroy menu when finished with it somehow? */ - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, - event->button.button, event->button.time); -} - - -static void -set_large_icons (GtkWidget *menuitem, - EShortcutBar *shortcut_bar) -{ - GtkWidget *menu; - gint group_num; - - menu = menuitem->parent; - g_return_if_fail (GTK_IS_MENU (menu)); - - group_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu), - "group_num")); - - e_shortcut_bar_set_view_type (shortcut_bar, group_num, - E_ICON_BAR_LARGE_ICONS); -} - - -static void -set_small_icons (GtkWidget *menuitem, - EShortcutBar *shortcut_bar) -{ - GtkWidget *menu; - gint group_num; - - menu = menuitem->parent; - g_return_if_fail (GTK_IS_MENU (menu)); - - group_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu), - "group_num")); - - e_shortcut_bar_set_view_type (shortcut_bar, group_num, - E_ICON_BAR_SMALL_ICONS); -} - - -static void -remove_group (GtkWidget *menuitem, - EShortcutBar *shortcut_bar) -{ - GtkWidget *menu; - gint group_num; - - menu = menuitem->parent; - g_return_if_fail (GTK_IS_MENU (menu)); - - group_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu), - "group_num")); - - e_shortcut_model_remove_group (shortcut_bar->model, group_num); -} - - -static void -show_context_popup (EShortcutBar *shortcut_bar, - GdkEvent *event, - gint group_num, - gint item_num) -{ - GtkWidget *menu, *menuitem, *label, *pixmap; - - menu = gtk_menu_new (); - - menuitem = gtk_pixmap_menu_item_new (); - label = gtk_label_new ("Open Folder"); - gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); - gtk_widget_show (label); - gtk_container_add (GTK_CONTAINER (menuitem), label); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - pixmap = gnome_stock_pixmap_widget (menu, GNOME_STOCK_MENU_OPEN); - if (pixmap) { - gtk_widget_show(pixmap); - gtk_pixmap_menu_item_set_pixmap (GTK_PIXMAP_MENU_ITEM (menuitem), pixmap); - } - - menuitem = gtk_menu_item_new_with_label ("Open in New Window"); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new_with_label ("Advanced Find"); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new (); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new_with_label ("Remove from Shortcut Bar"); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - gtk_signal_connect (GTK_OBJECT (menuitem), "activate", - GTK_SIGNAL_FUNC (remove_item), shortcut_bar); - - menuitem = gtk_menu_item_new_with_label ("Rename Shortcut"); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - gtk_signal_connect (GTK_OBJECT (menuitem), "activate", - GTK_SIGNAL_FUNC (rename_item), shortcut_bar); - - menuitem = gtk_menu_item_new (); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - menuitem = gtk_menu_item_new_with_label ("Properties"); - gtk_widget_set_sensitive (menuitem, FALSE); - gtk_widget_show (menuitem); - gtk_menu_append (GTK_MENU (menu), menuitem); - - - /* Save the group & item nums so we can get them in the callbacks. */ - gtk_object_set_data (GTK_OBJECT (menu), "group_num", - GINT_TO_POINTER (group_num)); - gtk_object_set_data (GTK_OBJECT (menu), "item_num", - GINT_TO_POINTER (item_num)); - - /* FIXME: Destroy menu when finished with it somehow? */ - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, - event->button.button, event->button.time); -} - - -static void -rename_item (GtkWidget *menuitem, - EShortcutBar *shortcut_bar) -{ - GtkWidget *menu; - gint group_num, item_num; - - menu = menuitem->parent; - g_return_if_fail (GTK_IS_MENU (menu)); - - group_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu), - "group_num")); - item_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu), - "item_num")); - - e_shortcut_bar_start_editing_item (shortcut_bar, group_num, item_num); -} - - -static void -remove_item (GtkWidget *menuitem, - EShortcutBar *shortcut_bar) -{ - GtkWidget *menu; - gint group_num, item_num; - - menu = menuitem->parent; - g_return_if_fail (GTK_IS_MENU (menu)); - - group_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu), - "group_num")); - item_num = GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (menu), - "item_num")); - - e_shortcut_model_remove_item (shortcut_bar->model, group_num, - item_num); -} - - -static void -on_set_group_button_clicked (GtkWidget *button, - EShortcutBar *shortcut_bar) -{ - g_print ("In on_set_group_button_clicked\n"); - - e_group_bar_set_current_group_num (E_GROUP_BAR (shortcut_bar), - 2, TRUE); -} - - -static void -on_set_group_button_no_animation_clicked (GtkWidget *button, - EShortcutBar *shortcut_bar) -{ - g_print ("In on_set_group_button_no_animation_clicked\n"); - - e_group_bar_set_current_group_num (E_GROUP_BAR (shortcut_bar), - 4, FALSE); -} - - -static void -on_item_added (EShortcutModel *shortcut_model, - gint group_num, - gint item_num) -{ - g_print ("In on_item_added Group:%i Item:%i\n", group_num, item_num); -} - - -static void -on_item_removed (EShortcutModel *shortcut_model, - gint group_num, - gint item_num) -{ - g_print ("In on_item_removed Group:%i Item:%i\n", group_num, item_num); -} - - -static void -on_group_added (EShortcutModel *shortcut_model, - gint group_num) -{ - g_print ("In on_group_added Group:%i\n", group_num); -} - - -static void -on_group_removed (EShortcutModel *shortcut_model, - gint group_num) -{ - g_print ("In on_group_removed Group:%i\n", group_num); -} diff --git a/widgets/table/.cvsignore b/widgets/table/.cvsignore deleted file mode 100644 index ecfa617948..0000000000 --- a/widgets/table/.cvsignore +++ /dev/null @@ -1,12 +0,0 @@ -.deps -.libs -.pure -Makefile -Makefile.in -*.lo -*.la -table-test -table-example-1 -table-example-2 -table-size-test -tree-example-1 diff --git a/widgets/table/add-col.xpm b/widgets/table/add-col.xpm deleted file mode 100644 index 9c5f314c8e..0000000000 --- a/widgets/table/add-col.xpm +++ /dev/null @@ -1,22 +0,0 @@ -/* XPM */ -static char * add_col_xpm[] = { -"16 16 3 1", -" c None", -". c #000000", -"+ c #FFFFFF", -" ", -" ", -" ", -" ", -" .............. ", -" .++++++++++++. ", -" .++++++++++++. ", -" ....+++....... ", -" .+. ", -" . ", -" ", -" ", -" ", -" ", -" ", -" "}; diff --git a/widgets/table/arrow-down.xpm b/widgets/table/arrow-down.xpm deleted file mode 100644 index f1e6cb4b3c..0000000000 --- a/widgets/table/arrow-down.xpm +++ /dev/null @@ -1,21 +0,0 @@ -/* XPM */ -static const char * arrow_down_xpm[] = { -"13 16 2 1", -" c None", -". c #FF0000", -" ... ", -" ... ", -" ... ", -" ... ", -" ... ", -" ... ", -" ... ", -" ... ", -" ... ", -".............", -" ........... ", -" ......... ", -" ....... ", -" ..... ", -" ... ", -" . "}; diff --git a/widgets/table/arrow-up.xpm b/widgets/table/arrow-up.xpm deleted file mode 100644 index 0cc5b9a00c..0000000000 --- a/widgets/table/arrow-up.xpm +++ /dev/null @@ -1,21 +0,0 @@ -/* XPM */ -static const char * arrow_up_xpm[] = { -"13 16 2 1", -" c None", -". c #FF0000", -" . ", -" ... ", -" ..... ", -" ....... ", -" ......... ", -" ........... ", -".............", -" ... ", -" ... ", -" ... ", -" ... ", -" ... ", -" ... ", -" ... ", -" ... ", -" ... "}; diff --git a/widgets/table/check-empty.xpm b/widgets/table/check-empty.xpm deleted file mode 100644 index 746b20234e..0000000000 --- a/widgets/table/check-empty.xpm +++ /dev/null @@ -1,21 +0,0 @@ -/* XPM */ -static const char * check_empty_xpm[] = { -"16 16 2 1", -" c None", -". c #000000", -" ", -" ", -" ............ ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" . . ", -" ............ ", -" ", -" "}; diff --git a/widgets/table/check-filled.xpm b/widgets/table/check-filled.xpm deleted file mode 100644 index c0468fc25b..0000000000 --- a/widgets/table/check-filled.xpm +++ /dev/null @@ -1,21 +0,0 @@ -/* XPM */ -static const char * check_filled_xpm[] = { -"16 16 2 1", -" c None", -". c #000000", -" ", -" ", -" ............ ", -" . . ", -" . . . ", -" . .. . ", -" . ... . ", -" . . ... . ", -" . .. ... . ", -" . ..... . ", -" . ... . ", -" . . . ", -" . . ", -" ............ ", -" ", -" "}; diff --git a/widgets/table/clip.png b/widgets/table/clip.png Binary files differdeleted file mode 100644 index 27aa5f072f..0000000000 --- a/widgets/table/clip.png +++ /dev/null diff --git a/widgets/table/e-cell-checkbox.c b/widgets/table/e-cell-checkbox.c deleted file mode 100644 index 1d7c319f74..0000000000 --- a/widgets/table/e-cell-checkbox.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * e-cell-checkbox.c: Checkbox cell renderer - * - * Author: - * Miguel de Icaza (miguel@kernel.org) - * - * (C) 1999 Helix Code, Inc - */ -#include <config.h> -#include <gtk/gtkenums.h> -#include <gtk/gtkentry.h> -#include <gtk/gtkwindow.h> -#include <gtk/gtksignal.h> -#include <gdk/gdkkeysyms.h> -#include <libgnomeui/gnome-canvas.h> -#include "e-cell-checkbox.h" -#include "e-util/e-util.h" -#include "e-table-item.h" - -#include "check-empty.xpm" -#include "check-filled.xpm" - -#define PARENT_TYPE e_cell_toggle_get_type () - -static GdkPixbuf *checks [2]; - -static void -e_cell_checkbox_class_init (GtkObjectClass *object_class) -{ - checks [0] = gdk_pixbuf_new_from_xpm_data (check_empty_xpm); - checks [1] = gdk_pixbuf_new_from_xpm_data (check_filled_xpm); -} - -E_MAKE_TYPE(e_cell_checkbox, "ECellCheckbox", ECellCheckbox, e_cell_checkbox_class_init, NULL, PARENT_TYPE); - -ECell * -e_cell_checkbox_new (void) -{ - ECellCheckbox *eccb = gtk_type_new (e_cell_checkbox_get_type ()); - - e_cell_toggle_construct (E_CELL_TOGGLE (eccb), 2, 2, checks); - - return (ECell *) eccb; -} diff --git a/widgets/table/e-cell-checkbox.h b/widgets/table/e-cell-checkbox.h deleted file mode 100644 index 969e4a5edc..0000000000 --- a/widgets/table/e-cell-checkbox.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _E_CELL_CHECKBOX_H_ -#define _E_CELL_CHECKBOX_H_ - -#include "e-cell-toggle.h" - -#define E_CELL_CHECKBOX_TYPE (e_cell_checkbox_get_type ()) -#define E_CELL_CHECKBOX(o) (GTK_CHECK_CAST ((o), E_CELL_CHECKBOX_TYPE, ECellCheckbox)) -#define E_CELL_CHECKBOX_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_CHECKBOX_TYPE, ECellCheckboxClass)) -#define E_IS_CELL_CHECKBOX(o) (GTK_CHECK_TYPE ((o), E_CELL_CHECKBOX_TYPE)) -#define E_IS_CELL_CHECKBOX_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_CHECKBOX_TYPE)) - -typedef struct { - ECellToggle parent; -} ECellCheckbox; - -typedef struct { - ECellToggleClass parent_class; -} ECellCheckboxClass; - -GtkType e_cell_checkbox_get_type (void); -ECell *e_cell_checkbox_new (void); - -#endif /* _E_CELL_CHECKBOX_H_ */ - diff --git a/widgets/table/e-cell-string.c b/widgets/table/e-cell-string.c deleted file mode 100644 index 992b1bd10e..0000000000 --- a/widgets/table/e-cell-string.c +++ /dev/null @@ -1,9 +0,0 @@ -ECell * -e_cell_string_new (void) -{ - ECell *ecell; - - ecell = gtk_type_new (ecell); - - return ecell; -} diff --git a/widgets/table/e-cell-text.c b/widgets/table/e-cell-text.c deleted file mode 100644 index 279ef4975b..0000000000 --- a/widgets/table/e-cell-text.c +++ /dev/null @@ -1,2314 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-cell-text.c - Text cell renderer - * Copyright (C) 2000 Helix Code, Inc. - * - * Authors: Miguel de Icaza <miguel@helixcode.com> - * Chris Lahey <clahey@helixcode.com> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - * - * TODO: - * Clean up UTF-8 handling - * UTF-8 selection - */ - -#include <config.h> -#include <gtk/gtkenums.h> -#include <gtk/gtkentry.h> -#include <gtk/gtkwindow.h> -#include <gtk/gtkinvisible.h> -#include <gtk/gtksignal.h> -#include <gdk/gdkkeysyms.h> -#include <libgnomeui/gnome-canvas.h> -#include <stdio.h> -#include <unicode.h> -#include "e-cell-text.h" -#include "e-util/e-util.h" -#include "e-util/e-font.h" -#include "e-table-item.h" -#include "e-text-event-processor.h" -#include "e-text-event-processor-emacs-like.h" - -#include <gdk/gdkx.h> /* for BlackPixel */ -#include <ctype.h> -#include <math.h> - -/* This defines a line of text */ -struct line { - char *text; /* Line's text UTF-8, it is a pointer into the text->text string */ - int length; /* Line's length in BYTES */ - int width; /* Line's width in pixels */ - int ellipsis_length; /* Length before adding ellipsis in BYTES */ -}; - -/* Object argument IDs */ -enum { - ARG_0, - ARG_TEXT, /* UTF-8 */ - ARG_X, - ARG_Y, - ARG_FONT, - ARG_FONTSET, - ARG_FONT_GDK, - ARG_ANCHOR, - ARG_JUSTIFICATION, - ARG_CLIP_WIDTH, - ARG_CLIP_HEIGHT, - ARG_CLIP, - ARG_X_OFFSET, - ARG_Y_OFFSET, - ARG_FILL_COLOR, - ARG_FILL_COLOR_GDK, - ARG_FILL_COLOR_RGBA, - ARG_FILL_STIPPLE, - ARG_TEXT_WIDTH, - ARG_TEXT_HEIGHT, - ARG_USE_ELLIPSIS, - ARG_ELLIPSIS, - ARG_STRIKEOUT_COLUMN, - ARG_BOLD_COLUMN, - ARG_TEXT_FILTER, - ARG_COLOR_COLUMN, -}; - - -enum { - E_SELECTION_PRIMARY, - E_SELECTION_CLIPBOARD -}; - -static GdkAtom clipboard_atom = GDK_NONE; - -#define PARENT_TYPE e_cell_get_type () - -#define TEXT_PAD 4 - -typedef struct { - gpointer lines; /* Text split into lines (private field) */ - int num_lines; /* Number of lines of text */ - int max_width; - int ref_count; -} ECellTextLineBreaks; - - -typedef struct _CellEdit CellEdit; - -typedef struct { - ECellView cell_view; - GdkGC *gc; -#if 0 - GdkFont *font; -#else - EFont *font; -#endif - GdkCursor *i_cursor; - GdkBitmap *stipple; /* Stipple for text */ - - GnomeCanvas *canvas; - - /* - * During editing. - */ - CellEdit *edit; - - - int xofs, yofs; /* This gets added to the x - and y for the cell text. */ - double ellipsis_width; /* The width of the ellipsis. */ - -} ECellTextView; - -typedef struct _CurrentCell{ - ECellTextView *text_view; - int width; - char *text; - int model_col, view_col, row; - ECellTextLineBreaks *breaks; -} CurrentCell; - -#define CURRENT_CELL(x) ((CurrentCell *)(x)) - -struct _CellEdit { - CurrentCell cell; - - char *old_text; - - /* - * Where the editing is taking place - */ - - int xofs_edit, yofs_edit; /* Offset because of editing. - This is negative compared - to the other offsets. */ - - /* This needs to be reworked a bit once we get line wrapping. */ - int selection_start; /* Start of selection - IN BYTES */ - int selection_end; /* End of selection - IN BYTES */ - gboolean select_by_word; /* Current selection is by word */ - - /* This section is for drag scrolling and blinking cursor. */ - /* Cursor handling. */ - gint timeout_id; /* Current timeout id for scrolling */ - GTimer *timer; /* Timer for blinking cursor and scrolling */ - - gint lastx, lasty; /* Last x and y motion events */ - gint last_state; /* Last state */ - gulong scroll_start; /* Starting time for scroll (microseconds) */ - - gint show_cursor; /* Is cursor currently shown */ - gboolean button_down; /* Is mouse button 1 down */ - - ETextEventProcessor *tep; /* Text Event Processor */ - - /* Hmmm... this should probably be in native encoding? */ - - GtkWidget *invisible; /* For selection handling */ - gboolean has_selection; /* TRUE if we have the selection */ - gchar *primary_selection; /* Primary selection text */ - gint primary_length; /* Primary selection text length in BYTES */ - gchar *clipboard_selection; /* Clipboard selection text */ - gint clipboard_length; /* Clipboard selection text length in BYTES */ - - guint pointer_in : 1; - guint default_cursor_shown : 1; -}; - -static void e_cell_text_view_command (ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data); - -static void e_cell_text_view_get_selection (CellEdit *edit, GdkAtom selection, guint32 time); -static void e_cell_text_view_supply_selection (CellEdit *edit, guint time, GdkAtom selection, char *data, gint length); - -static GtkWidget *e_cell_text_view_get_invisible (CellEdit *edit); -static void _selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - CellEdit *edit); -static void _selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - CellEdit *edit); -static void _selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - CellEdit *edit); -static int number_of_lines (char *text); -static void split_into_lines (CurrentCell *cell); -static void unref_lines (CurrentCell *cell); -static void calc_line_widths (CurrentCell *cell); -static int get_line_ypos (CurrentCell *cell, struct line *line); -static int get_line_xpos (CurrentCell *cell, struct line *line); -static void _get_tep (CellEdit *edit); - -static gint _get_position_from_xy (CurrentCell *cell, gint x, gint y); -static void _get_xy_from_position (CurrentCell *cell, gint position, gint *xp, gint *yp); -static gboolean _blink_scroll_timeout (gpointer data); - -static void build_current_cell (CurrentCell *cell, ECellTextView *text_view, int model_col, int view_col, int row); -static void unbuild_current_cell (CurrentCell *cell); -static void calc_ellipsis (ECellTextView *text_view); -static void ect_free_color (gchar *color_spec, GdkColor *color, GdkColormap *colormap); -static GdkColor* e_cell_text_get_color (ECellTextView *cell_view, gchar *color_spec); - -static ECellClass *parent_class; - -static void -ect_queue_redraw (ECellTextView *text_view, int view_col, int view_row) -{ - e_table_item_redraw_range ( - text_view->cell_view.e_table_item_view, - view_col, view_row, view_col, view_row); -} - -/* - * Accept the currently edited text. if it's the same as what's in the cell, do nothing. - */ -static void -ect_accept_edits (ECellTextView *text_view) -{ - CurrentCell *cell = (CurrentCell *) text_view->edit; - - if (strcmp (text_view->edit->old_text, cell->text)) { - e_table_model_set_value_at (text_view->cell_view.e_table_model, - cell->model_col, cell->row, cell->text); - } -} - -/* - * Shuts down the editing process - */ -static void -ect_stop_editing (ECellTextView *text_view) -{ - CellEdit *edit = text_view->edit; - int row, view_col; - - if (!edit) - return; - - row = edit->cell.row; - view_col = edit->cell.view_col; - - g_free (edit->old_text); - edit->old_text = NULL; - g_free (edit->cell.text); - edit->cell.text = NULL; - if (edit->invisible) - gtk_widget_unref (edit->invisible); - if (edit->tep) - gtk_object_unref (GTK_OBJECT(edit->tep)); - if (edit->primary_selection) - g_free (edit->primary_selection); - if (edit->clipboard_selection) - g_free (edit->clipboard_selection); - if (! edit->default_cursor_shown){ - gdk_window_set_cursor (GTK_WIDGET(text_view->canvas)->window, NULL); - edit->default_cursor_shown = TRUE; - } - if (edit->timeout_id) { - g_source_remove (edit->timeout_id); - edit->timeout_id = 0; - } - if (edit->timer) { - g_timer_stop (edit->timer); - g_timer_destroy (edit->timer); - edit->timer = NULL; - } - - g_free (edit); - - text_view->edit = NULL; - ect_queue_redraw (text_view, view_col, row); -} - -/* - * Cancels the edits - */ -static void -ect_cancel_edit (ECellTextView *text_view) -{ - ect_stop_editing (text_view); -} - -/* - * ECell::new_view method - */ -static ECellView * -ect_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - ECellText *ect = E_CELL_TEXT (ecell); - ECellTextView *text_view = g_new0 (ECellTextView, 1); - GnomeCanvas *canvas = GNOME_CANVAS_ITEM (e_table_item_view)->canvas; - - text_view->cell_view.ecell = ecell; - text_view->cell_view.e_table_model = table_model; - text_view->cell_view.e_table_item_view = e_table_item_view; - - if (ect->font_name){ -#if 0 - GdkFont *f; - - f = gdk_fontset_load (ect->font_name); - text_view->font = f; -#endif - text_view->font = e_font_from_gdk_name (ect->font_name); - } - if (!text_view->font){ - text_view->font = e_font_from_gdk_font (GTK_WIDGET (canvas)->style->font); - } - - text_view->canvas = canvas; - - text_view->xofs = 0.0; - text_view->yofs = 0.0; - - return (ECellView *)text_view; -} - -/* - * ECell::kill_view method - */ -static void -ect_kill_view (ECellView *ecv) -{ - ECellTextView *text_view = (ECellTextView *) ecv; - - g_free (text_view); -} - -/* - * ECell::realize method - */ -static void -ect_realize (ECellView *ecell_view) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - - text_view->gc = gdk_gc_new (GTK_WIDGET (text_view->canvas)->window); - - text_view->i_cursor = gdk_cursor_new (GDK_XTERM); - - calc_ellipsis (text_view); - - if (parent_class->realize) - (* parent_class->realize) (ecell_view); -} - -/* - * ECell::unrealize method - */ -static void -ect_unrealize (ECellView *ecv) -{ - ECellTextView *text_view = (ECellTextView *) ecv; - ECellText *ect = (ECellText*) ecv->ecell; - GdkColormap *colormap; - - gdk_gc_unref (text_view->gc); - text_view->gc = NULL; - - if (text_view->edit){ - ect_cancel_edit (text_view); - } - - if (text_view->font) - e_font_unref (text_view->font); - - if (text_view->stipple) - gdk_bitmap_unref (text_view->stipple); - - gdk_cursor_destroy (text_view->i_cursor); - - if (ect->colors) { - colormap = gtk_widget_get_colormap (GTK_WIDGET (text_view->canvas)); - g_hash_table_foreach (ect->colors, (GHFunc) ect_free_color, - colormap); - g_hash_table_destroy (ect->colors); - ect->colors = NULL; - } - - if (parent_class->unrealize) - (* parent_class->unrealize) (ecv); -} - -static void -ect_free_color (gchar *color_spec, GdkColor *color, GdkColormap *colormap) -{ - - g_free (color_spec); - - /* This frees the color. Note we don't free it if it is the special - value. */ - if (color != (GdkColor*) 1) { - gdk_colors_free (colormap, &color->pixel, 1, 0); - - /* This frees the memory for the GdkColor. */ - gdk_color_free (color); - } -} - -/* - * ECell::draw method - */ -static void -ect_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, gboolean selected, - int x1, int y1, int x2, int y2) -{ - /* New ECellText */ - ECellText *ect = E_CELL_TEXT (ecell_view->ecell); - ECellTextView *text_view = (ECellTextView *) ecell_view; - GtkWidget *canvas = GTK_WIDGET (text_view->canvas); - GdkRectangle rect, *clip_rect; - struct line *lines; - int i; - int xpos, ypos; - int start_char, end_char; - int sel_start, sel_end; - GdkRectangle sel_rect; - GdkGC *fg_gc; - EFont *font = text_view->font; - const int height = e_font_height (text_view->font); - CellEdit *edit = text_view->edit; - gboolean edit_display = FALSE; - ECellTextLineBreaks *linebreaks; - GdkColor *foreground, *cell_foreground, *cursor_color; - gchar *color_spec; - - EFontStyle style = E_FONT_PLAIN; - - if (ect->bold_column >= 0 && e_table_model_value_at(ecell_view->e_table_model, ect->bold_column, row)) - style = E_FONT_BOLD; - - if (edit){ - if ((edit->cell.view_col == view_col) && (edit->cell.row == row)) { - edit_display = TRUE; - fg_gc = canvas->style->fg_gc[edit->has_selection ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE]; - } else - fg_gc = canvas->style->fg_gc[GTK_STATE_ACTIVE]; - } else { - fg_gc = canvas->style->fg_gc[GTK_STATE_ACTIVE]; - } - - /* - * Be a nice citizen: clip to the region we are supposed to draw on - */ - rect.x = x1; - rect.y = y1; - rect.width = x2 - x1; - rect.height = y2 - y1; - - gdk_gc_set_clip_rectangle (text_view->gc, &rect); - gdk_gc_set_clip_rectangle (fg_gc, &rect); - clip_rect = ▭ - - if (selected){ - foreground = &canvas->style->text [GTK_STATE_SELECTED]; - } else { - foreground = &canvas->style->text [GTK_STATE_NORMAL]; - } - - cursor_color = foreground; - - if (ect->color_column != -1) { - color_spec = e_table_model_value_at (ecell_view->e_table_model, - ect->color_column, row); - cell_foreground = e_cell_text_get_color (text_view, - color_spec); - if (cell_foreground) - foreground = cell_foreground; - } - - gdk_gc_set_foreground (text_view->gc, foreground); - - x1 += 4; - y1 += 1; - x2 -= 4; - y2 -= 1; - - rect.x = x1; - rect.y = y1; - rect.width = x2 - x1; - rect.height = y2 - y1; - - gdk_gc_set_clip_rectangle (text_view->gc, &rect); - gdk_gc_set_clip_rectangle (fg_gc, &rect); - clip_rect = ▭ - - if (edit_display){ - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - - cell->width = x2 - x1; - - split_into_lines (cell); - - linebreaks = cell->breaks; - - lines = linebreaks->lines; - ypos = get_line_ypos (cell, lines); - ypos += e_font_ascent (text_view->font); - ypos -= edit->yofs_edit; - - for (i = 0; i < linebreaks->num_lines; i++) { - xpos = get_line_xpos (cell, lines); - xpos -= edit->xofs_edit; - - /* start_char, end_char, sel_start and sel_end are IN BYTES */ - - start_char = lines->text - cell->text; - end_char = start_char + lines->length; - - sel_start = edit->selection_start; - sel_end = edit->selection_end; - - if (sel_start > sel_end){ - sel_start ^= sel_end; - sel_end ^= sel_start; - sel_start ^= sel_end; - } - if (sel_start < start_char) - sel_start = start_char; - if (sel_end > end_char) - sel_end = end_char; - - if (sel_start < sel_end){ - sel_rect.x = xpos + x1 + e_font_utf8_text_width (font, style, lines->text, sel_start - start_char); - sel_rect.y = ypos + y1 - e_font_ascent (font); - sel_rect.width = e_font_utf8_text_width (font, style, - lines->text + sel_start - start_char, - sel_end - sel_start); - sel_rect.height = height; - gtk_paint_flat_box (canvas->style, - drawable, - edit->has_selection ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE, - GTK_SHADOW_NONE, - clip_rect, - canvas, - "text", - sel_rect.x, - sel_rect.y, - sel_rect.width, - sel_rect.height); - - e_font_draw_utf8_text (drawable, font, style, text_view->gc, xpos + x1, ypos + y1, - lines->text, - sel_start - start_char); - e_font_draw_utf8_text (drawable, font, style, fg_gc, - xpos + x1 + e_font_utf8_text_width (font, style, lines->text, sel_start - start_char), - ypos + y1, - lines->text + sel_start - start_char, - sel_end - sel_start); - e_font_draw_utf8_text (drawable, font, style, text_view->gc, - xpos + x1 + e_font_utf8_text_width (font, style, lines->text, sel_end - start_char), - ypos + y1, - lines->text + sel_end - start_char, - end_char - sel_end); -#if 0 /* Do Bold in EFont directly */ - /* Draw 1,0 moved image, to simulate bold font */ - /* We move that to EFont */ - if (bold) { - e_font_draw_utf8_text (drawable, font, text_view->gc, xpos + x1 + 1, ypos + y1, - lines->text, - sel_start - start_char); - e_font_draw_utf8_text (drawable, font, fg_gc, - xpos + x1 + 1 + e_font_utf8_text_width (font, lines->text, sel_start - start_char), - ypos + y1, - g_utf8_offset_to_pointer (lines->text, sel_start - start_char), - sel_end - sel_start); - e_font_draw_utf8_text (drawable, font, text_view->gc, - xpos + x1 + 1 + e_font_utf8_text_width (font, lines->text, sel_end - start_char), - ypos + y1, - g_utf8_offset_to_pointer (lines->text, sel_end - start_char), - end_char - sel_end); - } -#endif - } else { - e_font_draw_utf8_text (drawable, font, style, text_view->gc, - xpos + x1, ypos + y1, - lines->text, - lines->length); -#if 0 - if (bold) { - e_font_draw_ucs2_text (drawable, - font, - text_view->gc, - xpos + x1 + 1, - ypos + y1, - lines->text, - lines->length); - } -#endif - } - if (edit->selection_start == edit->selection_end && - edit->selection_start >= start_char && - edit->selection_start <= end_char && - edit->show_cursor) { - gdk_gc_set_foreground (text_view->gc, cursor_color); - gdk_draw_rectangle (drawable, - text_view->gc, - TRUE, - xpos + x1 + e_font_utf8_text_width (font, style, lines->text, sel_start - start_char), - ypos + y1 - e_font_ascent (font), - 1, - height); - } - if (ect->strikeout_column >= 0 && e_table_model_value_at(ecell_view->e_table_model, ect->strikeout_column, row)) { - gdk_draw_rectangle (drawable, - text_view->gc, - TRUE, - x1, ypos + y1 - (e_font_ascent (font) / 2), - x2 - x1, - 1); - } - ypos += height; - lines ++; - } - unref_lines (cell); - } else { - - ECellTextLineBreaks *linebreaks; - CurrentCell cell; - build_current_cell (&cell, text_view, model_col, view_col, row); - - cell.width = x2 - x1; - - split_into_lines (&cell); - - linebreaks = cell.breaks; - lines = linebreaks->lines; - ypos = get_line_ypos (&cell, lines); - ypos += e_font_ascent (text_view->font); - - - for (i = 0; i < linebreaks->num_lines; i++) { - xpos = get_line_xpos (&cell, lines); - if (ect->use_ellipsis && lines->ellipsis_length < lines->length) { - e_font_draw_utf8_text (drawable, font, style, text_view->gc, - xpos + x1, ypos + y1, - lines->text, - lines->ellipsis_length); - e_font_draw_utf8_text (drawable, font, style, text_view->gc, - xpos + x1 + lines->width - text_view->ellipsis_width, - ypos + y1, - ect->ellipsis ? ect->ellipsis : "...", - ect->ellipsis ? strlen (ect->ellipsis) : 3); -#if 0 - if (bold) { - e_font_draw_ucs2_text (drawable, - font, - text_view->gc, - xpos + x1 + 1, - ypos + y1, - lines->text, - lines->ellipsis_length); - e_font_draw_utf8_text (drawable, - font, - text_view->gc, - xpos + x1 + 1 + - lines->width - text_view->ellipsis_width, - ypos + y1, - ect->ellipsis ? ect->ellipsis : "...", - ect->ellipsis ? strlen (ect->ellipsis) : 3); - } -#endif - } else { - e_font_draw_utf8_text (drawable, font, style, text_view->gc, - xpos + x1, - ypos + y1, - lines->text, - lines->length); -#if 0 - if (bold) { - e_font_draw_ucs2_text (drawable, - font, - text_view->gc, - xpos + x1 + 1, - ypos + y1, - lines->text, - lines->length); - } -#endif - } - if (ect->strikeout_column >= 0 && e_table_model_value_at(ecell_view->e_table_model, ect->strikeout_column, row)) { - gdk_draw_rectangle (drawable, - text_view->gc, - TRUE, - x1, ypos + y1 - (e_font_ascent (font) / 2), - x2 - x1, - 1); - } - ypos += height; - lines++; - } - unref_lines (&cell); - unbuild_current_cell (&cell); - } - - gdk_gc_set_clip_rectangle (text_view->gc, NULL); - gdk_gc_set_clip_rectangle (fg_gc, NULL); -#if 0 - /* Old ECellText */ - - int xoff; - gboolean edit_display = FALSE; - - /* - * Figure if this cell is being edited - */ - if (edit_display){ - CellEdit *edit = text_view->edit; - const char *text = gtk_entry_get_text (edit->entry); - GdkWChar *p, *text_wc = g_new (GdkWChar, strlen (text) + 1); - int text_wc_len = gdk_mbstowcs (text_wc, text, strlen (text)); - const int cursor_pos = GTK_EDITABLE (edit->entry)->current_pos; - const int left_len = gdk_text_width_wc (text_view->font, text_wc, cursor_pos); - - text_wc [text_wc_len] = 0; - /* - * Paint - */ - gdk_gc_set_foreground (text_view->gc, &w->style->base [GTK_STATE_NORMAL]); - gdk_draw_rectangle (drawable, text_view->gc, TRUE, - rect.x, rect.y, rect.width, rect.height); - gdk_gc_set_foreground (text_view->gc, &w->style->text [GTK_STATE_NORMAL]); - - { - GdkGC *gc = text_view->gc; - const int y = y2 - font->descent - ((y2-y1-height)/2); - int px, i; - - /* - * Border - */ - x1 += 2; - x2--; - - px = x1; - - /* - * If the cursor is outside the visible range - * - * FIXME: we really want a better behaviour. - */ - if ((px + left_len) > x2) - px -= left_len - (x2-x1); - - /* - * Draw - */ - for (i = 0, p = text_wc; *p; p++, i++){ - gdk_draw_text_wc ( - drawable, font, gc, px, y, p, 1); - - if (i == cursor_pos){ - gdk_draw_line ( - drawable, gc, - px, y - font->ascent, - px, y + font->descent - 1); - } - - px += gdk_text_width_wc (font, p, 1); - } - - if (i == cursor_pos){ - gdk_draw_line ( - drawable, gc, - px, y - font->ascent, - px, y + font->descent - 1); - } - } - g_free (text_wc); - } else { - /* - * Regular cell - */ - GdkColor *background, *foreground; - int width; - - /* - * Border - */ - x1++; - x2--; - - /* - * Compute draw mode - */ - switch (ect->justify){ - case GTK_JUSTIFY_LEFT: - xoff = 1; - break; - - case GTK_JUSTIFY_RIGHT: - width = 1 + gdk_text_width (font, str, strlen (str)); - xoff = (x2 - x1) - width; - break; - - case GTK_JUSTIFY_CENTER: - xoff = ((x2 - x1) - gdk_text_width (font, str, strlen (str))) / 2; - break; - default: - xoff = 0; - g_warning ("Can not handle GTK_JUSTIFY_FILL"); - break; - } - - - if (selected){ - background = &w->style->bg [GTK_STATE_SELECTED]; - foreground = &w->style->text [GTK_STATE_SELECTED]; - } else { - background = &w->style->base [GTK_STATE_NORMAL]; - foreground = &w->style->text [GTK_STATE_NORMAL]; - } - - gdk_gc_set_foreground (text_view->gc, background); - gdk_draw_rectangle (drawable, text_view->gc, TRUE, - rect.x, rect.y, rect.width, rect.height); - gdk_gc_set_foreground (text_view->gc, foreground); - - gdk_draw_string ( - drawable, font, text_view->gc, - x1 + xoff, - y2 - font->descent - ((y2-y1-height)/2), str); - } -#endif -} - -/* - * Selects the entire string - */ -static void -ect_edit_select_all (ECellTextView *text_view) -{ - g_assert (text_view->edit); - - text_view->edit->selection_start = 0; - text_view->edit->selection_end = strlen (text_view->edit->cell.text); -} - -/* - * ECell::event method - */ -static gint -ect_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - ETextEventProcessorEvent e_tep_event; - gboolean edit_display = FALSE; - CellEdit *edit = text_view->edit; - GtkWidget *canvas = GTK_WIDGET (text_view->canvas); - gint return_val = 0; - - CurrentCell cell, *cellptr; - build_current_cell (&cell, text_view, model_col, view_col, row); - - - if (edit){ - if ((edit->cell.view_col == view_col) && (edit->cell.row == row)) { - edit_display = TRUE; - cellptr = CURRENT_CELL(edit); - } else { - cellptr = &cell; - } - } else { - cellptr = &cell; - } - - e_tep_event.type = event->type; - switch (event->type) { - case GDK_FOCUS_CHANGE: - break; - case GDK_KEY_PRESS: /* Fall Through */ - case GDK_KEY_RELEASE: - if (event->key.keyval == GDK_Escape){ - ect_cancel_edit (text_view); - return_val = TRUE; - break; - } - - if ((!edit_display) && e_table_model_is_cell_editable (ecell_view->e_table_model, model_col, row)) { - e_table_item_enter_edit (text_view->cell_view.e_table_item_view, view_col, row); - ect_edit_select_all (text_view); - edit = text_view->edit; - cellptr = CURRENT_CELL(edit); - edit_display = TRUE; - } - if (edit_display) { - GdkEventKey key = event->key; - if (key.keyval == GDK_KP_Enter || key.keyval == GDK_Return){ - e_table_item_leave_edit (text_view->cell_view.e_table_item_view); - } else { - e_tep_event.key.time = key.time; - e_tep_event.key.state = key.state; - e_tep_event.key.keyval = key.keyval; - e_tep_event.key.length = key.length; - e_tep_event.key.string = key.string; - _get_tep (edit); - return_val = e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - break; - } - } - - else - return 0; - break; - case GDK_BUTTON_PRESS: /* Fall Through */ - case GDK_BUTTON_RELEASE: - event->button.x -= 4; - event->button.y -= 1; - if ((!edit_display) - && e_table_model_is_cell_editable (ecell_view->e_table_model, model_col, row) - && event->type == GDK_BUTTON_RELEASE - && event->button.button == 1) { - GdkEventButton button = event->button; - - e_table_item_enter_edit (text_view->cell_view.e_table_item_view, view_col, row); - edit = text_view->edit; - cellptr = CURRENT_CELL(edit); - edit_display = TRUE; - - e_tep_event.button.type = GDK_BUTTON_PRESS; - e_tep_event.button.time = button.time; - e_tep_event.button.state = button.state; - e_tep_event.button.button = button.button; - e_tep_event.button.position = _get_position_from_xy (cellptr, button.x, button.y); - _get_tep (edit); - return_val = e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - if (event->button.button == 1) { - if (event->type == GDK_BUTTON_PRESS) - edit->button_down = TRUE; - else - edit->button_down = FALSE; - } - edit->lastx = button.x; - edit->lasty = button.y; - edit->last_state = button.state; - - e_tep_event.button.type = GDK_BUTTON_RELEASE; - } - if (edit_display) { - GdkEventButton button = event->button; - e_tep_event.button.time = button.time; - e_tep_event.button.state = button.state; - e_tep_event.button.button = button.button; - e_tep_event.button.position = _get_position_from_xy (cellptr, button.x, button.y); - _get_tep (edit); - return_val = e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - if (event->button.button == 1) { - if (event->type == GDK_BUTTON_PRESS) - edit->button_down = TRUE; - else - edit->button_down = FALSE; - } - edit->lastx = button.x; - edit->lasty = button.y; - edit->last_state = button.state; - } - break; - case GDK_MOTION_NOTIFY: - event->motion.x -= 4; - event->motion.y -= 1; - if (edit_display) { - GdkEventMotion motion = event->motion; - e_tep_event.motion.time = motion.time; - e_tep_event.motion.state = motion.state; - e_tep_event.motion.position = _get_position_from_xy (cellptr, motion.x, motion.y); - _get_tep (edit); - return_val = e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - edit->lastx = motion.x; - edit->lasty = motion.y; - edit->last_state = motion.state; - } - break; - case GDK_ENTER_NOTIFY: -#if 0 - edit->pointer_in = TRUE; -#endif - if (edit_display) { - if (edit->default_cursor_shown){ - gdk_window_set_cursor (canvas->window, text_view->i_cursor); - edit->default_cursor_shown = FALSE; - } - } - break; - case GDK_LEAVE_NOTIFY: -#if 0 - text_view->pointer_in = FALSE; -#endif - if (edit_display) { - if (! edit->default_cursor_shown){ - gdk_window_set_cursor (canvas->window, NULL); - edit->default_cursor_shown = TRUE; - } - } - break; - default: - break; - } - - unbuild_current_cell (&cell); - if (return_val) - return return_val; -#if 0 - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS(parent_class)->event (item, event); -#endif - else - return 0; - -#if 0 - switch (event->type){ - case GDK_BUTTON_PRESS: - /* - * Adjust for the border we use - */ - event->button.x++; - - printf ("Button pressed at %g %g\n", event->button.x, event->button.y); - if (text_view->edit){ - printf ("FIXME: Should handle click here\n"); - } else - e_table_item_enter_edit (text_view->cell_view.e_table_item_view, view_col, row); - break; - - case GDK_KEY_PRESS: - if (event->key.keyval == GDK_Escape){ - ect_cancel_edit (text_view); - return TRUE; - } - - if (!text_view->edit){ - e_table_item_enter_edit (text_view->cell_view.e_table_item_view, view_col, row); - ect_edit_select_all (text_view); - } - - gtk_widget_event (GTK_WIDGET (text_view->edit->entry), event); - ect_queue_redraw (text_view, view_col, row); - break; -#endif -} - -/* - * ECell::height method - */ -static int -ect_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - EFont *font; - ECellText *ect = E_CELL_TEXT(ecell_view->ecell); - - font = text_view->font; - if (ect->filter) { - gchar *string; - gint value; - - string = (*ect->filter)(e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - value = e_font_height (font) * number_of_lines(string) + TEXT_PAD; - - g_free(string); - - return value; - } else { - gchar * string; - gint value; - - string = e_table_model_value_at (ecell_view->e_table_model, model_col, row); - - value = e_font_height (font) * number_of_lines (string) + TEXT_PAD; - - return value; - } -} - -/* - * ECellView::enter_edit method - */ -static void * -ect_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - CellEdit *edit; - ECellText *ect = E_CELL_TEXT(ecell_view->ecell); - - edit = g_new (CellEdit, 1); - text_view->edit = edit; - - build_current_cell (CURRENT_CELL(edit), text_view, model_col, view_col, row); - - edit->xofs_edit = 0.0; - edit->yofs_edit = 0.0; - - edit->selection_start = 0; - edit->selection_end = 0; - edit->select_by_word = FALSE; - - edit->timeout_id = g_timeout_add (10, _blink_scroll_timeout, text_view); - edit->timer = g_timer_new (); - g_timer_elapsed (edit->timer, &(edit->scroll_start)); - g_timer_start (edit->timer); - - edit->lastx = 0; - edit->lasty = 0; - edit->last_state = 0; - - edit->scroll_start = 0; - edit->show_cursor = TRUE; - edit->button_down = FALSE; - - edit->tep = NULL; - - edit->has_selection = FALSE; - - edit->invisible = NULL; - edit->primary_selection = NULL; - edit->primary_length = 0; - edit->clipboard_selection = NULL; - edit->clipboard_length = 0; - - edit->pointer_in = FALSE; - edit->default_cursor_shown = TRUE; - - if (ect->filter) { - edit->old_text = (*ect->filter)(e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - } else { - edit->old_text = g_strdup (e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - } - edit->cell.text = g_strdup (edit->old_text); - -#if 0 - if (edit->pointer_in){ - if (edit->default_cursor_shown){ - gdk_window_set_cursor (GTK_WIDGET(item->canvas)->window, text_view->i_cursor); - edit->default_cursor_shown = FALSE; - } - } -#endif - - ect_queue_redraw (text_view, view_col, row); - - return NULL; -} - -/* - * ECellView::leave_edit method - */ -static void -ect_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context) -{ - ECellTextView *text_view = (ECellTextView *) ecell_view; - CellEdit *edit = text_view->edit; - - if (edit){ - ect_accept_edits (text_view); - ect_stop_editing (text_view); - /* FIXME: edit is freed in ect_stop_editing() so I've - commented this out - Damon. */ - /*unbuild_current_cell (CURRENT_CELL(edit));*/ - } else { - /* - * We did invoke this leave edit internally - */ - } -} - -static void -ect_print (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width, double height) -{ - GnomeFont *font = gnome_font_new ("Helvetica", 12); - char *string; - ECellText *ect = E_CELL_TEXT(ecell_view->ecell); - if (ect->filter) { - string = (*ect->filter)(e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - } else { - string = e_table_model_value_at (ecell_view->e_table_model, model_col, row); - } - gnome_print_gsave(context); - if (gnome_print_moveto(context, 2, 2) == -1) - /* FIXME */; - if (gnome_print_lineto(context, width - 2, 2) == -1) - /* FIXME */; - if (gnome_print_lineto(context, width - 2, height - 2) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 2, height - 2) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 2, 2) == -1) - /* FIXME */; - if (gnome_print_clip(context) == -1) - /* FIXME */; - gnome_print_moveto(context, 2, (height - gnome_font_get_ascender(font) + gnome_font_get_descender(font)) / 2); - gnome_print_setfont(context, font); - gnome_print_show(context, string); - gnome_print_grestore(context); - if (ect->filter) { - g_free(string); - } -} - -static gdouble -ect_print_height (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width) -{ - return 16; -} - -/* - * GtkObject::destroy method - */ -static void -ect_destroy (GtkObject *object) -{ - ECellText *ect = E_CELL_TEXT (object); - - g_free (ect->font_name); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} -/* Set_arg handler for the text item */ -static void -ect_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ECellText *text; - - text = E_CELL_TEXT (object); - - switch (arg_id) { - case ARG_STRIKEOUT_COLUMN: - text->strikeout_column = GTK_VALUE_INT (*arg); - break; - - case ARG_BOLD_COLUMN: - text->bold_column = GTK_VALUE_INT (*arg); - break; - - case ARG_COLOR_COLUMN: - text->color_column = GTK_VALUE_INT (*arg); - break; - - case ARG_TEXT_FILTER: - text->filter = GTK_VALUE_POINTER (*arg); - break; - default: - return; - } -} - -/* Get_arg handler for the text item */ -static void -ect_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ECellText *text; - - text = E_CELL_TEXT (object); - - switch (arg_id) { - case ARG_STRIKEOUT_COLUMN: - GTK_VALUE_INT (*arg) = text->strikeout_column; - break; - - case ARG_BOLD_COLUMN: - GTK_VALUE_INT (*arg) = text->bold_column; - break; - - case ARG_COLOR_COLUMN: - GTK_VALUE_INT (*arg) = text->color_column; - break; - - case ARG_TEXT_FILTER: - GTK_VALUE_POINTER (*arg) = text->filter; - break; - - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -e_cell_text_class_init (GtkObjectClass *object_class) -{ - ECellClass *ecc = (ECellClass *) object_class; - - object_class->destroy = ect_destroy; - - ecc->new_view = ect_new_view; - ecc->kill_view = ect_kill_view; - ecc->realize = ect_realize; - ecc->unrealize = ect_unrealize; - ecc->draw = ect_draw; - ecc->event = ect_event; - ecc->height = ect_height; - ecc->enter_edit = ect_enter_edit; - ecc->leave_edit = ect_leave_edit; - ecc->print = ect_print; - ecc->print_height = ect_print_height; - - object_class->get_arg = ect_get_arg; - object_class->set_arg = ect_set_arg; - - parent_class = gtk_type_class (PARENT_TYPE); - - gtk_object_add_arg_type ("ECellText::strikeout_column", - GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_STRIKEOUT_COLUMN); - gtk_object_add_arg_type ("ECellText::bold_column", - GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_BOLD_COLUMN); - gtk_object_add_arg_type ("ECellText::color_column", - GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_COLOR_COLUMN); - gtk_object_add_arg_type ("ECellText::text_filter", - GTK_TYPE_POINTER, GTK_ARG_READWRITE, ARG_TEXT_FILTER); - - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); -} - -static void -e_cell_text_init (ECellText *ect) -{ - ect->strikeout_column = -1; - ect->bold_column = -1; - ect->color_column = -1; -} - -E_MAKE_TYPE(e_cell_text, "ECellText", ECellText, e_cell_text_class_init, e_cell_text_init, PARENT_TYPE); - -ECell * -e_cell_text_new (ETableModel *etm, const char *fontname, GtkJustification justify) -{ - ECellText *ect = gtk_type_new (e_cell_text_get_type ()); - - ect->ellipsis = NULL; - ect->use_ellipsis = TRUE; - - ect->font_name = g_strdup (fontname); - ect->justify = justify; - - return (ECell *) ect; -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static int -get_line_xpos (CurrentCell *cell, struct line *line) -{ - int x; - - ECellTextView *text_view = cell->text_view; - ECellText *ect = E_CELL_TEXT (((ECellView *)cell->text_view)->ecell); - - x = text_view->xofs + ect->x; - - switch (ect->justify) { - case GTK_JUSTIFY_RIGHT: - x += cell->width - line->width; - break; - - case GTK_JUSTIFY_CENTER: - x += (cell->width - line->width) / 2; - break; - - default: - /* For GTK_JUSTIFY_LEFT, we don't have to do anything. We do not support - * GTK_JUSTIFY_FILL, yet. - */ - break; - } - - return x; -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static int -get_line_ypos (CurrentCell *cell, struct line *line) -{ - int y; - - ECellTextView *text_view = cell->text_view; - ECellText *ect = E_CELL_TEXT (((ECellView *)cell->text_view)->ecell); - ECellTextLineBreaks *linebreaks = cell->breaks; - - struct line *lines = linebreaks->lines; - - EFont *font; - - font = text_view->font; - - y = text_view->yofs + ect->y; - y += (line - lines) * e_font_height (font); - - return y; -} - -/* fixme: Handle Font attributes */ -/* position is in BYTES */ - -static void -_get_xy_from_position (CurrentCell *cell, gint position, gint *xp, gint *yp) -{ - if (xp || yp) { - struct line *lines; - int x, y; - int j; - ECellTextView *text_view = cell->text_view; - ECellTextLineBreaks *linebreaks; - EFont *font; - - font = text_view->font; - - split_into_lines (cell); - - linebreaks = cell->breaks; - lines = linebreaks->lines; - - x = get_line_xpos (cell, lines); - y = get_line_ypos (cell, lines); - for (j = 0, lines = linebreaks->lines; j < linebreaks->num_lines; lines++, j++) { - if (lines->text > cell->text + position) - break; - y += e_font_height (font); - } - lines --; - y -= e_font_descent (font); - - x += e_font_utf8_text_width (font, E_FONT_PLAIN, - lines->text, - position - (lines->text - cell->text)); - if ((CellEdit *) cell == cell->text_view->edit){ - x -= ((CellEdit *)cell)->xofs_edit; - y -= ((CellEdit *)cell)->yofs_edit; - } - if (xp) - *xp = x; - if (yp) - *yp = y; - unref_lines (cell); - } -} - -static gint -_get_position_from_xy (CurrentCell *cell, gint x, gint y) -{ - int i, j; - int xpos, ypos; - struct line *lines; - int return_val; - gchar *p; - - ECellTextView *text_view = cell->text_view; - ECellTextLineBreaks *linebreaks; - EFont *font; - - font = text_view->font; - - split_into_lines (cell); - - linebreaks = cell->breaks; - - lines = linebreaks->lines; - - if ((CellEdit *) cell == cell->text_view->edit){ - x += ((CellEdit *)cell)->xofs_edit; - y += ((CellEdit *)cell)->yofs_edit; - } - - ypos = get_line_ypos (cell, linebreaks->lines); - j = 0; - while (y > ypos) { - ypos += e_font_height (font); - j ++; - } - j--; - if (j >= linebreaks->num_lines) - j = linebreaks->num_lines - 1; - if (j < 0) - j = 0; - i = 0; - - lines += j; - xpos = get_line_xpos (cell, lines); - - for (p = lines->text; p < lines->text + lines->length; p = unicode_next_utf8 (p)) { - gint charwidth; - - charwidth = e_font_utf8_char_width (font, E_FONT_PLAIN, p); - - xpos += charwidth / 2; - if (xpos > x) { - break; - } - xpos += (charwidth + 1) / 2; - } - - return_val = p - cell->text; - - unref_lines (cell); - - return return_val; -} - -#define SCROLL_WAIT_TIME 30000 - -static gboolean -_blink_scroll_timeout (gpointer data) -{ - CurrentCell *cell = CURRENT_CELL(data); - ECellTextView *text_view = (ECellTextView *) data; - ECellText *ect = E_CELL_TEXT (((ECellView *)text_view)->ecell); - CellEdit *edit = text_view->edit; - ECellTextLineBreaks *linebreaks = cell->breaks; - - gulong current_time; - gboolean scroll = FALSE; - gboolean redraw = FALSE; - - g_timer_elapsed (edit->timer, ¤t_time); - - if (edit->scroll_start + SCROLL_WAIT_TIME > 1000000) { - if (current_time > edit->scroll_start - (1000000 - SCROLL_WAIT_TIME) && - current_time < edit->scroll_start) - scroll = TRUE; - } else { - if (current_time > edit->scroll_start + SCROLL_WAIT_TIME || - current_time < edit->scroll_start) - scroll = TRUE; - } - if (scroll && edit->button_down) { - /* FIXME: Copy this for y. */ - if (edit->lastx - ect->x > cell->width && - edit->xofs_edit < linebreaks->max_width - cell->width) { - edit->xofs_edit += 4; - if (edit->xofs_edit > linebreaks->max_width - cell->width + 1) - edit->xofs_edit = linebreaks->max_width - cell->width + 1; - redraw = TRUE; - } - if (edit->lastx - ect->x < 0 && - edit->xofs_edit > 0) { - edit->xofs_edit -= 4; - if (edit->xofs_edit < 0) - edit->xofs_edit = 0; - redraw = TRUE; - } - if (redraw) { - ETextEventProcessorEvent e_tep_event; - e_tep_event.type = GDK_MOTION_NOTIFY; - e_tep_event.motion.state = edit->last_state; - e_tep_event.motion.time = 0; - e_tep_event.motion.position = _get_position_from_xy (cell, edit->lastx, edit->lasty); - _get_tep (edit); - e_text_event_processor_handle_event (edit->tep, - &e_tep_event); - edit->scroll_start = current_time; - } - } - - if (!((current_time / 500000) % 2)) { - if (!edit->show_cursor) - redraw = TRUE; - edit->show_cursor = TRUE; - } else { - if (edit->show_cursor) - redraw = TRUE; - edit->show_cursor = FALSE; - } - if (redraw){ - ect_queue_redraw (text_view, edit->cell.view_col, edit->cell.row); - } - return TRUE; -} - -static int -_get_position (ECellTextView *text_view, ETextEventProcessorCommand *command) -{ - int length; - int x, y; - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - EFont *font; - gchar *p; - int unival; - - font = text_view->font; - - switch (command->position) { - - case E_TEP_VALUE: - return command->value; - - case E_TEP_SELECTION: - return edit->selection_end; - - case E_TEP_START_OF_BUFFER: - return 0; - - /* fixme: this probably confuses TEP */ - - case E_TEP_END_OF_BUFFER: - return strlen (cell->text); - - case E_TEP_START_OF_LINE: - - if (edit->selection_end < 1) return 0; - - p = unicode_previous_utf8 (cell->text, cell->text + edit->selection_end); - - if (p == cell->text) return 0; - - p = unicode_previous_utf8 (cell->text, p); - - while (p && p > cell->text) { - if (*p == '\n') return p - cell->text + 1; - p = unicode_previous_utf8 (cell->text, p); - } - - return 0; - - case E_TEP_END_OF_LINE: - - length = strlen (cell->text); - if (edit->selection_end >= length) return length; - - p = unicode_next_utf8 (cell->text + edit->selection_end); - - while (*p) { - if (*p == '\n') return p - cell->text; - p = unicode_next_utf8 (p); - } - - return p - cell->text; - - case E_TEP_FORWARD_CHARACTER: - - length = strlen (cell->text); - if (edit->selection_end >= length) return length; - - p = unicode_next_utf8 (cell->text + edit->selection_end); - - return p - cell->text; - - case E_TEP_BACKWARD_CHARACTER: - - if (edit->selection_end < 1) return 0; - - p = unicode_previous_utf8 (cell->text, cell->text + edit->selection_end); - - if (p == NULL) return 0; - - return p - cell->text; - - case E_TEP_FORWARD_WORD: - - length = strlen (cell->text); - if (edit->selection_end >= length) return length; - - p = unicode_next_utf8 (cell->text + edit->selection_end); - - while (*p) { - unicode_get_utf8 (p, &unival); - if (unicode_isspace (unival)) return p - cell->text; - p = unicode_next_utf8 (p); - } - - return p - cell->text; - - case E_TEP_BACKWARD_WORD: - - if (edit->selection_end < 1) return 0; - - p = unicode_previous_utf8 (cell->text, cell->text + edit->selection_end); - - if (p == cell->text) return 0; - - p = unicode_previous_utf8 (cell->text, p); - - while (p && p > cell->text) { - unicode_get_utf8 (p, &unival); - if (unicode_isspace (unival)) { - return (unicode_next_utf8 (p) - cell->text); - } - p = unicode_previous_utf8 (cell->text, p); - } - - return 0; - - case E_TEP_FORWARD_LINE: - _get_xy_from_position (cell, edit->selection_end, &x, &y); - y += e_font_height (font); - return _get_position_from_xy (cell, x, y); - case E_TEP_BACKWARD_LINE: - _get_xy_from_position (cell, edit->selection_end, &x, &y); - y -= e_font_height (font); - return _get_position_from_xy (cell, x, y); - - case E_TEP_FORWARD_PARAGRAPH: - case E_TEP_BACKWARD_PARAGRAPH: - - case E_TEP_FORWARD_PAGE: - case E_TEP_BACKWARD_PAGE: - return edit->selection_end; - default: - return edit->selection_end; - } - g_assert_not_reached (); - return 0; /* Kill warning */ -} - -static void -_delete_selection (ECellTextView *text_view) -{ - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - gint length; - gchar *sp, *ep; - - if (edit->selection_end == edit->selection_start) return; - - if (edit->selection_end < edit->selection_start) { - edit->selection_end ^= edit->selection_start; - edit->selection_start ^= edit->selection_end; - edit->selection_end ^= edit->selection_start; - } - - sp = cell->text + edit->selection_start; - ep = cell->text + edit->selection_end; - length = strlen (ep) + 1; - - memmove (sp, ep, length); - - edit->selection_end = edit->selection_start; -} - -/* fixme: */ -/* NB! We expect value to be length IN BYTES */ - -static void -_insert (ECellTextView *text_view, char *string, int value) -{ - CellEdit *edit = text_view->edit; - CurrentCell *cell = CURRENT_CELL(edit); - char *temp; - - if (value <= 0) return; - - temp = g_new (gchar, strlen (cell->text) + value + 1); - - strncpy (temp, cell->text, edit->selection_start); - strncpy (temp + edit->selection_start, string, value); - strcpy (temp + edit->selection_start + value, cell->text + edit->selection_end); - - g_free (cell->text); - - cell->text = temp; - - edit->selection_start += value; - edit->selection_end = edit->selection_start; -} - -static void -e_cell_text_view_command (ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data) -{ - CellEdit *edit = (CellEdit *) data; - CurrentCell *cell = CURRENT_CELL(edit); - ECellTextView *text_view = cell->text_view; - - gboolean change = FALSE; - gboolean redraw = FALSE; - - int sel_start, sel_end; - EFont *font; - - font = text_view->font; - - switch (command->action) { - case E_TEP_MOVE: - edit->selection_start = _get_position (text_view, command); - edit->selection_end = edit->selection_start; - if (edit->timer) { - g_timer_reset (edit->timer); - } - redraw = TRUE; - break; - case E_TEP_SELECT: - edit->selection_end = _get_position (text_view, command); - sel_start = MIN(edit->selection_start, edit->selection_end); - sel_end = MAX(edit->selection_start, edit->selection_end); - if (sel_start != sel_end) { - e_cell_text_view_supply_selection (edit, command->time, GDK_SELECTION_PRIMARY, - cell->text + sel_start, - sel_end - sel_start); - } else if (edit->timer) { - g_timer_reset (edit->timer); - } - redraw = TRUE; - break; - case E_TEP_DELETE: - if (edit->selection_end == edit->selection_start) { - edit->selection_end = _get_position (text_view, command); - } - _delete_selection (text_view); - if (edit->timer) { - g_timer_reset (edit->timer); - } - redraw = TRUE; - change = TRUE; - break; - - case E_TEP_INSERT: - if (edit->selection_end != edit->selection_start) { - _delete_selection (text_view); - } - _insert (text_view, command->string, command->value); - if (edit->timer) { - g_timer_reset (edit->timer); - } - redraw = TRUE; - change = TRUE; - break; - case E_TEP_COPY: - sel_start = MIN(edit->selection_start, edit->selection_end); - sel_end = MAX(edit->selection_start, edit->selection_end); - if (sel_start != sel_end) { - e_cell_text_view_supply_selection (edit, command->time, clipboard_atom, - cell->text + sel_start, - sel_end - sel_start); - } - if (edit->timer) { - g_timer_reset (edit->timer); - } - break; - case E_TEP_PASTE: - e_cell_text_view_get_selection (edit, clipboard_atom, command->time); - if (edit->timer) { - g_timer_reset (edit->timer); - } - redraw = TRUE; - change = TRUE; - break; - case E_TEP_GET_SELECTION: - e_cell_text_view_get_selection (edit, GDK_SELECTION_PRIMARY, command->time); - break; - case E_TEP_ACTIVATE: - e_table_item_leave_edit (text_view->cell_view.e_table_item_view); - break; - case E_TEP_SET_SELECT_BY_WORD: - edit->select_by_word = command->value; - break; - case E_TEP_GRAB: - case E_TEP_UNGRAB: -#if 0 - case E_TEP_GRAB: - gnome_canvas_item_grab (GNOME_CANVAS_ITEM(text), - GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, - text_view->i_cursor, - command->time); - break; - gnome_canvas_item_ungrab (GNOME_CANVAS_ITEM(text), command->time); - break; -#endif - case E_TEP_NOP: - break; - } - - if (!edit->button_down) { - int x; - int i; - struct line *lines; - ECellTextLineBreaks *linebreaks; - - split_into_lines (cell); - - linebreaks = cell->breaks; - - for (lines = linebreaks->lines, i = 0; i < linebreaks->num_lines ; i++, lines ++) { - if ((lines->text - cell->text) > edit->selection_end) { - break; - } - } - lines --; - x = e_font_utf8_text_width (font, E_FONT_PLAIN, - lines->text, - edit->selection_end - (lines->text - cell->text)); - - - if (x < edit->xofs_edit) { - edit->xofs_edit = x; - redraw = TRUE; - } - - if (2 + x - cell->width > edit->xofs_edit) { - edit->xofs_edit = 2 + x - cell->width; - redraw = TRUE; - } - unref_lines (cell); - } - - if (redraw){ - ect_queue_redraw (text_view, edit->cell.view_col, edit->cell.row); - } -#if 0 - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); -#endif -} - -static void _invisible_destroy (GtkInvisible *invisible, - CellEdit *edit) -{ - edit->invisible = NULL; -} - -static GtkWidget *e_cell_text_view_get_invisible (CellEdit *edit) -{ - GtkWidget *invisible; - if (edit->invisible) { - invisible = edit->invisible; - } else { - invisible = gtk_invisible_new (); - edit->invisible = invisible; - - gtk_selection_add_target (invisible, - GDK_SELECTION_PRIMARY, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_PRIMARY); - gtk_selection_add_target (invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_CLIPBOARD); - - gtk_signal_connect (GTK_OBJECT(invisible), "selection_get", - GTK_SIGNAL_FUNC (_selection_get), - edit); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_clear_event", - GTK_SIGNAL_FUNC (_selection_clear_event), - edit); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_received", - GTK_SIGNAL_FUNC (_selection_received), - edit); - - gtk_signal_connect (GTK_OBJECT(invisible), "destroy", - GTK_SIGNAL_FUNC (_invisible_destroy), - edit); - } - return invisible; -} - -static void -_selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - CellEdit *edit) -{ - if (event->selection == GDK_SELECTION_PRIMARY) { - g_free (edit->primary_selection); - edit->primary_selection = NULL; - edit->primary_length = 0; - - edit->has_selection = FALSE; -#if 0 - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); -#endif - - } else if (event->selection == clipboard_atom) { - g_free (edit->clipboard_selection); - edit->clipboard_selection = NULL; - edit->clipboard_length = 0; - } -} - -static void -_selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - CellEdit *edit) -{ - switch (info) { - case E_SELECTION_PRIMARY: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, edit->primary_selection, edit->primary_length); - break; - case E_SELECTION_CLIPBOARD: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, edit->clipboard_selection, edit->clipboard_length); - break; - } -} - -/* fixme: What happens, if delivered string is not UTF-8? */ - -static void -_selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - CellEdit *edit) -{ - if (selection_data->length < 0 || selection_data->type != GDK_SELECTION_TYPE_STRING) { - return; - } else { - ETextEventProcessorCommand command; - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.string = selection_data->data; - command.value = selection_data->length; - command.time = time; - e_cell_text_view_command (edit->tep, &command, edit); - } -} - -static void e_cell_text_view_supply_selection (CellEdit *edit, guint time, GdkAtom selection, char *data, gint length) -{ - gboolean successful; - GtkWidget *invisible; - - invisible = e_cell_text_view_get_invisible (edit); - - if (selection == GDK_SELECTION_PRIMARY){ - if (edit->primary_selection) { - g_free (edit->primary_selection); - } - edit->primary_selection = g_strndup (data, length); - edit->primary_length = length; - } else if (selection == clipboard_atom) { - if (edit->clipboard_selection) { - g_free (edit->clipboard_selection); - } - edit->clipboard_selection = g_strndup (data, length); - edit->clipboard_length = length; - } - - successful = gtk_selection_owner_set (invisible, - selection, - time); - - if (selection == GDK_SELECTION_PRIMARY) - edit->has_selection = successful; -} - -static void -e_cell_text_view_get_selection (CellEdit *edit, GdkAtom selection, guint32 time) -{ - GtkWidget *invisible; - invisible = e_cell_text_view_get_invisible (edit); - gtk_selection_convert (invisible, - selection, - GDK_SELECTION_TYPE_STRING, - time); -} - -static void -_get_tep (CellEdit *edit) -{ - if (!edit->tep) { - edit->tep = e_text_event_processor_emacs_like_new (); - gtk_object_ref (GTK_OBJECT (edit->tep)); - gtk_object_sink (GTK_OBJECT (edit->tep)); - gtk_signal_connect (GTK_OBJECT(edit->tep), - "command", - GTK_SIGNAL_FUNC(e_cell_text_view_command), - (gpointer) edit); - } -} - -static int -number_of_lines (char *text) -{ - int num_lines = 0; - gchar *p; - - if (!text) return 0; - - for (p = text; *p; p = unicode_next_utf8 (p)) { - if (*p == '\n') num_lines++; - } - - num_lines++; - return num_lines; -} - -/* Splits the text of the text item into lines */ -static void -split_into_lines (CurrentCell *cell) -{ - char *p; - struct line *lines; - gint len; - - char *text = cell->text; - ECellTextLineBreaks *linebreaks = cell->breaks; - - if (! cell->breaks) { - cell->breaks = g_new (ECellTextLineBreaks, 1); - cell->breaks->ref_count = 1; - } else { - cell->breaks->ref_count ++; - return; - } - linebreaks = cell->breaks; - - /* Check if already split. */ - - linebreaks->lines = NULL; - linebreaks->num_lines = 0; - - if (!text) - return; - - /* First, count the number of lines */ - - linebreaks->num_lines = number_of_lines(cell->text); - - /* Allocate array of lines and calculate split positions */ - - linebreaks->lines = lines = g_new0 (struct line, linebreaks->num_lines); - - len = 0; - for (p = text; *p; p = unicode_next_utf8 (p)) { - if (len == 0) lines->text = p; - if (*p == '\n') { - lines->length = p - lines->text; - lines++; - len = 0; - } else - len++; - } - - if (len == 0) - lines->text = p; - lines->length = p - lines->text; - - calc_line_widths (cell); -} - -/* Free lines structure. */ -static void -unref_lines (CurrentCell *cell) -{ - if (cell->breaks){ - cell->breaks->ref_count --; - if (cell->breaks->ref_count <= 0){ - g_free (cell->breaks->lines); - g_free (cell->breaks); - cell->breaks = NULL; - } - } -} - -static void -calc_ellipsis (ECellTextView *text_view) -{ - ECellText *ect = E_CELL_TEXT (((ECellView *)text_view)->ecell); - EFont *font; - - font = text_view->font; - if (font) - text_view->ellipsis_width = - e_font_utf8_text_width (font, E_FONT_PLAIN, - ect->ellipsis ? ect->ellipsis : "...", - ect->ellipsis ? strlen (ect->ellipsis) : 3); -} - -/* Calculates the line widths (in pixels) of the text's splitted lines */ -static void -calc_line_widths (CurrentCell *cell) -{ - ECellTextView *text_view = cell->text_view; - ECellText *ect = E_CELL_TEXT (((ECellView *)text_view)->ecell); - ECellTextLineBreaks *linebreaks = cell->breaks; - struct line *lines; - int i; - int j; - EFont *font; - - font = text_view->font; - - lines = linebreaks->lines; - linebreaks->max_width = 0; - - if (!lines) return; - - for (i = 0; i < linebreaks->num_lines; i++) { - if (lines->length != 0) { - if (font) { - lines->width = e_font_utf8_text_width (font, E_FONT_PLAIN, - lines->text, lines->length); - lines->ellipsis_length = 0; - } else { - lines->width = 0; - } - - if (ect->use_ellipsis && - (!(text_view->edit && - cell->row == text_view->edit->cell.row && - cell->view_col == text_view->edit->cell.view_col)) && - lines->width > cell->width) { - if (font) { - lines->ellipsis_length = 0; - for (j = 0; j < lines->length; j++){ - if (e_font_utf8_text_width (font, E_FONT_PLAIN, lines->text, j) + - text_view->ellipsis_width <= cell->width) - lines->ellipsis_length = j; - else - break; - } - } - else - lines->ellipsis_length = 0; - lines->width = e_font_utf8_text_width (font, E_FONT_PLAIN, lines->text, lines->ellipsis_length) + - text_view->ellipsis_width; - } - else - lines->ellipsis_length = lines->length; - - if (lines->width > linebreaks->max_width) - linebreaks->max_width = lines->width; - } else { - lines->width = 0; - lines->ellipsis_length = 0; - } - - lines++; - } -} - -static void -build_current_cell (CurrentCell *cell, ECellTextView *text_view, int model_col, int view_col, int row) -{ - ECellView *ecell_view = (ECellView *) text_view; - ECellText *ect = E_CELL_TEXT (ecell_view->ecell); - - cell->text_view = text_view; - cell->model_col = model_col; - cell->view_col = view_col; - cell->row = row; - cell->breaks = NULL; - - if (ect->filter) { - cell->text = (*ect->filter)(e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - } else { - cell->text = g_strdup (e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - } - cell->width = e_table_header_get_column ( - ((ETableItem *)ecell_view->e_table_item_view)->header, - view_col)->width - 8; -} - -static void -unbuild_current_cell (CurrentCell *cell) -{ - g_free(cell->text); - cell->text = NULL; -} - - -static GdkColor* -e_cell_text_get_color (ECellTextView *cell_view, gchar *color_spec) -{ - ECellText *ect = E_CELL_TEXT (((ECellView*) cell_view)->ecell); - GdkColormap *colormap; - GdkColor *color, tmp_color; - - /* If the color spec is NULL we use the default color. */ - if (color_spec == NULL) - return NULL; - - /* Create the hash table if we haven't already. */ - if (!ect->colors) - ect->colors = g_hash_table_new (g_str_hash, g_str_equal); - - /* See if we've already allocated the color. Note that we use a - special value of (GdkColor*) 1 in the hash to indicate that we've - already tried and failed to allocate the color, so we don't keep - trying to allocate it. */ - color = g_hash_table_lookup (ect->colors, color_spec); - if (color == (GdkColor*) 1) - return NULL; - if (color) - return color; - - /* Try to parse the color. */ - if (gdk_color_parse (color_spec, &tmp_color)) { - colormap = gtk_widget_get_colormap (GTK_WIDGET (cell_view->canvas)); - - /* Try to allocate the color. */ - if (gdk_color_alloc (colormap, &tmp_color)) - color = gdk_color_copy (&tmp_color); - } - - g_hash_table_insert (ect->colors, g_strdup (color_spec), - color ? color : (GdkColor*) 1); - return color; -} - diff --git a/widgets/table/e-cell-text.h b/widgets/table/e-cell-text.h deleted file mode 100644 index e0296998b3..0000000000 --- a/widgets/table/e-cell-text.h +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ECellText - Text item for e-table. - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * Drawing and event handling from: - * - * EText - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey <clahey@helixcode.com> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> */ -#ifndef _E_CELL_TEXT_H_ -#define _E_CELL_TEXT_H_ - -#include <libgnomeui/gnome-canvas.h> -#include "e-cell.h" - -/* Should return a malloced object. */ -typedef char *(*ECellTextFilter) (const void *); - -#define E_CELL_TEXT_TYPE (e_cell_text_get_type ()) -#define E_CELL_TEXT(o) (GTK_CHECK_CAST ((o), E_CELL_TEXT_TYPE, ECellText)) -#define E_CELL_TEXT_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_TEXT_TYPE, ECellTextClass)) -#define E_IS_CELL_TEXT(o) (GTK_CHECK_TYPE ((o), E_CELL_TEXT_TYPE)) -#define E_IS_CELL_TEXT_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_TEXT_TYPE)) - -typedef struct { - ECell parent; - - GtkJustification justify; - char *font_name; - - double x, y; /* Position at anchor */ - - gulong pixel; /* Fill color */ - - /* Clip handling */ - char *ellipsis; /* The ellipsis characters. NULL = "...". */ - - guint use_ellipsis : 1; /* Whether to use the ellipsis. */ - - int strikeout_column; - int bold_column; - - /* This column in the ETable should return a string specifying a color, - either a color name like "red" or a color spec like "rgb:F/0/0". - See the XParseColor man page for the formats available. */ - int color_column; - - ECellTextFilter filter; - - /* This stores the colors we have allocated. */ - GHashTable *colors; -} ECellText; - -typedef struct { - ECellClass parent_class; -} ECellTextClass; - -GtkType e_cell_text_get_type (void); -ECell *e_cell_text_new (ETableModel *model, const char *fontname, GtkJustification justify); - -#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 1be01348db..0000000000 --- a/widgets/table/e-cell-toggle.c +++ /dev/null @@ -1,289 +0,0 @@ -/* - * e-cell-toggle.c: Multi-state image toggle cell object. - * - * Author: - * Miguel de Icaza (miguel@kernel.org) - * - * (C) 1999, 2000 Helix Code, Inc - */ -#include <config.h> -#include <gtk/gtkenums.h> -#include <gtk/gtkentry.h> -#include <gtk/gtkwindow.h> -#include <gtk/gtksignal.h> -#include <gdk/gdkkeysyms.h> -#include <libgnomeui/gnome-canvas.h> -#include "e-cell-toggle.h" -#include "e-util/e-util.h" -#include "e-table-item.h" - -#define PARENT_TYPE e_cell_get_type () - -typedef struct { - ECellView cell_view; - GdkGC *gc; - GnomeCanvas *canvas; -} ECellToggleView; - -static ECellClass *parent_class; - -static void -etog_queue_redraw (ECellToggleView *text_view, int view_col, int view_row) -{ - e_table_item_redraw_range ( - text_view->cell_view.e_table_item_view, - view_col, view_row, view_col, view_row); -} - -/* - * ECell::realize method - */ -static ECellView * -etog_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - ECellToggleView *toggle_view = g_new0 (ECellToggleView, 1); - ETableItem *eti = E_TABLE_ITEM (e_table_item_view); - GnomeCanvas *canvas = GNOME_CANVAS_ITEM (eti)->canvas; - - toggle_view->cell_view.ecell = ecell; - toggle_view->cell_view.e_table_model = table_model; - toggle_view->cell_view.e_table_item_view = e_table_item_view; - toggle_view->canvas = canvas; - - return (ECellView *) toggle_view; -} - -static void -etog_kill_view (ECellView *ecell_view) -{ - g_free (ecell_view); -} - -static void -etog_realize (ECellView *ecell_view) -{ - ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; - - toggle_view->gc = gdk_gc_new (GTK_WIDGET (toggle_view->canvas)->window); -} - -/* - * ECell::unrealize method - */ -static void -etog_unrealize (ECellView *ecv) -{ - ECellToggleView *toggle_view = (ECellToggleView *) ecv; - - gdk_gc_unref (toggle_view->gc); - toggle_view->gc = NULL; -} - -/* - * ECell::draw method - */ -static void -etog_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, gboolean selected, - int x1, int y1, int x2, int y2) -{ - ECellToggle *toggle = E_CELL_TOGGLE (ecell_view->ecell); -#if 0 - ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; -#endif - GdkPixbuf *image; - int x, y, width, height; - - const int value = GPOINTER_TO_INT ( - e_table_model_value_at (ecell_view->e_table_model, model_col, row)); - - if (value >= toggle->n_states){ - g_warning ("Value from the table model is %d, the states we support are [0..%d)\n", - value, toggle->n_states); - return; - } - - image = toggle->images [value]; - - if ((x2 - x1) < gdk_pixbuf_get_width (image)){ - x = x1; - width = x2 - x1; - } else { - x = x1 + ((x2 - x1) - gdk_pixbuf_get_width (image)) / 2; - width = gdk_pixbuf_get_width (image); - } - - if ((y2 - y1) < gdk_pixbuf_get_height (image)){ - y = y1; - height = y2 - y1; - } else { - y = y1 + ((y2 - y1) - gdk_pixbuf_get_height (image)) / 2; - height = gdk_pixbuf_get_height (image); - } - -#if 0 /* do alpha */ - if (gdk_pixbuf_get_has_alpha (image)) { - flat = gdk_pixbuf_composite_color_simple ( - image, - gdk_pixbuf_get_width (image), - gdk_pixbuf_get_height (image), - GDK_INTERP_NEAREST, - 255, - 32, - 0xffffff, 0xffffff); - - gdk_pixbuf_render_to_drawable (flat, drawable, - toggle_view->gc, - 0, 0, - x, y, - width, height, - GDK_RGB_DITHER_NORMAL, - 0, 0); - gdk_pixbuf_unref (flat); - } else { - gdk_pixbuf_render_to_drawable (image, drawable, - toggle_view->gc, - 0, 0, - x, y, - width, height, - GDK_RGB_DITHER_NORMAL, - 0, 0); - } -#else - gdk_pixbuf_render_to_drawable_alpha (image, drawable, - 0, 0, - x, y, - width, height, - GDK_PIXBUF_ALPHA_BILEVEL, - 128, - GDK_RGB_DITHER_NORMAL, - x, y); -#endif -} - -static void -etog_set_value (ECellToggleView *toggle_view, int model_col, int view_col, int row, int value) -{ - ECell *ecell = toggle_view->cell_view.ecell; - ECellToggle *toggle = E_CELL_TOGGLE (ecell); - - if (value >= toggle->n_states) - value = 0; - - e_table_model_set_value_at (toggle_view->cell_view.e_table_model, - model_col, row, GINT_TO_POINTER (value)); - etog_queue_redraw (toggle_view, view_col, row); -} - -/* - * ECell::event method - */ -static gint -etog_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row) -{ - ECellToggleView *toggle_view = (ECellToggleView *) ecell_view; - void *_value = e_table_model_value_at (ecell_view->e_table_model, model_col, row); - const int value = GPOINTER_TO_INT (_value); - - switch (event->type){ - case GDK_BUTTON_RELEASE: - if (!e_table_model_is_cell_editable(ecell_view->e_table_model, model_col, row)) - return FALSE; - - etog_set_value (toggle_view, model_col, view_col, row, value + 1); - return TRUE; - - case GDK_KEY_PRESS: - if (!e_table_model_is_cell_editable(ecell_view->e_table_model, model_col, row)) - return FALSE; - - if (event->key.keyval == GDK_space){ - etog_set_value (toggle_view, model_col, view_col, row, value + 1); - return TRUE; - } - return FALSE; - - default: - return FALSE; - } - return TRUE; -} - -/* - * ECell::height method - */ -static int -etog_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - ECellToggle *toggle = E_CELL_TOGGLE (ecell_view->ecell); - - return toggle->height; -} - -static void -etog_destroy (GtkObject *object) -{ - ECellToggle *etog = E_CELL_TOGGLE (object); - int i; - - for (i = 0; i < etog->n_states; i++) - gdk_pixbuf_unref (etog->images [i]); - - g_free (etog->images); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -static void -e_cell_toggle_class_init (GtkObjectClass *object_class) -{ - ECellClass *ecc = (ECellClass *) object_class; - - object_class->destroy = etog_destroy; - - ecc->new_view = etog_new_view; - ecc->kill_view = etog_kill_view; - ecc->realize = etog_realize; - ecc->unrealize = etog_unrealize; - ecc->draw = etog_draw; - ecc->event = etog_event; - ecc->height = etog_height; - - parent_class = gtk_type_class (PARENT_TYPE); -} - -E_MAKE_TYPE(e_cell_toggle, "ECellToggle", ECellToggle, e_cell_toggle_class_init, NULL, PARENT_TYPE); - -void -e_cell_toggle_construct (ECellToggle *etog, int border, int n_states, GdkPixbuf **images) -{ - int max_height = 0; - int i; - - etog->border = border; - etog->n_states = n_states; - - etog->images = g_new (GdkPixbuf *, n_states); - - for (i = 0; i < n_states; i++){ - etog->images [i] = images [i]; - gdk_pixbuf_ref (images [i]); - - if (gdk_pixbuf_get_height (images [i]) > max_height) - max_height = gdk_pixbuf_get_height (images [i]); - } - - etog->height = max_height; -} - -ECell * -e_cell_toggle_new (int border, int n_states, GdkPixbuf **images) -{ - ECellToggle *etog = gtk_type_new (e_cell_toggle_get_type ()); - - e_cell_toggle_construct (etog, border, n_states, images); - - return (ECell *) etog; -} - - diff --git a/widgets/table/e-cell-toggle.h b/widgets/table/e-cell-toggle.h deleted file mode 100644 index d5773b454a..0000000000 --- a/widgets/table/e-cell-toggle.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _E_CELL_TOGGLE_H_ -#define _E_CELL_TOGGLE_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gdk-pixbuf/gdk-pixbuf.h> -#include "e-cell.h" - -#define E_CELL_TOGGLE_TYPE (e_cell_toggle_get_type ()) -#define E_CELL_TOGGLE(o) (GTK_CHECK_CAST ((o), E_CELL_TOGGLE_TYPE, ECellToggle)) -#define E_CELL_TOGGLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_TOGGLE_TYPE, ECellToggleClass)) -#define E_IS_CELL_TOGGLE(o) (GTK_CHECK_TYPE ((o), E_CELL_TOGGLE_TYPE)) -#define E_IS_CELL_TOGGLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_TOGGLE_TYPE)) - -typedef struct { - ECell parent; - - int border; - int n_states; - GdkPixbuf **images; - - int height; -} ECellToggle; - -typedef struct { - ECellClass parent_class; -} ECellToggleClass; - -GtkType e_cell_toggle_get_type (void); -ECell *e_cell_toggle_new (int border, int n_states, GdkPixbuf **images); -void e_cell_toggle_construct (ECellToggle *etog, int border, - int n_states, GdkPixbuf **images); - -#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 d4106271e6..0000000000 --- a/widgets/table/e-cell-tree.c +++ /dev/null @@ -1,542 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-cell-tree.c - Tree cell renderer - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Toshok <toshok@helixcode.com> - * - * A majority of code taken from: - * - * the ECellText renderer. - * - * Copyright (C) 1998 The Free Software Foundation - * - */ - -#include <config.h> -#include <gtk/gtkenums.h> -#include <gtk/gtkentry.h> -#include <gtk/gtkwindow.h> -#include <gtk/gtkinvisible.h> -#include <gtk/gtksignal.h> -#include <gdk/gdkkeysyms.h> -#include <libgnomeui/gnome-canvas.h> -#include <stdio.h> -#include "e-table-sorted-variable.h" -#include "e-tree-model.h" -#include "e-cell-tree.h" -#include "e-util/e-util.h" -#include "e-table-item.h" - -#include <gdk/gdkx.h> /* for BlackPixel */ -#include <ctype.h> -#include <math.h> - -#define PARENT_TYPE e_cell_get_type () - -typedef struct { - ECellView cell_view; - ECellView *subcell_view; - GdkGC *gc; - - GnomeCanvas *canvas; - -} ECellTreeView; - -static ECellClass *parent_class; - -#define INDENT_AMOUNT 16 - -static int -visible_depth_of_node (ETreeModel *tree_model, ETreePath *path) -{ - return (e_tree_model_node_depth (tree_model, path) - - (e_tree_model_root_node_is_visible (tree_model) ? 0 : 1)); -} - -static gint -offset_of_node (ETreeModel *tree_model, ETreePath *path) -{ - return (visible_depth_of_node(tree_model, path) + 1) * INDENT_AMOUNT; -} - -static ETreePath* -e_cell_tree_get_node (ETreeModel *tree_model, int row) -{ - return (ETreePath*)e_table_model_value_at (E_TABLE_MODEL(tree_model), -1, row); -} - -static ETreeModel* -e_cell_tree_get_tree_model (ETableModel *table_model, int row) -{ - return (ETreeModel*)e_table_model_value_at (table_model, -2, row); -} - -/* - * ECell::new_view method - */ -static ECellView * -ect_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - ECellTree *ect = E_CELL_TREE (ecell); - ECellTreeView *tree_view = g_new0 (ECellTreeView, 1); - GnomeCanvas *canvas = GNOME_CANVAS_ITEM (e_table_item_view)->canvas; - - tree_view->cell_view.ecell = ecell; - tree_view->cell_view.e_table_model = table_model; - tree_view->cell_view.e_table_item_view = e_table_item_view; - - /* create our subcell view */ - tree_view->subcell_view = e_cell_new_view (ect->subcell, table_model, e_table_item_view /* XXX */); - - tree_view->canvas = canvas; - - return (ECellView *)tree_view; -} - -/* - * ECell::kill_view method - */ -static void -ect_kill_view (ECellView *ecv) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecv; - - /* kill our subcell view */ - e_cell_kill_view (tree_view->subcell_view); - - g_free (tree_view); -} - -/* - * ECell::realize method - */ -static void -ect_realize (ECellView *ecell_view) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - - /* realize our subcell view */ - e_cell_realize (tree_view->subcell_view); - - tree_view->gc = gdk_gc_new (GTK_WIDGET (tree_view->canvas)->window); - - gdk_gc_set_line_attributes (tree_view->gc, 1, - GDK_LINE_ON_OFF_DASH, None, None); - gdk_gc_set_dashes (tree_view->gc, 0, "\1\1", 2); - - if (parent_class->realize) - (* parent_class->realize) (ecell_view); -} - -/* - * ECell::unrealize method - */ -static void -ect_unrealize (ECellView *ecv) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecv; - - /* unrealize our subcell view. */ - e_cell_unrealize (tree_view->subcell_view); - - gdk_gc_unref (tree_view->gc); - tree_view->gc = NULL; - - if (parent_class->unrealize) - (* parent_class->unrealize) (ecv); -} - -/* - * ECell::draw method - */ -static void -ect_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, gboolean selected, - int x1, int y1, int x2, int y2) -{ - ECellTreeView *tree_view = (ECellTreeView *)ecell_view; - ETreeModel *tree_model = e_cell_tree_get_tree_model(ecell_view->e_table_model, row); - ETreePath *node; - GdkRectangle rect, *clip_rect; - GtkWidget *canvas = GTK_WIDGET (tree_view->canvas); - GdkGC *fg_gc = canvas->style->fg_gc[GTK_STATE_ACTIVE]; - GdkColor *foreground; - - int offset, subcell_offset; - gboolean expanded, expandable; - - /* only draw the tree effects if we're the active sort */ - if (/* XXX */ TRUE) { - GdkPixbuf *node_image; - int node_image_width = 0, node_image_height = 0; - ETreePath *parent_node; - - node = e_cell_tree_get_node (tree_model, row); - - offset = offset_of_node (tree_model, node); - expandable = e_tree_model_node_is_expandable (tree_model, node); - expanded = e_tree_model_node_is_expanded (tree_model, node); - subcell_offset = offset; - - node_image = e_tree_model_icon_of_node (tree_model, node); - - if (node_image) { - node_image_width = gdk_pixbuf_get_width (node_image); - node_image_height = gdk_pixbuf_get_height (node_image); - } - - /* - * Be a nice citizen: clip to the region we are supposed to draw on - */ - rect.x = x1; - rect.y = y1; - rect.width = subcell_offset + node_image_width; - rect.height = y2 - y1; - - gdk_gc_set_clip_rectangle (tree_view->gc, &rect); - gdk_gc_set_clip_rectangle (fg_gc, &rect); - clip_rect = ▭ - - if (selected) { - foreground = &canvas->style->text [GTK_STATE_SELECTED]; - } else { - foreground = &canvas->style->text [GTK_STATE_NORMAL]; - } - - gdk_gc_set_foreground (tree_view->gc, foreground); - - /* draw our lines */ - if (E_CELL_TREE(tree_view->cell_view.ecell)->draw_lines) { - - if (visible_depth_of_node (tree_model, node) > 0 - || e_tree_model_node_get_children (tree_model, node, NULL) > 0) - gdk_draw_line (drawable, tree_view->gc, - rect.x + offset - INDENT_AMOUNT / 2 + 1, - rect.y + rect.height / 2, - rect.x + offset, - rect.y + rect.height / 2); - - if (visible_depth_of_node (tree_model, node) != 0) { - gdk_draw_line (drawable, tree_view->gc, - rect.x + offset - INDENT_AMOUNT / 2, - rect.y, - rect.x + offset - INDENT_AMOUNT / 2, - (e_tree_model_node_get_next (tree_model, node) - ? rect.y + rect.height - : rect.y + rect.height / 2)); - } - - /* now traverse back up to the root of the tree, checking at - each level if the node has siblings, and drawing the - correct vertical pipe for it's configuration. */ - parent_node = e_tree_model_node_get_parent (tree_model, node); - offset -= INDENT_AMOUNT; - while (parent_node && visible_depth_of_node (tree_model, parent_node) != 0) { - if (e_tree_model_node_get_next(tree_model, parent_node)) { - gdk_draw_line (drawable, tree_view->gc, - rect.x + offset - INDENT_AMOUNT / 2, - rect.y, - rect.x + offset - INDENT_AMOUNT / 2, - rect.y + rect.height); - } - parent_node = e_tree_model_node_get_parent (tree_model, parent_node); - offset -= INDENT_AMOUNT; - } - } - - /* now draw our icon if we're expandable */ - if (expandable) { - GdkPixbuf *image; - int image_width, image_height; - - image = (expanded - ? E_CELL_TREE(tree_view->cell_view.ecell)->open_pixbuf - : E_CELL_TREE(tree_view->cell_view.ecell)->closed_pixbuf); - - image_width = gdk_pixbuf_get_width(image); - image_height = gdk_pixbuf_get_height(image); - - gdk_pixbuf_render_to_drawable_alpha (image, - drawable, - 0, 0, - x1 + subcell_offset - INDENT_AMOUNT / 2 - image_width / 2, - y1 + (y2 - y1) / 2 - image_height / 2, - image_width, image_height, - GDK_PIXBUF_ALPHA_BILEVEL, - 128, - GDK_RGB_DITHER_NORMAL, - image_width, 0); - } - - if (node_image) { - gdk_pixbuf_render_to_drawable_alpha (node_image, - drawable, - 0, 0, - x1 + subcell_offset, - y1 + (y2 - y1) / 2 - node_image_height / 2, - node_image_width, node_image_height, - GDK_PIXBUF_ALPHA_BILEVEL, - 128, - GDK_RGB_DITHER_NORMAL, - node_image_width, 0); - subcell_offset += node_image_width; - } - } - - /* Now cause our subcell to draw its contents, shifted by - subcell_offset pixels */ - e_cell_draw (tree_view->subcell_view, drawable, - model_col, view_col, row, selected, - x1 + subcell_offset, y1, x2, y2); -} - -/* - * ECell::event method - */ -static gint -ect_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - ETreeModel *tree_model = e_cell_tree_get_tree_model (ecell_view->e_table_model, row); - ETreePath *node = e_cell_tree_get_node (tree_model, row); - int offset = offset_of_node (tree_model, node); - - switch (event->type) { - case GDK_BUTTON_PRESS: { - /* if the event happened in our area of control (and - we care about it), handle it. */ - - /* only activate the tree control if the click/release happens in the icon's area. */ - if (event->button.x > (offset - INDENT_AMOUNT) && event->button.x < offset) { - if (e_tree_model_node_is_expandable (tree_model, node)) { - e_tree_model_node_set_expanded (tree_model, - node, - !e_tree_model_node_is_expanded(tree_model, node)); - } - return TRUE; - } - else if (event->button.x < (offset - INDENT_AMOUNT)) - return TRUE; - } - default: - /* modify the event and pass it off to our subcell_view */ - switch (event->type) { - case GDK_BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - event->button.x -= offset; - break; - case GDK_MOTION_NOTIFY: - event->motion.x -= offset; - break; - default: - /* nada */ - } - e_cell_event(tree_view->subcell_view, event, model_col, view_col, row); - return TRUE; - } -} - -/* - * ECell::height method - */ -static int -ect_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - - return e_cell_height (tree_view->subcell_view, model_col, view_col, row); -} - -/* - * ECellView::enter_edit method - */ -static void * -ect_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) -{ - /* just defer to our subcell's view */ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - - return e_cell_enter_edit (tree_view->subcell_view, model_col, view_col, row); -} - -/* - * ECellView::leave_edit method - */ -static void -ect_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context) -{ - /* just defer to our subcell's view */ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - - e_cell_leave_edit (tree_view->subcell_view, model_col, view_col, row, edit_context); -} - -static void -ect_print (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width, double height) -{ - ECellTreeView *tree_view = (ECellTreeView *) ecell_view; - - if (/* XXX only if we're the active sort */ TRUE) { - ETreeModel *tree_model = e_cell_tree_get_tree_model (ecell_view->e_table_model, row); - ETreePath *node = e_cell_tree_get_node (tree_model, row); - int offset = offset_of_node (tree_model, node); - int subcell_offset = offset; - gboolean expandable = e_tree_model_node_is_expandable (tree_model, node); - gboolean expanded = e_tree_model_node_is_expanded (tree_model, node); - - /* draw our lines */ - if (E_CELL_TREE(tree_view->cell_view.ecell)->draw_lines) { - - if (!e_tree_model_node_is_root (tree_model, node) - || e_tree_model_node_get_children (tree_model, node, NULL) > 0) { - gnome_print_moveto (context, - offset - INDENT_AMOUNT / 2, - height / 2); - - gnome_print_lineto (context, - offset, - height / 2); - } - - if (visible_depth_of_node (tree_model, node) != 0) { - gnome_print_moveto (context, - offset - INDENT_AMOUNT / 2, - height); - gnome_print_lineto (context, - offset - INDENT_AMOUNT / 2, - (e_tree_model_node_get_next (tree_model, node) - ? 0 - : height / 2)); - } - - /* now traverse back up to the root of the tree, checking at - each level if the node has siblings, and drawing the - correct vertical pipe for it's configuration. */ - node = e_tree_model_node_get_parent (tree_model, node); - offset -= INDENT_AMOUNT; - while (node && visible_depth_of_node (tree_model, node) != 0) { - if (e_tree_model_node_get_next(tree_model, node)) { - gnome_print_moveto (context, - offset - INDENT_AMOUNT / 2, - height); - gnome_print_lineto (context, - offset - INDENT_AMOUNT / 2, - 0); - } - node = e_tree_model_node_get_parent (tree_model, node); - offset -= INDENT_AMOUNT; - } - } - - /* now draw our icon if we're expandable */ - if (expandable) { - double image_matrix [6] = {16, 0, 0, 16, 0, 0}; - GdkPixbuf *image = (expanded - ? E_CELL_TREE(tree_view->cell_view.ecell)->open_pixbuf - : E_CELL_TREE(tree_view->cell_view.ecell)->closed_pixbuf); - int image_width, image_height, image_rowstride; - guchar *image_pixels; - - image_width = gdk_pixbuf_get_width(image); - image_height = gdk_pixbuf_get_height(image); - image_pixels = gdk_pixbuf_get_pixels(image); - image_rowstride = gdk_pixbuf_get_rowstride(image); - - image_matrix [4] = subcell_offset - INDENT_AMOUNT / 2 - image_width / 2; - image_matrix [5] = height / 2 - image_height / 2; - - gnome_print_gsave (context); - gnome_print_concat (context, image_matrix); - - gnome_print_rgbaimage (context, image_pixels, image_width, image_height, image_rowstride); - gnome_print_grestore (context); - } - - gnome_print_stroke (context); - - if (gnome_print_translate(context, subcell_offset, 0) == -1) - /* FIXME */; - width -= subcell_offset; - } - - - e_cell_print (tree_view->subcell_view, context, model_col, view_col, row, width, height); -} - -static gdouble -ect_print_height (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width) -{ - return 12; /* XXX */ -} - -/* - * GtkObject::destroy method - */ -static void -ect_destroy (GtkObject *object) -{ - ECellTree *ect = E_CELL_TREE (object); - - /* destroy our subcell */ - gtk_object_destroy (GTK_OBJECT (ect->subcell)); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -static void -e_cell_tree_class_init (GtkObjectClass *object_class) -{ - ECellClass *ecc = (ECellClass *) object_class; - - object_class->destroy = ect_destroy; - - ecc->new_view = ect_new_view; - ecc->kill_view = ect_kill_view; - ecc->realize = ect_realize; - ecc->unrealize = ect_unrealize; - ecc->draw = ect_draw; - ecc->event = ect_event; - ecc->height = ect_height; - ecc->enter_edit = ect_enter_edit; - ecc->leave_edit = ect_leave_edit; - ecc->print = ect_print; - ecc->print_height = ect_print_height; - - parent_class = gtk_type_class (PARENT_TYPE); -} - -E_MAKE_TYPE(e_cell_tree, "ECellTree", ECellTree, e_cell_tree_class_init, NULL, PARENT_TYPE); - -void -e_cell_tree_construct (ECellTree *ect, - GdkPixbuf *open_pixbuf, - GdkPixbuf *closed_pixbuf, - gboolean draw_lines, - ECell *subcell) -{ - ect->subcell = subcell; - ect->open_pixbuf = open_pixbuf; - ect->closed_pixbuf = closed_pixbuf; - ect->draw_lines = draw_lines; -} - - -ECell * -e_cell_tree_new (ETableModel *etm, - GdkPixbuf *open_pixbuf, - GdkPixbuf *closed_pixbuf, - gboolean draw_lines, - ECell *subcell) -{ - ECellTree *ect = gtk_type_new (e_cell_tree_get_type ()); - - e_cell_tree_construct (ect, open_pixbuf, closed_pixbuf, draw_lines, subcell); - - return (ECell *) ect; -} diff --git a/widgets/table/e-cell-tree.h b/widgets/table/e-cell-tree.h deleted file mode 100644 index ef6babeda4..0000000000 --- a/widgets/table/e-cell-tree.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ECellTree - Tree item for e-table. - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Toshok <toshok@helixcode.com> - * - */ -#ifndef _E_CELL_TREE_H_ -#define _E_CELL_TREE_H_ - -#include <libgnomeui/gnome-canvas.h> -#include "e-cell.h" - -#define E_CELL_TREE_TYPE (e_cell_tree_get_type ()) -#define E_CELL_TREE(o) (GTK_CHECK_CAST ((o), E_CELL_TREE_TYPE, ECellTree)) -#define E_CELL_TREE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_TREE_TYPE, ECellTreeClass)) -#define E_IS_CELL_TREE(o) (GTK_CHECK_TYPE ((o), E_CELL_TREE_TYPE)) -#define E_IS_CELL_TREE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_TREE_TYPE)) - -typedef struct { - ECell parent; - - gboolean draw_lines; - - GdkPixbuf *open_pixbuf; - GdkPixbuf *closed_pixbuf; - - ECell *subcell; -} ECellTree; - -typedef struct { - ECellClass parent_class; -} ECellTreeClass; - -GtkType e_cell_tree_get_type (void); -ECell *e_cell_tree_new (ETableModel *model, - GdkPixbuf *open_pixbuf, - GdkPixbuf *closed_pixbuf, - gboolean draw_lines, - ECell *subcell); -void e_cell_tree_construct (ECellTree *ect, - GdkPixbuf *open_pixbuf, - GdkPixbuf *closed_pixbuf, - gboolean draw_lines, - ECell *subcell); - -#endif /* _E_CELL_TREE_H_ */ - - diff --git a/widgets/table/e-cell.c b/widgets/table/e-cell.c deleted file mode 100644 index 75be2ce916..0000000000 --- a/widgets/table/e-cell.c +++ /dev/null @@ -1,200 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-cell.c: base class for cell renderers in e-table - * - * Author: - * Miguel de Icaza (miguel@kernel.org) - * - * (C) 1999 Helix Code, Inc - */ -#include <config.h> -#include "e-cell.h" -#include "e-util/e-util.h" - -#define PARENT_TYPE gtk_object_get_type () - -static ECellView * -ec_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - return NULL; -} - -static void -ec_realize (ECellView *e_cell) -{ -} - -static void -ec_kill_view (ECellView *ecell_view) -{ -} - -static void -ec_unrealize (ECellView *e_cell) -{ -} - -static void -ec_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, gboolean selected, - int x1, int y1, int x2, int y2) -{ - g_error ("e-cell-draw invoked\n"); -} - -static gint -ec_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row) -{ - g_error ("e-cell-event invoked\n"); - return 0; -} - -static gint -ec_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - g_error ("e-cell-event invoked\n"); - return 0; -} - -static void -ec_focus (ECellView *ecell_view, int model_col, int view_col, int row, int x1, int y1, int x2, int y2) -{ - ecell_view->focus_col = view_col; - ecell_view->focus_row = row; - ecell_view->focus_x1 = x1; - ecell_view->focus_y1 = y1; - ecell_view->focus_x2 = x2; - ecell_view->focus_y2 = y2; -} - -static void -ec_unfocus (ECellView *ecell_view) -{ - ecell_view->focus_col = -1; - ecell_view->focus_row = -1; - ecell_view->focus_x1 = -1; - ecell_view->focus_y1 = -1; - ecell_view->focus_x2 = -1; - ecell_view->focus_y2 = -1; -} - -static void * -ec_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) -{ - return NULL; -} - -static void -ec_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *context) -{ -} - -static void -e_cell_class_init (GtkObjectClass *object_class) -{ - ECellClass *ecc = (ECellClass *) object_class; - - ecc->realize = ec_realize; - ecc->unrealize = ec_unrealize; - ecc->new_view = ec_new_view; - ecc->kill_view = ec_kill_view; - ecc->draw = ec_draw; - ecc->event = ec_event; - ecc->focus = ec_focus; - ecc->unfocus = ec_unfocus; - ecc->height = ec_height; - ecc->enter_edit = ec_enter_edit; - ecc->leave_edit = ec_leave_edit; - ecc->print = NULL; - ecc->print_height = NULL; -} - -static void -e_cell_init (GtkObject *object) -{ -} - -E_MAKE_TYPE(e_cell, "ECell", ECell, e_cell_class_init, e_cell_init, PARENT_TYPE); - - -void -e_cell_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->event ( - ecell_view, event, model_col, view_col, row); -} - -ECellView * -e_cell_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell)->klass)->new_view ( - ecell, table_model, e_table_item_view); -} - -void -e_cell_realize (ECellView *ecell_view) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->realize (ecell_view); -} - -void -e_cell_kill_view (ECellView *ecell_view) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->kill_view (ecell_view); -} - -void -e_cell_unrealize (ECellView *ecell_view) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->unrealize (ecell_view); -} - -void -e_cell_draw (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, gboolean selected, int x1, int y1, int x2, int y2) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->draw ( - ecell_view, drawable, model_col, view_col, row, selected, x1, y1, x2, y2); -} - -void -e_cell_print (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width, double height) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->print - (ecell_view, context, model_col, view_col, row, width, height); -} - -gdouble -e_cell_print_height (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width) -{ - if (E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->print_height) - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->print_height - (ecell_view, context, model_col, view_col, row, width); - else - return 0.0; -} - -int -e_cell_height (ECellView *ecell_view, int model_col, int view_col, int row) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->height ( - ecell_view, model_col, view_col, row); -} - -void * -e_cell_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row) -{ - return E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->enter_edit ( - ecell_view, model_col, view_col, row); -} - -void -e_cell_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context) -{ - E_CELL_CLASS (GTK_OBJECT (ecell_view->ecell)->klass)->leave_edit ( - ecell_view, model_col, view_col, row, edit_context); -} diff --git a/widgets/table/e-cell.h b/widgets/table/e-cell.h deleted file mode 100644 index 40b257f264..0000000000 --- a/widgets/table/e-cell.h +++ /dev/null @@ -1,85 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_CELL_H_ -#define _E_CELL_H_ - -#include <gdk/gdktypes.h> -#include <libgnomeprint/gnome-print.h> -#include "e-table-model.h" - -#define E_CELL_TYPE (e_cell_get_type ()) -#define E_CELL(o) (GTK_CHECK_CAST ((o), E_CELL_TYPE, ECell)) -#define E_CELL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CELL_TYPE, ECellClass)) -#define E_IS_CELL(o) (GTK_CHECK_TYPE ((o), E_CELL_TYPE)) -#define E_IS_CELL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CELL_TYPE)) - -typedef struct _ECell ECell; -typedef struct _ECellView ECellView; - -struct _ECell { - GtkObject object; -}; - -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; -}; - -#define E_CELL_IS_FOCUSED(ecell_view) (ecell_view->focus_x1 != -1) - -typedef struct { - GtkObjectClass parent_class; - - ECellView *(*new_view) (ECell *ecell, ETableModel *table_model, void *e_table_item_view); - void (*kill_view) (ECellView *ecell_view); - - void (*realize) (ECellView *ecell_view); - void (*unrealize) (ECellView *ecell_view); - - void (*draw) (ECellView *ecell_view, GdkDrawable *drawable, - int model_col, int view_col, int row, - gboolean selected, int x1, int y1, int x2, int y2); - gint (*event) (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row); - void (*focus) (ECellView *ecell_view, int model_col, int view_col, - int row, int x1, int y1, int x2, int y2); - void (*unfocus) (ECellView *ecell_view); - int (*height) (ECellView *ecell_view, int model_col, int view_col, int row); - - void *(*enter_edit) (ECellView *ecell_view, int model_col, int view_col, int row); - void (*leave_edit) (ECellView *ecell_view, int model_col, int view_col, int row, void *context); - void (*print) (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - gdouble width, gdouble height); - gdouble (*print_height) (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, gdouble width); -} ECellClass; - -GtkType e_cell_get_type (void); -ECellView *e_cell_new_view (ECell *ecell, ETableModel *table_model, void *e_table_item_view); -void e_cell_kill_view (ECellView *ecell_view); - -void e_cell_event (ECellView *ecell_view, GdkEvent *event, int model_col, int view_col, int row); - -void e_cell_realize (ECellView *ecell_view); -void e_cell_unrealize (ECellView *ecell_view); - -void e_cell_draw (ECellView *ecell_view, GdkDrawable *dr, - int model_col, int view_col, int row, gboolean selected, - int x1, int y1, int x2, int y2); -void e_cell_print (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, - double width, double height); -gdouble e_cell_print_height (ECellView *ecell_view, GnomePrintContext *context, - int model_col, int view_col, int row, gdouble width); -void e_cell_focus (ECellView *ecell_view, int model_col, int view_col, int row, - int x1, int y1, int x2, int y2); -void e_cell_unfocus (ECellView *ecell_view); -int e_cell_height (ECellView *ecell_view, int model_col, int view_col, int row); - -void *e_cell_enter_edit (ECellView *ecell_view, int model_col, int view_col, int row); -void e_cell_leave_edit (ECellView *ecell_view, int model_col, int view_col, int row, void *edit_context); - -#endif /* _E_CELL_H_ */ diff --git a/widgets/table/e-table-click-to-add.c b/widgets/table/e-table-click-to-add.c deleted file mode 100644 index ba38078b2c..0000000000 --- a/widgets/table/e-table-click-to-add.c +++ /dev/null @@ -1,504 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-click-to-add.c: A canvas item based view of the ETableColumn. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, 2000 Helix Code, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include <libgnomeui/gnome-canvas.h> -#include <libgnomeui/gnome-canvas-util.h> -#include <libgnomeui/gnome-canvas-rect-ellipse.h> -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include "e-table-header.h" -#include "e-table-click-to-add.h" -#include "e-table-defines.h" -#include "e-table-one.h" -#include "widgets/e-text/e-text.h" -#include "e-util/e-canvas.h" -#include "e-util/e-canvas-utils.h" - -enum { - CURSOR_CHANGE, - LAST_SIGNAL -}; - -static gint etcta_signals [LAST_SIGNAL] = { 0, }; - -#define PARENT_OBJECT_TYPE gnome_canvas_group_get_type () - -#define ELEMENTS(x) (sizeof (x) / sizeof (x[0])) - -static GnomeCanvasGroupClass *etcta_parent_class; - -enum { - ARG_0, - ARG_HEADER, - ARG_MODEL, - ARG_MESSAGE, - ARG_WIDTH, - ARG_HEIGHT, -}; - -static void -etcta_cursor_change (GtkObject *object, gint row, gint col, ETableClickToAdd *etcta) -{ - gtk_signal_emit (GTK_OBJECT (etcta), - etcta_signals [CURSOR_CHANGE], - row, col); -} - -static void -etcta_add_table_header (ETableClickToAdd *etcta, ETableHeader *header) -{ - etcta->eth = header; - if (etcta->eth) - gtk_object_ref (GTK_OBJECT (etcta->eth)); - if (etcta->row) - gnome_canvas_item_set(GNOME_CANVAS_ITEM(etcta->row), - "ETableHeader", header, - NULL); -} - -static void -etcta_drop_table_header (ETableClickToAdd *etcta) -{ - GtkObject *header; - - if (!etcta->eth) - return; - - header = GTK_OBJECT (etcta->eth); - - gtk_object_unref (header); - etcta->eth = NULL; -} - -static void -etcta_add_one (ETableClickToAdd *etcta, ETableModel *one) -{ - etcta->one = one; - if (etcta->one) - gtk_object_ref (GTK_OBJECT(etcta->one)); - if (etcta->row) - gnome_canvas_item_set(GNOME_CANVAS_ITEM(etcta->row), - "ETableModel", one, - NULL); - gtk_object_set(GTK_OBJECT(etcta->selection), - "model", one, - NULL); -} - -static void -etcta_drop_one (ETableClickToAdd *etcta) -{ - if (!etcta->one) - return; - gtk_object_unref (GTK_OBJECT(etcta->one)); - etcta->one = NULL; - gtk_object_set(GTK_OBJECT(etcta->selection), - "model", NULL, - NULL); -} - -static void -etcta_add_model (ETableClickToAdd *etcta, ETableModel *model) -{ - etcta->model = model; - if (etcta->model) - gtk_object_ref (GTK_OBJECT(etcta->model)); -} - -static void -etcta_drop_model (ETableClickToAdd *etcta) -{ - etcta_drop_one (etcta); - if (!etcta->model) - return; - gtk_object_unref (GTK_OBJECT(etcta->model)); - etcta->model = NULL; -} - -static void -etcta_add_message (ETableClickToAdd *etcta, char *message) -{ - etcta->message = g_strdup(message); -} - -static void -etcta_drop_message (ETableClickToAdd *etcta) -{ - g_free(etcta->message); - etcta->message = NULL; -} - - -static void -etcta_destroy (GtkObject *object){ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (object); - - etcta_drop_table_header (etcta); - etcta_drop_model (etcta); - etcta_drop_message (etcta); - gtk_object_unref(GTK_OBJECT(etcta->selection)); - - if (GTK_OBJECT_CLASS (etcta_parent_class)->destroy) - (*GTK_OBJECT_CLASS (etcta_parent_class)->destroy) (object); -} - -static void -etcta_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableClickToAdd *etcta; - - item = GNOME_CANVAS_ITEM (o); - etcta = E_TABLE_CLICK_TO_ADD (o); - - switch (arg_id){ - case ARG_HEADER: - etcta_drop_table_header (etcta); - etcta_add_table_header (etcta, E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg))); - break; - case ARG_MODEL: - etcta_drop_model (etcta); - etcta_add_model (etcta, E_TABLE_MODEL(GTK_VALUE_OBJECT (*arg))); - break; - case ARG_MESSAGE: - etcta_drop_message (etcta); - etcta_add_message (etcta, GTK_VALUE_STRING (*arg)); - break; - case ARG_WIDTH: - etcta->width = GTK_VALUE_DOUBLE (*arg); - if (etcta->row) - gnome_canvas_item_set(etcta->row, - "minimum_width", etcta->width, - NULL); - if (etcta->text) - gnome_canvas_item_set(etcta->text, - "width", etcta->width - 4, - NULL); - if (etcta->rect) - gnome_canvas_item_set(etcta->rect, - "x2", etcta->width - 1, - NULL); - break; - } - gnome_canvas_item_request_update(item); -} - -static void -etcta_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableClickToAdd *etcta; - - etcta = E_TABLE_CLICK_TO_ADD (o); - - switch (arg_id){ - case ARG_HEADER: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etcta->eth); - break; - case ARG_MODEL: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etcta->model); - break; - case ARG_MESSAGE: - GTK_VALUE_STRING (*arg) = g_strdup(etcta->message); - break; - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = etcta->width; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = etcta->height; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -etcta_realize (GnomeCanvasItem *item) -{ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item); - etcta->text = gnome_canvas_item_new(GNOME_CANVAS_GROUP(item), - e_text_get_type(), - "text", etcta->message ? etcta->message : "", - "anchor", GTK_ANCHOR_NW, - "width", etcta->width - 4, - NULL); - e_canvas_item_move_absolute (etcta->text, 2, 2); - etcta->rect = gnome_canvas_item_new(GNOME_CANVAS_GROUP(item), - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) etcta->width - 1, - "y2", (double) etcta->height - 1, - "outline_color", "black", - "fill_color", NULL, - NULL); - - if (GNOME_CANVAS_ITEM_CLASS (etcta_parent_class)->realize) - (*GNOME_CANVAS_ITEM_CLASS (etcta_parent_class)->realize)(item); -} - -static void -etcta_unrealize (GnomeCanvasItem *item) -{ - if (GNOME_CANVAS_ITEM_CLASS (etcta_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (etcta_parent_class)->unrealize)(item); -} - -static double -etcta_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - -/* - * Handles the events on the ETableClickToAdd, particularly it creates the ETableItem and passes in some events. - */ -static int -etcta_event (GnomeCanvasItem *item, GdkEvent *e) -{ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item); - int ret_val = TRUE; - - switch (e->type){ - case GDK_BUTTON_PRESS: - if (etcta->text) { - gtk_object_destroy(GTK_OBJECT(etcta->text)); - etcta->text = NULL; - } - if (etcta->rect) { - gtk_object_destroy(GTK_OBJECT(etcta->rect)); - etcta->rect = NULL; - } - if (!etcta->row) { - ETableModel *one; - - one = e_table_one_new(etcta->model); - etcta_add_one (etcta, one); - gtk_object_unref(GTK_OBJECT(one)); - - e_table_selection_model_clear(etcta->selection); - - etcta->row = gnome_canvas_item_new(GNOME_CANVAS_GROUP(item), - e_table_item_get_type(), - "ETableHeader", etcta->eth, - "ETableModel", etcta->one, - "minimum_width", etcta->width, - "drawgrid", TRUE, - "table_selection_model", etcta->selection, - NULL); - - } - /* Fall through. No break; */ - case GDK_BUTTON_RELEASE: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - if (etcta->row) { - gnome_canvas_item_i2w (item, &e->button.x, &e->button.y); - gnome_canvas_item_w2i (etcta->row, &e->button.x, &e->button.y); - gtk_signal_emit_by_name(GTK_OBJECT(etcta->row), "event", e, &ret_val); - gnome_canvas_item_i2w (etcta->row, &e->button.x, &e->button.y); - gnome_canvas_item_w2i (item, &e->button.x, &e->button.y); - } - break; - - case GDK_KEY_PRESS: - switch (e->key.keyval) { - case GDK_Return: - case GDK_KP_Enter: - case GDK_ISO_Enter: - case GDK_3270_Enter: - - case GDK_Tab: - case GDK_KP_Tab: - case GDK_ISO_Left_Tab: - - if (etcta->row) { - ETableModel *one; - - e_table_one_commit(E_TABLE_ONE(etcta->one)); - etcta_drop_one (etcta); - gtk_object_destroy(GTK_OBJECT(etcta->row)); - etcta->row = NULL; - - one = e_table_one_new(etcta->model); - etcta_add_one (etcta, one); - gtk_object_unref(GTK_OBJECT(one)); - - e_table_selection_model_clear(etcta->selection); - - etcta->row = gnome_canvas_item_new(GNOME_CANVAS_GROUP(item), - e_table_item_get_type(), - "ETableHeader", etcta->eth, - "ETableModel", etcta->one, - "minimum_width", etcta->width, - "drawgrid", TRUE, - "table_selection_model", etcta->selection, - NULL); - - e_table_item_set_cursor(E_TABLE_ITEM(etcta->row), 0, 0); - } - break; - default: - break; - } - - default: - return FALSE; - } - return TRUE; -} - -static void -etcta_reflow (GnomeCanvasItem *item, int flags) -{ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item); - - double old_height = etcta->height; - - if (etcta->text) { - gtk_object_get(GTK_OBJECT(etcta->text), - "height", &etcta->height, - NULL); - etcta->height += 4; - } - if (etcta->row) { - gtk_object_get(GTK_OBJECT(etcta->row), - "height", &etcta->height, - NULL); - } - - if (etcta->rect) { - gtk_object_set(GTK_OBJECT(etcta->rect), - "y2", etcta->height - 1, - NULL); - } - if (old_height != etcta->height) - e_canvas_item_request_parent_reflow(item); -} - -static void -etcta_class_init (ETableClickToAddClass *klass) -{ - GnomeCanvasItemClass *item_class = GNOME_CANVAS_ITEM_CLASS(klass); - GtkObjectClass *object_class = GTK_OBJECT_CLASS(klass); - - etcta_parent_class = gtk_type_class (PARENT_OBJECT_TYPE); - - klass->cursor_change = NULL; - - object_class->destroy = etcta_destroy; - object_class->set_arg = etcta_set_arg; - object_class->get_arg = etcta_get_arg; - - item_class->realize = etcta_realize; - item_class->unrealize = etcta_unrealize; - item_class->point = etcta_point; - item_class->event = etcta_event; - - gtk_object_add_arg_type ("ETableClickToAdd::header", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_HEADER); - gtk_object_add_arg_type ("ETableClickToAdd::model", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_MODEL); - gtk_object_add_arg_type ("ETableClickToAdd::message", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_MESSAGE); - gtk_object_add_arg_type ("ETableClickToAdd::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ETableClickToAdd::height", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_HEIGHT); - - etcta_signals [CURSOR_CHANGE] = - gtk_signal_new ("cursor_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClickToAddClass, cursor_change), - gtk_marshal_NONE__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, etcta_signals, LAST_SIGNAL); -} - -static void -etcta_init (GnomeCanvasItem *item) -{ - ETableClickToAdd *etcta = E_TABLE_CLICK_TO_ADD (item); - - etcta->one = NULL; - etcta->model = NULL; - etcta->eth = NULL; - - etcta->message = NULL; - - etcta->row = NULL; - etcta->text = NULL; - etcta->rect = NULL; - - etcta->selection = e_table_selection_model_new(); - gtk_signal_connect(GTK_OBJECT(etcta->selection), "cursor_changed", - GTK_SIGNAL_FUNC(etcta_cursor_change), etcta); - - e_canvas_item_set_reflow_callback(item, etcta_reflow); -} - -GtkType -e_table_click_to_add_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableClickToAdd", - sizeof (ETableClickToAdd), - sizeof (ETableClickToAddClass), - (GtkClassInitFunc) etcta_class_init, - (GtkObjectInitFunc) etcta_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_OBJECT_TYPE, &info); - } - - return type; -} - -void -e_table_click_to_add_commit (ETableClickToAdd *etcta) -{ - if (etcta->row) { - e_table_one_commit(E_TABLE_ONE(etcta->one)); - etcta_drop_one (etcta); - gtk_object_destroy(GTK_OBJECT(etcta->row)); - etcta->row = NULL; - } - if (!etcta->text) { - etcta->text = gnome_canvas_item_new(GNOME_CANVAS_GROUP(etcta), - e_text_get_type(), - "text", etcta->message ? etcta->message : "", - "anchor", GTK_ANCHOR_NW, - "width", etcta->width - 4, - NULL); - e_canvas_item_move_absolute (etcta->text, 2, 2); - } - if (!etcta->rect) { - etcta->rect = gnome_canvas_item_new(GNOME_CANVAS_GROUP(etcta), - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) etcta->width - 1, - "y2", (double) etcta->height - 1, - "outline_color", "black", - "fill_color", NULL, - NULL); - } -} 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 1dcbf9ef52..0000000000 --- a/widgets/table/e-table-click-to-add.h +++ /dev/null @@ -1,51 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_CLICK_TO_ADD_H_ -#define _E_TABLE_CLICK_TO_ADD_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gnome-xml/tree.h> -#include "e-table-header.h" -#include "e-table-sort-info.h" -#include "e-table-item.h" -#include "e-table-selection-model.h" - -#define E_TABLE_CLICK_TO_ADD_TYPE (e_table_click_to_add_get_type ()) -#define E_TABLE_CLICK_TO_ADD(o) (GTK_CHECK_CAST ((o), E_TABLE_CLICK_TO_ADD_TYPE, ETableClickToAdd)) -#define E_TABLE_CLICK_TO_ADD_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_CLICK_TO_ADD_TYPE, ETableClickToAddClass)) -#define E_IS_TABLE_CLICK_TO_ADD(o) (GTK_CHECK_TYPE ((o), E_TABLE_CLICK_TO_ADD_TYPE)) -#define E_IS_TABLE_CLICK_TO_ADD_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_CLICK_TO_ADD_TYPE)) - -typedef struct { - GnomeCanvasGroup parent; - - ETableModel *one; /* The ETableOne. */ - - ETableModel *model; /* The backend model. */ - ETableHeader *eth; /* This is just to give to the ETableItem. */ - - char *message; - - GnomeCanvasItem *row; /* If row is NULL, we're sitting with no data and a "Click here" message. */ - GnomeCanvasItem *text; /* If text is NULL, row shouldn't be. */ - GnomeCanvasItem *rect; /* What the heck. Why not. */ - - gdouble width; - gdouble height; - - ETableSelectionModel *selection; -} ETableClickToAdd; - -typedef struct { - GnomeCanvasGroupClass parent_class; - - /* - * signals - */ - void (*cursor_change) (ETableClickToAdd *etcta, gint row, gint col); -} ETableClickToAddClass; - -GtkType e_table_click_to_add_get_type (void); - -void e_table_click_to_add_commit (ETableClickToAdd *etcta); - -#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 c1c26175c7..0000000000 --- a/widgets/table/e-table-col-dnd.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _E_TABLE_COL_DND_H_ -#define _E_TABLE_COL_DND_H_ - -#define TARGET_ETABLE_COL_TYPE "application/x-etable-column-header" - -enum { - TARGET_ETABLE_COL_HEADER -}; - -#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 e767aa5567..0000000000 --- a/widgets/table/e-table-col.c +++ /dev/null @@ -1,168 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-col.c: ETableCol implementation - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc - */ -#include <config.h> -#include <gtk/gtkobject.h> -#include <gtk/gtksignal.h> -#include "e-table-col.h" -#include "e-util/e-util.h" - -#define PARENT_TYPE (gtk_object_get_type ()) - -static GtkObjectClass *parent_class; - - -enum { - ARG_0, - ARG_SORTABLE, -}; - -static void -etc_destroy (GtkObject *object) -{ - ETableCol *etc = E_TABLE_COL (object); - - gtk_object_unref (GTK_OBJECT(etc->ecell)); - - if (etc->is_pixbuf) - gdk_pixbuf_unref (etc->pixbuf); - else - g_free (etc->text); - - (*parent_class->destroy)(object); -} - - -static void -etc_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableCol *etc = E_TABLE_COL (o); - - switch (arg_id){ - case ARG_SORTABLE: - etc->sortable = GTK_VALUE_BOOL(*arg); - break; - } -} - -static void -etc_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableCol *etc = E_TABLE_COL (o); - - switch (arg_id){ - case ARG_SORTABLE: - GTK_VALUE_BOOL(*arg) = etc->sortable; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -e_table_col_class_init (GtkObjectClass *object_class) -{ - parent_class = gtk_type_class (PARENT_TYPE); - object_class->destroy = etc_destroy; - object_class->get_arg = etc_get_arg; - object_class->set_arg = etc_set_arg; - - gtk_object_add_arg_type ("ETableCol::sortable", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_SORTABLE); -} - -static void -e_table_col_init (ETableCol *etc) -{ - etc->width = 0; - etc->sortable = 1; - etc->groupable = 1; -} - -E_MAKE_TYPE(e_table_col, "ETableCol", ETableCol, e_table_col_class_init, e_table_col_init, PARENT_TYPE); - -ETableCol * -e_table_col_new (int col_idx, const char *text, double expansion, int min_width, - ECell *ecell, GCompareFunc compare, gboolean resizable) -{ - ETableCol *etc; - - g_return_val_if_fail (expansion >= 0, NULL); - g_return_val_if_fail (min_width >= 0, NULL); - g_return_val_if_fail (compare != NULL, NULL); - - etc = gtk_type_new (E_TABLE_COL_TYPE); - - etc->is_pixbuf = FALSE; - - etc->col_idx = col_idx; - etc->text = g_strdup (text); - etc->pixbuf = NULL; - etc->expansion = expansion; - etc->min_width = min_width; - etc->ecell = ecell; - etc->compare = compare; - - etc->arrow = E_TABLE_COL_ARROW_NONE; - - etc->selected = 0; - etc->resizeable = resizable; - - gtk_object_ref (GTK_OBJECT(etc->ecell)); - - return etc; -} - -ETableCol * -e_table_col_new_with_pixbuf (int col_idx, GdkPixbuf *pixbuf, double expansion, int min_width, - ECell *ecell, GCompareFunc compare, gboolean resizable) -{ - ETableCol *etc; - - g_return_val_if_fail (expansion >= 0, NULL); - g_return_val_if_fail (min_width >= 0, NULL); - g_return_val_if_fail (compare != NULL, NULL); - - etc = gtk_type_new (E_TABLE_COL_TYPE); - - etc->is_pixbuf = TRUE; - - etc->col_idx = col_idx; - etc->text = NULL; - etc->pixbuf = pixbuf; - etc->expansion = expansion; - etc->min_width = min_width; - etc->ecell = ecell; - etc->compare = compare; - - etc->arrow = E_TABLE_COL_ARROW_NONE; - - etc->selected = 0; - etc->resizeable = resizable; - - gtk_object_ref (GTK_OBJECT(etc->ecell)); - gdk_pixbuf_ref (etc->pixbuf); - - return etc; -} - -void -e_table_col_set_arrow (ETableCol *col, ETableColArrow arrow) -{ - col->arrow = arrow; -} - -ETableColArrow -e_table_col_get_arrow (ETableCol *col) -{ - return col->arrow; -} - - diff --git a/widgets/table/e-table-col.h b/widgets/table/e-table-col.h deleted file mode 100644 index 39aeb26ba9..0000000000 --- a/widgets/table/e-table-col.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_COL_H_ -#define _E_TABLE_COL_H_ - -#include "e-cell.h" -#include <gdk-pixbuf/gdk-pixbuf.h> - -#define E_TABLE_COL_TYPE (e_table_col_get_type ()) -#define E_TABLE_COL(o) (GTK_CHECK_CAST ((o), E_TABLE_COL_TYPE, ETableCol)) -#define E_TABLE_COL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_COL_TYPE, ETableColClass)) -#define E_IS_TABLE_COL(o) (GTK_CHECK_TYPE ((o), E_TABLE_COL_TYPE)) -#define E_IS_TABLE_COL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_COL_TYPE)) - -typedef struct _ETableCol ETableCol; -typedef struct _ETableColClass ETableColClass; -typedef enum _ETableColArrow ETableColArrow; - -enum _ETableColArrow { - E_TABLE_COL_ARROW_NONE = 0, - E_TABLE_COL_ARROW_UP, - E_TABLE_COL_ARROW_DOWN -}; - -/* - * Information about a single column - */ -struct _ETableCol { - GtkObject base; - char *text; - GdkPixbuf *pixbuf; - int min_width; - int width; - double expansion; - short x; - GCompareFunc compare; - unsigned int is_pixbuf:1; - unsigned int selected:1; - unsigned int resizeable:1; - unsigned int sortable:1; - unsigned int groupable:1; - int col_idx; - - ETableColArrow arrow; - - ECell *ecell; -}; - -struct _ETableColClass { - GtkObjectClass parent_class; -}; - -GtkType e_table_col_get_type (void); -ETableCol *e_table_col_new (int col_idx, const char *text, - double expansion, int min_width, - ECell *ecell, GCompareFunc compare, - gboolean resizable); -ETableCol *e_table_col_new_with_pixbuf (int col_idx, GdkPixbuf *pixbuf, - double expansion, int min_width, - ECell *ecell, GCompareFunc compare, - gboolean resizable); -void e_table_col_destroy (ETableCol *etc); -void e_table_col_set_arrow (ETableCol *col, ETableColArrow arrow); -ETableColArrow e_table_col_get_arrow (ETableCol *col); - - -#endif /* _E_TABLE_COL_H_ */ - diff --git a/widgets/table/e-table-column-model.h b/widgets/table/e-table-column-model.h deleted file mode 100644 index 043dd783ca..0000000000 --- a/widgets/table/e-table-column-model.h +++ /dev/null @@ -1,5 +0,0 @@ - -class ETableColumnModel { - virtual void add_column (ETableCol *et) = 0; - virtual ETableCol *get_column (int column); - virtual diff --git a/widgets/table/e-table-column.c b/widgets/table/e-table-column.c deleted file mode 100644 index d17a285321..0000000000 --- a/widgets/table/e-table-column.c +++ /dev/null @@ -1,293 +0,0 @@ -/* - * e-table-column.c: TableColumn implementation - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc - */ -#include <config.h> -#include "e-table-column.h" - -enum { - STRUCTURE_CHANGE, - DIMENSION_CHANGE, - LAST_SIGNAL -}; - -static guint etc_signals [LAST_SIGNAL] = { 0, }; - -static GtkObjectClass *e_table_column_parent_class; - -static void -e_table_column_destroy (GtkObject *object) -{ - ETableColumn *etc = E_TABLE_COLUMN (object); - const int cols = etc->col_count; - - /* - * Destroy listeners - */ - for (l = etc->listeners; l; l = l->next) - g_free (l->data); - g_slist_free (etc->listeners); - etc->listeners = NULL; - - /* - * Destroy columns - */ - for (i = 0; i < cols; i++) - e_table_column_remove (etc, i); - - if (e_table_column_parent_class->destroy) - e_table_column_parent_class->destroy (object); -} - -static void -e_table_column_class_init (GtkObjectClass *object_class) -{ - object_class->destroy = e_table_column_destroy; - - e_table_column_parent_class = (gtk_type_class (gtk_object_get_type ())); - - etc_signals [STRUCTURE_CHANGE] = - gtk_signal_new ("structure_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableColumn, structure_change), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - etc_signals [DIMENSION_CHANGE] = - gtk_signal_new ("dimension_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableColumn, dimension_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, etc_signals, LAST_SIGNAL); -} - -GtkType -e_table_column_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableColumn", - sizeof (ETableColumn), - sizeof (ETableColumnClass), - (GtkClassInitFunc) e_table_column_class_init, - (GtkObjectInitFunc) NULL, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &info); - } - - return type; -} - -static void -etc_do_insert (ETableColumn *etc, int pos, ETableCol *val) -{ - memcpy (&etc->columns [pos+1], &etc->columns [pos], - sizeof (ETableCol *) * (etc->col_count - pos)); - etc->columns [pos] = val; -} - -void -e_table_column_add_column (ETableColumn *etc, ETableCol *tc, int pos) -{ - ETableCol **new_ptr; - - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (tc != NULL); - g_return_if_fail (pos >= 0 && pos < etc->col_count); - - if (pos == -1) - pos = etc->col_count; - etc->columns = g_realloc (etc->columns, sizeof (ETableCol *) * (etc->col_count + 1)); - etc_do_insert (etc, pos, tc); - etc->col_count++; - - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [STRUCTURE_CHANGE]); -} - -ETableCol * -e_table_column_get_column (ETableColumn *etc, int column) -{ - g_return_val_if_fail (etc != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), NULL); - - if (column < 0) - return NULL; - - if (column >= etc->col_count) - return NULL; - - return etc->columns [column]; -} - -int -e_table_column_count (ETableColumn *etc) -{ - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - return etc->col_count; -} - -int -e_table_column_index (ETableColumn *etc, const char *identifier) -{ - int i; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - g_return_val_if_fail (identifier != NULL, 0); - - for (i = 0; i < etc->col_count; i++){ - ETableCol *tc = etc->columns [i]; - - if (strcmp (i->id, identifier) == 0) - return i; - } - - return -1; -} - -int -e_table_column_get_index_at (ETableColumn *etc, int x_offset) -{ - int i, total; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - g_return_val_if_fail (identifier != NULL, 0); - - total = 0; - for (i = 0; i < etc->col_count; i++){ - total += etc->columns [i]->width; - - if (x_offset < total) - return i; - } - - return -1; -} - -ETableCol ** -e_table_column_get_columns (ETableColumn *etc) -{ - ETableCol **ret; - int i; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - ret = g_new (ETableCol *, etc->col_count + 1); - memcpy (ret, etc->columns, sizeof (ETableCol *) * etc->col_count); - ret [etc->col_count] = NULL; - - return ret; -} - -gboolean -e_table_column_selection_ok (ETableColumn *etc) -{ - g_return_val_if_fail (etc != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), FALSE); - - return etc->selectable; -} - -int -ve_table_column_get_selected (ETableColumn *etc) -{ - int i; - int selected = 0; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - for (i = 0; i < etc->col_count; i++){ - if (etc->columns [i]->selected) - selected++; - } - - return selected; -} - -int -e_table_column_total_width (ETableColumn *etc) -{ - int total; - - g_return_val_if_fail (etc != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_COLUMN (etc), 0); - - total = 0; - for (i = 0; i < etc->col_count; i++) - total += etc->columns [i].width; - - return total; -} - -static void -etc_do_remove (ETableColumn *etc, int idx) -{ - memcpy (&etc->columns [idx], &etc->columns [idx+1], - sizeof (ETableCol *) * etc->col_count - idx); - etc->col_count--; -} - -void -e_table_column_move (ETableColumn *etc, int source_index, int target_index) -{ - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (source_index >= 0); - g_return_if_fail (target_index >= 0); - g_return_if_fail (source_index < etc->col_count); - g_return_if_fail (target_index < etc->col_count); - - old = etc->columns [source_index]; - etc_do_remove (etc, source_index); - etc_do_insert (etc, target_index, old); - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [STRUCTURE_CHANGE]); -} - -void -e_table_column_remove (ETableColumn *etc, int idx) -{ - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < etc->col_count); - - etc_do_remove (etc, idx); - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [STRUCTURE_CHANGE]); -} - -void -e_table_column_set_selection (ETableColumn *etc, gboolean allow_selection); -{ -} - -void -e_table_column_set_size (ETableColumn *etc, int idx, int size) -{ - g_return_if_fail (etc != NULL); - g_return_if_fail (E_IS_TABLE_COLUMN (etc)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < etc->col_count); - g_return_if_fail (size > 0); - - etc->columns [idx]->width = size; - gtk_signal_emit (GTK_OBJECT (etc), etc_signals [SIZE_CHANGE], idx); -} diff --git a/widgets/table/e-table-config.c b/widgets/table/e-table-config.c deleted file mode 100644 index 5d078f8f86..0000000000 --- a/widgets/table/e-table-config.c +++ /dev/null @@ -1,233 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table.c: A graphical view of a Table. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, Helix Code, Inc - */ -#include <config.h> -#include <gnome.h> -#include <glade/glade.h> -#include <gnome-xml/xmlmemory.h> -#include "e-util/e-util.h" -#include "e-util/e-xml-utils.h" -#include "e-util/e-canvas.h" -#include "e-table.h" -#include "e-table-header-item.h" -#include "e-table-subset.h" -#include "e-table-item.h" -#include "e-table-group.h" -#include "e-table-config.h" - -typedef struct { - GladeXML *gui; - char *old_spec; -} ConfigData; - -static void -load_data (GladeXML *xml, char *label_widget, const char *content) -{ - GtkLabel *label = GTK_LABEL (glade_xml_get_widget (xml, label_widget)); - - gtk_label_set_text (label, content); -} - -static char * -get_fields (ETable *etable, xmlNode *xmlRoot) -{ - xmlNode *xmlColumns; - xmlNode *column; - GString *res; - char *s; - - res = g_string_new (""); - xmlColumns = e_xml_get_child_by_name (xmlRoot, "columns-shown"); - - for (column = xmlColumns->childs; column; column = column->next){ - ETableCol *ecol; - char *content; - int col; - - content = xmlNodeListGetString (column->doc, column->childs, 1); - col = atoi (content); - xmlFree (content); - - ecol = e_table_header_get_column (etable->header, col); - - g_string_append (res, ecol->text); - if (column->next) - g_string_append (res, ", "); - } - s = res->str; - g_string_free (res, FALSE); - - return s; -} - -static char * -get_grouping (ETable *etable, xmlNode *xmlRoot) -{ - xmlNode *xmlGrouping; - GString *res; - char *s; - - res = g_string_new (""); - xmlGrouping = e_xml_get_child_by_name (xmlRoot, "grouping"); - - s = res->str; - g_string_free (res, FALSE); - - return s; -} - -static char * -get_sort (ETable *etable) -{ - return g_strdup ("None"); -} - -static char * -get_filter (ETable *etable) -{ - return g_strdup ("None"); -} - -/* - * Loads a user-readable definition of the various e-table parameters - * into the dialog for configuring it - */ -static void -load_label_data (GladeXML *gui, ETable *etable) -{ - /* FIXME: Set this to the right value. */ - xmlNode *xmlRoot = NULL; - char *s; - -/* xmlRoot = xmlDocGetRootElement (etable->specification); */ - - s = get_fields (etable, xmlRoot); - load_data (gui, "label1", s); - g_free (s); - - s = get_grouping (etable, xmlRoot); - load_data (gui, "label2", s); - g_free (s); - - s = get_sort (etable); - load_data (gui, "label3", s); - g_free (s); - - s = get_filter (etable); - load_data (gui, "label4", s); - g_free (s); -} - -static void -cb_button_fields (GtkWidget *widget, ETable *etable) -{ -} - -static void -cb_button_grouping (GtkWidget *widget, ETable *etable) -{ -} - -static void -cb_button_sort (GtkWidget *widget, ETable *etable) -{ -} - -static void -cb_button_filter (GtkWidget *widget, ETable *etable) -{ -} - -GnomeDialog * -e_table_gui_config (ETable *etable) -{ - GladeXML *gui; - GnomeDialog *dialog; - ConfigData *config_data; - - glade_gnome_init (); - gui = glade_xml_new (ETABLE_GLADEDIR "/e-table-config.glade", NULL); - if (!gui) - return NULL; - - dialog = GNOME_DIALOG (glade_xml_get_widget (gui, "e-table-config")); - - gtk_signal_connect ( - GTK_OBJECT (glade_xml_get_widget (gui, "button-fields")), - "clicked", GTK_SIGNAL_FUNC (cb_button_fields), etable); - gtk_signal_connect ( - GTK_OBJECT (glade_xml_get_widget (gui, "button-grouping")), - "clicked", GTK_SIGNAL_FUNC (cb_button_grouping), etable); - gtk_signal_connect ( - GTK_OBJECT (glade_xml_get_widget (gui, "button-sort")), - "clicked", GTK_SIGNAL_FUNC (cb_button_sort), etable); - gtk_signal_connect ( - GTK_OBJECT (glade_xml_get_widget (gui, "button-filter")), - "clicked", GTK_SIGNAL_FUNC (cb_button_filter), etable); - - load_label_data (gui, etable); - - config_data = g_new (ConfigData, 1); - config_data->gui = gui; - config_data->old_spec = e_table_get_specification (etable); - - gtk_object_set_data ( - GTK_OBJECT (dialog), "config-data", - config_data); - - return dialog; -} - -static void -e_table_gui_destroy_config_data (GtkWidget *widget) -{ - ConfigData *cd = gtk_object_get_data (GTK_OBJECT (widget), "config-data"); - - g_free (cd->old_spec); - gtk_object_destroy (GTK_OBJECT (cd->gui)); - g_free (cd); -} - -void -e_table_gui_config_accept (GtkWidget *widget, ETable *etable) -{ - e_table_gui_destroy_config_data (widget); -} - -void -e_table_gui_config_cancel (GtkWidget *widget, ETable *etable) -{ - e_table_gui_destroy_config_data (widget); -} - -void -e_table_do_gui_config (GtkWidget *parent, ETable *etable) -{ - GnomeDialog *dialog; - int r; - - dialog = GNOME_DIALOG (e_table_gui_config (etable)); - if (!dialog) - return; - - if (parent) - gnome_dialog_set_parent (dialog, GTK_WINDOW (parent)); - - r = gnome_dialog_run (GNOME_DIALOG (dialog)); - - if (r == -1 || r == 1) - e_table_gui_config_cancel (GTK_WIDGET (dialog), etable); - else - e_table_gui_config_accept (GTK_WIDGET (dialog), etable); - - if (r != -1) - gtk_object_destroy (GTK_OBJECT (dialog)); -} - - diff --git a/widgets/table/e-table-config.glade b/widgets/table/e-table-config.glade deleted file mode 100644 index 15223f21f1..0000000000 --- a/widgets/table/e-table-config.glade +++ /dev/null @@ -1,302 +0,0 @@ -<?xml version="1.0"?> -<GTK-Interface> - -<project> - <name>E-table</name> - <program_name>e-table</program_name> - <directory></directory> - <source_directory></source_directory> - <pixmaps_directory></pixmaps_directory> - <language>C</language> - <gnome_support>True</gnome_support> - <gettext_support>True</gettext_support> - <use_widget_names>False</use_widget_names> - <output_main_file>False</output_main_file> - <output_support_files>False</output_support_files> - <output_build_files>False</output_build_files> - <backup_source_files>True</backup_source_files> - <main_source_file>interface.c</main_source_file> - <main_header_file>interface.h</main_header_file> - <handler_source_file>callbacks.c</handler_source_file> - <handler_header_file>callbacks.h</handler_header_file> - <support_source_file>support.c</support_source_file> - <support_header_file>support.h</support_header_file> - <output_translatable_strings>True</output_translatable_strings> - <translatable_strings_file>e-table-config.glade.h</translatable_strings_file> -</project> - -<widget> - <class>GnomeDialog</class> - <name>e-table-config</name> - <visible>False</visible> - <type>GTK_WINDOW_TOPLEVEL</type> - <position>GTK_WIN_POS_NONE</position> - <modal>False</modal> - <allow_shrink>False</allow_shrink> - <allow_grow>False</allow_grow> - <auto_shrink>False</auto_shrink> - <auto_close>False</auto_close> - <hide_on_close>False</hide_on_close> - - <widget> - <class>GtkVBox</class> - <child_name>GnomeDialog:vbox</child_name> - <name>dialog-vbox2</name> - <homogeneous>False</homogeneous> - <spacing>0</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkFrame</class> - <name>top-frame</name> - <border_width>2</border_width> - <label></label> - <label_xalign>0</label_xalign> - <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkTable</class> - <name>table1</name> - <border_width>2</border_width> - <rows>4</rows> - <columns>2</columns> - <homogeneous>False</homogeneous> - <row_spacing>2</row_spacing> - <column_spacing>4</column_spacing> - - <widget> - <class>GtkButton</class> - <name>button-fields</name> - <can_focus>True</can_focus> - <label>Fields</label> - <child> - <left_attach>0</left_attach> - <right_attach>1</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - </widget> - - <widget> - <class>GtkButton</class> - <name>button-grouping</name> - <can_focus>True</can_focus> - <label>Grouping</label> - <child> - <left_attach>0</left_attach> - <right_attach>1</right_attach> - <top_attach>1</top_attach> - <bottom_attach>2</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - </widget> - - <widget> - <class>GtkButton</class> - <name>button-sort</name> - <can_focus>True</can_focus> - <label>Sort</label> - <child> - <left_attach>0</left_attach> - <right_attach>1</right_attach> - <top_attach>2</top_attach> - <bottom_attach>3</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - </widget> - - <widget> - <class>GtkButton</class> - <name>button-filter</name> - <can_focus>True</can_focus> - <label>Filter</label> - <child> - <left_attach>0</left_attach> - <right_attach>1</right_attach> - <top_attach>3</top_attach> - <bottom_attach>4</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label1</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <left_attach>1</left_attach> - <right_attach>2</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>False</yfill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label2</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <left_attach>1</left_attach> - <right_attach>2</right_attach> - <top_attach>1</top_attach> - <bottom_attach>2</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>False</yfill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label3</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <left_attach>1</left_attach> - <right_attach>2</right_attach> - <top_attach>2</top_attach> - <bottom_attach>3</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>False</yfill> - </child> - </widget> - - <widget> - <class>GtkLabel</class> - <name>label4</name> - <label></label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <left_attach>1</left_attach> - <right_attach>2</right_attach> - <top_attach>3</top_attach> - <bottom_attach>4</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>False</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>False</yfill> - </child> - </widget> - </widget> - </widget> - - <widget> - <class>GtkHButtonBox</class> - <child_name>GnomeDialog:action_area</child_name> - <name>dialog-action_area2</name> - <layout_style>GTK_BUTTONBOX_END</layout_style> - <spacing>0</spacing> - <child_min_width>85</child_min_width> - <child_min_height>27</child_min_height> - <child_ipad_x>7</child_ipad_x> - <child_ipad_y>0</child_ipad_y> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - <pack>GTK_PACK_END</pack> - </child> - - <widget> - <class>GtkButton</class> - <name>button12</name> - <can_default>True</can_default> - <can_focus>True</can_focus> - <stock_button>GNOME_STOCK_BUTTON_OK</stock_button> - </widget> - - <widget> - <class>GtkButton</class> - <name>button14</name> - <can_default>True</can_default> - <can_focus>True</can_focus> - <stock_button>GNOME_STOCK_BUTTON_CANCEL</stock_button> - </widget> - </widget> - </widget> -</widget> - -</GTK-Interface> diff --git a/widgets/table/e-table-config.glade.h b/widgets/table/e-table-config.glade.h deleted file mode 100644 index 4dc2ec8d31..0000000000 --- a/widgets/table/e-table-config.glade.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Translatable strings file generated by Glade. - * Add this file to your project's POTFILES.in. - * DO NOT compile it as part of your application. - */ - -gchar *s = N_("Fields"); -gchar *s = N_("Grouping"); -gchar *s = N_("Sort"); -gchar *s = N_("Filter"); diff --git a/widgets/table/e-table-config.h b/widgets/table/e-table-config.h deleted file mode 100644 index 617ef6a331..0000000000 --- a/widgets/table/e-table-config.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _E_TABLE_CONFIG_H -#define _E_TABLE_CONFIG_H - -GnomeDialog *e_table_gui_config (ETable *etable); -void e_table_do_gui_config (GtkWidget *, ETable *etable); - -void e_table_gui_config_accept (GtkWidget *widget, ETable *etable); -void e_table_gui_config_cancel (GtkWidget *widget, ETable *etable); - - -#endif /* _E_TABLE_CONFIG_H */ diff --git a/widgets/table/e-table-defines.h b/widgets/table/e-table-defines.h deleted file mode 100644 index 9bb9e107ac..0000000000 --- a/widgets/table/e-table-defines.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __E_TABLE_DEFINES__ -#define __E_TABLE_DEFINES__ 1 - -#define BUTTON_HEIGHT 10 -#define BUTTON_PADDING 2 -#define GROUP_INDENT (BUTTON_HEIGHT + (BUTTON_PADDING * 2)) - -/* Padding above and below of the string in the header display */ -#define HEADER_PADDING 2 - -#define MIN_ARROW_SIZE 10 - -typedef void (*ETableForeachFunc) (int model_row, - gpointer closure); - -#endif diff --git a/widgets/table/e-table-example-1.c b/widgets/table/e-table-example-1.c deleted file mode 100644 index 7c289778aa..0000000000 --- a/widgets/table/e-table-example-1.c +++ /dev/null @@ -1,287 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* This code is GPL. */ -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "e-util/e-cursors.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-cell-checkbox.h" -#include "e-table.h" - -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include "table-test.h" - -/* - * One way in which we make it simpler to build an ETableModel is through - * the ETableSimple class. Instead of creating your own ETableModel - * class, you simply create a new object of the ETableSimple class. You - * give it a bunch of functions that act as callbacks. - * - * You also get to pass a void * to ETableSimple and it gets passed to - * your callbacks. This would be for having multiple models of the same - * type. This is just an example though, so we statically define all the - * data and ignore the void *data parameter. - * - * In our example we will be creating a table model with 6 columns and 10 - * rows. This corresponds to having 6 different types of information and - * 10 different sets of data in our database. - * - * The headers will be hard coded, as will be the example data. - * - */ - -/* - * There are two different meanings to the word "column". The first is - * the model column. A model column corresponds to a specific type of - * data. This is very much like the usage in a database table where a - * column is a field in the database. - * - * The second type of column is a view column. A view column - * corresponds to a visually displayed column. Each view column - * corresponds to a specific model column, though a model column may - * have any number of view columns associated with it, from zero to - * greater than one. - * - * Also, a view column doesn't necessarily depend on only one model - * column. In some cases, the view column renderer can be given a - * reference to another column to get extra information about its - * display. -*/ - -#define ROWS 10 -#define COLS 4 - -#define IMPORTANCE_COLUMN 4 -#define COLOR_COLUMN 5 - -/* - * Here we define the initial layout of the table. This is an xml - * format that allows you to change the initial ordering of the - * columns or to do sorting or grouping initially. This specification - * shows all 5 columns, but moves the importance column nearer to the - * front. It also sorts by the "Full Name" column (ascending.) - * Sorting and grouping take the model column as their arguments - * (sorting is specified by the "column" argument to the leaf elemnt. - */ - -#define INITIAL_SPEC "<ETableSpecification> \ - <columns-shown> \ - <column> 0 </column> \ - <column> 4 </column> \ - <column> 1 </column> \ - <column> 2 </column> \ - <column> 3 </column> \ - </columns-shown> \ - <grouping> <leaf column=\"1\" ascending=\"1\"/> </grouping> \ -</ETableSpecification>" - -char *headers [COLS] = { - "Email", - "Full Name", - "Address", - "Phone" -}; - -/* - * Virtual Column list: - * 0 Email - * 1 Full Name - * 2 Address - * 3 Phone - */ - -char *table_data [ROWS] [COLS]; - -/* - * ETableSimple callbacks - * These are the callbacks that define the behavior of our custom model. - */ - -/* - * Since our model is a constant size, we can just return its size in - * the column and row count fields. - */ - -/* This function returns the number of columns in our ETableModel. */ -static int -my_col_count (ETableModel *etc, void *data) -{ - return COLS; -} - -/* This function returns the number of rows in our ETableModel. */ -static int -my_row_count (ETableModel *etc, void *data) -{ - return ROWS; -} - -/* This function returns the value at a particular point in our ETableModel. */ -static void * -my_value_at (ETableModel *etc, int col, int row, void *data) -{ - return (void *) table_data [row] [col]; -} - -/* This function sets the value at a particular point in our ETableModel. */ -static void -my_set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_free (table_data [row] [col]); - table_data [row] [col] = g_strdup (val); -} - -/* This function returns whether a particular cell is editable. */ -static gboolean -my_is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -/* This function duplicates the value passed to it. */ -static void * -my_duplicate_value (ETableModel *etc, int col, const void *value, void *data) -{ - return g_strdup (value); -} - -/* This function frees the value passed to it. */ -static void -my_free_value (ETableModel *etc, int col, void *value, void *data) -{ - g_free (value); -} - -/* This function creates an empty value. */ -static void * -my_initialize_value (ETableModel *etc, int col, void *data) -{ - return g_strdup (""); -} - -/* This function reports if a value is empty. */ -static gboolean -my_value_is_empty (ETableModel *etc, int col, const void *value, void *data) -{ - return !(value && *(char *)value); -} - -/* This function reports if a value is empty. */ -static char * -my_value_to_string (ETableModel *etc, int col, const void *value, void *data) -{ - return g_strdup(value); -} - -/* We create a window containing our new table. */ -static void -create_table (void) -{ - GtkWidget *e_table, *window, *frame; - ECell *cell_left_just; - ETableHeader *e_table_header; - int i, j; - ETableModel *e_table_model = NULL; - - /* First we fill in the simple data. */ - for (i = 0; i < ROWS; i++){ - for (j = 0; j < COLS; j++) - table_data [i] [j] = g_strdup (""); - } - /* Next we create our model. This uses the functions we defined - earlier. */ - e_table_model = e_table_simple_new ( - my_col_count, my_row_count, my_value_at, - my_set_value_at, my_is_cell_editable, - my_duplicate_value, my_free_value, - my_initialize_value, my_value_is_empty, - my_value_to_string, - NULL); - /* - * Next we create a header. The ETableHeader is used in two - * different way. The first is the full_header. This is the - * list of possible columns in the view. The second use is - * completely internal. Many of the ETableHeader functions are - * for that purpose. The only functions we really need are - * e_table_header_new and e_table_header_add_col. - * - * First we create the header. - */ - e_table_header = e_table_header_new (); - - /* - * Next we have to build renderers for all of the columns. - * Since all our columns are text columns, we can simply use - * the same renderer over and over again. If we had different - * types of columns, we could use a different renderer for - * each column. - */ - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - /* - * Next we create a column object for each view column and add - * them to the header. We don't create a column object for - * the importance column since it will not be shown. - */ - for (i = 0; i < COLS; i++) { - /* Create the column. */ - ETableCol *ecol = e_table_col_new ( - i, headers [i], - 1.0, 20, cell_left_just, - g_str_compare, TRUE); - /* Add it to the header. */ - e_table_header_add_column (e_table_header, ecol, i); - } - - /* - * Here we create a window for our new table. This window - * will get shown and the person will be able to test their - * item. - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - - /* This frame is simply to get a bevel around our table. */ - frame = gtk_frame_new (NULL); - - /* - * Here we create the table. We give it the three pieces of - * the table we've created, the header, the model, and the - * initial layout. It does the rest. - */ - e_table = e_table_new (e_table_header, e_table_model, INITIAL_SPEC); - - /* Build the gtk widget hierarchy. */ - gtk_container_add (GTK_CONTAINER (frame), e_table); - gtk_container_add (GTK_CONTAINER (window), frame); - - /* Size the initial window. */ - gtk_widget_set_usize (window, 200, 200); - - /* Show it all. */ - gtk_widget_show_all (window); -} - -/* This is the main function which just initializes gnome and call our create_table function */ - -int -main (int argc, char *argv []) -{ - gnome_init ("TableExample", "TableExample", argc, argv); - e_cursors_init (); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - create_table (); - - gtk_main (); - - e_cursors_shutdown (); - return 0; -} - diff --git a/widgets/table/e-table-example-2.c b/widgets/table/e-table-example-2.c deleted file mode 100644 index e9d8d9ea80..0000000000 --- a/widgets/table/e-table-example-2.c +++ /dev/null @@ -1,330 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* This code is GPL. */ -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "e-util/e-cursors.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-cell-checkbox.h" -#include "e-table.h" - -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include "table-test.h" - -/* -One way in which we make it simpler to build an ETableModel is through -the ETableSimple class. Instead of creating your own ETableModel -class, you simply create a new object of the ETableSimple class. You -give it a bunch of functions that act as callbacks. - -You also get to pass a void * to ETableSimple and it gets passed to -your callbacks. This would be for having multiple models of the same -type. This is just an example though, so we statically define all the -data and ignore the void *data parameter. - -In our example we will be creating a table model with 6 columns and 10 -rows. This corresponds to having 6 different types of information and -10 different sets of data in our database. - -The headers will be hard coded, as will be the example data. - -*/ - -/* - There are two different meanings to the word "column". The first is - the model column. A model column corresponds to a specific type of - data. This is very much like the usage in a database table where a - column is a field in the database. - - The second type of column is a view column. A view column - corresponds to a visually displayed column. Each view column - corresponds to a specific model column, though a model column may - have any number of view columns associated with it, from zero to - greater than one. - - Also, a view column doesn't necessarily depend on only one model - column. In some cases, the view column renderer can be given a - reference to another column to get extra information about its - display. -*/ - -#define ROWS 10 -#define VIEW_COLS 4 -#define PHYSICAL_COLS 5 -#define VIRTUAL_COLS 6 - -#define IMPORTANCE_COLUMN 4 -#define COLOR_COLUMN 5 - -/* Here we define the initial layout of the table. This is an xml - format that allows you to change the initial ordering of the - columns or to do sorting or grouping initially. This specification - shows all 5 columns, but moves the importance column nearer to the - front. It also sorts by the "Full Name" column (ascending.) - Sorting and grouping take the model column as their arguments - (sorting is specified by the "column" argument to the leaf elemnt. */ -#define INITIAL_SPEC "<ETableSpecification> \ - <columns-shown> \ - <column> 0 </column> \ - <column> 4 </column> \ - <column> 1 </column> \ - <column> 2 </column> \ - <column> 3 </column> \ - </columns-shown> \ - <grouping> <leaf column=\"1\" ascending=\"1\"/> </grouping> \ -</ETableSpecification>" - -char *headers[VIEW_COLS] = { - "Email", - "Full Name", - "Address", - "Phone" -}; - -/* Virtual Column list: - 0 Full Name - 1 Email - 2 Address - 3 Phone - 4 Importance field. This field will be a boolean. It also has a - special header, so doesn't appear in the headers list. - 5 Color field. This column is also not displayed. It is also - not stored in the database. It's calculated based on the - Importance field. -*/ - -char *table_data[ROWS][VIEW_COLS]; -gboolean importance_data[ROWS]; - -/* - * ETableSimple callbacks - * These are the callbacks that define the behavior of our custom model. - */ - -/* Since our model is a constant size, we can just return its size in - the column and row count fields. */ - -static GdkColor *color1; -static GdkColor *color2; - -static int -my_col_count (ETableModel *etc, void *data) -{ - return VIRTUAL_COLS; -} - -static int -my_row_count (ETableModel *etc, void *data) -{ - return ROWS; -} - -static void * -my_value_at (ETableModel *etc, int col, int row, void *data) -{ - if (col == COLOR_COLUMN){ - if (importance_data[row]){ - return color1; - } else { - return color2; - } - } else if (col == IMPORTANCE_COLUMN){ - return (gpointer) importance_data[row]; - } else { - return (void *) table_data [row][col]; - } -} - -static void -my_set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - if (col == COLOR_COLUMN){ - } else if (col == IMPORTANCE_COLUMN){ - importance_data[row] = (gboolean) val; - } else { - g_free (table_data [row][col]); - table_data [row][col] = g_strdup (val); - } -} - -static gboolean -my_is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - if (col == IMPORTANCE_COLUMN) - return FALSE; - else - return TRUE; -} - -static void * -my_duplicate_value (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == COLOR_COLUMN){ - return (void *) value; - } else if (col == IMPORTANCE_COLUMN){ - return (void *) value; - } else { - return g_strdup (value); - } -} - -static void -my_free_value (ETableModel *etc, int col, void *value, void *data) -{ - if (col == COLOR_COLUMN){ - } else if (col == IMPORTANCE_COLUMN){ - } else { - g_free (value); - } -} - -static void * -my_initialize_value (ETableModel *etc, int col, void *data) -{ - if (col == COLOR_COLUMN){ - return NULL; - } else if (col == IMPORTANCE_COLUMN){ - return NULL; - } else { - return g_strdup (""); - } -} - -static gboolean -my_value_is_empty (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == COLOR_COLUMN){ - return value == NULL; - } else if (col == IMPORTANCE_COLUMN){ - return value == NULL; - } else { - return !(value && *(char *)value); - } -} - -static char * -my_value_to_string (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == COLOR_COLUMN){ - return g_strdup_printf("%d", (int) value); - } else if (col == IMPORTANCE_COLUMN){ - return g_strdup_printf("%d", (int) value); - } else { - return g_strdup(value); - } -} - -/* We create a window containing our new table. */ -static void -create_table () -{ - GtkWidget *e_table, *window, *frame; - ECell *cell_left_just; - ECell *cell_checkbox; - ETableHeader *e_table_header; - int i, j; - ETableModel *e_table_model = NULL; - ETableCol *ecol; - GdkPixbuf *pixbuf; - - /* First we fill in the simple data. */ - for (i = 0; i < ROWS; i++){ - for (j = 0; j < VIEW_COLS; j++){ - table_data[i][j] = g_strdup (""); - } - importance_data[i] = FALSE; - } - /* Next we create our model. This uses the functions we defined - earlier. */ - e_table_model = e_table_simple_new ( - my_col_count, my_row_count, my_value_at, - my_set_value_at, my_is_cell_editable, - my_duplicate_value, my_free_value, - my_initialize_value, my_value_is_empty, - my_value_to_string, - NULL); - /* - Next we create a header. The ETableHeader is used in two - different way. The first is the full_header. This is the - list of possible columns in the view. The second use is - completely internal. Many of the ETableHeader functions are - for that purpose. The only functions we really need are - e_table_header_new and e_table_header_add_col. - - First we create the header. */ - e_table_header = e_table_header_new (); - - /* Next we have to build renderers for all of the columns. - Since all our columns are text columns, we can simply use - the same renderer over and over again. If we had different - types of columns, we could use a different renderer for - each column. */ - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - /* Next we create a column object for each view column and add - them to the header. We don't create a column object for - the importance column since it will not be shown. */ - for (i = 0; i < VIEW_COLS; i++){ - /* Create the column. */ - ETableCol *ecol = e_table_col_new ( - i, headers [i], - 1.0, 20, cell_left_just, - g_str_compare, TRUE); - /* Add it to the header. */ - e_table_header_add_column (e_table_header, ecol, i); - } - - /* Next we add a special column for the check box. */ - - cell_checkbox = e_cell_checkbox_new (); - pixbuf = gdk_pixbuf_new_from_file ("clip.png"); - ecol = e_table_col_new_with_pixbuf (i, pixbuf, 0.0, 18, cell_checkbox, g_int_compare, TRUE); - e_table_header_add_column (e_table_header, ecol, i); - - /* - * Setup GUI - */ - /* Here we create a window for our new table. This window - will get shown and the person will be able to test their - item. */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - /* This frame is simply to get a bevel around our table. */ - frame = gtk_frame_new (NULL); - /* Here we create the table. We give it the three pieces of - the table we've created, the header, the model, and the - initial layout. It does the rest. */ - e_table = e_table_new (e_table_header, e_table_model, INITIAL_SPEC); - - /* Build the gtk widget hierarchy. */ - gtk_container_add (GTK_CONTAINER (frame), e_table); - gtk_container_add (GTK_CONTAINER (window), frame); - - /* Size the initial window. */ - gtk_widget_set_usize (window, 200, 200); - /* Show it all. */ - gtk_widget_show_all (window); -} - - - -int -main (int argc, char *argv []) -{ - gnome_init ("TableExample", "TableExample", argc, argv); - e_cursors_init (); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - create_table (); - - gtk_main (); - - e_cursors_shutdown (); - return 0; -} diff --git a/widgets/table/e-table-field-chooser-dialog.c b/widgets/table/e-table-field-chooser-dialog.c deleted file mode 100644 index b54c57e80e..0000000000 --- a/widgets/table/e-table-field-chooser-dialog.c +++ /dev/null @@ -1,190 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-field-chooser-dialog.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <config.h> -#include <gnome.h> -#include <e-table-field-chooser-dialog.h> - -static void e_table_field_chooser_dialog_init (ETableFieldChooserDialog *card); -static void e_table_field_chooser_dialog_class_init (ETableFieldChooserDialogClass *klass); -static void e_table_field_chooser_dialog_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); -static void e_table_field_chooser_dialog_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_table_field_chooser_dialog_destroy (GtkObject *object); -static void e_table_field_chooser_dialog_clicked (GnomeDialog *dialog, gint button); - -static GnomeDialogClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0, - ARG_DND_CODE, - ARG_FULL_HEADER, -}; - -GtkType -e_table_field_chooser_dialog_get_type (void) -{ - static GtkType table_field_chooser_dialog_type = 0; - - if (!table_field_chooser_dialog_type) - { - static const GtkTypeInfo table_field_chooser_dialog_info = - { - "ETableFieldChooserDialog", - sizeof (ETableFieldChooserDialog), - sizeof (ETableFieldChooserDialogClass), - (GtkClassInitFunc) e_table_field_chooser_dialog_class_init, - (GtkObjectInitFunc) e_table_field_chooser_dialog_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - table_field_chooser_dialog_type = gtk_type_unique (gnome_dialog_get_type (), &table_field_chooser_dialog_info); - } - - return table_field_chooser_dialog_type; -} - -static void -e_table_field_chooser_dialog_class_init (ETableFieldChooserDialogClass *klass) -{ - GtkObjectClass *object_class; - GnomeDialogClass *dialog_class; - - object_class = (GtkObjectClass*) klass; - dialog_class = GNOME_DIALOG_CLASS (klass); - - parent_class = gtk_type_class (gnome_dialog_get_type ()); - - object_class->destroy = e_table_field_chooser_dialog_destroy; - object_class->set_arg = e_table_field_chooser_dialog_set_arg; - object_class->get_arg = e_table_field_chooser_dialog_get_arg; - - dialog_class->clicked = e_table_field_chooser_dialog_clicked; - - gtk_object_add_arg_type ("ETableFieldChooserDialog::dnd_code", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_DND_CODE); - gtk_object_add_arg_type ("ETableFieldChooserDialog::full_header", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_FULL_HEADER); -} - -static void -e_table_field_chooser_dialog_init (ETableFieldChooserDialog *e_table_field_chooser_dialog) -{ - GtkWidget *widget; - - e_table_field_chooser_dialog->etfc = NULL; - e_table_field_chooser_dialog->dnd_code = g_strdup(""); - e_table_field_chooser_dialog->full_header = NULL; - - gnome_dialog_append_buttons(GNOME_DIALOG(e_table_field_chooser_dialog), - GNOME_STOCK_BUTTON_CLOSE, - NULL); - - gtk_window_set_policy(GTK_WINDOW(e_table_field_chooser_dialog), FALSE, TRUE, FALSE); - - widget = e_table_field_chooser_new(); - e_table_field_chooser_dialog->etfc = E_TABLE_FIELD_CHOOSER(widget); - - gtk_object_set(GTK_OBJECT(widget), - "dnd_code", e_table_field_chooser_dialog->dnd_code, - "full_header", e_table_field_chooser_dialog->full_header, - NULL); - - gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(e_table_field_chooser_dialog)->vbox), - widget, TRUE, TRUE, 0); - - gtk_widget_show(GTK_WIDGET(widget)); -} - -GtkWidget* -e_table_field_chooser_dialog_new (void) -{ - GtkWidget *widget = GTK_WIDGET (gtk_type_new (e_table_field_chooser_dialog_get_type ())); - return widget; -} - -static void -e_table_field_chooser_dialog_destroy (GtkObject *object) -{ - ETableFieldChooserDialog *etfcd = E_TABLE_FIELD_CHOOSER_DIALOG (object); - g_free(etfcd->dnd_code); - if (etfcd->full_header) - gtk_object_unref(GTK_OBJECT(etfcd->full_header)); -} - -static void -e_table_field_chooser_dialog_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableFieldChooserDialog *etfcd = E_TABLE_FIELD_CHOOSER_DIALOG(object); - switch (arg_id){ - case ARG_DND_CODE: - g_free(etfcd->dnd_code); - etfcd->dnd_code = g_strdup(GTK_VALUE_STRING (*arg)); - if (etfcd->etfc) - gtk_object_set(GTK_OBJECT(etfcd->etfc), - "dnd_code", etfcd->dnd_code, - NULL); - break; - case ARG_FULL_HEADER: - if (etfcd->full_header) - gtk_object_unref(GTK_OBJECT(etfcd->full_header)); - if (GTK_VALUE_OBJECT(*arg)) - etfcd->full_header = E_TABLE_HEADER(GTK_VALUE_OBJECT(*arg)); - else - etfcd->full_header = NULL; - if (etfcd->full_header) - gtk_object_ref(GTK_OBJECT(etfcd->full_header)); - if (etfcd->etfc) - gtk_object_set(GTK_OBJECT(etfcd->etfc), - "full_header", etfcd->full_header, - NULL); - break; - default: - break; - } -} - -static void -e_table_field_chooser_dialog_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableFieldChooserDialog *etfcd = E_TABLE_FIELD_CHOOSER_DIALOG(object); - switch (arg_id) { - case ARG_DND_CODE: - GTK_VALUE_STRING (*arg) = g_strdup (etfcd->dnd_code); - break; - case ARG_FULL_HEADER: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etfcd->full_header); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -e_table_field_chooser_dialog_clicked (GnomeDialog *dialog, int button) -{ - if (button == 0) - gnome_dialog_close(dialog); -} diff --git a/widgets/table/e-table-field-chooser-dialog.h b/widgets/table/e-table-field-chooser-dialog.h deleted file mode 100644 index c209210dda..0000000000 --- a/widgets/table/e-table-field-chooser-dialog.h +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-table-field-chooser-dialog.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef __E_TABLE_FIELD_CHOOSER_DIALOG_H__ -#define __E_TABLE_FIELD_CHOOSER_DIALOG_H__ - -#include <gnome.h> -#include <glade/glade.h> -#include "e-table-field-chooser.h" -#include "e-table-header.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ETableFieldChooserDialog - A dialog displaying information about a contact. - * - * The following arguments are available: - * - * name type read/write description - * -------------------------------------------------------------------------------- - */ - -#define E_TABLE_FIELD_CHOOSER_DIALOG_TYPE (e_table_field_chooser_dialog_get_type ()) -#define E_TABLE_FIELD_CHOOSER_DIALOG(obj) (GTK_CHECK_CAST ((obj), E_TABLE_FIELD_CHOOSER_DIALOG_TYPE, ETableFieldChooserDialog)) -#define E_TABLE_FIELD_CHOOSER_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TABLE_FIELD_CHOOSER_DIALOG_TYPE, ETableFieldChooserDialogClass)) -#define E_IS_TABLE_FIELD_CHOOSER_DIALOG(obj) (GTK_CHECK_TYPE ((obj), E_TABLE_FIELD_CHOOSER_DIALOG_TYPE)) -#define E_IS_TABLE_FIELD_CHOOSER_DIALOG_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TABLE_FIELD_CHOOSER_DIALOG_TYPE)) - - -typedef struct _ETableFieldChooserDialog ETableFieldChooserDialog; -typedef struct _ETableFieldChooserDialogClass ETableFieldChooserDialogClass; - -struct _ETableFieldChooserDialog -{ - GnomeDialog parent; - - /* item specific fields */ - ETableFieldChooser *etfc; - gchar *dnd_code; - ETableHeader *full_header; -}; - -struct _ETableFieldChooserDialogClass -{ - GnomeDialogClass parent_class; -}; - - -GtkWidget *e_table_field_chooser_dialog_new(void); -GtkType e_table_field_chooser_dialog_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TABLE_FIELD_CHOOSER_DIALOG_H__ */ diff --git a/widgets/table/e-table-field-chooser-item.c b/widgets/table/e-table-field-chooser-item.c deleted file mode 100644 index e23fc4c9f5..0000000000 --- a/widgets/table/e-table-field-chooser-item.c +++ /dev/null @@ -1,566 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-column-view.c: A canvas item based view of the ETableColumn. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, 2000 Helix Code, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkdnd.h> -#include <libgnomeui/gnome-canvas.h> -#include <libgnomeui/gnome-canvas-util.h> -#include <libgnomeui/gnome-canvas-polygon.h> -#include <libgnomeui/gnome-canvas-rect-ellipse.h> -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include "e-util/e-xml-utils.h" -#include "e-util/e-canvas.h" - -#include "e-table-header.h" -#include "e-table-col-dnd.h" -#include "e-table-defines.h" - -#include "e-table-field-chooser-item.h" - -#if 0 -enum { - BUTTON_PRESSED, - LAST_SIGNAL -}; - -static guint etfci_signals [LAST_SIGNAL] = { 0, }; -#endif - -#define PARENT_OBJECT_TYPE gnome_canvas_item_get_type () - -#define ELEMENTS(x) (sizeof (x) / sizeof (x[0])) - -static GnomeCanvasItemClass *etfci_parent_class; - -static void etfci_drop_table_header (ETableFieldChooserItem *etfci); - -enum { - ARG_0, - ARG_FULL_HEADER, - ARG_DND_CODE, - ARG_WIDTH, - ARG_HEIGHT, -}; - -static void -etfci_destroy (GtkObject *object){ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (object); - - etfci_drop_table_header (etfci); - - gdk_font_unref(etfci->font); - - if (GTK_OBJECT_CLASS (etfci_parent_class)->destroy) - (*GTK_OBJECT_CLASS (etfci_parent_class)->destroy) (object); -} - -static void -etfci_reflow (GnomeCanvasItem *item, gint flags) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - double old_height; - - old_height = etfci->height; - - etfci->height = e_table_header_count (etfci->full_header) * etfci->button_height; - - if (old_height != etfci->height) - e_canvas_item_request_parent_reflow(item); - - gnome_canvas_item_request_update(item); -} - -static void -etfci_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - double i2c [6]; - ArtPoint c1, c2, i1, i2; - - if (GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)->update) - (*GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)->update)(item, affine, clip_path, flags); - - i1.x = i1.y = 0; - i2.x = etfci->width; - i2.y = etfci->height; - - gnome_canvas_item_i2c_affine (item, i2c); - art_affine_point (&c1, &i1, i2c); - art_affine_point (&c2, &i2, i2c); - - if (item->x1 != c1.x || - item->y1 != c1.y || - item->x2 != c2.x || - item->y2 != c2.y) - { - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); - item->x1 = c1.x; - item->y1 = c1.y; - item->x2 = c2.x; - item->y2 = c2.y; - - gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item); - } - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); -} - -static void -etfci_font_load (ETableFieldChooserItem *etfci, char *font) -{ - if (etfci->font) - gdk_font_unref (etfci->font); - etfci->font = NULL; - - if (font) - etfci->font = gdk_fontset_load (font); - - if (etfci->font == NULL) { - etfci->font = GTK_WIDGET(GNOME_CANVAS_ITEM(etfci)->canvas)->style->font; - gdk_font_ref(etfci->font); - } - - etfci->button_height = etfci->font->ascent + etfci->font->descent + HEADER_PADDING; -} - -static void -etfci_drop_table_header (ETableFieldChooserItem *etfci) -{ - GtkObject *header; - - if (!etfci->full_header) - return; - - header = GTK_OBJECT (etfci->full_header); - if (etfci->structure_change_id) - gtk_signal_disconnect (header, etfci->structure_change_id); - if (etfci->dimension_change_id) - gtk_signal_disconnect (header, etfci->dimension_change_id); - etfci->structure_change_id = 0; - etfci->dimension_change_id = 0; - - if (header) - gtk_object_unref (header); - etfci->full_header = NULL; - etfci->height = 0; - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(etfci)); -} - -static void -structure_changed (ETableHeader *header, ETableFieldChooserItem *etfci) -{ - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(etfci)); -} - -static void -dimension_changed (ETableHeader *header, int col, ETableFieldChooserItem *etfci) -{ - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(etfci)); -} - -static void -etfci_add_table_header (ETableFieldChooserItem *etfci, ETableHeader *header) -{ - etfci->full_header = header; - gtk_object_ref (GTK_OBJECT (etfci->full_header)); - - etfci->structure_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "structure_change", - GTK_SIGNAL_FUNC(structure_changed), etfci); - etfci->dimension_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "dimension_change", - GTK_SIGNAL_FUNC(dimension_changed), etfci); - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(etfci)); -} - -static void -etfci_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableFieldChooserItem *etfci; - - item = GNOME_CANVAS_ITEM (o); - etfci = E_TABLE_FIELD_CHOOSER_ITEM (o); - - switch (arg_id){ - case ARG_FULL_HEADER: - etfci_drop_table_header (etfci); - if (GTK_VALUE_OBJECT (*arg)) - etfci_add_table_header (etfci, E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg))); - break; - - case ARG_DND_CODE: - g_free(etfci->dnd_code); - etfci->dnd_code = g_strdup(GTK_VALUE_STRING (*arg)); - break; - - case ARG_WIDTH: - etfci->width = GTK_VALUE_DOUBLE (*arg); - gnome_canvas_item_request_update(item); - break; - } -} - -static void -etfci_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableFieldChooserItem *etfci; - - item = GNOME_CANVAS_ITEM (o); - etfci = E_TABLE_FIELD_CHOOSER_ITEM (o); - - switch (arg_id){ - - case ARG_DND_CODE: - GTK_VALUE_STRING (*arg) = g_strdup (etfci->dnd_code); - break; - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = etfci->width; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = etfci->height; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -etfci_drag_data_get (GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - ETableFieldChooserItem *etfci) -{ - if (etfci->drag_col != -1) { - gchar *string = g_strdup_printf("%d", etfci->drag_col); - gtk_selection_data_set(selection_data, - GDK_SELECTION_TYPE_STRING, - sizeof(string[0]), - string, - strlen(string)); - g_free(string); - } -} - -static void -etfci_drag_end (GtkWidget *canvas, - GdkDragContext *context, - ETableFieldChooserItem *etfci) -{ - etfci->drag_col = -1; -} - -static void -etfci_realize (GnomeCanvasItem *item) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - GdkWindow *window; - - if (GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)-> realize) - (*GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)->realize)(item); - - window = GTK_WIDGET (item->canvas)->window; - - if (!etfci->font) - etfci_font_load (etfci, NULL); - - etfci->drag_end_id = gtk_signal_connect ( - GTK_OBJECT (item->canvas), "drag_end", - GTK_SIGNAL_FUNC (etfci_drag_end), etfci); - etfci->drag_data_get_id = gtk_signal_connect ( - GTK_OBJECT (item->canvas), "drag_data_get", - GTK_SIGNAL_FUNC (etfci_drag_data_get), etfci); - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(etfci)); -} - -static void -etfci_unrealize (GnomeCanvasItem *item) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - - if (etfci->font) - gdk_font_unref (etfci->font); - etfci->font = NULL; - - gtk_signal_disconnect (GTK_OBJECT (item->canvas), etfci->drag_end_id); - etfci->drag_end_id = 0; - gtk_signal_disconnect (GTK_OBJECT (item->canvas), etfci->drag_data_get_id); - etfci->drag_data_get_id = 0; - - if (GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (etfci_parent_class)->unrealize)(item); -} - -static void -draw_button (ETableFieldChooserItem *etfci, ETableCol *col, - GdkDrawable *drawable, GtkStyle *style, - int x, int y, int width, int height) -{ - GdkRectangle clip; - int xtra; - GdkRectangle area; - - GtkWidget *widget = GTK_WIDGET(GNOME_CANVAS_ITEM(etfci)->canvas); - - gdk_window_clear_area (drawable, x, y, width, height); - - area.x = x; - area.y = y; - area.width = width; - area.height = height; - - gtk_paint_box (style, drawable, - GTK_STATE_NORMAL, GTK_SHADOW_OUT, - &area, widget, "button", - x, y, width, height); - - clip.x = x + HEADER_PADDING / 2; - clip.y = y + HEADER_PADDING / 2; - clip.width = width - HEADER_PADDING; - clip.height = etfci->button_height; - - if (col->is_pixbuf){ - xtra = (clip.width - gdk_pixbuf_get_width (col->pixbuf))/2; - - xtra += HEADER_PADDING / 2; - - gdk_pixbuf_render_to_drawable_alpha (col->pixbuf, - drawable, - 0, 0, - x + xtra, y + (clip.height - gdk_pixbuf_get_height (col->pixbuf)) / 2, - gdk_pixbuf_get_width (col->pixbuf), gdk_pixbuf_get_height(col->pixbuf), - GDK_PIXBUF_ALPHA_FULL, 128, - GDK_RGB_DITHER_NORMAL, - 0, 0); - } else { - /* Center the thing */ - xtra = (clip.width - gdk_string_measure (etfci->font, col->text))/2; - - /* Skip over border */ - if (xtra < 0) - xtra = 0; - - xtra += HEADER_PADDING / 2; - - gdk_draw_text ( - drawable, etfci->font, - style->text_gc[GTK_STATE_NORMAL], x + xtra, y + etfci->button_height - etfci->font->descent - HEADER_PADDING / 2, - col->text, strlen (col->text)); - } -} - -static void -etfci_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - const int rows = e_table_header_count (etfci->full_header); - int y1, y2; - int row; - - y1 = y2 = 0; - for (row = 0; row < rows; row++, y1 = y2){ - ETableCol *ecol = e_table_header_get_column (etfci->full_header, row); - - y2 += etfci->button_height; - - if (y1 > (y + height)) - break; - - if (y2 < y) - continue; - - draw_button (etfci, ecol, drawable, - GTK_WIDGET (canvas)->style, - - x, y1 - y, etfci->width, y2 - y1); - } -} - -static double -etfci_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - -static gboolean -etfci_maybe_start_drag (ETableFieldChooserItem *etfci, double x, double y) -{ - if (!etfci->maybe_drag) - return FALSE; - - if (MAX (abs (etfci->click_x - x), - abs (etfci->click_y - y)) <= 3) - return FALSE; - - return TRUE; -} - -static void -etfci_start_drag (ETableFieldChooserItem *etfci, GdkEvent *event, double x, double y) -{ - GtkWidget *widget = GTK_WIDGET (GNOME_CANVAS_ITEM (etfci)->canvas); - GtkTargetList *list; - GdkDragContext *context; - ETableCol *ecol; - GdkPixmap *pixmap; - int drag_col; - - GtkTargetEntry etfci_drag_types [] = { - { TARGET_ETABLE_COL_TYPE, 0, TARGET_ETABLE_COL_HEADER }, - }; - - drag_col = y / etfci->button_height; - - if (drag_col < 0 || drag_col > e_table_header_count(etfci->full_header)) - return; - - ecol = e_table_header_get_column (etfci->full_header, drag_col); - - etfci->drag_col = ecol->col_idx; - - etfci_drag_types[0].target = g_strdup_printf("%s-%s", etfci_drag_types[0].target, etfci->dnd_code); - list = gtk_target_list_new (etfci_drag_types, ELEMENTS (etfci_drag_types)); - context = gtk_drag_begin (widget, list, GDK_ACTION_MOVE, 1, event); - g_free(etfci_drag_types[0].target); - - - pixmap = gdk_pixmap_new (widget->window, etfci->width, etfci->button_height, -1); - draw_button (etfci, ecol, pixmap, - widget->style, - 0, 0, etfci->width, etfci->button_height); - gtk_drag_set_icon_pixmap (context, - gdk_window_get_colormap (widget->window), - pixmap, - NULL, - etfci->width / 2, - etfci->button_height / 2); - gdk_pixmap_unref (pixmap); - etfci->maybe_drag = FALSE; -} - -/* - * Handles the events on the ETableFieldChooserItem - */ -static int -etfci_event (GnomeCanvasItem *item, GdkEvent *e) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - int x, y; - - switch (e->type){ - case GDK_MOTION_NOTIFY: - gnome_canvas_w2c (canvas, e->motion.x, e->motion.y, &x, &y); - - if (etfci_maybe_start_drag (etfci, x, y)) - etfci_start_drag (etfci, e, x, y); - break; - - case GDK_BUTTON_PRESS: - gnome_canvas_w2c (canvas, e->button.x, e->button.y, &x, &y); - - if (e->button.button == 1){ - etfci->click_x = x; - etfci->click_y = y; - etfci->maybe_drag = TRUE; - } - break; - - case GDK_BUTTON_RELEASE: { - etfci->maybe_drag = FALSE; - break; - } - - default: - return FALSE; - } - return TRUE; -} - -static void -etfci_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - - etfci_parent_class = gtk_type_class (PARENT_OBJECT_TYPE); - - object_class->destroy = etfci_destroy; - object_class->set_arg = etfci_set_arg; - object_class->get_arg = etfci_get_arg; - - item_class->update = etfci_update; - item_class->realize = etfci_realize; - item_class->unrealize = etfci_unrealize; - item_class->draw = etfci_draw; - item_class->point = etfci_point; - item_class->event = etfci_event; - - gtk_object_add_arg_type ("ETableFieldChooserItem::dnd_code", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_DND_CODE); - gtk_object_add_arg_type ("ETableFieldChooserItem::full_header", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_FULL_HEADER); - gtk_object_add_arg_type ("ETableFieldChooserItem::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ETableFieldChooserItem::height", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_HEIGHT); -} - -static void -etfci_init (GnomeCanvasItem *item) -{ - ETableFieldChooserItem *etfci = E_TABLE_FIELD_CHOOSER_ITEM (item); - - etfci->full_header = NULL; - - etfci->height = etfci->width = 0; - etfci->button_height = 0; - - etfci->font = NULL; - - etfci->structure_change_id = 0; - etfci->dimension_change_id = 0; - - etfci->dnd_code = NULL; - - etfci->maybe_drag = 0; - etfci->drag_end_id = 0; - - e_canvas_item_set_reflow_callback(item, etfci_reflow); -} - -GtkType -e_table_field_chooser_item_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableFieldChooserItem", - sizeof (ETableFieldChooserItem), - sizeof (ETableFieldChooserItemClass), - (GtkClassInitFunc) etfci_class_init, - (GtkObjectInitFunc) etfci_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_OBJECT_TYPE, &info); - } - - return type; -} - diff --git a/widgets/table/e-table-field-chooser-item.h b/widgets/table/e-table-field-chooser-item.h deleted file mode 100644 index 4b349f40e3..0000000000 --- a/widgets/table/e-table-field-chooser-item.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_FIELD_CHOOSER_ITEM_H_ -#define _E_TABLE_FIELD_CHOOSER_ITEM_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gnome-xml/tree.h> -#include "e-table-header.h" - -#define E_TABLE_FIELD_CHOOSER_ITEM_TYPE (e_table_field_chooser_item_get_type ()) -#define E_TABLE_FIELD_CHOOSER_ITEM(o) (GTK_CHECK_CAST ((o), E_TABLE_FIELD_CHOOSER_ITEM_TYPE, ETableFieldChooserItem)) -#define E_TABLE_FIELD_CHOOSER_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_FIELD_CHOOSER_ITEM_TYPE, ETableFieldChooserItemClass)) -#define E_IS_TABLE_FIELD_CHOOSER_ITEM(o) (GTK_CHECK_TYPE ((o), E_TABLE_FIELD_CHOOSER_ITEM_TYPE)) -#define E_IS_TABLE_FIELD_CHOOSER_ITEM_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_FIELD_CHOOSER_ITEM_TYPE)) - -typedef struct { - GnomeCanvasItem parent; - ETableHeader *full_header; - - double height, width; - double button_height; - - GdkFont *font; - - /* - * Ids - */ - int structure_change_id, dimension_change_id; - - gchar *dnd_code; - - /* - * For dragging columns - */ - guint maybe_drag:1; - int click_x, click_y; - int drag_col; - guint drag_data_get_id; - guint drag_end_id; -} ETableFieldChooserItem; - -typedef struct { - GnomeCanvasItemClass parent_class; -} ETableFieldChooserItemClass; - -GtkType e_table_field_chooser_item_get_type (void); - -#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 0d56945f7f..0000000000 --- a/widgets/table/e-table-field-chooser.c +++ /dev/null @@ -1,246 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-field-chooser.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <config.h> -#include <gnome.h> -#include <e-table-field-chooser.h> -#include <e-table-field-chooser-item.h> - -static void e_table_field_chooser_init (ETableFieldChooser *card); -static void e_table_field_chooser_class_init (ETableFieldChooserClass *klass); -static void e_table_field_chooser_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); -static void e_table_field_chooser_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_table_field_chooser_destroy (GtkObject *object); - -static GtkVBoxClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0, - ARG_FULL_HEADER, - ARG_DND_CODE, -}; - -GtkType -e_table_field_chooser_get_type (void) -{ - static GtkType table_field_chooser_type = 0; - - if (!table_field_chooser_type) - { - static const GtkTypeInfo table_field_chooser_info = - { - "ETableFieldChooser", - sizeof (ETableFieldChooser), - sizeof (ETableFieldChooserClass), - (GtkClassInitFunc) e_table_field_chooser_class_init, - (GtkObjectInitFunc) e_table_field_chooser_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - table_field_chooser_type = gtk_type_unique (gtk_vbox_get_type (), &table_field_chooser_info); - } - - return table_field_chooser_type; -} - -static void -e_table_field_chooser_class_init (ETableFieldChooserClass *klass) -{ - GtkObjectClass *object_class; - GtkVBoxClass *vbox_class; - - object_class = (GtkObjectClass*) klass; - vbox_class = (GtkVBoxClass *) klass; - - parent_class = gtk_type_class (gtk_vbox_get_type ()); - - object_class->set_arg = e_table_field_chooser_set_arg; - object_class->get_arg = e_table_field_chooser_get_arg; - object_class->destroy = e_table_field_chooser_destroy; - gtk_object_add_arg_type ("ETableFieldChooser::dnd_code", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_DND_CODE); - gtk_object_add_arg_type ("ETableFieldChooser::full_header", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_FULL_HEADER); -} - -static void allocate_callback(GtkWidget *canvas, GtkAllocation *allocation, ETableFieldChooser *etfc) -{ - double height; - etfc->last_alloc = *allocation; - gnome_canvas_item_set( etfc->item, - "width", (double) allocation->width, - NULL ); - gtk_object_get(GTK_OBJECT(etfc->item), - "height", &height, - NULL); - height = MAX(height, allocation->height); - gnome_canvas_set_scroll_region(GNOME_CANVAS( etfc->canvas ), 0, 0, allocation->width - 1, height - 1); - gnome_canvas_item_set( etfc->rect, - "x2", (double) allocation->width, - "y2", (double) height, - NULL ); -} - -static void resize(GnomeCanvas *canvas, ETableFieldChooser *etfc) -{ - double height; - gtk_object_get(GTK_OBJECT(etfc->item), - "height", &height, - NULL); - - height = MAX(height, etfc->last_alloc.height); - - gnome_canvas_set_scroll_region (GNOME_CANVAS(etfc->canvas), 0, 0, etfc->last_alloc.width - 1, height - 1); - gnome_canvas_item_set( etfc->rect, - "x2", (double) etfc->last_alloc.width, - "y2", (double) height, - NULL ); -} - -static void -e_table_field_chooser_init (ETableFieldChooser *etfc) -{ - GladeXML *gui; - GtkWidget *widget; - - gui = glade_xml_new (ETABLE_GLADEDIR "/e-table-field-chooser.glade", NULL); - etfc->gui = gui; - - widget = glade_xml_get_widget(gui, "vbox-top"); - if (!widget) { - return; - } - gtk_widget_reparent(widget, - GTK_WIDGET(etfc)); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - etfc->canvas = GNOME_CANVAS(glade_xml_get_widget(gui, "canvas-buttons")); - - etfc->rect = gnome_canvas_item_new(gnome_canvas_root( GNOME_CANVAS( etfc->canvas ) ), - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) 100, - "y2", (double) 100, - "fill_color", "white", - NULL ); - - etfc->item = gnome_canvas_item_new(gnome_canvas_root(etfc->canvas), - e_table_field_chooser_item_get_type(), - "width", (double) 100, - "full_header", etfc->full_header, - "dnd_code", etfc->dnd_code, - NULL ); - - gtk_signal_connect( GTK_OBJECT( etfc->canvas ), "reflow", - GTK_SIGNAL_FUNC( resize ), - etfc); - - gnome_canvas_set_scroll_region ( GNOME_CANVAS( etfc->canvas ), - 0, 0, - 100, 100 ); - - /* Connect the signals */ - gtk_signal_connect (GTK_OBJECT (etfc->canvas), "size_allocate", - GTK_SIGNAL_FUNC (allocate_callback), - etfc); - - gtk_widget_pop_visual (); - gtk_widget_pop_colormap (); - gtk_widget_show(widget); -} - -static void -e_table_field_chooser_destroy (GtkObject *object) -{ - ETableFieldChooser *etfc = E_TABLE_FIELD_CHOOSER(object); - - g_free(etfc->dnd_code); - if (etfc->full_header) - gtk_object_unref(GTK_OBJECT(etfc->full_header)); - - if (etfc->gui) - gtk_object_unref(GTK_OBJECT(etfc->gui)); -} - -GtkWidget* -e_table_field_chooser_new (void) -{ - GtkWidget *widget = GTK_WIDGET (gtk_type_new (e_table_field_chooser_get_type ())); - return widget; -} - -static void -e_table_field_chooser_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableFieldChooser *etfc = E_TABLE_FIELD_CHOOSER(object); - - switch (arg_id){ - case ARG_DND_CODE: - g_free(etfc->dnd_code); - etfc->dnd_code = g_strdup(GTK_VALUE_STRING (*arg)); - if (etfc->item) - gtk_object_set(GTK_OBJECT(etfc->item), - "dnd_code", etfc->dnd_code, - NULL); - break; - case ARG_FULL_HEADER: - if (etfc->full_header) - gtk_object_unref(GTK_OBJECT(etfc->full_header)); - if (GTK_VALUE_OBJECT(*arg)) - etfc->full_header = E_TABLE_HEADER(GTK_VALUE_OBJECT(*arg)); - else - etfc->full_header = NULL; - if (etfc->full_header) - gtk_object_ref(GTK_OBJECT(etfc->full_header)); - if (etfc->item) - gtk_object_set(GTK_OBJECT(etfc->item), - "full_header", etfc->full_header, - NULL); - break; - default: - break; - } -} - -static void -e_table_field_chooser_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableFieldChooser *etfc = E_TABLE_FIELD_CHOOSER(object); - - switch (arg_id) { - case ARG_DND_CODE: - GTK_VALUE_STRING (*arg) = g_strdup (etfc->dnd_code); - break; - case ARG_FULL_HEADER: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etfc->full_header); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} diff --git a/widgets/table/e-table-field-chooser.glade b/widgets/table/e-table-field-chooser.glade deleted file mode 100644 index a5cd37c2df..0000000000 --- a/widgets/table/e-table-field-chooser.glade +++ /dev/null @@ -1,131 +0,0 @@ -<?xml version="1.0"?> -<GTK-Interface> - -<project> - <name>e-table-field-chooser</name> - <program_name>e-table-field-chooser</program_name> - <directory></directory> - <source_directory>src</source_directory> - <pixmaps_directory>pixmaps</pixmaps_directory> - <language>C</language> - <gnome_support>True</gnome_support> - <gettext_support>True</gettext_support> - <use_widget_names>True</use_widget_names> - <output_main_file>False</output_main_file> - <output_support_files>False</output_support_files> - <output_build_files>False</output_build_files> - <gnome_help_support>True</gnome_help_support> - <output_translatable_strings>True</output_translatable_strings> - <translatable_strings_file>e-table-field-chooser.glade.h</translatable_strings_file> -</project> - -<widget> - <class>GnomeDialog</class> - <name>dialog-field-chooser</name> - <visible>False</visible> - <title>Field Chooser</title> - <type>GTK_WINDOW_TOPLEVEL</type> - <position>GTK_WIN_POS_NONE</position> - <modal>False</modal> - <allow_shrink>False</allow_shrink> - <allow_grow>True</allow_grow> - <auto_shrink>False</auto_shrink> - <auto_close>False</auto_close> - <hide_on_close>False</hide_on_close> - - <widget> - <class>GtkVBox</class> - <child_name>GnomeDialog:vbox</child_name> - <name>dialog-vbox1</name> - <homogeneous>False</homogeneous> - <spacing>8</spacing> - <child> - <padding>4</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkHButtonBox</class> - <child_name>GnomeDialog:action_area</child_name> - <name>dialog-action_area1</name> - <layout_style>GTK_BUTTONBOX_END</layout_style> - <spacing>8</spacing> - <child_min_width>85</child_min_width> - <child_min_height>27</child_min_height> - <child_ipad_x>7</child_ipad_x> - <child_ipad_y>0</child_ipad_y> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>True</fill> - <pack>GTK_PACK_END</pack> - </child> - - <widget> - <class>GtkButton</class> - <name>button3</name> - <can_default>True</can_default> - <can_focus>True</can_focus> - <stock_button>GNOME_STOCK_BUTTON_CLOSE</stock_button> - </widget> - </widget> - - <widget> - <class>GtkVBox</class> - <name>vbox-top</name> - <homogeneous>False</homogeneous> - <spacing>4</spacing> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>GtkLabel</class> - <name>label1</name> - <label>To add a column to your table, drag it into -the location in which you want it to appear.</label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkScrolledWindow</class> - <name>scrolledwindow1</name> - <width>200</width> - <height>200</height> - <hscrollbar_policy>GTK_POLICY_AUTOMATIC</hscrollbar_policy> - <vscrollbar_policy>GTK_POLICY_AUTOMATIC</vscrollbar_policy> - <hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy> - <vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy> - <child> - <padding>0</padding> - <expand>True</expand> - <fill>True</fill> - </child> - - <widget> - <class>Custom</class> - <name>canvas-buttons</name> - <creation_function>e_canvas_new</creation_function> - <int1>0</int1> - <int2>0</int2> - <last_modification_time>Thu, 08 Jun 2000 07:27:33 GMT</last_modification_time> - </widget> - </widget> - </widget> - </widget> -</widget> - -</GTK-Interface> diff --git a/widgets/table/e-table-field-chooser.glade.h b/widgets/table/e-table-field-chooser.glade.h deleted file mode 100644 index a36bd6052c..0000000000 --- a/widgets/table/e-table-field-chooser.glade.h +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Translatable strings file generated by Glade. - * Add this file to your project's POTFILES.in. - * DO NOT compile it as part of your application. - */ - -gchar *s = N_("Field Chooser"); -gchar *s = N_("To add a column to your table, drag it into\n" - "the location in which you want it to appear."); diff --git a/widgets/table/e-table-field-chooser.h b/widgets/table/e-table-field-chooser.h deleted file mode 100644 index d84aafdc63..0000000000 --- a/widgets/table/e-table-field-chooser.h +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-contact-editor-fullname.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef __E_TABLE_FIELD_CHOOSER_H__ -#define __E_TABLE_FIELD_CHOOSER_H__ - -#include <gnome.h> -#include <glade/glade.h> -#include "e-table-header.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ETableFieldChooser - A dialog displaying information about a contact. - * - * The following arguments are available: - * - * name type read/write description - * -------------------------------------------------------------------------------- - */ - -#define E_TABLE_FIELD_CHOOSER_TYPE (e_table_field_chooser_get_type ()) -#define E_TABLE_FIELD_CHOOSER(obj) (GTK_CHECK_CAST ((obj), E_TABLE_FIELD_CHOOSER_TYPE, ETableFieldChooser)) -#define E_TABLE_FIELD_CHOOSER_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TABLE_FIELD_CHOOSER_TYPE, ETableFieldChooserClass)) -#define E_IS_TABLE_FIELD_CHOOSER(obj) (GTK_CHECK_TYPE ((obj), E_TABLE_FIELD_CHOOSER_TYPE)) -#define E_IS_TABLE_FIELD_CHOOSER_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TABLE_FIELD_CHOOSER_TYPE)) - - -typedef struct _ETableFieldChooser ETableFieldChooser; -typedef struct _ETableFieldChooserClass ETableFieldChooserClass; - -struct _ETableFieldChooser -{ - GtkVBox parent; - - /* item specific fields */ - GladeXML *gui; - GnomeCanvas *canvas; - GnomeCanvasItem *item; - - GnomeCanvasItem *rect; - GtkAllocation last_alloc; - - gchar *dnd_code; - ETableHeader *full_header; -}; - -struct _ETableFieldChooserClass -{ - GtkVBoxClass parent_class; -}; - - -GtkWidget *e_table_field_chooser_new(void); -GtkType e_table_field_chooser_get_type (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TABLE_FIELD_CHOOSER_H__ */ diff --git a/widgets/table/e-table-group-container.c b/widgets/table/e-table-group-container.c deleted file mode 100644 index 3a68bc044b..0000000000 --- a/widgets/table/e-table-group-container.c +++ /dev/null @@ -1,1169 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-Table-Group.c: Implements the grouping objects for elements on a table - * - * Author: - * Chris Lahey <clahey@helixcode.com> - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, 2000 Helix Code, Inc. - */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-table-group-container.h" -#include "e-table-group-leaf.h" -#include "e-table-item.h" -#include <libgnomeui/gnome-canvas-rect-ellipse.h> -#include "e-util/e-util.h" -#include "e-util/e-canvas.h" -#include "e-util/e-canvas-utils.h" -#include "widgets/e-text/e-text.h" -#include "e-table-defines.h" - -#define TITLE_HEIGHT 16 - -#define PARENT_TYPE e_table_group_get_type () - -static GnomeCanvasGroupClass *etgc_parent_class; - -/* The arguments we take */ -enum { - ARG_0, - ARG_HEIGHT, - ARG_WIDTH, - ARG_MINIMUM_WIDTH, - ARG_FROZEN, - ARG_TABLE_DRAW_GRID, - ARG_TABLE_DRAW_FOCUS, - ARG_CURSOR_MODE, - ARG_TABLE_SELECTION_MODEL, - ARG_LENGTH_THRESHOLD, -}; - -typedef struct { - ETableGroup *child; - void *key; - char *string; - GnomeCanvasItem *text; - GnomeCanvasItem *rect; - gint count; -} ETableGroupContainerChildNode; - -static EPrintable * -etgc_get_printable (ETableGroup *etg); - - -static void -e_table_group_container_child_node_free (ETableGroupContainer *etgc, - ETableGroupContainerChildNode *child_node) -{ - ETableGroup *etg = E_TABLE_GROUP (etgc); - ETableGroup *child = child_node->child; - - gtk_object_destroy (GTK_OBJECT (child)); - e_table_model_free_value (etg->model, etgc->ecol->col_idx, - child_node->key); - g_free(child_node->string); - gtk_object_destroy (GTK_OBJECT (child_node->text)); - gtk_object_destroy (GTK_OBJECT (child_node->rect)); -} - -static void -e_table_group_container_list_free (ETableGroupContainer *etgc) -{ - ETableGroupContainerChildNode *child_node; - GList *list; - - for (list = etgc->children; list; list = g_list_next (list)) { - child_node = (ETableGroupContainerChildNode *) list->data; - e_table_group_container_child_node_free (etgc, child_node); - } - - g_list_free (etgc->children); -} - -static void -etgc_destroy (GtkObject *object) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (object); - - if (etgc->font) - gdk_font_unref (etgc->font); - etgc->font = NULL; - - if (etgc->ecol) - gtk_object_unref (GTK_OBJECT(etgc->ecol)); - - if (etgc->sort_info) - gtk_object_unref (GTK_OBJECT(etgc->sort_info)); - - if (etgc->table_selection_model) - gtk_object_unref (GTK_OBJECT(etgc->table_selection_model)); - - if (etgc->rect) - gtk_object_destroy (GTK_OBJECT(etgc->rect)); - - e_table_group_container_list_free (etgc); - - GTK_OBJECT_CLASS (etgc_parent_class)->destroy (object); -} - -void -e_table_group_container_construct (GnomeCanvasGroup *parent, ETableGroupContainer *etgc, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, ETableSortInfo *sort_info, int n) -{ - ETableCol *col; - ETableSortColumn column = e_table_sort_info_grouping_get_nth(sort_info, n); - - if (column.column > e_table_header_count (full_header)) - col = e_table_header_get_column (full_header, e_table_header_count (full_header) - 1); - else - col = e_table_header_get_column (full_header, column.column); - - e_table_group_construct (parent, E_TABLE_GROUP (etgc), full_header, header, model); - etgc->ecol = col; - gtk_object_ref (GTK_OBJECT(etgc->ecol)); - etgc->sort_info = sort_info; - gtk_object_ref (GTK_OBJECT(etgc->sort_info)); - etgc->n = n; - etgc->ascending = column.ascending; - - - etgc->font = gdk_font_load ("lucidasans-10"); - if (!etgc->font){ - etgc->font = GTK_WIDGET (GNOME_CANVAS_ITEM (etgc)->canvas)->style->font; - - gdk_font_ref (etgc->font); - } - etgc->open = TRUE; -} - -ETableGroup * -e_table_group_container_new (GnomeCanvasGroup *parent, ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, ETableSortInfo *sort_info, int n) -{ - ETableGroupContainer *etgc; - - g_return_val_if_fail (parent != NULL, NULL); - - etgc = gtk_type_new (e_table_group_container_get_type ()); - - e_table_group_container_construct (parent, etgc, full_header, header, - model, sort_info, n); - return E_TABLE_GROUP (etgc); -} - - -static int -etgc_event (GnomeCanvasItem *item, GdkEvent *event) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(item); - gboolean return_val = TRUE; - gboolean change_focus = FALSE; - gboolean use_col = FALSE; - gint start_col = 0; - gint old_col; - EFocus direction = E_FOCUS_START; - - switch (event->type) { - case GDK_KEY_PRESS: - if (event->key.keyval == GDK_Tab || - event->key.keyval == GDK_KP_Tab || - event->key.keyval == GDK_ISO_Left_Tab) { - change_focus = TRUE; - use_col = TRUE; - start_col = (event->key.state & GDK_SHIFT_MASK) ? -1 : 0; - direction = (event->key.state & GDK_SHIFT_MASK) ? E_FOCUS_END : E_FOCUS_START; - } else if (event->key.keyval == GDK_Left || - event->key.keyval == GDK_KP_Left) { - change_focus = TRUE; - use_col = TRUE; - start_col = -1; - direction = E_FOCUS_END; - } else if (event->key.keyval == GDK_Right || - event->key.keyval == GDK_KP_Right) { - change_focus = TRUE; - use_col = TRUE; - start_col = 0; - direction = E_FOCUS_START; - } else if (event->key.keyval == GDK_Down || - event->key.keyval == GDK_KP_Down) { - change_focus = TRUE; - use_col = FALSE; - direction = E_FOCUS_START; - } else if (event->key.keyval == GDK_Up || - event->key.keyval == GDK_KP_Up) { - change_focus = TRUE; - use_col = FALSE; - direction = E_FOCUS_END; - } else if (event->key.keyval == GDK_Return || - event->key.keyval == GDK_KP_Enter) { - change_focus = TRUE; - use_col = FALSE; - direction = E_FOCUS_START; - } - if (change_focus){ - GList *list; - for (list = etgc->children; list; list = list->next) { - ETableGroupContainerChildNode *child_node; - ETableGroup *child; - - child_node = (ETableGroupContainerChildNode *)list->data; - child = child_node->child; - - if (e_table_group_get_focus (child)) { - old_col = e_table_group_get_focus_column (child); - if (old_col == -1) - old_col = 0; - if (start_col == -1) - start_col = e_table_header_count (e_table_group_get_header (child)) - 1; - - if (direction == E_FOCUS_END) - list = list->prev; - else - list = list->next; - - if (list) { - child_node = (ETableGroupContainerChildNode *)list->data; - child = child_node->child; - if (use_col) - e_table_group_set_focus (child, direction, start_col); - else - e_table_group_set_focus (child, direction, old_col); - return 1; - } else { - return 0; - } - } - } - if (direction == E_FOCUS_END) - list = g_list_last(etgc->children); - else - list = etgc->children; - if (list) { - ETableGroupContainerChildNode *child_node; - ETableGroup *child; - - child_node = (ETableGroupContainerChildNode *)list->data; - child = child_node->child; - - if (start_col == -1) - start_col = e_table_header_count (e_table_group_get_header (child)) - 1; - - e_table_group_set_focus (child, direction, start_col); - return 1; - } - } - return_val = FALSE; - break; - default: - return_val = FALSE; - break; - } - if (return_val == FALSE) { - if (GNOME_CANVAS_ITEM_CLASS(etgc_parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS (etgc_parent_class)->event (item, event); - } - return return_val; - -} - -/* Realize handler for the text item */ -static void -etgc_realize (GnomeCanvasItem *item) -{ - ETableGroupContainer *etgc; - - if (GNOME_CANVAS_ITEM_CLASS (etgc_parent_class)->realize) - (* GNOME_CANVAS_ITEM_CLASS (etgc_parent_class)->realize) (item); - - etgc = E_TABLE_GROUP_CONTAINER (item); - - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etgc)); -} - -/* Unrealize handler for the etgc item */ -static void -etgc_unrealize (GnomeCanvasItem *item) -{ - ETableGroupContainer *etgc; - - etgc = E_TABLE_GROUP_CONTAINER (item); - - if (GNOME_CANVAS_ITEM_CLASS (etgc_parent_class)->unrealize) - (* GNOME_CANVAS_ITEM_CLASS (etgc_parent_class)->unrealize) (item); -} - -static void -compute_text (ETableGroupContainer *etgc, ETableGroupContainerChildNode *child_node) -{ - gchar *text; - if (etgc->ecol->text) - text = g_strdup_printf ("%s : %s (%d item%s)", - etgc->ecol->text, - child_node->string, - (gint) child_node->count, - child_node->count == 1 ? "" : "s"); - else - text = g_strdup_printf ("%s (%d item%s)", - child_node->string, - (gint) child_node->count, - child_node->count == 1 ? "" : "s"); - gnome_canvas_item_set (child_node->text, - "text", text, - NULL); - g_free (text); -} - -static void -child_cursor_change (ETableGroup *etg, int row, - ETableGroupContainer *etgc) -{ - e_table_group_cursor_change (E_TABLE_GROUP (etgc), row); -} - -static void -child_double_click (ETableGroup *etg, int row, - ETableGroupContainer *etgc) -{ - e_table_group_double_click (E_TABLE_GROUP (etgc), row); -} - -static gint -child_right_click (ETableGroup *etg, int row, int col, GdkEvent *event, - ETableGroupContainer *etgc) -{ - return e_table_group_right_click (E_TABLE_GROUP (etgc), row, col, event); -} - -static gint -child_key_press (ETableGroup *etg, int row, int col, GdkEvent *event, - ETableGroupContainer *etgc) -{ - return e_table_group_key_press (E_TABLE_GROUP (etgc), row, col, event); -} - -static void -etgc_add (ETableGroup *etg, gint row) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (etg); - void *val = e_table_model_value_at (etg->model, etgc->ecol->col_idx, row); - GCompareFunc comp = etgc->ecol->compare; - GList *list = etgc->children; - ETableGroup *child; - ETableGroupContainerChildNode *child_node; - int i = 0; - - for (; list; list = g_list_next (list), i++){ - int comp_val; - - child_node = list->data; - comp_val = (*comp)(child_node->key, val); - if (comp_val == 0) { - child = child_node->child; - child_node->count ++; - e_table_group_add (child, row); - compute_text (etgc, child_node); - return; - } - if ((comp_val > 0 && etgc->ascending) || - (comp_val < 0 && (!etgc->ascending))) - break; - } - child_node = g_new (ETableGroupContainerChildNode, 1); - child_node->rect = gnome_canvas_item_new (GNOME_CANVAS_GROUP (etgc), - gnome_canvas_rect_get_type (), - "fill_color", "grey70", - "outline_color", "grey50", - NULL); - child_node->text = gnome_canvas_item_new (GNOME_CANVAS_GROUP (etgc), - e_text_get_type (), - "font_gdk", etgc->font, - "anchor", GTK_ANCHOR_SW, - "fill_color", "black", - NULL); - child = e_table_group_new (GNOME_CANVAS_GROUP (etgc), etg->full_header, - etg->header, etg->model, etgc->sort_info, etgc->n + 1); - gnome_canvas_item_set(GNOME_CANVAS_ITEM(child), - "drawgrid", etgc->draw_grid, - "drawfocus", etgc->draw_focus, - "cursor_mode", etgc->cursor_mode, - "table_selection_model", etgc->table_selection_model, - "length_threshold", etgc->length_threshold, - NULL); - gtk_signal_connect (GTK_OBJECT (child), "cursor_change", - GTK_SIGNAL_FUNC (child_cursor_change), etgc); - gtk_signal_connect (GTK_OBJECT (child), "double_click", - GTK_SIGNAL_FUNC (child_double_click), etgc); - gtk_signal_connect (GTK_OBJECT (child), "right_click", - GTK_SIGNAL_FUNC (child_right_click), etgc); - gtk_signal_connect (GTK_OBJECT (child), "key_press", - GTK_SIGNAL_FUNC (child_key_press), etgc); - child_node->child = child; - child_node->key = e_table_model_duplicate_value (etg->model, etgc->ecol->col_idx, val); - child_node->string = e_table_model_value_to_string (etg->model, etgc->ecol->col_idx, val); - child_node->count = 1; - e_table_group_add (child, row); - - if (list) - etgc->children = g_list_insert (etgc->children, child_node, i); - else - etgc->children = g_list_append (etgc->children, child_node); - - compute_text (etgc, child_node); - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etgc)); -} - -static void -etgc_add_all (ETableGroup *etg) -{ - int rows = e_table_model_row_count(etg->model); - int i; - for (i = 0; i < rows; i++) - etgc_add(etg, i); -} - -static gboolean -etgc_remove (ETableGroup *etg, gint row) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - GList *list; - - for (list = etgc->children ; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = list->data; - ETableGroup *child = child_node->child; - - if (e_table_group_remove (child, row)) { - child_node->count --; - if (child_node->count == 0) { - e_table_group_container_child_node_free (etgc, child_node); - etgc->children = g_list_remove (etgc->children, child_node); - g_free (child_node); - } else - compute_text (etgc, child_node); - - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (etgc)); - - return TRUE; - } - } - return FALSE; -} - -static int -etgc_row_count (ETableGroup *etg) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - GList *list; - gint count = 0; - for (list = etgc->children; list; list = g_list_next(list)) { - ETableGroup *group = ((ETableGroupContainerChildNode *)list->data)->child; - gint this_count = e_table_group_row_count(group); - count += this_count; - } - return count; -} - -static void -etgc_increment (ETableGroup *etg, gint position, gint amount) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - GList *list = etgc->children; - - for (list = etgc->children ; list; list = g_list_next (list)) - e_table_group_increment (((ETableGroupContainerChildNode *)list->data)->child, - position, amount); -} - -static void -etgc_decrement (ETableGroup *etg, gint position, gint amount) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - GList *list = etgc->children; - - for (list = etgc->children ; list; list = g_list_next (list)) - e_table_group_decrement (((ETableGroupContainerChildNode *)list->data)->child, - position, amount); -} - -static void -etgc_set_cursor_row (ETableGroup *etg, gint row) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - GList *list; - 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); - if (row < this_count) { - e_table_group_set_cursor_row(group, row); - return; - } - row -= this_count; - } -} - -static int -etgc_get_cursor_row (ETableGroup *etg) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - GList *list; - int count = 0; - for (list = etgc->children; list; list = g_list_next(list)) { - ETableGroup *group = ((ETableGroupContainerChildNode *)list->data)->child; - int row = e_table_group_get_cursor_row(group); - if (row != -1) - return count + row; - count += e_table_group_row_count(group); - } - return -1; -} - -static void -etgc_set_focus (ETableGroup *etg, EFocus direction, gint view_col) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - if (etgc->children) { - if (direction == E_FOCUS_END) - e_table_group_set_focus (((ETableGroupContainerChildNode *)g_list_last (etgc->children)->data)->child, - direction, view_col); - else - e_table_group_set_focus (((ETableGroupContainerChildNode *)etgc->children->data)->child, - direction, view_col); - } -} - -static gint -etgc_get_focus_column (ETableGroup *etg) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - if (etgc->children) { - GList *list; - for (list = etgc->children; list; list = list->next) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - ETableGroup *child = child_node->child; - if (e_table_group_get_focus (child)) { - return e_table_group_get_focus_column (child); - } - } - } - return 0; -} - -static void -etgc_compute_location (ETableGroup *etg, int *x, int *y, int *row, int *col) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - - if (row) - *row = -1; - if (col) - *col = -1; - - *x -= GROUP_INDENT; - *y -= TITLE_HEIGHT; - - if (*x >= 0 && *y >= 0 && etgc->children) { - GList *list; - for (list = etgc->children; list; list = list->next) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - ETableGroup *child = child_node->child; - - e_table_group_compute_location (child, x, y, row, col); - if ((*row != -1) && (*col != -1)) - return; - } - } -} - -static void etgc_thaw (ETableGroup *etg) -{ - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(etg)); -} - -static void -etgc_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (object); - GList *list; - - switch (arg_id) { - case ARG_FROZEN: - if (GTK_VALUE_BOOL (*arg)) - etg->frozen = TRUE; - else { - etg->frozen = FALSE; - etgc_thaw (etg); - } - break; - case ARG_MINIMUM_WIDTH: - case ARG_WIDTH: - etgc->minimum_width = GTK_VALUE_DOUBLE(*arg); - - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - gtk_object_set (GTK_OBJECT(child_node->child), - "minimum_width", etgc->minimum_width - GROUP_INDENT, - NULL); - } - break; - case ARG_LENGTH_THRESHOLD: - etgc->length_threshold = GTK_VALUE_INT (*arg); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - gtk_object_set (GTK_OBJECT(child_node->child), - "length_threshold", GTK_VALUE_INT (*arg), - NULL); - } - break; - - case ARG_TABLE_SELECTION_MODEL: - if (etgc->table_selection_model) - gtk_object_unref(GTK_OBJECT(etgc->table_selection_model)); - etgc->table_selection_model = E_TABLE_SELECTION_MODEL(GTK_VALUE_OBJECT (*arg)); - if (etgc->table_selection_model) - gtk_object_ref(GTK_OBJECT(etgc->table_selection_model)); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - gtk_object_set (GTK_OBJECT(child_node->child), - "table_selection_model", etgc->table_selection_model, - NULL); - } - break; - - case ARG_TABLE_DRAW_GRID: - etgc->draw_grid = GTK_VALUE_BOOL (*arg); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - gtk_object_set (GTK_OBJECT(child_node->child), - "drawgrid", GTK_VALUE_BOOL (*arg), - NULL); - } - break; - - case ARG_TABLE_DRAW_FOCUS: - etgc->draw_focus = GTK_VALUE_BOOL (*arg); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - gtk_object_set (GTK_OBJECT(child_node->child), - "drawfocus", GTK_VALUE_BOOL (*arg), - NULL); - } - break; - - case ARG_CURSOR_MODE: - etgc->cursor_mode = GTK_VALUE_INT (*arg); - for (list = etgc->children; list; list = g_list_next (list)) { - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *)list->data; - gtk_object_set (GTK_OBJECT(child_node->child), - "cursor_mode", GTK_VALUE_INT (*arg), - NULL); - } - break; - default: - break; - } -} - -static void -etgc_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (object); - - switch (arg_id) { - case ARG_FROZEN: - GTK_VALUE_BOOL (*arg) = etg->frozen; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = etgc->height; - break; - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = etgc->width; - break; - case ARG_MINIMUM_WIDTH: - etgc->minimum_width = GTK_VALUE_DOUBLE(*arg); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -etgc_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - ETableGroupClass *e_group_class = E_TABLE_GROUP_CLASS(object_class); - - object_class->destroy = etgc_destroy; - object_class->set_arg = etgc_set_arg; - object_class->get_arg = etgc_get_arg; - - item_class->event = etgc_event; - item_class->realize = etgc_realize; - item_class->unrealize = etgc_unrealize; - - etgc_parent_class = gtk_type_class (PARENT_TYPE); - - e_group_class->add = etgc_add; - e_group_class->add_all = etgc_add_all; - e_group_class->remove = etgc_remove; - e_group_class->increment = etgc_increment; - e_group_class->decrement = etgc_decrement; - e_group_class->row_count = etgc_row_count; - e_group_class->set_focus = etgc_set_focus; - e_group_class->set_cursor_row = etgc_set_cursor_row; - e_group_class->get_cursor_row = etgc_get_cursor_row; - e_group_class->get_focus_column = etgc_get_focus_column; - e_group_class->get_printable = etgc_get_printable; - e_group_class->compute_location = etgc_compute_location; - - gtk_object_add_arg_type ("ETableGroupContainer::drawgrid", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_GRID); - gtk_object_add_arg_type ("ETableGroupContainer::drawfocus", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_FOCUS); - gtk_object_add_arg_type ("ETableGroupContainer::cursor_mode", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_CURSOR_MODE); - gtk_object_add_arg_type ("ETableGroupContainer::table_selection_model", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_TABLE_SELECTION_MODEL); - gtk_object_add_arg_type ("ETableGroupContainer::length_threshold", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_LENGTH_THRESHOLD); - - gtk_object_add_arg_type ("ETableGroupContainer::frozen", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_FROZEN); - gtk_object_add_arg_type ("ETableGroupContainer::height", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_HEIGHT); - gtk_object_add_arg_type ("ETableGroupContainer::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ETableGroupContainer::minimum_width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_MINIMUM_WIDTH); -} - -static void -etgc_reflow (GnomeCanvasItem *item, gint flags) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(item); - gboolean frozen; - - gtk_object_get (GTK_OBJECT(etgc), - "frozen", &frozen, - NULL); - - if (frozen) - return; - - - if (GTK_OBJECT_FLAGS(etgc)& GNOME_CANVAS_ITEM_REALIZED){ - gdouble running_height = 0; - gdouble running_width = 0; - gdouble old_height; - gdouble old_width; - - old_height = etgc->height; - old_width = etgc->width; - if (etgc->children == NULL){ - } else { - GList *list; - gdouble extra_height = 0; - gdouble item_height = 0; - gdouble item_width = 0; - - if (etgc->font) - extra_height += etgc->font->ascent + etgc->font->descent + BUTTON_PADDING * 2; - - extra_height = MAX(extra_height, BUTTON_HEIGHT + BUTTON_PADDING * 2); - - running_height = extra_height; - - for ( list = etgc->children; list; list = g_list_next (list)){ - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data; - ETableGroup *child = child_node->child; - - gtk_object_get (GTK_OBJECT(child), - "width", &item_width, - NULL); - - if (item_width > running_width) - running_width = item_width; - } - for ( list = etgc->children; list; list = g_list_next (list)){ - ETableGroupContainerChildNode *child_node = (ETableGroupContainerChildNode *) list->data; - ETableGroup *child = child_node->child; - gtk_object_get (GTK_OBJECT(child), - "height", &item_height, - NULL); - - e_canvas_item_move_absolute (GNOME_CANVAS_ITEM(child_node->text), - GROUP_INDENT, - running_height - BUTTON_PADDING); - - e_canvas_item_move_absolute (GNOME_CANVAS_ITEM(child), - GROUP_INDENT, - running_height); - - gnome_canvas_item_set (GNOME_CANVAS_ITEM(child_node->rect), - "x1", (double) 0, - "x2", (double) running_width + GROUP_INDENT, - "y1", (double) running_height - extra_height, - "y2", (double) running_height + item_height, - NULL); - - running_height += item_height + extra_height; - } - running_height -= extra_height; - } - if (running_height != old_height || running_width != old_width) { - etgc->height = running_height; - etgc->width = running_width; - e_canvas_item_request_parent_reflow (item); - } - } -} - -static void -etgc_init (GtkObject *object) -{ - ETableGroupContainer *container = E_TABLE_GROUP_CONTAINER(object); - container->children = FALSE; - - e_canvas_item_set_reflow_callback (GNOME_CANVAS_ITEM(object), etgc_reflow); - - container->draw_grid = 1; - container->draw_focus = 1; - container->cursor_mode = E_TABLE_CURSOR_SIMPLE; - container->length_threshold = -1; - container->table_selection_model = NULL; -} - -E_MAKE_TYPE (e_table_group_container, "ETableGroupContainer", ETableGroupContainer, etgc_class_init, etgc_init, PARENT_TYPE); - -void -e_table_group_apply_to_leafs (ETableGroup *etg, ETableGroupLeafFn fn, void *closure) -{ - if (E_IS_TABLE_GROUP_CONTAINER (etg)){ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER (etg); - GList *list = etgc->children; - - for (list = etgc->children; list; list = list->next){ - ETableGroupContainerChildNode *child_node = list->data; - - e_table_group_apply_to_leafs (child_node->child, fn, closure); - } - } else if (E_IS_TABLE_GROUP_LEAF (etg)){ - (*fn) (E_TABLE_GROUP_LEAF (etg)->item, closure); - } else { - g_error ("Unknown ETableGroup found: %s", - gtk_type_name (GTK_OBJECT (etg)->klass->type)); - } -} - - -typedef struct { - ETableGroupContainer *etgc; - GList *child; - EPrintable *child_printable; -} ETGCPrintContext; - -#if 0 -#define CHECK(x) if((x) == -1) return -1; - -static gint -gp_draw_rect (GnomePrintContext *context, gdouble x, gdouble y, gdouble width, gdouble height, gdouble r, gdouble g, gdouble b) -{ - CHECK(gnome_print_moveto(context, x, y)); - CHECK(gnome_print_lineto(context, x + width, y)); - CHECK(gnome_print_lineto(context, x + width, y - height)); - CHECK(gnome_print_lineto(context, x, y - height)); - CHECK(gnome_print_lineto(context, x, y)); - return gnome_print_fill(context); -} -#endif - -static void -e_table_group_container_print_page (EPrintable *ep, - GnomePrintContext *context, - gdouble width, - gdouble height, - gboolean quantize, - ETGCPrintContext *groupcontext) -{ - gdouble yd = height; - gdouble child_height; - ETableGroupContainerChildNode *child_node; - GList *child; - EPrintable *child_printable; - - child_printable = groupcontext->child_printable; - child = groupcontext->child; - - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - else { - if (!child) { - return; - } else { - child_node = child->data; - child_printable = e_table_group_get_printable(child_node->child); - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - e_printable_reset(child_printable); - } - } - - while (1) { - child_height = e_printable_height(child_printable, context, width - 36, yd, quantize); - - if (gnome_print_gsave(context) == -1) - /* FIXME */; - if (gnome_print_translate(context, 36, yd - child_height) == -1) - /* FIXME */; - - if (gnome_print_moveto(context, 0, 0) == -1) - /* FIXME */; - if (gnome_print_lineto(context, width - 36, 0) == -1) - /* FIXME */; - if (gnome_print_lineto(context, width - 36, child_height) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 0, child_height) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 0, 0) == -1) - /* FIXME */; - if (gnome_print_clip(context) == -1) - /* FIXME */; - - e_printable_print_page(child_printable, context, width - 36, child_height, quantize); - - if (gnome_print_grestore(context) == -1) - /* FIXME */; - - yd -= child_height; - - if (e_printable_data_left(child_printable)) - break; - - child = child->next; - if (!child) { - child_printable = NULL; - break; - } - - child_node = child->data; - if (child_printable) - gtk_object_unref(GTK_OBJECT(child_printable)); - child_printable = e_table_group_get_printable(child_node->child); - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - e_printable_reset(child_printable); - } - - if (groupcontext->child_printable) - gtk_object_unref(GTK_OBJECT(groupcontext->child_printable)); - groupcontext->child_printable = child_printable; - groupcontext->child = child; - -} - -static gboolean -e_table_group_container_data_left (EPrintable *ep, - ETGCPrintContext *groupcontext) -{ - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "data_left"); - return groupcontext->child != NULL; -} - -static void -e_table_group_container_reset (EPrintable *ep, - ETGCPrintContext *groupcontext) -{ - groupcontext->child = groupcontext->etgc->children; - if (groupcontext->child_printable) - gtk_object_unref(GTK_OBJECT(groupcontext->child_printable)); - groupcontext->child_printable = NULL; -} - -static gdouble -e_table_group_container_height (EPrintable *ep, - GnomePrintContext *context, - gdouble width, - gdouble max_height, - gboolean quantize, - ETGCPrintContext *groupcontext) -{ - gdouble height = 0; - gdouble child_height; - gdouble yd = max_height; - ETableGroupContainerChildNode *child_node; - GList *child; - EPrintable *child_printable; - - child_printable = groupcontext->child_printable; - child = groupcontext->child; - - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - else { - if (!child) { - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "height"); - return 0; - } else { - child_node = child->data; - child_printable = e_table_group_get_printable(child_node->child); - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - e_printable_reset(child_printable); - } - } - - while (1) { - child_height = e_printable_height(child_printable, context, width - 36, yd, quantize); - - height += child_height; - - if (yd != -1) { - if (!e_printable_will_fit(child_printable, context, width - 36, yd, quantize)) { - break; - } - - yd -= child_height; - } - - child = child->next; - if (!child) { - break; - } - - child_node = child->data; - if (child_printable) - gtk_object_unref(GTK_OBJECT(child_printable)); - child_printable = e_table_group_get_printable(child_node->child); - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - e_printable_reset(child_printable); - } - if (child_printable) - gtk_object_unref(GTK_OBJECT(child_printable)); - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "height"); - return height; -} - -static gboolean -e_table_group_container_will_fit (EPrintable *ep, - GnomePrintContext *context, - gdouble width, - gdouble max_height, - gboolean quantize, - ETGCPrintContext *groupcontext) -{ - gboolean will_fit = TRUE; - gdouble child_height; - gdouble yd = max_height; - ETableGroupContainerChildNode *child_node; - GList *child; - EPrintable *child_printable; - - child_printable = groupcontext->child_printable; - child = groupcontext->child; - - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - else { - if (!child) { - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "will_fit"); - return will_fit; - } else { - child_node = child->data; - child_printable = e_table_group_get_printable(child_node->child); - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - e_printable_reset(child_printable); - } - } - - while (1) { - child_height = e_printable_height(child_printable, context, width - 36, yd, quantize); - - if (yd != -1) { - if (!e_printable_will_fit(child_printable, context, width - 36, yd, quantize)) { - will_fit = FALSE; - break; - } - - yd -= child_height; - } - - child = child->next; - if (!child) { - break; - } - - child_node = child->data; - if (child_printable) - gtk_object_unref(GTK_OBJECT(child_printable)); - child_printable = e_table_group_get_printable(child_node->child); - if (child_printable) - gtk_object_ref(GTK_OBJECT(child_printable)); - e_printable_reset(child_printable); - } - - if (child_printable) - gtk_object_unref(GTK_OBJECT(child_printable)); - - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "will_fit"); - return will_fit; -} - -static void -e_table_group_container_printable_destroy (GtkObject *object, - ETGCPrintContext *groupcontext) -{ - gtk_object_unref(GTK_OBJECT(groupcontext->etgc)); - if (groupcontext->child_printable) - gtk_object_ref(GTK_OBJECT(groupcontext->child_printable)); - g_free(groupcontext); -} - -static EPrintable * -etgc_get_printable (ETableGroup *etg) -{ - ETableGroupContainer *etgc = E_TABLE_GROUP_CONTAINER(etg); - EPrintable *printable = e_printable_new(); - ETGCPrintContext *groupcontext; - - groupcontext = g_new(ETGCPrintContext, 1); - groupcontext->etgc = etgc; - gtk_object_ref(GTK_OBJECT(etgc)); - groupcontext->child = etgc->children; - groupcontext->child_printable = NULL; - - gtk_signal_connect (GTK_OBJECT(printable), - "print_page", - GTK_SIGNAL_FUNC(e_table_group_container_print_page), - groupcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "data_left", - GTK_SIGNAL_FUNC(e_table_group_container_data_left), - groupcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "reset", - GTK_SIGNAL_FUNC(e_table_group_container_reset), - groupcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "height", - GTK_SIGNAL_FUNC(e_table_group_container_height), - groupcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "will_fit", - GTK_SIGNAL_FUNC(e_table_group_container_will_fit), - groupcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "destroy", - GTK_SIGNAL_FUNC(e_table_group_container_printable_destroy), - groupcontext); - - return printable; -} diff --git a/widgets/table/e-table-group-container.h b/widgets/table/e-table-group-container.h deleted file mode 100644 index bdb717b92d..0000000000 --- a/widgets/table/e-table-group-container.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_GROUP_CONTAINER_H_ -#define _E_TABLE_GROUP_CONTAINER_H_ - -#include <libgnomeui/gnome-canvas.h> -#include "e-table-model.h" -#include "e-table-header.h" -#include "e-table-group.h" -#include "e-table-item.h" - -#define E_TABLE_GROUP_CONTAINER_TYPE (e_table_group_container_get_type ()) -#define E_TABLE_GROUP_CONTAINER(o) (GTK_CHECK_CAST ((o), E_TABLE_GROUP_CONTAINER_TYPE, ETableGroupContainer)) -#define E_TABLE_GROUP_CONTAINER_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_GROUP_CONTAINER_TYPE, ETableGroupContainerClass)) -#define E_IS_TABLE_GROUP_CONTAINER(o) (GTK_CHECK_TYPE ((o), E_TABLE_GROUP_CONTAINER_TYPE)) -#define E_IS_TABLE_GROUP_CONTAINER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_GROUP_CONTAINER_TYPE)) - -typedef struct { - ETableGroup group; - - /* - * The ETableCol used to group this set - */ - ETableCol *ecol; - gint ascending; - - /* - * List of ETableGroups we stack - */ - GList *children; - - /* - * The canvas rectangle that contains the children - */ - GnomeCanvasItem *rect; - - GdkFont *font; - - gdouble width, height, minimum_width; - - ETableSortInfo *sort_info; - int n; - int length_threshold; - - ETableSelectionModel *table_selection_model; - - guint draw_grid : 1; - guint draw_focus : 1; - ETableCursorMode cursor_mode; - - /* - * State: the ETableGroup is open or closed - */ - guint open:1; -} ETableGroupContainer; - -typedef struct { - ETableGroupClass parent_class; -} ETableGroupContainerClass; - -ETableGroup *e_table_group_container_new (GnomeCanvasGroup *parent, ETableHeader *full_header, ETableHeader *header, - ETableModel *model, ETableSortInfo *sort_info, int n); -void e_table_group_container_construct (GnomeCanvasGroup *parent, ETableGroupContainer *etgc, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, ETableSortInfo *sort_info, int n); - -GtkType e_table_group_container_get_type (void); - -#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 c4792eb87e..0000000000 --- a/widgets/table/e-table-group-leaf.c +++ /dev/null @@ -1,425 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-Table-Group.c: Implements the grouping objects for elements on a table - * - * Author: - * Miguel de Icaza (miguel@gnu.org () - * - * Copyright 1999, Helix Code, Inc. - */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-table-group-leaf.h" -#include "e-table-item.h" -#include <libgnomeui/gnome-canvas-rect-ellipse.h> -#include "e-util/e-util.h" -#include "e-util/e-canvas.h" - -#define PARENT_TYPE e_table_group_get_type () - -static GnomeCanvasGroupClass *etgl_parent_class; - -/* The arguments we take */ -enum { - ARG_0, - ARG_HEIGHT, - ARG_WIDTH, - ARG_MINIMUM_WIDTH, - ARG_FROZEN, - ARG_TABLE_DRAW_GRID, - ARG_TABLE_DRAW_FOCUS, - ARG_CURSOR_MODE, - ARG_LENGTH_THRESHOLD, - ARG_TABLE_SELECTION_MODEL, -}; - -static void etgl_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void etgl_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); - -static void -etgl_destroy (GtkObject *object) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF(object); - if (etgl->subset) - gtk_object_unref (GTK_OBJECT(etgl->subset)); - if (etgl->item) - gtk_object_destroy (GTK_OBJECT(etgl->item)); - if (etgl->table_selection_model) - gtk_object_unref (GTK_OBJECT(etgl->table_selection_model)); - if (GTK_OBJECT_CLASS (etgl_parent_class)->destroy) - GTK_OBJECT_CLASS (etgl_parent_class)->destroy (object); -} - -static void -e_table_group_leaf_construct (GnomeCanvasGroup *parent, - ETableGroupLeaf *etgl, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info) -{ - etgl->subset = E_TABLE_SUBSET_VARIABLE(e_table_sorted_variable_new (model, full_header, sort_info)); - gtk_object_ref(GTK_OBJECT(etgl->subset)); - gtk_object_sink(GTK_OBJECT(etgl->subset)); - e_table_group_construct (parent, E_TABLE_GROUP (etgl), full_header, header, model); -} - -ETableGroup * -e_table_group_leaf_new (GnomeCanvasGroup *parent, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info) -{ - ETableGroupLeaf *etgl; - - g_return_val_if_fail (parent != NULL, NULL); - - etgl = gtk_type_new (e_table_group_leaf_get_type ()); - - e_table_group_leaf_construct (parent, etgl, full_header, - header, model, sort_info); - return E_TABLE_GROUP (etgl); -} - -static void -etgl_cursor_change (GtkObject *object, gint row, ETableGroupLeaf *etgl) -{ - if (row < E_TABLE_SUBSET(etgl->subset)->n_map) - e_table_group_cursor_change (E_TABLE_GROUP(etgl), E_TABLE_SUBSET(etgl->subset)->map_table[row]); -} - -static void -etgl_double_click (GtkObject *object, gint row, ETableGroupLeaf *etgl) -{ - if (row < E_TABLE_SUBSET(etgl->subset)->n_map) - e_table_group_double_click (E_TABLE_GROUP(etgl), E_TABLE_SUBSET(etgl->subset)->map_table[row]); -} - -static gint -etgl_key_press (GtkObject *object, gint row, gint col, GdkEvent *event, ETableGroupLeaf *etgl) -{ - if (row < E_TABLE_SUBSET(etgl->subset)->n_map) - return e_table_group_key_press (E_TABLE_GROUP(etgl), E_TABLE_SUBSET(etgl->subset)->map_table[row], col, event); - else - return 0; -} - -static gint -etgl_right_click (GtkObject *object, gint row, gint col, GdkEvent *event, ETableGroupLeaf *etgl) -{ - if (row < E_TABLE_SUBSET(etgl->subset)->n_map) - return e_table_group_right_click (E_TABLE_GROUP(etgl), E_TABLE_SUBSET(etgl->subset)->map_table[row], col, event); - else - return 0; -} - -static void -etgl_reflow (GnomeCanvasItem *item, gint flags) -{ - ETableGroupLeaf *leaf = E_TABLE_GROUP_LEAF(item); - gtk_object_get(GTK_OBJECT(leaf->item), - "height", &leaf->height, - NULL); - gtk_object_get(GTK_OBJECT(leaf->item), - "width", &leaf->width, - NULL); - e_canvas_item_request_parent_reflow (item); -} - -static void -etgl_realize (GnomeCanvasItem *item) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF(item); - - if (GNOME_CANVAS_ITEM_CLASS (etgl_parent_class)->realize) - GNOME_CANVAS_ITEM_CLASS (etgl_parent_class)->realize (item); - - etgl->item = E_TABLE_ITEM(gnome_canvas_item_new (GNOME_CANVAS_GROUP(etgl), - e_table_item_get_type (), - "ETableHeader", E_TABLE_GROUP(etgl)->header, - "ETableModel", etgl->subset, - "drawgrid", etgl->draw_grid, - "drawfocus", etgl->draw_focus, - "cursor_mode", etgl->cursor_mode, - "minimum_width", etgl->minimum_width, - "length_threshold", etgl->length_threshold, - "table_selection_model", etgl->table_selection_model, - NULL)); - - gtk_signal_connect (GTK_OBJECT(etgl->item), "cursor_change", - GTK_SIGNAL_FUNC(etgl_cursor_change), etgl); - gtk_signal_connect (GTK_OBJECT(etgl->item), "double_click", - GTK_SIGNAL_FUNC(etgl_double_click), etgl); - gtk_signal_connect (GTK_OBJECT(etgl->item), "right_click", - GTK_SIGNAL_FUNC(etgl_right_click), etgl); - gtk_signal_connect (GTK_OBJECT(etgl->item), "key_press", - GTK_SIGNAL_FUNC(etgl_key_press), etgl); - e_canvas_item_request_reflow(item); -} - -static void -etgl_add (ETableGroup *etg, gint row) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - e_table_subset_variable_add (etgl->subset, row); -} - -static void -etgl_add_all (ETableGroup *etg) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - e_table_subset_variable_add_all (etgl->subset); -} - -static gboolean -etgl_remove (ETableGroup *etg, gint row) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - return e_table_subset_variable_remove (etgl->subset, row); -} - -static void -etgl_increment (ETableGroup *etg, gint position, gint amount) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - e_table_subset_variable_increment (etgl->subset, position, amount); -} - -static void -etgl_decrement (ETableGroup *etg, gint position, gint amount) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - e_table_subset_variable_decrement (etgl->subset, position, amount); -} - -static int -etgl_row_count (ETableGroup *etg) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - return e_table_model_row_count(E_TABLE_MODEL(etgl->subset)); -} - -static void -etgl_set_focus (ETableGroup *etg, EFocus direction, gint view_col) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - if (direction == E_FOCUS_END) { - e_table_item_set_cursor (etgl->item, view_col, e_table_model_row_count(E_TABLE_MODEL(etgl->subset)) - 1); - } else { - e_table_item_set_cursor (etgl->item, view_col, 0); - } -} - -static void -etgl_set_cursor_row (ETableGroup *etg, gint row) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - gnome_canvas_item_set(GNOME_CANVAS_ITEM(etgl->item), - "cursor_row", row, - NULL); -} - -static int -etgl_get_cursor_row (ETableGroup *etg) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - int row; - gtk_object_get(GTK_OBJECT(etgl->item), - "cursor_row", &row, - NULL); - return row; -} - -static gint -etgl_get_focus_column (ETableGroup *etg) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - return e_table_item_get_focused_column (etgl->item); -} - -static EPrintable * -etgl_get_printable (ETableGroup *etg) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - return e_table_item_get_printable (etgl->item); -} - -static void -etgl_compute_location (ETableGroup *etg, int *x, int *y, int *row, int *col) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (etg); - e_table_item_compute_location (etgl->item, x, y, row, col); -} - -static void -etgl_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (object); - - switch (arg_id) { - case ARG_FROZEN: - if (GTK_VALUE_BOOL (*arg)) - etg->frozen = TRUE; - else { - etg->frozen = FALSE; - } - break; - case ARG_MINIMUM_WIDTH: - case ARG_WIDTH: - etgl->minimum_width = GTK_VALUE_DOUBLE(*arg); - if (etgl->item) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etgl->item), - "minimum_width", etgl->minimum_width, - NULL); - } - break; - case ARG_LENGTH_THRESHOLD: - etgl->length_threshold = GTK_VALUE_INT (*arg); - if (etgl->item) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etgl->item), - "length_threshold", GTK_VALUE_INT (*arg), - NULL); - } - break; - case ARG_TABLE_SELECTION_MODEL: - if (etgl->table_selection_model) - gtk_object_unref(GTK_OBJECT(etgl->table_selection_model)); - etgl->table_selection_model = E_TABLE_SELECTION_MODEL(GTK_VALUE_OBJECT (*arg)); - if (etgl->table_selection_model) - gtk_object_ref(GTK_OBJECT(etgl->table_selection_model)); - if (etgl->item) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etgl->item), - "table_selection_model", etgl->table_selection_model, - NULL); - } - - case ARG_TABLE_DRAW_GRID: - etgl->draw_grid = GTK_VALUE_BOOL (*arg); - if (etgl->item) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etgl->item), - "drawgrid", GTK_VALUE_BOOL (*arg), - NULL); - } - break; - - case ARG_TABLE_DRAW_FOCUS: - etgl->draw_focus = GTK_VALUE_BOOL (*arg); - if (etgl->item) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etgl->item), - "drawfocus", GTK_VALUE_BOOL (*arg), - NULL); - } - break; - - case ARG_CURSOR_MODE: - etgl->cursor_mode = GTK_VALUE_INT (*arg); - if (etgl->item) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etgl->item), - "cursor_mode", GTK_VALUE_INT (*arg), - NULL); - } - break; - default: - break; - } -} - -static void -etgl_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableGroup *etg = E_TABLE_GROUP (object); - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (object); - - switch (arg_id) { - case ARG_FROZEN: - GTK_VALUE_BOOL (*arg) = etg->frozen; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = etgl->height; - break; - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = etgl->width; - break; - case ARG_MINIMUM_WIDTH: - GTK_VALUE_DOUBLE (*arg) = etgl->minimum_width; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -etgl_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - ETableGroupClass *e_group_class = E_TABLE_GROUP_CLASS(object_class); - - object_class->destroy = etgl_destroy; - object_class->set_arg = etgl_set_arg; - object_class->get_arg = etgl_get_arg; - - item_class->realize = etgl_realize; - - etgl_parent_class = gtk_type_class (PARENT_TYPE); - - e_group_class->add = etgl_add; - e_group_class->add_all = etgl_add_all; - e_group_class->remove = etgl_remove; - e_group_class->increment = etgl_increment; - e_group_class->decrement = etgl_decrement; - e_group_class->row_count = etgl_row_count; - e_group_class->set_focus = etgl_set_focus; - e_group_class->set_cursor_row = etgl_set_cursor_row; - e_group_class->get_cursor_row = etgl_get_cursor_row; - e_group_class->get_focus_column = etgl_get_focus_column; - e_group_class->get_printable = etgl_get_printable; - e_group_class->compute_location = etgl_compute_location; - - gtk_object_add_arg_type ("ETableGroupLeaf::drawgrid", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_GRID); - gtk_object_add_arg_type ("ETableGroupLeaf::drawfocus", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_FOCUS); - gtk_object_add_arg_type ("ETableGroupLeaf::cursor_mode", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_CURSOR_MODE); - gtk_object_add_arg_type ("ETableGroupLeaf::length_threshold", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_LENGTH_THRESHOLD); - gtk_object_add_arg_type ("ETableGroupLeaf::table_selection_model", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_TABLE_SELECTION_MODEL); - - gtk_object_add_arg_type ("ETableGroupLeaf::height", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_HEIGHT); - gtk_object_add_arg_type ("ETableGroupLeaf::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ETableGroupLeaf::minimum_width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_MINIMUM_WIDTH); - gtk_object_add_arg_type ("ETableGroupLeaf::frozen", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_FROZEN); -} - -static void -etgl_init (GtkObject *object) -{ - ETableGroupLeaf *etgl = E_TABLE_GROUP_LEAF (object); - - etgl->width = 1; - etgl->height = 1; - etgl->minimum_width = 0; - - etgl->subset = NULL; - etgl->item = NULL; - - etgl->draw_grid = 1; - etgl->draw_focus = 1; - etgl->cursor_mode = E_TABLE_CURSOR_SIMPLE; - etgl->length_threshold = -1; - - etgl->table_selection_model = NULL; - - e_canvas_item_set_reflow_callback (GNOME_CANVAS_ITEM(object), etgl_reflow); -} - -E_MAKE_TYPE (e_table_group_leaf, "ETableGroupLeaf", ETableGroupLeaf, etgl_class_init, etgl_init, PARENT_TYPE); diff --git a/widgets/table/e-table-group-leaf.h b/widgets/table/e-table-group-leaf.h deleted file mode 100644 index 1cc041206b..0000000000 --- a/widgets/table/e-table-group-leaf.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_GROUP_LEAF_H_ -#define _E_TABLE_GROUP_LEAF_H_ - -#include <libgnomeui/gnome-canvas.h> -#include "e-table-group.h" -#include "e-table-sorted-variable.h" -#include "e-table-item.h" - -#define E_TABLE_GROUP_LEAF_TYPE (e_table_group_leaf_get_type ()) -#define E_TABLE_GROUP_LEAF(o) (GTK_CHECK_CAST ((o), E_TABLE_GROUP_LEAF_TYPE, ETableGroupLeaf)) -#define E_TABLE_GROUP_LEAF_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_GROUP_LEAF_TYPE, ETableGroupLeafClass)) -#define E_IS_TABLE_GROUP_LEAF(o) (GTK_CHECK_TYPE ((o), E_TABLE_GROUP_LEAF_TYPE)) -#define E_IS_TABLE_GROUP_LEAF_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_GROUP_LEAF_TYPE)) - -typedef struct { - ETableGroup group; - - /* - * Item. - */ - ETableItem *item; - - gdouble height; - gdouble width; - gdouble minimum_width; - - ETableSubsetVariable *subset; - - int length_threshold; - - guint draw_grid : 1; - guint draw_focus : 1; - ETableCursorMode cursor_mode; - - ETableSelectionModel *table_selection_model; -} ETableGroupLeaf; - -typedef struct { - ETableGroupClass parent_class; -} ETableGroupLeafClass; - -ETableGroup *e_table_group_leaf_new (GnomeCanvasGroup *parent, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info); -GtkType e_table_group_leaf_get_type (void); - - -#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 fbd9026096..0000000000 --- a/widgets/table/e-table-group.c +++ /dev/null @@ -1,420 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-Table-Group.c: Implements the grouping objects for elements on a table - * - * Author: - * Miguel de Icaza (miguel@helixcode.com) - * Chris Lahey (clahey@helixcode.com) - * - * Copyright 1999, 2000 Helix Code, Inc. - */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-table-group.h" -#include "e-table-group-container.h" -#include "e-table-group-leaf.h" -#include "e-table-item.h" -#include <libgnomeui/gnome-canvas-rect-ellipse.h> -#include "e-util/e-util.h" - -#define PARENT_TYPE gnome_canvas_group_get_type () - -#define ETG_CLASS(e) (E_TABLE_GROUP_CLASS(GTK_OBJECT(e)->klass)) - -static GnomeCanvasGroupClass *etg_parent_class; - -enum { - CURSOR_CHANGE, - DOUBLE_CLICK, - RIGHT_CLICK, - KEY_PRESS, - LAST_SIGNAL -}; - -static gint etg_signals [LAST_SIGNAL] = { 0, }; - -static gboolean etg_get_focus (ETableGroup *etg); -static void etg_destroy (GtkObject *object); - -static void -etg_destroy (GtkObject *object) -{ - ETableGroup *etg = E_TABLE_GROUP(object); - if (etg->header) - gtk_object_unref (GTK_OBJECT(etg->header)); - if (etg->full_header) - gtk_object_unref (GTK_OBJECT(etg->full_header)); - if (etg->model) - gtk_object_unref (GTK_OBJECT(etg->model)); - if (GTK_OBJECT_CLASS (etg_parent_class)->destroy) - GTK_OBJECT_CLASS (etg_parent_class)->destroy (object); -} - -ETableGroup * -e_table_group_new (GnomeCanvasGroup *parent, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info, - int n) -{ - g_return_val_if_fail (model != NULL, NULL); - - if (n < e_table_sort_info_grouping_get_count(sort_info)) { - return e_table_group_container_new (parent, full_header, header, model, sort_info, n); - } else { - return e_table_group_leaf_new (parent, full_header, header, model, sort_info); - } - return NULL; -} - -void -e_table_group_construct (GnomeCanvasGroup *parent, - ETableGroup *etg, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model) -{ - etg->full_header = full_header; - gtk_object_ref (GTK_OBJECT(etg->full_header)); - etg->header = header; - gtk_object_ref (GTK_OBJECT(etg->header)); - etg->model = model; - gtk_object_ref (GTK_OBJECT(etg->model)); - gnome_canvas_item_constructv (GNOME_CANVAS_ITEM (etg), parent, 0, NULL); -} - -void -e_table_group_add (ETableGroup *etg, - gint row) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->add) - ETG_CLASS (etg)->add (etg, row); -} - -void -e_table_group_add_all (ETableGroup *etg) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->add_all) - ETG_CLASS (etg)->add_all (etg); -} - -gboolean -e_table_group_remove (ETableGroup *etg, - gint row) -{ - g_return_val_if_fail (etg != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), FALSE); - - if (ETG_CLASS (etg)->remove) - return ETG_CLASS (etg)->remove (etg, row); - else - return FALSE; -} - -gint -e_table_group_get_count (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), 0); - - if (ETG_CLASS (etg)->get_count) - return ETG_CLASS (etg)->get_count (etg); - else - return 0; -} - -gint -e_table_group_row_count (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), 0); - - if (ETG_CLASS (etg)->row_count) - return ETG_CLASS (etg)->row_count (etg); - else - return 0; -} - -void -e_table_group_increment (ETableGroup *etg, - gint position, - gint amount) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->increment) - ETG_CLASS (etg)->increment (etg, position, amount); -} - -void -e_table_group_decrement (ETableGroup *etg, - gint position, - gint amount) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->decrement) - ETG_CLASS (etg)->decrement (etg, position, amount); -} - -void -e_table_group_set_focus (ETableGroup *etg, - EFocus direction, - gint row) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->set_focus) - ETG_CLASS (etg)->set_focus (etg, direction, row); -} - -void -e_table_group_set_cursor_row (ETableGroup *etg, - gint row) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->set_cursor_row) - ETG_CLASS (etg)->set_cursor_row (etg, row); -} - -int -e_table_group_get_cursor_row (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, -1); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), -1); - - if (ETG_CLASS (etg)->get_cursor_row) - return ETG_CLASS (etg)->get_cursor_row (etg); - else - return -1; -} - -gboolean -e_table_group_get_focus (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), FALSE); - - if (ETG_CLASS (etg)->get_focus) - return ETG_CLASS (etg)->get_focus (etg); - else - return FALSE; -} - -gboolean -e_table_group_get_focus_column (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), FALSE); - - if (ETG_CLASS (etg)->get_focus_column) - return ETG_CLASS (etg)->get_focus_column (etg); - else - return FALSE; -} - -ETableCol * -e_table_group_get_ecol (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), NULL); - - if (ETG_CLASS (etg)->get_ecol) - return ETG_CLASS (etg)->get_ecol (etg); - else - return NULL; -} - -EPrintable * -e_table_group_get_printable (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), NULL); - - if (ETG_CLASS (etg)->get_printable) - return ETG_CLASS (etg)->get_printable (etg); - else - return NULL; -} - -void -e_table_group_compute_location (ETableGroup *etg, int *x, int *y, int *row, int *col) -{ - g_return_if_fail (etg != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (etg)); - - if (ETG_CLASS (etg)->compute_location) - ETG_CLASS (etg)->compute_location (etg, x, y, row, col); -} - -void -e_table_group_cursor_change (ETableGroup *e_table_group, gint row) -{ - g_return_if_fail (e_table_group != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (e_table_group)); - - gtk_signal_emit (GTK_OBJECT (e_table_group), - etg_signals [CURSOR_CHANGE], - row); -} - -void -e_table_group_double_click (ETableGroup *e_table_group, gint row) -{ - g_return_if_fail (e_table_group != NULL); - g_return_if_fail (E_IS_TABLE_GROUP (e_table_group)); - - gtk_signal_emit (GTK_OBJECT (e_table_group), - etg_signals [DOUBLE_CLICK], - row); -} - -gint -e_table_group_right_click (ETableGroup *e_table_group, gint row, gint col, GdkEvent *event) -{ - gint return_val = 0; - - g_return_val_if_fail (e_table_group != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_GROUP (e_table_group), 0); - - gtk_signal_emit (GTK_OBJECT (e_table_group), - etg_signals [RIGHT_CLICK], - row, col, event, &return_val); - - return return_val; -} - -gint -e_table_group_key_press (ETableGroup *e_table_group, gint row, gint col, GdkEvent *event) -{ - gint return_val = 0; - - g_return_val_if_fail (e_table_group != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_GROUP (e_table_group), 0); - - gtk_signal_emit (GTK_OBJECT (e_table_group), - etg_signals [KEY_PRESS], - row, col, event, &return_val); - - return return_val; -} - -ETableHeader * -e_table_group_get_header (ETableGroup *etg) -{ - g_return_val_if_fail (etg != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_GROUP (etg), NULL); - - return etg->header; -} - -static int -etg_event (GnomeCanvasItem *item, GdkEvent *event) -{ - ETableGroup *etg = E_TABLE_GROUP (item); - gboolean return_val = TRUE; - - switch (event->type) { - - case GDK_FOCUS_CHANGE: - etg->has_focus = event->focus_change.in; - return_val = FALSE; - - default: - return_val = FALSE; - } - if (return_val == FALSE){ - if (GNOME_CANVAS_ITEM_CLASS(etg_parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS(etg_parent_class)->event (item, event); - } - return return_val; - -} - -static gboolean -etg_get_focus (ETableGroup *etg) -{ - return etg->has_focus; -} - -static void -etg_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - ETableGroupClass *klass = (ETableGroupClass *) object_class; - - object_class->destroy = etg_destroy; - - item_class->event = etg_event; - - klass->cursor_change = NULL; - klass->double_click = NULL; - klass->right_click = NULL; - klass->key_press = NULL; - - klass->add = NULL; - klass->add_all = NULL; - klass->remove = NULL; - klass->get_count = NULL; - klass->row_count = NULL; - klass->increment = NULL; - klass->decrement = NULL; - klass->set_focus = NULL; - klass->set_cursor_row = NULL; - klass->get_cursor_row = NULL; - klass->get_focus = etg_get_focus; - klass->get_ecol = NULL; - klass->get_printable = NULL; - klass->compute_location = NULL; - - etg_parent_class = gtk_type_class (PARENT_TYPE); - - etg_signals [CURSOR_CHANGE] = - gtk_signal_new ("cursor_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableGroupClass, cursor_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - etg_signals [DOUBLE_CLICK] = - gtk_signal_new ("double_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableGroupClass, double_click), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - etg_signals [RIGHT_CLICK] = - gtk_signal_new ("right_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableGroupClass, right_click), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - etg_signals [KEY_PRESS] = - gtk_signal_new ("key_press", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableGroupClass, key_press), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - gtk_object_class_add_signals (object_class, etg_signals, LAST_SIGNAL); -} - -E_MAKE_TYPE (e_table_group, "ETableGroup", ETableGroup, etg_class_init, NULL, PARENT_TYPE); diff --git a/widgets/table/e-table-group.glade b/widgets/table/e-table-group.glade deleted file mode 100644 index 39274d3c61..0000000000 --- a/widgets/table/e-table-group.glade +++ /dev/null @@ -1,208 +0,0 @@ -<?xml version="1.0"?> -<GTK-Interface> - -<project> - <directory></directory> - <source_directory>src</source_directory> - <pixmaps_directory>pixmaps</pixmaps_directory> - <language>C</language> - <gnome_support>True</gnome_support> - <gettext_support>True</gettext_support> - <use_widget_names>False</use_widget_names> - <output_main_file>False</output_main_file> - <output_support_files>False</output_support_files> - <output_build_files>False</output_build_files> - <backup_source_files>False</backup_source_files> - <main_source_file>interface.c</main_source_file> - <main_header_file>interface.h</main_header_file> - <handler_source_file>callbacks.c</handler_source_file> - <handler_header_file>callbacks.h</handler_header_file> - <support_source_file>support.c</support_source_file> - <support_header_file>support.h</support_header_file> - <output_translatable_strings>True</output_translatable_strings> - <translatable_strings_file>e-table-group.glade.h</translatable_strings_file> -</project> - -<widget> - <class>GtkWindow</class> - <name>window1</name> - <title>window1</title> - <type>GTK_WINDOW_TOPLEVEL</type> - <position>GTK_WIN_POS_NONE</position> - <modal>False</modal> - <allow_shrink>False</allow_shrink> - <allow_grow>True</allow_grow> - <auto_shrink>False</auto_shrink> - - <widget> - <class>GtkTable</class> - <name>table1</name> - <rows>3</rows> - <columns>3</columns> - <homogeneous>False</homogeneous> - <row_spacing>0</row_spacing> - <column_spacing>0</column_spacing> - - <widget> - <class>GtkFrame</class> - <name>frame1</name> - <border_width>4</border_width> - <label>Available fields</label> - <label_xalign>0</label_xalign> - <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type> - <child> - <left_attach>0</left_attach> - <right_attach>1</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>True</xexpand> - <yexpand>True</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - - <widget> - <class>GtkScrolledWindow</class> - <name>scrolledwindow1</name> - <hscrollbar_policy>GTK_POLICY_ALWAYS</hscrollbar_policy> - <vscrollbar_policy>GTK_POLICY_ALWAYS</vscrollbar_policy> - <hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy> - <vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy> - - <widget> - <class>GtkCList</class> - <name>clist1</name> - <can_focus>True</can_focus> - <columns>1</columns> - <column_widths>80</column_widths> - <selection_mode>GTK_SELECTION_SINGLE</selection_mode> - <show_titles>False</show_titles> - <shadow_type>GTK_SHADOW_NONE</shadow_type> - - <widget> - <class>GtkLabel</class> - <child_name>CList:title</child_name> - <name>label1</name> - <label>label1</label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - </widget> - </widget> - </widget> - </widget> - - <widget> - <class>GtkFrame</class> - <name>frame2</name> - <border_width>4</border_width> - <label>Show in this order</label> - <label_xalign>0</label_xalign> - <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type> - <child> - <left_attach>2</left_attach> - <right_attach>3</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>0</xpad> - <ypad>0</ypad> - <xexpand>True</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>True</xfill> - <yfill>True</yfill> - </child> - - <widget> - <class>GtkScrolledWindow</class> - <name>scrolledwindow2</name> - <hscrollbar_policy>GTK_POLICY_ALWAYS</hscrollbar_policy> - <vscrollbar_policy>GTK_POLICY_ALWAYS</vscrollbar_policy> - <hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy> - <vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy> - - <widget> - <class>GtkCList</class> - <name>clist2</name> - <can_focus>True</can_focus> - <columns>1</columns> - <column_widths>80</column_widths> - <selection_mode>GTK_SELECTION_SINGLE</selection_mode> - <show_titles>False</show_titles> - <shadow_type>GTK_SHADOW_NONE</shadow_type> - - <widget> - <class>GtkLabel</class> - <child_name>CList:title</child_name> - <name>label2</name> - <label>label2</label> - <justify>GTK_JUSTIFY_CENTER</justify> - <wrap>False</wrap> - <xalign>0.5</xalign> - <yalign>0.5</yalign> - <xpad>0</xpad> - <ypad>0</ypad> - </widget> - </widget> - </widget> - </widget> - - <widget> - <class>GtkVBox</class> - <name>vbox1</name> - <border_width>4</border_width> - <homogeneous>False</homogeneous> - <spacing>0</spacing> - <child> - <left_attach>1</left_attach> - <right_attach>2</right_attach> - <top_attach>0</top_attach> - <bottom_attach>1</bottom_attach> - <xpad>4</xpad> - <ypad>4</ypad> - <xexpand>True</xexpand> - <yexpand>False</yexpand> - <xshrink>False</xshrink> - <yshrink>False</yshrink> - <xfill>False</xfill> - <yfill>True</yfill> - </child> - - <widget> - <class>GtkButton</class> - <name>button1</name> - <border_width>4</border_width> - <can_focus>True</can_focus> - <label>Add >></label> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - - <widget> - <class>GtkButton</class> - <name>button2</name> - <border_width>4</border_width> - <can_focus>True</can_focus> - <label><< Remove</label> - <child> - <padding>0</padding> - <expand>False</expand> - <fill>False</fill> - </child> - </widget> - </widget> - </widget> -</widget> - -</GTK-Interface> diff --git a/widgets/table/e-table-group.glade.h b/widgets/table/e-table-group.glade.h deleted file mode 100644 index 3ab6304734..0000000000 --- a/widgets/table/e-table-group.glade.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Translatable strings file generated by Glade. - * Add this file to your project's POTFILES.in. - * DO NOT compile it as part of your application. - */ - -gchar *s = N_("window1"); -gchar *s = N_("Available fields"); -gchar *s = N_("label1"); -gchar *s = N_("Show in this order"); -gchar *s = N_("label2"); -gchar *s = N_("Add >>"); -gchar *s = N_("<< Remove"); diff --git a/widgets/table/e-table-group.h b/widgets/table/e-table-group.h deleted file mode 100644 index a3afe7f5e1..0000000000 --- a/widgets/table/e-table-group.h +++ /dev/null @@ -1,135 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_GROUP_H_ -#define _E_TABLE_GROUP_H_ - -#include <libgnomeui/gnome-canvas.h> -#include "e-table-model.h" -#include "e-table-header.h" -#include "e-table-sort-info.h" -#include "e-table-defines.h" -#include "e-util/e-util.h" -#include "e-util/e-printable.h" - -#define E_TABLE_GROUP_TYPE (e_table_group_get_type ()) -#define E_TABLE_GROUP(o) (GTK_CHECK_CAST ((o), E_TABLE_GROUP_TYPE, ETableGroup)) -#define E_TABLE_GROUP_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_GROUP_TYPE, ETableGroupClass)) -#define E_IS_TABLE_GROUP(o) (GTK_CHECK_TYPE ((o), E_TABLE_GROUP_TYPE)) -#define E_IS_TABLE_GROUP_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_GROUP_TYPE)) - -typedef struct { - GnomeCanvasGroup group; - - /* - * The full header. - */ - ETableHeader *full_header; - ETableHeader *header; - - /* - * The model we pull data from. - */ - ETableModel *model; - - /* - * Whether we should add indentation and open/close markers, - * or if we just act as containers of subtables. - */ - guint transparent : 1; - - guint has_focus : 1; - - guint frozen : 1; -} ETableGroup; - -typedef struct { - GnomeCanvasGroupClass parent_class; - - /* Signals */ - void (*cursor_change) (ETableGroup *etg, int row); - void (*double_click) (ETableGroup *etg, int row); - gint (*right_click) (ETableGroup *etg, int row, int col, GdkEvent *event); - gint (*key_press) (ETableGroup *etg, int row, int col, GdkEvent *event); - - /* Virtual functions. */ - void (*add) (ETableGroup *etg, gint row); - void (*add_all) (ETableGroup *etg); - gboolean (*remove) (ETableGroup *etg, gint row); - gint (*get_count) (ETableGroup *etg); - 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); - void (*set_cursor_row) (ETableGroup *etg, gint row); - int (*get_cursor_row) (ETableGroup *etg); - gboolean (*get_focus) (ETableGroup *etg); - gint (*get_focus_column) (ETableGroup *etg); - ETableCol *(*get_ecol) (ETableGroup *etg); - EPrintable *(*get_printable) (ETableGroup *etg); - void (*compute_location) (ETableGroup *etg, int *x, int *y, int *row, int *col); - -} ETableGroupClass; - -/* Virtual functions */ -void e_table_group_add (ETableGroup *etg, - gint row); -void e_table_group_add_all (ETableGroup *etg); -gboolean e_table_group_remove (ETableGroup *etg, - gint row); -gint e_table_group_get_count (ETableGroup *etg); -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); -void e_table_group_set_cursor_row (ETableGroup *etg, - gint row); -int e_table_group_get_cursor_row (ETableGroup *etg); -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); -ETableCol *e_table_group_get_ecol (ETableGroup *etg); -EPrintable *e_table_group_get_printable (ETableGroup *etg); -void e_table_group_compute_location (ETableGroup *etg, - int *x, - int *y, - int *row, - int *col); - -ETableGroup *e_table_group_new (GnomeCanvasGroup *parent, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model, - ETableSortInfo *sort_info, - int n); -void e_table_group_construct (GnomeCanvasGroup *parent, - ETableGroup *etg, - ETableHeader *full_header, - ETableHeader *header, - ETableModel *model); - -/* For emitting the signals */ -void e_table_group_cursor_change (ETableGroup *etg, - gint row); -void e_table_group_double_click (ETableGroup *etg, - gint row); -gint e_table_group_right_click (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event); -gint e_table_group_key_press (ETableGroup *etg, - gint row, - gint col, - GdkEvent *event); - -GtkType e_table_group_get_type (void); - -typedef void (*ETableGroupLeafFn) (void *e_table_item, void *closure); -void e_table_group_apply_to_leafs (ETableGroup *etg, - ETableGroupLeafFn fn, void *closure); - -#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 506ad546ca..0000000000 --- a/widgets/table/e-table-header-item.c +++ /dev/null @@ -1,1449 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-column-view.c: A canvas item based view of the ETableColumn. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, 2000 Helix Code, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkdnd.h> -#include <libgnomeui/gnome-canvas.h> -#include <libgnomeui/gnome-canvas-util.h> -#include <libgnomeui/gnome-canvas-polygon.h> -#include <libgnomeui/gnome-canvas-rect-ellipse.h> -#include <gdk-pixbuf/gdk-pixbuf.h> -#include "e-util/e-cursors.h" -#include "e-util/e-xml-utils.h" -#include "e-util/e-popup-menu.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-col-dnd.h" -#include "e-table-defines.h" -#include "e-table-field-chooser-dialog.h" - -#include "add-col.xpm" -#include "remove-col.xpm" -#include "arrow-up.xpm" -#include "arrow-down.xpm" - -enum { - BUTTON_PRESSED, - LAST_SIGNAL -}; - -static guint ethi_signals [LAST_SIGNAL] = { 0, }; - -#define ARROW_DOWN_HEIGHT 16 -#define ARROW_PTR 7 - -/* Defines the tolerance for proximity of the column division to the cursor position */ -#define TOLERANCE 4 - -#define ETHI_RESIZING(x) ((x)->resize_col != -1) - -#define PARENT_OBJECT_TYPE gnome_canvas_item_get_type () - -#define ELEMENTS(x) (sizeof (x) / sizeof (x[0])) - -static GnomeCanvasItemClass *ethi_parent_class; - -static void ethi_drop_table_header (ETableHeaderItem *ethi); - -/* - * They display the arrows for the drop location. - */ - -static GtkWidget *arrow_up, *arrow_down; - -/* - * DnD icons - */ -static GdkColormap *dnd_colormap; -static GdkPixmap *remove_col_pixmap, *remove_col_mask; -static GdkPixmap *add_col_pixmap, *add_col_mask; - -enum { - ARG_0, - ARG_TABLE_HEADER, - ARG_FULL_HEADER, - ARG_DND_CODE, - ARG_TABLE_FONTSET, - ARG_SORT_INFO -}; - -static void -ethi_destroy (GtkObject *object){ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (object); - - ethi_drop_table_header (ethi); - - if (ethi->sort_info){ - if (ethi->sort_info_changed_id) - gtk_signal_disconnect (GTK_OBJECT(ethi->sort_info), ethi->sort_info_changed_id); - if (ethi->group_info_changed_id) - gtk_signal_disconnect (GTK_OBJECT(ethi->sort_info), ethi->group_info_changed_id); - gtk_object_unref (GTK_OBJECT(ethi->sort_info)); - } - - if (GTK_OBJECT_CLASS (ethi_parent_class)->destroy) - (*GTK_OBJECT_CLASS (ethi_parent_class)->destroy) (object); -} - -static void -ethi_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - - double i2c [6]; - ArtPoint c1, c2, i1, i2; - - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->update) - (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->update)(item, affine, clip_path, flags); - - - if (ethi->sort_info) - ethi->group_indent_width = e_table_sort_info_grouping_get_count(ethi->sort_info) * GROUP_INDENT; - else - ethi->group_indent_width = 0; - - ethi->width = e_table_header_total_width (ethi->eth) + ethi->group_indent_width; - - i1.x = i1.y = 0; - i2.x = ethi->width; - i2.y = ethi->height; - - gnome_canvas_item_i2c_affine (item, i2c); - art_affine_point (&c1, &i1, i2c); - art_affine_point (&c2, &i2, i2c); - - if (item->x1 != c1.x || - item->y1 != c1.y || - item->x2 != c2.x || - item->y2 != c2.y) - { - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); - item->x1 = c1.x; - item->y1 = c1.y; - item->x2 = c2.x; - item->y2 = c2.y; - - gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item); - } - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); -} - -static void -ethi_font_load (ETableHeaderItem *ethi, char *font) -{ - if (ethi->font) - gdk_font_unref (ethi->font); - - ethi->font = gdk_fontset_load (font); - if (ethi->font == NULL) - ethi->font = gdk_font_load ("-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-iso8859-1"); - - ethi->height = ethi->font->ascent + ethi->font->descent + HEADER_PADDING; - if (ethi->height < MIN_ARROW_SIZE + 4 + HEADER_PADDING) - ethi->height = MIN_ARROW_SIZE + 4 + HEADER_PADDING; -} - -static void -ethi_drop_table_header (ETableHeaderItem *ethi) -{ - GtkObject *header; - - if (!ethi->eth) - return; - - header = GTK_OBJECT (ethi->eth); - gtk_signal_disconnect (header, ethi->structure_change_id); - gtk_signal_disconnect (header, ethi->dimension_change_id); - - gtk_object_unref (header); - ethi->eth = NULL; - ethi->width = 0; -} - -static void -structure_changed (ETableHeader *header, ETableHeaderItem *ethi) -{ - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(ethi)); -} - -static void -dimension_changed (ETableHeader *header, int col, ETableHeaderItem *ethi) -{ - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(ethi)); -} - -static void -ethi_add_table_header (ETableHeaderItem *ethi, ETableHeader *header) -{ - ethi->eth = header; - gtk_object_ref (GTK_OBJECT (ethi->eth)); - - ethi->structure_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "structure_change", - GTK_SIGNAL_FUNC(structure_changed), ethi); - ethi->dimension_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "dimension_change", - GTK_SIGNAL_FUNC(dimension_changed), ethi); - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(ethi)); -} - -static void -ethi_sort_info_changed (ETableSortInfo *sort_info, ETableHeaderItem *ethi) -{ - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(ethi)); -} - -static void -ethi_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableHeaderItem *ethi; - - item = GNOME_CANVAS_ITEM (o); - ethi = E_TABLE_HEADER_ITEM (o); - - switch (arg_id){ - case ARG_TABLE_HEADER: - ethi_drop_table_header (ethi); - ethi_add_table_header (ethi, E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg))); - break; - - case ARG_FULL_HEADER: - if (ethi->full_header) - gtk_object_unref(GTK_OBJECT(ethi->full_header)); - ethi->full_header = E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg)); - if (ethi->full_header) - gtk_object_ref(GTK_OBJECT(ethi->full_header)); - break; - - case ARG_DND_CODE: - g_free(ethi->dnd_code); - ethi->dnd_code = g_strdup (GTK_VALUE_STRING (*arg)); - break; - - case ARG_TABLE_FONTSET: - ethi_font_load (ethi, GTK_VALUE_STRING (*arg)); - break; - - case ARG_SORT_INFO: - if (ethi->sort_info){ - if (ethi->sort_info_changed_id) - gtk_signal_disconnect ( - GTK_OBJECT(ethi->sort_info), - ethi->sort_info_changed_id); - - if (ethi->group_info_changed_id) - gtk_signal_disconnect ( - GTK_OBJECT(ethi->sort_info), - ethi->group_info_changed_id); - gtk_object_unref (GTK_OBJECT(ethi->sort_info)); - } - ethi->sort_info = GTK_VALUE_POINTER (*arg); - gtk_object_ref (GTK_OBJECT(ethi->sort_info)); - ethi->sort_info_changed_id = - gtk_signal_connect ( - GTK_OBJECT(ethi->sort_info), "sort_info_changed", - GTK_SIGNAL_FUNC(ethi_sort_info_changed), ethi); - ethi->group_info_changed_id = - gtk_signal_connect ( - GTK_OBJECT(ethi->sort_info), "group_info_changed", - GTK_SIGNAL_FUNC(ethi_sort_info_changed), ethi); - break; - - } - gnome_canvas_item_request_update(item); -} - -static void -ethi_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableHeaderItem *ethi; - - ethi = E_TABLE_HEADER_ITEM (o); - - switch (arg_id){ - case ARG_FULL_HEADER: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT (ethi->full_header); - break; - case ARG_DND_CODE: - GTK_VALUE_STRING (*arg) = g_strdup (ethi->dnd_code); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static int -ethi_find_col_by_x (ETableHeaderItem *ethi, int x) -{ - const int cols = e_table_header_count (ethi->eth); - int x1 = 0; - int col; - - if (x < x1) - return -1; - - x1 += ethi->group_indent_width; - - for (col = 0; col < cols; col++){ - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - - if ((x >= x1) && (x <= x1 + ecol->width)) - return col; - - x1 += ecol->width; - } - return -1; -} - -static int -ethi_find_col_by_x_nearest (ETableHeaderItem *ethi, int x) -{ - const int cols = e_table_header_count (ethi->eth); - int x1 = 0; - int col; - - if (x < x1) - return -1; - - x1 += ethi->group_indent_width; - - for (col = 0; col < cols; col++){ - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - - x1 += (ecol->width / 2); - - if (x <= x1) - return col; - - x1 += (ecol->width + 1) / 2; - } - return col; -} - -static void -ethi_remove_drop_marker (ETableHeaderItem *ethi) -{ - if (ethi->drag_mark == -1) - return; - - gtk_widget_hide (arrow_up); - gtk_widget_hide (arrow_down); - - ethi->drag_mark = -1; -} - -static GtkWidget * -make_shapped_window_from_xpm (const char **xpm) -{ - GdkPixbuf *pixbuf; - GdkPixmap *pixmap; - GdkBitmap *bitmap; - GtkWidget *win, *pix; - - pixbuf = gdk_pixbuf_new_from_xpm_data (xpm); - gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &bitmap, 128); - gdk_pixbuf_unref (pixbuf); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - win = gtk_window_new (GTK_WINDOW_POPUP); - pix = gtk_pixmap_new (pixmap, bitmap); - gtk_widget_realize (win); - gtk_container_add (GTK_CONTAINER (win), pix); - gtk_widget_shape_combine_mask (win, bitmap, 0, 0); - gtk_widget_pop_visual (); - gtk_widget_pop_colormap (); - - gdk_pixmap_unref (pixmap); - gdk_bitmap_unref (bitmap); - - return win; -} - -static void -ethi_add_drop_marker (ETableHeaderItem *ethi, int col) -{ - int rx, ry; - int x; - - if (ethi->drag_mark == col) - return; - - ethi->drag_mark = col; - - x = e_table_header_col_diff (ethi->eth, 0, col); - if (col > 0) - x += ethi->group_indent_width; - - if (!arrow_up){ - arrow_up = make_shapped_window_from_xpm (arrow_up_xpm); - arrow_down = make_shapped_window_from_xpm (arrow_down_xpm); - } - - gdk_window_get_origin ( - GTK_WIDGET (GNOME_CANVAS_ITEM (ethi)->canvas)->window, - &rx, &ry); - - gtk_widget_set_uposition (arrow_down, rx + x - ARROW_PTR, ry - ARROW_DOWN_HEIGHT); - gtk_widget_show_all (arrow_down); - - gtk_widget_set_uposition (arrow_up, rx + x - ARROW_PTR, ry + ethi->height); - gtk_widget_show_all (arrow_up); -} - -#define gray50_width 2 -#define gray50_height 2 -static char gray50_bits [] = { - 0x02, 0x01, }; - -static void -ethi_add_destroy_marker (ETableHeaderItem *ethi) -{ - double x1; - - if (ethi->remove_item) - gtk_object_destroy (GTK_OBJECT (ethi->remove_item)); - - if (!ethi->stipple) - ethi->stipple = gdk_bitmap_create_from_data ( - NULL, gray50_bits, gray50_width, gray50_height); - - x1 = (double) e_table_header_col_diff (ethi->eth, 0, ethi->drag_col); - if (ethi->drag_col > 0) - x1 += ethi->group_indent_width; - - ethi->remove_item = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (GNOME_CANVAS_ITEM (ethi)->canvas->root), - gnome_canvas_rect_get_type (), - "x1", x1 + 1, - "y1", (double) 1, - "x2", (double) x1 + e_table_header_col_diff ( - ethi->eth, ethi->drag_col, ethi->drag_col+1) - 2, - - "y2", (double) ethi->height - 2, - "fill_color", "red", - "fill_stipple", ethi->stipple, - NULL); -} - -static void -ethi_remove_destroy_marker (ETableHeaderItem *ethi) -{ - if (!ethi->remove_item) - return; - - gtk_object_destroy (GTK_OBJECT (ethi->remove_item)); - ethi->remove_item = NULL; -} - -#if 0 -static gboolean -moved (ETableHeaderItem *ethi, guint col, guint model_col) -{ - if (col == -1) - return TRUE; - ecol = e_table_header_get_column (ethi->eth, col); - if (ecol->col_idx == model_col) - return FALSE; - if (col > 0) { - ecol = e_table_header_get_column (ethi->eth, col - 1); - if (ecol->col_idx == model_col) - return FALSE; - } - return TRUE; -} -#endif - -static gboolean -ethi_drag_motion (GtkObject *canvas, GdkDragContext *context, - gint x, gint y, guint time, - ETableHeaderItem *ethi) -{ - gdk_drag_status (context, 0, time); - if ((x >= 0) && (x <= (ethi->width)) && - (y >= 0) && (y <= (ethi->height))){ - int col; - - col = ethi_find_col_by_x_nearest (ethi, x); - - if (col == ethi->drag_col || col == ethi->drag_col + 1) { - if (ethi->drag_col != -1) - ethi_remove_destroy_marker (ethi); - - ethi_remove_drop_marker (ethi); - gdk_drag_status (context, context->suggested_action, time); - } - else if (col != -1){ - if (ethi->drag_col != -1) - ethi_remove_destroy_marker (ethi); - - ethi_add_drop_marker (ethi, col); - gdk_drag_status (context, context->suggested_action, time); - } else { - ethi_remove_drop_marker (ethi); - if (ethi->drag_col != -1) - ethi_add_destroy_marker (ethi); - } - } else { - ethi_remove_drop_marker (ethi); - if (ethi->drag_col != -1) - ethi_add_destroy_marker (ethi); - } - - return TRUE; -} - -static void -ethi_drag_end (GtkWidget *canvas, GdkDragContext *context, ETableHeaderItem *ethi) -{ - if (context->action == 0) { - e_table_header_remove (ethi->eth, ethi->drag_col); - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(ethi)); - } - ethi_remove_drop_marker (ethi); - ethi_remove_destroy_marker (ethi); - ethi->drag_col = -1; -} - -static void -ethi_drag_data_received (GtkWidget *canvas, - GdkDragContext *drag_context, - gint x, - gint y, - GtkSelectionData *data, - guint info, - guint time, - ETableHeaderItem *ethi) -{ - int found = FALSE; - int count = e_table_header_count(ethi->eth); - int column = atoi(data->data); - int drop_col = ethi->drop_col; - int i; - ethi->drop_col = -1; - if (column < 0) - return; - for (i = 0; i < count; i++) { - ETableCol *ecol = e_table_header_get_column (ethi->eth, i); - if (ecol->col_idx == column) { - e_table_header_move(ethi->eth, i, drop_col); - found = TRUE; - break; - } - } - if (!found) { - count = e_table_header_count(ethi->full_header); - for (i = 0; i < count; i++) { - ETableCol *ecol = e_table_header_get_column (ethi->full_header, i); - if (ecol->col_idx == column) { - e_table_header_add_column (ethi->eth, ecol, drop_col); - break; - } - } - } - ethi_remove_drop_marker (ethi); - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(ethi)); -} - -static void -ethi_drag_data_get (GtkWidget *canvas, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - ETableHeaderItem *ethi) -{ - if (ethi->drag_col != -1) { - ETableCol *ecol = e_table_header_get_column (ethi->eth, ethi->drag_col); - - gchar *string = g_strdup_printf("%d", ecol->col_idx); - gtk_selection_data_set(selection_data, - GDK_SELECTION_TYPE_STRING, - sizeof(string[0]), - string, - strlen(string)); - g_free(string); - } -} - -static gboolean -ethi_drag_drop (GtkWidget *canvas, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETableHeaderItem *ethi) -{ - gboolean successful = FALSE; - - if ((x >= 0) && (x <= (ethi->width)) && - (y >= 0) && (y <= (ethi->height))){ - int col; - - col = ethi_find_col_by_x_nearest (ethi, x); - - ethi_add_drop_marker (ethi, col); - - ethi->drop_col = col; - - if (col != -1) { - char *target = g_strdup_printf ("%s-%s", TARGET_ETABLE_COL_TYPE, ethi->dnd_code); - gtk_drag_get_data (canvas, context, gdk_atom_intern(target, FALSE), time); - g_free (target); - } - } - gtk_drag_finish (context, successful, successful, time); - return successful; -} - -static void -ethi_drag_leave (GtkWidget *widget, GdkDragContext *context, guint time, ETableHeaderItem *ethi) -{ - ethi_remove_drop_marker (ethi); - if (ethi->drag_col != -1) - ethi_add_destroy_marker (ethi); -} - -static void -ethi_realize (GnomeCanvasItem *item) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - GdkWindow *window; - GdkColor c; - GtkTargetEntry ethi_drop_types [] = { - { TARGET_ETABLE_COL_TYPE, 0, TARGET_ETABLE_COL_HEADER }, - }; - - - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)-> realize) - (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->realize)(item); - - window = GTK_WIDGET (item->canvas)->window; - - ethi->gc = gdk_gc_new (window); - gnome_canvas_get_color (item->canvas, "black", &c); - gdk_gc_set_foreground (ethi->gc, &c); - - if (!ethi->font) - ethi_font_load (ethi, "-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-iso8859-1"); - - /* - * Now, configure DnD - */ - ethi_drop_types[0].target = g_strdup_printf("%s-%s", ethi_drop_types[0].target, ethi->dnd_code); - gtk_drag_dest_set (GTK_WIDGET (item->canvas), 0, - ethi_drop_types, ELEMENTS (ethi_drop_types), - GDK_ACTION_MOVE); - g_free(ethi_drop_types[0].target); - - /* Drop signals */ - ethi->drag_motion_id = gtk_signal_connect (GTK_OBJECT (item->canvas), "drag_motion", - GTK_SIGNAL_FUNC (ethi_drag_motion), ethi); - ethi->drag_leave_id = gtk_signal_connect (GTK_OBJECT (item->canvas), "drag_leave", - GTK_SIGNAL_FUNC (ethi_drag_leave), ethi); - ethi->drag_drop_id = gtk_signal_connect (GTK_OBJECT (item->canvas), "drag_drop", - GTK_SIGNAL_FUNC (ethi_drag_drop), ethi); - ethi->drag_data_received_id = gtk_signal_connect (GTK_OBJECT (item->canvas), "drag_data_received", - GTK_SIGNAL_FUNC (ethi_drag_data_received), ethi); - - /* Drag signals */ - ethi->drag_end_id = gtk_signal_connect (GTK_OBJECT (item->canvas), "drag_end", - GTK_SIGNAL_FUNC (ethi_drag_end), ethi); - ethi->drag_data_get_id = gtk_signal_connect (GTK_OBJECT (item->canvas), "drag_data_get", - GTK_SIGNAL_FUNC (ethi_drag_data_get), ethi); - -} - -static void -ethi_unrealize (GnomeCanvasItem *item) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - - gdk_gc_unref (ethi->gc); - ethi->gc = NULL; - - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_motion_id); - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_leave_id); - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_drop_id); - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_data_received_id); - - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_end_id); - gtk_signal_disconnect (GTK_OBJECT (item->canvas), ethi->drag_data_get_id); - - if (ethi->stipple){ - gdk_bitmap_unref (ethi->stipple); - ethi->stipple = NULL; - } - - if (GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (ethi_parent_class)->unrealize)(item); -} - -static void -draw_button (ETableHeaderItem *ethi, ETableCol *col, - GdkDrawable *drawable, GdkGC *gc, GtkStyle *style, - int x, int y, int width, int height, ETableColArrow arrow) -{ - GdkRectangle clip; - int xtra; - - gdk_draw_rectangle ( - drawable, gc, TRUE, - x + 1, y + 1, width - 2, height -2); - - gtk_draw_shadow ( - style, drawable, - GTK_STATE_NORMAL, GTK_SHADOW_OUT, - x , y, width, height); - - clip.x = x + HEADER_PADDING / 2; - clip.y = y + HEADER_PADDING / 2; - clip.width = width - HEADER_PADDING; - clip.height = ethi->height; - - gdk_gc_set_clip_rectangle (ethi->gc, &clip); - - if (col->is_pixbuf){ - xtra = (clip.width - gdk_pixbuf_get_width (col->pixbuf))/2; - - xtra += HEADER_PADDING / 2; - - gdk_pixbuf_render_to_drawable_alpha (col->pixbuf, - drawable, - 0, 0, - x + xtra, y + (clip.height - gdk_pixbuf_get_height (col->pixbuf)) / 2, - gdk_pixbuf_get_width (col->pixbuf), gdk_pixbuf_get_height(col->pixbuf), - GDK_PIXBUF_ALPHA_FULL, 128, - GDK_RGB_DITHER_NORMAL, - 0, 0); - } else { - /* Center the thing */ - xtra = (clip.width - gdk_string_measure (ethi->font, col->text))/2; - - /* Skip over border */ - if (xtra < 0) - xtra = 0; - - xtra += HEADER_PADDING / 2; - - gdk_draw_text ( - drawable, ethi->font, - ethi->gc, x + xtra, y + ethi->height - ethi->font->descent - HEADER_PADDING / 2, - col->text, strlen (col->text)); - } - - if (col->pixbuf){ - if ((gdk_pixbuf_get_width (col->pixbuf) + MIN_ARROW_SIZE + 4) > width) - return; - } - - switch (arrow){ - case E_TABLE_COL_ARROW_NONE: - break; - - case E_TABLE_COL_ARROW_UP: - case E_TABLE_COL_ARROW_DOWN: - gtk_paint_arrow ( - gtk_widget_get_style (GTK_WIDGET(GNOME_CANVAS_ITEM(ethi)->canvas)), - drawable, - GTK_STATE_NORMAL, - GTK_SHADOW_IN, - &clip, - GTK_WIDGET(GNOME_CANVAS_ITEM(ethi)->canvas), - "header", - (arrow == E_TABLE_COL_ARROW_UP) ? GTK_ARROW_UP : GTK_ARROW_DOWN, - TRUE, - x + HEADER_PADDING / 2 + clip.width - MIN_ARROW_SIZE - 2, - y + (ethi->height - MIN_ARROW_SIZE) / 2, - MIN_ARROW_SIZE, - MIN_ARROW_SIZE); - break; - } -} - -static void -ethi_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - GdkGC *gc; - const int cols = e_table_header_count (ethi->eth); - int x1, x2; - int col; - GHashTable *arrows = g_hash_table_new (NULL, NULL); - - - if (ethi->sort_info) { - int length = e_table_sort_info_grouping_get_count(ethi->sort_info); - int i; - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_grouping_get_nth(ethi->sort_info, i); - g_hash_table_insert (arrows, - (gpointer) column.column, - (gpointer) (column.ascending ? - E_TABLE_COL_ARROW_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, - (gpointer) column.column, - (gpointer) (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; - for (col = 0; col < cols; col++, x1 = x2){ - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - int col_width; - - col_width = ecol->width; - - x2 += col_width; - - if (x1 > (x + width)) - break; - - if (x2 < x) - continue; - - gc = GTK_WIDGET (canvas)->style->bg_gc [GTK_STATE_NORMAL]; - - draw_button (ethi, ecol, drawable, gc, - GTK_WIDGET (canvas)->style, - x1 - x, - y, x2 - x1, ethi->height, - (ETableColArrow) g_hash_table_lookup (arrows, (gpointer) ecol->col_idx)); - } - g_hash_table_destroy (arrows); -} - -static double -ethi_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - return 0.0; -} - -/* - * is_pointer_on_division: - * - * Returns whether @pos is a column header division; If @the_total is not NULL, - * then the actual position is returned here. If @return_ecol is not NULL, - * then the ETableCol that actually contains this point is returned here - */ -static gboolean -is_pointer_on_division (ETableHeaderItem *ethi, int pos, int *the_total, int *return_col) -{ - const int cols = e_table_header_count (ethi->eth); - int col, total; - - total = 0; - for (col = 0; col < cols; col++){ - ETableCol *ecol = e_table_header_get_column (ethi->eth, col); - - if (col == 0) - total += ethi->group_indent_width; - - total += ecol->width; - - if ((total - TOLERANCE < pos)&& (pos < total + TOLERANCE)){ - if (return_col) - *return_col = col; - if (the_total) - *the_total = total; - - return TRUE; - } - - if (total > pos + TOLERANCE) - return FALSE; - } - - return FALSE; -} - -#define convert(c,sx,sy,x,y) gnome_canvas_w2c (c,sx,sy,x,y) - -static void -set_cursor (ETableHeaderItem *ethi, int pos) -{ - GtkWidget *canvas = GTK_WIDGET (GNOME_CANVAS_ITEM (ethi)->canvas); - - /* We might be invoked before we are realized */ - if (!canvas->window) - return; - - if (is_pointer_on_division (ethi, pos, NULL, NULL)) - e_cursor_set (canvas->window, E_CURSOR_SIZE_X); - else - e_cursor_set (canvas->window, E_CURSOR_ARROW); -} - -static void -ethi_end_resize (ETableHeaderItem *ethi) -{ - ethi->resize_col = -1; - ethi->resize_guide = GINT_TO_POINTER (0); - - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(ethi)); -} - -static gboolean -ethi_maybe_start_drag (ETableHeaderItem *ethi, GdkEventMotion *event) -{ - if (!ethi->maybe_drag) - return FALSE; - - if (ethi->eth->col_count < 2) - return FALSE; - - if (MAX (abs (ethi->click_x - event->x), - abs (ethi->click_y - event->y)) <= 3) - return FALSE; - - return TRUE; -} - -static void -ethi_start_drag (ETableHeaderItem *ethi, GdkEvent *event) -{ - GtkWidget *widget = GTK_WIDGET (GNOME_CANVAS_ITEM (ethi)->canvas); - GtkTargetList *list; - GdkDragContext *context; - ETableCol *ecol; - int col_width; - GdkPixmap *pixmap; - GdkGC *gc; - int group_indent = 0; - GHashTable *arrows = g_hash_table_new (NULL, NULL); - - GtkTargetEntry ethi_drag_types [] = { - { TARGET_ETABLE_COL_TYPE, 0, TARGET_ETABLE_COL_HEADER }, - }; - - ethi->drag_col = ethi_find_col_by_x (ethi, event->motion.x); - - if (ethi->drag_col == -1) - return; - - if (ethi->sort_info) { - int length = e_table_sort_info_grouping_get_count(ethi->sort_info); - int i; - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_grouping_get_nth(ethi->sort_info, i); - group_indent ++; - g_hash_table_insert (arrows, - (gpointer) column.column, - (gpointer) (column.ascending ? - E_TABLE_COL_ARROW_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, - (gpointer) column.column, - (gpointer) (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, ELEMENTS (ethi_drag_types)); - context = gtk_drag_begin (widget, list, GDK_ACTION_MOVE, 1, event); - g_free(ethi_drag_types[0].target); - - ecol = e_table_header_get_column (ethi->eth, ethi->drag_col); - col_width = ecol->width; - pixmap = gdk_pixmap_new (widget->window, col_width, ethi->height, -1); - gc = widget->style->bg_gc [GTK_STATE_ACTIVE]; - draw_button (ethi, ecol, pixmap, gc, - widget->style, - 0, 0, col_width, ethi->height, - (ETableColArrow) g_hash_table_lookup (arrows, (gpointer) ecol->col_idx)); - gtk_drag_set_icon_pixmap (context, - gdk_window_get_colormap (widget->window), - pixmap, - NULL, - col_width / 2, - ethi->height / 2); - gdk_pixmap_unref (pixmap); - - ethi->maybe_drag = FALSE; - g_hash_table_destroy (arrows); -} - -typedef struct { - ETableHeaderItem *ethi; - int col; -} EthiHeaderInfo; - -static void -ethi_popup_sort_ascending(GtkWidget *widget, EthiHeaderInfo *info) -{ - ETableCol *col; - int model_col; - int length; - int i; - int found = FALSE; - ETableHeaderItem *ethi = info->ethi; - - col = e_table_header_get_column (ethi->eth, info->col); - model_col = col->col_idx; - - length = e_table_sort_info_grouping_get_count(ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_grouping_get_nth(ethi->sort_info, i); - if (model_col == column.column){ - column.ascending = 1; - e_table_sort_info_grouping_set_nth(ethi->sort_info, i, column); - found = 1; - break; - } - } - if (!found) { - length = e_table_sort_info_sorting_get_count(ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(ethi->sort_info, i); - if (model_col == column.column){ - column.ascending = 1; - e_table_sort_info_sorting_set_nth(ethi->sort_info, i, column); - found = 1; - break; - } - } - } - if (!found) { - ETableSortColumn column = { model_col, 1 }; - length = e_table_sort_info_sorting_get_count(ethi->sort_info); - if (length == 0) - length++; - e_table_sort_info_sorting_set_nth(ethi->sort_info, length - 1, column); - } -} - -static void -ethi_popup_sort_descending(GtkWidget *widget, EthiHeaderInfo *info) -{ - ETableCol *col; - int model_col; - int length; - int i; - int found = FALSE; - ETableHeaderItem *ethi = info->ethi; - - col = e_table_header_get_column (ethi->eth, info->col); - model_col = col->col_idx; - - length = e_table_sort_info_grouping_get_count(ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_grouping_get_nth(ethi->sort_info, i); - if (model_col == column.column){ - column.ascending = 0; - e_table_sort_info_grouping_set_nth(ethi->sort_info, i, column); - found = 1; - break; - } - } - if (!found) { - length = e_table_sort_info_sorting_get_count(ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(ethi->sort_info, i); - if (model_col == column.column){ - column.ascending = 0; - e_table_sort_info_sorting_set_nth(ethi->sort_info, i, column); - found = 1; - break; - } - } - } - if (!found) { - ETableSortColumn column = { model_col, 0 }; - length = e_table_sort_info_sorting_get_count(ethi->sort_info); - if (length == 0) - length++; - e_table_sort_info_sorting_set_nth(ethi->sort_info, length - 1, column); - } -} - -static void -ethi_popup_unsort(GtkWidget *widget, EthiHeaderInfo *info) -{ - ETableHeaderItem *ethi = info->ethi; - - e_table_sort_info_grouping_truncate(ethi->sort_info, 0); - e_table_sort_info_sorting_truncate(ethi->sort_info, 0); -} - -static void -ethi_popup_group_field(GtkWidget *widget, EthiHeaderInfo *info) -{ - ETableCol *col; - int model_col; - ETableHeaderItem *ethi = info->ethi; - ETableSortColumn column; - - col = e_table_header_get_column (ethi->eth, info->col); - model_col = col->col_idx; - - column.column = model_col; - column.ascending = 1; - e_table_sort_info_grouping_set_nth(ethi->sort_info, 0, column); - e_table_sort_info_grouping_truncate(ethi->sort_info, 1); -} - -static void -ethi_popup_group_box(GtkWidget *widget, EthiHeaderInfo *info) -{ -} - -static void -ethi_popup_remove_column(GtkWidget *widget, EthiHeaderInfo *info) -{ - e_table_header_remove(info->ethi->eth, info->col); -} - -static void -ethi_popup_field_chooser(GtkWidget *widget, EthiHeaderInfo *info) -{ - GtkWidget *etfcd = e_table_field_chooser_dialog_new(); - gtk_object_set(GTK_OBJECT(etfcd), - "full_header", info->ethi->full_header, - "dnd_code", info->ethi->dnd_code, - NULL); - gtk_widget_show(etfcd); -} - -static void -ethi_popup_alignment(GtkWidget *widget, EthiHeaderInfo *info) -{ -} - -static void -ethi_popup_best_fit(GtkWidget *widget, EthiHeaderInfo *info) -{ -} - -static void -ethi_popup_format_columns(GtkWidget *widget, EthiHeaderInfo *info) -{ -} - -static void -ethi_popup_customize_view(GtkWidget *widget, EthiHeaderInfo *info) -{ -} - -/* Bit 1 is always disabled. */ -/* Bit 2 is disabled if not "sortable". */ -static EPopupMenu ethi_context_menu [] = { - { N_("Sort Ascending"), NULL, GTK_SIGNAL_FUNC(ethi_popup_sort_ascending), 2}, - { N_("Sort Descending"), NULL, GTK_SIGNAL_FUNC(ethi_popup_sort_descending), 2}, - { N_("Unsort"), NULL, GTK_SIGNAL_FUNC(ethi_popup_unsort), 0}, - { "", NULL, GTK_SIGNAL_FUNC(NULL), 0}, - { N_("Group By This Field"), NULL, GTK_SIGNAL_FUNC(ethi_popup_group_field), 0}, - { N_("Group By Box"), NULL, GTK_SIGNAL_FUNC(ethi_popup_group_box), 1}, - { "", NULL, GTK_SIGNAL_FUNC(NULL), 1}, - { N_("Remove This Column"), NULL, GTK_SIGNAL_FUNC(ethi_popup_remove_column), 0}, - { N_("Field Chooser"), NULL, GTK_SIGNAL_FUNC(ethi_popup_field_chooser), 0}, - { "", NULL, GTK_SIGNAL_FUNC(NULL), 1}, - { N_("Alignment"), NULL, GTK_SIGNAL_FUNC(ethi_popup_alignment), 1}, - { N_("Best Fit"), NULL, GTK_SIGNAL_FUNC(ethi_popup_best_fit), 1}, - { N_("Format Columns..."), NULL, GTK_SIGNAL_FUNC(ethi_popup_format_columns), 1}, - { "", NULL, GTK_SIGNAL_FUNC(NULL), 1}, - { N_("Customize Current View..."), NULL, GTK_SIGNAL_FUNC(ethi_popup_customize_view), 1}, - { NULL, NULL, NULL, 0 } -}; - -static void -ethi_header_context_menu (ETableHeaderItem *ethi, GdkEventButton *event) -{ - EthiHeaderInfo *info = g_new(EthiHeaderInfo, 1); - ETableCol *col; - info->ethi = ethi; - info->col = ethi_find_col_by_x (ethi, event->x); - col = e_table_header_get_column (ethi->eth, info->col); - e_popup_menu_run (ethi_context_menu, event, 1 + (col->sortable ? 0 : 2), 0, info); -} - -static void -ethi_button_pressed (ETableHeaderItem *ethi, GdkEventButton *event) -{ - gtk_signal_emit (GTK_OBJECT (ethi), - ethi_signals [BUTTON_PRESSED], event); -} - -/* - * Handles the events on the ETableHeaderItem, particularly it handles resizing - */ -static int -ethi_event (GnomeCanvasItem *item, GdkEvent *e) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - GnomeCanvas *canvas = item->canvas; - const gboolean resizing = ETHI_RESIZING (ethi); - int x, y, start, col; - int was_maybe_drag = 0; - - switch (e->type){ - case GDK_ENTER_NOTIFY: - convert (canvas, e->crossing.x, e->crossing.y, &x, &y); - set_cursor (ethi, x); - break; - - case GDK_LEAVE_NOTIFY: - e_cursor_set (GTK_WIDGET (canvas)->window, E_CURSOR_ARROW); - break; - - case GDK_MOTION_NOTIFY: - - convert (canvas, e->motion.x, e->motion.y, &x, &y); - if (resizing){ - int new_width; - - if (ethi->resize_guide == NULL){ - /* Quick hack until I actually bind the views */ - ethi->resize_guide = GINT_TO_POINTER (1); - - gnome_canvas_item_grab (item, - GDK_POINTER_MOTION_MASK | - GDK_BUTTON_RELEASE_MASK, - e_cursor_get (E_CURSOR_SIZE_X), - e->button.time); - } - - new_width = x - ethi->resize_start_pos; - - e_table_header_set_size (ethi->eth, ethi->resize_col, new_width); - - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(ethi)); - } else if (ethi_maybe_start_drag (ethi, &e->motion)){ - ethi_start_drag (ethi, e); - } else - set_cursor (ethi, x); - break; - - case GDK_BUTTON_PRESS: - if (e->button.button > 3) - return FALSE; - - convert (canvas, e->button.x, e->button.y, &x, &y); - - if (is_pointer_on_division (ethi, x, &start, &col) && e->button.button == 1){ - ETableCol *ecol; - - /* - * Record the important bits. - * - * By setting resize_pos to a non -1 value, - * we know that we are being resized (used in the - * other event handlers). - */ - ecol = e_table_header_get_column (ethi->eth, col); - - if (!ecol->resizeable) - break; - ethi->resize_col = col; - ethi->resize_start_pos = start - ecol->width; - ethi->resize_min_width = ecol->min_width; - } else { - if (e->button.button == 1){ - ethi->click_x = e->button.x; - ethi->click_y = e->button.y; - ethi->maybe_drag = TRUE; - } else if (e->button.button == 3){ - ethi_header_context_menu (ethi, &e->button); - } else - ethi_button_pressed (ethi, &e->button); - } - break; - - case GDK_2BUTTON_PRESS: - if (!resizing) - break; - - if (e->button.button != 1) - break; - 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 *col; - int model_col; - int length; - int i; - int found = FALSE; - - col = e_table_header_get_column (ethi->eth, ethi_find_col_by_x (ethi, e->button.x)); - model_col = col->col_idx; - - length = e_table_sort_info_grouping_get_count(ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_grouping_get_nth(ethi->sort_info, i); - if (model_col == column.column){ - int ascending = column.ascending; - ascending = ! ascending; - column.ascending = ascending; - e_table_sort_info_grouping_set_nth(ethi->sort_info, i, column); - found = 1; - break; - } - } - if(col->sortable) { - if (!found) { - length = e_table_sort_info_sorting_get_count(ethi->sort_info); - for (i = 0; i < length; i++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(ethi->sort_info, i); - if (model_col == column.column){ - int ascending = column.ascending; - ascending = ! ascending; - column.ascending = ascending; - e_table_sort_info_sorting_set_nth(ethi->sort_info, i, column); - found = 1; - break; - } - } - } - if (!found) { - ETableSortColumn column = { model_col, 1 }; - length = e_table_sort_info_sorting_get_count(ethi->sort_info); - if (length == 0) - length++; - e_table_sort_info_sorting_set_nth(ethi->sort_info, length - 1, column); - } - } - } - - if (needs_ungrab) - gnome_canvas_item_ungrab (item, e->button.time); - - break; - } - - default: - return FALSE; - } - return TRUE; -} - -static void -ethi_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - - ethi_parent_class = gtk_type_class (PARENT_OBJECT_TYPE); - - object_class->destroy = ethi_destroy; - object_class->set_arg = ethi_set_arg; - object_class->get_arg = ethi_get_arg; - - item_class->update = ethi_update; - item_class->realize = ethi_realize; - item_class->unrealize = ethi_unrealize; - item_class->draw = ethi_draw; - item_class->point = ethi_point; - item_class->event = ethi_event; - - gtk_object_add_arg_type ("ETableHeaderItem::ETableHeader", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_TABLE_HEADER); - gtk_object_add_arg_type ("ETableHeaderItem::full_header", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_FULL_HEADER); - gtk_object_add_arg_type ("ETableHeaderItem::dnd_code", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_DND_CODE); - gtk_object_add_arg_type ("ETableHeaderItem::fontset", GTK_TYPE_STRING, - GTK_ARG_WRITABLE, ARG_TABLE_FONTSET); - gtk_object_add_arg_type ("ETableHeaderItem::sort_info", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_SORT_INFO); - - /* - * Create our pixmaps for DnD - */ - dnd_colormap = gtk_widget_get_default_colormap (); - remove_col_pixmap = gdk_pixmap_colormap_create_from_xpm_d ( - NULL, dnd_colormap, - &remove_col_mask, NULL, remove_col_xpm); - - add_col_pixmap = gdk_pixmap_colormap_create_from_xpm_d ( - NULL, dnd_colormap, - &add_col_mask, NULL, add_col_xpm); - - ethi_signals [BUTTON_PRESSED] = - gtk_signal_new ("button_pressed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableHeaderItemClass, button_pressed), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, GTK_TYPE_POINTER); - -} - -static void -ethi_init (GnomeCanvasItem *item) -{ - ETableHeaderItem *ethi = E_TABLE_HEADER_ITEM (item); - - ethi->resize_col = -1; - - item->x1 = 0; - item->y1 = 0; - item->x2 = 0; - item->y2 = 0; - - ethi->drag_col = -1; - ethi->drag_mark = -1; - - ethi->sort_info = NULL; - - ethi->sort_info_changed_id = 0; - ethi->group_info_changed_id = 0; - - ethi->group_indent_width = 0; -} - -GtkType -e_table_header_item_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableHeaderItem", - sizeof (ETableHeaderItem), - sizeof (ETableHeaderItemClass), - (GtkClassInitFunc) ethi_class_init, - (GtkObjectInitFunc) ethi_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_OBJECT_TYPE, &info); - } - - return type; -} diff --git a/widgets/table/e-table-header-item.h b/widgets/table/e-table-header-item.h deleted file mode 100644 index 15b627bfa9..0000000000 --- a/widgets/table/e-table-header-item.h +++ /dev/null @@ -1,76 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_HEADER_ITEM_H_ -#define _E_TABLE_HEADER_ITEM_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gnome-xml/tree.h> -#include "e-table-header.h" -#include "e-table-sort-info.h" - -#define E_TABLE_HEADER_ITEM_TYPE (e_table_header_item_get_type ()) -#define E_TABLE_HEADER_ITEM(o) (GTK_CHECK_CAST ((o), E_TABLE_HEADER_ITEM_TYPE, ETableHeaderItem)) -#define E_TABLE_HEADER_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_HEADER_ITEM_TYPE, ETableHeaderItemClass)) -#define E_IS_TABLE_HEADER_ITEM(o) (GTK_CHECK_TYPE ((o), E_TABLE_HEADER_ITEM_TYPE)) -#define E_IS_TABLE_HEADER_ITEM_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_HEADER_ITEM_TYPE)) - -typedef struct { - GnomeCanvasItem parent; - ETableHeader *eth; - - GdkGC *gc; - GdkCursor *change_cursor; - - short height, width; - GdkFont *font; - - /* - * Used during resizing; Could be shorts - */ - int resize_col; - int resize_start_pos; - int resize_min_width; - - GtkObject *resize_guide; - - int group_indent_width; - - /* - * Ids - */ - int structure_change_id, dimension_change_id; - - /* - * For dragging columns - */ - guint maybe_drag:1; - guint dnd_ready:1; - int click_x, click_y; - int drag_col, drop_col, drag_mark; - guint drag_motion_id, drag_end_id, drag_leave_id, drag_drop_id, drag_data_received_id, drag_data_get_id; - guint sort_info_changed_id, group_info_changed_id; - GnomeCanvasItem *remove_item; - GdkBitmap *stipple; - - gchar *dnd_code; - - /* - * For column sorting info - */ - ETableSortInfo *sort_info; - - /* For adding fields. */ - ETableHeader *full_header; -} ETableHeaderItem; - -typedef struct { - GnomeCanvasItemClass parent_class; - - /* - * signals - */ - void (*button_pressed) (ETableHeaderItem *ethi, GdkEventButton *button); -} ETableHeaderItemClass; - -GtkType e_table_header_item_get_type (void); - -#endif /* _E_TABLE_HEADER_ITEM_H_ */ diff --git a/widgets/table/e-table-header.c b/widgets/table/e-table-header.c deleted file mode 100644 index fddda13da8..0000000000 --- a/widgets/table/e-table-header.c +++ /dev/null @@ -1,665 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-col-head.c: TableColHead implementation - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc - */ -#include <config.h> -#include <string.h> -#include <gtk/gtkobject.h> -#include <gtk/gtksignal.h> -#include "e-table-header.h" -#include "e-table-defines.h" - -/* The arguments we take */ -enum { - ARG_0, - ARG_SORT_INFO, - ARG_WIDTH, -}; - -enum { - STRUCTURE_CHANGE, - DIMENSION_CHANGE, - LAST_SIGNAL -}; - -static void eth_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void eth_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void eth_do_remove (ETableHeader *eth, int idx, gboolean do_unref); -static void eth_set_width(ETableHeader *eth, int width); -static void eth_set_size (ETableHeader *eth, int idx, int size); -static void eth_calc_widths (ETableHeader *eth); -static void dequeue(ETableHeader *eth, int *column, int *width); - -static guint eth_signals [LAST_SIGNAL] = { 0, }; - -static GtkObjectClass *e_table_header_parent_class; - -struct two_ints { - int column; - int width; -}; - -static gboolean -dequeue_idle(ETableHeader *eth) -{ - int column, width; - dequeue(eth, &column, &width); - while(eth->change_queue && ((struct two_ints *)eth->change_queue->data)->column == column) - dequeue(eth, &column, &width); - if (column == -1) - eth_set_width(eth, width); - else if (column < eth->col_count) - eth_set_size(eth, column, width); - if (eth->change_queue) - return TRUE; - else { - eth_calc_widths(eth); - eth->idle = 0; - return FALSE; - } -} - -static void -enqueue(ETableHeader *eth, int column, int width) -{ - struct two_ints *store; - store = g_new(struct two_ints, 1); - store->column = column; - store->width = width; - - eth->change_tail = g_slist_last(g_slist_append(eth->change_tail, store)); - if (!eth->change_queue) - eth->change_queue = eth->change_tail; - - if (!eth->idle) { - eth->idle = g_idle_add_full(G_PRIORITY_LOW, (GSourceFunc) dequeue_idle, eth, NULL); - } -} - -static void -dequeue(ETableHeader *eth, int *column, int *width) -{ - GSList *head; - struct two_ints *store; - head = eth->change_queue; - eth->change_queue = eth->change_queue->next; - if (!eth->change_queue) - eth->change_tail = NULL; - store = head->data; - g_slist_free_1(head); - if (column) - *column = store->column; - if (width) - *width = store->width; - g_free(store); -} - -static void -eth_destroy (GtkObject *object) -{ - ETableHeader *eth = E_TABLE_HEADER (object); - const int cols = eth->col_count; - int i; - - if (eth->sort_info) { - if (eth->sort_info_group_change_id) - gtk_signal_disconnect(GTK_OBJECT(eth->sort_info), - eth->sort_info_group_change_id); - gtk_object_unref(GTK_OBJECT(eth->sort_info)); - } - - if (eth->idle) - g_source_remove(eth->idle); - g_slist_foreach(eth->change_queue, (GFunc) g_free, NULL); - g_slist_free(eth->change_queue); - - /* - * Destroy columns - */ - for (i = cols - 1; i >= 0; i--){ - eth_do_remove (eth, i, TRUE); - } - - if (e_table_header_parent_class->destroy) - e_table_header_parent_class->destroy (object); -} - -static void -e_table_header_class_init (GtkObjectClass *object_class) -{ - object_class->destroy = eth_destroy; - object_class->set_arg = eth_set_arg; - object_class->get_arg = eth_get_arg; - - - e_table_header_parent_class = (gtk_type_class (gtk_object_get_type ())); - - gtk_object_add_arg_type ("ETableHeader::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ETableHeader::sort_info", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_SORT_INFO); - - eth_signals [STRUCTURE_CHANGE] = - gtk_signal_new ("structure_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableHeaderClass, structure_change), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - eth_signals [DIMENSION_CHANGE] = - gtk_signal_new ("dimension_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableHeaderClass, dimension_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, eth_signals, LAST_SIGNAL); -} - -static void -e_table_header_init (ETableHeader *eth) -{ - eth->col_count = 0; - eth->width = 0; - - eth->sort_info = NULL; - eth->sort_info_group_change_id = 0; - - eth->columns = NULL; - eth->selectable = FALSE; - - eth->change_queue = NULL; - eth->change_tail = NULL; -} - -GtkType -e_table_header_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableHeader", - sizeof (ETableHeader), - sizeof (ETableHeaderClass), - (GtkClassInitFunc) e_table_header_class_init, - (GtkObjectInitFunc) e_table_header_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &info); - } - - return type; -} - -ETableHeader * -e_table_header_new (void) -{ - ETableHeader *eth; - - eth = gtk_type_new (e_table_header_get_type ()); - - return eth; -} - -static void -eth_group_info_changed(ETableSortInfo *info, ETableHeader *eth) -{ - enqueue(eth, -1, eth->nominal_width); -} - -static void -eth_set_width(ETableHeader *eth, int width) -{ - eth->width = width; -} - -static void -eth_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableHeader *eth = E_TABLE_HEADER (object); - - switch (arg_id) { - case ARG_WIDTH: - eth->nominal_width = GTK_VALUE_DOUBLE (*arg); - enqueue(eth, -1, GTK_VALUE_DOUBLE (*arg)); - break; - case ARG_SORT_INFO: - if (eth->sort_info) { - if (eth->sort_info_group_change_id) - gtk_signal_disconnect(GTK_OBJECT(eth->sort_info), eth->sort_info_group_change_id); - gtk_object_unref(GTK_OBJECT(eth->sort_info)); - } - eth->sort_info = E_TABLE_SORT_INFO(GTK_VALUE_OBJECT (*arg)); - if (eth->sort_info) { - gtk_object_ref(GTK_OBJECT(eth->sort_info)); - eth->sort_info_group_change_id - = gtk_signal_connect(GTK_OBJECT(eth->sort_info), "group_info_changed", - GTK_SIGNAL_FUNC(eth_group_info_changed), eth); - } - enqueue(eth, -1, eth->nominal_width); - break; - default: - break; - } -} - -static void -eth_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETableHeader *eth = E_TABLE_HEADER (object); - - switch (arg_id) { - case ARG_SORT_INFO: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(eth->sort_info); - break; - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = eth->nominal_width; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -eth_update_offsets (ETableHeader *eth) -{ - int i; - int x = 0; - - for (i = 0; i < eth->col_count; i++){ - ETableCol *etc = eth->columns [i]; - - etc->x = x; - x += etc->width; - } -} - -static void -eth_do_insert (ETableHeader *eth, int pos, ETableCol *val) -{ - memmove (ð->columns [pos+1], ð->columns [pos], - sizeof (ETableCol *) * (eth->col_count - pos)); - eth->columns [pos] = val; - eth->col_count ++; -} - -void -e_table_header_add_column (ETableHeader *eth, ETableCol *tc, int pos) -{ - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (tc != NULL); - g_return_if_fail (E_IS_TABLE_COL (tc)); - g_return_if_fail (pos >= -1 && pos <= eth->col_count); - - if (pos == -1) - pos = eth->col_count; - eth->columns = g_realloc (eth->columns, sizeof (ETableCol *) * (eth->col_count + 1)); - - /* - * We are the primary owners of the column - */ - gtk_object_ref (GTK_OBJECT (tc)); - gtk_object_sink (GTK_OBJECT (tc)); - - eth_do_insert (eth, pos, tc); - - enqueue(eth, -1, eth->nominal_width); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [STRUCTURE_CHANGE]); -} - -ETableCol * -e_table_header_get_column (ETableHeader *eth, int column) -{ - g_return_val_if_fail (eth != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), NULL); - - if (column < 0) - return NULL; - - if (column >= eth->col_count) - return NULL; - - return eth->columns [column]; -} - -int -e_table_header_count (ETableHeader *eth) -{ - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - return eth->col_count; -} - -int -e_table_header_index (ETableHeader *eth, int col) -{ - g_return_val_if_fail (eth != NULL, -1); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), -1); - g_return_val_if_fail (col < eth->col_count, -1); - - return eth->columns [col]->col_idx; -} - -int -e_table_header_get_index_at (ETableHeader *eth, int x_offset) -{ - int i, total; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - total = 0; - for (i = 0; i < eth->col_count; i++){ - total += eth->columns [i]->width; - - if (x_offset < total) - return i; - } - - return -1; -} - -ETableCol ** -e_table_header_get_columns (ETableHeader *eth) -{ - ETableCol **ret; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - ret = g_new (ETableCol *, eth->col_count + 1); - memcpy (ret, eth->columns, sizeof (ETableCol *) * eth->col_count); - ret [eth->col_count] = NULL; - - return ret; -} - -gboolean -e_table_header_selection_ok (ETableHeader *eth) -{ - g_return_val_if_fail (eth != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), FALSE); - - return eth->selectable; -} - -int -e_table_header_get_selected (ETableHeader *eth) -{ - int i; - int selected = 0; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - for (i = 0; i < eth->col_count; i++){ - if (eth->columns [i]->selected) - selected++; - } - - return selected; -} - -int -e_table_header_total_width (ETableHeader *eth) -{ - int total, i; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - total = 0; - for (i = 0; i < eth->col_count; i++) - total += eth->columns [i]->width; - - return total; -} - -static void -eth_do_remove (ETableHeader *eth, int idx, gboolean do_unref) -{ - if (do_unref) - gtk_object_unref (GTK_OBJECT (eth->columns [idx])); - - memmove (ð->columns [idx], ð->columns [idx+1], - sizeof (ETableCol *) * (eth->col_count - idx - 1)); - eth->col_count--; -} - -void -e_table_header_move (ETableHeader *eth, int source_index, int target_index) -{ - ETableCol *old; - - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (source_index >= 0); - g_return_if_fail (target_index >= 0); - g_return_if_fail (source_index < eth->col_count); - g_return_if_fail (target_index < eth->col_count + 1); /* Can be moved beyond the last item. */ - - if (source_index < target_index) - target_index --; - - old = eth->columns [source_index]; - eth_do_remove (eth, source_index, FALSE); - eth_do_insert (eth, target_index, old); - eth_update_offsets (eth); - - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [DIMENSION_CHANGE]); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [STRUCTURE_CHANGE]); -} - -void -e_table_header_remove (ETableHeader *eth, int idx) -{ - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < eth->col_count); - - eth_do_remove (eth, idx, TRUE); - enqueue(eth, -1, eth->nominal_width); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [STRUCTURE_CHANGE]); -} - -void -e_table_header_set_selection (ETableHeader *eth, gboolean allow_selection) -{ -} - -void -e_table_header_set_size(ETableHeader *eth, int idx, int size) -{ - enqueue(eth, idx, size); -} - -static void -eth_set_size (ETableHeader *eth, int idx, int size) -{ - double expansion; - double old_expansion; - int min_width; - int left_width; - int total_extra; - int expandable_count; - int usable_width; - int i; - g_return_if_fail (eth != NULL); - g_return_if_fail (E_IS_TABLE_HEADER (eth)); - g_return_if_fail (idx >= 0); - g_return_if_fail (idx < eth->col_count); - - /* If this column is not resizable, don't do anything. */ - if (!eth->columns[idx]->resizeable) - return; - - expansion = 0; - min_width = 0; - left_width = 0; - expandable_count = -1; - - /* Calculate usable area. */ - for (i = 0; i < idx; i++) { - left_width += eth->columns[i]->width; - } - /* - 1 to account for the last pixel border. */ - usable_width = eth->width - left_width - 1; - - if (eth->sort_info) - usable_width -= e_table_sort_info_grouping_get_count(eth->sort_info) * GROUP_INDENT; - - /* Calculate minimum_width of stuff on the right as well as - * total usable expansion on the right. - */ - for (; i < eth->col_count; i++) { - min_width += eth->columns[i]->min_width; - if (eth->columns[i]->resizeable) { - expansion += eth->columns[i]->expansion; - expandable_count ++; - } - } - /* If there's no room for anything, don't change. */ - if (expansion == 0) - return; - - /* (1) If none of the columns to the right are expandable, use - * all the expansion space in this column. - */ - if(expandable_count == 0) { - eth->columns[idx]->expansion = expansion; - for (i = idx + 1; i < eth->col_count; i++) { - eth->columns[i]->expansion = 0; - } - return; - } - - total_extra = usable_width - min_width; - /* If there's no extra space, set all expansions to 0. */ - if (total_extra <= 0) { - for (i = idx; i < eth->col_count; i++) { - eth->columns[i]->expansion = 0; - } - return; - } - - /* If you try to resize smaller than the minimum width, it - * uses the minimum. */ - if (size < eth->columns[idx]->min_width) - size = eth->columns[idx]->min_width; - - /* 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->columns[idx]->expansion = expansion; - for (i = idx + 1; i < eth->col_count; i++) { - eth->columns[i]->expansion = 0; - } - return; - } - - /* The old_expansion used by columns to the right. */ - old_expansion = expansion; - old_expansion -= eth->columns[idx]->expansion; - /* Set the new expansion so that it will generate the desired size. */ - eth->columns[idx]->expansion = expansion * (((double)(size - eth->columns[idx]->min_width))/((double)total_extra)); - /* The expansion left for the columns on the right. */ - expansion -= eth->columns[idx]->expansion; - - /* (2) If the old columns to the right didn't have any - * expansion before, expand them evenly. old_expansion > 0 by - * expansion = SUM(i=idx to col_count -1, - * columns[i]->min_width) - columns[idx]->min_width) = - * SUM(non-negatives). - */ - if (old_expansion == 0) { - for (i = idx + 1; i < eth->col_count; i++) { - if (eth->columns[idx]->resizeable) { - /* expandable_count != 0 by (1) */ - eth->columns[i]->expansion = expansion / expandable_count; - } - } - return; - } - - /* Remove from total_extra the amount used for this column. */ - total_extra -= size - eth->columns[idx]->min_width; - for (i = idx + 1; i < eth->col_count; i++) { - if (eth->columns[idx]->resizeable) { - /* old_expansion != 0 by (2) */ - eth->columns[i]->expansion *= expansion / old_expansion; - } - } -} - -int -e_table_header_col_diff (ETableHeader *eth, int start_col, int end_col) -{ - int total, col; - - g_return_val_if_fail (eth != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_HEADER (eth), 0); - - { - if (start_col < 0) - start_col = 0; - if (end_col > eth->col_count) - end_col = eth->col_count; - - total = 0; - for (col = start_col; col < end_col; col++){ - - total += eth->columns [col]->width; - } - } - - return total; -} - -static void -eth_calc_widths (ETableHeader *eth) -{ - int i; - int extra; - double expansion; - int last_position = 0; - double next_position = 0; - int last_resizable = -1; - /* - 1 to account for the last pixel border. */ - extra = eth->width - 1; - expansion = 0; - for (i = 0; i < eth->col_count; i++) { - extra -= eth->columns[i]->min_width; - if (eth->columns[i]->resizeable && eth->columns[i]->expansion > 0) - last_resizable = i; - expansion += eth->columns[i]->resizeable ? eth->columns[i]->expansion : 0; - eth->columns[i]->width = eth->columns[i]->min_width; - } - if (eth->sort_info) - extra -= e_table_sort_info_grouping_get_count(eth->sort_info) * GROUP_INDENT; - if (expansion == 0 || extra <= 0) - return; - for (i = 0; i < last_resizable; i++) { - next_position += extra * (eth->columns[i]->resizeable ? eth->columns[i]->expansion : 0)/expansion; - eth->columns[i]->width += next_position - last_position; - last_position = next_position; - } - eth->columns[i]->width += extra - last_position; - - eth_update_offsets (eth); - gtk_signal_emit (GTK_OBJECT (eth), eth_signals [DIMENSION_CHANGE]); -} diff --git a/widgets/table/e-table-header.h b/widgets/table/e-table-header.h deleted file mode 100644 index 0dcce14b1e..0000000000 --- a/widgets/table/e-table-header.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_COLUMN_H_ -#define _E_TABLE_COLUMN_H_ - -#include <gtk/gtkobject.h> -#include <gdk/gdk.h> -#include "e-table-sort-info.h" -#include "e-table-col.h" - -typedef struct _ETableHeader ETableHeader; - -#define E_TABLE_HEADER_TYPE (e_table_header_get_type ()) -#define E_TABLE_HEADER(o) (GTK_CHECK_CAST ((o), E_TABLE_HEADER_TYPE, ETableHeader)) -#define E_TABLE_HEADER_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_HEADER_TYPE, ETableHeaderClass)) -#define E_IS_TABLE_HEADER(o) (GTK_CHECK_TYPE ((o), E_TABLE_HEADER_TYPE)) -#define E_IS_TABLE_HEADER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_HEADER_TYPE)) - -/* - * A Columnar header. - */ -struct _ETableHeader { - GtkObject base; - - int col_count; - int width; - int nominal_width; - - ETableSortInfo *sort_info; - int sort_info_group_change_id; - - ETableCol **columns; - gboolean selectable; - - GSList *change_queue, *change_tail; - gint idle; -}; - -typedef struct { - GtkObjectClass parent_class; - - void (*structure_change) (ETableHeader *eth); - void (*dimension_change) (ETableHeader *eth, int col); -} ETableHeaderClass; - -GtkType e_table_header_get_type (void); -ETableHeader *e_table_header_new (void); - -void e_table_header_add_column (ETableHeader *eth, - ETableCol *tc, int pos); -ETableCol * e_table_header_get_column (ETableHeader *eth, - int column); -int e_table_header_count (ETableHeader *eth); -int e_table_header_index (ETableHeader *eth, - int col); -int e_table_header_get_index_at (ETableHeader *eth, - int x_offset); -ETableCol **e_table_header_get_columns (ETableHeader *eth); - -gboolean e_table_header_selection_ok (ETableHeader *eth); -int e_table_header_get_selected (ETableHeader *eth); -int e_table_header_total_width (ETableHeader *eth); -void e_table_header_move (ETableHeader *eth, - int source_index, - int target_index); -void e_table_header_remove (ETableHeader *eth, int idx); -void e_table_header_set_size (ETableHeader *eth, int idx, int size); -void e_table_header_set_selection (ETableHeader *eth, - gboolean allow_selection); - -int e_table_header_col_diff (ETableHeader *eth, - int start_col, int end_col); - -void e_table_header_calc_widths (ETableHeader *eth); - -GList *e_table_header_get_selected_indexes (ETableHeader *eth); - - -#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 0f70861f1e..0000000000 --- a/widgets/table/e-table-item.c +++ /dev/null @@ -1,2228 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-item.c: A GnomeCanvasItem that is a view of an ETableModel. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * Copyright 1999, Helix Code, Inc. - * - * TODO: - * Add a border to the thing, so that focusing works properly. - * - */ -#include <config.h> -#include <stdio.h> -#include <gtk/gtksignal.h> -#include <gdk/gdkkeysyms.h> -#include <math.h> -#include "e-table-item.h" -#include "e-table-subset.h" -#include "e-cell.h" -#include "e-util/e-canvas.h" -#include "e-util/e-canvas-utils.h" -#include "e-util/e-util.h" - -#define PARENT_OBJECT_TYPE gnome_canvas_item_get_type () - -#define FOCUSED_BORDER 2 - -static GnomeCanvasItemClass *eti_parent_class; - -enum { - CURSOR_CHANGE, - DOUBLE_CLICK, - RIGHT_CLICK, - KEY_PRESS, - LAST_SIGNAL -}; - -static gint eti_signals [LAST_SIGNAL] = { 0, }; - -enum { - ARG_0, - ARG_TABLE_HEADER, - ARG_TABLE_MODEL, - ARG_TABLE_SELECTION_MODEL, - ARG_TABLE_DRAW_GRID, - ARG_TABLE_DRAW_FOCUS, - ARG_CURSOR_MODE, - ARG_LENGTH_THRESHOLD, - ARG_CURSOR_ROW, - - ARG_MINIMUM_WIDTH, - ARG_WIDTH, - ARG_HEIGHT, -}; - -static int eti_get_height (ETableItem *eti); -static int eti_get_minimum_width (ETableItem *eti); -static int eti_row_height (ETableItem *eti, int row); -static void e_table_item_focus (ETableItem *eti, int col, int row, GdkModifierType state); -static void eti_cursor_change (ETableSelectionModel *selection, int row, int col, ETableItem *eti); -static void eti_selection_change (ETableSelectionModel *selection, ETableItem *eti); -#if 0 -static void eti_request_region_show (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row); -#endif -#define ETI_ROW_HEIGHT(eti,row) ((eti)->height_cache && (eti)->height_cache[(row)] != -1 ? (eti)->height_cache[(row)] : eti_row_height((eti),(row))) - -inline static gint -model_to_view_row(ETableItem *eti, int row) -{ - int i; - if (eti->uses_source_model) { - ETableSubset *etss = E_TABLE_SUBSET(eti->table_model); - if (eti->row_guess >= 0 && eti->row_guess < etss->n_map) { - if (etss->map_table[eti->row_guess] == row) { - return eti->row_guess; - } - } - for (i = 0; i < etss->n_map; i++) { - if (etss->map_table[i] == row) - return i; - } - return -1; - } else - return row; -} - -inline static gint -view_to_model_row(ETableItem *eti, int row) -{ - if (eti->uses_source_model) { - ETableSubset *etss = E_TABLE_SUBSET(eti->table_model); - if (row >= 0 && row < etss->n_map) - return etss->map_table[row]; - else - return -1; - } else - return row; -} - -inline static gint -model_to_view_col(ETableItem *eti, int col) -{ - int i; - for (i = 0; i < eti->cols; i++) { - ETableCol *ecol = e_table_header_get_column (eti->header, i); - if (ecol->col_idx == col) - return i; - } - return -1; -} - -inline static gint -view_to_model_col(ETableItem *eti, int col) -{ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - return ecol->col_idx; -} - -static gboolean -eti_editing (ETableItem *eti) -{ - if (eti->editing_col == -1) - return FALSE; - else - return TRUE; -} - -/* - * During realization, we have to invoke the per-ecell realize routine - * (On our current setup, we have one e-cell per column. - * - * We might want to optimize this to only realize the unique e-cells: - * ie, a strings-only table, uses the same e-cell for every column, and - * we might want to avoid realizing each e-cell. - */ -static void -eti_realize_cell_views (ETableItem *eti) -{ - int i; - - for (i = 0; i < eti->n_cells; i++) - e_cell_realize (eti->cell_views [i]); - eti->cell_views_realized = 1; -} - -static void -eti_attach_cell_views (ETableItem *eti) -{ - int i; - - g_assert (eti->header); - g_assert (eti->table_model); - - /* - * Now realize the various ECells - */ - eti->n_cells = eti->cols; - eti->cell_views = g_new (ECellView *, eti->n_cells); - - for (i = 0; i < eti->n_cells; i++){ - ETableCol *ecol = e_table_header_get_column (eti->header, i); - - eti->cell_views [i] = e_cell_new_view (ecol->ecell, eti->table_model, eti); - } - - eti->needs_compute_height = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); -} - -/* - * During unrealization: we invoke every e-cell (one per column in the current - * setup) to dispose all X resources allocated - */ -static void -eti_unrealize_cell_views (ETableItem *eti) -{ - int i; - - if (eti->cell_views_realized == 0) - return; - - for (i = 0; i < eti->n_cells; i++) - e_cell_unrealize (eti->cell_views [i]); - eti->cell_views_realized = 0; -} - -static void -eti_detach_cell_views (ETableItem *eti) -{ - int i; - - for (i = 0; i < eti->n_cells; i++){ - e_cell_kill_view (eti->cell_views [i]); - eti->cell_views [i] = NULL; - } - - g_free (eti->cell_views); - eti->cell_views = NULL; - eti->n_cells = 0; -} - -static void -eti_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2) -{ - double i2c [6]; - ArtPoint c1, c2, i1, i2; - ETableItem *eti = E_TABLE_ITEM (item); - - /* Wrong BBox's are the source of redraw nightmares */ - - gnome_canvas_item_i2c_affine (GNOME_CANVAS_ITEM (eti), i2c); - - i1.x = eti->x1; - i1.y = eti->y1; - i2.x = eti->x1 + eti->width; - i2.y = eti->y1 + eti->height; - art_affine_point (&c1, &i1, i2c); - art_affine_point (&c2, &i2, i2c); - - *x1 = c1.x; - *y1 = c1.y; - *x2 = c2.x + 1; - *y2 = c2.y + 1; -} - -static void -eti_reflow (GnomeCanvasItem *item, gint flags) -{ - ETableItem *eti = E_TABLE_ITEM (item); - - if (eti->needs_compute_height) { - int new_height = eti_get_height (eti); - - if (new_height != eti->height) { - eti->height = new_height; - e_canvas_item_request_parent_reflow (GNOME_CANVAS_ITEM (eti)); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); - } - eti->needs_compute_height = 0; - } - if (eti->needs_compute_width) { - int new_width = eti_get_minimum_width (eti); - new_width = MAX(new_width, eti->minimum_width); - if (new_width != eti->width) { - eti->width = new_width; - e_canvas_item_request_parent_reflow (GNOME_CANVAS_ITEM (eti)); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); - } - eti->needs_compute_width = 0; - } -} - -/* - * GnomeCanvasItem::update method - */ -static void -eti_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - ArtPoint o1, o2; - ETableItem *eti = E_TABLE_ITEM (item); - - if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->update) - (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->update)(item, affine, clip_path, flags); - - o1.x = item->x1; - o1.y = item->y1; - o2.x = item->x2; - o2.y = item->y2; - - eti_bounds (item, &item->x1, &item->y1, &item->x2, &item->y2); - if (item->x1 != o1.x || - item->y1 != o1.y || - item->x2 != o2.x || - item->y2 != o2.y) { - gnome_canvas_request_redraw (item->canvas, o1.x, o1.y, o2.x, o2.y); - eti->needs_redraw = 1; - } - - if (eti->needs_redraw) { - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, - item->x2, item->y2); - eti->needs_redraw = 0; - } -} - -/* - * eti_remove_table_model: - * - * Invoked to release the table model associated with this ETableItem - */ -static void -eti_remove_table_model (ETableItem *eti) -{ - if (!eti->table_model) - return; - - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_pre_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_row_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_cell_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_row_inserted_id); - gtk_signal_disconnect (GTK_OBJECT (eti->table_model), - eti->table_model_row_deleted_id); - gtk_object_unref (GTK_OBJECT (eti->table_model)); - if (eti->source_model) - gtk_object_unref (GTK_OBJECT (eti->source_model)); - - eti->table_model_pre_change_id = 0; - eti->table_model_change_id = 0; - eti->table_model_row_change_id = 0; - eti->table_model_cell_change_id = 0; - eti->table_model_row_inserted_id = 0; - eti->table_model_row_deleted_id = 0; - eti->table_model = NULL; - eti->source_model = NULL; - eti->uses_source_model = 0; -} - -/* - * eti_remove_table_model: - * - * Invoked to release the table model associated with this ETableItem - */ -static void -eti_remove_table_selection_model (ETableItem *eti) -{ - if (!eti->selection) - return; - - gtk_signal_disconnect (GTK_OBJECT (eti->selection), - eti->selection_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->selection), - eti->cursor_change_id); - gtk_object_unref (GTK_OBJECT (eti->selection)); - - eti->selection_change_id = 0; - eti->cursor_change_id = 0; - eti->selection = NULL; -} - -/* - * eti_remove_header_model: - * - * Invoked to release the header model associated with this ETableItem - */ -static void -eti_remove_header_model (ETableItem *eti) -{ - if (!eti->header) - return; - - gtk_signal_disconnect (GTK_OBJECT (eti->header), - eti->header_structure_change_id); - gtk_signal_disconnect (GTK_OBJECT (eti->header), - eti->header_dim_change_id); - - if (eti->cell_views){ - eti_unrealize_cell_views (eti); - eti_detach_cell_views (eti); - } - gtk_object_unref (GTK_OBJECT (eti->header)); - - - eti->header_structure_change_id = 0; - eti->header_dim_change_id = 0; - eti->header = NULL; -} - -/* - * eti_row_height_real: - * - * Returns the height used by row @row. This does not include the one-pixel - * used as a separator between rows - */ -static int -eti_row_height_real (ETableItem *eti, int row) -{ - const int cols = e_table_header_count (eti->header); - int col; - int h, max_h; - - g_assert (eti->cell_views); - - max_h = 0; - - for (col = 0; col < cols; col++){ - h = e_cell_height (eti->cell_views [col], view_to_model_col(eti, col), col, row); - - if (h > max_h) - max_h = h; - } - return max_h; -} - -static gboolean -height_cache_idle(ETableItem *eti) -{ - int changed = 0; - int i; - if (!eti->height_cache) { - eti->height_cache = g_new(int, eti->rows); - } - for (i = eti->height_cache_idle_count; i < eti->rows; i++) { - if (eti->height_cache[i] == -1) { - eti_row_height(eti, i); - changed ++; - if (changed >= 20) - break; - } - } - if (changed >= 20) { - eti->height_cache_idle_count = i; - return TRUE; - } - eti->height_cache_idle_id = 0; - return FALSE; -} - -static void -free_height_cache (ETableItem *eti) -{ - if (eti->height_cache) - g_free (eti->height_cache); - eti->height_cache = NULL; - eti->height_cache_idle_count = 0; - - if (eti->height_cache_idle_id == 0) - eti->height_cache_idle_id = g_idle_add_full(G_PRIORITY_LOW, (GSourceFunc) height_cache_idle, eti, NULL); -} - -static void -calculate_height_cache (ETableItem *eti) -{ - int i; - free_height_cache(eti); - eti->height_cache = g_new(int, eti->rows); - for (i = 0; i < eti->rows; i++) { - eti->height_cache[i] = -1; - } -} - - -/* - * eti_row_height: - * - * Returns the height used by row @row. This does not include the one-pixel - * used as a separator between rows - */ -static int -eti_row_height (ETableItem *eti, int row) -{ - if (!eti->height_cache) { - calculate_height_cache (eti); - } - if (eti->height_cache[row] == -1) { - eti->height_cache[row] = eti_row_height_real(eti, row); - if (row > 0 && - eti->length_threshold != -1 && - eti->rows > eti->length_threshold && - eti->height_cache[row] != eti_row_height(eti, 0)) { - eti->needs_compute_height = 1; - e_canvas_item_request_reflow(GNOME_CANVAS_ITEM(eti)); - } - } - return eti->height_cache[row]; -} - -/* - * eti_get_height: - * - * Returns the height of the ETableItem. - * - * The ETableItem might compute the whole height by asking every row its - * size. There is a special mode (designed to work when there are too - * many rows in the table that performing the previous step could take - * too long) set by the ETableItem->length_threshold that would determine - * when the height is computed by using the first row as the size for - * every other row in the ETableItem. - */ -static int -eti_get_height (ETableItem *eti) -{ - const int rows = eti->rows; - int row; - int height; - - if (rows == 0) - return 0; - - if (eti->length_threshold != -1){ - if (rows > eti->length_threshold){ - int row_height = eti_row_height(eti, 0); - if (eti->height_cache) { - height = 0; - for (row = 0; row < rows; row++) { - if (eti->height_cache[row] == -1) { - height += (row_height + 1) * (rows - row); - break; - } - else - height += eti->height_cache[row] + 1; - } - } else - height = (eti_row_height (eti, 0) + 1) * rows; - - /* - * 1 pixel at the top - */ - return height + 1; - } - } - - height = 1; - for (row = 0; row < rows; row++) - height += eti_row_height (eti, row) + 1; - - return height; -} - -static int -eti_get_minimum_width (ETableItem *eti) -{ - int width = 0; - int col; - for (col = 0; col < eti->cols; col++){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - width += ecol->min_width; - } - return width; -} - -static void -eti_item_region_redraw (ETableItem *eti, int x0, int y0, int x1, int y1) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (eti); - ArtDRect rect; - double i2c [6]; - - rect.x0 = x0; - rect.y0 = y0; - rect.x1 = x1; - rect.y1 = y1; - - gnome_canvas_item_i2c_affine (item, i2c); - art_drect_affine_transform (&rect, &rect, i2c); - - gnome_canvas_request_redraw (item->canvas, rect.x0, rect.y0, rect.x1, rect.y1); -} - -/* - * Callback routine: invoked before the ETableModel has suffers a change - */ -static void -eti_table_model_pre_change (ETableModel *table_model, ETableItem *eti) -{ - if (eti_editing (eti)) - e_table_item_leave_edit (eti); -} - -/* - * Callback routine: invoked when the ETableModel has suffered a change - */ -static void -eti_table_model_changed (ETableModel *table_model, ETableItem *eti) -{ -#if 0 - int view_row; -#endif - - eti->rows = e_table_model_row_count (eti->table_model); - - free_height_cache(eti); - - eti->needs_compute_height = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); - -#if 0 - view_row = model_to_view_row(eti, eti->cursor_row); - if (view_row >= 0 && eti->cursor_col >= 0) - eti_request_region_show (eti, eti->cursor_col, view_row, eti->cursor_col, view_row); -#endif -} - -/* - * Computes the distance between @start_row and @end_row in pixels - */ -static int -eti_row_diff (ETableItem *eti, int start_row, int end_row) -{ - int row, total; - - total = 0; - - for (row = start_row; row < end_row; row++) - total += eti_row_height (eti, row) + 1; - - return total; -} - -/* - * eti_request_region_redraw: - * - * Request a canvas redraw on the range (start_col, start_row) to (end_col, end_row). - * This is inclusive (ie, you can use: 0,0-0,0 to redraw the first cell). - * - * The @border argument is a number of pixels around the region that should also be queued - * for redraw. This is typically used by the focus routines to queue a redraw for the - * border as well. - */ -static void -eti_request_region_redraw (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row, int border) -{ - int x1, y1, width, height; - - if (eti->rows > 0) { - - x1 = e_table_header_col_diff (eti->header, 0, start_col); - y1 = eti_row_diff (eti, 0, start_row); - width = e_table_header_col_diff (eti->header, start_col, end_col + 1); - height = eti_row_diff (eti, start_row, end_row + 1); - - eti_item_region_redraw (eti, eti->x1 + x1 - border, - eti->y1 + y1 - border, - eti->x1 + x1 + width + 1 + border, - eti->y1 + y1 + height + 1 + border); - } -} - -/* - * eti_request_region_show - * - * Request a canvas show on the range (start_col, start_row) to (end_col, end_row). - * This is inclusive (ie, you can use: 0,0-0,0 to show the first cell). - */ -static void -eti_request_region_show (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row) -{ - int x1, y1, x2, y2; - - x1 = e_table_header_col_diff (eti->header, 0, start_col); - y1 = eti_row_diff (eti, 0, start_row); - x2 = x1 + e_table_header_col_diff (eti->header, start_col, end_col + 1); - y2 = y1 + eti_row_diff (eti, start_row, end_row + 1); - - e_canvas_item_show_area(GNOME_CANVAS_ITEM(eti), x1, y1, x2, y2); -} - -static void -eti_table_model_row_changed (ETableModel *table_model, int row, ETableItem *eti) -{ - if (eti->renderers_can_change_size) { - eti_table_model_changed (table_model, eti); - return; - } - - eti_request_region_redraw (eti, 0, row, eti->cols, row, 0); -} - -static void -eti_table_model_cell_changed (ETableModel *table_model, int col, int row, ETableItem *eti) -{ - if (eti->renderers_can_change_size) { - eti_table_model_changed (table_model, eti); - return; - } - - eti_request_region_redraw (eti, 0, row, eti->cols -1, row, 0); -} - -static void -eti_table_model_row_inserted (ETableModel *table_model, int row, ETableItem *eti) -{ - eti_table_model_changed (table_model, eti); -} - -static void -eti_table_model_row_deleted (ETableModel *table_model, int row, ETableItem *eti) -{ - eti_table_model_changed (table_model, eti); -} - -void -e_table_item_redraw_range (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row) -{ - int border; - int cursor_col, cursor_row; - - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - "cursor_row", &cursor_row, - NULL); - - if ((start_col == cursor_col) || - (end_col == cursor_col) || - (view_to_model_row(eti, start_row) == cursor_row) || - (view_to_model_row(eti, end_row) == cursor_row)) - border = 2; - else - border = 0; - - eti_request_region_redraw(eti, start_col, start_row, end_col, end_row, border); -} - -static void -eti_add_table_model (ETableItem *eti, ETableModel *table_model) -{ - g_assert (eti->table_model == NULL); - - eti->table_model = table_model; - gtk_object_ref (GTK_OBJECT (eti->table_model)); - - eti->table_model_pre_change_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_pre_change", - GTK_SIGNAL_FUNC (eti_table_model_pre_change), eti); - - eti->table_model_change_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_changed", - GTK_SIGNAL_FUNC (eti_table_model_changed), eti); - - eti->table_model_row_change_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_row_changed", - GTK_SIGNAL_FUNC (eti_table_model_row_changed), eti); - - eti->table_model_cell_change_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_cell_changed", - GTK_SIGNAL_FUNC (eti_table_model_cell_changed), eti); - - eti->table_model_row_inserted_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_row_inserted", - GTK_SIGNAL_FUNC (eti_table_model_row_inserted), eti); - - eti->table_model_row_deleted_id = gtk_signal_connect ( - GTK_OBJECT (table_model), "model_row_deleted", - GTK_SIGNAL_FUNC (eti_table_model_row_deleted), eti); - - if (eti->header) { - eti_detach_cell_views (eti); - eti_attach_cell_views (eti); - } - - if (E_IS_TABLE_SUBSET(table_model)) { - eti->uses_source_model = 1; - eti->source_model = E_TABLE_SUBSET(table_model)->source; - if (eti->source_model) - gtk_object_ref(GTK_OBJECT(eti->source_model)); - } - - eti_table_model_changed (table_model, eti); -} - -static void -eti_add_table_selection_model (ETableItem *eti, ETableSelectionModel *selection) -{ - g_assert (eti->selection == NULL); - - eti->selection = selection; - gtk_object_ref (GTK_OBJECT (eti->selection)); - - eti->selection_change_id = gtk_signal_connect ( - GTK_OBJECT (selection), "selection_changed", - GTK_SIGNAL_FUNC (eti_selection_change), eti); - - eti->cursor_change_id = gtk_signal_connect ( - GTK_OBJECT (selection), "cursor_changed", - GTK_SIGNAL_FUNC (eti_cursor_change), eti); - - eti_selection_change(selection, eti); -} - -static void -eti_header_dim_changed (ETableHeader *eth, int col, ETableItem *eti) -{ - eti->needs_compute_width = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); -} - -static void -eti_header_structure_changed (ETableHeader *eth, ETableItem *eti) -{ - eti->cols = e_table_header_count (eti->header); - eti->width = e_table_header_total_width (eti->header); - - /* - * There should be at least one column - */ - g_assert (eti->cols != 0); - - if (eti->cell_views){ - eti_unrealize_cell_views (eti); - eti_detach_cell_views (eti); - eti_attach_cell_views (eti); - eti_realize_cell_views (eti); - } else { - if (eti->table_model) { - eti_detach_cell_views (eti); - eti_attach_cell_views (eti); - } - } - eti->needs_compute_width = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); -} - -static void -eti_add_header_model (ETableItem *eti, ETableHeader *header) -{ - g_assert (eti->header == NULL); - - eti->header = header; - gtk_object_ref (GTK_OBJECT (header)); - - eti_header_structure_changed (header, eti); - - eti->header_dim_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "dimension_change", - GTK_SIGNAL_FUNC (eti_header_dim_changed), eti); - - eti->header_structure_change_id = gtk_signal_connect ( - GTK_OBJECT (header), "structure_change", - GTK_SIGNAL_FUNC (eti_header_structure_changed), eti); -} - -/* - * GtkObject::destroy method - */ -static void -eti_destroy (GtkObject *object) -{ - ETableItem *eti = E_TABLE_ITEM (object); - - eti_remove_header_model (eti); - eti_remove_table_model (eti); - eti_remove_table_selection_model (eti); - - if (eti->selection) - gtk_object_unref(GTK_OBJECT(eti->selection)); - - if (eti->height_cache_idle_id) - g_source_remove(eti->height_cache_idle_id); - - g_free (eti->height_cache); - - if (GTK_OBJECT_CLASS (eti_parent_class)->destroy) - (*GTK_OBJECT_CLASS (eti_parent_class)->destroy) (object); -} - -static void -eti_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableItem *eti; - int cursor_col; - - item = GNOME_CANVAS_ITEM (o); - eti = E_TABLE_ITEM (o); - - switch (arg_id){ - case ARG_TABLE_HEADER: - eti_remove_header_model (eti); - eti_add_header_model (eti, E_TABLE_HEADER(GTK_VALUE_OBJECT (*arg))); - break; - - case ARG_TABLE_MODEL: - eti_remove_table_model (eti); - eti_add_table_model (eti, E_TABLE_MODEL(GTK_VALUE_OBJECT (*arg))); - break; - - case ARG_TABLE_SELECTION_MODEL: - eti_remove_table_selection_model (eti); - if (GTK_VALUE_OBJECT (*arg)) - eti_add_table_selection_model (eti, E_TABLE_SELECTION_MODEL(GTK_VALUE_OBJECT (*arg))); - break; - - case ARG_LENGTH_THRESHOLD: - eti->length_threshold = GTK_VALUE_INT (*arg); - break; - - case ARG_TABLE_DRAW_GRID: - eti->draw_grid = GTK_VALUE_BOOL (*arg); - break; - - case ARG_TABLE_DRAW_FOCUS: - eti->draw_focus = GTK_VALUE_BOOL (*arg); - break; - - case ARG_CURSOR_MODE: - eti->cursor_mode = GTK_VALUE_INT (*arg); - break; - - case ARG_MINIMUM_WIDTH: - case ARG_WIDTH: - if (eti->minimum_width == eti->width && GTK_VALUE_DOUBLE (*arg) > eti->width) - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); - eti->minimum_width = GTK_VALUE_DOUBLE (*arg); - if (eti->minimum_width < eti->width) - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); - break; - case ARG_CURSOR_ROW: - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - NULL); - - e_table_item_focus (eti, cursor_col != -1 ? cursor_col : 0, view_to_model_row(eti, GTK_VALUE_INT (*arg)), 0); - break; - } - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(eti)); -} - -static void -eti_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - ETableItem *eti; - int row; - - item = GNOME_CANVAS_ITEM (o); - eti = E_TABLE_ITEM (o); - - switch (arg_id){ - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = eti->width; - break; - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = eti->height; - break; - case ARG_MINIMUM_WIDTH: - GTK_VALUE_DOUBLE (*arg) = eti->minimum_width; - break; - case ARG_CURSOR_ROW: - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &row, - NULL); - GTK_VALUE_INT (*arg) = model_to_view_row(eti, row); - break; - default: - arg->type = GTK_TYPE_INVALID; - } -} - -static void -eti_init (GnomeCanvasItem *item) -{ - ETableItem *eti = E_TABLE_ITEM (item); - - eti->editing_col = -1; - eti->editing_row = -1; - eti->height = 0; - eti->width = 0; - eti->minimum_width = 0; - - eti->height_cache = NULL; - eti->height_cache_idle_id = 0; - eti->height_cache_idle_count = 0; - - eti->length_threshold = -1; - eti->renderers_can_change_size = 1; - - eti->uses_source_model = 0; - eti->source_model = NULL; - - eti->row_guess = -1; - eti->cursor_mode = E_TABLE_CURSOR_SIMPLE; - - eti->selection_change_id = 0; - eti->cursor_change_id = 0; - eti->selection = NULL; - - eti->needs_redraw = 0; - eti->needs_compute_height = 0; - - e_canvas_item_set_reflow_callback (GNOME_CANVAS_ITEM (eti), eti_reflow); -} - -#define gray50_width 2 -#define gray50_height 2 -static const char gray50_bits[] = { - 0x02, 0x01, }; - -static void -eti_realize (GnomeCanvasItem *item) -{ - ETableItem *eti = E_TABLE_ITEM (item); - GtkWidget *canvas_widget = GTK_WIDGET (item->canvas); - GdkWindow *window; - - if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->realize) - (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->realize)(item); - - /* - * Gdk Resource allocation - */ - window = canvas_widget->window; - - eti->fill_gc = gdk_gc_new (window); - - eti->grid_gc = gdk_gc_new (window); -#if 0 - /* This sets it to gray */ -/* gdk_gc_set_foreground (eti->grid_gc, &canvas_widget->style->bg [GTK_STATE_NORMAL]); */ -#else - gdk_gc_set_foreground (eti->grid_gc, &canvas_widget->style->dark [GTK_STATE_NORMAL]); -#endif - eti->focus_gc = gdk_gc_new (window); - gdk_gc_set_foreground (eti->focus_gc, &canvas_widget->style->bg [GTK_STATE_NORMAL]); - gdk_gc_set_background (eti->focus_gc, &canvas_widget->style->fg [GTK_STATE_NORMAL]); - eti->stipple = gdk_bitmap_create_from_data (NULL, gray50_bits, gray50_width, gray50_height); - gdk_gc_set_ts_origin (eti->focus_gc, 0, 0); - gdk_gc_set_stipple (eti->focus_gc, eti->stipple); - gdk_gc_set_fill (eti->focus_gc, GDK_OPAQUE_STIPPLED); - - if (eti->cell_views == NULL) - eti_attach_cell_views (eti); - - eti_realize_cell_views (eti); - - eti->needs_compute_height = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (eti)); - eti->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (eti)); -} - -static void -eti_unrealize (GnomeCanvasItem *item) -{ - ETableItem *eti = E_TABLE_ITEM (item); - - if (eti_editing (eti)) - e_table_item_leave_edit (eti); - - gdk_gc_unref (eti->fill_gc); - eti->fill_gc = NULL; - gdk_gc_unref (eti->grid_gc); - eti->grid_gc = NULL; - gdk_gc_unref (eti->focus_gc); - eti->focus_gc = NULL; - gdk_bitmap_unref (eti->stipple); - eti->stipple = NULL; - - eti_unrealize_cell_views (eti); - - eti->height = 0; - - if (GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize) - (*GNOME_CANVAS_ITEM_CLASS (eti_parent_class)->unrealize)(item); -} - -static void -eti_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) -{ - ETableItem *eti = E_TABLE_ITEM (item); - const int rows = eti->rows; - const int cols = eti->cols; - int row, col, y1, y2; - int first_col, last_col, x_offset; - int first_row, last_row, y_offset, yd; - int x1, x2; - int f_x1, f_x2, f_y1, f_y2; - gboolean f_found; - double i2c [6]; - ArtPoint eti_base, eti_base_item; - GtkWidget *canvas = GTK_WIDGET(item->canvas); - GdkColor *background; - - /* - * Clear the background - */ -#if 0 - gdk_draw_rectangle ( - drawable, eti->fill_gc, TRUE, - eti->x1 - x, eti->y1 - y, eti->width, eti->height); -#endif - - /* - * Find out our real position after grouping - */ - gnome_canvas_item_i2c_affine (item, i2c); - eti_base_item.x = eti->x1; - eti_base_item.y = eti->y1; - art_affine_point (&eti_base, &eti_base_item, i2c); - - /* - * First column to draw, last column to draw - */ - first_col = -1; - last_col = x_offset = 0; - x1 = x2 = floor (eti_base.x); - for (col = 0; col < cols; col++, x1 = x2){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - x2 = x1 + ecol->width; - - if (x1 > (x + width)) - break; - if (x2 < x) - continue; - if (first_col == -1){ - x_offset = x1 - x; - first_col = col; - } - } - last_col = col; - - /* - * Nothing to paint - */ - if (first_col == -1) - return; - - /* - * Compute row span. - */ - first_row = -1; - y_offset = 0; - y1 = y2 = floor (eti_base.y) + 1; - for (row = 0; row < rows; row++, y1 = y2){ - - y2 += ETI_ROW_HEIGHT (eti, row) + 1; - - if (y1 > y + height) - break; - - if (y2 < y) - continue; - - if (first_row == -1){ - y_offset = y1 - y; - first_row = row; - } - } - last_row = row; - - if (first_row == -1) - return; - - /* - * Draw cells - */ - yd = y_offset; - f_x1 = f_x2 = f_y1 = f_y2 = -1; - f_found = FALSE; - - if (eti->draw_grid && first_row == 0){ - gdk_draw_line ( - drawable, eti->grid_gc, - eti_base.x - x, yd, eti_base.x + eti->width - x, yd); - } - yd++; - - for (row = first_row; row < last_row; row++){ - int xd, height; - gboolean selected; - gint cursor_col, cursor_row; - - height = ETI_ROW_HEIGHT (eti, row); - - xd = x_offset; -/* printf ("paint: %d %d\n", yd, yd + height); */ - - selected = e_table_selection_model_is_row_selected(eti->selection, view_to_model_row(eti,row)); - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - "cursor_row", &cursor_row, - NULL); - - for (col = first_col; col < last_col; col++){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - ECellView *ecell_view = eti->cell_views [col]; - gboolean col_selected = selected; - switch (eti->cursor_mode) { - case E_TABLE_CURSOR_SIMPLE: - if (cursor_col == ecol->col_idx && cursor_row == view_to_model_row(eti, row)) - col_selected = !col_selected; - break; - case E_TABLE_CURSOR_LINE: - /* Nothing */ - break; - } - - if (selected){ - background = &canvas->style->bg [GTK_STATE_SELECTED]; - } else { - if (row % 2) - background = &canvas->style->base [GTK_STATE_NORMAL]; - else - background = &canvas->style->base [GTK_STATE_SELECTED]; - } - - gdk_gc_set_foreground (eti->fill_gc, background); - gdk_draw_rectangle (drawable, eti->fill_gc, TRUE, - xd, yd, ecol->width, height); - - e_cell_draw (ecell_view, drawable, ecol->col_idx, col, row, col_selected, - xd, yd, xd + ecol->width, yd + height); - - 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; - } - - xd += ecol->width; - } - yd += height; - - if (eti->draw_grid) - gdk_draw_line ( - drawable, eti->grid_gc, - eti_base.x - x, yd, eti_base.x + eti->width - x, yd); - yd++; - } - - if (eti->draw_grid){ - int xd = x_offset; - - for (col = first_col; col <= last_col; col++){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - gdk_draw_line ( - drawable, eti->grid_gc, - xd, y_offset, xd, yd - 1); - - /* - * This looks wierd, but it is to draw the last line - */ - if (ecol) - xd += ecol->width; - } - } - - /* - * Draw focus - */ - if (f_found && eti->draw_focus){ - gdk_draw_rectangle (drawable, eti->focus_gc, FALSE, - f_x1 + 1, f_y1, f_x2 - f_x1 - 2, f_y2 - f_y1 - 1); - } -} - -static double -eti_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item) -{ - *actual_item = item; - - return 0.0; -} - -static gboolean -find_cell (ETableItem *eti, double x, double y, int *col_res, int *row_res, double *x1_res, double *y1_res) -{ - const int cols = eti->cols; - const int rows = eti->rows; - gdouble x1, y1, x2, y2; - int col, row; - - /* FIXME: this routine is inneficient, fix later */ - - if (cols == 0 || rows == 0) - return FALSE; - - x -= eti->x1; - y -= eti->y1; - - x1 = 0; - for (col = 0; col < cols - 1; col++, x1 = x2){ - ETableCol *ecol = e_table_header_get_column (eti->header, col); - - if (x < x1) - return FALSE; - - x2 = x1 + ecol->width; - - if (x <= x2) - break; - } - - y1 = y2 = 0; - for (row = 0; row < rows - 1; row++, y1 = y2){ - if (y < y1) - return FALSE; - - y2 += ETI_ROW_HEIGHT (eti, row) + 1; - - if (y <= y2) - break; - } - *col_res = col; - if (x1_res) - *x1_res = x - x1; - *row_res = row; - if (y1_res) - *y1_res = y - y1; - return TRUE; -} - -static void -eti_cursor_move (ETableItem *eti, gint row, gint column) -{ - e_table_item_leave_edit (eti); - e_table_item_focus (eti, view_to_model_col(eti, column), view_to_model_row(eti, row), 0); -} - -static void -eti_cursor_move_left (ETableItem *eti) -{ - int cursor_col, cursor_row; - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - "cursor_row", &cursor_row, - NULL); - - eti_cursor_move (eti, model_to_view_row(eti, cursor_row), model_to_view_col(eti, cursor_col) - 1); -} - -static void -eti_cursor_move_right (ETableItem *eti) -{ - int cursor_col, cursor_row; - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - "cursor_row", &cursor_row, - NULL); - - eti_cursor_move (eti, model_to_view_row(eti, cursor_row), model_to_view_col(eti, cursor_col) + 1); -} - -static void -eti_cursor_move_up (ETableItem *eti) -{ - int cursor_col, cursor_row; - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - "cursor_row", &cursor_row, - NULL); - - eti_cursor_move (eti, model_to_view_row(eti, cursor_row) - 1, model_to_view_col(eti, cursor_col)); -} - -static void -eti_cursor_move_down (ETableItem *eti) -{ - int cursor_col, cursor_row; - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - "cursor_row", &cursor_row, - NULL); - - eti_cursor_move (eti, model_to_view_row(eti, cursor_row) + 1, model_to_view_col(eti, cursor_col)); -} - -/* FIXME: cursor */ -static int -eti_event (GnomeCanvasItem *item, GdkEvent *e) -{ - ETableItem *eti = E_TABLE_ITEM (item); - ECellView *ecell_view; - gint return_val = TRUE; - - switch (e->type){ - case GDK_BUTTON_PRESS: { - double x1, y1; - int col, row; - gint cursor_row, cursor_col; - - e_canvas_item_grab_focus(GNOME_CANVAS_ITEM(eti)); - - switch (e->button.button) { - case 1: /* Fall through. */ - case 2: - gnome_canvas_item_w2i (item, &e->button.x, &e->button.y); - - if (!find_cell (eti, e->button.x, e->button.y, &col, &row, &x1, &y1)) - return TRUE; - - e_table_selection_model_do_something(eti->selection, view_to_model_row(eti, row), view_to_model_col(eti, col), e->button.state); - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (cursor_row == view_to_model_row(eti, row) && cursor_col == view_to_model_col(eti, col)){ - - if ((!eti_editing(eti)) && e_table_model_is_cell_editable(eti->selection->model, cursor_col, cursor_row)) { - e_table_item_enter_edit (eti, col, row); - } - - ecell_view = eti->cell_views [col]; - - /* - * Adjust the event positions - */ - e->button.x = x1; - e->button.y = y1; - - e_cell_event (ecell_view, e, view_to_model_col(eti, col), col, row); - } - break; - case 3: - gnome_canvas_item_w2i (item, &e->button.x, &e->button.y); - if (!find_cell (eti, e->button.x, e->button.y, &col, &row, &x1, &y1)) - return TRUE; - - e_table_selection_model_maybe_do_something(eti->selection, view_to_model_row(eti, row), view_to_model_col(eti, col), 0); - - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [RIGHT_CLICK], - row, col, e, &return_val); - break; - case 4: - case 5: - return FALSE; - break; - - } - break; - } - - case GDK_BUTTON_RELEASE: { - double x1, y1; - int col, row; - gint cursor_row, cursor_col; - - switch (e->button.button) { - case 1: /* Fall through. */ - case 2: - gnome_canvas_item_w2i (item, &e->button.x, &e->button.y); - - if (!find_cell (eti, e->button.x, e->button.y, &col, &row, &x1, &y1)) - return TRUE; - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (cursor_row == view_to_model_row(eti, row) && cursor_col == view_to_model_col(eti, col)){ - - ecell_view = eti->cell_views [col]; - - /* - * Adjust the event positions - */ - e->button.x = x1; - e->button.y = y1; - - e_cell_event (ecell_view, e, view_to_model_col(eti, col), col, row); - } - break; - case 3: - case 4: - case 5: - return FALSE; - break; - - } - break; - } - - case GDK_2BUTTON_PRESS: { - double x1, y1; - int col, row; - - if (e->button.button == 5 || - e->button.button == 4) - return FALSE; - - gnome_canvas_item_w2i (item, &e->button.x, &e->button.y); - - if (!find_cell (eti, e->button.x, e->button.y, &col, &row, &x1, &y1)) - return TRUE; - - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [DOUBLE_CLICK], - row); - break; - } - case GDK_MOTION_NOTIFY: { - int col, row; - double x1, y1; - gint cursor_col, cursor_row; - - gnome_canvas_item_w2i (item, &e->motion.x, &e->motion.y); - - if (!find_cell (eti, e->motion.x, e->motion.y, &col, &row, &x1, &y1)) - return TRUE; - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (cursor_row == view_to_model_row(eti, row) && cursor_col == view_to_model_col(eti, col)){ - ecell_view = eti->cell_views [col]; - - /* - * Adjust the event positions - */ - e->motion.x = x1; - e->motion.y = y1; - - e_cell_event (ecell_view, e, view_to_model_col(eti, col), col, row); - } - break; - } - - case GDK_KEY_PRESS: { - gint cursor_row, cursor_col; - gint handled = TRUE; - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (cursor_col == -1) - return FALSE; - - switch (e->key.keyval){ - case GDK_Left: - if (eti_editing (eti)) { - handled = FALSE; - break; - } - - if (cursor_col != view_to_model_col(eti, 0)) - eti_cursor_move_left (eti); - break; - - case GDK_Right: - if (eti_editing (eti)) { - handled = FALSE; - break; - } - - if (cursor_col != view_to_model_col(eti, eti->cols - 1)) - eti_cursor_move_right (eti); - break; - - case GDK_Up: - if (cursor_row != view_to_model_row(eti, 0)) - eti_cursor_move_up (eti); - else - return_val = FALSE; - break; - - case GDK_Down: - if (cursor_row != view_to_model_row(eti, eti->rows - 1)) - eti_cursor_move_down (eti); - else - return_val = FALSE; - break; - - case GDK_Tab: - case GDK_KP_Tab: - case GDK_ISO_Left_Tab: - if ((e->key.state & GDK_SHIFT_MASK) != 0){ - /* shift tab */ - if (cursor_col != view_to_model_col(eti, 0)) - eti_cursor_move_left (eti); - else if (cursor_row != view_to_model_row(eti, 0)) - eti_cursor_move (eti, model_to_view_row(eti, cursor_row) - 1, eti->cols - 1); - else - return_val = FALSE; - } else { - if (cursor_col != view_to_model_col (eti, eti->cols - 1)) - eti_cursor_move_right (eti); - else if (cursor_row != view_to_model_row(eti, eti->rows - 1)) - eti_cursor_move (eti, model_to_view_row(eti, cursor_row) + 1, 0); - else - return_val = FALSE; - } - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (cursor_col >= 0 && cursor_row >= 0 && return_val && - (!eti_editing(eti)) && e_table_model_is_cell_editable(eti->selection->model, cursor_col, cursor_row)) { - e_table_item_enter_edit (eti, model_to_view_col(eti, cursor_col), model_to_view_row(eti, cursor_row)); - } - break; - - case GDK_Return: - case GDK_KP_Enter: - case GDK_ISO_Enter: - case GDK_3270_Enter: - if (eti_editing (eti)){ - e_table_item_leave_edit (eti); -#if 0 - ecell_view = eti->cell_views [eti->editing_col]; - e_cell_event (ecell_view, e, view_to_model_col(eti, eti->editing_col), eti->editing_col, eti->editing_row); -#endif - } - return_val = FALSE; - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [KEY_PRESS], - model_to_view_row(eti, cursor_row), cursor_col, e, &return_val); - break; - - default: - handled = FALSE; - break; - } - if (!handled) { - if (!eti_editing (eti)){ - gint col, row; - row = model_to_view_row(eti, cursor_row); - col = model_to_view_col(eti, cursor_col); - if (col != -1 && row != -1 && e_table_model_is_cell_editable(eti->selection->model, cursor_col, cursor_row)) { - e_table_item_enter_edit (eti, col, row); - } - } - if (!eti_editing (eti)){ - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [KEY_PRESS], - model_to_view_row(eti, cursor_row), cursor_col, e, &return_val); - } else { - ecell_view = eti->cell_views [eti->editing_col]; - e_cell_event (ecell_view, e, view_to_model_col(eti, eti->editing_col), eti->editing_col, eti->editing_row); - } - } - break; - } - - case GDK_KEY_RELEASE: { - gint cursor_row, cursor_col; - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_row", &cursor_row, - "cursor_col", &cursor_col, - NULL); - - if (cursor_col == -1) - return FALSE; - - if (eti_editing (eti)){ - ecell_view = eti->cell_views [eti->editing_col]; - e_cell_event (ecell_view, e, view_to_model_col(eti, eti->editing_col), eti->editing_col, eti->editing_row); - } - break; - } - - default: - return_val = FALSE; - } - return return_val; -} - -static void -eti_class_init (GtkObjectClass *object_class) -{ - GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; - ETableItemClass *eti_class = (ETableItemClass *) object_class; - - eti_parent_class = gtk_type_class (PARENT_OBJECT_TYPE); - - object_class->destroy = eti_destroy; - object_class->set_arg = eti_set_arg; - object_class->get_arg = eti_get_arg; - - item_class->update = eti_update; - item_class->realize = eti_realize; - item_class->unrealize = eti_unrealize; - item_class->draw = eti_draw; - item_class->point = eti_point; - item_class->event = eti_event; - - eti_class->cursor_change = NULL; - eti_class->double_click = NULL; - eti_class->right_click = NULL; - eti_class->key_press = NULL; - - gtk_object_add_arg_type ("ETableItem::ETableHeader", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_TABLE_HEADER); - gtk_object_add_arg_type ("ETableItem::ETableModel", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_TABLE_MODEL); - gtk_object_add_arg_type ("ETableItem::table_selection_model", GTK_TYPE_OBJECT, - GTK_ARG_WRITABLE, ARG_TABLE_SELECTION_MODEL); - gtk_object_add_arg_type ("ETableItem::drawgrid", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_GRID); - gtk_object_add_arg_type ("ETableItem::drawfocus", GTK_TYPE_BOOL, - GTK_ARG_WRITABLE, ARG_TABLE_DRAW_FOCUS); - gtk_object_add_arg_type ("ETableItem::cursor_mode", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_CURSOR_MODE); - gtk_object_add_arg_type ("ETableItem::length_threshold", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_LENGTH_THRESHOLD); - - gtk_object_add_arg_type ("ETableItem::minimum_width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_MINIMUM_WIDTH); - gtk_object_add_arg_type ("ETableItem::width", GTK_TYPE_DOUBLE, - GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("ETableItem::height", GTK_TYPE_DOUBLE, - GTK_ARG_READABLE, ARG_HEIGHT); - gtk_object_add_arg_type ("ETableItem::cursor_row", GTK_TYPE_INT, - GTK_ARG_READWRITE, ARG_CURSOR_ROW); - - eti_signals [CURSOR_CHANGE] = - gtk_signal_new ("cursor_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableItemClass, cursor_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - eti_signals [DOUBLE_CLICK] = - gtk_signal_new ("double_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableItemClass, double_click), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - eti_signals [RIGHT_CLICK] = - gtk_signal_new ("right_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableItemClass, right_click), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - eti_signals [KEY_PRESS] = - gtk_signal_new ("key_press", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableItemClass, key_press), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - gtk_object_class_add_signals (object_class, eti_signals, LAST_SIGNAL); - -} - -GtkType -e_table_item_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableItem", - sizeof (ETableItem), - sizeof (ETableItemClass), - (GtkClassInitFunc) eti_class_init, - (GtkObjectInitFunc) eti_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_OBJECT_TYPE, &info); - } - - return type; -} - -void -e_table_item_set_cursor (ETableItem *eti, int col, int row) -{ - e_table_item_focus(eti, col, view_to_model_row(eti, row), 0); -} - -static void -e_table_item_focus (ETableItem *eti, int col, int row, GdkModifierType state) -{ - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (row == -1) { - row = view_to_model_row(eti, eti->rows - 1); - } - - if (col == -1) { - col = eti->cols - 1; - } - - if (row != -1) { - e_table_selection_model_do_something(eti->selection, - row, col, - state); - } -} - -gint -e_table_item_get_focused_column (ETableItem *eti) -{ - int cursor_col; - - g_return_val_if_fail (eti != NULL, -1); - g_return_val_if_fail (E_IS_TABLE_ITEM (eti), -1); - - gtk_object_get(GTK_OBJECT(eti->selection), - "cursor_col", &cursor_col, - NULL); - - return cursor_col; -} - -gboolean -e_table_item_is_row_selected (ETableItem *eti, int row) -{ - g_return_val_if_fail (eti != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_ITEM (eti), FALSE); - - return e_table_selection_model_is_row_selected(eti->selection, row); -} - -static void -eti_cursor_change (ETableSelectionModel *selection, int row, int col, ETableItem *eti) -{ - int view_row = model_to_view_row(eti, row); - int view_col = model_to_view_col(eti, col); - - if (view_row == -1 || view_col == -1) { - e_table_item_leave_edit (eti); - return; - } - - eti_request_region_show (eti, view_col, view_row, view_col, view_row); - e_canvas_item_grab_focus(GNOME_CANVAS_ITEM(eti)); - if (eti_editing(eti)) - e_table_item_leave_edit (eti); - gtk_signal_emit (GTK_OBJECT (eti), eti_signals [CURSOR_CHANGE], - view_row); - eti->needs_redraw = TRUE; - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(eti)); -} - -static void -eti_selection_change (ETableSelectionModel *selection, ETableItem *eti) -{ - eti->needs_redraw = TRUE; - gnome_canvas_item_request_update(GNOME_CANVAS_ITEM(eti)); -} - -void -e_table_item_enter_edit (ETableItem *eti, int col, int row) -{ - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (eti_editing (eti)) - e_table_item_leave_edit(eti); - - eti->editing_col = col; - eti->editing_row = row; - - eti->edit_ctx = e_cell_enter_edit (eti->cell_views [col], view_to_model_col(eti, col), col, row); -} - -void -e_table_item_leave_edit (ETableItem *eti) -{ - int col, row; - void *edit_ctx; - - g_return_if_fail (eti != NULL); - g_return_if_fail (E_IS_TABLE_ITEM (eti)); - - if (!eti_editing (eti)) - return; - - col = eti->editing_col; - row = eti->editing_row; - edit_ctx = eti->edit_ctx; - - eti->editing_col = -1; - eti->editing_row = -1; - eti->edit_ctx = NULL; - - e_cell_leave_edit (eti->cell_views [col], - view_to_model_col(eti, col), - col, row, edit_ctx); -} - -void -e_table_item_compute_location (ETableItem *eti, - int *x, - int *y, - int *row, - int *col) -{ - if (!find_cell (eti, *x, *y, col, row, NULL, NULL)) { - *y -= eti_get_height(eti); - } - -} - -typedef struct { - ETableItem *item; - int rows_printed; -} ETableItemPrintContext; - -static gdouble * -e_table_item_calculate_print_widths (ETableHeader *eth, gdouble width) -{ - int i; - double extra; - double expansion; - int last_resizable = -1; - gdouble scale = 300.0L / 70.0L; - gdouble *widths = g_new(gdouble, e_table_header_count(eth)); - /* - 1 to account for the last pixel border. */ - extra = width - 1; - expansion = 0; - for (i = 0; i < eth->col_count; i++) { - extra -= eth->columns[i]->min_width * scale; - if (eth->columns[i]->resizeable && eth->columns[i]->expansion > 0) - last_resizable = i; - expansion += eth->columns[i]->resizeable ? eth->columns[i]->expansion : 0; - widths[i] = eth->columns[i]->min_width * scale; - } - for (i = 0; i <= last_resizable; i++) { - widths[i] += extra * (eth->columns[i]->resizeable ? eth->columns[i]->expansion : 0)/expansion; - } - - return widths; -} - -static gdouble -eti_printed_row_height (ETableItem *eti, gdouble *widths, GnomePrintContext *context, gint row) -{ - int col; - int cols = eti->cols; - gdouble height = 0; - for (col = 0; col < cols; col++) { - ECellView *ecell_view = eti->cell_views [col]; - gdouble this_height = e_cell_print_height (ecell_view, context, view_to_model_col(eti, col), col, row, - widths[col] - 1); - if (this_height > height) - height = this_height; - } - return height; -} - -#define CHECK(x) if((x) == -1) return -1; - -static gint -gp_draw_rect (GnomePrintContext *context, gdouble x, gdouble y, gdouble width, gdouble height) -{ - CHECK(gnome_print_moveto(context, x, y)); - CHECK(gnome_print_lineto(context, x + width, y)); - CHECK(gnome_print_lineto(context, x + width, y - height)); - CHECK(gnome_print_lineto(context, x, y - height)); - CHECK(gnome_print_lineto(context, x, y)); - return gnome_print_fill(context); -} - -static void -e_table_item_print_page (EPrintable *ep, - GnomePrintContext *context, - gdouble width, - gdouble height, - gboolean quantize, - ETableItemPrintContext *itemcontext) -{ - ETableItem *eti = itemcontext->item; - const int rows = eti->rows; - const int cols = eti->cols; - int rows_printed = itemcontext->rows_printed; - gdouble *widths; - int row, col; - gdouble yd = height; - - widths = e_table_item_calculate_print_widths (itemcontext->item->header, width); - - /* - * Draw cells - */ - if (eti->draw_grid){ - gp_draw_rect(context, 0, yd, width, 1); - } - yd--; - - for (row = rows_printed; row < rows; row++){ - gdouble xd = 1, row_height; - - row_height = eti_printed_row_height(eti, widths, context, row); - if (quantize) { - if (yd - row_height - 1 < 0 && row != rows_printed) { - break; - } - } else { - if (yd < 0) { - break; - } - } - - for (col = 0; col < cols; col++){ - ECellView *ecell_view = eti->cell_views [col]; - - if (gnome_print_gsave(context) == -1) - /* FIXME */; - if (gnome_print_translate(context, xd, yd - row_height) == -1) - /* FIXME */; - - if (gnome_print_moveto(context, 0, 0) == -1) - /* FIXME */; - if (gnome_print_lineto(context, widths[col] - 1, 0) == -1) - /* FIXME */; - if (gnome_print_lineto(context, widths[col] - 1, row_height) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 0, row_height) == -1) - /* FIXME */; - if (gnome_print_lineto(context, 0, 0) == -1) - /* FIXME */; - if (gnome_print_clip(context) == -1) - /* FIXME */; - - e_cell_print (ecell_view, context, view_to_model_col(eti, col), col, row, - widths[col] - 1, row_height); - - if (gnome_print_grestore(context) == -1) - /* FIXME */; - - xd += widths[col]; - } - yd -= row_height; - - if (eti->draw_grid){ - gp_draw_rect(context, 0, yd, width, 1); - } - yd--; - } - - itemcontext->rows_printed = row; - - if (eti->draw_grid){ - gdouble xd = 0; - - for (col = 0; col < cols; col++){ - gp_draw_rect(context, xd, height, 1, height - yd); - - xd += widths[col]; - } - gp_draw_rect(context, xd, height, 1, height - yd); - } - - g_free (widths); -} - -static gboolean -e_table_item_data_left (EPrintable *ep, - ETableItemPrintContext *itemcontext) -{ - ETableItem *item = itemcontext->item; - int rows_printed = itemcontext->rows_printed; - - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "data_left"); - return rows_printed < item->rows; -} - -static void -e_table_item_reset (EPrintable *ep, - ETableItemPrintContext *itemcontext) -{ - itemcontext->rows_printed = 0; -} - -static gdouble -e_table_item_height (EPrintable *ep, - GnomePrintContext *context, - gdouble width, - gdouble max_height, - gboolean quantize, - ETableItemPrintContext *itemcontext) -{ - ETableItem *item = itemcontext->item; - const int rows = item->rows; - int rows_printed = itemcontext->rows_printed; - gdouble *widths; - int row; - gdouble yd = 0; - - widths = e_table_item_calculate_print_widths (itemcontext->item->header, width); - - /* - * Draw cells - */ - yd++; - - for (row = rows_printed; row < rows; row++){ - gdouble row_height; - - row_height = eti_printed_row_height(item, widths, context, row); - if (quantize) { - if (max_height != -1 && yd + row_height + 1 > max_height && row != rows_printed) { - break; - } - } else { - if (max_height != -1 && yd > max_height) { - break; - } - } - - yd += row_height; - - yd++; - } - - g_free (widths); - - if (max_height != -1 && (!quantize) && yd > max_height) - yd = max_height; - - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "height"); - return yd; -} - -static gboolean -e_table_item_will_fit (EPrintable *ep, - GnomePrintContext *context, - gdouble width, - gdouble max_height, - gboolean quantize, - ETableItemPrintContext *itemcontext) -{ - ETableItem *item = itemcontext->item; - const int rows = item->rows; - int rows_printed = itemcontext->rows_printed; - gdouble *widths; - int row; - gdouble yd = 0; - gboolean ret_val = TRUE; - - widths = e_table_item_calculate_print_widths (itemcontext->item->header, width); - - /* - * Draw cells - */ - yd++; - - for (row = rows_printed; row < rows; row++){ - gdouble row_height; - - row_height = eti_printed_row_height(item, widths, context, row); - if (quantize) { - if (max_height != -1 && yd + row_height + 1 > max_height && row != rows_printed) { - ret_val = FALSE; - break; - } - } else { - if (max_height != -1 && yd > max_height) { - ret_val = FALSE; - break; - } - } - - yd += row_height; - - yd++; - } - - g_free (widths); - - gtk_signal_emit_stop_by_name(GTK_OBJECT(ep), "will_fit"); - return ret_val; -} - -static void -e_table_item_printable_destroy (GtkObject *object, - ETableItemPrintContext *itemcontext) -{ - gtk_object_unref(GTK_OBJECT(itemcontext->item)); - g_free(itemcontext); -} - -EPrintable * -e_table_item_get_printable (ETableItem *item) -{ - EPrintable *printable = e_printable_new(); - ETableItemPrintContext *itemcontext; - - itemcontext = g_new(ETableItemPrintContext, 1); - itemcontext->item = item; - gtk_object_ref(GTK_OBJECT(item)); - itemcontext->rows_printed = 0; - - gtk_signal_connect (GTK_OBJECT(printable), - "print_page", - GTK_SIGNAL_FUNC(e_table_item_print_page), - itemcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "data_left", - GTK_SIGNAL_FUNC(e_table_item_data_left), - itemcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "reset", - GTK_SIGNAL_FUNC(e_table_item_reset), - itemcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "height", - GTK_SIGNAL_FUNC(e_table_item_height), - itemcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "will_fit", - GTK_SIGNAL_FUNC(e_table_item_will_fit), - itemcontext); - gtk_signal_connect (GTK_OBJECT(printable), - "destroy", - GTK_SIGNAL_FUNC(e_table_item_printable_destroy), - itemcontext); - - return printable; -} diff --git a/widgets/table/e-table-item.h b/widgets/table/e-table-item.h deleted file mode 100644 index 2d81bca758..0000000000 --- a/widgets/table/e-table-item.h +++ /dev/null @@ -1,143 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_ITEM_H_ -#define _E_TABLE_ITEM_H_ - -#include <libgnomeui/gnome-canvas.h> -#include "e-table-model.h" -#include "e-table-header.h" -#include "e-table-selection-model.h" -#include "e-table-defines.h" -#include <e-util/e-printable.h> - -#define E_TABLE_ITEM_TYPE (e_table_item_get_type ()) -#define E_TABLE_ITEM(o) (GTK_CHECK_CAST ((o), E_TABLE_ITEM_TYPE, ETableItem)) -#define E_TABLE_ITEM_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_ITEM_TYPE, ETableItemClass)) -#define E_IS_TABLE_ITEM(o) (GTK_CHECK_TYPE ((o), E_TABLE_ITEM_TYPE)) -#define E_IS_TABLE_ITEM_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_ITEM_TYPE)) - -/* list selection modes */ -typedef enum -{ - E_TABLE_CURSOR_LINE, - E_TABLE_CURSOR_SIMPLE, -} ETableCursorMode; - -typedef struct { - GnomeCanvasItem parent; - ETableModel *table_model; - ETableHeader *header; - - ETableModel *source_model; - ETableSelectionModel *selection; - - int x1, y1; - int minimum_width, width, height; - - int cols, rows; - - /* - * Ids for the signals we connect to - */ - int header_dim_change_id; - int header_structure_change_id; - int table_model_pre_change_id; - int table_model_change_id; - int table_model_row_change_id; - int table_model_cell_change_id; - int table_model_row_inserted_id; - int table_model_row_deleted_id; - - int selection_change_id; - int cursor_change_id; - - GdkGC *fill_gc; - GdkGC *grid_gc; - GdkGC *focus_gc; - GdkBitmap *stipple; - - guint draw_grid:1; - guint draw_focus:1; - guint renderers_can_change_size:1; - guint cell_views_realized:1; - - guint needs_redraw : 1; - guint needs_compute_height : 1; - guint needs_compute_width : 1; - - guint uses_source_model : 1; - - /* - * Realized views, per column - */ - ECellView **cell_views; - int n_cells; - - int *height_cache; - int height_cache_idle_id; - int height_cache_idle_count; - - /* - * Lengh Threshold: above this, we stop computing correctly - * the size - */ - int length_threshold; - - gint row_guess; - ETableCursorMode cursor_mode; - - /* - * During editing - */ - int editing_col, editing_row; - void *edit_ctx; - -} ETableItem; - -typedef struct { - GnomeCanvasItemClass parent_class; - - void (*cursor_change) (ETableItem *eti, int row); - void (*double_click) (ETableItem *eti, int row); - gint (*right_click) (ETableItem *eti, int row, int col, GdkEvent *event); - gint (*key_press) (ETableItem *eti, int row, int col, GdkEvent *event); -} ETableItemClass; - -GtkType e_table_item_get_type (void); - - -/* - * Focus - */ -void e_table_item_set_cursor (ETableItem *eti, int col, int row); - -gint e_table_item_get_focused_column (ETableItem *eti); - -/* - * Handling the selection - */ -gboolean e_table_item_is_row_selected (ETableItem *e_table_Item, - int row); - -void e_table_item_selected_row_foreach (ETableItem *eti, - ETableForeachFunc func, - gpointer closure); - -void e_table_item_leave_edit (ETableItem *eti); -void e_table_item_enter_edit (ETableItem *eti, int col, int row); - -void e_table_item_redraw_range (ETableItem *eti, - int start_col, int start_row, - int end_col, int end_row); - -EPrintable *e_table_item_get_printable (ETableItem *eti); -void e_table_item_print_height (ETableItem *eti, - GnomePrintContext *context, - gdouble width); -void e_table_item_compute_location (ETableItem *eti, - int *x, - int *y, - int *row, - int *col); - - -#endif /* _E_TABLE_ITEM_H_ */ diff --git a/widgets/table/e-table-model.c b/widgets/table/e-table-model.c deleted file mode 100644 index d9c0c4fd38..0000000000 --- a/widgets/table/e-table-model.c +++ /dev/null @@ -1,354 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-model.c: a Table Model - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-table-model.h" - -#define ETM_CLASS(e) ((ETableModelClass *)((GtkObject *)e)->klass) - -#define PARENT_TYPE gtk_object_get_type () - -#define d(x) - -d(static gint depth = 0); - - -static GtkObjectClass *e_table_model_parent_class; - -enum { - MODEL_CHANGED, - MODEL_PRE_CHANGE, - MODEL_ROW_CHANGED, - MODEL_CELL_CHANGED, - MODEL_ROW_INSERTED, - MODEL_ROW_DELETED, - ROW_SELECTION, - LAST_SIGNAL -}; - -static guint e_table_model_signals [LAST_SIGNAL] = { 0, }; - -int -e_table_model_column_count (ETableModel *e_table_model) -{ - g_return_val_if_fail (e_table_model != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), 0); - - return ETM_CLASS (e_table_model)->column_count (e_table_model); -} - - -int -e_table_model_row_count (ETableModel *e_table_model) -{ - g_return_val_if_fail (e_table_model != NULL, 0); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), 0); - - return ETM_CLASS (e_table_model)->row_count (e_table_model); -} - -void * -e_table_model_value_at (ETableModel *e_table_model, int col, int row) -{ - g_return_val_if_fail (e_table_model != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - return ETM_CLASS (e_table_model)->value_at (e_table_model, col, row); -} - -void -e_table_model_set_value_at (ETableModel *e_table_model, int col, int row, const void *data) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - ETM_CLASS (e_table_model)->set_value_at (e_table_model, col, row, data); -} - -gboolean -e_table_model_is_cell_editable (ETableModel *e_table_model, int col, int row) -{ - g_return_val_if_fail (e_table_model != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), FALSE); - - return ETM_CLASS (e_table_model)->is_cell_editable (e_table_model, col, row); -} - -void -e_table_model_append_row (ETableModel *e_table_model, ETableModel *source, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - if (ETM_CLASS (e_table_model)->append_row) - ETM_CLASS (e_table_model)->append_row (e_table_model, source, row); -} - -void * -e_table_model_duplicate_value (ETableModel *e_table_model, int col, const void *value) -{ - g_return_val_if_fail (e_table_model != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - if (ETM_CLASS (e_table_model)->duplicate_value) - return ETM_CLASS (e_table_model)->duplicate_value (e_table_model, col, value); - else - return NULL; -} - -void -e_table_model_free_value (ETableModel *e_table_model, int col, void *value) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - if (ETM_CLASS (e_table_model)->free_value) - ETM_CLASS (e_table_model)->free_value (e_table_model, col, value); -} - -void * -e_table_model_initialize_value (ETableModel *e_table_model, int col) -{ - g_return_val_if_fail (e_table_model != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - if (ETM_CLASS (e_table_model)->initialize_value) - return ETM_CLASS (e_table_model)->initialize_value (e_table_model, col); - else - return NULL; -} - -gboolean -e_table_model_value_is_empty (ETableModel *e_table_model, int col, const void *value) -{ - g_return_val_if_fail (e_table_model != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), FALSE); - - if (ETM_CLASS (e_table_model)->value_is_empty) - return ETM_CLASS (e_table_model)->value_is_empty (e_table_model, col, value); - else - return FALSE; -} - -char * -e_table_model_value_to_string (ETableModel *e_table_model, int col, const void *value) -{ - g_return_val_if_fail (e_table_model != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_MODEL (e_table_model), NULL); - - if (ETM_CLASS (e_table_model)->value_to_string) - return ETM_CLASS (e_table_model)->value_to_string (e_table_model, col, value); - else - return g_strdup(""); -} - -static void -e_table_model_destroy (GtkObject *object) -{ - if (e_table_model_parent_class->destroy) - (*e_table_model_parent_class->destroy)(object); -} - -static void -e_table_model_class_init (GtkObjectClass *object_class) -{ - ETableModelClass *klass = E_TABLE_MODEL_CLASS(object_class); - e_table_model_parent_class = gtk_type_class (PARENT_TYPE); - - object_class->destroy = e_table_model_destroy; - - e_table_model_signals [MODEL_CHANGED] = - gtk_signal_new ("model_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_table_model_signals [MODEL_PRE_CHANGE] = - gtk_signal_new ("model_pre_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_pre_change), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_table_model_signals [MODEL_ROW_CHANGED] = - gtk_signal_new ("model_row_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_row_changed), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - e_table_model_signals [MODEL_CELL_CHANGED] = - gtk_signal_new ("model_cell_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_cell_changed), - gtk_marshal_NONE__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); - - e_table_model_signals [MODEL_ROW_INSERTED] = - gtk_signal_new ("model_row_inserted", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_row_inserted), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - e_table_model_signals [MODEL_ROW_DELETED] = - gtk_signal_new ("model_row_deleted", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableModelClass, model_row_deleted), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - gtk_object_class_add_signals (object_class, e_table_model_signals, LAST_SIGNAL); - - klass->column_count = NULL; - klass->row_count = NULL; - klass->value_at = NULL; - klass->set_value_at = NULL; - klass->is_cell_editable = NULL; - klass->append_row = NULL; - - klass->duplicate_value = NULL; - klass->free_value = NULL; - klass->initialize_value = NULL; - klass->value_is_empty = NULL; - klass->value_to_string = NULL; - klass->model_changed = NULL; - klass->model_row_changed = NULL; - klass->model_cell_changed = NULL; - klass->model_row_inserted = NULL; - klass->model_row_deleted = NULL; -} - - -guint -e_table_model_get_type (void) -{ - static guint type = 0; - - if (!type) - { - GtkTypeInfo info = - { - "ETableModel", - sizeof (ETableModel), - sizeof (ETableModelClass), - (GtkClassInitFunc) e_table_model_class_init, - NULL, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - type = gtk_type_unique (PARENT_TYPE, &info); - } - - return type; -} - -#if d(!)0 -static void -print_tabs (void) -{ - int i; - for (i = 0; i < depth; i++) - g_print("\t"); -} -#endif - -void -e_table_model_pre_change (ETableModel *e_table_model) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - d(print_tabs()); - d(g_print("Emitting pre_change on model 0x%p.\n", e_table_model)); - d(depth++); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_PRE_CHANGE]); - d(depth--); -} - -void -e_table_model_changed (ETableModel *e_table_model) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - d(print_tabs()); - d(g_print("Emitting model_changed on model 0x%p.\n", e_table_model)); - d(depth++); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_CHANGED]); - d(depth--); -} - -void -e_table_model_row_changed (ETableModel *e_table_model, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - d(print_tabs()); - d(g_print("Emitting row_changed on model 0x%p, row %d.\n", e_table_model, row)); - d(depth++); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_ROW_CHANGED], row); - d(depth--); -} - -void -e_table_model_cell_changed (ETableModel *e_table_model, int col, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - d(print_tabs()); - d(g_print("Emitting cell_changed on model 0x%p, row %d, col %d.\n", e_table_model, row, col)); - d(depth++); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_CELL_CHANGED], col, row); - d(depth--); -} - -void -e_table_model_row_inserted (ETableModel *e_table_model, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - d(print_tabs()); - d(g_print("Emitting row_inserted on model 0x%p, row %d.\n", e_table_model, row)); - d(depth++); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_ROW_INSERTED], row); - d(depth--); -} - -void -e_table_model_row_deleted (ETableModel *e_table_model, int row) -{ - g_return_if_fail (e_table_model != NULL); - g_return_if_fail (E_IS_TABLE_MODEL (e_table_model)); - - d(print_tabs()); - d(g_print("Emitting row_deleted on model 0x%p, row %d.\n", e_table_model, row)); - d(depth++); - gtk_signal_emit (GTK_OBJECT (e_table_model), - e_table_model_signals [MODEL_ROW_DELETED], row); - d(depth--); -} diff --git a/widgets/table/e-table-model.h b/widgets/table/e-table-model.h deleted file mode 100644 index d4fae1659e..0000000000 --- a/widgets/table/e-table-model.h +++ /dev/null @@ -1,88 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_MODEL_H_ -#define _E_TABLE_MODEL_H_ - -#include <gtk/gtkobject.h> - -#define E_TABLE_MODEL_TYPE (e_table_model_get_type ()) -#define E_TABLE_MODEL(o) (GTK_CHECK_CAST ((o), E_TABLE_MODEL_TYPE, ETableModel)) -#define E_TABLE_MODEL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_MODEL_TYPE, ETableModelClass)) -#define E_IS_TABLE_MODEL(o) (GTK_CHECK_TYPE ((o), E_TABLE_MODEL_TYPE)) -#define E_IS_TABLE_MODEL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_MODEL_TYPE)) - -typedef struct { - GtkObject base; -} ETableModel; - -typedef struct { - GtkObjectClass parent_class; - - /* - * Virtual methods - */ - int (*column_count) (ETableModel *etm); - int (*row_count) (ETableModel *etm); - void *(*value_at) (ETableModel *etm, int col, int row); - void (*set_value_at) (ETableModel *etm, int col, int row, const void *value); - gboolean (*is_cell_editable) (ETableModel *etm, int col, int row); - void (*append_row) (ETableModel *etm, ETableModel *source, int row); - - /* Allocate a copy of the given value. */ - void *(*duplicate_value) (ETableModel *etm, int col, const void *value); - /* Free an allocated value. */ - void (*free_value) (ETableModel *etm, int col, void *value); - /* Return an allocated empty value. */ - void *(*initialize_value) (ETableModel *etm, int col); - /* Return TRUE if value is equivalent to an empty cell. */ - gboolean (*value_is_empty) (ETableModel *etm, int col, const void *value); - /* Return an allocated string. */ - char *(*value_to_string) (ETableModel *etm, int col, const void *value); - - /* - * Signals - */ - - /* - * These all come after the change has been made. - * Major structural changes: model_changed - * Changes only in a row: row_changed - * Only changes in a cell: cell_changed - * A row inserted: row_inserted - * A row deleted: row_deleted - */ - void (*model_pre_change) (ETableModel *etm); - - void (*model_changed) (ETableModel *etm); - void (*model_row_changed) (ETableModel *etm, int row); - void (*model_cell_changed) (ETableModel *etm, int col, int row); - void (*model_row_inserted) (ETableModel *etm, int row); - void (*model_row_deleted) (ETableModel *etm, int row); -} ETableModelClass; - -GtkType e_table_model_get_type (void); - -int e_table_model_column_count (ETableModel *e_table_model); -const char *e_table_model_column_name (ETableModel *e_table_model, int col); -int e_table_model_row_count (ETableModel *e_table_model); -void *e_table_model_value_at (ETableModel *e_table_model, int col, int row); -void e_table_model_set_value_at (ETableModel *e_table_model, int col, int row, const void *value); -gboolean e_table_model_is_cell_editable (ETableModel *e_table_model, int col, int row); -void e_table_model_append_row (ETableModel *e_table_model, ETableModel *source, int row); - -void *e_table_model_duplicate_value (ETableModel *e_table_model, int col, const void *value); -void e_table_model_free_value (ETableModel *e_table_model, int col, void *value); -void *e_table_model_initialize_value (ETableModel *e_table_model, int col); -gboolean e_table_model_value_is_empty (ETableModel *e_table_model, int col, const void *value); -char *e_table_model_value_to_string (ETableModel *e_table_model, int col, const void *value); - -/* - * Routines for emitting signals on the e_table - */ -void e_table_model_pre_change (ETableModel *e_table_model); -void e_table_model_changed (ETableModel *e_table_model); -void e_table_model_row_changed (ETableModel *e_table_model, int row); -void e_table_model_cell_changed (ETableModel *e_table_model, int col, int row); -void e_table_model_row_inserted (ETableModel *e_table_model, int row); -void e_table_model_row_deleted (ETableModel *e_table_model, int row); - -#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 40c24517f8..0000000000 --- a/widgets/table/e-table-one.c +++ /dev/null @@ -1,236 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-model.c: a one table model implementation that uses function - * pointers to simplify the creation of new, exotic and colorful tables in - * no time. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ - -#include <config.h> -#include "e-table-one.h" - -#define PARENT_TYPE e_table_model_get_type () - -static int -one_column_count (ETableModel *etm) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - return e_table_model_column_count(one->source); - else - return 0; -} - -static int -one_row_count (ETableModel *etm) -{ - return 1; -} - -static void * -one_value_at (ETableModel *etm, int col, int row) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->data) - return one->data[col]; - else - return NULL; -} - -static void -one_set_value_at (ETableModel *etm, int col, int row, const void *val) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->data && one->source) { - e_table_model_free_value(one->source, col, one->data[col]); - one->data[col] = e_table_model_duplicate_value(one->source, col, val); - } -} - -static gboolean -one_is_cell_editable (ETableModel *etm, int col, int row) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - return e_table_model_is_cell_editable(one->source, 0, row); - else - return FALSE; -} - -/* The default for one_duplicate_value is to return the raw value. */ -static void * -one_duplicate_value (ETableModel *etm, int col, const void *value) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - return e_table_model_duplicate_value(one->source, col, value); - else - return (void *)value; -} - -static void -one_free_value (ETableModel *etm, int col, void *value) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - e_table_model_free_value(one->source, col, value); -} - -static void * -one_initialize_value (ETableModel *etm, int col) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - return e_table_model_initialize_value (one->source, col); - else - return NULL; -} - -static gboolean -one_value_is_empty (ETableModel *etm, int col, const void *value) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - return e_table_model_value_is_empty (one->source, col, value); - else - return FALSE; -} - -static char * -one_value_to_string (ETableModel *etm, int col, const void *value) -{ - ETableOne *one = E_TABLE_ONE(etm); - - if (one->source) - return e_table_model_value_to_string (one->source, col, value); - else - return g_strdup(""); -} - -static void -one_destroy (GtkObject *object) -{ - ETableOne *one = E_TABLE_ONE(object); - - if (one->source) { - int i; - int col_count; - - col_count = e_table_model_column_count(one->source); - - if (one->data) { - for (i = 0; i < col_count; i++) { - e_table_model_free_value(one->source, i, one->data[i]); - } - } - - gtk_object_unref(GTK_OBJECT(one->source)); - } - - g_free(one->data); -} - -static void -e_table_one_class_init (GtkObjectClass *object_class) -{ - ETableModelClass *model_class = (ETableModelClass *) object_class; - - model_class->column_count = one_column_count; - model_class->row_count = one_row_count; - model_class->value_at = one_value_at; - model_class->set_value_at = one_set_value_at; - model_class->is_cell_editable = one_is_cell_editable; - model_class->duplicate_value = one_duplicate_value; - model_class->free_value = one_free_value; - model_class->initialize_value = one_initialize_value; - model_class->value_is_empty = one_value_is_empty; - model_class->value_to_string = one_value_to_string; - - object_class->destroy = one_destroy; -} - -static void -e_table_one_init (GtkObject *object) -{ - ETableOne *one = E_TABLE_ONE(object); - - one->source = NULL; - one->data = NULL; -} - -GtkType -e_table_one_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableOne", - sizeof (ETableOne), - sizeof (ETableOneClass), - (GtkClassInitFunc) e_table_one_class_init, - (GtkObjectInitFunc) e_table_one_init, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_TYPE, &info); - } - - return type; -} - -ETableModel * -e_table_one_new (ETableModel *source) -{ - ETableOne *eto; - int col_count; - int i; - - eto = gtk_type_new (e_table_one_get_type ()); - - eto->source = source; - - col_count = e_table_model_column_count(source); - eto->data = g_new(void *, col_count); - for (i = 0; i < col_count; i++) { - eto->data[i] = e_table_model_initialize_value(source, i); - } - - if (source) - gtk_object_ref(GTK_OBJECT(source)); - - return (ETableModel *) eto; -} - -void -e_table_one_commit (ETableOne *one) -{ - if (one->source) { - int empty = TRUE; - int col; - int cols = e_table_model_column_count(one->source); - for (col = 0; col < cols; col++) { - if (!e_table_model_value_is_empty(one->source, col, one->data[col])) { - empty = FALSE; - break; - } - } - if (!empty) { - e_table_model_append_row(one->source, E_TABLE_MODEL(one), 0); - } - } -} diff --git a/widgets/table/e-table-one.h b/widgets/table/e-table-one.h deleted file mode 100644 index c6958cee3a..0000000000 --- a/widgets/table/e-table-one.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_ONE_H_ -#define _E_TABLE_ONE_H_ - -#include "e-table-model.h" - -#define E_TABLE_ONE_TYPE (e_table_one_get_type ()) -#define E_TABLE_ONE(o) (GTK_CHECK_CAST ((o), E_TABLE_ONE_TYPE, ETableOne)) -#define E_TABLE_ONE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_ONE_TYPE, ETableOneClass)) -#define E_IS_TABLE_ONE(o) (GTK_CHECK_TYPE ((o), E_TABLE_ONE_TYPE)) -#define E_IS_TABLE_ONE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_ONE_TYPE)) - -typedef struct { - ETableModel parent; - - ETableModel *source; - void **data; -} ETableOne; - -typedef struct { - ETableModelClass parent_class; -} ETableOneClass; - -GtkType e_table_one_get_type (void); - -ETableModel *e_table_one_new (ETableModel *source); -void e_table_one_commit (ETableOne *one); - -#endif /* _E_TABLE_ONE_H_ */ - diff --git a/widgets/table/e-table-scrolled.c b/widgets/table/e-table-scrolled.c deleted file mode 100644 index f70ca5320a..0000000000 --- a/widgets/table/e-table-scrolled.c +++ /dev/null @@ -1,341 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-scrolled.c: A graphical view of a Table. - * - * Author: - * Chris Lahey <clahey@helixcode.com> - * Miguel de Icaza (miguel@helixcode.com) - * - * Copyright 2000, 1999, Helix Code, Inc - */ -#include <config.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <stdio.h> -#include <libgnomeui/gnome-canvas.h> -#include <gtk/gtksignal.h> -#include <gnome-xml/parser.h> -#include <gnome-xml/xmlmemory.h> - -#include "e-table.h" -#include "e-table-scrolled.h" - -#define COLUMN_HEADER_HEIGHT 16 - -#define PARENT_TYPE e_scroll_frame_get_type () - -static GtkObjectClass *parent_class; - -enum { - CURSOR_CHANGE, - DOUBLE_CLICK, - RIGHT_CLICK, - KEY_PRESS, - LAST_SIGNAL -}; - -enum { - ARG_0, - ARG_TABLE_DRAW_GRID, - ARG_TABLE_DRAW_FOCUS, - ARG_CURSOR_MODE, - ARG_LENGTH_THRESHOLD, - ARG_CLICK_TO_ADD_MESSAGE, -}; - -static gint ets_signals [LAST_SIGNAL] = { 0, }; - -static void -cursor_change_proxy (ETable *et, int row, ETableScrolled *ets) -{ - gtk_signal_emit (GTK_OBJECT (ets), - ets_signals [CURSOR_CHANGE], - row); -} - -static void -double_click_proxy (ETable *et, int row, ETableScrolled *ets) -{ - gtk_signal_emit (GTK_OBJECT (ets), - ets_signals [DOUBLE_CLICK], - row); -} - -static gint -right_click_proxy (ETable *et, int row, int col, GdkEvent *event, ETableScrolled *ets) -{ - int return_val = 0; - gtk_signal_emit (GTK_OBJECT (ets), - ets_signals [RIGHT_CLICK], - row, col, event, &return_val); - return return_val; -} - -static gint -key_press_proxy (ETable *et, int row, int col, GdkEvent *event, ETableScrolled *ets) -{ - int return_val; - gtk_signal_emit (GTK_OBJECT (ets), - ets_signals [KEY_PRESS], - row, col, event, &return_val); - return return_val; -} - -static void -e_table_scrolled_init (GtkObject *object) -{ - ETableScrolled *ets; - EScrollFrame *scroll_frame; - - ets = E_TABLE_SCROLLED (object); - scroll_frame = E_SCROLL_FRAME (object); - - ets->table = gtk_type_new(e_table_get_type()); - - e_scroll_frame_set_policy (scroll_frame, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - e_scroll_frame_set_shadow_type (scroll_frame, GTK_SHADOW_IN); -} - -static void -e_table_scrolled_real_construct (ETableScrolled *ets) -{ - gtk_object_set(GTK_OBJECT(ets), - "shadow_type", GTK_SHADOW_IN, - "hscrollbar_policy", GTK_POLICY_NEVER, - "vscrollbar_policy", GTK_POLICY_AUTOMATIC, - NULL); - - gtk_container_add(GTK_CONTAINER(ets), GTK_WIDGET(ets->table)); - - gtk_signal_connect(GTK_OBJECT(ets->table), "cursor_change", - GTK_SIGNAL_FUNC(cursor_change_proxy), ets); - gtk_signal_connect(GTK_OBJECT(ets->table), "double_click", - GTK_SIGNAL_FUNC(double_click_proxy), ets); - gtk_signal_connect(GTK_OBJECT(ets->table), "right_click", - GTK_SIGNAL_FUNC(right_click_proxy), ets); - gtk_signal_connect(GTK_OBJECT(ets->table), "key_press", - GTK_SIGNAL_FUNC(key_press_proxy), ets); - - gtk_widget_show(GTK_WIDGET(ets->table)); -} - -ETableScrolled * -e_table_scrolled_construct (ETableScrolled *ets, ETableHeader *full_header, - ETableModel *etm, const char *spec) -{ - e_table_construct(ets->table, full_header, etm, spec); - - e_table_scrolled_real_construct(ets); - - return ets; -} - -ETableScrolled * -e_table_scrolled_construct_from_spec_file (ETableScrolled *ets, ETableHeader *full_header, ETableModel *etm, - const char *filename) -{ - e_table_construct_from_spec_file(ets->table, full_header, etm, filename); - - e_table_scrolled_real_construct(ets); - - return ets; -} - -GtkWidget * -e_table_scrolled_new (ETableHeader *full_header, ETableModel *etm, const char *spec) -{ - ETableScrolled *ets; - - ets = E_TABLE_SCROLLED (gtk_widget_new (e_table_scrolled_get_type (), - "hadjustment", NULL, - "vadjustment", NULL, - NULL)); - - ets = e_table_scrolled_construct (ets, full_header, etm, spec); - - return GTK_WIDGET (ets); -} - -GtkWidget * -e_table_scrolled_new_from_spec_file (ETableHeader *full_header, ETableModel *etm, const char *filename) -{ - ETableScrolled *ets; - - ets = gtk_type_new (e_table_scrolled_get_type ()); - - ets = e_table_scrolled_construct_from_spec_file (ets, full_header, etm, filename); - - return GTK_WIDGET (ets); -} - -gchar * -e_table_scrolled_get_specification (ETableScrolled *ets) -{ - return e_table_get_specification(ets->table); -} - -void -e_table_scrolled_save_specification (ETableScrolled *ets, gchar *filename) -{ - e_table_save_specification(ets->table, filename); -} - -void -e_table_scrolled_set_cursor_row (ETableScrolled *ets, int row) -{ - e_table_set_cursor_row(ets->table, row); -} - -int -e_table_scrolled_get_cursor_row (ETableScrolled *ets) -{ - return e_table_get_cursor_row(ets->table); -} - -void -e_table_scrolled_selected_row_foreach (ETableScrolled *ets, - ETableForeachFunc callback, - gpointer closure) -{ - e_table_selected_row_foreach(ets->table, - callback, - closure); -} - -EPrintable * -e_table_scrolled_get_printable (ETableScrolled *ets) -{ - return e_table_get_printable(ets->table); -} - -static void -ets_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableScrolled *ets = E_TABLE_SCROLLED (o); - gboolean bool_val; - gchar *string_val; - - switch (arg_id){ - case ARG_TABLE_DRAW_GRID: - gtk_object_get(GTK_OBJECT(ets->table), - "drawgrid", &bool_val, - NULL); - GTK_VALUE_BOOL (*arg) = bool_val; - break; - - case ARG_TABLE_DRAW_FOCUS: - gtk_object_get(GTK_OBJECT(ets->table), - "drawfocus", &bool_val, - NULL); - GTK_VALUE_BOOL (*arg) = bool_val; - break; - - case ARG_CLICK_TO_ADD_MESSAGE: - gtk_object_get(GTK_OBJECT(ets->table), - "click_to_add_message", &string_val, - NULL); - GTK_VALUE_STRING (*arg) = string_val; - break; - } -} - -static void -ets_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableScrolled *ets = E_TABLE_SCROLLED (o); - - switch (arg_id){ - case ARG_LENGTH_THRESHOLD: - gtk_object_set(GTK_OBJECT(ets->table), - "length_threshold", GTK_VALUE_INT (*arg), - NULL); - break; - - case ARG_TABLE_DRAW_GRID: - gtk_object_set(GTK_OBJECT(ets->table), - "drawgrid", GTK_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_TABLE_DRAW_FOCUS: - gtk_object_set(GTK_OBJECT(ets->table), - "drawfocus", GTK_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_CURSOR_MODE: - gtk_object_set(GTK_OBJECT(ets->table), - "cursor_mode", GTK_VALUE_INT (*arg), - NULL); - break; - case ARG_CLICK_TO_ADD_MESSAGE: - gtk_object_set(GTK_OBJECT(ets->table), - "click_to_add_message", GTK_VALUE_STRING (*arg), - NULL); - break; - } -} - -static void -e_table_scrolled_class_init (GtkObjectClass *object_class) -{ - ETableScrolledClass *klass = E_TABLE_SCROLLED_CLASS(object_class); - parent_class = gtk_type_class (PARENT_TYPE); - - object_class->set_arg = ets_set_arg; - object_class->get_arg = ets_get_arg; - - klass->cursor_change = NULL; - klass->double_click = NULL; - klass->right_click = NULL; - klass->key_press = NULL; - - ets_signals [CURSOR_CHANGE] = - gtk_signal_new ("cursor_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableScrolledClass, cursor_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - ets_signals [DOUBLE_CLICK] = - gtk_signal_new ("double_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableScrolledClass, double_click), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - ets_signals [RIGHT_CLICK] = - gtk_signal_new ("right_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableScrolledClass, right_click), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - ets_signals [KEY_PRESS] = - gtk_signal_new ("key_press", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableScrolledClass, key_press), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - gtk_object_class_add_signals (object_class, ets_signals, LAST_SIGNAL); - - gtk_object_add_arg_type ("ETableScrolled::drawgrid", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_TABLE_DRAW_GRID); - gtk_object_add_arg_type ("ETableScrolled::drawfocus", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_TABLE_DRAW_FOCUS); - gtk_object_add_arg_type ("ETableScrolled::cursor_mode", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_CURSOR_MODE); - gtk_object_add_arg_type ("ETableScrolled::length_threshold", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_LENGTH_THRESHOLD); - gtk_object_add_arg_type ("ETableScrolled::click_to_add_message", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_CLICK_TO_ADD_MESSAGE); -} - -E_MAKE_TYPE(e_table_scrolled, "ETableScrolled", ETableScrolled, e_table_scrolled_class_init, e_table_scrolled_init, PARENT_TYPE); - diff --git a/widgets/table/e-table-scrolled.h b/widgets/table/e-table-scrolled.h deleted file mode 100644 index d5a0c06a58..0000000000 --- a/widgets/table/e-table-scrolled.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SCROLLED_H_ -#define _E_TABLE_SCROLLED_H_ - -#include "widgets/misc/e-scroll-frame.h" -#include "e-table-model.h" -#include "e-table-header.h" -#include "e-table.h" -#include "e-util/e-printable.h" - -BEGIN_GNOME_DECLS - -#define E_TABLE_SCROLLED_TYPE (e_table_scrolled_get_type ()) -#define E_TABLE_SCROLLED(o) (GTK_CHECK_CAST ((o), E_TABLE_SCROLLED_TYPE, ETableScrolled)) -#define E_TABLE_SCROLLED_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SCROLLED_TYPE, ETableScrolledClass)) -#define E_IS_SCROLLED_TABLE(o) (GTK_CHECK_TYPE ((o), E_TABLE_SCROLLED_TYPE)) -#define E_IS_SCROLLED_TABLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SCROLLED_TYPE)) - -typedef struct { - EScrollFrame parent; - - ETable *table; -} ETableScrolled; - -typedef struct { - EScrollFrameClass parent_class; - - void (*cursor_change) (ETableScrolled *est, int row); - void (*double_click) (ETableScrolled *est, int row); - gint (*right_click) (ETableScrolled *est, int row, int col, GdkEvent *event); - gint (*key_press) (ETableScrolled *est, int row, int col, GdkEvent *event); -} ETableScrolledClass; - -GtkType e_table_scrolled_get_type (void); - -ETableScrolled *e_table_scrolled_construct (ETableScrolled *ets, ETableHeader *full_header, ETableModel *etm, - const char *spec); -GtkWidget *e_table_scrolled_new (ETableHeader *full_header, ETableModel *etm, - const char *spec); - -ETableScrolled *e_table_scrolled_construct_from_spec_file (ETableScrolled *e_table_scrolled, - ETableHeader *full_header, - ETableModel *etm, - const char *filename); -GtkWidget *e_table_scrolled_new_from_spec_file (ETableHeader *full_header, - ETableModel *etm, - const char *filename); - -gchar *e_table_scrolled_get_specification (ETableScrolled *e_table_scrolled); -void e_table_scrolled_save_specification (ETableScrolled *e_table_scrolled, gchar *filename); - -void e_table_scrolled_set_cursor_row (ETableScrolled *e_table_scrolled, - int row); -/* -1 means we don't have the cursor. */ -int e_table_scrolled_get_cursor_row (ETableScrolled *e_table_scrolled); -void e_table_scrolled_selected_row_foreach (ETableScrolled *e_table_scrolled, - ETableForeachFunc callback, - gpointer closure); -EPrintable *e_table_scrolled_get_printable (ETableScrolled *e_table_scrolled); - -END_GNOME_DECLS - -#endif /* _E_TABLE_SCROLLED_H_ */ - diff --git a/widgets/table/e-table-selection-model.c b/widgets/table/e-table-selection-model.c deleted file mode 100644 index 9079ce8623..0000000000 --- a/widgets/table/e-table-selection-model.c +++ /dev/null @@ -1,500 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-selection-model.c: a Table Selection Model - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-table-selection-model.h" -#include "e-util/e-util.h" - -#define ETSM_CLASS(e) ((ETableSelectionModelClass *)((GtkObject *)e)->klass) - -#define PARENT_TYPE gtk_object_get_type () - -#define ONES ((guint32) 0xffffffff) - -#define BOX(n) ((n) / 32) -#define OFFSET(n) (31 - ((n) % 32)) -#define BITMASK(n) ((guint32)(((guint32) 0x1) << OFFSET(n))) -#define BITMASK_LEFT(n) ((guint32)(((guint32) ONES) << (32 - ((n) % 32)))) -#define BITMASK_RIGHT(n) ((guint32)(((guint32) ONES) >> ((n) % 32))) - -static GtkObjectClass *e_table_selection_model_parent_class; - -enum { - CURSOR_CHANGED, - SELECTION_CHANGED, - LAST_SIGNAL -}; - -static guint e_table_selection_model_signals [LAST_SIGNAL] = { 0, }; - -enum { - ARG_0, - ARG_MODEL, - ARG_SORTER, - ARG_CURSOR_ROW, - ARG_CURSOR_COL, -}; - -static void -model_changed(ETableModel *etm, ETableSelectionModel *etsm) -{ - e_table_selection_model_clear(etsm); -} - -#if 0 -static void -model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm) -{ - int box; - int i; - if(etsm->row_count >= 0) { - /* Add another word if needed. */ - if ((etsm->row_count & 0x1f) == 0) { - etsm->selection = g_renew(etsm->selection, gint, (etsm->row_count >> 5) + 1); - etsm->selection[etsm->row_count >> 5] = 0; - } - - /* The box is the word that our row is in. */ - box = BOX(row); - /* Shift all words to the right of our box right one bit. */ - for (i = etsm->row_count >> 5; i > box; i--) { - etsm->selection[i] = (etsm->selection[i] >> 1) | (etsm->selection[i - 1] << 31); - } - - /* Shift right half of box one bit to the right. */ - etsm->selection[box] = (etsm->selection[box] & BITMASK_LEFT(row)) | ((etsm->selection[box] & BITMASK_RIGHT(row)) >> 1); - etsm->row_count ++; - } -} - -static void -model_row_deleted(ETableModel *etm, int row, ETableSelectionModel *etsm) -{ - int box; - int i; - int last; - if(etsm->row_count >= 0) { - guint32 bitmask; - box = row >> 5; - last = etsm->row_count >> 5; - - /* Build bitmasks for the left and right half of the box */ - bitmask = BITMASK_RIGHT(row) >> 1; - /* Shift right half of box one bit to the left. */ - etsm->selection[box] = (etsm->selection[box] & BITMASK_LEFT(row))| ((etsm->selection[box] & bitmask) << 1); - - /* Shift all words to the right of our box left one bit. */ - if (box < last) { - etsm->selection[box] &= etsm->selection[box + 1] >> 31; - - for (i = box + 1; i < last; i++) { - etsm->selection[i] = (etsm->selection[i] << 1) | (etsm->selection[i + 1] >> 31); - } - etsm->selection[i] = etsm->selection[i] << 1; - } - etsm->row_count --; - /* Remove the last word if not needed. */ - if ((etsm->row_count & 0x1f) == 0) { - etsm->selection = g_renew(etsm->selection, gint, etsm->row_count >> 5); - } - } -} - -#else - -static void -model_row_inserted(ETableModel *etm, int row, ETableSelectionModel *etsm) -{ - model_changed(etm, etsm); -} - -static void -model_row_deleted(ETableModel *etm, int row, ETableSelectionModel *etsm) -{ - model_changed(etm, etsm); -} -#endif - -inline static void -add_model(ETableSelectionModel *etsm, ETableModel *model) -{ - etsm->model = model; - if (model) { - gtk_object_ref(GTK_OBJECT(model)); - etsm->model_changed_id = gtk_signal_connect(GTK_OBJECT(model), "model_changed", - GTK_SIGNAL_FUNC(model_changed), etsm); - etsm->model_row_inserted_id = gtk_signal_connect(GTK_OBJECT(model), "model_row_inserted", - GTK_SIGNAL_FUNC(model_row_inserted), etsm); - etsm->model_row_deleted_id = gtk_signal_connect(GTK_OBJECT(model), "model_row_deleted", - GTK_SIGNAL_FUNC(model_row_deleted), etsm); - } -} - -inline static void -drop_model(ETableSelectionModel *etsm) -{ - if (etsm->model) { - gtk_signal_disconnect(GTK_OBJECT(etsm->model), - etsm->model_changed_id); - gtk_signal_disconnect(GTK_OBJECT(etsm->model), - etsm->model_row_inserted_id); - gtk_signal_disconnect(GTK_OBJECT(etsm->model), - etsm->model_row_deleted_id); - gtk_object_unref(GTK_OBJECT(etsm->model)); - } - etsm->model = NULL; -} - -inline static void -add_sorter(ETableSelectionModel *etsm, ETableSorter *sorter) -{ - etsm->sorter = sorter; - if (sorter) { - gtk_object_ref(GTK_OBJECT(sorter)); - } -} - -inline static void -drop_sorter(ETableSelectionModel *etsm) -{ - if (etsm->sorter) { - gtk_object_unref(GTK_OBJECT(etsm->sorter)); - } - etsm->sorter = NULL; -} - -static void -etsm_destroy (GtkObject *object) -{ - ETableSelectionModel *etsm; - - etsm = E_TABLE_SELECTION_MODEL (object); - - drop_model(etsm); - drop_sorter(etsm); - - g_free(etsm->selection); -} - -static void -etsm_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableSelectionModel *etsm = E_TABLE_SELECTION_MODEL (o); - - switch (arg_id){ - case ARG_MODEL: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etsm->model); - break; - - case ARG_SORTER: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etsm->sorter); - break; - - case ARG_CURSOR_ROW: - GTK_VALUE_INT(*arg) = etsm->cursor_row; - break; - - case ARG_CURSOR_COL: - GTK_VALUE_INT(*arg) = etsm->cursor_col; - break; - } -} - -static void -etsm_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableSelectionModel *etsm = E_TABLE_SELECTION_MODEL (o); - - switch (arg_id){ - case ARG_MODEL: - drop_model(etsm); - add_model(etsm, GTK_VALUE_OBJECT (*arg) ? E_TABLE_MODEL(GTK_VALUE_OBJECT (*arg)) : NULL); - break; - - case ARG_SORTER: - drop_sorter(etsm); - add_sorter(etsm, GTK_VALUE_OBJECT (*arg) ? E_TABLE_SORTER(GTK_VALUE_OBJECT (*arg)) : NULL); - break; - - case ARG_CURSOR_ROW: - e_table_selection_model_do_something(etsm, GTK_VALUE_INT(*arg), etsm->cursor_col, 0); - break; - - case ARG_CURSOR_COL: - e_table_selection_model_do_something(etsm, etsm->cursor_row, GTK_VALUE_INT(*arg), 0); - break; - } -} - -static void -e_table_selection_model_init (ETableSelectionModel *selection) -{ - selection->selection = NULL; - selection->row_count = -1; - selection->model = NULL; -} - -static void -e_table_selection_model_class_init (ETableSelectionModelClass *klass) -{ - GtkObjectClass *object_class; - - e_table_selection_model_parent_class = gtk_type_class (gtk_object_get_type ()); - - object_class = GTK_OBJECT_CLASS(klass); - - object_class->destroy = etsm_destroy; - object_class->get_arg = etsm_get_arg; - object_class->set_arg = etsm_set_arg; - - e_table_selection_model_signals [CURSOR_CHANGED] = - gtk_signal_new ("cursor_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableSelectionModelClass, cursor_changed), - gtk_marshal_NONE__INT_INT, - GTK_TYPE_NONE, 2, GTK_TYPE_INT, GTK_TYPE_INT); - - e_table_selection_model_signals [SELECTION_CHANGED] = - gtk_signal_new ("selection_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableSelectionModelClass, selection_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - klass->cursor_changed = NULL; - klass->selection_changed = NULL; - - gtk_object_class_add_signals (object_class, e_table_selection_model_signals, LAST_SIGNAL); - - gtk_object_add_arg_type ("ETableSelectionModel::model", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_MODEL); - gtk_object_add_arg_type ("ETableSelectionModel::sorter", GTK_TYPE_OBJECT, - GTK_ARG_READWRITE, ARG_SORTER); - gtk_object_add_arg_type ("ETableSelectionModel::cursor_row", GTK_TYPE_INT, - GTK_ARG_READWRITE, ARG_CURSOR_ROW); - gtk_object_add_arg_type ("ETableSelectionModel::cursor_col", GTK_TYPE_INT, - GTK_ARG_READWRITE, ARG_CURSOR_COL); -} - -E_MAKE_TYPE(e_table_selection_model, "ETableSelectionModel", ETableSelectionModel, - e_table_selection_model_class_init, e_table_selection_model_init, PARENT_TYPE); - -ETableSelectionModel * -e_table_selection_model_new (void) -{ - return gtk_type_new (e_table_selection_model_get_type ()); -} - -gboolean -e_table_selection_model_is_row_selected (ETableSelectionModel *selection, - gint n) -{ - if (selection->row_count < n) - return 0; - else - return (selection->selection[BOX(n)] >> OFFSET(n)) & 0x1; -} - -void -e_table_selection_model_foreach (ETableSelectionModel *selection, - ETableForeachFunc callback, - gpointer closure) -{ - int i; - int last = (selection->row_count + 31) / 32; - for (i = 0; i < last; i++) { - if (selection->selection[i]) { - int j; - guint32 value = selection->selection[i]; - for (j = 0; j < 32; j++) { - if (value & 0x80000000) { - callback(i * 32 + j, closure); - } - value <<= 1; - } - } - } -} - -#define OPERATE(object, mask, grow) ((grow) ? ((object) |= (~(mask))) : ((object) &= (mask))) - -static void -change_one_row(ETableSelectionModel *selection, int row, gboolean grow) -{ - int i; - i = BOX(row); - - OPERATE(selection->selection[i], BITMASK_LEFT(row) | BITMASK_RIGHT(row + 1), grow); -} - -static void -change_selection(ETableSelectionModel *selection, int start, int end, gboolean grow) -{ - int i, last; - if (start != end) { - if (selection->sorter && e_table_sorter_needs_sorting(selection->sorter)) { - for ( i = start; i < end; i++) { - change_one_row(selection, e_table_sorter_sorted_to_model(selection->sorter, i), grow); - } - } else { - i = BOX(start); - last = BOX(end); - - if (i == last) { - OPERATE(selection->selection[i], BITMASK_LEFT(start) | BITMASK_RIGHT(end), grow); - } else { - OPERATE(selection->selection[i], BITMASK_LEFT(start), grow); - if (grow) - for (i ++; i < last; i++) - selection->selection[i] = ONES; - else - for (i ++; i < last; i++) - selection->selection[i] = 0; - OPERATE(selection->selection[i], BITMASK_RIGHT(end), grow); - } - } - } -} - -void e_table_selection_model_do_something (ETableSelectionModel *selection, - guint row, - guint col, - GdkModifierType state) -{ - gint shift_p = state & GDK_SHIFT_MASK; - gint ctrl_p = state & GDK_CONTROL_MASK; - if (selection->row_count < 0) { - if (selection->model) { - selection->row_count = e_table_model_row_count(selection->model); - g_free(selection->selection); - selection->selection = g_new0(gint, (selection->row_count + 31) / 32); - } - } - if (selection->row_count >= 0 && row < selection->row_count) { - if (shift_p) { - int old_start; - int old_end; - int new_start; - int new_end; - if (selection->sorter && e_table_sorter_needs_sorting(selection->sorter)) { - old_start = MIN (e_table_sorter_model_to_sorted(selection->sorter, selection->selection_start_row), - e_table_sorter_model_to_sorted(selection->sorter, selection->cursor_row)); - old_end = MAX (e_table_sorter_model_to_sorted(selection->sorter, selection->selection_start_row), - e_table_sorter_model_to_sorted(selection->sorter, selection->cursor_row)) + 1; - new_start = MIN (e_table_sorter_model_to_sorted(selection->sorter, selection->selection_start_row), - e_table_sorter_model_to_sorted(selection->sorter, row)); - new_end = MAX (e_table_sorter_model_to_sorted(selection->sorter, selection->selection_start_row), - e_table_sorter_model_to_sorted(selection->sorter, row)) + 1; - } else { - old_start = MIN (selection->selection_start_row, selection->cursor_row); - old_end = MAX (selection->selection_start_row, selection->cursor_row) + 1; - new_start = MIN (selection->selection_start_row, row); - new_end = MAX (selection->selection_start_row, row) + 1; - } - /* This wouldn't work nearly so smoothly if one end of the selection held in place. */ - if (old_start < new_start) - change_selection(selection, old_start, new_start, FALSE); - if (new_start < old_start) - change_selection(selection, new_start, old_start, TRUE); - if (old_end < new_end) - change_selection(selection, old_end, new_end, TRUE); - if (new_end < old_end) - change_selection(selection, new_end, old_end, FALSE); - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals [SELECTION_CHANGED]); - } else { - if (ctrl_p) { - if (selection->selection[BOX(row)] & BITMASK(row)) - selection->selection[BOX(row)] &= ~BITMASK(row); - else - selection->selection[BOX(row)] |= BITMASK(row); - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals [SELECTION_CHANGED]); - } else { - int i; - for (i = 0; i < ((selection->row_count + 31) / 32); i++) { - if (!((i == BOX(row) && selection->selection[i] == BITMASK(row)) || - (i != BOX(row) && selection->selection[i] == 0))) { - g_free(selection->selection); - selection->selection = g_new0(gint, (selection->row_count + 31) / 32); - selection->selection[BOX(row)] = BITMASK(row); - - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals [SELECTION_CHANGED]); - break; - } - } - } - selection->selection_start_row = row; - } - if (selection->cursor_row != row || - selection->cursor_col != col) { - selection->cursor_row = row; - selection->cursor_col = col; - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals[CURSOR_CHANGED], row, col); - } - } -} - -void e_table_selection_model_maybe_do_something (ETableSelectionModel *selection, - guint row, - guint col, - GdkModifierType state) -{ - if (e_table_selection_model_is_row_selected(selection, row)) { - selection->cursor_row = row; - selection->cursor_col = col; - } else { - e_table_selection_model_do_something(selection, row, col, state); - } -} - -void -e_table_selection_model_clear(ETableSelectionModel *selection) -{ - g_free(selection->selection); - selection->selection = NULL; - selection->row_count = -1; - selection->cursor_row = -1; - selection->cursor_col = -1; - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals [CURSOR_CHANGED], -1, -1); - gtk_signal_emit(GTK_OBJECT(selection), - e_table_selection_model_signals [SELECTION_CHANGED]); -} - -#define PART(x,n) (((x) & (0x01010101 << n)) >> n) -#define SECTION(x, n) (((x) >> (n * 8)) & 0xff) - -gint -e_table_selection_model_selected_count (ETableSelectionModel *selection) -{ - gint count; - int i; - int last; - - count = 0; - - last = BOX(selection->row_count - 1); - - for (i = 0; i <= last; i++) { - int j; - guint32 thiscount = 0; - for (j = 0; j < 8; j++) - thiscount += PART(selection->selection[i], j); - for (j = 0; j < 4; j++) - count += SECTION(thiscount, j); - } - - return count; -} diff --git a/widgets/table/e-table-selection-model.h b/widgets/table/e-table-selection-model.h deleted file mode 100644 index 6d7b25ed3d..0000000000 --- a/widgets/table/e-table-selection-model.h +++ /dev/null @@ -1,70 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SELECTION_MODEL_H_ -#define _E_TABLE_SELECTION_MODEL_H_ - -#include <gtk/gtkobject.h> -#include "widgets/e-table/e-table-model.h" -#include "widgets/e-table/e-table-defines.h" -#include "widgets/e-table/e-table-sorter.h" - -#define E_TABLE_SELECTION_MODEL_TYPE (e_table_selection_model_get_type ()) -#define E_TABLE_SELECTION_MODEL(o) (GTK_CHECK_CAST ((o), E_TABLE_SELECTION_MODEL_TYPE, ETableSelectionModel)) -#define E_TABLE_SELECTION_MODEL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SELECTION_MODEL_TYPE, ETableSelectionModelClass)) -#define E_IS_TABLE_SELECTION_MODEL(o) (GTK_CHECK_TYPE ((o), E_TABLE_SELECTION_MODEL_TYPE)) -#define E_IS_TABLE_SELECTION_MODEL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SELECTION_MODEL_TYPE)) - -typedef struct { - GtkObject base; - - ETableModel *model; - ETableSorter *sorter; - - gint row_count; - guint32 *selection; - - gint cursor_row; - gint cursor_col; - gint selection_start_row; - - guint model_changed_id; - guint model_row_inserted_id, model_row_deleted_id; - - guint frozen : 1; - guint selection_model_changed : 1; - guint group_info_changed : 1; -} ETableSelectionModel; - -typedef struct { - GtkObjectClass parent_class; - - /* - * Signals - */ - - void (*cursor_changed) (ETableSelectionModel *selection, int row, int col); - void (*selection_changed) (ETableSelectionModel *selection); - -} ETableSelectionModelClass; - -GtkType e_table_selection_model_get_type (void); - -gboolean e_table_selection_model_is_row_selected (ETableSelectionModel *selection, - gint n); -void e_table_selection_model_foreach (ETableSelectionModel *selection, - ETableForeachFunc callback, - gpointer closure); - -void e_table_selection_model_do_something (ETableSelectionModel *selection, - guint row, - guint col, - GdkModifierType state); -void e_table_selection_model_maybe_do_something (ETableSelectionModel *selection, - guint row, - guint col, - GdkModifierType state); -void e_table_selection_model_clear (ETableSelectionModel *selection); -gint e_table_selection_model_selected_count (ETableSelectionModel *selection); - -ETableSelectionModel *e_table_selection_model_new (void); - -#endif /* _E_TABLE_SELECTION_MODEL_H_ */ diff --git a/widgets/table/e-table-simple.c b/widgets/table/e-table-simple.c deleted file mode 100644 index 8c8ed87b70..0000000000 --- a/widgets/table/e-table-simple.c +++ /dev/null @@ -1,242 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-model.c: a simple table model implementation that uses function - * pointers to simplify the creation of new, exotic and colorful tables in - * no time. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ - -#include <config.h> -#include "e-table-simple.h" - -enum { - ARG_0, - ARG_APPEND_ROW, -}; - -#define PARENT_TYPE e_table_model_get_type () - -static int -simple_column_count (ETableModel *etm) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->col_count) - return simple->col_count (etm, simple->data); - else - return 0; -} - -static int -simple_row_count (ETableModel *etm) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->row_count) - return simple->row_count (etm, simple->data); - else - return 0; -} - -static void * -simple_value_at (ETableModel *etm, int col, int row) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->value_at) - return simple->value_at (etm, col, row, simple->data); - else - return NULL; -} - -static void -simple_set_value_at (ETableModel *etm, int col, int row, const void *val) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->set_value_at) - simple->set_value_at (etm, col, row, val, simple->data); -} - -static gboolean -simple_is_cell_editable (ETableModel *etm, int col, int row) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->is_cell_editable) - return simple->is_cell_editable (etm, col, row, simple->data); - else - return FALSE; -} - -/* The default for simple_duplicate_value is to return the raw value. */ -static void * -simple_duplicate_value (ETableModel *etm, int col, const void *value) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->duplicate_value) - return simple->duplicate_value (etm, col, value, simple->data); - else - return (void *)value; -} - -static void -simple_free_value (ETableModel *etm, int col, void *value) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->free_value) - simple->free_value (etm, col, value, simple->data); -} - -static void * -simple_initialize_value (ETableModel *etm, int col) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->initialize_value) - return simple->initialize_value (etm, col, simple->data); - else - return NULL; -} - -static gboolean -simple_value_is_empty (ETableModel *etm, int col, const void *value) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->value_is_empty) - return simple->value_is_empty (etm, col, value, simple->data); - else - return FALSE; -} - -static char * -simple_value_to_string (ETableModel *etm, int col, const void *value) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->value_to_string) - return simple->value_to_string (etm, col, value, simple->data); - else - return g_strdup (""); -} - -static void -simple_append_row (ETableModel *etm, ETableModel *source, int row) -{ - ETableSimple *simple = E_TABLE_SIMPLE(etm); - - if (simple->append_row) - simple->append_row (etm, source, row, simple->data); -} - -static void -simple_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableSimple *simple = E_TABLE_SIMPLE (o); - - switch (arg_id){ - case ARG_APPEND_ROW: - GTK_VALUE_POINTER(*arg) = simple->append_row; - break; - } -} - -static void -simple_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETableSimple *simple = E_TABLE_SIMPLE (o); - - switch (arg_id){ - case ARG_APPEND_ROW: - simple->append_row = GTK_VALUE_POINTER(*arg); - break; - default: - arg->type = GTK_TYPE_INVALID; - } -} - -static void -e_table_simple_class_init (GtkObjectClass *object_class) -{ - ETableModelClass *model_class = (ETableModelClass *) object_class; - - object_class->set_arg = simple_set_arg; - object_class->get_arg = simple_get_arg; - - model_class->column_count = simple_column_count; - model_class->row_count = simple_row_count; - model_class->value_at = simple_value_at; - model_class->set_value_at = simple_set_value_at; - model_class->is_cell_editable = simple_is_cell_editable; - model_class->duplicate_value = simple_duplicate_value; - model_class->free_value = simple_free_value; - model_class->initialize_value = simple_initialize_value; - model_class->value_is_empty = simple_value_is_empty; - model_class->value_to_string = simple_value_to_string; - model_class->append_row = simple_append_row; - - gtk_object_add_arg_type ("ETableSimple::append_row", GTK_TYPE_POINTER, - GTK_ARG_READWRITE, ARG_APPEND_ROW); -} - -GtkType -e_table_simple_get_type (void) -{ - static GtkType type = 0; - - if (!type){ - GtkTypeInfo info = { - "ETableSimple", - sizeof (ETableSimple), - sizeof (ETableSimpleClass), - (GtkClassInitFunc) e_table_simple_class_init, - (GtkObjectInitFunc) NULL, - NULL, /* reserved 1 */ - NULL, /* reserved 2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_TYPE, &info); - } - - return type; -} - -ETableModel * -e_table_simple_new (ETableSimpleColumnCountFn col_count, - ETableSimpleRowCountFn row_count, - ETableSimpleValueAtFn value_at, - ETableSimpleSetValueAtFn set_value_at, - ETableSimpleIsCellEditableFn is_cell_editable, - ETableSimpleDuplicateValueFn duplicate_value, - ETableSimpleFreeValueFn free_value, - ETableSimpleInitializeValueFn initialize_value, - ETableSimpleValueIsEmptyFn value_is_empty, - ETableSimpleValueToStringFn value_to_string, - void *data) -{ - ETableSimple *et; - - et = gtk_type_new (e_table_simple_get_type ()); - - et->col_count = col_count; - et->row_count = row_count; - et->value_at = value_at; - et->set_value_at = set_value_at; - et->is_cell_editable = is_cell_editable; - et->duplicate_value = duplicate_value; - et->free_value = free_value; - et->initialize_value = initialize_value; - et->value_is_empty = value_is_empty; - et->value_to_string = value_to_string; - et->data = data; - - return (ETableModel *) et; -} diff --git a/widgets/table/e-table-simple.h b/widgets/table/e-table-simple.h deleted file mode 100644 index 34e76eed79..0000000000 --- a/widgets/table/e-table-simple.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SIMPLE_H_ -#define _E_TABLE_SIMPLE_H_ - -#include "e-table-model.h" - -#define E_TABLE_SIMPLE_TYPE (e_table_simple_get_type ()) -#define E_TABLE_SIMPLE(o) (GTK_CHECK_CAST ((o), E_TABLE_SIMPLE_TYPE, ETableSimple)) -#define E_TABLE_SIMPLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SIMPLE_TYPE, ETableSimpleClass)) -#define E_IS_TABLE_SIMPLE(o) (GTK_CHECK_TYPE ((o), E_TABLE_SIMPLE_TYPE)) -#define E_IS_TABLE_SIMPLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SIMPLE_TYPE)) - -typedef int (*ETableSimpleColumnCountFn) (ETableModel *etm, void *data); -typedef int (*ETableSimpleRowCountFn) (ETableModel *etm, void *data); -typedef void *(*ETableSimpleValueAtFn) (ETableModel *etm, int col, int row, void *data); -typedef void (*ETableSimpleSetValueAtFn) (ETableModel *etm, int col, int row, const void *val, void *data); -typedef gboolean (*ETableSimpleIsCellEditableFn) (ETableModel *etm, int col, int row, void *data); -typedef void (*ETableSimpleAppendRowFn) (ETableModel *etm, ETableModel *model, int row, void *data); -typedef void *(*ETableSimpleDuplicateValueFn) (ETableModel *etm, int col, const void *val, void *data); -typedef void (*ETableSimpleFreeValueFn) (ETableModel *etm, int col, void *val, void *data); -typedef void *(*ETableSimpleInitializeValueFn) (ETableModel *etm, int col, void *data); -typedef gboolean (*ETableSimpleValueIsEmptyFn) (ETableModel *etm, int col, const void *val, void *data); -typedef char *(*ETableSimpleValueToStringFn) (ETableModel *etm, int col, const void *val, void *data); - -typedef struct { - ETableModel parent; - - ETableSimpleColumnCountFn col_count; - ETableSimpleRowCountFn row_count; - ETableSimpleValueAtFn value_at; - ETableSimpleSetValueAtFn set_value_at; - ETableSimpleIsCellEditableFn is_cell_editable; - ETableSimpleDuplicateValueFn duplicate_value; - ETableSimpleFreeValueFn free_value; - ETableSimpleInitializeValueFn initialize_value; - ETableSimpleValueIsEmptyFn value_is_empty; - ETableSimpleValueToStringFn value_to_string; - ETableSimpleAppendRowFn append_row; - void *data; -} ETableSimple; - -typedef struct { - ETableModelClass parent_class; -} ETableSimpleClass; - -GtkType e_table_simple_get_type (void); - -ETableModel *e_table_simple_new (ETableSimpleColumnCountFn col_count, - ETableSimpleRowCountFn row_count, - ETableSimpleValueAtFn value_at, - ETableSimpleSetValueAtFn set_value_at, - ETableSimpleIsCellEditableFn is_cell_editable, - ETableSimpleDuplicateValueFn duplicate_value, - ETableSimpleFreeValueFn free_value, - ETableSimpleInitializeValueFn initialize_value, - ETableSimpleValueIsEmptyFn value_is_empty, - ETableSimpleValueToStringFn value_to_string, - void *data); - -#endif /* _E_TABLE_SIMPLE_H_ */ - diff --git a/widgets/table/e-table-size-test.c b/widgets/table/e-table-size-test.c deleted file mode 100644 index 2bc18235e8..0000000000 --- a/widgets/table/e-table-size-test.c +++ /dev/null @@ -1,288 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* This code is GPL. */ -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "e-util/e-cursors.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-cell-checkbox.h" -#include "e-table.h" - -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include "table-test.h" - -/* - * One way in which we make it simpler to build an ETableModel is through - * the ETableSimple class. Instead of creating your own ETableModel - * class, you simply create a new object of the ETableSimple class. You - * give it a bunch of functions that act as callbacks. - * - * You also get to pass a void * to ETableSimple and it gets passed to - * your callbacks. This would be for having multiple models of the same - * type. This is just an example though, so we statically define all the - * data and ignore the void *data parameter. - * - * In our example we will be creating a table model with 6 columns and 10 - * rows. This corresponds to having 6 different types of information and - * 10 different sets of data in our database. - * - * The headers will be hard coded, as will be the example data. - * - */ - -/* - * There are two different meanings to the word "column". The first is - * the model column. A model column corresponds to a specific type of - * data. This is very much like the usage in a database table where a - * column is a field in the database. - * - * The second type of column is a view column. A view column - * corresponds to a visually displayed column. Each view column - * corresponds to a specific model column, though a model column may - * have any number of view columns associated with it, from zero to - * greater than one. - * - * Also, a view column doesn't necessarily depend on only one model - * column. In some cases, the view column renderer can be given a - * reference to another column to get extra information about its - * display. -*/ - -#define ROWS 5000 -#define COLS 4 - -#define IMPORTANCE_COLUMN 4 -#define COLOR_COLUMN 5 - -/* - * Here we define the initial layout of the table. This is an xml - * format that allows you to change the initial ordering of the - * columns or to do sorting or grouping initially. This specification - * shows all 5 columns, but moves the importance column nearer to the - * front. It also sorts by the "Full Name" column (ascending.) - * Sorting and grouping take the model column as their arguments - * (sorting is specified by the "column" argument to the leaf elemnt. - */ - -#define INITIAL_SPEC "<ETableSpecification> \ - <columns-shown> \ - <column> 0 </column> \ - <column> 4 </column> \ - <column> 1 </column> \ - <column> 2 </column> \ - <column> 3 </column> \ - </columns-shown> \ - <grouping> <leaf column=\"1\" ascending=\"1\"/> </grouping> \ -</ETableSpecification>" - -char *headers [COLS] = { - "Email", - "Full Name", - "Address", - "Phone" -}; - -/* - * Virtual Column list: - * 0 Email - * 1 Full Name - * 2 Address - * 3 Phone - */ - -/* - * ETableSimple callbacks - * These are the callbacks that define the behavior of our custom model. - */ - -/* - * Since our model is a constant size, we can just return its size in - * the column and row count fields. - */ - -/* This function returns the number of columns in our ETableModel. */ -static int -my_col_count (ETableModel *etc, void *data) -{ - return COLS; -} - -/* This function returns the number of rows in our ETableModel. */ -static int -my_row_count (ETableModel *etc, void *data) -{ - return ROWS; -} - -/* This function returns the value at a particular point in our ETableModel. */ -static void * -my_value_at (ETableModel *etc, int col, int row, void *data) -{ - static guchar t[] = {'A', 0xc3, 0x84, 0xc3, 0x95, 0xc3, 0x94, 0xc3, 0xb5, 0x00}; - -#if 0 - if (col == 1) return "toshok@helixcode.com"; -#else - if (col == 1) return t; -#endif - else if (col == 2) return "Chris Toshok"; - else if (col == 3) return "43 Vicksburg, SF"; - else if (col == 4) return "415-867-5309"; - else return NULL; -} - -/* This function sets the value at a particular point in our ETableModel. */ -static void -my_set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ -} - -/* This function returns whether a particular cell is editable. */ -static gboolean -my_is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return FALSE; -} - -/* This function duplicates the value passed to it. */ -static void * -my_duplicate_value (ETableModel *etc, int col, const void *value, void *data) -{ - return g_strdup (value); -} - -/* This function frees the value passed to it. */ -static void -my_free_value (ETableModel *etc, int col, void *value, void *data) -{ - g_free (value); -} - -/* This function creates an empty value. */ -static void * -my_initialize_value (ETableModel *etc, int col, void *data) -{ - return g_strdup (""); -} - -/* This function reports if a value is empty. */ -static gboolean -my_value_is_empty (ETableModel *etc, int col, const void *value, void *data) -{ - return !(value && *(char *)value); -} - -/* This function reports if a value is empty. */ -static char * -my_value_to_string (ETableModel *etc, int col, const void *value, void *data) -{ - return g_strdup(value); -} - -/* We create a window containing our new table. */ -static void -create_table (void) -{ - GtkWidget *e_table, *window, *frame; - ECell *cell_left_just; - ETableHeader *e_table_header; - ETableModel *e_table_model = NULL; - int i; - - /* Next we create our model. This uses the functions we defined - earlier. */ - e_table_model = e_table_simple_new ( - my_col_count, my_row_count, my_value_at, - my_set_value_at, my_is_cell_editable, - my_duplicate_value, my_free_value, - my_initialize_value, my_value_is_empty, - my_value_to_string, - NULL); - /* - * Next we create a header. The ETableHeader is used in two - * different way. The first is the full_header. This is the - * list of possible columns in the view. The second use is - * completely internal. Many of the ETableHeader functions are - * for that purpose. The only functions we really need are - * e_table_header_new and e_table_header_add_col. - * - * First we create the header. - */ - e_table_header = e_table_header_new (); - - /* - * Next we have to build renderers for all of the columns. - * Since all our columns are text columns, we can simply use - * the same renderer over and over again. If we had different - * types of columns, we could use a different renderer for - * each column. - */ - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - /* - * Next we create a column object for each view column and add - * them to the header. We don't create a column object for - * the importance column since it will not be shown. - */ - for (i = 0; i < COLS; i++) { - /* Create the column. */ - ETableCol *ecol = e_table_col_new ( - i, headers [i], - 1.0, 20, cell_left_just, - g_str_compare, TRUE); - /* Add it to the header. */ - e_table_header_add_column (e_table_header, ecol, i); - } - - /* - * Here we create a window for our new table. This window - * will get shown and the person will be able to test their - * item. - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - - /* This frame is simply to get a bevel around our table. */ - frame = gtk_frame_new (NULL); - - /* - * Here we create the table. We give it the three pieces of - * the table we've created, the header, the model, and the - * initial layout. It does the rest. - */ - e_table = e_table_new (e_table_header, e_table_model, INITIAL_SPEC); - - /* Build the gtk widget hierarchy. */ - gtk_container_add (GTK_CONTAINER (frame), e_table); - gtk_container_add (GTK_CONTAINER (window), frame); - - /* Size the initial window. */ - gtk_widget_set_usize (window, 300, 200); - - /* Show it all. */ - gtk_widget_show_all (window); -} - -/* This is the main function which just initializes gnome and call our create_table function */ - -int -main (int argc, char *argv []) -{ - gnome_init ("TableExample", "TableExample", argc, argv); - e_cursors_init (); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - create_table (); - - gtk_main (); - - e_cursors_shutdown (); - return 0; -} - diff --git a/widgets/table/e-table-sort-info.c b/widgets/table/e-table-sort-info.c deleted file mode 100644 index 32ba3d9e65..0000000000 --- a/widgets/table/e-table-sort-info.c +++ /dev/null @@ -1,238 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-table-sort-info.c: a Table Model - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-table-sort-info.h" -#include "e-util/e-util.h" - -#define ETM_CLASS(e) ((ETableSortInfoClass *)((GtkObject *)e)->klass) - -#define PARENT_TYPE gtk_object_get_type () - - -static GtkObjectClass *e_table_sort_info_parent_class; - -enum { - SORT_INFO_CHANGED, - GROUP_INFO_CHANGED, - LAST_SIGNAL -}; - -static guint e_table_sort_info_signals [LAST_SIGNAL] = { 0, }; - -static void -etsi_destroy (GtkObject *object) -{ - ETableSortInfo *etsi; - - etsi = E_TABLE_SORT_INFO (object); - - if (etsi->groupings) - g_free(etsi->groupings); - if (etsi->sortings) - g_free(etsi->sortings); -} - -static void -e_table_sort_info_init (ETableSortInfo *info) -{ - info->group_count = 0; - info->groupings = NULL; - info->sort_count = 0; - info->sortings = NULL; - info->frozen = 0; - info->sort_info_changed = 0; - info->group_info_changed = 0; -} - -static void -e_table_sort_info_class_init (ETableSortInfoClass *klass) -{ - GtkObjectClass *object_class; - - e_table_sort_info_parent_class = gtk_type_class (gtk_object_get_type ()); - - object_class = GTK_OBJECT_CLASS(klass); - - object_class->destroy = etsi_destroy; - - e_table_sort_info_signals [SORT_INFO_CHANGED] = - gtk_signal_new ("sort_info_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableSortInfoClass, sort_info_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_table_sort_info_signals [GROUP_INFO_CHANGED] = - gtk_signal_new ("group_info_changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableSortInfoClass, group_info_changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - klass->sort_info_changed = NULL; - klass->group_info_changed = NULL; - - gtk_object_class_add_signals (object_class, e_table_sort_info_signals, LAST_SIGNAL); -} - -E_MAKE_TYPE(e_table_sort_info, "ETableSortInfo", ETableSortInfo, - e_table_sort_info_class_init, e_table_sort_info_init, PARENT_TYPE); - -static void -e_table_sort_info_sort_info_changed (ETableSortInfo *info) -{ - g_return_if_fail (info != NULL); - g_return_if_fail (E_IS_TABLE_SORT_INFO (info)); - - if (info->frozen) { - info->sort_info_changed = 1; - } else { - gtk_signal_emit (GTK_OBJECT (info), - e_table_sort_info_signals [SORT_INFO_CHANGED]); - } -} - -static void -e_table_sort_info_group_info_changed (ETableSortInfo *info) -{ - g_return_if_fail (info != NULL); - g_return_if_fail (E_IS_TABLE_SORT_INFO (info)); - - if (info->frozen) { - info->group_info_changed = 1; - } else { - gtk_signal_emit (GTK_OBJECT (info), - e_table_sort_info_signals [GROUP_INFO_CHANGED]); - } -} - -void -e_table_sort_info_freeze (ETableSortInfo *info) -{ - info->frozen = 1; -} - -void -e_table_sort_info_thaw (ETableSortInfo *info) -{ - info->frozen = 0; - 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); - } -} - - -guint -e_table_sort_info_grouping_get_count (ETableSortInfo *info) -{ - return info->group_count; -} - -static void -e_table_sort_info_grouping_real_truncate (ETableSortInfo *info, int length) -{ - if (length < info->group_count) { - info->group_count = length; - } - if (length > info->group_count) { - info->groupings = g_realloc(info->groupings, length * sizeof(ETableSortColumn)); - info->group_count = length; - } -} - -void -e_table_sort_info_grouping_truncate (ETableSortInfo *info, int length) -{ - e_table_sort_info_grouping_real_truncate(info, length); - e_table_sort_info_group_info_changed(info); -} - -ETableSortColumn -e_table_sort_info_grouping_get_nth (ETableSortInfo *info, int n) -{ - if (n < info->group_count) { - return info->groupings[n]; - } else { - ETableSortColumn fake = {0, 0}; - return fake; - } -} - -void -e_table_sort_info_grouping_set_nth (ETableSortInfo *info, int n, ETableSortColumn column) -{ - if (n >= info->group_count) { - e_table_sort_info_grouping_real_truncate(info, n + 1); - } - info->groupings[n] = column; - e_table_sort_info_group_info_changed(info); -} - - -guint -e_table_sort_info_sorting_get_count (ETableSortInfo *info) -{ - return info->sort_count; -} - -static void -e_table_sort_info_sorting_real_truncate (ETableSortInfo *info, int length) -{ - if (length < info->sort_count) { - info->sort_count = length; - } - if (length > info->sort_count) { - info->sortings = g_realloc(info->sortings, length * sizeof(ETableSortColumn)); - info->sort_count = length; - } -} - -void -e_table_sort_info_sorting_truncate (ETableSortInfo *info, int length) -{ - e_table_sort_info_sorting_real_truncate (info, length); - e_table_sort_info_sort_info_changed(info); -} - -ETableSortColumn -e_table_sort_info_sorting_get_nth (ETableSortInfo *info, int n) -{ - if (n < info->sort_count) { - return info->sortings[n]; - } else { - ETableSortColumn fake = {0, 0}; - return fake; - } -} - -void -e_table_sort_info_sorting_set_nth (ETableSortInfo *info, int n, ETableSortColumn column) -{ - if (n >= info->sort_count) { - e_table_sort_info_sorting_real_truncate(info, n + 1); - } - info->sortings[n] = column; - e_table_sort_info_sort_info_changed(info); -} - - -ETableSortInfo * -e_table_sort_info_new (void) -{ - return gtk_type_new (e_table_sort_info_get_type ()); -} diff --git a/widgets/table/e-table-sort-info.h b/widgets/table/e-table-sort-info.h deleted file mode 100644 index 6446230116..0000000000 --- a/widgets/table/e-table-sort-info.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SORT_INFO_H_ -#define _E_TABLE_SORT_INFO_H_ - -#include <gtk/gtkobject.h> - -#define E_TABLE_SORT_INFO_TYPE (e_table_sort_info_get_type ()) -#define E_TABLE_SORT_INFO(o) (GTK_CHECK_CAST ((o), E_TABLE_SORT_INFO_TYPE, ETableSortInfo)) -#define E_TABLE_SORT_INFO_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SORT_INFO_TYPE, ETableSortInfoClass)) -#define E_IS_TABLE_SORT_INFO(o) (GTK_CHECK_TYPE ((o), E_TABLE_SORT_INFO_TYPE)) -#define E_IS_TABLE_SORT_INFO_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SORT_INFO_TYPE)) - -typedef struct _ETableSortColumn ETableSortColumn; - -struct _ETableSortColumn { - guint column : 31; - guint ascending : 1; -}; - -typedef struct { - GtkObject base; - - gint group_count; - ETableSortColumn *groupings; - gint sort_count; - ETableSortColumn *sortings; - - guint frozen : 1; - guint sort_info_changed : 1; - guint group_info_changed : 1; -} ETableSortInfo; - -typedef struct { - GtkObjectClass parent_class; - - /* - * Signals - */ - void (*sort_info_changed) (ETableSortInfo *info); - void (*group_info_changed) (ETableSortInfo *info); -} ETableSortInfoClass; - -GtkType e_table_sort_info_get_type (void); - -void e_table_sort_info_freeze (ETableSortInfo *info); -void e_table_sort_info_thaw (ETableSortInfo *info); - -guint e_table_sort_info_grouping_get_count (ETableSortInfo *info); -void e_table_sort_info_grouping_truncate (ETableSortInfo *info, int length); -ETableSortColumn e_table_sort_info_grouping_get_nth (ETableSortInfo *info, int n); -void e_table_sort_info_grouping_set_nth (ETableSortInfo *info, int n, ETableSortColumn column); - -guint e_table_sort_info_sorting_get_count (ETableSortInfo *info); -void e_table_sort_info_sorting_truncate (ETableSortInfo *info, int length); -ETableSortColumn e_table_sort_info_sorting_get_nth (ETableSortInfo *info, int n); -void e_table_sort_info_sorting_set_nth (ETableSortInfo *info, int n, ETableSortColumn column); - -ETableSortInfo *e_table_sort_info_new (void); - -#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 7584b31a74..0000000000 --- a/widgets/table/e-table-sorted-variable.c +++ /dev/null @@ -1,337 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-sorted.c: Implements a table that sorts another table - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> -#include <string.h> -#include "e-util/e-util.h" -#include "e-table-sorted-variable.h" - -#define PARENT_TYPE E_TABLE_SUBSET_VARIABLE_TYPE - -#define INCREMENT_AMOUNT 100 - -static ETableSubsetVariableClass *etsv_parent_class; - -static void etsv_proxy_model_changed (ETableModel *etm, ETableSortedVariable *etsv); -#if 0 -static void etsv_proxy_model_row_changed (ETableModel *etm, int row, ETableSortedVariable *etsv); -static void etsv_proxy_model_cell_changed (ETableModel *etm, int col, int row, ETableSortedVariable *etsv); -#endif -static void etsv_sort_info_changed (ETableSortInfo *info, ETableSortedVariable *etsv); -static void etsv_sort (ETableSortedVariable *etsv); -static void etsv_add (ETableSubsetVariable *etssv, gint row); -static void etsv_add_all (ETableSubsetVariable *etssv); - -static void -etsv_destroy (GtkObject *object) -{ - ETableSortedVariable *etsv = E_TABLE_SORTED_VARIABLE (object); - ETableSubset *etss = E_TABLE_SUBSET (object); - - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etsv->table_model_changed_id); -#if 0 - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etsv->table_model_row_changed_id); - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etsv->table_model_cell_changed_id); -#endif - gtk_signal_disconnect (GTK_OBJECT (etsv->sort_info), - etsv->sort_info_changed_id); - - if (etsv->sort_idle_id) { - g_source_remove(etsv->sort_idle_id); - } - - etsv->table_model_changed_id = 0; - etsv->table_model_row_changed_id = 0; - etsv->table_model_cell_changed_id = 0; - - if (etsv->sort_info) - gtk_object_unref(GTK_OBJECT(etsv->sort_info)); - if (etsv->full_header) - gtk_object_unref(GTK_OBJECT(etsv->full_header)); - - GTK_OBJECT_CLASS (etsv_parent_class)->destroy (object); -} - -static void -etsv_class_init (GtkObjectClass *object_class) -{ - ETableSubsetVariableClass *etssv_class = E_TABLE_SUBSET_VARIABLE_CLASS(object_class); - - etsv_parent_class = gtk_type_class (PARENT_TYPE); - - object_class->destroy = etsv_destroy; - - etssv_class->add = etsv_add; - etssv_class->add_all = etsv_add_all; -} - -static void -etsv_init (ETableSortedVariable *etsv) -{ - etsv->full_header = NULL; - etsv->sort_info = NULL; - - etsv->table_model_changed_id = 0; - etsv->table_model_row_changed_id = 0; - etsv->table_model_cell_changed_id = 0; - etsv->sort_info_changed_id = 0; - - etsv->sort_idle_id = 0; -} - -E_MAKE_TYPE(e_table_sorted_variable, "ETableSortedVariable", ETableSortedVariable, etsv_class_init, etsv_init, PARENT_TYPE); - -static gboolean -etsv_sort_idle(ETableSortedVariable *etsv) -{ - gtk_object_ref(GTK_OBJECT(etsv)); - etsv_sort(etsv); - etsv->sort_idle_id = 0; - gtk_object_unref(GTK_OBJECT(etsv)); - return FALSE; -} - -/* This takes source rows. */ -static int -etsv_compare(ETableSortedVariable *etsv, int row1, int row2) -{ - int j; - int sort_count = e_table_sort_info_sorting_get_count(etsv->sort_info); - int comp_val = 0; - int ascending = 1; - ETableSubset *etss = E_TABLE_SUBSET(etsv); - - for (j = 0; j < sort_count; j++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(etsv->sort_info, j); - ETableCol *col; - if (column.column > e_table_header_count (etsv->full_header)) - col = e_table_header_get_column (etsv->full_header, e_table_header_count (etsv->full_header) - 1); - else - col = e_table_header_get_column (etsv->full_header, column.column); - comp_val = (*col->compare)(e_table_model_value_at (etss->source, col->col_idx, row1), - e_table_model_value_at (etss->source, col->col_idx, row2)); - ascending = column.ascending; - if (comp_val != 0) - break; - } - if (comp_val == 0) { - if (row1 < row2) - comp_val = -1; - if (row1 > row2) - comp_val = 1; - } - if (!ascending) - comp_val = -comp_val; - return comp_val; -} - - -static void -etsv_add (ETableSubsetVariable *etssv, - gint row) -{ - ETableModel *etm = E_TABLE_MODEL(etssv); - ETableSubset *etss = E_TABLE_SUBSET(etssv); - ETableSortedVariable *etsv = E_TABLE_SORTED_VARIABLE (etssv); - int i; - - if (etss->n_map + 1 > etssv->n_vals_allocated) { - etssv->n_vals_allocated += INCREMENT_AMOUNT; - etss->map_table = g_realloc (etss->map_table, (etssv->n_vals_allocated) * sizeof(int)); - } - i = etss->n_map; - if (etsv->sort_idle_id == 0) { - i = 0; - while (i < etss->n_map && etsv_compare(etsv, etss->map_table[i], row) < 0) - i++; - memmove(etss->map_table + i + 1, etss->map_table + i, (etss->n_map - i) * sizeof(int)); - } - etss->map_table[i] = row; - etss->n_map++; - - e_table_model_row_inserted (etm, i); -} - -static void -etsv_add_all (ETableSubsetVariable *etssv) -{ - ETableModel *etm = E_TABLE_MODEL(etssv); - ETableSubset *etss = E_TABLE_SUBSET(etssv); - ETableSortedVariable *etsv = E_TABLE_SORTED_VARIABLE (etssv); - int rows; - int i; - - e_table_model_pre_change(etm); - - rows = e_table_model_row_count(etss->source); - - if (etss->n_map + rows > etssv->n_vals_allocated){ - etssv->n_vals_allocated += MAX(INCREMENT_AMOUNT, rows); - etss->map_table = g_realloc (etss->map_table, etssv->n_vals_allocated * sizeof(int)); - } - for (i = 0; i < rows; i++) - etss->map_table[etss->n_map++] = i; - - if (etsv->sort_idle_id == 0) { - etsv->sort_idle_id = g_idle_add_full(50, (GSourceFunc) etsv_sort_idle, etsv, NULL); - } - - e_table_model_changed (etm); -} - -ETableModel * -e_table_sorted_variable_new (ETableModel *source, ETableHeader *full_header, ETableSortInfo *sort_info) -{ - ETableSortedVariable *etsv = gtk_type_new (E_TABLE_SORTED_VARIABLE_TYPE); - ETableSubsetVariable *etssv = E_TABLE_SUBSET_VARIABLE (etsv); - - if (e_table_subset_variable_construct (etssv, source) == NULL){ - gtk_object_destroy (GTK_OBJECT (etsv)); - return NULL; - } - - etsv->sort_info = sort_info; - gtk_object_ref(GTK_OBJECT(etsv->sort_info)); - etsv->full_header = full_header; - gtk_object_ref(GTK_OBJECT(etsv->full_header)); - - etsv->table_model_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_changed", - GTK_SIGNAL_FUNC (etsv_proxy_model_changed), etsv); -#if 0 - etsv->table_model_row_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_row_changed", - GTK_SIGNAL_FUNC (etsv_proxy_model_row_changed), etsv); - etsv->table_model_cell_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_cell_changed", - GTK_SIGNAL_FUNC (etsv_proxy_model_cell_changed), etsv); -#endif - etsv->sort_info_changed_id = gtk_signal_connect (GTK_OBJECT (sort_info), "sort_info_changed", - GTK_SIGNAL_FUNC (etsv_sort_info_changed), etsv); - - return E_TABLE_MODEL(etsv); -} - -static void -etsv_proxy_model_changed (ETableModel *etm, ETableSortedVariable *etsv) -{ - /* FIXME: do_resort (); */ -} -#if 0 -static void -etsv_proxy_model_row_changed (ETableModel *etm, int row, ETableSortedVariable *etsv) -{ - ETableSubsetVariable *etssv = E_TABLE_SUBSET_VARIABLE(etsv); - - if (e_table_subset_variable_remove(etssv, row)) - e_table_subset_variable_add (etssv, row); -} - -static void -etsv_proxy_model_cell_changed (ETableModel *etm, int col, int row, ETableSortedVariable *etsv) -{ - ETableSubsetVariable *etssv = E_TABLE_SUBSET_VARIABLE(etsv); - - if (e_table_subset_variable_remove(etssv, row)) - e_table_subset_variable_add (etssv, row); -} -#endif - -static void -etsv_sort_info_changed (ETableSortInfo *info, ETableSortedVariable *etsv) -{ - etsv_sort(etsv); -} - -static ETableSortedVariable *etsv_closure; -void **vals_closure; -int cols_closure; -int *ascending_closure; -GCompareFunc *compare_closure; - -/* FIXME: Make it not cache the second and later columns (as if anyone cares.) */ - -static int -qsort_callback(const void *data1, const void *data2) -{ - gint row1 = *(int *)data1; - gint row2 = *(int *)data2; - int j; - int sort_count = e_table_sort_info_sorting_get_count(etsv_closure->sort_info); - int comp_val = 0; - int ascending = 1; - for (j = 0; j < sort_count; j++) { - comp_val = (*(compare_closure[j]))(vals_closure[cols_closure * row1 + j], vals_closure[cols_closure * row2 + j]); - ascending = ascending_closure[j]; - if (comp_val != 0) - break; - } - if (comp_val == 0) { - if (row1 < row2) - comp_val = -1; - if (row1 > row2) - comp_val = 1; - } - if (!ascending) - comp_val = -comp_val; - return comp_val; -} - - -static void -etsv_sort(ETableSortedVariable *etsv) -{ - ETableSubset *etss = E_TABLE_SUBSET(etsv); - static int reentering = 0; - int rows = E_TABLE_SUBSET(etsv)->n_map; - int total_rows; - int i; - int j; - int cols; - if (reentering) - return; - reentering = 1; - - e_table_model_pre_change(E_TABLE_MODEL(etsv)); - - total_rows = e_table_model_row_count(E_TABLE_SUBSET(etsv)->source); - cols = e_table_sort_info_sorting_get_count(etsv->sort_info); - cols_closure = cols; - etsv_closure = etsv; - vals_closure = g_new(void *, total_rows * cols); - ascending_closure = g_new(int, cols); - compare_closure = g_new(GCompareFunc, cols); - for (j = 0; j < cols; j++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(etsv->sort_info, j); - ETableCol *col; - if (column.column > e_table_header_count (etsv->full_header)) - col = e_table_header_get_column (etsv->full_header, e_table_header_count (etsv->full_header) - 1); - else - col = e_table_header_get_column (etsv->full_header, column.column); - for (i = 0; i < rows; i++) { -#if 0 - if( !(i & 0xff) ) { - while(gtk_events_pending()) - gtk_main_iteration(); - } -#endif - vals_closure[E_TABLE_SUBSET(etsv)->map_table[i] * cols + j] = e_table_model_value_at (etss->source, col->col_idx, E_TABLE_SUBSET(etsv)->map_table[i]); - } - compare_closure[j] = col->compare; - ascending_closure[j] = column.ascending; - } - qsort(E_TABLE_SUBSET(etsv)->map_table, rows, sizeof(int), qsort_callback); - g_free(vals_closure); - g_free(ascending_closure); - g_free(compare_closure); - e_table_model_changed (E_TABLE_MODEL(etsv)); - reentering = 0; -} diff --git a/widgets/table/e-table-sorted-variable.h b/widgets/table/e-table-sorted-variable.h deleted file mode 100644 index c6a57c5ede..0000000000 --- a/widgets/table/e-table-sorted-variable.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SORTED_VARIABLE_H_ -#define _E_TABLE_SORTED_VARIABLE_H_ - -#include <gtk/gtkobject.h> -#include "e-table-model.h" -#include "e-table-subset-variable.h" -#include "e-table-sort-info.h" -#include "e-table-header.h" - -#define E_TABLE_SORTED_VARIABLE_TYPE (e_table_sorted_variable_get_type ()) -#define E_TABLE_SORTED_VARIABLE(o) (GTK_CHECK_CAST ((o), E_TABLE_SORTED_VARIABLE_TYPE, ETableSortedVariable)) -#define E_TABLE_SORTED_VARIABLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SORTED_VARIABLE_TYPE, ETableSortedVariableClass)) -#define E_IS_TABLE_SORTED_VARIABLE(o) (GTK_CHECK_TYPE ((o), E_TABLE_SORTED_VARIABLE_TYPE)) -#define E_IS_TABLE_SORTED_VARIABLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SORTED_VARIABLE_TYPE)) - -typedef struct { - ETableSubsetVariable base; - - ETableSortInfo *sort_info; - - ETableHeader *full_header; - - int table_model_changed_id; - int table_model_row_changed_id; - int table_model_cell_changed_id; - int sort_info_changed_id; - int sort_idle_id; -} ETableSortedVariable; - -typedef struct { - ETableSubsetVariableClass parent_class; -} ETableSortedVariableClass; - -GtkType e_table_sorted_variable_get_type (void); -ETableModel *e_table_sorted_variable_new (ETableModel *etm, ETableHeader *header, ETableSortInfo *sort_info); - -#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 c754f4cff7..0000000000 --- a/widgets/table/e-table-sorted.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * E-table-sorted.c: Implements a table that sorts another table - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include "e-util/e-util.h" -#include "e-table-sorted.h" - -#define PARENT_TYPE E_TABLE_SUBSET_TYPE - -static ETableSubsetClass *ets_parent_class; - -static void -ets_class_init (GtkObjectClass *klass) -{ - ets_parent_class = gtk_type_class (PARENT_TYPE); -} - -E_MAKE_TYPE(e_table_sorted, "ETableSorted", ETableSorted, ets_class_init, NULL, PARENT_TYPE); - -static ETableSorted *sort_ets; - -static int -my_sort (const void *a, const void *b) -{ - ETableModel *source = E_TABLE_SUBSET (sort_ets)->source; - const int *ia = (const int *) a; - const int *ib = (const int *) b; - void *va, *vb; - - va = e_table_model_value_at (source, sort_ets->sort_col, *ia); - vb = e_table_model_value_at (source, sort_ets->sort_col, *ib); - - return (*sort_ets->compare) (va, vb); -} - -static void -do_sort (ETableSorted *ets) -{ - ETableSubset *etss = E_TABLE_SUBSET (ets); - g_assert (sort_ets == NULL); - - sort_ets = ets; - qsort (etss->map_table, etss->n_map, sizeof (unsigned int), my_sort); - sort_ets = NULL; -} - -ETableModel * -e_table_sorted_new (ETableModel *source, int col, GCompareFunc compare) -{ - ETableSorted *ets = gtk_type_new (E_TABLE_SORTED_TYPE); - ETableSubset *etss = E_TABLE_SUBSET (ets); - const int nvals = e_table_model_row_count (source); - int i; - - if (e_table_subset_construct (etss, source, nvals) == NULL){ - gtk_object_destroy (GTK_OBJECT (ets)); - return NULL; - } - - ets->compare = compare; - ets->sort_col = col; - - /* Init */ - for (i = 0; i < nvals; i++) - etss->map_table [i] = i; - - do_sort (ets); - - return (ETableModel *) ets; -} - -void -e_table_sorted_resort (ETableSorted *ets, int col, GCompareFunc compare) -{ - if (col == -1 || compare == NULL) - do_sort (ets); - else { - ets->sort_col = col; - ets->compare = compare; - do_sort (ets); - } -} - diff --git a/widgets/table/e-table-sorted.h b/widgets/table/e-table-sorted.h deleted file mode 100644 index 92bd8d1522..0000000000 --- a/widgets/table/e-table-sorted.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef _E_TABLE_SORTED_H_ -#define _E_TABLE_SORTED_H_ - -#include <gtk/gtkobject.h> -#include "e-table-model.h" -#include "e-table-subset.h" - -#define E_TABLE_SORTED_TYPE (e_table_sorted_get_type ()) -#define E_TABLE_SORTED(o) (GTK_CHECK_CAST ((o), E_TABLE_SORTED_TYPE, ETableSorted)) -#define E_TABLE_SORTED_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SORTED_TYPE, ETableSortedClass)) -#define E_IS_TABLE_SORTED(o) (GTK_CHECK_TYPE ((o), E_TABLE_SORTED_TYPE)) -#define E_IS_TABLE_SORTED_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SORTED_TYPE)) - -typedef struct { - ETableSubset base; - - short sort_col; - GCompareFunc compare; -} ETableSorted; - -typedef struct { - ETableSubsetClass parent_class; -} ETableSortedClass; - -GtkType e_table_sorted_get_type (void); -ETableModel *e_table_sorted_new (ETableModel *etm, int col, GCompareFunc compare); -void e_table_sorted_resort (ETableSorted *ets, int col, GCompareFunc compare); - -#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 eb2391b0d0..0000000000 --- a/widgets/table/e-table-sorter.c +++ /dev/null @@ -1,295 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-sorted.c: Implements a table that sorts another table - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> -#include <string.h> -#include "e-util/e-util.h" -#include "e-table-sorter.h" - -#define PARENT_TYPE gtk_object_get_type() - -#define INCREMENT_AMOUNT 100 - -static GtkObjectClass *parent_class; - -static void ets_model_changed (ETableModel *etm, ETableSorter *ets); -static void ets_model_row_changed (ETableModel *etm, int row, ETableSorter *ets); -static void ets_model_cell_changed (ETableModel *etm, int col, int row, ETableSorter *ets); -static void ets_sort_info_changed (ETableSortInfo *info, ETableSorter *ets); -static void ets_clean (ETableSorter *ets); -static void ets_sort (ETableSorter *ets); -static void ets_backsort (ETableSorter *ets); - -static void -ets_destroy (GtkObject *object) -{ - ETableSorter *ets = E_TABLE_SORTER (object); - - gtk_signal_disconnect (GTK_OBJECT (ets->source), - ets->table_model_changed_id); - gtk_signal_disconnect (GTK_OBJECT (ets->source), - ets->table_model_row_changed_id); - gtk_signal_disconnect (GTK_OBJECT (ets->source), - ets->table_model_cell_changed_id); - gtk_signal_disconnect (GTK_OBJECT (ets->sort_info), - ets->sort_info_changed_id); - - ets->table_model_changed_id = 0; - ets->table_model_row_changed_id = 0; - ets->table_model_cell_changed_id = 0; - ets->sort_info_changed_id = 0; - - if (ets->sort_info) - gtk_object_unref(GTK_OBJECT(ets->sort_info)); - if (ets->full_header) - gtk_object_unref(GTK_OBJECT(ets->full_header)); - if (ets->source) - gtk_object_unref(GTK_OBJECT(ets->source)); - - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -static void -ets_class_init (ETableSorterClass *klass) -{ - GtkObjectClass *object_class = GTK_OBJECT_CLASS(klass); - - parent_class = gtk_type_class (PARENT_TYPE); - - object_class->destroy = ets_destroy; -} - -static void -ets_init (ETableSorter *ets) -{ - ets->full_header = NULL; - ets->sort_info = NULL; - ets->source = NULL; - - ets->needs_sorting = -1; - - ets->table_model_changed_id = 0; - ets->table_model_row_changed_id = 0; - ets->table_model_cell_changed_id = 0; - ets->sort_info_changed_id = 0; -} - -E_MAKE_TYPE(e_table_sorter, "ETableSorter", ETableSorter, ets_class_init, ets_init, PARENT_TYPE); - -ETableSorter * -e_table_sorter_new (ETableModel *source, ETableHeader *full_header, ETableSortInfo *sort_info) -{ - ETableSorter *ets = gtk_type_new (E_TABLE_SORTER_TYPE); - - ets->sort_info = sort_info; - gtk_object_ref(GTK_OBJECT(ets->sort_info)); - ets->full_header = full_header; - gtk_object_ref(GTK_OBJECT(ets->full_header)); - ets->source = source; - gtk_object_ref(GTK_OBJECT(ets->source)); - - ets->table_model_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_changed", - GTK_SIGNAL_FUNC (ets_model_changed), ets); - ets->table_model_row_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_row_changed", - GTK_SIGNAL_FUNC (ets_model_row_changed), ets); - ets->table_model_cell_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_cell_changed", - GTK_SIGNAL_FUNC (ets_model_cell_changed), ets); - ets->sort_info_changed_id = gtk_signal_connect (GTK_OBJECT (sort_info), "sort_info_changed", - GTK_SIGNAL_FUNC (ets_sort_info_changed), ets); - - return ets; -} - -static void -ets_model_changed (ETableModel *etm, ETableSorter *ets) -{ - ets_clean(ets); -} - -static void -ets_model_row_changed (ETableModel *etm, int row, ETableSorter *ets) -{ - ets_clean(ets); -} - -static void -ets_model_cell_changed (ETableModel *etm, int col, int row, ETableSorter *ets) -{ - ets_clean(ets); -} - -static void -ets_sort_info_changed (ETableSortInfo *info, ETableSorter *ets) -{ - ets_clean(ets); -} - -static ETableSorter *ets_closure; -void **vals_closure; -int cols_closure; -int *ascending_closure; -GCompareFunc *compare_closure; - -/* FIXME: Make it not cache the second and later columns (as if anyone cares.) */ - -static int -qsort_callback(const void *data1, const void *data2) -{ - gint row1 = *(int *)data1; - gint row2 = *(int *)data2; - int j; - int sort_count = e_table_sort_info_sorting_get_count(ets_closure->sort_info) + e_table_sort_info_grouping_get_count(ets_closure->sort_info); - int comp_val = 0; - int ascending = 1; - for (j = 0; j < sort_count; j++) { - comp_val = (*(compare_closure[j]))(vals_closure[cols_closure * row1 + j], vals_closure[cols_closure * row2 + j]); - ascending = ascending_closure[j]; - if (comp_val != 0) - break; - } - if (comp_val == 0) { - if (row1 < row2) - comp_val = -1; - if (row1 > row2) - comp_val = 1; - } - if (!ascending) - comp_val = -comp_val; - return comp_val; -} - -static void -ets_clean(ETableSorter *ets) -{ - g_free(ets->sorted); - ets->sorted = NULL; - - g_free(ets->backsorted); - ets->backsorted = NULL; - - ets->needs_sorting = -1; -} - -static void -ets_sort(ETableSorter *ets) -{ - int rows; - int i; - int j; - int cols; - int group_cols; - - if (ets->sorted) - return; - - rows = e_table_model_row_count(ets->source); - group_cols = e_table_sort_info_grouping_get_count(ets->sort_info); - cols = e_table_sort_info_sorting_get_count(ets->sort_info) + group_cols; - - ets->sorted = g_new(int, rows); - for (i = 0; i < rows; i++) - ets->sorted[i] = i; - - cols_closure = cols; - ets_closure = ets; - - vals_closure = g_new(void *, rows * cols); - ascending_closure = g_new(int, cols); - compare_closure = g_new(GCompareFunc, cols); - - for (j = 0; j < cols; j++) { - ETableSortColumn column; - ETableCol *col; - - if (j < group_cols) - column = e_table_sort_info_grouping_get_nth(ets->sort_info, j); - else - column = e_table_sort_info_sorting_get_nth(ets->sort_info, j - group_cols); - - if (column.column > e_table_header_count (ets->full_header)) - col = e_table_header_get_column (ets->full_header, e_table_header_count (ets->full_header) - 1); - else - col = e_table_header_get_column (ets->full_header, column.column); - - for (i = 0; i < rows; i++) { - vals_closure[i * cols + j] = e_table_model_value_at (ets->source, col->col_idx, i); - } - - compare_closure[j] = col->compare; - ascending_closure[j] = column.ascending; - } - qsort(ets->sorted, rows, sizeof(int), qsort_callback); - - g_free(vals_closure); - g_free(ascending_closure); - g_free(compare_closure); -} - -static void -ets_backsort(ETableSorter *ets) -{ - int i, rows; - - if (ets->backsorted) - return; - - ets_sort(ets); - - rows = e_table_model_row_count(ets->source); - ets->backsorted = g_new0(int, rows); - - for (i = 0; i < rows; i++) { - ets->backsorted[ets->sorted[i]] = i; - } -} - -gboolean -e_table_sorter_needs_sorting(ETableSorter *ets) -{ - if (ets->needs_sorting < 0) { - if (e_table_sort_info_sorting_get_count(ets->sort_info) + e_table_sort_info_grouping_get_count(ets->sort_info)) - ets->needs_sorting = 1; - else - ets->needs_sorting = 0; - } - return ets->needs_sorting; -} - - -gint -e_table_sorter_model_to_sorted (ETableSorter *sorter, int row) -{ - int rows = e_table_model_row_count(sorter->source); - - g_return_val_if_fail(row >= 0, -1); - g_return_val_if_fail(row < rows, -1); - - if (e_table_sorter_needs_sorting(sorter)) { - ets_backsort(sorter); - return sorter->backsorted[row]; - } else - return row; -} - -gint -e_table_sorter_sorted_to_model (ETableSorter *sorter, int row) -{ - int rows = e_table_model_row_count(sorter->source); - - g_return_val_if_fail(row >= 0, -1); - g_return_val_if_fail(row < rows, -1); - - if (e_table_sorter_needs_sorting(sorter)) { - ets_sort(sorter); - return sorter->sorted[row]; - } else - return row; -} diff --git a/widgets/table/e-table-sorter.h b/widgets/table/e-table-sorter.h deleted file mode 100644 index f5a71565a3..0000000000 --- a/widgets/table/e-table-sorter.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SORTER_H_ -#define _E_TABLE_SORTER_H_ - -#include <gtk/gtkobject.h> -#include "e-table-model.h" -#include "e-table-subset-variable.h" -#include "e-table-sort-info.h" -#include "e-table-header.h" - -#define E_TABLE_SORTER_TYPE (e_table_sorter_get_type ()) -#define E_TABLE_SORTER(o) (GTK_CHECK_CAST ((o), E_TABLE_SORTER_TYPE, ETableSorter)) -#define E_TABLE_SORTER_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SORTER_TYPE, ETableSorterClass)) -#define E_IS_TABLE_SORTER(o) (GTK_CHECK_TYPE ((o), E_TABLE_SORTER_TYPE)) -#define E_IS_TABLE_SORTER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SORTER_TYPE)) - -typedef struct { - GtkObject base; - - ETableModel *source; - ETableHeader *full_header; - ETableSortInfo *sort_info; - - int needs_sorting; - - int *sorted; - int *backsorted; - - int table_model_changed_id; - int table_model_row_changed_id; - int table_model_cell_changed_id; - int sort_info_changed_id; -} ETableSorter; - -typedef struct { - GtkObjectClass parent_class; -} ETableSorterClass; - -GtkType e_table_sorter_get_type (void); -ETableSorter *e_table_sorter_new (ETableModel *etm, ETableHeader *full_header, ETableSortInfo *sort_info); - -gint e_table_sorter_model_to_sorted (ETableSorter *sorter, int row); -gint e_table_sorter_sorted_to_model (ETableSorter *sorter, int row); - -gboolean e_table_sorter_needs_sorting (ETableSorter *sorter); - -#endif /* _E_TABLE_SORTER_H_ */ diff --git a/widgets/table/e-table-subset-variable.c b/widgets/table/e-table-subset-variable.c deleted file mode 100644 index d429604301..0000000000 --- a/widgets/table/e-table-subset-variable.c +++ /dev/null @@ -1,193 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-subset.c: Implements a table that contains a subset of another table. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> -#include <string.h> -#include "e-util/e-util.h" -#include "e-table-subset-variable.h" - -#define ETSSV_CLASS(e) ((ETableSubsetVariableClass *)((GtkObject *)e)->klass) - -#define PARENT_TYPE E_TABLE_SUBSET_TYPE - -#define INCREMENT_AMOUNT 10 - -static ETableSubsetClass *etssv_parent_class; - -static void -etssv_add (ETableSubsetVariable *etssv, - gint row) -{ - ETableModel *etm = E_TABLE_MODEL(etssv); - ETableSubset *etss = E_TABLE_SUBSET(etssv); - - e_table_model_pre_change(etm); - - if (etss->n_map + 1 > etssv->n_vals_allocated){ - etss->map_table = g_realloc (etss->map_table, (etssv->n_vals_allocated + INCREMENT_AMOUNT) * sizeof(int)); - etssv->n_vals_allocated += INCREMENT_AMOUNT; - } - - etss->map_table[etss->n_map++] = row; - - e_table_model_row_inserted (etm, etss->n_map - 1); -} - -static void -etssv_add_all (ETableSubsetVariable *etssv) -{ - ETableModel *etm = E_TABLE_MODEL(etssv); - ETableSubset *etss = E_TABLE_SUBSET(etssv); - int rows; - int i; - - e_table_model_pre_change(etm); - - rows = e_table_model_row_count(etss->source); - if (etss->n_map + rows > etssv->n_vals_allocated){ - etssv->n_vals_allocated += MAX(INCREMENT_AMOUNT, rows); - etss->map_table = g_realloc (etss->map_table, etssv->n_vals_allocated * sizeof(int)); - } - for (i = 0; i < rows; i++) - etss->map_table[etss->n_map++] = i; - - e_table_model_changed (etm); -} - -static gboolean -etssv_remove (ETableSubsetVariable *etssv, - gint row) -{ - ETableModel *etm = E_TABLE_MODEL(etssv); - ETableSubset *etss = E_TABLE_SUBSET(etssv); - int i; - - for (i = 0; i < etss->n_map; i++){ - if (etss->map_table[i] == row) { - e_table_model_pre_change (etm); - memmove (etss->map_table + i, etss->map_table + i + 1, (etss->n_map - i - 1) * sizeof(int)); - etss->n_map --; - - e_table_model_row_deleted (etm, i); - return TRUE; - } - } - return FALSE; -} - -static void -etssv_class_init (GtkObjectClass *object_class) -{ - ETableSubsetVariableClass *klass = E_TABLE_SUBSET_VARIABLE_CLASS(object_class); - etssv_parent_class = gtk_type_class (PARENT_TYPE); - - klass->add = etssv_add; - klass->add_all = etssv_add_all; - klass->remove = etssv_remove; -} - -E_MAKE_TYPE(e_table_subset_variable, "ETableSubsetVariable", ETableSubsetVariable, etssv_class_init, NULL, PARENT_TYPE); - -ETableModel * -e_table_subset_variable_construct (ETableSubsetVariable *etssv, - ETableModel *source) -{ - if (e_table_subset_construct (E_TABLE_SUBSET(etssv), source, 1) == NULL) - return NULL; - E_TABLE_SUBSET(etssv)->n_map = 0; - - return E_TABLE_MODEL (etssv); -} - -ETableModel * -e_table_subset_variable_new (ETableModel *source) -{ - ETableSubsetVariable *etssv = gtk_type_new (E_TABLE_SUBSET_VARIABLE_TYPE); - - if (e_table_subset_variable_construct (etssv, source) == NULL){ - gtk_object_destroy (GTK_OBJECT (etssv)); - return NULL; - } - - return (ETableModel *) etssv; -} - -void -e_table_subset_variable_add (ETableSubsetVariable *etssv, - gint row) -{ - g_return_if_fail (etssv != NULL); - g_return_if_fail (E_IS_TABLE_SUBSET_VARIABLE(etssv)); - - if (ETSSV_CLASS(etssv)->add) - ETSSV_CLASS (etssv)->add (etssv, row); -} - -void -e_table_subset_variable_add_all (ETableSubsetVariable *etssv) -{ - g_return_if_fail (etssv != NULL); - g_return_if_fail (E_IS_TABLE_SUBSET_VARIABLE(etssv)); - - if (ETSSV_CLASS(etssv)->add_all) - ETSSV_CLASS (etssv)->add_all (etssv); -} - -gboolean -e_table_subset_variable_remove (ETableSubsetVariable *etssv, - gint row) -{ - g_return_val_if_fail (etssv != NULL, FALSE); - g_return_val_if_fail (E_IS_TABLE_SUBSET_VARIABLE(etssv), FALSE); - - if (ETSSV_CLASS(etssv)->remove) - return ETSSV_CLASS (etssv)->remove (etssv, row); - else - return FALSE; -} - -void -e_table_subset_variable_increment (ETableSubsetVariable *etssv, - gint position, - gint amount) -{ - int i; - ETableSubset *etss = E_TABLE_SUBSET(etssv); - for (i = 0; i < etss->n_map; i++) { - if (etss->map_table[i] > position) - etss->map_table[i] += amount; - } -} - -void -e_table_subset_variable_decrement (ETableSubsetVariable *etssv, - gint position, - gint amount) -{ - int i; - ETableSubset *etss = E_TABLE_SUBSET(etssv); - for (i = 0; i < etss->n_map; i++) { - if (etss->map_table[i] > position) - etss->map_table[i] -= amount; - } -} - -void -e_table_subset_variable_set_allocation (ETableSubsetVariable *etssv, - gint total) -{ - ETableSubset *etss = E_TABLE_SUBSET(etssv); - if (total <= 0) - total = 1; - if (total > etss->n_map){ - etss->map_table = g_realloc (etss->map_table, total * sizeof(int)); - } -} diff --git a/widgets/table/e-table-subset-variable.h b/widgets/table/e-table-subset-variable.h deleted file mode 100644 index 9d44828728..0000000000 --- a/widgets/table/e-table-subset-variable.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SUBSET_VARIABLE_H_ -#define _E_TABLE_SUBSET_VARIABLE_H_ - -#include <gtk/gtkobject.h> -#include "e-table-subset.h" - -#define E_TABLE_SUBSET_VARIABLE_TYPE (e_table_subset_variable_get_type ()) -#define E_TABLE_SUBSET_VARIABLE(o) (GTK_CHECK_CAST ((o), E_TABLE_SUBSET_VARIABLE_TYPE, ETableSubsetVariable)) -#define E_TABLE_SUBSET_VARIABLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SUBSET_VARIABLE_TYPE, ETableSubsetVariableClass)) -#define E_IS_TABLE_SUBSET_VARIABLE(o) (GTK_CHECK_TYPE ((o), E_TABLE_SUBSET_VARIABLE_TYPE)) -#define E_IS_TABLE_SUBSET_VARIABLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SUBSET_VARIABLE_TYPE)) - -typedef struct { - ETableSubset base; - - int n_vals_allocated; -} ETableSubsetVariable; - -typedef struct { - ETableSubsetClass parent_class; - - void (*add) (ETableSubsetVariable *ets, - gint row); - void (*add_all) (ETableSubsetVariable *ets); - gboolean (*remove) (ETableSubsetVariable *ets, - gint row); -} ETableSubsetVariableClass; - -GtkType e_table_subset_variable_get_type (void); -ETableModel *e_table_subset_variable_new (ETableModel *etm); -ETableModel *e_table_subset_variable_construct (ETableSubsetVariable *etssv, - ETableModel *source); -void e_table_subset_variable_add (ETableSubsetVariable *ets, - gint row); -void e_table_subset_variable_add_all (ETableSubsetVariable *ets); -gboolean e_table_subset_variable_remove (ETableSubsetVariable *ets, - gint row); -void e_table_subset_variable_increment (ETableSubsetVariable *ets, - gint position, - gint amount); -void e_table_subset_variable_decrement (ETableSubsetVariable *ets, - gint position, - gint amount); -void e_table_subset_variable_set_allocation (ETableSubsetVariable *ets, - gint total); -#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 1cac0f88ea..0000000000 --- a/widgets/table/e-table-subset.c +++ /dev/null @@ -1,253 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table-subset.c: Implements a table that contains a subset of another table. - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - * - * (C) 1999 Helix Code, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> -#include "e-util/e-util.h" -#include "e-table-subset.h" - -#define PARENT_TYPE E_TABLE_MODEL_TYPE - -static ETableModelClass *etss_parent_class; - -static void -etss_destroy (GtkObject *object) -{ - ETableSubset *etss = E_TABLE_SUBSET (object); - - if (etss->source) - gtk_object_unref (GTK_OBJECT (etss->source)); - - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etss->table_model_pre_change_id); - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etss->table_model_changed_id); - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etss->table_model_row_changed_id); - gtk_signal_disconnect (GTK_OBJECT (etss->source), - etss->table_model_cell_changed_id); - - etss->table_model_pre_change_id = 0; - etss->table_model_changed_id = 0; - etss->table_model_row_changed_id = 0; - etss->table_model_cell_changed_id = 0; - - g_free (etss->map_table); - - GTK_OBJECT_CLASS (etss_parent_class)->destroy (object); -} - -static int -etss_column_count (ETableModel *etm) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_column_count (etss->source); -} - -static int -etss_row_count (ETableModel *etm) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return etss->n_map; -} - -static void * -etss_value_at (ETableModel *etm, int col, int row) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_value_at (etss->source, col, etss->map_table [row]); -} - -static void -etss_set_value_at (ETableModel *etm, int col, int row, const void *val) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_set_value_at (etss->source, col, etss->map_table [row], val); -} - -static gboolean -etss_is_cell_editable (ETableModel *etm, int col, int row) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_is_cell_editable (etss->source, col, etss->map_table [row]); -} - -static void -etss_append_row (ETableModel *etm, ETableModel *source, int row) -{ - ETableSubset *etss = (ETableSubset *)etm; - e_table_model_append_row (etss->source, source, row); -} - -static void * -etss_duplicate_value (ETableModel *etm, int col, const void *value) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_duplicate_value (etss->source, col, value); -} - -static void -etss_free_value (ETableModel *etm, int col, void *value) -{ - ETableSubset *etss = (ETableSubset *)etm; - - e_table_model_free_value (etss->source, col, value); -} - -static void * -etss_initialize_value (ETableModel *etm, int col) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_initialize_value (etss->source, col); -} - -static gboolean -etss_value_is_empty (ETableModel *etm, int col, const void *value) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_value_is_empty (etss->source, col, value); -} - -static char * -etss_value_to_string (ETableModel *etm, int col, const void *value) -{ - ETableSubset *etss = (ETableSubset *)etm; - - return e_table_model_value_to_string (etss->source, col, value); -} - -static void -etss_class_init (GtkObjectClass *klass) -{ - ETableModelClass *table_class = (ETableModelClass *) klass; - - etss_parent_class = gtk_type_class (PARENT_TYPE); - - klass->destroy = etss_destroy; - - table_class->column_count = etss_column_count; - table_class->row_count = etss_row_count; - table_class->value_at = etss_value_at; - table_class->set_value_at = etss_set_value_at; - table_class->is_cell_editable = etss_is_cell_editable; - table_class->append_row = etss_append_row; - table_class->duplicate_value = etss_duplicate_value; - table_class->free_value = etss_free_value; - table_class->initialize_value = etss_initialize_value; - table_class->value_is_empty = etss_value_is_empty; - table_class->value_to_string = etss_value_to_string; -} - -E_MAKE_TYPE(e_table_subset, "ETableSubset", ETableSubset, etss_class_init, NULL, PARENT_TYPE); - -static void -etss_proxy_model_pre_change (ETableModel *etm, ETableSubset *etss) -{ - e_table_model_pre_change (E_TABLE_MODEL (etss)); -} - -static void -etss_proxy_model_changed (ETableModel *etm, ETableSubset *etss) -{ - e_table_model_changed (E_TABLE_MODEL (etss)); -} - -static void -etss_proxy_model_row_changed (ETableModel *etm, int row, ETableSubset *etss) -{ - const int n = etss->n_map; - const int * const map_table = etss->map_table; - int i; - - for (i = 0; i < n; i++){ - if (map_table [i] == row){ - e_table_model_row_changed (E_TABLE_MODEL (etss), i); - return; - } - } -} - -static void -etss_proxy_model_cell_changed (ETableModel *etm, int col, int row, ETableSubset *etss) -{ - const int n = etss->n_map; - const int * const map_table = etss->map_table; - int i; - - for (i = 0; i < n; i++){ - if (map_table [i] == row){ - e_table_model_cell_changed (E_TABLE_MODEL (etss), col, i); - return; - } - } -} - -ETableModel * -e_table_subset_construct (ETableSubset *etss, ETableModel *source, int nvals) -{ - unsigned int *buffer; - int i; - - buffer = (unsigned int *) g_malloc (sizeof (unsigned int) * nvals); - if (buffer == NULL) - return NULL; - etss->map_table = buffer; - etss->n_map = nvals; - etss->source = source; - gtk_object_ref (GTK_OBJECT (source)); - - /* Init */ - for (i = 0; i < nvals; i++) - etss->map_table [i] = i; - - etss->table_model_pre_change_id = gtk_signal_connect (GTK_OBJECT (source), "model_pre_change", - GTK_SIGNAL_FUNC (etss_proxy_model_pre_change), etss); - etss->table_model_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_changed", - GTK_SIGNAL_FUNC (etss_proxy_model_changed), etss); - etss->table_model_row_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_row_changed", - GTK_SIGNAL_FUNC (etss_proxy_model_row_changed), etss); - etss->table_model_cell_changed_id = gtk_signal_connect (GTK_OBJECT (source), "model_cell_changed", - GTK_SIGNAL_FUNC (etss_proxy_model_cell_changed), etss); - - return E_TABLE_MODEL (etss); -} - -ETableModel * -e_table_subset_new (ETableModel *source, const int nvals) -{ - ETableSubset *etss = gtk_type_new (E_TABLE_SUBSET_TYPE); - - if (e_table_subset_construct (etss, source, nvals) == NULL){ - gtk_object_destroy (GTK_OBJECT (etss)); - return NULL; - } - - return (ETableModel *) etss; -} - -ETableModel * -e_table_subset_get_toplevel (ETableSubset *table) -{ - g_return_val_if_fail (table != NULL, NULL); - g_return_val_if_fail (E_IS_TABLE_SUBSET (table), NULL); - - if (E_IS_TABLE_SUBSET (table->source)) - return e_table_subset_get_toplevel (E_TABLE_SUBSET (table->source)); - else - return table->source; -} diff --git a/widgets/table/e-table-subset.h b/widgets/table/e-table-subset.h deleted file mode 100644 index 9e10de7a4b..0000000000 --- a/widgets/table/e-table-subset.h +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_SUBSET_H_ -#define _E_TABLE_SUBSET_H_ - -#include <gtk/gtkobject.h> -#include "e-table-model.h" - -#define E_TABLE_SUBSET_TYPE (e_table_subset_get_type ()) -#define E_TABLE_SUBSET(o) (GTK_CHECK_CAST ((o), E_TABLE_SUBSET_TYPE, ETableSubset)) -#define E_TABLE_SUBSET_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_SUBSET_TYPE, ETableSubsetClass)) -#define E_IS_TABLE_SUBSET(o) (GTK_CHECK_TYPE ((o), E_TABLE_SUBSET_TYPE)) -#define E_IS_TABLE_SUBSET_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_SUBSET_TYPE)) - -typedef struct { - ETableModel base; - - ETableModel *source; - int n_map; - int *map_table; - - int table_model_pre_change_id; - int table_model_changed_id; - int table_model_row_changed_id; - int table_model_cell_changed_id; -} ETableSubset; - -typedef struct { - ETableModelClass parent_class; -} ETableSubsetClass; - -GtkType e_table_subset_get_type (void); -ETableModel *e_table_subset_new (ETableModel *etm, int n_vals); -ETableModel *e_table_subset_construct (ETableSubset *ets, ETableModel *source, int nvals); - -ETableModel *e_table_subset_get_toplevel (ETableSubset *table_model); - -#endif /* _E_TABLE_SUBSET_H_ */ - diff --git a/widgets/table/e-table-text-model.c b/widgets/table/e-table-text-model.c deleted file mode 100644 index 5b6fa8b707..0000000000 --- a/widgets/table/e-table-text-model.c +++ /dev/null @@ -1,220 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ETableTextModel - Text item model for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey <clahey@umich.edu> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> */ - -#include <config.h> -#include <ctype.h> -#include "e-table-text-model.h" - -static void e_table_text_model_class_init (ETableTextModelClass *class); -static void e_table_text_model_init (ETableTextModel *model); -static void e_table_text_model_destroy (GtkObject *object); - -static gchar *e_table_text_model_get_text (ETextModel *model); -static void e_table_text_model_set_text (ETextModel *model, gchar *text); -static void e_table_text_model_insert (ETextModel *model, gint postion, gchar *text); -static void e_table_text_model_insert_length (ETextModel *model, gint postion, gchar *text, gint length); -static void e_table_text_model_delete (ETextModel *model, gint postion, gint length); - -static GtkObject *parent_class; - - - -/** - * e_table_text_model_get_type: - * @void: - * - * Registers the &ETableTextModel class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &ETableTextModel class. - **/ -GtkType -e_table_text_model_get_type (void) -{ - static GtkType model_type = 0; - - if (!model_type) { - GtkTypeInfo model_info = { - "ETableTextModel", - sizeof (ETableTextModel), - sizeof (ETableTextModelClass), - (GtkClassInitFunc) e_table_text_model_class_init, - (GtkObjectInitFunc) e_table_text_model_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - model_type = gtk_type_unique (e_text_model_get_type (), &model_info); - } - - return model_type; -} - -/* Class initialization function for the text item */ -static void -e_table_text_model_class_init (ETableTextModelClass *klass) -{ - GtkObjectClass *object_class; - ETextModelClass *model_class; - - object_class = (GtkObjectClass *) klass; - model_class = (ETextModelClass *) klass; - - parent_class = gtk_type_class (e_text_model_get_type ()); - - model_class->get_text = e_table_text_model_get_text; - model_class->set_text = e_table_text_model_set_text; - model_class->insert = e_table_text_model_insert; - model_class->insert_length = e_table_text_model_insert_length; - model_class->delete = e_table_text_model_delete; - - object_class->destroy = e_table_text_model_destroy; -} - -/* Object initialization function for the text item */ -static void -e_table_text_model_init (ETableTextModel *model) -{ - model->model = NULL; - model->row = 0; - model->model_col = 0; - model->cell_changed_signal_id = 0; - model->row_changed_signal_id = 0; -} - -/* Destroy handler for the text item */ -static void -e_table_text_model_destroy (GtkObject *object) -{ - ETableTextModel *model; - - g_return_if_fail (object != NULL); - g_return_if_fail (E_IS_TABLE_TEXT_MODEL (object)); - - model = E_TABLE_TEXT_MODEL (object); - - if (model->model) - g_assert (GTK_IS_OBJECT (model->model)); - - if (model->cell_changed_signal_id) - gtk_signal_disconnect (GTK_OBJECT(model->model), - model->cell_changed_signal_id); - - if (model->row_changed_signal_id) - gtk_signal_disconnect (GTK_OBJECT(model->model), - model->row_changed_signal_id); - - if (model->model) - gtk_object_unref (GTK_OBJECT(model->model)); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} -static gchar * -e_table_text_model_get_text (ETextModel *text_model) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model) - return (gchar *)e_table_model_value_at (model->model, model->model_col, model->row); - else - return ""; -} - -static void -e_table_text_model_set_text (ETextModel *text_model, gchar *text) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model) - e_table_model_set_value_at (model->model, model->model_col, model->row, (void *) text); -} - -static void -e_table_text_model_insert (ETextModel *text_model, gint position, gchar *text) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model){ - gchar *temp = (gchar *)e_table_model_value_at (model->model, model->model_col, model->row); - temp = g_strdup_printf ("%.*s%s%s", position, temp, text, temp + position); - e_table_model_set_value_at (model->model, model->model_col, model->row, temp); - g_free (temp); - } -} - -static void -e_table_text_model_insert_length (ETextModel *text_model, gint position, gchar *text, gint length) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model){ - gchar *temp = (gchar *)e_table_model_value_at (model->model, model->model_col, model->row); - temp = g_strdup_printf ("%.*s%.*s%s", position, temp, length, text, temp + position); - e_table_model_set_value_at (model->model, model->model_col, model->row, temp); - g_free (temp); - } -} - -static void -e_table_text_model_delete (ETextModel *text_model, gint position, gint length) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model){ - gchar *temp = (gchar *)e_table_model_value_at (model->model, model->model_col, model->row); - temp = g_strdup_printf ("%.*s%s", position, temp, temp + position + length); - e_table_model_set_value_at (model->model, model->model_col, model->row, temp); - g_free (temp); - } -} - -static void -cell_changed (ETableModel *table_model, int model_col, int row, ETableTextModel *model) -{ - if (model->model_col == model_col && - model->row == row) - e_text_model_changed (E_TEXT_MODEL(model)); -} - -static void -row_changed (ETableModel *table_model, int row, ETableTextModel *model) -{ - if (model->row == row) - e_text_model_changed (E_TEXT_MODEL(model)); -} - -ETableTextModel * -e_table_text_model_new (ETableModel *table_model, int row, int model_col) -{ - ETableTextModel *model = gtk_type_new (e_table_text_model_get_type ()); - model->model = table_model; - if (model->model){ - gtk_object_ref (GTK_OBJECT(model->model)); - model->cell_changed_signal_id = - gtk_signal_connect (GTK_OBJECT(model->model), - "model_cell_changed", - GTK_SIGNAL_FUNC(cell_changed), - model); - model->row_changed_signal_id = - gtk_signal_connect (GTK_OBJECT(model->model), - "model_row_changed", - GTK_SIGNAL_FUNC(row_changed), - model); - } - model->row = row; - model->model_col = model_col; - return model; -} - diff --git a/widgets/table/e-table-text-model.h b/widgets/table/e-table-text-model.h deleted file mode 100644 index dcc9afde7c..0000000000 --- a/widgets/table/e-table-text-model.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ETableTextModel - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey <clahey@umich.edu> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> */ - -#ifndef E_TABLE_TEXT_MODEL_H -#define E_TABLE_TEXT_MODEL_H - -#include <gnome.h> -#include "e-text-model.h" -#include "e-table-model.h" - - -BEGIN_GNOME_DECLS - -#define E_TYPE_TABLE_TEXT_MODEL (e_table_text_model_get_type ()) -#define E_TABLE_TEXT_MODEL(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TABLE_TEXT_MODEL, ETableTextModel)) -#define E_TABLE_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TABLE_TEXT_MODEL, ETableTextModelClass)) -#define E_IS_TABLE_TEXT_MODEL(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TABLE_TEXT_MODEL)) -#define E_IS_TABLE_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TABLE_TEXT_MODEL)) - -typedef struct _ETableTextModel ETableTextModel; -typedef struct _ETableTextModelClass ETableTextModelClass; - -struct _ETableTextModel { - ETextModel parent; - - ETableModel *model; - int row; - int model_col; - - int cell_changed_signal_id; - int row_changed_signal_id; -}; - -struct _ETableTextModelClass { - ETextModelClass parent_class; - -}; - - -/* Standard Gtk function */ -GtkType e_table_text_model_get_type (void); -ETableTextModel *e_table_text_model_new (ETableModel *table_model, int row, int model_col); - -END_GNOME_DECLS - -#endif diff --git a/widgets/table/e-table-tree.h b/widgets/table/e-table-tree.h deleted file mode 100644 index e7e125a6af..0000000000 --- a/widgets/table/e-table-tree.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _E_TABLE_TREE_H_ -#define _E_TABLE_TREE_H_ - -typedef struct { - char *title; - - union { - ETableModel *table; - GList *children; - } u; - - guint expanded :1; - guint is_leaf :1; -} ETableGroup; - -ETableGroup *e_table_group_new (const char *title, ETableModel *table); -ETableGroup *e_table_group_new_leaf (const char *title); - -#endif /* _E_TABLE_TREE_H_ */ diff --git a/widgets/table/e-table.c b/widgets/table/e-table.c deleted file mode 100644 index bd6d7bc60c..0000000000 --- a/widgets/table/e-table.c +++ /dev/null @@ -1,1669 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table.c: A graphical view of a Table. - * - * Author: - * Miguel de Icaza (miguel@helixcode.com) - * Chris Lahey (clahey@helixcode.com) - * - * Copyright 1999, Helix Code, Inc - */ -#include <config.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#ifdef HAVE_ALLOCA_H -#include <alloca.h> -#endif -#include <stdio.h> -#include <libgnomeui/gnome-canvas.h> -#include <gtk/gtksignal.h> -#include <gnome-xml/parser.h> -#include <gnome-xml/xmlmemory.h> - -#include "e-util/e-util.h" -#include "e-util/e-xml-utils.h" -#include "e-util/e-canvas.h" -#include "e-util/e-canvas-vbox.h" -#include "e-table.h" -#include "e-table-header-item.h" -#include "e-table-subset.h" -#include "e-table-item.h" -#include "e-table-group.h" -#include "e-table-group-leaf.h" -#include "e-table-click-to-add.h" - -#define COLUMN_HEADER_HEIGHT 16 - -#define PARENT_TYPE gtk_table_get_type () - -static GtkObjectClass *e_table_parent_class; - -enum { - CURSOR_CHANGE, - DOUBLE_CLICK, - RIGHT_CLICK, - KEY_PRESS, - - TABLE_DRAG_BEGIN, - TABLE_DRAG_END, - TABLE_DRAG_DATA_GET, - TABLE_DRAG_DATA_DELETE, - - TABLE_DRAG_LEAVE, - TABLE_DRAG_MOTION, - TABLE_DRAG_DROP, - TABLE_DRAG_DATA_RECEIVED, - - LAST_SIGNAL -}; - -enum { - ARG_0, - ARG_TABLE_DRAW_GRID, - ARG_TABLE_DRAW_FOCUS, - ARG_CURSOR_MODE, - ARG_LENGTH_THRESHOLD, - ARG_CLICK_TO_ADD_MESSAGE, -}; - -static gint et_signals [LAST_SIGNAL] = { 0, }; - -static void e_table_fill_table (ETable *e_table, ETableModel *model); -static gboolean changed_idle (gpointer data); - -static void et_drag_begin (GtkWidget *widget, - GdkDragContext *context, - ETable *et); -static void et_drag_end (GtkWidget *widget, - GdkDragContext *context, - ETable *et); -static void et_drag_data_get(GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - ETable *et); -static void et_drag_data_delete(GtkWidget *widget, - GdkDragContext *context, - ETable *et); - -static void et_drag_leave(GtkWidget *widget, - GdkDragContext *context, - guint time, - ETable *et); -static gboolean et_drag_motion(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETable *et); -static gboolean et_drag_drop(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETable *et); -static void et_drag_data_received(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time, - ETable *et); -static gint e_table_drag_source_event_cb (GtkWidget *widget, - GdkEvent *event, - ETable *table); - -static void -et_destroy (GtkObject *object) -{ - ETable *et = E_TABLE (object); - - - gtk_signal_disconnect (GTK_OBJECT (et->model), - et->table_model_change_id); - gtk_signal_disconnect (GTK_OBJECT (et->model), - et->table_row_change_id); - gtk_signal_disconnect (GTK_OBJECT (et->model), - et->table_cell_change_id); - gtk_signal_disconnect (GTK_OBJECT (et->model), - et->table_row_inserted_id); - gtk_signal_disconnect (GTK_OBJECT (et->model), - et->table_row_deleted_id); - if (et->group_info_change_id) - gtk_signal_disconnect (GTK_OBJECT (et->sort_info), - et->group_info_change_id); - - if (et->reflow_idle_id) - g_source_remove(et->reflow_idle_id); - et->reflow_idle_id = 0; - - gtk_object_unref (GTK_OBJECT (et->model)); - gtk_object_unref (GTK_OBJECT (et->full_header)); - gtk_object_unref (GTK_OBJECT (et->header)); - gtk_object_unref (GTK_OBJECT (et->sort_info)); - gtk_object_unref (GTK_OBJECT (et->sorter)); - gtk_widget_destroy (GTK_WIDGET (et->header_canvas)); - gtk_widget_destroy (GTK_WIDGET (et->table_canvas)); - - if (et->rebuild_idle_id) { - g_source_remove (et->rebuild_idle_id); - et->rebuild_idle_id = 0; - } - - g_free(et->click_to_add_message); - - (*e_table_parent_class->destroy)(object); -} - -static void -e_table_init (GtkObject *object) -{ - ETable *e_table = E_TABLE (object); - GtkTable *gtk_table = GTK_TABLE (object); - - gtk_table->homogeneous = FALSE; - - e_table->sort_info = NULL; - e_table->group_info_change_id = 0; - e_table->reflow_idle_id = 0; - - e_table->draw_grid = 1; - e_table->draw_focus = 1; - e_table->cursor_mode = E_TABLE_CURSOR_SIMPLE; - e_table->length_threshold = 200; - - e_table->need_rebuild = 0; - e_table->rebuild_idle_id = 0; - - e_table->click_to_add_message = NULL; - - e_table->drag_get_data_row = -1; - e_table->drag_get_data_col = -1; - e_table->drop_row = -1; - e_table->drop_col = -1; - e_table->site = NULL; - e_table->drag_source_button_press_event_id = 0; - e_table->drag_source_motion_notify_event_id = 0; - - e_table->sorter = NULL; - e_table->selection = e_table_selection_model_new(); - e_table->cursor_loc = E_TABLE_CURSOR_LOC_NONE; -} - -static void -header_canvas_size_allocate (GtkWidget *widget, GtkAllocation *alloc, ETable *e_table) -{ - gnome_canvas_set_scroll_region ( - GNOME_CANVAS (e_table->header_canvas), - 0, 0, alloc->width - 1, COLUMN_HEADER_HEIGHT - 1); -} - -static void -sort_info_changed (ETableSortInfo *info, ETable *et) -{ - et->need_rebuild = TRUE; - if (!et->rebuild_idle_id) - et->rebuild_idle_id = g_idle_add_full (20, changed_idle, et, NULL); -} - -static void -e_table_setup_header (ETable *e_table) -{ - e_table->header_canvas = GNOME_CANVAS (e_canvas_new ()); - - gtk_widget_show (GTK_WIDGET (e_table->header_canvas)); - - 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", "(unset)", - NULL); - - gtk_signal_connect ( - GTK_OBJECT (e_table->header_canvas), "size_allocate", - GTK_SIGNAL_FUNC (header_canvas_size_allocate), e_table); - - gtk_widget_set_usize (GTK_WIDGET (e_table->header_canvas), -1, COLUMN_HEADER_HEIGHT); -} - -static gboolean -table_canvas_reflow_idle (ETable *e_table) -{ - gdouble height, width; - GtkAllocation *alloc = &(GTK_WIDGET (e_table->table_canvas)->allocation); - - gtk_object_get (GTK_OBJECT (e_table->canvas_vbox), - "height", &height, - "width", &width, - NULL); - height = MAX ((int)height, alloc->height); - width = MAX((int)width, alloc->width); - /* I have no idea why this needs to be -1, but it works. */ - gnome_canvas_set_scroll_region ( - GNOME_CANVAS (e_table->table_canvas), - 0, 0, width - 1, height - 1); - e_table->reflow_idle_id = 0; - return FALSE; -} - -static void -table_canvas_size_allocate (GtkWidget *widget, GtkAllocation *alloc, - ETable *e_table) -{ - gdouble width; - width = alloc->width; - - gtk_object_set (GTK_OBJECT (e_table->canvas_vbox), - "width", width, - NULL); - gtk_object_set (GTK_OBJECT (e_table->header), - "width", width, - NULL); - if (e_table->reflow_idle_id) - g_source_remove(e_table->reflow_idle_id); - table_canvas_reflow_idle(e_table); -} - -static void -table_canvas_reflow (GnomeCanvas *canvas, ETable *e_table) -{ - if (!e_table->reflow_idle_id) - e_table->reflow_idle_id = g_idle_add_full (400, (GSourceFunc) table_canvas_reflow_idle, e_table, NULL); -} - -static void -click_to_add_cursor_change (ETableClickToAdd *etcta, int row, int col, ETable *et) -{ - if (et->cursor_loc == E_TABLE_CURSOR_LOC_TABLE) { - e_table_selection_model_clear(et->selection); - } - et->cursor_loc = E_TABLE_CURSOR_LOC_ETCTA; -} - -static void -group_cursor_change (ETableGroup *etg, int row, ETable *et) -{ - if (et->cursor_loc == E_TABLE_CURSOR_LOC_ETCTA && et->click_to_add) { - e_table_click_to_add_commit(E_TABLE_CLICK_TO_ADD(et->click_to_add)); - } - et->cursor_loc = E_TABLE_CURSOR_LOC_TABLE; - gtk_signal_emit (GTK_OBJECT (et), - et_signals [CURSOR_CHANGE], - row); -} - -static void -group_double_click (ETableGroup *etg, int row, ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [DOUBLE_CLICK], - row); -} - -static gint -group_right_click (ETableGroup *etg, int row, int col, GdkEvent *event, ETable *et) -{ - int return_val; - gtk_signal_emit (GTK_OBJECT (et), - et_signals [RIGHT_CLICK], - row, col, event, &return_val); - return return_val; -} - -static gint -group_key_press (ETableGroup *etg, int row, int col, GdkEvent *event, ETable *et) -{ - int return_val; - gtk_signal_emit (GTK_OBJECT (et), - et_signals [KEY_PRESS], - row, col, event, &return_val); - return return_val; -} - -static gboolean -changed_idle (gpointer data) -{ - ETable *et = E_TABLE (data); - - if (et->need_rebuild) { - gtk_object_destroy (GTK_OBJECT (et->group)); - et->group = e_table_group_new (GNOME_CANVAS_GROUP (et->canvas_vbox), - et->full_header, - et->header, - et->model, - et->sort_info, - 0); - e_canvas_vbox_add_item(E_CANVAS_VBOX(et->canvas_vbox), GNOME_CANVAS_ITEM(et->group)); - gnome_canvas_item_set(GNOME_CANVAS_ITEM(et->group), - "drawgrid", et->draw_grid, - "drawfocus", et->draw_focus, - "cursor_mode", et->cursor_mode, - "length_threshold", et->length_threshold, - "table_selection_model", et->selection, - NULL); - gtk_signal_connect (GTK_OBJECT (et->group), "cursor_change", - GTK_SIGNAL_FUNC (group_cursor_change), et); - gtk_signal_connect (GTK_OBJECT (et->group), "double_click", - GTK_SIGNAL_FUNC (group_double_click), et); - gtk_signal_connect (GTK_OBJECT (et->group), "right_click", - GTK_SIGNAL_FUNC (group_right_click), et); - gtk_signal_connect (GTK_OBJECT (et->group), "key_press", - GTK_SIGNAL_FUNC (group_key_press), et); - e_table_fill_table (et, et->model); - - gtk_object_set (GTK_OBJECT (et->canvas_vbox), - "width", (double) GTK_WIDGET (et->table_canvas)->allocation.width, - NULL); - } - - et->need_rebuild = 0; - et->rebuild_idle_id = 0; - - return FALSE; -} - -static void -et_table_model_changed (ETableModel *model, ETable *et) -{ - et->need_rebuild = TRUE; - if (!et->rebuild_idle_id) - et->rebuild_idle_id = g_idle_add_full (20, changed_idle, et, NULL); -} - -static void -et_table_row_changed (ETableModel *table_model, int row, ETable *et) -{ - if (!et->need_rebuild) { - if (e_table_group_remove (et->group, row)) - e_table_group_add (et->group, row); - } -} - -static void -et_table_cell_changed (ETableModel *table_model, int view_col, int row, ETable *et) -{ - et_table_row_changed (table_model, row, et); -} - -static void -et_table_row_inserted (ETableModel *table_model, int row, ETable *et) -{ - int row_count = e_table_model_row_count(table_model); - if (!et->need_rebuild) { - if (row != row_count - 1) - e_table_group_increment(et->group, row, 1); - e_table_group_add (et->group, row); - } -} - -static void -et_table_row_deleted (ETableModel *table_model, int row, ETable *et) -{ - int row_count = e_table_model_row_count(table_model); - if (!et->need_rebuild) { - e_table_group_remove (et->group, row); - if (row != row_count - 1) - e_table_group_decrement(et->group, row, 1); - } -} - -static void -e_table_setup_table (ETable *e_table, ETableHeader *full_header, ETableHeader *header, - ETableModel *model) -{ - e_table->table_canvas = GNOME_CANVAS (e_canvas_new ()); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "size_allocate", - GTK_SIGNAL_FUNC (table_canvas_size_allocate), e_table); - - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "drag_begin", - GTK_SIGNAL_FUNC (et_drag_begin), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "drag_end", - GTK_SIGNAL_FUNC (et_drag_end), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "drag_data_get", - GTK_SIGNAL_FUNC (et_drag_data_get), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "drag_data_delete", - GTK_SIGNAL_FUNC (et_drag_data_delete), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "drag_motion", - GTK_SIGNAL_FUNC (et_drag_motion), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "drag_leave", - GTK_SIGNAL_FUNC (et_drag_leave), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "drag_drop", - GTK_SIGNAL_FUNC (et_drag_drop), e_table); - gtk_signal_connect ( - GTK_OBJECT (e_table->table_canvas), "drag_data_received", - GTK_SIGNAL_FUNC (et_drag_data_received), e_table); - - gtk_signal_connect (GTK_OBJECT(e_table->table_canvas), "reflow", - GTK_SIGNAL_FUNC (table_canvas_reflow), e_table); - - gtk_widget_show (GTK_WIDGET (e_table->table_canvas)); - - - e_table->canvas_vbox = gnome_canvas_item_new(gnome_canvas_root(e_table->table_canvas), - e_canvas_vbox_get_type(), - "spacing", 10.0, - NULL); - - if (e_table->use_click_to_add) { - e_table->click_to_add = gnome_canvas_item_new (GNOME_CANVAS_GROUP(e_table->canvas_vbox), - e_table_click_to_add_get_type (), - "header", e_table->header, - "model", e_table->model, - "message", e_table->click_to_add_message, - NULL); - - e_canvas_vbox_add_item(E_CANVAS_VBOX(e_table->canvas_vbox), e_table->click_to_add); - gtk_signal_connect(GTK_OBJECT (e_table->click_to_add), "cursor_change", - GTK_SIGNAL_FUNC(click_to_add_cursor_change), e_table); - } - - e_table->group = e_table_group_new ( - GNOME_CANVAS_GROUP (e_table->canvas_vbox), - full_header, header, - model, e_table->sort_info, 0); - e_canvas_vbox_add_item(E_CANVAS_VBOX(e_table->canvas_vbox), GNOME_CANVAS_ITEM(e_table->group)); - - gnome_canvas_item_set(GNOME_CANVAS_ITEM(e_table->group), - "drawgrid", e_table->draw_grid, - "drawfocus", e_table->draw_focus, - "cursor_mode", e_table->cursor_mode, - "length_threshold", e_table->length_threshold, - "table_selection_model", e_table->selection, - NULL); - - gtk_signal_connect (GTK_OBJECT (e_table->group), "cursor_change", - GTK_SIGNAL_FUNC(group_cursor_change), e_table); - gtk_signal_connect (GTK_OBJECT (e_table->group), "double_click", - GTK_SIGNAL_FUNC(group_double_click), e_table); - gtk_signal_connect (GTK_OBJECT (e_table->group), "right_click", - GTK_SIGNAL_FUNC(group_right_click), e_table); - gtk_signal_connect (GTK_OBJECT (e_table->group), "key_press", - GTK_SIGNAL_FUNC(group_key_press), e_table); - - e_table->table_model_change_id = gtk_signal_connect ( - GTK_OBJECT (model), "model_changed", - GTK_SIGNAL_FUNC (et_table_model_changed), e_table); - - e_table->table_row_change_id = gtk_signal_connect ( - GTK_OBJECT (model), "model_row_changed", - GTK_SIGNAL_FUNC (et_table_row_changed), e_table); - - e_table->table_cell_change_id = gtk_signal_connect ( - GTK_OBJECT (model), "model_cell_changed", - GTK_SIGNAL_FUNC (et_table_cell_changed), e_table); - - e_table->table_row_inserted_id = gtk_signal_connect ( - GTK_OBJECT (model), "model_row_inserted", - GTK_SIGNAL_FUNC (et_table_row_inserted), e_table); - - e_table->table_row_deleted_id = gtk_signal_connect ( - GTK_OBJECT (model), "model_row_deleted", - GTK_SIGNAL_FUNC (et_table_row_deleted), e_table); - -} - -static void -e_table_fill_table (ETable *e_table, ETableModel *model) -{ - e_table_group_add_all (e_table->group); -} - -static ETableHeader * -et_xml_to_header (ETable *e_table, ETableHeader *full_header, xmlNode *xmlColumns) -{ - ETableHeader *nh; - xmlNode *column; - const int max_cols = e_table_header_count (full_header); - - g_return_val_if_fail (e_table, NULL); - g_return_val_if_fail (full_header, NULL); - g_return_val_if_fail (xmlColumns, NULL); - - nh = e_table_header_new (); - - for (column = xmlColumns->childs; column; column = column->next) { - gchar *content; - int col; - - content = xmlNodeListGetString (column->doc, column->childs, 1); - col = atoi (content); - xmlFree (content); - - if (col >= max_cols) - continue; - - e_table_header_add_column (nh, e_table_header_get_column (full_header, col), -1); - } - - return nh; -} - -static void -et_grouping_xml_to_sort_info (ETable *table, xmlNode *grouping) -{ - int i; - - g_return_if_fail (table!=NULL); - g_return_if_fail (grouping!=NULL); - - table->sort_info = e_table_sort_info_new (); - - gtk_object_ref (GTK_OBJECT (table->sort_info)); - gtk_object_sink (GTK_OBJECT (table->sort_info)); - - i = 0; - for (grouping = grouping->childs; grouping && !strcmp (grouping->name, "group"); grouping = grouping->childs) { - ETableSortColumn column; - column.column = e_xml_get_integer_prop_by_name (grouping, "column"); - column.ascending = e_xml_get_integer_prop_by_name (grouping, "ascending"); - e_table_sort_info_grouping_set_nth(table->sort_info, i++, column); - } - i = 0; - for (; grouping && !strcmp (grouping->name, "leaf"); grouping = grouping->childs) { - ETableSortColumn column; - column.column = e_xml_get_integer_prop_by_name (grouping, "column"); - column.ascending = e_xml_get_integer_prop_by_name (grouping, "ascending"); - e_table_sort_info_sorting_set_nth(table->sort_info, i++, column); - } - - table->group_info_change_id = - gtk_signal_connect (GTK_OBJECT (table->sort_info), "group_info_changed", - GTK_SIGNAL_FUNC (sort_info_changed), table); -} - -static ETable * -et_real_construct (ETable *e_table, ETableHeader *full_header, ETableModel *etm, - xmlDoc *xmlSpec) -{ - xmlNode *xmlRoot; - xmlNode *xmlColumns; - xmlNode *xmlGrouping; - gboolean no_header; - int row = 0; - - xmlRoot = xmlDocGetRootElement (xmlSpec); - xmlColumns = e_xml_get_child_by_name (xmlRoot, "columns-shown"); - xmlGrouping = e_xml_get_child_by_name (xmlRoot, "grouping"); - - if ((xmlColumns == NULL) || (xmlGrouping == NULL)) - return NULL; - - no_header = e_xml_get_integer_prop_by_name(xmlRoot, "no-header"); - e_table->use_click_to_add = e_xml_get_integer_prop_by_name(xmlRoot, "click-to-add"); - - - e_table->full_header = full_header; - gtk_object_ref (GTK_OBJECT (full_header)); - - e_table->model = etm; - gtk_object_ref (GTK_OBJECT (etm)); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - e_table->header = et_xml_to_header (e_table, full_header, xmlColumns); - et_grouping_xml_to_sort_info (e_table, xmlGrouping); - - gtk_object_set(GTK_OBJECT(e_table->header), - "sort_info", e_table->sort_info, - NULL); - - e_table->sorter = e_table_sorter_new(etm, e_table->full_header, e_table->sort_info); - - gtk_object_set (GTK_OBJECT (e_table->selection), - "model", etm, - "sorter", e_table->sorter, - NULL); - - if (!no_header) { - e_table_setup_header (e_table); - } - e_table_setup_table (e_table, full_header, e_table->header, etm); - e_table_fill_table (e_table, etm); - - gtk_layout_get_vadjustment (GTK_LAYOUT (e_table->table_canvas))->step_increment = 20; - gtk_adjustment_changed(gtk_layout_get_vadjustment (GTK_LAYOUT (e_table->table_canvas))); - - if (!no_header) { - /* - * The header - */ - gtk_table_attach (GTK_TABLE (e_table), GTK_WIDGET (e_table->header_canvas), - 0, 1, 0 + row, 1 + row, - GTK_FILL | GTK_EXPAND, - GTK_FILL, 0, 0); - row ++; - } - gtk_table_attach (GTK_TABLE (e_table), GTK_WIDGET (e_table->table_canvas), - 0, 1, 0 + row, 1 + row, - GTK_FILL | GTK_EXPAND, - GTK_FILL | GTK_EXPAND, - 0, 0); - - gtk_widget_pop_colormap (); - gtk_widget_pop_visual (); - - return e_table; -} - -ETable * -e_table_construct (ETable *e_table, ETableHeader *full_header, - ETableModel *etm, const char *spec) -{ - xmlDoc *xmlSpec; - char *copy; - copy = g_strdup (spec); - - xmlSpec = xmlParseMemory (copy, strlen(copy)); - e_table = et_real_construct (e_table, full_header, etm, xmlSpec); - xmlFreeDoc (xmlSpec); - g_free (copy); - - return e_table; -} - -ETable * -e_table_construct_from_spec_file (ETable *e_table, ETableHeader *full_header, ETableModel *etm, - const char *filename) -{ - xmlDoc *xmlSpec; - - xmlSpec = xmlParseFile (filename); - e_table = et_real_construct (e_table, full_header, etm, xmlSpec); - xmlFreeDoc (xmlSpec); - - return e_table; -} - -GtkWidget * -e_table_new (ETableHeader *full_header, ETableModel *etm, const char *spec) -{ - ETable *e_table; - - e_table = gtk_type_new (e_table_get_type ()); - - e_table = e_table_construct (e_table, full_header, etm, spec); - - return GTK_WIDGET (e_table); -} - -GtkWidget * -e_table_new_from_spec_file (ETableHeader *full_header, ETableModel *etm, const char *filename) -{ - ETable *e_table; - - e_table = gtk_type_new (e_table_get_type ()); - - e_table = e_table_construct_from_spec_file (e_table, full_header, etm, filename); - - return (GtkWidget *) e_table; -} - -static xmlNode * -et_build_column_spec (ETable *e_table) -{ - xmlNode *columns_shown; - gint i; - gint col_count; - - columns_shown = xmlNewNode (NULL, "columns-shown"); - - col_count = e_table_header_count (e_table->header); - for (i = 0; i < col_count; i++){ - gchar *text = g_strdup_printf ("%d", e_table_header_index(e_table->header, i)); - xmlNewChild (columns_shown, NULL, "column", text); - g_free (text); - } - - return columns_shown; -} - -static xmlNode * -et_build_grouping_spec (ETable *e_table) -{ - xmlNode *node; - xmlNode *grouping; - int i; - const int sort_count = e_table_sort_info_sorting_get_count (e_table->sort_info); - const int group_count = e_table_sort_info_grouping_get_count (e_table->sort_info); - - grouping = xmlNewNode (NULL, "grouping"); - node = grouping; - - for (i = 0; i < group_count; i++) { - ETableSortColumn column = e_table_sort_info_grouping_get_nth(e_table->sort_info, i); - xmlNode *new_node = xmlNewChild(node, NULL, "group", NULL); - - e_xml_set_integer_prop_by_name (new_node, "column", column.column); - e_xml_set_integer_prop_by_name (new_node, "ascending", column.ascending); - node = new_node; - } - - for (i = 0; i < sort_count; i++) { - ETableSortColumn column = e_table_sort_info_sorting_get_nth(e_table->sort_info, i); - xmlNode *new_node = xmlNewChild(node, NULL, "leaf", NULL); - - e_xml_set_integer_prop_by_name (new_node, "column", column.column); - e_xml_set_integer_prop_by_name (new_node, "ascending", column.ascending); - node = new_node; - } - - return grouping; -} - -static xmlDoc * -et_build_tree (ETable *e_table) -{ - xmlDoc *doc; - xmlNode *root; - - doc = xmlNewDoc ("1.0"); - if (doc == NULL) - return NULL; - - root = xmlNewDocNode (doc, NULL, "ETableSpecification", NULL); - xmlDocSetRootElement (doc, root); - xmlAddChild (root, et_build_column_spec (e_table)); - xmlAddChild (root, et_build_grouping_spec (e_table)); - - return doc; -} - -gchar * -e_table_get_specification (ETable *e_table) -{ - xmlDoc *doc; - xmlChar *buffer; - gint size; - - doc = et_build_tree (e_table); - xmlDocDumpMemory (doc, &buffer, &size); - xmlFreeDoc (doc); - - return buffer; -} - -void -e_table_save_specification (ETable *e_table, gchar *filename) -{ - xmlDoc *doc = et_build_tree (e_table); - - xmlSaveFile (filename, doc); - xmlFreeDoc (doc); -} - -void -e_table_set_cursor_row (ETable *e_table, int row) -{ - row = e_table_sorter_model_to_sorted(e_table->sorter, row); - if (row != -1) - e_table_group_set_cursor_row(e_table->group, row); -} - -int -e_table_get_cursor_row (ETable *e_table) -{ - int row = e_table_group_get_cursor_row(e_table->group); - row = e_table_sorter_sorted_to_model(e_table->sorter, row); - return row; -} - -void -e_table_selected_row_foreach (ETable *e_table, - ETableForeachFunc callback, - gpointer closure) -{ - e_table_selection_model_foreach(e_table->selection, - callback, - closure); -} - - -EPrintable * -e_table_get_printable (ETable *e_table) -{ - return e_table_group_get_printable(e_table->group); -} - -static void -et_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETable *etable = E_TABLE (o); - - switch (arg_id){ - case ARG_TABLE_DRAW_GRID: - GTK_VALUE_BOOL (*arg) = etable->draw_grid; - break; - - case ARG_TABLE_DRAW_FOCUS: - GTK_VALUE_BOOL (*arg) = etable->draw_focus; - break; - - case ARG_CLICK_TO_ADD_MESSAGE: - GTK_VALUE_STRING (*arg) = g_strdup (etable->click_to_add_message); - break; - } -} - -typedef struct { - char *arg; - gboolean setting; -} bool_closure; - -static void -et_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - ETable *etable = E_TABLE (o); - - switch (arg_id){ - case ARG_LENGTH_THRESHOLD: - etable->length_threshold = GTK_VALUE_INT (*arg); - if (etable->group) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etable->group), - "length_threshold", GTK_VALUE_INT (*arg), - NULL); - } - break; - - case ARG_TABLE_DRAW_GRID: - etable->draw_grid = GTK_VALUE_BOOL (*arg); - if (etable->group) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etable->group), - "drawgrid", GTK_VALUE_BOOL (*arg), - NULL); - } - break; - - case ARG_TABLE_DRAW_FOCUS: - etable->draw_focus = GTK_VALUE_BOOL (*arg); - if (etable->group) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etable->group), - "drawfocus", GTK_VALUE_BOOL (*arg), - NULL); - } - break; - - case ARG_CURSOR_MODE: - etable->cursor_mode = GTK_VALUE_INT (*arg); - if (etable->group) { - gnome_canvas_item_set (GNOME_CANVAS_ITEM(etable->group), - "cursor_mode", GTK_VALUE_INT (*arg), - NULL); - } - break; - case ARG_CLICK_TO_ADD_MESSAGE: - if (etable->click_to_add_message) - g_free(etable->click_to_add_message); - etable->click_to_add_message = g_strdup(GTK_VALUE_STRING (*arg)); - if (etable->click_to_add) - gnome_canvas_item_set(etable->click_to_add, - "message", etable->click_to_add_message, - NULL); - break; - } -} - -static void -set_scroll_adjustments (ETable *table, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment) -{ - if (vadjustment != NULL) { - vadjustment->step_increment = 20; - gtk_adjustment_changed(vadjustment); - } - - gtk_layout_set_hadjustment (GTK_LAYOUT(table->table_canvas), - hadjustment); - gtk_layout_set_vadjustment (GTK_LAYOUT(table->table_canvas), - vadjustment); - gtk_layout_set_hadjustment (GTK_LAYOUT(table->header_canvas), - hadjustment); -} - -gint -e_table_get_next_row (ETable *e_table, - gint model_row) -{ - if (e_table->sorter) { - int i; - i = e_table_sorter_model_to_sorted(e_table->sorter, model_row); - i++; - if (i < e_table_model_row_count(e_table->model)) { - return e_table_sorter_sorted_to_model(e_table->sorter, i); - } else - return -1; - } else - if (model_row < e_table_model_row_count(e_table->model) - 1) - return model_row + 1; - else - return -1; -} - -gint -e_table_get_prev_row (ETable *e_table, - gint model_row) -{ - if (e_table->sorter) { - int i; - i = e_table_sorter_model_to_sorted(e_table->sorter, model_row); - i--; - if (i >= 0) - return e_table_sorter_sorted_to_model(e_table->sorter, i); - else - return -1; - } else - return model_row - 1; -} - -gint -e_table_model_to_view_row (ETable *e_table, - gint model_row) -{ - if (e_table->sorter) - return e_table_sorter_model_to_sorted(e_table->sorter, model_row); - else - return model_row; -} - -gint -e_table_view_to_model_row (ETable *e_table, - gint view_row) -{ - if (e_table->sorter) - return e_table_sorter_sorted_to_model(e_table->sorter, view_row); - else - return view_row; -} - -struct _ETableDragSourceSite -{ - GdkModifierType start_button_mask; - GtkTargetList *target_list; /* Targets for drag data */ - GdkDragAction actions; /* Possible actions */ - GdkColormap *colormap; /* Colormap for drag icon */ - GdkPixmap *pixmap; /* Icon for drag data */ - GdkBitmap *mask; - - /* Stored button press information to detect drag beginning */ - gint state; - gint x, y; - gint row, col; -}; - -typedef enum -{ - GTK_DRAG_STATUS_DRAG, - GTK_DRAG_STATUS_WAIT, - GTK_DRAG_STATUS_DROP -} GtkDragStatus; - -typedef struct _GtkDragDestInfo GtkDragDestInfo; -typedef struct _GtkDragSourceInfo GtkDragSourceInfo; - -struct _GtkDragDestInfo -{ - GtkWidget *widget; /* Widget in which drag is in */ - GdkDragContext *context; /* Drag context */ - GtkDragSourceInfo *proxy_source; /* Set if this is a proxy drag */ - GtkSelectionData *proxy_data; /* Set while retrieving proxied data */ - gboolean dropped : 1; /* Set after we receive a drop */ - guint32 proxy_drop_time; /* Timestamp for proxied drop */ - gboolean proxy_drop_wait : 1; /* Set if we are waiting for a - * status reply before sending - * a proxied drop on. - */ - gint drop_x, drop_y; /* Position of drop */ -}; - -struct _GtkDragSourceInfo -{ - GtkWidget *widget; - GtkTargetList *target_list; /* Targets for drag data */ - GdkDragAction possible_actions; /* Actions allowed by source */ - GdkDragContext *context; /* drag context */ - GtkWidget *icon_window; /* Window for drag */ - GtkWidget *ipc_widget; /* GtkInvisible for grab, message passing */ - GdkCursor *cursor; /* Cursor for drag */ - gint hot_x, hot_y; /* Hot spot for drag */ - gint button; /* mouse button starting drag */ - - GtkDragStatus status; /* drag status */ - GdkEvent *last_event; /* motion event waiting for response */ - - gint start_x, start_y; /* Initial position */ - gint cur_x, cur_y; /* Current Position */ - - GList *selections; /* selections we've claimed */ - - GtkDragDestInfo *proxy_dest; /* Set if this is a proxy drag */ - - guint drop_timeout; /* Timeout for aborting drop */ - guint destroy_icon : 1; /* If true, destroy icon_window - */ -}; - -/* Drag & drop stuff. */ -/* Target */ -void e_table_drag_get_data (ETable *table, - int row, - int col, - GdkDragContext *context, - GdkAtom target, - guint32 time) -{ - table->drag_get_data_row = row; - table->drag_get_data_col = col; - gtk_drag_get_data(GTK_WIDGET(table), - context, - target, - time); - -} - -void e_table_drag_highlight (ETable *table, - int row, - int col) /* col == -1 to highlight entire row. */ -{ -} - -void e_table_drag_unhighlight (ETable *table) -{ -} - -void e_table_drag_dest_set (ETable *table, - GtkDestDefaults flags, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions) -{ - 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) -{ - 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) -{ - gtk_drag_dest_unset(widget); -} - -/* Source side */ - -void e_table_drag_source_set (ETable *table, - GdkModifierType start_button_mask, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions) -{ - ETableDragSourceSite *site; - GtkWidget *canvas = GTK_WIDGET(table->table_canvas); - - g_return_if_fail (table != NULL); - - site = table->site; - - gtk_widget_add_events (canvas, - gtk_widget_get_events (canvas) | - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | - GDK_BUTTON_MOTION_MASK); - - if (site) { - if (site->target_list) - gtk_target_list_unref (site->target_list); - } else { - site = g_new0 (ETableDragSourceSite, 1); - - table->drag_source_button_press_event_id = - gtk_signal_connect (GTK_OBJECT (canvas), "button_press_event", - GTK_SIGNAL_FUNC (e_table_drag_source_event_cb), - table); - table->drag_source_motion_notify_event_id = - gtk_signal_connect (GTK_OBJECT (canvas), "motion_notify_event", - GTK_SIGNAL_FUNC (e_table_drag_source_event_cb), - table); - - table->site = site; - } - - site->start_button_mask = start_button_mask; - - if (targets) - site->target_list = gtk_target_list_new (targets, n_targets); - else - site->target_list = NULL; - - site->actions = actions; -} - -void e_table_drag_source_unset (ETable *table) -{ - ETableDragSourceSite *site; - - g_return_if_fail (table != NULL); - - site = table->site; - - if (site) { - gtk_signal_disconnect (GTK_OBJECT (table->table_canvas), table->drag_source_button_press_event_id); - gtk_signal_disconnect (GTK_OBJECT (table->table_canvas), table->drag_source_motion_notify_event_id); - g_free(site); - table->site = NULL; - } -} - -/* There probably should be functions for setting the targets - * as a GtkTargetList - */ - -GdkDragContext * -e_table_drag_begin (ETable *table, - int row, - int col, - GtkTargetList *targets, - GdkDragAction actions, - gint button, - GdkEvent *event) -{ - table->drag_row = row; - table->drag_col = col; - - return gtk_drag_begin(GTK_WIDGET(table), - targets, - actions, - button, - event); -} - -static void -e_table_compute_location(ETable *table, - GtkWidget *widget, - int x, - int y, - int *row, - int *col) -{ - if (!(row || col)) - return; - e_table_group_compute_location(table->group, &x, &y, row, col); -} - -static void -et_drag_begin (GtkWidget *widget, - GdkDragContext *context, - ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_BEGIN], - et->drag_row, - et->drag_col, - context); -} - -static void -et_drag_end (GtkWidget *widget, - GdkDragContext *context, - ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_END], - et->drag_row, - et->drag_col, - context); -} - -static void -et_drag_data_get(GtkWidget *widget, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time, - ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_DATA_GET], - et->drag_row, - et->drag_col, - context, - selection_data, - info, - time); -} - -static void -et_drag_data_delete(GtkWidget *widget, - GdkDragContext *context, - ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_DATA_DELETE], - et->drag_row, - et->drag_col, - context); -} - -static void -et_drag_leave(GtkWidget *widget, - GdkDragContext *context, - guint time, - ETable *et) -{ - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_LEAVE], - et->drop_row, - et->drop_col, - context, - time); - et->drop_row = -1; - et->drop_col = -1; -} - -static gboolean -et_drag_motion(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETable *et) -{ - gboolean ret_val; - int row, col; - e_table_compute_location(et, - widget, - x, - y, - &row, - &col); - if (et->drop_row >= 0 && et->drop_col >= 0 && - row != et->drop_row && col != et->drop_row) { - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_LEAVE], - et->drop_row, - et->drop_col, - context, - time); - } - et->drop_row = row; - et->drop_col = col; - if (row >= 0 && col >= 0) - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_MOTION], - et->drop_row, - et->drop_col, - context, - x, - y, - time, - &ret_val); - return ret_val; -} - -static gboolean -et_drag_drop(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - guint time, - ETable *et) -{ - gboolean ret_val; - int row, col; - e_table_compute_location(et, - widget, - x, - y, - &row, - &col); - if (et->drop_row >= 0 && et->drop_col >= 0 && - row != et->drop_row && col != et->drop_row) { - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_LEAVE], - et->drop_row, - et->drop_col, - context, - time); - if (row >= 0 && col >= 0) - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_MOTION], - row, - col, - context, - x, - y, - time, - &ret_val); - } - et->drop_row = row; - et->drop_col = col; - if (row >= 0 && col >= 0) - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_DROP], - et->drop_row, - et->drop_col, - context, - x, - y, - time, - &ret_val); - et->drop_row = -1; - et->drop_col = -1; - return ret_val; -} - -static void -et_drag_data_received(GtkWidget *widget, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time, - ETable *et) -{ - int row, col; - e_table_compute_location(et, - widget, - x, - y, - &row, - &col); - gtk_signal_emit (GTK_OBJECT (et), - et_signals [TABLE_DRAG_MOTION], - row, - col, - context, - x, - y, - selection_data, - info, - time); -} - -static gint -e_table_drag_source_event_cb (GtkWidget *widget, - GdkEvent *event, - ETable *table) -{ - ETableDragSourceSite *site; - site = table->site; - - switch (event->type) { - case GDK_BUTTON_PRESS: - if ((GDK_BUTTON1_MASK << (event->button.button - 1)) & site->start_button_mask) { - int row, col; - e_table_compute_location(table, widget, event->button.x, event->button.y, &row, &col); - if (row >= 0 && col >= 0) { - site->state |= (GDK_BUTTON1_MASK << (event->button.button - 1)); - site->x = event->button.x; - site->y = event->button.y; - site->row = row; - site->col = col; - } - } - break; - - case GDK_BUTTON_RELEASE: - if ((GDK_BUTTON1_MASK << (event->button.button - 1)) & site->start_button_mask) { - site->state &= ~(GDK_BUTTON1_MASK << (event->button.button - 1)); - } - break; - - case GDK_MOTION_NOTIFY: - if (site->state & event->motion.state & site->start_button_mask) { - /* FIXME: This is really broken and can leave us - * with a stuck grab - */ - int i; - for (i=1; i<6; i++) { - if (site->state & event->motion.state & - GDK_BUTTON1_MASK << (i - 1)) - break; - } - - if (MAX (abs (site->x - event->motion.x), - abs (site->y - event->motion.y)) > 3) { - GtkDragSourceInfo *info; - GdkDragContext *context; - - site->state = 0; - context = e_table_drag_begin (table, site->row, site->col, - site->target_list, - site->actions, - i, event); - - - info = g_dataset_get_data (context, "gtk-info"); - - if (!info->icon_window) { - if (site->pixmap) - gtk_drag_set_icon_pixmap (context, - site->colormap, - site->pixmap, - site->mask, -2, -2); - else - gtk_drag_set_icon_default (context); - } - - return TRUE; - } - } - break; - - default: /* hit for 2/3BUTTON_PRESS */ - break; - } - return FALSE; -} - -static void -e_table_class_init (GtkObjectClass *object_class) -{ - ETableClass *klass = E_TABLE_CLASS(object_class); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(object_class); - - e_table_parent_class = gtk_type_class (PARENT_TYPE); - - object_class->destroy = et_destroy; - object_class->set_arg = et_set_arg; - object_class->get_arg = et_get_arg; - - klass->cursor_change = NULL; - klass->double_click = NULL; - klass->right_click = NULL; - klass->key_press = NULL; - - klass->table_drag_begin = NULL; - klass->table_drag_end = NULL; - klass->table_drag_data_get = NULL; - klass->table_drag_data_delete = NULL; - - klass->table_drag_leave = NULL; - klass->table_drag_motion = NULL; - klass->table_drag_drop = NULL; - klass->table_drag_data_received = NULL; - - et_signals [CURSOR_CHANGE] = - gtk_signal_new ("cursor_change", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, cursor_change), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - et_signals [DOUBLE_CLICK] = - gtk_signal_new ("double_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, double_click), - gtk_marshal_NONE__INT, - GTK_TYPE_NONE, 1, GTK_TYPE_INT); - - et_signals [RIGHT_CLICK] = - gtk_signal_new ("right_click", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, right_click), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - et_signals [KEY_PRESS] = - gtk_signal_new ("key_press", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, key_press), - e_marshal_INT__INT_INT_POINTER, - GTK_TYPE_INT, 3, GTK_TYPE_INT, GTK_TYPE_INT, GTK_TYPE_POINTER); - - et_signals[TABLE_DRAG_BEGIN] = - gtk_signal_new ("table_drag_begin", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_begin), - gtk_marshal_NONE__INT_INT_POINTER, - GTK_TYPE_NONE, 3, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT); - et_signals[TABLE_DRAG_END] = - gtk_signal_new ("table_drag_end", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_end), - gtk_marshal_NONE__INT_INT_POINTER, - GTK_TYPE_NONE, 3, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT); - et_signals[TABLE_DRAG_DATA_GET] = - gtk_signal_new ("table_drag_data_get", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_data_get), - e_marshal_NONE__INT_INT_POINTER_POINTER_UINT_UINT, - GTK_TYPE_NONE, 6, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT, - GTK_TYPE_SELECTION_DATA, - GTK_TYPE_UINT, - GTK_TYPE_UINT); - et_signals[TABLE_DRAG_DATA_DELETE] = - gtk_signal_new ("table_drag_data_delete", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_data_delete), - gtk_marshal_NONE__INT_INT_POINTER, - GTK_TYPE_NONE, 3, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT); - - et_signals[TABLE_DRAG_LEAVE] = - gtk_signal_new ("table_drag_leave", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_leave), - e_marshal_NONE__INT_INT_POINTER_UINT, - GTK_TYPE_NONE, 4, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT, - GTK_TYPE_UINT); - et_signals[TABLE_DRAG_MOTION] = - gtk_signal_new ("table_drag_motion", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_motion), - e_marshal_BOOL__INT_INT_POINTER_INT_INT_UINT, - GTK_TYPE_BOOL, 6, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_UINT); - et_signals[TABLE_DRAG_DROP] = - gtk_signal_new ("table_drag_drop", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_drop), - e_marshal_BOOL__INT_INT_POINTER_INT_INT_UINT, - GTK_TYPE_BOOL, 6, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_UINT); - et_signals[TABLE_DRAG_DATA_RECEIVED] = - gtk_signal_new ("table_drag_data_received", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, table_drag_data_received), - e_marshal_NONE__INT_INT_POINTER_INT_INT_POINTER_UINT_UINT, - GTK_TYPE_NONE, 8, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_GDK_DRAG_CONTEXT, - GTK_TYPE_INT, - GTK_TYPE_INT, - GTK_TYPE_SELECTION_DATA, - GTK_TYPE_UINT, - GTK_TYPE_UINT); - - gtk_object_class_add_signals (object_class, et_signals, LAST_SIGNAL); - - klass->set_scroll_adjustments = set_scroll_adjustments; - - widget_class->set_scroll_adjustments_signal = - gtk_signal_new ("set_scroll_adjustments", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETableClass, set_scroll_adjustments), - gtk_marshal_NONE__POINTER_POINTER, - GTK_TYPE_NONE, 2, GTK_TYPE_ADJUSTMENT, GTK_TYPE_ADJUSTMENT); - - gtk_object_add_arg_type ("ETable::drawgrid", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_TABLE_DRAW_GRID); - gtk_object_add_arg_type ("ETable::drawfocus", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_TABLE_DRAW_FOCUS); - gtk_object_add_arg_type ("ETable::cursor_mode", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_CURSOR_MODE); - gtk_object_add_arg_type ("ETable::length_threshold", GTK_TYPE_INT, - GTK_ARG_WRITABLE, ARG_LENGTH_THRESHOLD); - gtk_object_add_arg_type ("ETable::click_to_add_message", GTK_TYPE_STRING, - GTK_ARG_READWRITE, ARG_CLICK_TO_ADD_MESSAGE); -} - -E_MAKE_TYPE(e_table, "ETable", ETable, e_table_class_init, e_table_init, PARENT_TYPE); - diff --git a/widgets/table/e-table.h b/widgets/table/e-table.h deleted file mode 100644 index 19dcbfecc8..0000000000 --- a/widgets/table/e-table.h +++ /dev/null @@ -1,252 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TABLE_H_ -#define _E_TABLE_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gtk/gtktable.h> -#include <gnome-xml/tree.h> -#include "e-table-model.h" -#include "e-table-header.h" -#include "e-table-group.h" -#include "e-table-sort-info.h" -#include "e-table-item.h" -#include "e-table-selection-model.h" -#include "e-util/e-printable.h" - -BEGIN_GNOME_DECLS - -#define E_TABLE_TYPE (e_table_get_type ()) -#define E_TABLE(o) (GTK_CHECK_CAST ((o), E_TABLE_TYPE, ETable)) -#define E_TABLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TABLE_TYPE, ETableClass)) -#define E_IS_TABLE(o) (GTK_CHECK_TYPE ((o), E_TABLE_TYPE)) -#define E_IS_TABLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TABLE_TYPE)) - -typedef struct _ETableDragSourceSite ETableDragSourceSite; - -typedef enum { - E_TABLE_CURSOR_LOC_NONE = 0, - E_TABLE_CURSOR_LOC_ETCTA = 1 << 0, - E_TABLE_CURSOR_LOC_TABLE = 1 << 1, -} ETableCursorLoc; - -typedef struct { - GtkTable parent; - - ETableModel *model; - - ETableHeader *full_header, *header; - - GnomeCanvasItem *canvas_vbox; - ETableGroup *group; - - ETableSortInfo *sort_info; - ETableSorter *sorter; - - ETableSelectionModel *selection; - ETableCursorLoc cursor_loc; - - int table_model_change_id; - int table_row_change_id; - int table_cell_change_id; - int table_row_inserted_id; - int table_row_deleted_id; - - int group_info_change_id; - - int reflow_idle_id; - - GnomeCanvas *header_canvas, *table_canvas; - - GnomeCanvasItem *header_item, *root; - - gint length_threshold; - - gint rebuild_idle_id; - guint need_rebuild:1; - - /* - * Configuration settings - */ - guint draw_grid : 1; - guint draw_focus : 1; - guint row_selection_active : 1; - - char *click_to_add_message; - GnomeCanvasItem *click_to_add; - gboolean use_click_to_add; - - ETableCursorMode cursor_mode; - - int drag_get_data_row; - int drag_get_data_col; - - int drop_row; - int drop_col; - - int drag_row; - int drag_col; - ETableDragSourceSite *site; - - int drag_source_button_press_event_id; - int drag_source_motion_notify_event_id; -} ETable; - -typedef struct { - GtkTableClass parent_class; - - void (*cursor_change) (ETable *et, int row); - void (*double_click) (ETable *et, int row); - gint (*right_click) (ETable *et, int row, int col, GdkEvent *event); - gint (*key_press) (ETable *et, int row, int col, GdkEvent *event); - - void (*set_scroll_adjustments) (ETable *table, - GtkAdjustment *hadjustment, - GtkAdjustment *vadjustment); - - /* Source side drag signals */ - void (* table_drag_begin) (ETable *table, - int row, - int col, - GdkDragContext *context); - void (* table_drag_end) (ETable *table, - int row, - int col, - GdkDragContext *context); - void (* table_drag_data_get) (ETable *table, - int row, - int col, - GdkDragContext *context, - GtkSelectionData *selection_data, - guint info, - guint time); - void (* table_drag_data_delete) (ETable *table, - int row, - int col, - GdkDragContext *context); - - /* Target side drag signals */ - void (* table_drag_leave) (ETable *table, - int row, - int col, - GdkDragContext *context, - guint time); - gboolean (* table_drag_motion) (ETable *table, - int row, - int col, - GdkDragContext *context, - gint x, - gint y, - guint time); - gboolean (* table_drag_drop) (ETable *table, - int row, - int col, - GdkDragContext *context, - gint x, - gint y, - guint time); - void (* table_drag_data_received) (ETable *table, - int row, - int col, - GdkDragContext *context, - gint x, - gint y, - GtkSelectionData *selection_data, - guint info, - guint time); -} ETableClass; - -GtkType e_table_get_type (void); - -ETable *e_table_construct (ETable *e_table, ETableHeader *full_header, ETableModel *etm, - const char *spec); -GtkWidget *e_table_new (ETableHeader *full_header, ETableModel *etm, - const char *spec); - -ETable *e_table_construct_from_spec_file (ETable *e_table, - ETableHeader *full_header, - ETableModel *etm, - const char *filename); -GtkWidget *e_table_new_from_spec_file (ETableHeader *full_header, - ETableModel *etm, - const char *filename); - -gchar *e_table_get_specification (ETable *e_table); -void e_table_save_specification (ETable *e_table, gchar *filename); - -void e_table_set_cursor_row (ETable *e_table, - int row); -/* -1 means we don't have the cursor. */ -int e_table_get_cursor_row (ETable *e_table); -void e_table_selected_row_foreach (ETable *e_table, - ETableForeachFunc callback, - gpointer closure); -EPrintable *e_table_get_printable (ETable *e_table); - -gint e_table_get_next_row (ETable *e_table, - gint model_row); -gint e_table_get_prev_row (ETable *e_table, - gint model_row); - -gint e_table_model_to_view_row (ETable *e_table, - gint model_row); -gint e_table_view_to_model_row (ETable *e_table, - gint view_row); - - -/* Drag & drop stuff. */ -/* Target */ -void e_table_drag_get_data (ETable *table, - int row, - int col, - GdkDragContext *context, - GdkAtom target, - guint32 time); - -void e_table_drag_highlight (ETable *table, - int row, - int col); /* col == -1 to highlight entire row. */ -void e_table_drag_unhighlight (ETable *table); - -void e_table_drag_dest_set (ETable *table, - GtkDestDefaults flags, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions); - -void e_table_drag_dest_set_proxy (ETable *table, - GdkWindow *proxy_window, - GdkDragProtocol protocol, - gboolean use_coordinates); - -/* There probably should be functions for setting the targets - * as a GtkTargetList - */ - -void e_table_drag_dest_unset (GtkWidget *widget); - -/* Source side */ - -void e_table_drag_source_set (ETable *table, - GdkModifierType start_button_mask, - const GtkTargetEntry *targets, - gint n_targets, - GdkDragAction actions); - -void e_table_drag_source_unset (ETable *table); - -/* There probably should be functions for setting the targets - * as a GtkTargetList - */ - -GdkDragContext *e_table_drag_begin (ETable *table, - int row, - int col, - GtkTargetList *targets, - GdkDragAction actions, - gint button, - GdkEvent *event); - -END_GNOME_DECLS - -#endif /* _E_TABLE_H_ */ - diff --git a/widgets/table/e-tree-example-1.c b/widgets/table/e-tree-example-1.c deleted file mode 100644 index 308f462f64..0000000000 --- a/widgets/table/e-tree-example-1.c +++ /dev/null @@ -1,403 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* This code is GPL. */ -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "e-util/e-cursors.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-cell-tree.h" -#include "e-cell-checkbox.h" -#include "e-table.h" -#include "e-tree-simple.h" -#include "libgnomeprint/gnome-print.h" -#include "libgnomeprint/gnome-print-preview.h" - -#include <gdk-pixbuf/gdk-pixbuf.h> - -#include "tree-expanded.xpm" -#include "tree-unexpanded.xpm" - -GdkPixbuf *tree_expanded_pixbuf; -GdkPixbuf *tree_unexpanded_pixbuf; - -#define COLS 4 - -#define IMPORTANCE_COLUMN 4 -#define COLOR_COLUMN 5 - -/* - * Here we define the initial layout of the table. This is an xml - * format that allows you to change the initial ordering of the - * columns or to do sorting or grouping initially. This specification - * shows all 5 columns, but moves the importance column nearer to the - * front. It also sorts by the "Full Name" column (ascending.) - * Sorting and grouping take the model column as their arguments - * (sorting is specified by the "column" argument to the leaf elemnt. - */ - -#define INITIAL_SPEC "<ETableSpecification> \ - <columns-shown> \ - <column> 0 </column> \ - <column> 4 </column> \ - <column> 1 </column> \ - <column> 2 </column> \ - <column> 3 </column> \ - </columns-shown> \ - <grouping></grouping> \ -</ETableSpecification>" - -/* - * Virtual Column list: - * 0 Subject - * 1 Full Name - * 2 Email - * 3 Date - */ -char *headers [COLS] = { - "Subject", - "Full Name", - "Email", - "Date" -}; - -GtkWidget *e_table; - -/* - * ETreeSimple callbacks - * These are the callbacks that define the behavior of our custom model. - */ - -/* This function returns the value at a particular point in our ETreeModel. */ -static void * -my_value_at (ETreeModel *etm, ETreePath *path, int col, void *model_data) -{ - switch (col) { - case 0: return e_tree_model_node_get_data (etm, path); - case 1: return "Chris Toshok"; - case 2: return "toshok@helixcode.com"; - case 3: return "Jun 07 2000"; - default: return NULL; - } -} - -static GdkPixbuf * -my_icon_at (ETreeModel *etm, ETreePath *path, void *model_data) -{ - if (e_tree_model_node_is_expanded (etm, path)) - return tree_expanded_pixbuf; - else - return tree_unexpanded_pixbuf; -} - -/* This function sets the value at a particular point in our ETreeModel. */ -static void -my_set_value_at (ETreeModel *etm, ETreePath *path, int col, const void *val, void *model_data) -{ - if (col == 0) { - char *str = e_tree_model_node_get_data (etm, path); - g_free (str); - e_tree_model_node_set_data (etm, path, g_strdup(val)); - } -} - -/* This function returns whether a particular cell is editable. */ -static gboolean -my_is_editable (ETreeModel *etm, ETreePath *path, int col, void *model_data) -{ - if (col == 0) - return TRUE; - else - return FALSE; -} - -static void -toggle_root (GtkButton *button, gpointer data) -{ - ETreeModel *e_tree_model = (ETreeModel*)data; - e_tree_model_root_node_set_visible (e_tree_model, !e_tree_model_root_node_is_visible (e_tree_model)); -} - -static void -add_sibling (GtkButton *button, gpointer data) -{ - ETreeModel *e_tree_model = E_TREE_MODEL (data); - int selected_row; - ETreePath *selected_node; - ETreePath *parent_node; - - selected_row = e_table_get_cursor_row (E_TABLE (e_table)); - if (selected_row == -1) - return; - - selected_node = e_tree_model_node_at_row (e_tree_model, selected_row); - g_assert (selected_node); - - parent_node = e_tree_model_node_get_parent (e_tree_model, selected_node); - - e_tree_model_node_insert_before (e_tree_model, parent_node, - selected_node, - g_strdup("User added sibling")); - -} - -static void -add_child (GtkButton *button, gpointer data) -{ - ETreeModel *e_tree_model = E_TREE_MODEL (data); - int selected_row; - ETreePath *selected_node; - - selected_row = e_table_get_cursor_row (E_TABLE (e_table)); - if (selected_row == -1) - return; - - selected_node = e_tree_model_node_at_row (e_tree_model, selected_row); - g_assert (selected_node); - - e_tree_model_node_insert (e_tree_model, selected_node, - 0, - g_strdup("User added child")); -} - -static void -remove_node (GtkButton *button, gpointer data) -{ - ETreeModel *e_tree_model = E_TREE_MODEL (data); - int selected_row; - char *str; - ETreePath *selected_node; - - selected_row = e_table_get_cursor_row (E_TABLE (e_table)); - if (selected_row == -1) - return; - - selected_node = e_tree_model_node_at_row (e_tree_model, selected_row); - g_assert (selected_node); - - if (e_tree_model_node_get_children (e_tree_model, selected_node, NULL) > 0) - return; - - str = (char*)e_tree_model_node_remove (e_tree_model, selected_node); - printf ("removed node %s\n", str); - g_free (str); -} - -static void -expand_all (GtkButton *button, gpointer data) -{ - ETreeModel *e_tree_model = E_TREE_MODEL (data); - int selected_row; - ETreePath *selected_node; - - selected_row = e_table_get_cursor_row (E_TABLE (e_table)); - if (selected_row == -1) - return; - - selected_node = e_tree_model_node_at_row (e_tree_model, selected_row); - g_assert (selected_node); - - e_tree_model_node_set_expanded_recurse (e_tree_model, selected_node, TRUE); -} - -static void -collapse_all (GtkButton *button, gpointer data) -{ - ETreeModel *e_tree_model = E_TREE_MODEL (data); - int selected_row; - ETreePath *selected_node; - - selected_row = e_table_get_cursor_row (E_TABLE (e_table)); - if (selected_row == -1) - return; - - selected_node = e_tree_model_node_at_row (e_tree_model, selected_row); - g_assert (selected_node); - - e_tree_model_node_set_expanded_recurse (e_tree_model, selected_node, FALSE); -} - -static void -print_tree (GtkButton *button, gpointer data) -{ - EPrintable *printable = e_table_get_printable (E_TABLE (e_table)); - GnomePrintContext *gpc; - - gpc = gnome_print_context_new (gnome_printer_new_generic_ps ("tree-out.ps")); - - e_printable_print_page (printable, gpc, 8*72, 10*72, FALSE); - - gnome_print_context_close (gpc); -} - -/* We create a window containing our new tree. */ -static void -create_tree (void) -{ - GtkWidget *window, *frame, *button, *vbox; - ECell *cell_left_just; - ECell *cell_tree; - ETableHeader *e_table_header; - int i, j; - ETreeModel *e_tree_model = NULL; - ETreePath *root_node; - - /* here we create our model. This uses the functions we defined - earlier. */ - e_tree_model = e_tree_simple_new (my_icon_at, - my_value_at, - my_set_value_at, - my_is_editable, - NULL); - - /* create a root node with 5 children */ - root_node = e_tree_model_node_insert (e_tree_model, NULL, - 0, - g_strdup("Root Node")); - - for (i = 0; i < 5; i++){ - ETreePath *n = e_tree_model_node_insert (e_tree_model, - root_node, 0, - g_strdup("First level of children")); - for (j = 0; j < 5; j ++) { - e_tree_model_node_insert (e_tree_model, - n, 0, - g_strdup("Second level of children")); - } - } - - /* - * Next we create a header. The ETableHeader is used in two - * different way. The first is the full_header. This is the - * list of possible columns in the view. The second use is - * completely internal. Many of the ETableHeader functions are - * for that purpose. The only functions we really need are - * e_table_header_new and e_table_header_add_col. - * - * First we create the header. - */ - e_table_header = e_table_header_new (); - - /* - * Next we have to build renderers for all of the columns. - * Since all our columns are text columns, we can simply use - * the same renderer over and over again. If we had different - * types of columns, we could use a different renderer for - * each column. - */ - cell_left_just = e_cell_text_new (E_TABLE_MODEL(e_tree_model), NULL, GTK_JUSTIFY_LEFT); - - /* - * This renderer is used for the tree column (the leftmost one), and - * has as its subcell renderer the text renderer. this means that - * text is displayed to the right of the tree pipes. - */ - cell_tree = e_cell_tree_new (E_TABLE_MODEL(e_tree_model), - tree_expanded_pixbuf, tree_unexpanded_pixbuf, - TRUE, cell_left_just); - - /* - * Next we create a column object for each view column and add - * them to the header. We don't create a column object for - * the importance column since it will not be shown. - */ - for (i = 0; i < COLS; i++) { - /* Create the column. */ - ETableCol *ecol = e_table_col_new ( - i, headers [i], - 80, 20, - i == 0 ? cell_tree - : cell_left_just, - g_str_compare, TRUE); - /* Add it to the header. */ - e_table_header_add_column (e_table_header, ecol, i); - } - - /* - * Here we create a window for our new table. This window - * will get shown and the person will be able to test their - * item. - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - - /* This frame is simply to get a bevel around our table. */ - vbox = gtk_vbox_new (FALSE, 0); - frame = gtk_frame_new (NULL); - - /* - * Here we create the table. We give it the three pieces of - * the table we've created, the header, the model, and the - * initial layout. It does the rest. - */ - e_table = e_table_new (e_table_header, E_TABLE_MODEL(e_tree_model), INITIAL_SPEC); - - if (!e_table) printf ("BAH!"); - - /* Build the gtk widget hierarchy. */ - gtk_container_add (GTK_CONTAINER (frame), e_table); - gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0); - - button = gtk_button_new_with_label ("Toggle Root Node"); - gtk_signal_connect (GTK_OBJECT (button), "clicked", toggle_root, e_tree_model); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - button = gtk_button_new_with_label ("Add Sibling"); - gtk_signal_connect (GTK_OBJECT (button), "clicked", add_sibling, e_tree_model); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - button = gtk_button_new_with_label ("Add Child"); - gtk_signal_connect (GTK_OBJECT (button), "clicked", add_child, e_tree_model); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - button = gtk_button_new_with_label ("Remove Node"); - gtk_signal_connect (GTK_OBJECT (button), "clicked", remove_node, e_tree_model); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - button = gtk_button_new_with_label ("Expand All Below"); - gtk_signal_connect (GTK_OBJECT (button), "clicked", expand_all, e_tree_model); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - button = gtk_button_new_with_label ("Collapse All Below"); - gtk_signal_connect (GTK_OBJECT (button), "clicked", collapse_all, e_tree_model); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - button = gtk_button_new_with_label ("Print Tree"); - gtk_signal_connect (GTK_OBJECT (button), "clicked", print_tree, e_tree_model); - gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - gtk_container_add (GTK_CONTAINER (window), vbox); - - /* Size the initial window. */ - gtk_widget_set_usize (window, 200, 200); - - /* Show it all. */ - gtk_widget_show_all (window); -} - -/* This is the main function which just initializes gnome and call our create_tree function */ - -int -main (int argc, char *argv []) -{ - gnome_init ("TableExample", "TableExample", argc, argv); - e_cursors_init (); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - /* - * Create our pixbuf for expanding/unexpanding - */ - tree_expanded_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)tree_expanded_xpm); - tree_unexpanded_pixbuf = gdk_pixbuf_new_from_xpm_data((const char**)tree_unexpanded_xpm); - - create_tree (); - - gtk_main (); - - e_cursors_shutdown (); - return 0; -} - diff --git a/widgets/table/e-tree-model.c b/widgets/table/e-tree-model.c deleted file mode 100644 index c57bf2d683..0000000000 --- a/widgets/table/e-tree-model.c +++ /dev/null @@ -1,760 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-tree-model.c: a Tree Model - * - * Author: - * Chris Toshok (toshok@helixcode.com) - * - * Adapted from the gtree code and ETableModel. - * - * (C) 2000 Helix Code, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include <stdlib.h> -#include "e-util/e-util.h" -#include "e-tree-model.h" - -#define ETM_CLASS(e) ((ETreeModelClass *)((GtkObject *)e)->klass) - -#define PARENT_TYPE E_TABLE_MODEL_TYPE - -static ETableModel *e_tree_model_parent_class; - -typedef struct { - gboolean expanded; - guint visible_descendents; - gpointer node_data; -} ENode; - -enum { - NODE_CHANGED, - NODE_INSERTED, - NODE_REMOVED, - LAST_SIGNAL -}; - -static guint e_tree_model_signals [LAST_SIGNAL] = {0, }; - -static void add_visible_descendents_to_array (ETreeModel *etm, GNode *gnode, int *row, int *count); - - -/* virtual methods */ - -static void -etree_destroy (GtkObject *object) -{ - ETreeModel *etree = E_TREE_MODEL (object); - - /* XXX lots of stuff to free here */ - g_array_free (etree->row_array, TRUE); - - GTK_OBJECT_CLASS (e_tree_model_parent_class)->destroy (object); -} - -static ETreePath* -etree_get_root (ETreeModel *etm) -{ - return etm->root; -} - -static ETreePath* -etree_get_parent (ETreeModel *etm, ETreePath *path) -{ - g_return_val_if_fail (path, NULL); - - return path->parent; -} - -static ETreePath* -etree_get_next (ETreeModel *etm, ETreePath *node) -{ - g_return_val_if_fail (node, NULL); - - return g_node_next_sibling(node); -} - -static ETreePath* -etree_get_prev (ETreeModel *etm, ETreePath *node) -{ - g_return_val_if_fail (node, NULL); - - return g_node_prev_sibling (node); -} - -static guint -etree_get_children (ETreeModel *etm, ETreePath* node, ETreePath ***paths) -{ - guint n_children; - - g_return_val_if_fail (node, 0); - - n_children = g_node_n_children (node); - - if (paths) { - int i; - (*paths) = g_malloc (sizeof (ETreePath*) * n_children); - for (i = 0; i < n_children; i ++) { - (*paths)[i] = g_node_nth_child (node, i); - } - } - - return n_children; -} - -static gboolean -etree_is_expanded (ETreeModel *etm, ETreePath* node) -{ - g_return_val_if_fail (node && node->data, FALSE); - - return ((ENode*)node->data)->expanded; -} - -static gboolean -etree_is_visible (ETreeModel *etm, ETreePath* node) -{ - g_return_val_if_fail (node, FALSE); - - for (node = node->parent; node; node = node->parent) { - if (!((ENode*)node->data)->expanded) - return FALSE; - } - - return TRUE; -} - -static void -etree_set_expanded (ETreeModel *etm, ETreePath* node, gboolean expanded) -{ - GNode *child; - ENode *enode; - int row; - - g_return_if_fail (node && node->data); - - enode = ((ENode*)node->data); - - if (enode->expanded == expanded) - return; - - enode->expanded = expanded; - - /* if the node wasn't visible at present */ - if ((row = e_tree_model_row_of_node (etm, node)) == -1) - return; - - row++; - - if (expanded) { - GNode *parent; - - if (e_tree_model_node_is_visible (etm, node)) { - enode->visible_descendents = 0; - for (child = g_node_first_child (node); child; - child = g_node_next_sibling (child)) { - add_visible_descendents_to_array (etm, child, &row, &enode->visible_descendents); - } - } - /* now iterate back up the tree, adding to our - ancestors' visible descendents */ - - for (parent = node->parent; parent; parent = parent->parent) { - ENode *parent_enode = (ENode*)parent->data; - parent_enode->visible_descendents += enode->visible_descendents; - } - } - else { - int i; - GNode *parent; - - if (e_tree_model_node_is_visible (etm, node)) { - for (i = 0; i < enode->visible_descendents; i ++) { - etm->row_array = g_array_remove_index (etm->row_array, row); - e_table_model_row_deleted (E_TABLE_MODEL (etm), row); - } - } - /* now iterate back up the tree, subtracting from our - ancestors' visible descendents */ - - for (parent = node->parent; parent; parent = parent->parent) { - ENode *parent_enode = (ENode*)parent->data; - - parent_enode->visible_descendents -= enode->visible_descendents; - } - - enode->visible_descendents = 0; - } -} - -/* fairly naive implementation */ -static void -etree_set_expanded_recurse (ETreeModel *etm, ETreePath* node, gboolean expanded) -{ - ETreePath **paths; - guint num_children; - int i; - - e_tree_model_node_set_expanded (etm, node, expanded); - - num_children = e_tree_model_node_get_children (etm, node, &paths); - if (num_children) { - for (i = 0; i < num_children; i ++) { - e_tree_model_node_set_expanded_recurse (etm, paths[i], expanded); - } - - g_free (paths); - } -} - -static ETreePath * -etree_node_at_row (ETreeModel *etree, int row) -{ - g_return_val_if_fail (row < etree->row_array->len, NULL); - - return g_array_index (etree->row_array, GNode*, row); -} - - -/* ETable analogs */ -static void* -etree_value_at (ETreeModel *etm, ETreePath* node, int col) -{ - /* shouldn't be called */ - g_assert (0); - return NULL; -} - -static GdkPixbuf* -etree_icon_at (ETreeModel *etm, ETreePath* node) -{ - /* shouldn't be called */ - g_assert (0); - return NULL; -} - -static void -etree_set_value_at (ETreeModel *etm, ETreePath* node, int col, const void *val) -{ - /* shouldn't be called */ - g_assert (0); -} - -static gboolean -etree_is_editable (ETreeModel *etm, ETreePath* node, int col) -{ - /* shouldn't be called */ - g_assert(0); - return FALSE; -} - - -/* ETable virtual functions we map */ -static int -etable_row_count (ETableModel *etm) -{ - ETreeModel *tree = E_TREE_MODEL (etm); - return tree->row_array->len; -} - -static void * -etable_value_at (ETableModel *etm, int col, int row) -{ - ETreeModel *etree = E_TREE_MODEL(etm); - ETreeModelClass *et_class = ETM_CLASS(etm); - ETreePath* node = e_tree_model_node_at_row (etree, row); - - g_return_val_if_fail (node, NULL); - - if (col == -1) - return node; - else if (col == -2) - return etm; - else - return et_class->value_at (etree, node, col); -} - -static void -etable_set_value_at (ETableModel *etm, int col, int row, const void *val) -{ - ETreeModel *etree = E_TREE_MODEL(etm); - ETreeModelClass *et_class = ETM_CLASS(etm); - ETreePath* node = e_tree_model_node_at_row (etree, row); - - g_return_if_fail (node); - - et_class->set_value_at (etree, node, col, val); -} - -static gboolean -etable_is_cell_editable (ETableModel *etm, int col, int row) -{ - ETreeModel *etree = E_TREE_MODEL(etm); - ETreeModelClass *et_class = ETM_CLASS(etm); - ETreePath* node = e_tree_model_node_at_row (etree, row); - - g_return_val_if_fail (node, FALSE); - - return et_class->is_editable (etree, node, col); -} - - -static void -e_tree_model_class_init (GtkObjectClass *klass) -{ - ETableModelClass *table_class = (ETableModelClass *) klass; - ETreeModelClass *tree_class = (ETreeModelClass *) klass; - - e_tree_model_parent_class = gtk_type_class (PARENT_TYPE); - - klass->destroy = etree_destroy; - - e_tree_model_signals [NODE_CHANGED] = - gtk_signal_new ("node_changed", - GTK_RUN_LAST, - klass->type, - GTK_SIGNAL_OFFSET (ETreeModelClass, node_changed), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, GTK_TYPE_POINTER); - - e_tree_model_signals [NODE_INSERTED] = - gtk_signal_new ("node_inserted", - GTK_RUN_LAST, - klass->type, - GTK_SIGNAL_OFFSET (ETreeModelClass, node_inserted), - gtk_marshal_NONE__POINTER_POINTER, - GTK_TYPE_NONE, 2, GTK_TYPE_POINTER, GTK_TYPE_POINTER); - - e_tree_model_signals [NODE_REMOVED] = - gtk_signal_new ("node_removed", - GTK_RUN_LAST, - klass->type, - GTK_SIGNAL_OFFSET (ETreeModelClass, node_removed), - gtk_marshal_NONE__POINTER_POINTER, - GTK_TYPE_NONE, 2, GTK_TYPE_POINTER, GTK_TYPE_POINTER); - - gtk_object_class_add_signals (klass, e_tree_model_signals, LAST_SIGNAL); - - table_class->row_count = etable_row_count; - table_class->value_at = etable_value_at; - table_class->set_value_at = etable_set_value_at; - table_class->is_cell_editable = etable_is_cell_editable; -#if 0 - /* XX need to pass these through */ - table_class->duplicate_value = etable_duplicate_value; - table_class->free_value = etable_free_value; - table_class->initialize_value = etable_initialize_value; - table_class->value_is_empty = etable_value_is_empty; - table_class->value_to_string = etable_value_to_string; - table_class->thaw = etable_thaw; -#endif - - tree_class->get_root = etree_get_root; - tree_class->get_prev = etree_get_prev; - tree_class->get_next = etree_get_next; - tree_class->get_parent = etree_get_parent; - - tree_class->value_at = etree_value_at; - tree_class->icon_at = etree_icon_at; - tree_class->set_value_at = etree_set_value_at; - tree_class->is_editable = etree_is_editable; - - tree_class->get_children = etree_get_children; - tree_class->is_expanded = etree_is_expanded; - tree_class->is_visible = etree_is_visible; - tree_class->set_expanded = etree_set_expanded; - tree_class->set_expanded_recurse = etree_set_expanded_recurse; - tree_class->node_at_row = etree_node_at_row; -} - -E_MAKE_TYPE(e_tree_model, "ETreeModel", ETreeModel, e_tree_model_class_init, NULL, PARENT_TYPE) - - -/* signals */ -void -e_tree_model_node_changed (ETreeModel *tree_model, ETreePath *node) -{ - g_return_if_fail (tree_model != NULL); - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - gtk_signal_emit (GTK_OBJECT (tree_model), - e_tree_model_signals [NODE_CHANGED]); -} - -void -e_tree_model_node_inserted (ETreeModel *tree_model, - ETreePath *parent_node, - ETreePath *inserted_node) -{ - g_return_if_fail (tree_model != NULL); - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - gtk_signal_emit (GTK_OBJECT (tree_model), - e_tree_model_signals [NODE_INSERTED], - parent_node, inserted_node); -} - -void -e_tree_model_node_removed (ETreeModel *tree_model, ETreePath *parent_node, ETreePath *removed_node) -{ - g_return_if_fail (tree_model != NULL); - g_return_if_fail (E_IS_TREE_MODEL (tree_model)); - - gtk_signal_emit (GTK_OBJECT (tree_model), - e_tree_model_signals [NODE_REMOVED], - parent_node, removed_node); -} - - -void -e_tree_model_construct (ETreeModel *etree) -{ - etree->root = NULL; - etree->root_visible = TRUE; - etree->row_array = g_array_new (FALSE, FALSE, sizeof(GNode*)); -} - -ETreeModel * -e_tree_model_new () -{ - ETreeModel *et; - - et = gtk_type_new (e_tree_model_get_type ()); - - return et; -} - -ETreePath * -e_tree_model_get_root (ETreeModel *etree) -{ - return ETM_CLASS(etree)->get_root(etree); -} - -ETreePath * -e_tree_model_node_at_row (ETreeModel *etree, int row) -{ - return ETM_CLASS(etree)->node_at_row (etree, row); -} - -GdkPixbuf * -e_tree_model_icon_of_node (ETreeModel *etree, ETreePath *path) -{ - return ETM_CLASS(etree)->icon_at (etree, path); -} - -int -e_tree_model_row_of_node (ETreeModel *etree, ETreePath *node) -{ - int i; - - for (i = 0; i < etree->row_array->len; i ++) - if (g_array_index (etree->row_array, GNode*, i) == node) - return i; - - g_warning ("e_tree_model_row_of_node failed for node %p\n", node); - - return -1; -} - -void -e_tree_model_root_node_set_visible (ETreeModel *etm, gboolean visible) -{ - if (visible != etm->root_visible) { - etm->root_visible = visible; - if (etm->root) { - if (visible) { - etm->row_array = g_array_insert_val (etm->row_array, 0, etm->root); - } - else { - ETreePath *root_path = e_tree_model_get_root (etm); - e_tree_model_node_set_expanded (etm, root_path, TRUE); - etm->row_array = g_array_remove_index (etm->row_array, 0); - } - - e_table_model_changed (E_TABLE_MODEL (etm)); - } - } -} - -gboolean -e_tree_model_root_node_is_visible (ETreeModel *etm) -{ - return etm->root_visible; -} - - -ETreePath * -e_tree_model_node_get_next (ETreeModel *etree, ETreePath *node) -{ - return ETM_CLASS(etree)->get_next(etree, node); -} - -ETreePath * -e_tree_model_node_get_prev (ETreeModel *etree, ETreePath *node) -{ - return ETM_CLASS(etree)->get_prev(etree, node); -} - -guint -e_tree_model_node_depth (ETreeModel *etree, ETreePath *path) -{ - return g_node_depth (path) - 1; -} - -ETreePath * -e_tree_model_node_get_parent (ETreeModel *etree, ETreePath *path) -{ - return ETM_CLASS(etree)->get_parent(etree, path); -} - -gboolean -e_tree_model_node_is_root (ETreeModel *etree, ETreePath *path) -{ - return (e_tree_model_node_depth (etree, path) == 0); -} - -gboolean -e_tree_model_node_is_expandable (ETreeModel *etree, ETreePath *path) -{ - return (e_tree_model_node_get_children (etree, path, NULL) > 0); -} - -gboolean -e_tree_model_node_is_expanded (ETreeModel *etree, ETreePath *path) -{ - return ETM_CLASS(etree)->is_expanded (etree, path); -} - -gboolean -e_tree_model_node_is_visible (ETreeModel *etree, ETreePath *path) -{ - return ETM_CLASS(etree)->is_visible (etree, path); -} - -void -e_tree_model_node_set_expanded (ETreeModel *etree, ETreePath *path, gboolean expanded) -{ - ETM_CLASS(etree)->set_expanded (etree, path, expanded); -} - -void -e_tree_model_node_set_expanded_recurse (ETreeModel *etree, ETreePath *path, gboolean expanded) -{ - ETM_CLASS(etree)->set_expanded_recurse (etree, path, expanded); -} - -guint -e_tree_model_node_get_children (ETreeModel *etree, ETreePath *path, ETreePath ***paths) -{ - return ETM_CLASS(etree)->get_children (etree, path, paths); -} - -guint -e_tree_model_node_num_visible_descendents (ETreeModel *etm, ETreePath *node) -{ - ENode *enode = (ENode*)node->data; - - return enode->visible_descendents; -} - -gpointer -e_tree_model_node_get_data (ETreeModel *etm, ETreePath *node) -{ - ENode *enode; - - g_return_val_if_fail (node && node->data, NULL); - - enode = (ENode*)node->data; - - return enode->node_data; -} - -void -e_tree_model_node_set_data (ETreeModel *etm, ETreePath *node, gpointer node_data) -{ - ENode *enode; - - g_return_if_fail (node && node->data); - - enode = (ENode*)node->data; - - enode->node_data = node_data; -} - -ETreePath* -e_tree_model_node_insert (ETreeModel *tree_model, - ETreePath *parent_path, - int position, - gpointer node_data) -{ - ENode *node; - ETreePath *new_path; - - g_return_val_if_fail (parent_path != NULL || tree_model->root == NULL, NULL); - - node = g_new0 (ENode, 1); - - node->expanded = FALSE; - node->node_data = node_data; - - if (parent_path != NULL) { - - new_path = g_node_new (node); - - g_node_insert (parent_path, position, new_path); - - if (e_tree_model_node_is_visible (tree_model, new_path)) { - int parent_row; - GNode *n; - - /* we need to iterate back up to the root, incrementing the number of visible - descendents */ - for (n = parent_path; n; n = n->parent) { - ENode *parent_enode = (ENode*)n->data; - - parent_enode->visible_descendents ++; - } - - /* finally, insert a row into the table */ - if (position == -1) - position = e_tree_model_node_num_visible_descendents (tree_model, parent_path) - 1; - - parent_row = e_tree_model_row_of_node (tree_model, parent_path); - - tree_model->row_array = g_array_insert_val (tree_model->row_array, - parent_row + position + 1, new_path); - - e_table_model_row_inserted (E_TABLE_MODEL(tree_model), parent_row + position + 1); - } - } - else { - tree_model->root = g_node_new (node); - if (tree_model->root_visible) { - tree_model->row_array = g_array_insert_val (tree_model->row_array, 0, tree_model->root); - e_table_model_row_inserted (E_TABLE_MODEL (tree_model), 0); - } - else { - /* need to mark the new node as expanded or - we'll never see it's children */ - node->expanded = TRUE; - } - new_path = tree_model->root; - } - - return new_path; -} - -ETreePath * -e_tree_model_node_insert_before (ETreeModel *etree, - ETreePath *parent, - ETreePath *sibling, - gpointer node_data) -{ - return e_tree_model_node_insert (etree, parent, - g_node_child_position (parent, sibling), - node_data); -} - -static void -child_remove (GNode *node, gpointer etree) -{ - e_tree_model_node_remove (etree, node); -} - -gpointer -e_tree_model_node_remove (ETreeModel *etree, ETreePath *path) -{ - GNode *parent = path->parent; - ENode *enode = (ENode*)path->data; - gpointer ret = enode->node_data; - - /* remove children */ - g_node_children_foreach (path, G_TRAVERSE_ALL, child_remove, etree); - - /* clean up the display */ - if (parent) { - if (e_tree_model_node_is_visible (etree, path)) { - int row = e_tree_model_row_of_node (etree, path); - e_table_model_row_deleted (E_TABLE_MODEL (etree), row); - etree->row_array = g_array_remove_index (etree->row_array, row); - - /* we need to iterate back up to the root, incrementing the number of visible - descendents */ - for (; parent; parent = parent->parent) { - ENode *parent_enode = (ENode*)parent->data; - - parent_enode->visible_descendents --; - } - } - } - else if (path == etree->root) { - etree->root = NULL; - if (etree->root_visible) { - etree->row_array = g_array_remove_index (etree->row_array, 0); - e_table_model_row_deleted (E_TABLE_MODEL (etree), 0); - } - } - else { - /* XXX invalid path */ - return NULL; - } - - - /* now free up the storage from that path */ - g_node_destroy (path); - g_free (enode); - - return ret; -} - - -static void -add_visible_descendents_to_array (ETreeModel *etm, GNode *gnode, int *row, int *count) -{ - GNode *child; - ENode *enode; - - /* add a row for this node */ - etm->row_array = g_array_insert_val (etm->row_array, (*row), gnode); - e_table_model_row_inserted (E_TABLE_MODEL (etm), (*row)++); - (*count) ++; - - /* then loop over its children, calling this routine for each - of them */ - enode = (ENode*)gnode->data; - if (enode->expanded) { - for (child = g_node_first_child (gnode); child; - child = g_node_next_sibling (child)) { - add_visible_descendents_to_array (etm, child, row, count); - } - } -} - -void -e_tree_model_node_sort (ETreeModel *tree_model, - ETreePath *node, - GCompareFunc compare) -{ - int num_nodes = g_node_n_children (node); - ETreePath **path_array; - int i; - - if (num_nodes == 0) - return; - - path_array = g_new (ETreePath*, num_nodes); - - for (i = 0; i < num_nodes; i ++) { - path_array[i] = g_node_first_child(node); - g_node_unlink (path_array[i]); - } - - qsort (path_array, num_nodes, sizeof(ETreePath*), compare); - - for (i = 0; i < num_nodes; i ++) { - g_node_append (node, path_array[i]); - } - - g_free (path_array); - - e_table_model_changed (E_TABLE_MODEL (tree_model)); -} diff --git a/widgets/table/e-tree-model.h b/widgets/table/e-tree-model.h deleted file mode 100644 index 403aff9a30..0000000000 --- a/widgets/table/e-tree-model.h +++ /dev/null @@ -1,107 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_TREE_MODEL_H_ -#define _E_TREE_MODEL_H_ - -#include "e-table-model.h" -#include "gdk-pixbuf/gdk-pixbuf.h" - -#define E_TREE_MODEL_TYPE (e_tree_model_get_type ()) -#define E_TREE_MODEL(o) (GTK_CHECK_CAST ((o), E_TREE_MODEL_TYPE, ETreeModel)) -#define E_TREE_MODEL_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TREE_MODEL_TYPE, ETreeModelClass)) -#define E_IS_TREE_MODEL(o) (GTK_CHECK_TYPE ((o), E_TREE_MODEL_TYPE)) -#define E_IS_TREE_MODEL_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TREE_MODEL_TYPE)) - -typedef GNode ETreePath; - -typedef struct { - ETableModel base; - GNode *root; - gboolean root_visible; - GArray *row_array; /* used in the mapping between ETable and our tree */ -} ETreeModel; - -typedef struct { - ETableModelClass parent_class; - - /* - * Virtual methods - */ - ETreePath *(*get_root) (ETreeModel *etm); - - ETreePath *(*get_parent) (ETreeModel *etm, ETreePath* node); - ETreePath *(*get_next) (ETreeModel *etm, ETreePath* node); - ETreePath *(*get_prev) (ETreeModel *etm, ETreePath* node); - guint (*get_children) (ETreeModel *etm, ETreePath* node, ETreePath ***paths); - - gboolean (*is_expanded) (ETreeModel *etm, ETreePath* node); - gboolean (*is_visible) (ETreeModel *etm, ETreePath* node); - void (*set_expanded) (ETreeModel *etm, ETreePath* node, gboolean expanded); - void (*set_expanded_recurse) (ETreeModel *etm, ETreePath *node, gboolean expanded); - void (*set_expanded_level) (ETreeModel *etm, ETreePath *node, gboolean expanded, int level); - - GdkPixbuf *(*icon_at) (ETreeModel *etm, ETreePath* node); - ETreePath* (*node_at_row) (ETreeModel *etm, int row); - - /* - * ETable analogs - */ - void *(*value_at) (ETreeModel *etm, ETreePath* node, int col); - void (*set_value_at) (ETreeModel *etm, ETreePath* node, int col, const void *val); - gboolean (*is_editable) (ETreeModel *etm, ETreePath* node, int col); - - - /* - * Signals - */ - void (*node_changed) (ETreeModel *etm, ETreePath *node); - void (*node_inserted) (ETreeModel *etm, ETreePath *parent, ETreePath *inserted_node); - void (*node_removed) (ETreeModel *etm, ETreePath *parent, ETreePath *removed_node); - -} ETreeModelClass; - -GtkType e_tree_model_get_type (void); -void e_tree_model_construct (ETreeModel *etree); -ETreeModel *e_tree_model_new (void); - -/* tree traversal operations */ -ETreePath *e_tree_model_get_root (ETreeModel *etree); -ETreePath *e_tree_model_node_get_parent (ETreeModel *etree, ETreePath *path); -ETreePath *e_tree_model_node_get_next (ETreeModel *etree, ETreePath *path); -ETreePath *e_tree_model_node_get_prev (ETreeModel *etree, ETreePath *path); - -/* node operations */ -ETreePath *e_tree_model_node_insert (ETreeModel *etree, ETreePath *parent, int position, gpointer node_data); -ETreePath *e_tree_model_node_insert_before (ETreeModel *etree, ETreePath *parent, ETreePath *sibling, gpointer node_data); -gpointer e_tree_model_node_remove (ETreeModel *etree, ETreePath *path); - -/* node accessors */ -gboolean e_tree_model_node_is_root (ETreeModel *etree, ETreePath *path); -gboolean e_tree_model_node_is_expandable (ETreeModel *etree, ETreePath *path); -gboolean e_tree_model_node_is_expanded (ETreeModel *etree, ETreePath *path); -gboolean e_tree_model_node_is_visible (ETreeModel *etree, ETreePath *path); -void e_tree_model_node_set_expanded (ETreeModel *etree, ETreePath *path, gboolean expanded); -void e_tree_model_node_set_expanded_recurse (ETreeModel *etree, ETreePath *path, gboolean expanded); -guint e_tree_model_node_get_children (ETreeModel *etree, ETreePath *path, ETreePath ***paths); -guint e_tree_model_node_depth (ETreeModel *etree, ETreePath *path); -guint e_tree_model_node_num_visible_descendents (ETreeModel *etm, ETreePath *node); -gpointer e_tree_model_node_get_data (ETreeModel *etm, ETreePath *node); -void e_tree_model_node_set_data (ETreeModel *etm, ETreePath *node, gpointer node_data); - -/* display oriented routines */ -ETreePath *e_tree_model_node_at_row (ETreeModel *etree, int row); -GdkPixbuf *e_tree_model_icon_of_node (ETreeModel *etree, ETreePath *path); -int e_tree_model_row_of_node (ETreeModel *etree, ETreePath *path); -void e_tree_model_root_node_set_visible (ETreeModel *etree, gboolean visible); -gboolean e_tree_model_root_node_is_visible (ETreeModel *etree); - -/* sort routine, analogous to gtk_ctree_node_sort */ -void e_tree_model_node_sort (ETreeModel *tree_model, ETreePath *node, GCompareFunc compare); - -/* -** Routines for emitting signals on the ETreeModel -*/ -void e_tree_model_node_changed (ETreeModel *tree_model, ETreePath *node); -void e_tree_model_node_inserted (ETreeModel *tree_model, ETreePath *parent_node, ETreePath *inserted_node); -void e_tree_model_node_removed (ETreeModel *tree_model, ETreePath *parent_node, ETreePath *removed_node); - -#endif /* _E_TREE_MODEL_H */ diff --git a/widgets/table/e-tree-simple.c b/widgets/table/e-tree-simple.c deleted file mode 100644 index e5883e6ae0..0000000000 --- a/widgets/table/e-tree-simple.c +++ /dev/null @@ -1,84 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-tree-simple.c: a Tree Model that offers a function pointer - * interface to using ETreeModel, similar to ETableSimple. - * - * Author: - * Chris Toshok (toshok@helixcode.com) - * - * (C) 2000 Helix Code, Inc. */ - -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-util/e-util.h" -#include "e-tree-simple.h" - -#define PARENT_TYPE E_TREE_MODEL_TYPE - -static void * -simple_value_at (ETreeModel *etm, ETreePath *node, int col) -{ - ETreeSimple *simple = E_TREE_SIMPLE(etm); - - return simple->value_at (etm, node, col, simple->model_data); -} - -static GdkPixbuf * -simple_icon_at (ETreeModel *etm, ETreePath *node) -{ - ETreeSimple *simple = E_TREE_SIMPLE(etm); - - return simple->icon_at (etm, node, simple->model_data); -} - -static void -simple_set_value_at (ETreeModel *etm, ETreePath *node, int col, const void *val) -{ - ETreeSimple *simple = E_TREE_SIMPLE(etm); - - simple->set_value_at (etm, node, col, val, simple->model_data); -} - -static gboolean -simple_is_editable (ETreeModel *etm, ETreePath *node, int col) -{ - ETreeSimple *simple = E_TREE_SIMPLE(etm); - - return simple->is_editable (etm, node, col, simple->model_data); -} - -static void -e_tree_simple_class_init (GtkObjectClass *object_class) -{ - ETreeModelClass *model_class = (ETreeModelClass *) object_class; - - model_class->icon_at = simple_icon_at; - model_class->value_at = simple_value_at; - model_class->set_value_at = simple_set_value_at; - model_class->is_editable = simple_is_editable; -} - -E_MAKE_TYPE(e_tree_simple, "ETreeSimple", ETreeSimple, e_tree_simple_class_init, NULL, PARENT_TYPE) - -ETreeModel * -e_tree_simple_new (ETreeSimpleIconAtFn icon_at, - ETreeSimpleValueAtFn value_at, - ETreeSimpleSetValueAtFn set_value_at, - ETreeSimpleIsEditableFn is_editable, - gpointer model_data) -{ - ETreeSimple *etg; - - etg = gtk_type_new (e_tree_simple_get_type ()); - - e_tree_model_construct (E_TREE_MODEL (etg)); - - etg->icon_at = icon_at; - etg->value_at = value_at; - etg->set_value_at = set_value_at; - etg->is_editable = is_editable; - etg->model_data = model_data; - - return (ETreeModel*)etg; -} - diff --git a/widgets/table/e-tree-simple.h b/widgets/table/e-tree-simple.h deleted file mode 100644 index edda53e82d..0000000000 --- a/widgets/table/e-tree-simple.h +++ /dev/null @@ -1,43 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -#ifndef _E_TREE_SIMPLE_H_ -#define _E_TREE_SIMPLE_H_ - -#include "e-tree-model.h" - -#define E_TREE_SIMPLE_TYPE (e_tree_simple_get_type ()) -#define E_TREE_SIMPLE(o) (GTK_CHECK_CAST ((o), E_TREE_SIMPLE_TYPE, ETreeSimple)) -#define E_TREE_SIMPLE_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_TREE_SIMPLE_TYPE, ETreeSimpleClass)) -#define E_IS_TREE_SIMPLE(o) (GTK_CHECK_TYPE ((o), E_TREE_SIMPLE_TYPE)) -#define E_IS_TREE_SIMPLE_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_TREE_SIMPLE_TYPE)) - - -typedef GdkPixbuf* (*ETreeSimpleIconAtFn) (ETreeModel *etree, ETreePath *path, void *model_data); -typedef void* (*ETreeSimpleValueAtFn) (ETreeModel *etree, ETreePath *path, int col, void *model_data); -typedef void (*ETreeSimpleSetValueAtFn) (ETreeModel *etree, ETreePath *path, int col, const void *val, void *model_data); -typedef gboolean (*ETreeSimpleIsEditableFn) (ETreeModel *etree, ETreePath *path, int col, void *model_data); - -typedef struct { - ETreeModel parent; - - ETreeSimpleIconAtFn icon_at; - ETreeSimpleValueAtFn value_at; - ETreeSimpleSetValueAtFn set_value_at; - ETreeSimpleIsEditableFn is_editable; - - gpointer model_data; -} ETreeSimple; - -typedef struct { - ETreeModelClass parent_class; -} ETreeSimpleClass; - -GtkType e_tree_simple_get_type (void); - -ETreeModel *e_tree_simple_new (ETreeSimpleIconAtFn icon_at, - ETreeSimpleValueAtFn value_at, - ETreeSimpleSetValueAtFn set_value_at, - ETreeSimpleIsEditableFn is_editable, - gpointer model_data); - -#endif /* _E_TREE_SIMPLE_H_ */ diff --git a/widgets/table/image1.png b/widgets/table/image1.png Binary files differdeleted file mode 100644 index 8326ac241f..0000000000 --- a/widgets/table/image1.png +++ /dev/null diff --git a/widgets/table/image2.png b/widgets/table/image2.png Binary files differdeleted file mode 100644 index e6a4c75dbe..0000000000 --- a/widgets/table/image2.png +++ /dev/null diff --git a/widgets/table/image3.png b/widgets/table/image3.png Binary files differdeleted file mode 100644 index 50e16e8620..0000000000 --- a/widgets/table/image3.png +++ /dev/null diff --git a/widgets/table/remove-col.xpm b/widgets/table/remove-col.xpm deleted file mode 100644 index ff1024f0c9..0000000000 --- a/widgets/table/remove-col.xpm +++ /dev/null @@ -1,22 +0,0 @@ -/* XPM */ -static char * remove_col_xpm[] = { -"16 16 3 1", -" c None", -". c #000000", -"+ c #FF0000", -"... ...", -".++. .++.", -".+++. .+++.", -" .+++. .+++. ", -" .+++. .+++. ", -" .+++..+++. ", -" .++++++. ", -" .++++. ", -" .++++. ", -" .++++++. ", -" .+++..+++. ", -" .+++. .+++. ", -" .+++. .+++. ", -".+++. .+++.", -".++. .++.", -"... ..."}; diff --git a/widgets/table/sample.table b/widgets/table/sample.table deleted file mode 100644 index 45c8ff0691..0000000000 --- a/widgets/table/sample.table +++ /dev/null @@ -1,11 +0,0 @@ -Col1 Col2 Address Title Dorks -c1.a c2.a a.a tit-1 DorkA -c1.b c2.b a.b tit-2 DDork -c1.c c2.c a.c tit-1 DorkB -c1.d c2.d a.d tit-2 ADork -c1.e c2.e a.e tit-1 DorkC -c1.f c2.f a.f tit-2 UDork -c1.g c2.g a.g tit-3 Dork--- -j k k tit-1 DorkA - - diff --git a/widgets/table/table-test.c b/widgets/table/table-test.c deleted file mode 100644 index 62160e7035..0000000000 --- a/widgets/table/table-test.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include <config.h> -#include <stdio.h> -#include <string.h> -#include <fcntl.h> -#include <gnome.h> -#include "e-util/e-cursors.h" -#include "table-test.h" - -int -main (int argc, char *argv []) -{ - - if (isatty (0)){ - int fd; - - close (0); - fd = open ("sample.table", O_RDONLY); - if (fd == -1){ - fprintf (stderr, "Could not find sample.table, try feeding a table on stdin"); - exit (1); - } - dup2 (fd, 0); - } - - gnome_init ("TableTest", "TableTest", argc, argv); - e_cursors_init (); - - - table_browser_test (); - multi_cols_test (); - check_test (); - - e_table_test (); - - gtk_main (); - - e_cursors_shutdown (); - return 0; -} diff --git a/widgets/table/table-test.h b/widgets/table/table-test.h deleted file mode 100644 index ad8cfcc083..0000000000 --- a/widgets/table/table-test.h +++ /dev/null @@ -1,4 +0,0 @@ -void table_browser_test (void); -void multi_cols_test (void); -void check_test (void); -void e_table_test (void); diff --git a/widgets/table/test-check.c b/widgets/table/test-check.c deleted file mode 100644 index 3bb022821e..0000000000 --- a/widgets/table/test-check.c +++ /dev/null @@ -1,206 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include <config.h> -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-util/e-cursors.h" -#include "e-util/e-canvas-utils.h" -#include "e-util/e-canvas.h" -#include "e-util/e-util.h" -#include "e-cell-text.h" -#include "e-cell-checkbox.h" - -#include "table-test.h" - -#define LINES 4 - -static struct { - int value; - char *string; -} my_table [LINES] = { - { 0, "Buy food" }, - { 1, "Breathe " }, - { 0, "Cancel gdb session with shrink" }, - { 1, "Make screenshots" }, -}; -/* - * ETableSimple callbacks - */ -static int -col_count (ETableModel *etc, void *data) -{ - return 2; -} - -static int -row_count (ETableModel *etc, void *data) -{ - return LINES; -} - -static void * -value_at (ETableModel *etc, int col, int row, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0) - return GINT_TO_POINTER (my_table [row].value); - else - return my_table [row].string; - -} - -static void -set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0) { - my_table [row].value = GPOINTER_TO_INT (val); - printf ("Value at %d,%d set to %d\n", col, row, GPOINTER_TO_INT (val)); - } else { - my_table [row].string = g_strdup (val); - printf ("Value at %d,%d set to %s\n", col, row, (char *) val); - } -} - -static gboolean -is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -static void * -duplicate_value (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == 0) { - return (void *) value; - } else { - return g_strdup (value); - } -} - -static void -free_value (ETableModel *etc, int col, void *value, void *data) -{ - if (col != 0) { - g_free (value); - } -} - -static void * -initialize_value (ETableModel *etc, int col, void *data) -{ - if (col == 0) - return NULL; - else - return g_strdup (""); -} - -static gboolean -value_is_empty (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == 0) - return value == NULL; - else - return !(value && *(char *)value); -} - -static char * -value_to_string (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == 0) - return g_strdup_printf("%d", (int) value); - else - return g_strdup(value); -} - -static void -set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) -{ - gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); -} - -void -check_test (void) -{ - GtkWidget *canvas, *window; - ETableModel *e_table_model; - ETableHeader *e_table_header; - ETableCol *col_0, *col_1; - ECell *cell_left_just, *cell_image_check; - GdkPixbuf *pixbuf; - GnomeCanvasItem *item; - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - e_table_model = e_table_simple_new ( - col_count, row_count, value_at, - set_value_at, is_cell_editable, - duplicate_value, free_value, - initialize_value, value_is_empty, - value_to_string, - NULL); - - /* - * Header - */ - e_table_header = e_table_header_new (); - - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - cell_image_check = e_cell_checkbox_new (); - pixbuf = gdk_pixbuf_new_from_file ("clip.png"); - col_0 = e_table_col_new_with_pixbuf (0, pixbuf, 0.0, 18, cell_image_check, g_int_compare, TRUE); - gdk_pixbuf_unref (pixbuf); - e_table_header_add_column (e_table_header, col_0, 0); - - col_1 = e_table_col_new (1, "Item Name", 1.0, 20, cell_left_just, g_str_compare, TRUE); - e_table_header_add_column (e_table_header, col_1, 1); - e_table_col_set_arrow (col_1, E_TABLE_COL_ARROW_DOWN); - - /* - * GUI - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - canvas = e_canvas_new (); - - gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate", - GTK_SIGNAL_FUNC (set_canvas_size), NULL); - - gtk_container_add (GTK_CONTAINER (window), canvas); - gtk_widget_show_all (window); - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header, - NULL); - - item = gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_item_get_type (), - "ETableHeader", e_table_header, - "ETableModel", e_table_model, - "drawgrid", TRUE, - "drawfocus", TRUE, -#if 0 - "spreadsheet", TRUE, -#endif - "cursor_mode", E_TABLE_CURSOR_SIMPLE, - NULL); - e_canvas_item_move_absolute (item, 0, 30); -} - diff --git a/widgets/table/test-cols.c b/widgets/table/test-cols.c deleted file mode 100644 index c47a1d47d7..0000000000 --- a/widgets/table/test-cols.c +++ /dev/null @@ -1,250 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include <config.h> -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "e-util/e-canvas-utils.h" -#include "e-util/e-canvas.h" -#include "e-util/e-cursors.h" -#include "e-util/e-util.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-cell-toggle.h" - -#include "table-test.h" - -#define LINES 4 - -static struct { - int value; - char *string; -} my_table [LINES] = { - { 0, "You are not" }, - { 1, "A beautiful and unique " }, - { 0, "Snowflake" }, - { 2, "You are not your wallet" }, -}; -/* - * ETableSimple callbacks - */ -static int -col_count (ETableModel *etc, void *data) -{ - return 2; -} - -static int -row_count (ETableModel *etc, void *data) -{ - return LINES; -} - -static void * -value_at (ETableModel *etc, int col, int row, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0) - return GINT_TO_POINTER (my_table [row].value); - else - return my_table [row].string; - -} - -static void -set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_assert (col < 2); - g_assert (row < LINES); - - if (col == 0){ - my_table [row].value = GPOINTER_TO_INT (val); - printf ("Value at %d,%d set to %d\n", col, row, GPOINTER_TO_INT (val)); - } else { - my_table [row].string = g_strdup (val); - printf ("Value at %d,%d set to %s\n", col, row, (char *) val); - } -} - -static gboolean -is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -static void * -duplicate_value (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == 0){ - return (void *)value; - } else { - return g_strdup (value); - } -} - -static void -free_value (ETableModel *etc, int col, void *value, void *data) -{ - if (col != 0){ - g_free (value); - } -} - -static void * -initialize_value (ETableModel *etc, int col, void *data) -{ - if (col == 0) - return NULL; - else - return g_strdup (""); -} - -static gboolean -value_is_empty (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == 0) - return value == NULL; - else - return !(value && *(char *)value); -} - -static char * -value_to_string (ETableModel *etc, int col, const void *value, void *data) -{ - if (col == 0) - return g_strdup_printf("%d", (int) value); - else - return g_strdup(value); -} - -static void -set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) -{ - gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); -} - -void -multi_cols_test (void) -{ - GtkWidget *canvas, *window; - ETableModel *e_table_model; - ETableHeader *e_table_header, *e_table_header_multiple; - ETableCol *col_0, *col_1; - ECell *cell_left_just, *cell_image_toggle; - GnomeCanvasItem *item; - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - - e_table_model = e_table_simple_new ( - col_count, row_count, value_at, - set_value_at, is_cell_editable, - duplicate_value, free_value, - initialize_value, value_is_empty, - value_to_string, - NULL); - - /* - * Header - */ - e_table_header = e_table_header_new (); - - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - { - GdkPixbuf **images = g_new (GdkPixbuf *, 3); - int i; - - images [0] = gdk_pixbuf_new_from_file ("image1.png"); - images [1] = gdk_pixbuf_new_from_file ("image2.png"); - images [2] = gdk_pixbuf_new_from_file ("image3.png"); - - cell_image_toggle = e_cell_toggle_new (0, 3, images); - - for (i = 0; i < 3; i++) - gdk_pixbuf_unref (images [i]); - - g_free (images); - } - - col_1 = e_table_col_new (1, "Item Name", 1.0, 20, cell_left_just, g_str_compare, TRUE); - e_table_header_add_column (e_table_header, col_1, 0); - - col_0 = e_table_col_new (0, "A", 0.0, 48, cell_image_toggle, g_int_compare, TRUE); - e_table_header_add_column (e_table_header, col_0, 1); - - /* - * Second test - */ - e_table_header_multiple = e_table_header_new (); - e_table_header_add_column (e_table_header_multiple, col_0, 0); - e_table_header_add_column (e_table_header_multiple, col_1, 1); - e_table_header_add_column (e_table_header_multiple, col_1, 2); - - /* - * GUI - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - canvas = e_canvas_new (); - - gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate", - GTK_SIGNAL_FUNC (set_canvas_size), NULL); - - gtk_container_add (GTK_CONTAINER (window), canvas); - gtk_widget_show_all (window); - - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header, - NULL); - - item = gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_item_get_type (), - "ETableHeader", e_table_header, - "ETableModel", e_table_model, - "drawgrid", TRUE, - "drawfocus", TRUE, - "cursor_mode", E_TABLE_CURSOR_SIMPLE, -#if 0 - "spreadsheet", TRUE, -#endif - NULL); - - e_canvas_item_move_absolute (item, 0, 30); - - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header_multiple, - NULL); - item = gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_item_get_type (), - "ETableHeader", e_table_header_multiple, - "ETableModel", e_table_model, - "drawgrid", TRUE, - "drawfocus", TRUE, -#if 0 - "spreadsheet", TRUE, -#endif - "cursor_mode", E_TABLE_CURSOR_SIMPLE, - NULL); - e_canvas_item_move_absolute (item, 300, 30); -} - - - - - diff --git a/widgets/table/test-table.c b/widgets/table/test-table.c deleted file mode 100644 index b30b412f08..0000000000 --- a/widgets/table/test-table.c +++ /dev/null @@ -1,394 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Test code for the ETable package - * - * Author: - * Miguel de Icaza (miguel@gnu.org) - */ -#include <config.h> -#include <stdio.h> -#include <string.h> -#include <gnome.h> -#include "e-util/e-cursors.h" -#include "e-util/e-canvas.h" -#include "e-table-simple.h" -#include "e-table-header.h" -#include "e-table-header-item.h" -#include "e-table-item.h" -#include "e-cell-text.h" -#include "e-table.h" -#include "e-table-config.h" - -#include "table-test.h" - -char buffer [1024]; -char **column_labels; -char ***table_data; -int cols = 0; -int lines = 0; -int lines_alloc = 0; - -static void -parse_headers () -{ - char *p, *s; - int in_value = 0, i; - - fgets (buffer, sizeof (buffer)-1, stdin); - - for (p = buffer; *p; p++){ - if (*p == ' ' || *p == '\t'){ - if (in_value){ - cols++; - in_value = 0; - } - } else - in_value = 1; - } - if (in_value) - cols++; - - if (!cols){ - fprintf (stderr, "No columns in first row\n"); - exit (1); - } - - column_labels = g_new0 (char *, cols); - - p = buffer; - for (i = 0; (s = strtok (p, " \t")) != NULL; i++){ - column_labels [i] = g_strdup (s); - if (strchr (column_labels [i], '\n')) - *strchr (column_labels [i], '\n') = 0; - p = NULL; - } - - printf ("%d headers:\n", cols); - for (i = 0; i < cols; i++){ - printf ("header %d: %s\n", i, column_labels [i]); - } -} - -static char ** -load_line (char *buffer, int cols) -{ - char **line = g_new0 (char *, cols); - char *p; - int i; - - for (i = 0; i < cols; i++){ - p = strtok (buffer, " \t\n"); - if (p == NULL){ - for (; i < cols; i++) - line [i] = g_strdup (""); - return line; - } else - line [i] = g_strdup (p); - buffer = NULL; - } - return line; -} - -static void -append_line (char **line) -{ - if (lines <= lines_alloc){ - lines_alloc = lines + 50; - table_data = g_renew (char **, table_data, lines_alloc); - } - table_data [lines] = line; - lines++; -} - -static void -load_data () -{ - int i; - - { - static int loaded; - - if (loaded) - return; - - loaded = TRUE; - } - - - parse_headers (); - - while (fgets (buffer, sizeof (buffer)-1, stdin) != NULL){ - char **line; - - if (buffer [0] == '\n') - continue; - line = load_line (buffer, cols); - append_line (line); - } - - for (i = 0; i < lines; i++){ - int j; - - printf ("Line %d: ", i); - for (j = 0; j < cols; j++) - printf ("[%s] ", table_data [i][j]); - printf ("\n"); - } -} - -/* - * ETableSimple callbacks - */ -static int -col_count (ETableModel *etc, void *data) -{ - return cols; -} - -static int -row_count (ETableModel *etc, void *data) -{ - return lines; -} - -static void * -value_at (ETableModel *etc, int col, int row, void *data) -{ - g_assert (col < cols); - g_assert (row < lines); - - return (void *) table_data [row][col]; -} - -static void -set_value_at (ETableModel *etc, int col, int row, const void *val, void *data) -{ - g_assert (col < cols); - g_assert (row < lines); - - g_free (table_data [row][col]); - table_data [row][col] = g_strdup (val); - - printf ("Value at %d,%d set to %s\n", col, row, (char *) val); -} - -static gboolean -is_cell_editable (ETableModel *etc, int col, int row, void *data) -{ - return TRUE; -} - -static void * -duplicate_value (ETableModel *etc, int col, const void *value, void *data) -{ - return g_strdup (value); -} - -static void -free_value (ETableModel *etc, int col, void *value, void *data) -{ - g_free (value); -} - -static void * -initialize_value (ETableModel *etc, int col, void *data) -{ - return g_strdup (""); -} - -static gboolean -value_is_empty (ETableModel *etc, int col, const void *value, void *data) -{ - return !(value && *(char *)value); -} - -static char * -value_to_string (ETableModel *etc, int col, const void *value, void *data) -{ - return g_strdup(value); -} - -static void -set_canvas_size (GnomeCanvas *canvas, GtkAllocation *alloc) -{ - gnome_canvas_set_scroll_region (canvas, 0, 0, alloc->width, alloc->height); -} - -void -table_browser_test (void) -{ - GtkWidget *canvas, *window; - ETableModel *e_table_model; - ETableHeader *e_table_header; - ECell *cell_left_just; - GnomeCanvasItem *group; - int i; - - load_data (); - - /* - * Data model - */ - e_table_model = e_table_simple_new ( - col_count, row_count, value_at, - set_value_at, is_cell_editable, - duplicate_value, free_value, - initialize_value, value_is_empty, - value_to_string, - NULL); - - /* - * Header - */ - e_table_header = e_table_header_new (); - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - for (i = 0; i < cols; i++){ - ETableCol *ecol = e_table_col_new ( - i, column_labels [i], - 1.0, 20, cell_left_just, - g_str_compare, TRUE); - - e_table_header_add_column (e_table_header, ecol, i); - } - - /* - * Setup GUI - */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - canvas = e_canvas_new (); - - gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate", - GTK_SIGNAL_FUNC (set_canvas_size), NULL); - - gtk_container_add (GTK_CONTAINER (window), canvas); - gtk_widget_show_all (window); - gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - e_table_header_item_get_type (), - "ETableHeader", e_table_header, - NULL); - - group = gnome_canvas_item_new ( - gnome_canvas_root (GNOME_CANVAS (canvas)), - gnome_canvas_group_get_type (), - "x", 30.0, - "y", 30.0, - NULL); - - gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (group), - e_table_item_get_type (), - "ETableHeader", e_table_header, - "ETableModel", e_table_model, - "drawgrid", TRUE, - "drawfocus", TRUE, -#if 0 - "spreadsheet", TRUE, -#endif - NULL); -} - -static void -save_spec (GtkWidget *button, ETable *e_table) -{ - e_table_save_specification (e_table, "e-table-test.xml"); -} - -static void -row_selection_test (ETable *table, int row, gboolean selected) -{ - if (selected) - g_print ("Row %d selected\n", row); - else - g_print ("Row %d unselected\n", row); -} - -static void -toggle_grid (void *nothing, ETable *etable) -{ - static gboolean shown; - - gtk_object_get (GTK_OBJECT (etable), "drawgrid", &shown, NULL); - gtk_object_set (GTK_OBJECT (etable), "drawgrid", !shown, NULL); -} - -static void -do_e_table_demo (const char *spec) -{ - GtkWidget *e_table, *window, *frame, *vbox, *button, *bhide; - ECell *cell_left_just; - ETableHeader *full_header; - int i; - - /* - * Data model - */ - static ETableModel *e_table_model = NULL; - - if (e_table_model == NULL) - e_table_model = - e_table_simple_new (col_count, row_count, value_at, - set_value_at, is_cell_editable, - duplicate_value, free_value, - initialize_value, value_is_empty, - value_to_string, - NULL); - - full_header = e_table_header_new (); - cell_left_just = e_cell_text_new (e_table_model, NULL, GTK_JUSTIFY_LEFT); - - for (i = 0; i < cols; i++){ - ETableCol *ecol = e_table_col_new ( - i, column_labels [i], - 1.0, 20, cell_left_just, - g_str_compare, TRUE); - - e_table_header_add_column (full_header, ecol, i); - } - - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - frame = gtk_frame_new (NULL); - e_table = e_table_new (full_header, e_table_model, spec); - gtk_signal_connect (GTK_OBJECT(e_table), "row_selection", - GTK_SIGNAL_FUNC(row_selection_test), NULL); - - vbox = gtk_vbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), e_table, TRUE, TRUE, 0); - gtk_container_add (GTK_CONTAINER (frame), vbox); - gtk_container_add (GTK_CONTAINER (window), frame); - - /* - * gadgets - */ - button = gtk_button_new_with_label ("Save spec"); - gtk_signal_connect (GTK_OBJECT (button), "clicked", - GTK_SIGNAL_FUNC (save_spec), e_table); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); - - bhide = gtk_button_new_with_label ("Toggle Grid"); - gtk_signal_connect (GTK_OBJECT (bhide), "clicked", - GTK_SIGNAL_FUNC (toggle_grid), e_table); - gtk_box_pack_start (GTK_BOX (vbox), bhide, FALSE, FALSE, 0); - - gtk_widget_set_usize (window, 200, 200); - gtk_widget_show_all (window); - - if (getenv ("TEST")){ - e_table_do_gui_config (NULL, E_TABLE(e_table)); - } -} - -void -e_table_test (void) -{ - load_data (); - - if (1){/*getenv ("DO")){*/ - do_e_table_demo ("<ETableSpecification> <columns-shown> <column> 0 </column> <column> 1 </column> <column> 2 </column> <column> 3 </column> <column> 4 </column> </columns-shown> <grouping> <leaf column=\"3\" ascending=\"1\"/> </grouping> </ETableSpecification>"); - do_e_table_demo ("<ETableSpecification> <columns-shown> <column> 0 </column> <column> 0 </column> <column> 1 </column> <column> 2 </column> <column> 3 </column> <column> 4 </column> </columns-shown> <grouping> <group column=\"3\" ascending=\"1\"> <group column=\"4\" ascending=\"0\"> <leaf column=\"2\" ascending=\"1\"/> </group> </group> </grouping> </ETableSpecification>"); - } - do_e_table_demo ("<ETableSpecification> <columns-shown> <column> 0 </column> <column> 1 </column> <column> 2 </column> <column> 3 </column> <column> 4 </column> </columns-shown> <grouping> <group column=\"4\" ascending=\"1\"> <leaf column=\"2\" ascending=\"1\"/> </group> </grouping> </ETableSpecification>"); - do_e_table_demo ("<ETableSpecification> <columns-shown> <column> 0 </column> <column> 1 </column> <column> 2 </column> <column> 3 </column> <column> 4 </column> </columns-shown> <grouping> <group column=\"3\" ascending=\"1\"> <leaf column=\"2\" ascending=\"1\"/> </group> </grouping> </ETableSpecification>"); -} diff --git a/widgets/table/tree-expanded.xpm b/widgets/table/tree-expanded.xpm deleted file mode 100644 index fc748953eb..0000000000 --- a/widgets/table/tree-expanded.xpm +++ /dev/null @@ -1,22 +0,0 @@ -/* XPM */ -static char * tree_expanded_xpm[] = { -"16 16 3 1", -" c None", -". c #000000", -"+ c #FFFFFF", -" ", -" ", -" ", -" ", -" ......... ", -" .+++++++. ", -" .+++++++. ", -" .+++++++. ", -" .+.....+. ", -" .+++++++. ", -" .+++++++. ", -" .+++++++. ", -" ......... ", -" ", -" ", -" "}; diff --git a/widgets/table/tree-unexpanded.xpm b/widgets/table/tree-unexpanded.xpm deleted file mode 100644 index 0dfb12a0a5..0000000000 --- a/widgets/table/tree-unexpanded.xpm +++ /dev/null @@ -1,22 +0,0 @@ -/* XPM */ -static char * tree_unexpanded_xpm[] = { -"16 16 3 1", -" c None", -". c #000000", -"+ c #FFFFFF", -" ", -" ", -" ", -" ", -" ......... ", -" .+++++++. ", -" .+++.+++. ", -" .+++.+++. ", -" .+.....+. ", -" .+++.+++. ", -" .+++.+++. ", -" .+++++++. ", -" ......... ", -" ", -" ", -" "}; diff --git a/widgets/text/.cvsignore b/widgets/text/.cvsignore deleted file mode 100644 index ab703bd5e1..0000000000 --- a/widgets/text/.cvsignore +++ /dev/null @@ -1,9 +0,0 @@ -.deps -.libs -.pure -Makefile -Makefile.in -*.lo -*.la -e-text-test -e-entry-test diff --git a/widgets/text/e-entry-test.c b/widgets/text/e-entry-test.c deleted file mode 100644 index 411e8d693c..0000000000 --- a/widgets/text/e-entry-test.c +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* test-minicard.c - * - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - */ - - - -#include "config.h" - -#include <gnome.h> -#include "e-entry.h" - -static void destroy_callback(GtkWidget *app, gpointer data) -{ - exit(0); -} - -#if 0 -static void about_callback( GtkWidget *widget, gpointer data ) -{ - - const gchar *authors[] = - { - "Christopher James Lahey <clahey@umich.edu>", - NULL - }; - - GtkWidget *about = - gnome_about_new ( _( "Minicard Test" ), VERSION, - _( "Copyright (C) 2000, Helix Code, Inc." ), - authors, - _( "This should test the minicard canvas item" ), - NULL); - gtk_widget_show (about); -} -#endif - -int main( int argc, char *argv[] ) -{ - GtkWidget *app; - GtkWidget *entry; - - /* bindtextdomain (PACKAGE, GNOMELOCALEDIR); - textdomain (PACKAGE);*/ - - gnome_init( "EEntry Test", VERSION, argc, argv); - app = gnome_app_new("EEntry Test", NULL); - - entry = e_entry_new(); - gtk_object_set(GTK_OBJECT(entry), - "editable", TRUE, - "use_ellipsis", TRUE, - NULL); - gnome_app_set_contents( GNOME_APP( app ), entry ); - - /* Connect the signals */ - gtk_signal_connect( GTK_OBJECT( app ), "destroy", - GTK_SIGNAL_FUNC( destroy_callback ), - ( gpointer ) app ); - - gtk_widget_show_all( app ); - - gtk_main(); - - /* Not reached. */ - return 0; -} diff --git a/widgets/text/e-entry.c b/widgets/text/e-entry.c deleted file mode 100644 index cbde382c93..0000000000 --- a/widgets/text/e-entry.c +++ /dev/null @@ -1,408 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-table.c: A graphical view of a Table. - * - * Author: - * Miguel de Icaza (miguel@helixcode.com) - * Chris Lahey (clahey@helixcode.com) - * - * Copyright 1999, Helix Code, Inc - */ -#include <config.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#ifdef HAVE_ALLOCA_H -#include <alloca.h> -#endif -#include <stdio.h> -#include <libgnomeui/gnome-canvas.h> -#include <gtk/gtksignal.h> -#include <gnome-xml/parser.h> -#include "e-util/e-util.h" -#include "e-util/e-canvas.h" -#include "e-entry.h" -#include "e-util/e-canvas-utils.h" - -#define MIN_ENTRY_WIDTH 150 -#define INNER_BORDER 2 - -#define PARENT_TYPE gtk_table_get_type () - -static GtkObjectClass *parent_class; - -enum { - E_ENTRY_CHANGED, - E_ENTRY_ACTIVATE, - E_ENTRY_LAST_SIGNAL -}; - -static guint e_entry_signals[E_ENTRY_LAST_SIGNAL] = { 0 }; - -/* Object argument IDs */ -enum { - ARG_0, - ARG_MODEL, - ARG_EVENT_PROCESSOR, - ARG_TEXT, - ARG_FONT, - ARG_FONTSET, - ARG_FONT_GDK, - ARG_ANCHOR, - ARG_JUSTIFICATION, - ARG_X_OFFSET, - ARG_Y_OFFSET, - ARG_FILL_COLOR, - ARG_FILL_COLOR_GDK, - ARG_FILL_COLOR_RGBA, - ARG_FILL_STIPPLE, - ARG_EDITABLE, - ARG_USE_ELLIPSIS, - ARG_ELLIPSIS, - ARG_LINE_WRAP, - ARG_BREAK_CHARACTERS, - ARG_MAX_LINES, - ARG_WIDTH, - ARG_HEIGHT -}; - -static void -canvas_size_allocate (GtkWidget *widget, GtkAllocation *alloc, - EEntry *e_entry) -{ - gnome_canvas_set_scroll_region ( - e_entry->canvas, - 0, 0, alloc->width, alloc->height); - gtk_object_set (GTK_OBJECT (e_entry->item), - "clip_width", (double) alloc->width, - "clip_height", (double) alloc->height, - NULL); -} - -static void -canvas_size_request (GtkWidget *widget, GtkRequisition *requisition, - EEntry *e_entry) -{ - g_return_if_fail (widget != NULL); - g_return_if_fail (GNOME_IS_CANVAS (widget)); - g_return_if_fail (requisition != NULL); - - requisition->width = MIN_ENTRY_WIDTH + (widget->style->klass->xthickness + INNER_BORDER) * 2; - requisition->height = (widget->style->font->ascent + - widget->style->font->descent + - (widget->style->klass->ythickness + INNER_BORDER) * 2); -} - -static void -e_entry_init (GtkObject *object) -{ - EEntry *e_entry = E_ENTRY (object); - GtkTable *gtk_table = GTK_TABLE (object); - - e_entry->canvas = GNOME_CANVAS(e_canvas_new()); - gtk_signal_connect(GTK_OBJECT(e_entry->canvas), "size_allocate", - GTK_SIGNAL_FUNC(canvas_size_allocate), e_entry); - gtk_signal_connect(GTK_OBJECT(e_entry->canvas), "size_request", - GTK_SIGNAL_FUNC(canvas_size_request), e_entry); - e_entry->item = E_TEXT(gnome_canvas_item_new(gnome_canvas_root(e_entry->canvas), - e_text_get_type(), - "clip", TRUE, - "fill_clip_rectangle", TRUE, - "anchor", GTK_ANCHOR_NW, - "draw_borders", TRUE, - NULL)); - - gtk_table_attach_defaults(gtk_table, GTK_WIDGET(e_entry->canvas), - 0, 1, 0, 1); - gtk_widget_show(GTK_WIDGET(e_entry->canvas)); -} - -EEntry * -e_entry_construct (EEntry *e_entry) -{ - return e_entry; -} - -GtkWidget * -e_entry_new (void) -{ - EEntry *e_entry; - e_entry = gtk_type_new (e_entry_get_type ()); - e_entry = e_entry_construct (e_entry); - - return GTK_WIDGET (e_entry); -} - -static void -et_get_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - EEntry *ee = E_ENTRY (o); - - switch (arg_id){ - case ARG_MODEL: - gtk_object_get(GTK_OBJECT(ee->item), - "model", >K_VALUE_OBJECT (*arg), - NULL); - break; - - case ARG_EVENT_PROCESSOR: - gtk_object_get(GTK_OBJECT(ee->item), - "event_processor", >K_VALUE_OBJECT (*arg), - NULL); - break; - - case ARG_TEXT: - gtk_object_get(GTK_OBJECT(ee->item), - "text", >K_VALUE_STRING (*arg), - NULL); - break; - - case ARG_FONT_GDK: - gtk_object_get(GTK_OBJECT(ee->item), - "font_gdk", >K_VALUE_BOXED (*arg), - NULL); - break; - - case ARG_JUSTIFICATION: - gtk_object_get(GTK_OBJECT(ee->item), - "justification", >K_VALUE_ENUM (*arg), - NULL); - break; - - case ARG_FILL_COLOR_GDK: - gtk_object_get(GTK_OBJECT(ee->item), - "fill_color_gdk", >K_VALUE_BOXED (*arg), - NULL); - break; - - case ARG_FILL_COLOR_RGBA: - gtk_object_get(GTK_OBJECT(ee->item), - "fill_color_rgba", >K_VALUE_UINT (*arg), - NULL); - break; - - case ARG_FILL_STIPPLE: - gtk_object_get(GTK_OBJECT(ee->item), - "fill_stiple", >K_VALUE_BOXED (*arg), - NULL); - break; - - case ARG_EDITABLE: - gtk_object_get(GTK_OBJECT(ee->item), - "editable", >K_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_USE_ELLIPSIS: - gtk_object_get(GTK_OBJECT(ee->item), - "use_ellipsis", >K_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_ELLIPSIS: - gtk_object_get(GTK_OBJECT(ee->item), - "ellipsis", >K_VALUE_STRING (*arg), - NULL); - break; - - case ARG_LINE_WRAP: - gtk_object_get(GTK_OBJECT(ee->item), - "line_wrap", >K_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_BREAK_CHARACTERS: - gtk_object_get(GTK_OBJECT(ee->item), - "break_characters", >K_VALUE_STRING (*arg), - NULL); - break; - - case ARG_MAX_LINES: - gtk_object_get(GTK_OBJECT(ee->item), - "max_lines", >K_VALUE_INT (*arg), - NULL); - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -static void -et_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) -{ - EEntry *ee = E_ENTRY (o); - - switch (arg_id){ - case ARG_MODEL: - gtk_object_set(GTK_OBJECT(ee->item), - "model", GTK_VALUE_OBJECT (*arg), - NULL); - break; - - case ARG_EVENT_PROCESSOR: - gtk_object_set(GTK_OBJECT(ee->item), - "event_processor", GTK_VALUE_OBJECT (*arg), - NULL); - break; - - case ARG_TEXT: - gtk_object_set(GTK_OBJECT(ee->item), - "text", GTK_VALUE_STRING (*arg), - NULL); - break; - - case ARG_FONT: - gtk_object_set(GTK_OBJECT(ee->item), - "font", GTK_VALUE_STRING (*arg), - NULL); - break; - - case ARG_FONTSET: - gtk_object_set(GTK_OBJECT(ee->item), - "fontset", GTK_VALUE_STRING (*arg), - NULL); - break; - - case ARG_FONT_GDK: - gtk_object_set(GTK_OBJECT(ee->item), - "font_gdk", GTK_VALUE_BOXED (*arg), - NULL); - break; - - case ARG_JUSTIFICATION: - gtk_object_set(GTK_OBJECT(ee->item), - "justification", GTK_VALUE_ENUM (*arg), - NULL); - break; - - case ARG_FILL_COLOR: - gtk_object_set(GTK_OBJECT(ee->item), - "fill_color", GTK_VALUE_STRING (*arg), - NULL); - break; - - case ARG_FILL_COLOR_GDK: - gtk_object_set(GTK_OBJECT(ee->item), - "fill_color_gdk", GTK_VALUE_BOXED (*arg), - NULL); - break; - - case ARG_FILL_COLOR_RGBA: - gtk_object_set(GTK_OBJECT(ee->item), - "fill_color_rgba", GTK_VALUE_UINT (*arg), - NULL); - break; - - case ARG_FILL_STIPPLE: - gtk_object_set(GTK_OBJECT(ee->item), - "fill_stiple", GTK_VALUE_BOXED (*arg), - NULL); - break; - - case ARG_EDITABLE: - gtk_object_set(GTK_OBJECT(ee->item), - "editable", GTK_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_USE_ELLIPSIS: - gtk_object_set(GTK_OBJECT(ee->item), - "use_ellipsis", GTK_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_ELLIPSIS: - gtk_object_set(GTK_OBJECT(ee->item), - "ellipsis", GTK_VALUE_STRING (*arg), - NULL); - break; - - case ARG_LINE_WRAP: - gtk_object_set(GTK_OBJECT(ee->item), - "line_wrap", GTK_VALUE_BOOL (*arg), - NULL); - break; - - case ARG_BREAK_CHARACTERS: - gtk_object_set(GTK_OBJECT(ee->item), - "break_characters", GTK_VALUE_STRING (*arg), - NULL); - break; - - case ARG_MAX_LINES: - gtk_object_set(GTK_OBJECT(ee->item), - "max_lines", GTK_VALUE_INT (*arg), - NULL); - break; - } -} - -static void -e_entry_class_init (GtkObjectClass *object_class) -{ - EEntryClass *klass = E_ENTRY_CLASS(object_class); - parent_class = gtk_type_class (PARENT_TYPE); - - object_class->set_arg = et_set_arg; - object_class->get_arg = et_get_arg; - - klass->changed = NULL; - klass->activate = NULL; - - e_entry_signals[E_ENTRY_CHANGED] = - gtk_signal_new ("changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EEntryClass, changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_entry_signals[E_ENTRY_ACTIVATE] = - gtk_signal_new ("activate", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EEntryClass, activate), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - - gtk_object_class_add_signals (object_class, e_entry_signals, E_ENTRY_LAST_SIGNAL); - - gtk_object_add_arg_type ("EEntry::model", - GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_MODEL); - gtk_object_add_arg_type ("EEntry::event_processor", - GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_EVENT_PROCESSOR); - gtk_object_add_arg_type ("EEntry::text", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TEXT); - gtk_object_add_arg_type ("EEntry::font", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONT); - gtk_object_add_arg_type ("EEntry::fontset", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONTSET); - gtk_object_add_arg_type ("EEntry::font_gdk", - GTK_TYPE_GDK_FONT, GTK_ARG_READWRITE, ARG_FONT_GDK); - gtk_object_add_arg_type ("EEntry::justification", - GTK_TYPE_JUSTIFICATION, GTK_ARG_READWRITE, ARG_JUSTIFICATION); - gtk_object_add_arg_type ("EEntry::fill_color", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FILL_COLOR); - gtk_object_add_arg_type ("EEntry::fill_color_gdk", - GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_FILL_COLOR_GDK); - gtk_object_add_arg_type ("EEntry::fill_color_rgba", - GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_FILL_COLOR_RGBA); - gtk_object_add_arg_type ("EEntry::fill_stipple", - GTK_TYPE_GDK_WINDOW, GTK_ARG_READWRITE, ARG_FILL_STIPPLE); - gtk_object_add_arg_type ("EEntry::editable", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_EDITABLE); - gtk_object_add_arg_type ("EEntry::use_ellipsis", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_USE_ELLIPSIS); - gtk_object_add_arg_type ("EEntry::ellipsis", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ELLIPSIS); - gtk_object_add_arg_type ("EEntry::line_wrap", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_LINE_WRAP); - gtk_object_add_arg_type ("EEntry::break_characters", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_BREAK_CHARACTERS); - gtk_object_add_arg_type ("EEntry::max_lines", - GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_MAX_LINES); -} - -E_MAKE_TYPE(e_entry, "EEntry", EEntry, e_entry_class_init, e_entry_init, PARENT_TYPE); diff --git a/widgets/text/e-entry.h b/widgets/text/e-entry.h deleted file mode 100644 index ad349659c3..0000000000 --- a/widgets/text/e-entry.h +++ /dev/null @@ -1,39 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_ENTRY_H_ -#define _E_ENTRY_H_ - -#include <libgnomeui/gnome-canvas.h> -#include <gtk/gtktable.h> -#include <gnome-xml/tree.h> -#include "e-text.h" - -BEGIN_GNOME_DECLS - -#define E_ENTRY_TYPE (e_entry_get_type ()) -#define E_ENTRY(o) (GTK_CHECK_CAST ((o), E_ENTRY_TYPE, EEntry)) -#define E_ENTRY_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_ENTRY_TYPE, EEntryClass)) -#define E_IS_ENTRY(o) (GTK_CHECK_TYPE ((o), E_ENTRY_TYPE)) -#define E_IS_ENTRY_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_ENTRY_TYPE)) - -typedef struct { - GtkTable parent; - - GnomeCanvas *canvas; - EText *item; -} EEntry; - -typedef struct { - GtkTableClass parent_class; - - void (* changed) (EEntry *entry); - void (* activate) (EEntry *entry); -} EEntryClass; - -GtkType e_entry_get_type (void); - -EEntry *e_entry_construct (EEntry *e_entry); -GtkWidget *e_entry_new (void); - -END_GNOME_DECLS - -#endif /* _E_ENTRY_H_ */ diff --git a/widgets/text/e-table-text-model.c b/widgets/text/e-table-text-model.c deleted file mode 100644 index 5b6fa8b707..0000000000 --- a/widgets/text/e-table-text-model.c +++ /dev/null @@ -1,220 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ETableTextModel - Text item model for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey <clahey@umich.edu> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> */ - -#include <config.h> -#include <ctype.h> -#include "e-table-text-model.h" - -static void e_table_text_model_class_init (ETableTextModelClass *class); -static void e_table_text_model_init (ETableTextModel *model); -static void e_table_text_model_destroy (GtkObject *object); - -static gchar *e_table_text_model_get_text (ETextModel *model); -static void e_table_text_model_set_text (ETextModel *model, gchar *text); -static void e_table_text_model_insert (ETextModel *model, gint postion, gchar *text); -static void e_table_text_model_insert_length (ETextModel *model, gint postion, gchar *text, gint length); -static void e_table_text_model_delete (ETextModel *model, gint postion, gint length); - -static GtkObject *parent_class; - - - -/** - * e_table_text_model_get_type: - * @void: - * - * Registers the &ETableTextModel class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &ETableTextModel class. - **/ -GtkType -e_table_text_model_get_type (void) -{ - static GtkType model_type = 0; - - if (!model_type) { - GtkTypeInfo model_info = { - "ETableTextModel", - sizeof (ETableTextModel), - sizeof (ETableTextModelClass), - (GtkClassInitFunc) e_table_text_model_class_init, - (GtkObjectInitFunc) e_table_text_model_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - model_type = gtk_type_unique (e_text_model_get_type (), &model_info); - } - - return model_type; -} - -/* Class initialization function for the text item */ -static void -e_table_text_model_class_init (ETableTextModelClass *klass) -{ - GtkObjectClass *object_class; - ETextModelClass *model_class; - - object_class = (GtkObjectClass *) klass; - model_class = (ETextModelClass *) klass; - - parent_class = gtk_type_class (e_text_model_get_type ()); - - model_class->get_text = e_table_text_model_get_text; - model_class->set_text = e_table_text_model_set_text; - model_class->insert = e_table_text_model_insert; - model_class->insert_length = e_table_text_model_insert_length; - model_class->delete = e_table_text_model_delete; - - object_class->destroy = e_table_text_model_destroy; -} - -/* Object initialization function for the text item */ -static void -e_table_text_model_init (ETableTextModel *model) -{ - model->model = NULL; - model->row = 0; - model->model_col = 0; - model->cell_changed_signal_id = 0; - model->row_changed_signal_id = 0; -} - -/* Destroy handler for the text item */ -static void -e_table_text_model_destroy (GtkObject *object) -{ - ETableTextModel *model; - - g_return_if_fail (object != NULL); - g_return_if_fail (E_IS_TABLE_TEXT_MODEL (object)); - - model = E_TABLE_TEXT_MODEL (object); - - if (model->model) - g_assert (GTK_IS_OBJECT (model->model)); - - if (model->cell_changed_signal_id) - gtk_signal_disconnect (GTK_OBJECT(model->model), - model->cell_changed_signal_id); - - if (model->row_changed_signal_id) - gtk_signal_disconnect (GTK_OBJECT(model->model), - model->row_changed_signal_id); - - if (model->model) - gtk_object_unref (GTK_OBJECT(model->model)); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} -static gchar * -e_table_text_model_get_text (ETextModel *text_model) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model) - return (gchar *)e_table_model_value_at (model->model, model->model_col, model->row); - else - return ""; -} - -static void -e_table_text_model_set_text (ETextModel *text_model, gchar *text) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model) - e_table_model_set_value_at (model->model, model->model_col, model->row, (void *) text); -} - -static void -e_table_text_model_insert (ETextModel *text_model, gint position, gchar *text) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model){ - gchar *temp = (gchar *)e_table_model_value_at (model->model, model->model_col, model->row); - temp = g_strdup_printf ("%.*s%s%s", position, temp, text, temp + position); - e_table_model_set_value_at (model->model, model->model_col, model->row, temp); - g_free (temp); - } -} - -static void -e_table_text_model_insert_length (ETextModel *text_model, gint position, gchar *text, gint length) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model){ - gchar *temp = (gchar *)e_table_model_value_at (model->model, model->model_col, model->row); - temp = g_strdup_printf ("%.*s%.*s%s", position, temp, length, text, temp + position); - e_table_model_set_value_at (model->model, model->model_col, model->row, temp); - g_free (temp); - } -} - -static void -e_table_text_model_delete (ETextModel *text_model, gint position, gint length) -{ - ETableTextModel *model = E_TABLE_TEXT_MODEL(text_model); - if (model->model){ - gchar *temp = (gchar *)e_table_model_value_at (model->model, model->model_col, model->row); - temp = g_strdup_printf ("%.*s%s", position, temp, temp + position + length); - e_table_model_set_value_at (model->model, model->model_col, model->row, temp); - g_free (temp); - } -} - -static void -cell_changed (ETableModel *table_model, int model_col, int row, ETableTextModel *model) -{ - if (model->model_col == model_col && - model->row == row) - e_text_model_changed (E_TEXT_MODEL(model)); -} - -static void -row_changed (ETableModel *table_model, int row, ETableTextModel *model) -{ - if (model->row == row) - e_text_model_changed (E_TEXT_MODEL(model)); -} - -ETableTextModel * -e_table_text_model_new (ETableModel *table_model, int row, int model_col) -{ - ETableTextModel *model = gtk_type_new (e_table_text_model_get_type ()); - model->model = table_model; - if (model->model){ - gtk_object_ref (GTK_OBJECT(model->model)); - model->cell_changed_signal_id = - gtk_signal_connect (GTK_OBJECT(model->model), - "model_cell_changed", - GTK_SIGNAL_FUNC(cell_changed), - model); - model->row_changed_signal_id = - gtk_signal_connect (GTK_OBJECT(model->model), - "model_row_changed", - GTK_SIGNAL_FUNC(row_changed), - model); - } - model->row = row; - model->model_col = model_col; - return model; -} - diff --git a/widgets/text/e-table-text-model.h b/widgets/text/e-table-text-model.h deleted file mode 100644 index dcc9afde7c..0000000000 --- a/widgets/text/e-table-text-model.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ETableTextModel - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey <clahey@umich.edu> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> */ - -#ifndef E_TABLE_TEXT_MODEL_H -#define E_TABLE_TEXT_MODEL_H - -#include <gnome.h> -#include "e-text-model.h" -#include "e-table-model.h" - - -BEGIN_GNOME_DECLS - -#define E_TYPE_TABLE_TEXT_MODEL (e_table_text_model_get_type ()) -#define E_TABLE_TEXT_MODEL(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TABLE_TEXT_MODEL, ETableTextModel)) -#define E_TABLE_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TABLE_TEXT_MODEL, ETableTextModelClass)) -#define E_IS_TABLE_TEXT_MODEL(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TABLE_TEXT_MODEL)) -#define E_IS_TABLE_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TABLE_TEXT_MODEL)) - -typedef struct _ETableTextModel ETableTextModel; -typedef struct _ETableTextModelClass ETableTextModelClass; - -struct _ETableTextModel { - ETextModel parent; - - ETableModel *model; - int row; - int model_col; - - int cell_changed_signal_id; - int row_changed_signal_id; -}; - -struct _ETableTextModelClass { - ETextModelClass parent_class; - -}; - - -/* Standard Gtk function */ -GtkType e_table_text_model_get_type (void); -ETableTextModel *e_table_text_model_new (ETableModel *table_model, int row, int model_col); - -END_GNOME_DECLS - -#endif diff --git a/widgets/text/e-text-event-processor-emacs-like.c b/widgets/text/e-text-event-processor-emacs-like.c deleted file mode 100644 index be323d028f..0000000000 --- a/widgets/text/e-text-event-processor-emacs-like.c +++ /dev/null @@ -1,372 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <gnome.h> -#include "e-text-event-processor-emacs-like.h" -static void e_text_event_processor_emacs_like_init (ETextEventProcessorEmacsLike *card); -static void e_text_event_processor_emacs_like_class_init (ETextEventProcessorEmacsLikeClass *klass); -static gint e_text_event_processor_emacs_like_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event); - -static ETextEventProcessorClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0 -}; - -static const ETextEventProcessorCommand control_keys[26] = -{ - { E_TEP_START_OF_LINE, E_TEP_MOVE, 0, "" }, /* a */ - { E_TEP_BACKWARD_CHARACTER, E_TEP_MOVE, 0, "" }, /* b */ - { E_TEP_SELECTION, E_TEP_COPY, 0, "" }, /* c */ - { E_TEP_FORWARD_CHARACTER, E_TEP_DELETE, 0, "" }, /* d */ - { E_TEP_END_OF_LINE, E_TEP_MOVE, 0, "" }, /* e */ - { E_TEP_FORWARD_CHARACTER, E_TEP_MOVE, 0, "" }, /* f */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* g */ - { E_TEP_BACKWARD_CHARACTER, E_TEP_DELETE, 0, "" }, /* h */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* i */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* j */ - { E_TEP_END_OF_LINE, E_TEP_DELETE, 0, "" }, /* k */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* l */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* m */ - { E_TEP_FORWARD_LINE, E_TEP_MOVE, 0, "" }, /* n */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* o */ - { E_TEP_BACKWARD_LINE, E_TEP_MOVE, 0, "" }, /* p */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* q */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* r */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* s */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* t */ - { E_TEP_START_OF_LINE, E_TEP_DELETE, 0, "" }, /* u */ - { E_TEP_SELECTION, E_TEP_PASTE, 0, "" }, /* v */ - { E_TEP_SELECTION, E_TEP_DELETE, 0, "" }, /* w */ - { E_TEP_SELECTION, E_TEP_DELETE, 0, "" }, /* x */ - { E_TEP_SELECTION, E_TEP_PASTE, 0, "" }, /* y */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" } /* z */ -}; - -static const ETextEventProcessorCommand alt_keys[26] = -{ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* a */ - { E_TEP_BACKWARD_WORD, E_TEP_MOVE, 0, "" }, /* b */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* c */ - { E_TEP_FORWARD_WORD, E_TEP_DELETE, 0, "" }, /* d */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* e */ - { E_TEP_FORWARD_WORD, E_TEP_MOVE, 0, "" }, /* f */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* g */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* h */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* i */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* j */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* k */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* l */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* m */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* n */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* o */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* p */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* q */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* r */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* s */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* t */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* u */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* v */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* w */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* x */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* y */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" } /* z */ - -}; - -GtkType -e_text_event_processor_emacs_like_get_type (void) -{ - static GtkType text_event_processor_emacs_like_type = 0; - - if (!text_event_processor_emacs_like_type) - { - static const GtkTypeInfo text_event_processor_emacs_like_info = - { - "ETextEventProcessorEmacsLike", - sizeof (ETextEventProcessorEmacsLike), - sizeof (ETextEventProcessorEmacsLikeClass), - (GtkClassInitFunc) e_text_event_processor_emacs_like_class_init, - (GtkObjectInitFunc) e_text_event_processor_emacs_like_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - text_event_processor_emacs_like_type = gtk_type_unique (e_text_event_processor_get_type (), &text_event_processor_emacs_like_info); - } - - return text_event_processor_emacs_like_type; -} - -static void -e_text_event_processor_emacs_like_class_init (ETextEventProcessorEmacsLikeClass *klass) -{ - GtkObjectClass *object_class; - ETextEventProcessorClass *processor_class; - - object_class = (GtkObjectClass*) klass; - processor_class = (ETextEventProcessorClass*) klass; - - parent_class = gtk_type_class (e_text_event_processor_get_type ()); - - processor_class->event = e_text_event_processor_emacs_like_event; -} - -static void -e_text_event_processor_emacs_like_init (ETextEventProcessorEmacsLike *tep) -{ -} - -static gint -e_text_event_processor_emacs_like_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event) -{ - ETextEventProcessorCommand command; - ETextEventProcessorEmacsLike *tep_el = E_TEXT_EVENT_PROCESSOR_EMACS_LIKE(tep); - command.action = E_TEP_NOP; - switch (event->type) { - case GDK_BUTTON_PRESS: - if (event->button.button == 1) { - command.action = E_TEP_GRAB; - command.time = event->button.time; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - if (event->button.state & GDK_SHIFT_MASK) - command.action = E_TEP_SELECT; - else - command.action = E_TEP_MOVE; - command.position = E_TEP_VALUE; - command.value = event->button.position; - command.time = event->button.time; - tep_el->mouse_down = TRUE; - } - break; - case GDK_2BUTTON_PRESS: - if (event->button.button == 1) { - command.action = E_TEP_SELECT; - command.position = E_TEP_SELECT_WORD; - command.time = event->button.time; - } - break; - case GDK_3BUTTON_PRESS: - if (event->button.button == 1) { - command.action = E_TEP_SELECT; - command.position = E_TEP_SELECT_ALL; - command.time = event->button.time; - } - break; - case GDK_BUTTON_RELEASE: - if (event->button.button == 1) { - command.action = E_TEP_UNGRAB; - command.time = event->button.time; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - command.time = event->button.time; - tep_el->mouse_down = FALSE; - command.action = E_TEP_NOP; - } else if (event->button.button == 2) { - command.action = E_TEP_MOVE; - command.position = E_TEP_VALUE; - command.value = event->button.position; - command.time = event->button.time; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - - command.action = E_TEP_GET_SELECTION; - command.position = E_TEP_SELECTION; - command.value = 0; - command.time = event->button.time; - } - break; - case GDK_MOTION_NOTIFY: - if (tep_el->mouse_down) { - command.action = E_TEP_SELECT; - command.position = E_TEP_VALUE; - command.time = event->motion.time; - command.value = event->motion.position; - } - break; - case GDK_KEY_PRESS: - { - ETextEventProcessorEventKey key = event->key; - command.time = event->key.time; - if (key.state & GDK_SHIFT_MASK) - command.action = E_TEP_SELECT; - else - command.action = E_TEP_MOVE; - switch(key.keyval) { - case GDK_Home: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_START_OF_BUFFER; - else - command.position = E_TEP_START_OF_LINE; - break; - case GDK_End: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_END_OF_BUFFER; - else - command.position = E_TEP_END_OF_LINE; - break; - case GDK_Page_Up: command.position = E_TEP_BACKWARD_PAGE; break; - case GDK_Page_Down: command.position = E_TEP_FORWARD_PAGE; break; - /* CUA has Ctrl-Up/Ctrl-Down as paragraph up down */ - case GDK_Up: command.position = E_TEP_BACKWARD_LINE; break; - case GDK_Down: command.position = E_TEP_FORWARD_LINE; break; - case GDK_Left: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_BACKWARD_WORD; - else - command.position = E_TEP_BACKWARD_CHARACTER; - break; - case GDK_Right: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_FORWARD_WORD; - else - command.position = E_TEP_FORWARD_CHARACTER; - break; - - case GDK_BackSpace: - command.action = E_TEP_DELETE; - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_BACKWARD_WORD; - else - command.position = E_TEP_BACKWARD_CHARACTER; - break; - case GDK_Clear: - command.action = E_TEP_DELETE; - command.position = E_TEP_END_OF_LINE; - break; - case GDK_Insert: - if (key.state & GDK_SHIFT_MASK) { - command.action = E_TEP_PASTE; - command.position = E_TEP_SELECTION; - } else if (key.state & GDK_CONTROL_MASK) { - command.action = E_TEP_COPY; - command.position = E_TEP_SELECTION; - } else { - /* gtk_toggle_insert(text) -- IMPLEMENT */ - } - break; - case GDK_Delete: - if (key.state & GDK_CONTROL_MASK){ - command.action = E_TEP_DELETE; - command.position = E_TEP_FORWARD_WORD; - } else if (key.state & GDK_SHIFT_MASK) { - command.action = E_TEP_COPY; - command.position = E_TEP_SELECTION; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - - command.action = E_TEP_DELETE; - command.position = E_TEP_SELECTION; - } else { - command.action = E_TEP_DELETE; - command.position = E_TEP_FORWARD_CHARACTER; - } - break; - case GDK_Tab: - /* Don't insert literally */ - command.action = E_TEP_NOP; - command.position = E_TEP_SELECTION; - break; - case GDK_Return: - if (key.state & GDK_CONTROL_MASK) { - command.action = E_TEP_ACTIVATE; - command.position = E_TEP_SELECTION; - } else { - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "\n"; - } - break; - case GDK_Escape: - /* Don't insert literally */ - command.action = E_TEP_NOP; - command.position = E_TEP_SELECTION; - break; - - default: - if (key.state & GDK_CONTROL_MASK) { - if ((key.keyval >= 'A') && (key.keyval <= 'Z')) - key.keyval -= 'A' - 'a'; - - if ((key.keyval >= 'a') && (key.keyval <= 'z')) { - command.position = control_keys[(int) (key.keyval - 'a')].position; - if (control_keys[(int) (key.keyval - 'a')].action != E_TEP_MOVE) - command.action = control_keys[(int) (key.keyval - 'a')].action; - command.value = control_keys[(int) (key.keyval - 'a')].value; - command.string = control_keys[(int) (key.keyval - 'a')].string; - } - - if (key.keyval == 'x' || key.keyval == 'w') { - command.action = E_TEP_COPY; - command.position = E_TEP_SELECTION; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - - command.action = E_TEP_DELETE; - command.position = E_TEP_SELECTION; - } - - break; - } else if (key.state & GDK_MOD1_MASK) { - if ((key.keyval >= 'A') && (key.keyval <= 'Z')) - key.keyval -= 'A' - 'a'; - - if ((key.keyval >= 'a') && (key.keyval <= 'z')) { - command.position = alt_keys[(int) (key.keyval - 'a')].position; - if (alt_keys[(int) (key.keyval - 'a')].action != E_TEP_MOVE) - command.action = alt_keys[(int) (key.keyval - 'a')].action; - command.value = alt_keys[(int) (key.keyval - 'a')].value; - command.string = alt_keys[(int) (key.keyval - 'a')].string; - } - } else if (key.length > 0) { - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = strlen(key.string); - command.string = key.string; - - } else { - command.action = E_TEP_NOP; - } - } - break; - case GDK_KEY_RELEASE: - command.time = event->key.time; - command.action = E_TEP_NOP; - break; - default: - command.action = E_TEP_NOP; - break; - } - } - if (command.action != E_TEP_NOP) { - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - return 1; - } - else - return 0; -} - -ETextEventProcessor * -e_text_event_processor_emacs_like_new (void) -{ - ETextEventProcessorEmacsLike *retval = gtk_type_new (e_text_event_processor_emacs_like_get_type ()); - return E_TEXT_EVENT_PROCESSOR (retval); -} - diff --git a/widgets/text/e-text-event-processor-emacs-like.h b/widgets/text/e-text-event-processor-emacs-like.h deleted file mode 100644 index 651bb552b3..0000000000 --- a/widgets/text/e-text-event-processor-emacs-like.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor-emacs-like.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef __E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_H__ -#define __E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_H__ - -#include <gnome.h> -#include "e-text-event-processor.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ETextEventProcessorEmacsLike - Turns events on a text widget into commands. Uses an emacs-ish interface. - * - */ - -#define E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE (e_text_event_processor_emacs_like_get_type ()) -#define E_TEXT_EVENT_PROCESSOR_EMACS_LIKE(obj) (GTK_CHECK_CAST ((obj), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE, ETextEventProcessorEmacsLike)) -#define E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE, ETextEventProcessorEmacsLikeClass)) -#define E_IS_TEXT_EVENT_PROCESSOR_EMACS_LIKE(obj) (GTK_CHECK_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE)) -#define E_IS_TEXT_EVENT_PROCESSOR_EMACS_LIKE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE)) - - -typedef struct _ETextEventProcessorEmacsLike ETextEventProcessorEmacsLike; -typedef struct _ETextEventProcessorEmacsLikeClass ETextEventProcessorEmacsLikeClass; - -struct _ETextEventProcessorEmacsLike -{ - ETextEventProcessor parent; - - /* object specific fields */ - gboolean mouse_down; -}; - -struct _ETextEventProcessorEmacsLikeClass -{ - ETextEventProcessorClass parent_class; -}; - - -GtkType e_text_event_processor_emacs_like_get_type (void); -ETextEventProcessor *e_text_event_processor_emacs_like_new (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_H__ */ diff --git a/widgets/text/e-text-event-processor-types.h b/widgets/text/e-text-event-processor-types.h deleted file mode 100644 index 8f2ffbaf39..0000000000 --- a/widgets/text/e-text-event-processor-types.h +++ /dev/null @@ -1,140 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#ifndef __E_TEXT_EVENT_PROCESSOR_TYPES_H__ -#define __E_TEXT_EVENT_PROCESSOR_TYPES_H__ - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -#include <gdk/gdktypes.h> - -typedef enum _ETextEventProcessorCommandPosition ETextEventProcessorCommandPosition; -typedef enum _ETextEventProcessorCommandAction ETextEventProcessorCommandAction; -typedef struct _ETextEventProcessorCommand ETextEventProcessorCommand; - -typedef union _ETextEventProcessorEvent ETextEventProcessorEvent; -typedef struct _ETextEventProcessorEventButton ETextEventProcessorEventButton; -typedef struct _ETextEventProcessorEventKey ETextEventProcessorEventKey; -typedef struct _ETextEventProcessorEventMotion ETextEventProcessorEventMotion; - -enum _ETextEventProcessorCommandPosition { - E_TEP_VALUE, - E_TEP_SELECTION, - - E_TEP_START_OF_BUFFER, - E_TEP_END_OF_BUFFER, - - E_TEP_START_OF_LINE, - E_TEP_END_OF_LINE, - - E_TEP_FORWARD_CHARACTER, - E_TEP_BACKWARD_CHARACTER, - - E_TEP_FORWARD_WORD, - E_TEP_BACKWARD_WORD, - - E_TEP_FORWARD_LINE, - E_TEP_BACKWARD_LINE, - - E_TEP_FORWARD_PARAGRAPH, - E_TEP_BACKWARD_PARAGRAPH, - - E_TEP_FORWARD_PAGE, - E_TEP_BACKWARD_PAGE, - - E_TEP_SELECT_WORD, - E_TEP_SELECT_ALL - -}; - -enum _ETextEventProcessorCommandAction { - E_TEP_MOVE, - E_TEP_SELECT, - E_TEP_DELETE, - E_TEP_INSERT, - - E_TEP_COPY, - E_TEP_PASTE, - E_TEP_GET_SELECTION, - E_TEP_SET_SELECT_BY_WORD, - E_TEP_ACTIVATE, - - E_TEP_GRAB, - E_TEP_UNGRAB, - - E_TEP_NOP -}; - -struct _ETextEventProcessorCommand { - ETextEventProcessorCommandPosition position; - ETextEventProcessorCommandAction action; - int value; - char *string; - guint32 time; -}; - -struct _ETextEventProcessorEventButton { - GdkEventType type; - guint32 time; - guint state; - guint button; - gint position; -}; - -struct _ETextEventProcessorEventKey { - GdkEventType type; - guint32 time; - guint state; - guint keyval; - gint length; - gchar *string; -}; - -struct _ETextEventProcessorEventMotion { - GdkEventType type; - guint32 time; - guint state; - gint position; -}; - -union _ETextEventProcessorEvent { - GdkEventType type; - ETextEventProcessorEventButton button; - ETextEventProcessorEventKey key; - ETextEventProcessorEventMotion motion; -}; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TEXT_EVENT_PROCESSOR_TYPES_H__ */ diff --git a/widgets/text/e-text-event-processor.c b/widgets/text/e-text-event-processor.c deleted file mode 100644 index 47f028ca62..0000000000 --- a/widgets/text/e-text-event-processor.c +++ /dev/null @@ -1,103 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <gnome.h> -#include "e-text-event-processor.h" -static void e_text_event_processor_init (ETextEventProcessor *card); -static void e_text_event_processor_class_init (ETextEventProcessorClass *klass); - -static GtkObjectClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0 -}; - -enum { - E_TEP_EVENT, - E_TEP_LAST_SIGNAL -}; - -static guint e_tep_signals[E_TEP_LAST_SIGNAL] = { 0 }; - -GtkType -e_text_event_processor_get_type (void) -{ - static GtkType text_event_processor_type = 0; - - if (!text_event_processor_type) - { - static const GtkTypeInfo text_event_processor_info = - { - "ETextEventProcessor", - sizeof (ETextEventProcessor), - sizeof (ETextEventProcessorClass), - (GtkClassInitFunc) e_text_event_processor_class_init, - (GtkObjectInitFunc) e_text_event_processor_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - text_event_processor_type = gtk_type_unique (gtk_object_get_type (), &text_event_processor_info); - } - - return text_event_processor_type; -} - -static void -e_text_event_processor_class_init (ETextEventProcessorClass *klass) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass*) klass; - - parent_class = gtk_type_class (gtk_object_get_type ()); - - e_tep_signals[E_TEP_EVENT] = - gtk_signal_new ("command", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETextEventProcessorClass, command), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, - GTK_TYPE_POINTER); - - gtk_object_class_add_signals (object_class, e_tep_signals, E_TEP_LAST_SIGNAL); - - klass->event = NULL; - klass->command = NULL; -} - -static void -e_text_event_processor_init (ETextEventProcessor *tep) -{ -} - -gint -e_text_event_processor_handle_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event) -{ - if (E_TEXT_EVENT_PROCESSOR_CLASS(GTK_OBJECT(tep)->klass)->event) { - return E_TEXT_EVENT_PROCESSOR_CLASS(GTK_OBJECT(tep)->klass)->event(tep, event); - } else { - return 0; - } -} diff --git a/widgets/text/e-text-event-processor.h b/widgets/text/e-text-event-processor.h deleted file mode 100644 index 1fc79f3f70..0000000000 --- a/widgets/text/e-text-event-processor.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef __E_TEXT_EVENT_PROCESSOR_H__ -#define __E_TEXT_EVENT_PROCESSOR_H__ - -#include <gnome.h> -#include "e-text-event-processor-types.h" - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ETextEventProcessor - Turns events on a text widget into commands. - * - */ - -#define E_TEXT_EVENT_PROCESSOR_TYPE (e_text_event_processor_get_type ()) -#define E_TEXT_EVENT_PROCESSOR(obj) (GTK_CHECK_CAST ((obj), E_TEXT_EVENT_PROCESSOR_TYPE, ETextEventProcessor)) -#define E_TEXT_EVENT_PROCESSOR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TEXT_EVENT_PROCESSOR_TYPE, ETextEventProcessorClass)) -#define E_IS_TEXT_EVENT_PROCESSOR(obj) (GTK_CHECK_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_TYPE)) -#define E_IS_TEXT_EVENT_PROCESSOR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_TYPE)) - - -typedef struct _ETextEventProcessor ETextEventProcessor; -typedef struct _ETextEventProcessorClass ETextEventProcessorClass; - -struct _ETextEventProcessor -{ - GtkObject parent; - - /* object specific fields */ - -}; - -struct _ETextEventProcessorClass -{ - GtkObjectClass parent_class; - - /* signals */ - void (* command) (ETextEventProcessor *tep, ETextEventProcessorCommand *command); - - /* virtual functions */ - gint (* event) (ETextEventProcessor *tep, ETextEventProcessorEvent *event); -}; - - -GtkType e_text_event_processor_get_type (void); -gint e_text_event_processor_handle_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TEXT_EVENT_PROCESSOR_H__ */ diff --git a/widgets/text/e-text-model.c b/widgets/text/e-text-model.c deleted file mode 100644 index 6ca650867c..0000000000 --- a/widgets/text/e-text-model.c +++ /dev/null @@ -1,244 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ETextModel - Text item model for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey <clahey@umich.edu> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> */ - -#include <config.h> -#include <ctype.h> -#include "e-text-model.h" - -enum { - E_TEXT_MODEL_CHANGED, - E_TEXT_MODEL_LAST_SIGNAL -}; - -static guint e_text_model_signals[E_TEXT_MODEL_LAST_SIGNAL] = { 0 }; - -static void e_text_model_class_init (ETextModelClass *class); -static void e_text_model_init (ETextModel *model); -static void e_text_model_destroy (GtkObject *object); - -static gchar *e_text_model_real_get_text(ETextModel *model); -static void e_text_model_real_set_text(ETextModel *model, gchar *text); -static void e_text_model_real_insert(ETextModel *model, gint postion, gchar *text); -static void e_text_model_real_insert_length(ETextModel *model, gint postion, gchar *text, gint length); -static void e_text_model_real_delete(ETextModel *model, gint postion, gint length); - -static GtkObject *parent_class; - - - -/** - * e_text_model_get_type: - * @void: - * - * Registers the &ETextModel class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &ETextModel class. - **/ -GtkType -e_text_model_get_type (void) -{ - static GtkType model_type = 0; - - if (!model_type) { - GtkTypeInfo model_info = { - "ETextModel", - sizeof (ETextModel), - sizeof (ETextModelClass), - (GtkClassInitFunc) e_text_model_class_init, - (GtkObjectInitFunc) e_text_model_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - model_type = gtk_type_unique (gtk_object_get_type (), &model_info); - } - - return model_type; -} - -/* Class initialization function for the text item */ -static void -e_text_model_class_init (ETextModelClass *klass) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass *) klass; - - parent_class = gtk_type_class (gtk_object_get_type ()); - - e_text_model_signals[E_TEXT_MODEL_CHANGED] = - gtk_signal_new ("changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETextModelClass, changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, e_text_model_signals, E_TEXT_MODEL_LAST_SIGNAL); - - klass->changed = NULL; - klass->get_text = e_text_model_real_get_text; - klass->set_text = e_text_model_real_set_text; - klass->insert = e_text_model_real_insert; - klass->insert_length = e_text_model_real_insert_length; - klass->delete = e_text_model_real_delete; - - object_class->destroy = e_text_model_destroy; -} - -/* Object initialization function for the text item */ -static void -e_text_model_init (ETextModel *model) -{ - model->text = NULL; -} - -/* Destroy handler for the text item */ -static void -e_text_model_destroy (GtkObject *object) -{ - ETextModel *model; - - g_return_if_fail (object != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (object)); - - model = E_TEXT_MODEL (object); - - if (model->text) - g_free (model->text); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -static gchar * -e_text_model_real_get_text(ETextModel *model) -{ - if (model->text) - return model->text; - else - return ""; -} - -static void -e_text_model_real_set_text(ETextModel *model, gchar *text) -{ - if (model->text) - g_free(model->text); - model->text = g_strdup(text); - e_text_model_changed(model); -} - -static void -e_text_model_real_insert(ETextModel *model, gint position, gchar *text) -{ - gchar *temp = g_strdup_printf("%.*s%s%s", position, model->text, text, model->text + position); - if (model->text) - g_free(model->text); - model->text = temp; - e_text_model_changed(model); -} - -static void -e_text_model_real_insert_length(ETextModel *model, gint position, gchar *text, gint length) -{ - gchar *temp = g_strdup_printf("%.*s%.*s%s", position, model->text, length, text, model->text + position); - if (model->text) - g_free(model->text); - model->text = temp; - e_text_model_changed(model); -} - -static void -e_text_model_real_delete(ETextModel *model, gint position, gint length) -{ - memmove(model->text + position, model->text + position + length, strlen(model->text + position + length) + 1); - e_text_model_changed(model); -} - -void -e_text_model_changed(ETextModel *model) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - gtk_signal_emit (GTK_OBJECT (model), - e_text_model_signals [E_TEXT_MODEL_CHANGED]); -} - -gchar * -e_text_model_get_text(ETextModel *model) -{ - g_return_val_if_fail (model != NULL, NULL); - g_return_val_if_fail (E_IS_TEXT_MODEL (model), NULL); - - if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->get_text ) - return E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->get_text(model); - else - return ""; -} - -void -e_text_model_set_text(ETextModel *model, gchar *text) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->set_text ) - E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->set_text(model, text); -} - -void -e_text_model_insert(ETextModel *model, gint position, gchar *text) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert ) - E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert(model, position, text); -} - -void -e_text_model_insert_length(ETextModel *model, gint position, gchar *text, gint length) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert_length ) - E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->insert_length(model, position, text, length); -} - -void -e_text_model_delete(ETextModel *model, gint position, gint length) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - if ( E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->delete ) - E_TEXT_MODEL_CLASS(GTK_OBJECT(model)->klass)->delete(model, position, length); -} - -ETextModel * -e_text_model_new(void) -{ - ETextModel *model = gtk_type_new (e_text_model_get_type ()); - model->text = g_strdup(""); - return model; -} diff --git a/widgets/text/e-text-model.h b/widgets/text/e-text-model.h deleted file mode 100644 index 5b15ccb117..0000000000 --- a/widgets/text/e-text-model.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* ETextModel - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey <clahey@umich.edu> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> */ - -#ifndef E_TEXT_MODEL_H -#define E_TEXT_MODEL_H - -#include <gnome.h> - - -BEGIN_GNOME_DECLS - -#define E_TYPE_TEXT_MODEL (e_text_model_get_type ()) -#define E_TEXT_MODEL(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TEXT_MODEL, ETextModel)) -#define E_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TEXT_MODEL, ETextModelClass)) -#define E_IS_TEXT_MODEL(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TEXT_MODEL)) -#define E_IS_TEXT_MODEL_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TEXT_MODEL)) - -typedef struct _ETextModel ETextModel; -typedef struct _ETextModelClass ETextModelClass; - -struct _ETextModel { - GtkObject item; - - char *text; /* Text to display */ - int length; -}; - -struct _ETextModelClass { - GtkObjectClass parent_class; - - /* Signal */ - void (* changed) (ETextModel *model); - - /* Virtual methods */ - char *(* get_text) (ETextModel *model); - void (* set_text) (ETextModel *model, gchar *text); - void (* insert) (ETextModel *model, gint position, gchar *text); - void (* insert_length) (ETextModel *model, gint position, gchar *text, gint length); - void (* delete) (ETextModel *model, gint position, gint length); -}; - - -/* Standard Gtk function */ -GtkType e_text_model_get_type (void); -ETextModel *e_text_model_new(void); - -void e_text_model_changed(ETextModel *model); -gchar *e_text_model_get_text(ETextModel *model); -void e_text_model_set_text(ETextModel *model, gchar *text); -void e_text_model_insert(ETextModel *model, gint position, gchar *text); -void e_text_model_insert_length(ETextModel *model, gint position, gchar *text, gint length); -void e_text_model_delete(ETextModel *model, gint position, gint length); - - -END_GNOME_DECLS - -#endif diff --git a/widgets/text/e-text-test.c b/widgets/text/e-text-test.c deleted file mode 100644 index 12a31cce7e..0000000000 --- a/widgets/text/e-text-test.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - ETextTest: E-Text item test program - Copyright (C)2000: Iain Holmes <ih@csd.abdn.ac.uk> - - This code is licensed under the GPL -*/ - -#include "e-text.h" -#include <gnome.h> -#include "e-util/e-canvas.h" -GnomeCanvasItem *rect; - -static void allocate_callback(GtkWidget *canvas, GtkAllocation *allocation, GnomeCanvasItem *item) -{ - double height; - gnome_canvas_item_set( item, - "width", (double) allocation->width, - NULL ); - gtk_object_get(GTK_OBJECT(item), - "height", &height, - NULL); - height = MAX(height, allocation->height); - gnome_canvas_set_scroll_region(GNOME_CANVAS( canvas ), 0, 0, allocation->width, height ); - gnome_canvas_item_set( rect, - "x2", (double) allocation->width, - "y2", (double) height, - NULL ); -} - -static void -reflow (GtkWidget *canvas, GnomeCanvasItem *item) -{ - double height; - gtk_object_get(GTK_OBJECT(item), - "height", &height, - NULL); - height = MAX(height, canvas->allocation.height); - gnome_canvas_set_scroll_region(GNOME_CANVAS( canvas ), 0, 0, canvas->allocation.width, height ); - gnome_canvas_item_set( rect, - "x2", (double) canvas->allocation.width, - "y2", (double) height, - NULL ); -} - -static void -quit_cb (GtkWidget *widget, - gpointer data) -{ - gtk_main_quit (); -} - -static void -change_text_cb (GtkEntry *entry, - EText *text) -{ - gchar *str; - - str = gtk_entry_get_text (entry); - gnome_canvas_item_set (GNOME_CANVAS_ITEM (text), - "text", str, - NULL); -} - -static void -change_font_cb (GtkEntry *entry, - EText *text) -{ - gchar *font; - - font = gtk_entry_get_text (entry); - gnome_canvas_item_set (GNOME_CANVAS_ITEM (text), - "font", font, - NULL); -} - -int -main (int argc, - char **argv) -{ - GtkWidget *window, *canvas, *scroller, *vbox, *text, *font; - GtkWidget *frame; - GnomeCanvasItem *item; - - gnome_init ("ETextTest", "0.0.1", argc, argv); - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title (GTK_WINDOW (window), "EText Test"); - gtk_signal_connect (GTK_OBJECT (window), "destroy", - GTK_SIGNAL_FUNC (quit_cb), NULL); - - gtk_widget_push_visual (gdk_rgb_get_visual ()); - gtk_widget_push_colormap (gdk_rgb_get_cmap ()); - canvas = e_canvas_new (); - gtk_widget_pop_visual (); - gtk_widget_pop_colormap (); - scroller = gtk_scrolled_window_new (NULL, NULL); - vbox = gtk_vbox_new (FALSE, 2); - - gtk_container_add (GTK_CONTAINER (window), vbox); - gtk_box_pack_start (GTK_BOX (vbox), scroller, TRUE, TRUE, 2); - gtk_container_add (GTK_CONTAINER (scroller), canvas); - - frame = gtk_frame_new ("Text"); - text = gtk_entry_new (); - gtk_entry_set_text(GTK_ENTRY(text), "Hello World! This is a really long string to test out the ellipsis stuff."); - gtk_container_add (GTK_CONTAINER (frame), text); - gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); - - frame = gtk_frame_new ("Font"); - font = gtk_entry_new (); - gtk_entry_set_text(GTK_ENTRY(font), "fixed"); - gtk_container_add (GTK_CONTAINER (frame), font); - gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); - - rect = gnome_canvas_item_new( gnome_canvas_root( GNOME_CANVAS( canvas ) ), - gnome_canvas_rect_get_type(), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) 100, - "y2", (double) 100, - "fill_color", "white", - NULL ); - - item = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)), - e_text_get_type (), - "text", "Hello World! This is a really long string to test out the ellipsis stuff.", - "font", "fixed", - "fill_color", "black", - "anchor", GTK_ANCHOR_NW, - "clip", TRUE, - "use_ellipsis", TRUE, - "editable", TRUE, - "line_wrap", TRUE, - "max_lines", 2, - "width", 150.0, - NULL); - - gtk_signal_connect (GTK_OBJECT (text), "activate", - GTK_SIGNAL_FUNC (change_text_cb), item); - gtk_signal_connect (GTK_OBJECT (font), "activate", - GTK_SIGNAL_FUNC (change_font_cb), item); - - gtk_signal_connect( GTK_OBJECT( canvas ), "size_allocate", - GTK_SIGNAL_FUNC( allocate_callback ), - item ); - gtk_signal_connect( GTK_OBJECT( canvas ), "reflow", - GTK_SIGNAL_FUNC( reflow ), - item ); - gnome_canvas_set_scroll_region (GNOME_CANVAS (canvas), 0.0, 0.0, 400.0, 400.0); - gtk_widget_show_all (window); - gtk_main (); - - return 0; -} diff --git a/widgets/text/e-text.c b/widgets/text/e-text.c deleted file mode 100644 index 30e6452ed0..0000000000 --- a/widgets/text/e-text.c +++ /dev/null @@ -1,3365 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* EText - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey <clahey@umich.edu> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> */ - -#include <config.h> -#include <math.h> -#include <ctype.h> -#include "e-text.h" -#include <gdk/gdkx.h> /* for BlackPixel */ -#include <libart_lgpl/art_affine.h> -#include <libart_lgpl/art_rgb.h> -#include <libart_lgpl/art_rgb_bitmap_affine.h> -#include <unicode.h> -#include <gtk/gtkinvisible.h> -#include "e-util/e-canvas.h" -#include "e-util/e-canvas-utils.h" - -#include "e-text-event-processor-emacs-like.h" - -#define BORDER_INDENT 4 - -enum { - E_TEXT_CHANGED, - E_TEXT_ACTIVATE, - E_TEXT_LAST_SIGNAL -}; - -static guint e_text_signals[E_TEXT_LAST_SIGNAL] = { 0 }; - - - -/* This defines a line of text */ -struct line { - char *text; /* Line's text, it is a pointer into the text->text string */ - int length; /* Line's length in characters */ - int width; /* Line's width in pixels */ - int ellipsis_length; /* Length before adding ellipsis */ -}; - - - -/* Object argument IDs */ -enum { - ARG_0, - ARG_MODEL, - ARG_EVENT_PROCESSOR, - ARG_TEXT, - ARG_FONT, - ARG_FONTSET, - ARG_FONT_GDK, - ARG_ANCHOR, - ARG_JUSTIFICATION, - ARG_CLIP_WIDTH, - ARG_CLIP_HEIGHT, - ARG_CLIP, - ARG_FILL_CLIP_RECTANGLE, - ARG_X_OFFSET, - ARG_Y_OFFSET, - ARG_FILL_COLOR, - ARG_FILL_COLOR_GDK, - ARG_FILL_COLOR_RGBA, - ARG_FILL_STIPPLE, - ARG_TEXT_WIDTH, - ARG_TEXT_HEIGHT, - ARG_EDITABLE, - ARG_USE_ELLIPSIS, - ARG_ELLIPSIS, - ARG_LINE_WRAP, - ARG_BREAK_CHARACTERS, - ARG_MAX_LINES, - ARG_WIDTH, - ARG_HEIGHT, - ARG_DRAW_BORDERS, -}; - - -enum { - E_SELECTION_PRIMARY, - E_SELECTION_CLIPBOARD -}; -enum { - TARGET_STRING, - TARGET_TEXT, - TARGET_COMPOUND_TEXT -}; - -static void e_text_class_init (ETextClass *class); -static void e_text_init (EText *text); -static void e_text_destroy (GtkObject *object); -static void e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_text_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); - -static void e_text_reflow (GnomeCanvasItem *item, int flags); -static void e_text_update (GnomeCanvasItem *item, double *affine, - ArtSVP *clip_path, int flags); -static void e_text_realize (GnomeCanvasItem *item); -static void e_text_unrealize (GnomeCanvasItem *item); -static void e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, - int x, int y, int width, int height); -static double e_text_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, - GnomeCanvasItem **actual_item); -static void e_text_bounds (GnomeCanvasItem *item, - double *x1, double *y1, double *x2, double *y2); -static void e_text_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf); -static gint e_text_event (GnomeCanvasItem *item, GdkEvent *event); - -static void e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data); - -static void e_text_get_selection(EText *text, GdkAtom selection, guint32 time); -static void e_text_supply_selection (EText *text, guint time, GdkAtom selection, guchar *data, gint length); - -static void e_text_text_model_changed(ETextModel *model, EText *text); - -static void _get_tep(EText *text); - -static GtkWidget *e_text_get_invisible(EText *text); -static void _selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - EText *text); -static void _selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EText *text); -static void _selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - EText *text); - -#if 0 -static ETextSuckFont *e_suck_font (GdkFont *font); -static void e_suck_font_free (ETextSuckFont *suckfont); -#endif - -static void e_text_free_lines(EText *text); - -static void calc_height (EText *text); -static void calc_line_widths (EText *text); -static void split_into_lines (EText *text); - -static GnomeCanvasItemClass *parent_class; -static GdkAtom clipboard_atom = GDK_NONE; - - - -/** - * e_text_get_type: - * @void: - * - * Registers the &EText class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &EText class. - **/ -GtkType -e_text_get_type (void) -{ - static GtkType text_type = 0; - - if (!text_type) { - GtkTypeInfo text_info = { - "EText", - sizeof (EText), - sizeof (ETextClass), - (GtkClassInitFunc) e_text_class_init, - (GtkObjectInitFunc) e_text_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - text_type = gtk_type_unique (gnome_canvas_item_get_type (), &text_info); - } - - return text_type; -} - -/* Class initialization function for the text item */ -static void -e_text_class_init (ETextClass *klass) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - object_class = (GtkObjectClass *) klass; - item_class = (GnomeCanvasItemClass *) klass; - - parent_class = gtk_type_class (gnome_canvas_item_get_type ()); - - e_text_signals[E_TEXT_CHANGED] = - gtk_signal_new ("changed", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETextClass, changed), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - e_text_signals[E_TEXT_ACTIVATE] = - gtk_signal_new ("activate", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETextClass, activate), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, e_text_signals, E_TEXT_LAST_SIGNAL); - - - gtk_object_add_arg_type ("EText::model", - GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_MODEL); - gtk_object_add_arg_type ("EText::event_processor", - GTK_TYPE_OBJECT, GTK_ARG_READWRITE, ARG_EVENT_PROCESSOR); - gtk_object_add_arg_type ("EText::text", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_TEXT); - gtk_object_add_arg_type ("EText::font", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONT); - gtk_object_add_arg_type ("EText::fontset", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FONTSET); - gtk_object_add_arg_type ("EText::font_gdk", - GTK_TYPE_GDK_FONT, GTK_ARG_READWRITE, ARG_FONT_GDK); - gtk_object_add_arg_type ("EText::anchor", - GTK_TYPE_ANCHOR_TYPE, GTK_ARG_READWRITE, ARG_ANCHOR); - gtk_object_add_arg_type ("EText::justification", - GTK_TYPE_JUSTIFICATION, GTK_ARG_READWRITE, ARG_JUSTIFICATION); - gtk_object_add_arg_type ("EText::clip_width", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_CLIP_WIDTH); - gtk_object_add_arg_type ("EText::clip_height", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_CLIP_HEIGHT); - gtk_object_add_arg_type ("EText::clip", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_CLIP); - gtk_object_add_arg_type ("EText::fill_clip_rectangle", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_FILL_CLIP_RECTANGLE); - gtk_object_add_arg_type ("EText::x_offset", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_X_OFFSET); - gtk_object_add_arg_type ("EText::y_offset", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_Y_OFFSET); - gtk_object_add_arg_type ("EText::fill_color", - GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_FILL_COLOR); - gtk_object_add_arg_type ("EText::fill_color_gdk", - GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_FILL_COLOR_GDK); - gtk_object_add_arg_type ("EText::fill_color_rgba", - GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_FILL_COLOR_RGBA); - gtk_object_add_arg_type ("EText::fill_stipple", - GTK_TYPE_GDK_WINDOW, GTK_ARG_READWRITE, ARG_FILL_STIPPLE); - gtk_object_add_arg_type ("EText::text_width", - GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_TEXT_WIDTH); - gtk_object_add_arg_type ("EText::text_height", - GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_TEXT_HEIGHT); - gtk_object_add_arg_type ("EText::editable", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_EDITABLE); - gtk_object_add_arg_type ("EText::use_ellipsis", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_USE_ELLIPSIS); - gtk_object_add_arg_type ("EText::ellipsis", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_ELLIPSIS); - gtk_object_add_arg_type ("EText::line_wrap", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_LINE_WRAP); - gtk_object_add_arg_type ("EText::break_characters", - GTK_TYPE_STRING, GTK_ARG_READWRITE, ARG_BREAK_CHARACTERS); - gtk_object_add_arg_type ("EText::max_lines", - GTK_TYPE_INT, GTK_ARG_READWRITE, ARG_MAX_LINES); - gtk_object_add_arg_type ("EText::width", - GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("EText::height", - GTK_TYPE_DOUBLE, GTK_ARG_READABLE, ARG_HEIGHT); - gtk_object_add_arg_type ("EText::draw_borders", - GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_DRAW_BORDERS); - - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); - - - - klass->changed = NULL; - klass->activate = NULL; - - object_class->destroy = e_text_destroy; - object_class->set_arg = e_text_set_arg; - object_class->get_arg = e_text_get_arg; - - item_class->update = e_text_update; - item_class->realize = e_text_realize; - item_class->unrealize = e_text_unrealize; - item_class->draw = e_text_draw; - item_class->point = e_text_point; - item_class->bounds = e_text_bounds; - item_class->render = e_text_render; - item_class->event = e_text_event; -} - -/* Object initialization function for the text item */ -static void -e_text_init (EText *text) -{ - text->text = NULL; - text->model = e_text_model_new(); - gtk_object_ref(GTK_OBJECT(text->model)); - gtk_object_sink(GTK_OBJECT(text->model)); - text->model_changed_signal_id = - gtk_signal_connect(GTK_OBJECT(text->model), - "changed", - GTK_SIGNAL_FUNC(e_text_text_model_changed), - text); - - text->anchor = GTK_ANCHOR_CENTER; - text->justification = GTK_JUSTIFY_LEFT; - text->clip_width = -1.0; - text->clip_height = -1.0; - text->xofs = 0.0; - text->yofs = 0.0; - - text->ellipsis = NULL; - text->use_ellipsis = FALSE; - text->ellipsis_width = 0; - - text->editable = FALSE; - text->editing = FALSE; - text->xofs_edit = 0; - text->yofs_edit = 0; - - text->selection_start = 0; - text->selection_end = 0; - text->select_by_word = FALSE; - - text->timeout_id = 0; - text->timer = NULL; - - text->lastx = 0; - text->lasty = 0; - text->last_state = 0; - - text->scroll_start = 0; - text->show_cursor = TRUE; - text->button_down = FALSE; - - text->tep = NULL; - text->tep_command_id = 0; - - text->has_selection = FALSE; - - text->invisible = NULL; - text->primary_selection = NULL; - text->primary_length = 0; - text->clipboard_selection = NULL; - text->clipboard_length = 0; - - text->pointer_in = FALSE; - text->default_cursor_shown = TRUE; - - text->line_wrap = FALSE; - text->break_characters = NULL; - text->max_lines = -1; - - text->tooltip_timeout = 0; - text->tooltip_count = 0; - - text->dbl_timeout = 0; - text->tpl_timeout = 0; - - e_canvas_item_set_reflow_callback(GNOME_CANVAS_ITEM(text), e_text_reflow); -} - -/* Destroy handler for the text item */ -static void -e_text_destroy (GtkObject *object) -{ - EText *text; - - g_return_if_fail (object != NULL); - g_return_if_fail (E_IS_TEXT (object)); - - text = E_TEXT (object); - - if (text->model_changed_signal_id) - gtk_signal_disconnect(GTK_OBJECT(text->model), - text->model_changed_signal_id); - - if (text->model) - gtk_object_unref(GTK_OBJECT(text->model)); - - if (text->tep_command_id) - gtk_signal_disconnect(GTK_OBJECT(text->tep), - text->tep_command_id); - - if (text->tep) - gtk_object_unref (GTK_OBJECT(text->tep)); - - if (text->invisible) - gtk_object_unref (GTK_OBJECT(text->invisible)); - - if (text->lines) - g_free (text->lines); - - if (text->font) - e_font_unref (text->font); - -#if 0 - if (text->suckfont) - e_suck_font_free (text->suckfont); -#endif - - if (text->stipple) - gdk_bitmap_unref (text->stipple); - - if (text->timeout_id) { - g_source_remove(text->timeout_id); - text->timeout_id = 0; - } - - if (text->timer) { - g_timer_stop(text->timer); - g_timer_destroy(text->timer); - text->timer = NULL; - } - - if ( text->tooltip_timeout ) { - gtk_timeout_remove (text->tooltip_timeout); - text->tooltip_timeout = 0; - } - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -static void -e_text_text_model_changed (ETextModel *model, EText *text) -{ - text->text = e_text_model_get_text(model); - e_text_free_lines(text); - gtk_signal_emit (GTK_OBJECT (text), e_text_signals[E_TEXT_CHANGED]); - text->needs_split_into_lines = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(text)); -} - -static void -get_bounds_item_relative (EText *text, double *px1, double *py1, double *px2, double *py2) -{ - GnomeCanvasItem *item; - double x, y; - double clip_x, clip_y; - int old_height; - - item = GNOME_CANVAS_ITEM (text); - - x = 0; - y = 0; - - clip_x = x; - clip_y = y; - - /* Calculate text dimensions */ - - old_height = text->height; - - if (text->text && text->font) - text->height = (e_font_ascent (text->font) + e_font_descent (text->font)) * text->num_lines; - else - text->height = 0; - - if (old_height != text->height) - e_canvas_item_request_parent_reflow(item); - - /* Anchor text */ - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - x -= text->max_width / 2; - if ( text->clip_width >= 0) - clip_x -= text->clip_width / 2; - else - clip_x -= text->width / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - x -= text->max_width; - if (text->clip_width >= 0) - clip_x -= text->clip_width; - else - clip_x -= text->width; - break; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - y -= text->height / 2; - if ( text->clip_height >= 0 ) - clip_y -= text->clip_height / 2; - else - clip_y -= text->height / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - y -= text->height; - if ( text->clip_height >= 0 ) - clip_y -= text->clip_height; - else - clip_y -= text->height; - break; - } - - /* Bounds */ - - if (text->clip) { - /* maybe do bbox intersection here? */ - *px1 = clip_x; - *py1 = clip_y; - if (text->clip_width >= 0) - *px2 = clip_x + text->clip_width; - else - *px2 = clip_x + text->width; - - if ( text->clip_height >= 0 ) - *py2 = clip_y + text->clip_height; - else - *py2 = clip_y + text->height; - } else { - *px1 = x; - *py1 = y; - *px2 = x + text->max_width; - *py2 = y + text->height; - } -} - -static void -get_bounds (EText *text, double *px1, double *py1, double *px2, double *py2) -{ - GnomeCanvasItem *item; - double wx, wy, clip_width; - - item = GNOME_CANVAS_ITEM (text); - - /* Get canvas pixel coordinates for text position */ - - wx = 0; - wy = 0; - gnome_canvas_item_i2w (item, &wx, &wy); - gnome_canvas_w2c (item->canvas, wx + text->xofs, wy + text->yofs, &text->cx, &text->cy); - - /* Calculate the width and heights */ - calc_height (text); - calc_line_widths (text); - - if (text->clip_width < 0) - clip_width = text->max_width; - else - clip_width = text->clip_width; - - /* Get canvas pixel coordinates for clip rectangle position */ - gnome_canvas_w2c (item->canvas, wx, wy, &text->clip_cx, &text->clip_cy); - text->clip_cwidth = clip_width * item->canvas->pixels_per_unit; - if ( text->clip_height >= 0 ) - text->clip_cheight = text->clip_height * item->canvas->pixels_per_unit; - else - text->clip_cheight = text->height * item->canvas->pixels_per_unit; - - /* Anchor text */ - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - text->cx -= text->max_width / 2; - text->clip_cx -= text->clip_cwidth / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - text->cx -= text->max_width; - text->clip_cx -= text->clip_cwidth; - break; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - text->cy -= text->height / 2; - text->clip_cy -= text->clip_cheight / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - text->cy -= text->height; - text->clip_cy -= text->clip_cheight; - break; - } - - /* Bounds */ - - if (text->clip) { - *px1 = text->clip_cx; - *py1 = text->clip_cy; - *px2 = text->clip_cx + text->clip_cwidth; - *py2 = text->clip_cy + text->clip_cheight; - } else { - *px1 = text->cx; - *py1 = text->cy; - *px2 = text->cx + text->max_width; - *py2 = text->cy + text->height; - } -} - -static void -calc_height (EText *text) -{ - GnomeCanvasItem *item; - int old_height; - - item = GNOME_CANVAS_ITEM (text); - - /* Calculate text dimensions */ - - old_height = text->height; - - /* Make sure the text is split into lines first */ - if (text->text && text->num_lines == 0) - split_into_lines (text); - - if (text->text && text->font) - text->height = (e_font_ascent (text->font) + e_font_descent (text->font)) * text->num_lines; - else - text->height = 0; - - if (old_height != text->height) - e_canvas_item_request_parent_reflow(item); -} - -static void -calc_ellipsis (EText *text) -{ - if (text->font) - text->ellipsis_width = - e_font_utf8_text_width (text->font, E_FONT_PLAIN, - text->ellipsis ? text->ellipsis : "...", - text->ellipsis ? unicode_strlen (text->ellipsis, -1) : 3); -} - -/* Calculates the line widths (in pixels) of the text's splitted lines */ -static void -calc_line_widths (EText *text) -{ - struct line *lines; - int i; - int j; - gdouble clip_width; - - /* Make sure line has been split */ - if (text->text && text->num_lines == 0) - split_into_lines (text); - - lines = text->lines; - text->max_width = 0; - - clip_width = text->clip_width; - if (clip_width >= 0 && text->draw_borders) { - clip_width -= 6; - if (clip_width < 0) - clip_width = 0; - } - - - if (!lines) - return; - - for (i = 0; i < text->num_lines; i++) { - if (lines->length != 0) { - if (text->font) { - lines->width = e_font_utf8_text_width (text->font, E_FONT_PLAIN, - lines->text, lines->length); - lines->ellipsis_length = 0; - } else { - lines->width = 0; - } - - if (text->clip && - text->use_ellipsis && - ! text->editing && - lines->width > clip_width && - clip_width >= 0) { - if (text->font) { - lines->ellipsis_length = 0; - for (j = 0; j < lines->length; j++ ) { - if (e_font_utf8_text_width (text->font, E_FONT_PLAIN, lines->text, j) + text->ellipsis_width - <= clip_width) - lines->ellipsis_length = j; - else - break; - } - } - else - lines->ellipsis_length = 0; - lines->width = e_font_utf8_text_width (text->font, E_FONT_PLAIN, lines->text, lines->ellipsis_length) + - text->ellipsis_width; - } - else - lines->ellipsis_length = lines->length; - - if (lines->width > text->max_width) - text->max_width = lines->width; - } - - lines++; - } -} - -static void -e_text_free_lines(EText *text) -{ - if (text->lines) - g_free (text->lines); - - text->lines = NULL; - text->num_lines = 0; -} - -#define IS_BREAKCHAR(text,c) ((text)->break_characters && unicode_strchr ((text)->break_characters, (c))) -/* Splits the text of the text item into lines */ -static void -split_into_lines (EText *text) -{ - char *p, *cp; - struct line *lines; - int len; - int line_num; - char *laststart; - char *lastend; - char *linestart; - double clip_width; - unicode_char_t unival; - gint charpos; - - /* Free old array of lines */ - e_text_free_lines(text); - - if (!text->text) - return; - - /* First, count the number of lines */ - - lastend = text->text; - laststart = text->text; - linestart = text->text; - - clip_width = text->clip_width; - if (clip_width >= 0 && text->draw_borders) { - clip_width -= 6; - if (clip_width < 0) - clip_width = 0; - } - - cp = text->text; - charpos = 0; - - for (p = unicode_get_utf8 (cp, &unival); (unival && p); charpos++, cp = p, p = unicode_get_utf8 (p, &unival)) { - if (text->line_wrap && (unicode_isspace (unival) || unival == '\n')) { - if (laststart != lastend - && e_font_utf8_text_width(text->font, E_FONT_PLAIN, - linestart, - unicode_index_to_offset (linestart, cp - linestart)) - > clip_width ) { - text->num_lines ++; - linestart = laststart; - laststart = p; - lastend = cp; - } else if (unicode_isspace (unival)) { - laststart = p; - lastend = cp; - } - } else if (text->line_wrap && (IS_BREAKCHAR(text, unival))) { - if ( laststart != lastend - && unicode_index_to_offset (linestart, cp - linestart) != 1 - && e_font_utf8_text_width(text->font, E_FONT_PLAIN, - linestart, - unicode_index_to_offset (linestart, p - linestart)) - > clip_width ) { - text->num_lines ++; - linestart = laststart; - laststart = p; - lastend = p; - } else { - laststart = p; - lastend = p; - } - } - if (unival == '\n') { - text->num_lines ++; - lastend = p; - laststart = p; - linestart = p; - } - } - - /* fixme: */ - if (text->line_wrap) { - if ( p - && laststart != lastend - && e_font_utf8_text_width(text->font, E_FONT_PLAIN, - linestart, - unicode_index_to_offset (linestart, cp - linestart)) - > clip_width ) { - text->num_lines ++; - } - } - - text->num_lines++; - - if ( (!text->editing) && text->max_lines != -1 && text->num_lines > text->max_lines ) { - text->num_lines = text->max_lines; - } - - /* Allocate array of lines and calculate split positions */ - - text->lines = lines = g_new0 (struct line, text->num_lines); - len = 0; - line_num = 1; - lastend = text->text; - laststart = text->text; - - cp = text->text; - for (p = unicode_get_utf8 (cp, &unival); line_num < text->num_lines && unival; cp = p, p = unicode_get_utf8 (p, &unival)) { - gboolean handled = FALSE; - if (len == 0) - lines->text = cp; - if (text->line_wrap && (unicode_isspace (unival) || unival == '\n')) { - if (e_font_utf8_text_width(text->font, E_FONT_PLAIN, - lines->text, - unicode_index_to_offset (lines->text, cp - lines->text)) - > clip_width - && laststart != lastend) { - lines->length = unicode_index_to_offset (lines->text, lastend - lines->text); - lines++; - line_num++; - len = unicode_index_to_offset (laststart, cp - laststart); - lines->text = laststart; - laststart = p; - lastend = cp; - } else if (unicode_isspace (unival)) { - laststart = p; - lastend = cp; - len ++; - } - handled = TRUE; - } else if (text->line_wrap && (IS_BREAKCHAR(text, unival))) { - if (laststart != lastend - && unicode_index_to_offset (lines->text, cp - lines->text) != 1 - && e_font_utf8_text_width(text->font, E_FONT_PLAIN, - lines->text, - unicode_index_to_offset (lines->text, p - lines->text)) - > clip_width ) { - lines->length = unicode_index_to_offset (lines->text, lastend - lines->text); - lines++; - line_num++; - len = unicode_index_to_offset (laststart, p - laststart); - lines->text = laststart; - laststart = p; - lastend = p; - } else { - laststart = p; - lastend = p; - len ++; - } - } - if (line_num >= text->num_lines) - break; - if (unival == '\n') { - lines->length = unicode_index_to_offset (lines->text, cp - lines->text); - lines++; - line_num++; - len = 0; - lastend = p; - laststart = p; - handled = TRUE; - } - if (!handled) - len++; - } - - if ( line_num < text->num_lines && text->line_wrap ) { - if (e_font_utf8_text_width(text->font, E_FONT_PLAIN, - lines->text, - unicode_index_to_offset (lines->text, cp - lines->text)) - > clip_width - && laststart != lastend ) { - lines->length = unicode_index_to_offset (lines->text, lastend - lines->text); - lines++; - line_num++; - len = unicode_index_to_offset (laststart, cp - laststart); - lines->text = laststart; - laststart = p; - lastend = cp; - } - } - - if (len == 0) - lines->text = cp; - lines->length = unicode_strlen (lines->text, -1); -} - -/* Convenience function to set the text's GC's foreground color */ -static void -set_text_gc_foreground (EText *text) -{ - GdkColor c; - - if (!text->gc) - return; - - c.pixel = text->pixel; - gdk_gc_set_foreground (text->gc, &c); -} - -/* Sets the stipple pattern for the text */ -static void -set_stipple (EText *text, GdkBitmap *stipple, int reconfigure) -{ - if (text->stipple && !reconfigure) - gdk_bitmap_unref (text->stipple); - - text->stipple = stipple; - if (stipple && !reconfigure) - gdk_bitmap_ref (stipple); - - if (text->gc) { - if (stipple) { - gdk_gc_set_stipple (text->gc, stipple); - gdk_gc_set_fill (text->gc, GDK_STIPPLED); - } else - gdk_gc_set_fill (text->gc, GDK_SOLID); - } -} - -/* Set_arg handler for the text item */ -static void -e_text_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - GnomeCanvasItem *item; - EText *text; - GdkColor color = { 0, 0, 0, 0, }; - GdkColor *pcolor; - gboolean color_changed; - int have_pixel; - - gboolean needs_update = 0; - gboolean needs_reflow = 0; - - item = GNOME_CANVAS_ITEM (object); - text = E_TEXT (object); - - color_changed = FALSE; - have_pixel = FALSE; - - switch (arg_id) { - case ARG_MODEL: - if ( text->model_changed_signal_id ) - gtk_signal_disconnect(GTK_OBJECT(text->model), - text->model_changed_signal_id); - gtk_object_unref(GTK_OBJECT(text->model)); - text->model = E_TEXT_MODEL(GTK_VALUE_OBJECT (*arg)); - gtk_object_ref(GTK_OBJECT(text->model)); - - text->model_changed_signal_id = - gtk_signal_connect(GTK_OBJECT(text->model), - "changed", - GTK_SIGNAL_FUNC(e_text_text_model_changed), - text); - - e_text_free_lines(text); - text->text = e_text_model_get_text(text->model); - - text->needs_split_into_lines = 1; - needs_reflow = 1; - break; - - case ARG_EVENT_PROCESSOR: - if ( text->tep && text->tep_command_id ) - gtk_signal_disconnect(GTK_OBJECT(text->tep), - text->tep_command_id); - if ( text->tep ) - gtk_object_unref(GTK_OBJECT(text->tep)); - text->tep = E_TEXT_EVENT_PROCESSOR(GTK_VALUE_OBJECT (*arg)); - gtk_object_ref(GTK_OBJECT(text->tep)); - text->tep_command_id = - gtk_signal_connect(GTK_OBJECT(text->tep), - "command", - GTK_SIGNAL_FUNC(e_text_command), - text); - break; - - case ARG_TEXT: - text->num_lines = 1; - e_text_model_set_text(text->model, GTK_VALUE_STRING (*arg)); - break; - - case ARG_FONT: - if (text->font) - e_font_unref (text->font); - - text->font = e_font_from_gdk_name (GTK_VALUE_STRING (*arg)); - -#if 0 - if (item->canvas->aa) { - if (text->suckfont) - e_suck_font_free (text->suckfont); - - text->suckfont = e_suck_font (text->font); - } -#endif - - calc_ellipsis (text); - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else - text->needs_calc_line_widths = 1; - needs_reflow = 1; - break; - - case ARG_FONTSET: - if (text->font) - e_font_unref (text->font); - - text->font = e_font_from_gdk_name (GTK_VALUE_STRING (*arg)); - -#if 0 - if (item->canvas->aa) { - if (text->suckfont) - e_suck_font_free (text->suckfont); - - text->suckfont = e_suck_font (text->font); - } -#endif - - calc_ellipsis (text); - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else - text->needs_calc_line_widths = 1; - needs_reflow = 1; - break; - - case ARG_FONT_GDK: - if (text->font) - e_font_unref (text->font); - - text->font = e_font_from_gdk_font (GTK_VALUE_BOXED (*arg)); - -#if 0 - if (item->canvas->aa) { - if (text->suckfont) - e_suck_font_free (text->suckfont); - - text->suckfont = e_suck_font (text->font); - } -#endif - - calc_ellipsis (text); - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else - text->needs_calc_line_widths = 1; - needs_reflow = 1; - break; - - case ARG_ANCHOR: - text->anchor = GTK_VALUE_ENUM (*arg); - text->needs_recalc_bounds = 1; - needs_update = 1; - break; - - case ARG_JUSTIFICATION: - text->justification = GTK_VALUE_ENUM (*arg); - text->needs_redraw = 1; - needs_update = 1; - break; - - case ARG_CLIP_WIDTH: - text->clip_width = fabs (GTK_VALUE_DOUBLE (*arg)); - calc_ellipsis (text); - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else - text->needs_calc_line_widths = 1; - needs_reflow = 1; - break; - - case ARG_CLIP_HEIGHT: - text->clip_height = fabs (GTK_VALUE_DOUBLE (*arg)); - text->needs_recalc_bounds = 1; - needs_reflow = 1; - break; - - case ARG_CLIP: - text->clip = GTK_VALUE_BOOL (*arg); - calc_ellipsis (text); - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else - text->needs_calc_line_widths = 1; - needs_reflow = 1; - break; - - case ARG_FILL_CLIP_RECTANGLE: - text->fill_clip_rectangle = GTK_VALUE_BOOL (*arg); - needs_update = 1; - break; - - case ARG_X_OFFSET: - text->xofs = GTK_VALUE_DOUBLE (*arg); - text->needs_recalc_bounds = 1; - needs_update = 1; - break; - - case ARG_Y_OFFSET: - text->yofs = GTK_VALUE_DOUBLE (*arg); - text->needs_recalc_bounds = 1; - needs_update = 1; - break; - - case ARG_FILL_COLOR: - if (GTK_VALUE_STRING (*arg)) - gdk_color_parse (GTK_VALUE_STRING (*arg), &color); - - text->rgba = ((color.red & 0xff00) << 16 | - (color.green & 0xff00) << 8 | - (color.blue & 0xff00) | - 0xff); - color_changed = TRUE; - text->needs_redraw = 1; - needs_update = 1; - break; - - case ARG_FILL_COLOR_GDK: - pcolor = GTK_VALUE_BOXED (*arg); - if (pcolor) { - color = *pcolor; - gdk_color_context_query_color (item->canvas->cc, &color); - have_pixel = TRUE; - } - - text->rgba = ((color.red & 0xff00) << 16 | - (color.green & 0xff00) << 8 | - (color.blue & 0xff00) | - 0xff); - color_changed = TRUE; - text->needs_redraw = 1; - needs_update = 1; - break; - - case ARG_FILL_COLOR_RGBA: - text->rgba = GTK_VALUE_UINT (*arg); - color_changed = TRUE; - text->needs_redraw = 1; - needs_update = 1; - break; - - case ARG_FILL_STIPPLE: - set_stipple (text, GTK_VALUE_BOXED (*arg), FALSE); - text->needs_redraw = 1; - needs_update = 1; - break; - - case ARG_EDITABLE: - text->editable = GTK_VALUE_BOOL (*arg); - text->needs_redraw = 1; - needs_update = 1; - break; - - case ARG_USE_ELLIPSIS: - text->use_ellipsis = GTK_VALUE_BOOL (*arg); - text->needs_calc_line_widths = 1; - needs_reflow = 1; - break; - - case ARG_ELLIPSIS: - if (text->ellipsis) - g_free (text->ellipsis); - - text->ellipsis = g_strdup (GTK_VALUE_STRING (*arg)); - calc_ellipsis (text); - text->needs_calc_line_widths = 1; - needs_reflow = 1; - break; - - case ARG_LINE_WRAP: - text->line_wrap = GTK_VALUE_BOOL (*arg); - text->needs_split_into_lines = 1; - needs_reflow = 1; - break; - - case ARG_BREAK_CHARACTERS: - if ( text->break_characters ) { - g_free(text->break_characters); - text->break_characters = NULL; - } - if ( GTK_VALUE_STRING (*arg) ) - text->break_characters = g_strdup( GTK_VALUE_STRING (*arg) ); - text->needs_split_into_lines = 1; - needs_reflow = 1; - break; - - case ARG_MAX_LINES: - text->max_lines = GTK_VALUE_INT (*arg); - text->needs_split_into_lines = 1; - needs_reflow = 1; - break; - - case ARG_WIDTH: - text->clip_width = fabs (GTK_VALUE_DOUBLE (*arg)); - calc_ellipsis (text); - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else - text->needs_calc_line_widths = 1; - needs_reflow = 1; - break; - - case ARG_DRAW_BORDERS: - if (text->draw_borders != GTK_VALUE_BOOL (*arg)) { - text->draw_borders = GTK_VALUE_BOOL (*arg); - text->needs_calc_height = 1; - text->needs_redraw = 1; - needs_reflow = 1; - needs_update = 1; - } - break; - - default: - return; - } - - if (color_changed) { - if (have_pixel) - text->pixel = color.pixel; - else - text->pixel = gnome_canvas_get_color_pixel (item->canvas, text->rgba); - - if (!item->canvas->aa) - set_text_gc_foreground (text); - - } - - if ( needs_reflow ) - e_canvas_item_request_reflow (item); - if ( needs_update ) - gnome_canvas_item_request_update (item); -} - -/* Get_arg handler for the text item */ -static void -e_text_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - EText *text; - GdkColor *color; - - text = E_TEXT (object); - - switch (arg_id) { - case ARG_MODEL: - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(text->model); - break; - - case ARG_EVENT_PROCESSOR: - _get_tep(text); - GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(text->tep); - break; - - case ARG_TEXT: - GTK_VALUE_STRING (*arg) = g_strdup (text->text); - break; - - /* fixme: */ - case ARG_FONT_GDK: - GTK_VALUE_BOXED (*arg) = text->font; - break; - - case ARG_ANCHOR: - GTK_VALUE_ENUM (*arg) = text->anchor; - break; - - case ARG_JUSTIFICATION: - GTK_VALUE_ENUM (*arg) = text->justification; - break; - - case ARG_CLIP_WIDTH: - GTK_VALUE_DOUBLE (*arg) = text->clip_width; - break; - - case ARG_CLIP_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = text->clip_height; - break; - - case ARG_CLIP: - GTK_VALUE_BOOL (*arg) = text->clip; - break; - - case ARG_FILL_CLIP_RECTANGLE: - GTK_VALUE_BOOL (*arg) = text->fill_clip_rectangle; - break; - - case ARG_X_OFFSET: - GTK_VALUE_DOUBLE (*arg) = text->xofs; - break; - - case ARG_Y_OFFSET: - GTK_VALUE_DOUBLE (*arg) = text->yofs; - break; - - case ARG_FILL_COLOR_GDK: - color = g_new (GdkColor, 1); - color->pixel = text->pixel; - gdk_color_context_query_color (text->item.canvas->cc, color); - GTK_VALUE_BOXED (*arg) = color; - break; - - case ARG_FILL_COLOR_RGBA: - GTK_VALUE_UINT (*arg) = text->rgba; - break; - - case ARG_FILL_STIPPLE: - GTK_VALUE_BOXED (*arg) = text->stipple; - break; - - case ARG_TEXT_WIDTH: - GTK_VALUE_DOUBLE (*arg) = text->max_width / text->item.canvas->pixels_per_unit; - break; - - case ARG_TEXT_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = text->height / text->item.canvas->pixels_per_unit; - break; - - case ARG_EDITABLE: - GTK_VALUE_BOOL (*arg) = text->editable; - break; - - case ARG_USE_ELLIPSIS: - GTK_VALUE_BOOL (*arg) = text->use_ellipsis; - break; - - case ARG_ELLIPSIS: - GTK_VALUE_STRING (*arg) = g_strdup (text->ellipsis); - break; - - case ARG_LINE_WRAP: - GTK_VALUE_BOOL (*arg) = text->line_wrap; - break; - - case ARG_BREAK_CHARACTERS: - GTK_VALUE_STRING (*arg) = g_strdup (text->break_characters); - break; - - case ARG_MAX_LINES: - GTK_VALUE_INT (*arg) = text->max_lines; - break; - - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = text->clip_width; - break; - - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = text->clip && text->clip_height != -1 ? text->clip_height : text->height / text->item.canvas->pixels_per_unit; - break; - - case ARG_DRAW_BORDERS: - GTK_VALUE_BOOL (*arg) = text->draw_borders; - break; - - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -/* Update handler for the text item */ -static void -e_text_reflow (GnomeCanvasItem *item, int flags) -{ - EText *text; - - text = E_TEXT (item); - - if ( text->needs_split_into_lines ) { - split_into_lines(text); - text->needs_split_into_lines = 0; - text->needs_calc_line_widths = 1; - } - if ( text->needs_calc_line_widths ) { - int x; - int i; - struct line *lines; - gdouble clip_width; - calc_line_widths(text); - text->needs_calc_line_widths = 0; - text->needs_calc_height = 1; - text->needs_redraw = 1; - - lines = text->lines; - if ( !lines ) - return; - - for (lines = text->lines, i = 0; i < text->num_lines ; i++, lines ++) { - if (unicode_index_to_offset (text->text, lines->text - text->text) > text->selection_end) { - break; - } - } - lines --; - i--; - x = e_font_utf8_text_width(text->font, E_FONT_PLAIN, - lines->text, - text->selection_end - unicode_index_to_offset (text->text, lines->text - text->text)); - - - if (x < text->xofs_edit) { - text->xofs_edit = x; - } - - clip_width = text->clip_width; - if (clip_width >= 0 && text->draw_borders) { - clip_width -= 6; - if (clip_width < 0) - clip_width = 0; - } - - if (2 + x - clip_width > text->xofs_edit) { - text->xofs_edit = 2 + x - clip_width; - } - - if ((e_font_ascent (text->font) + e_font_descent (text->font)) * i < text->yofs_edit) - text->yofs_edit = (e_font_ascent (text->font) + e_font_descent (text->font)) * i; - - if ((e_font_ascent (text->font) + e_font_descent (text->font)) * (i + 1) - - (text->clip_height != -1 ? text->clip_height : text->height) > text->yofs_edit) - text->yofs_edit = (e_font_ascent (text->font) + e_font_descent (text->font)) * (i + 1) - - (text->clip_height != -1 ? text->clip_height : text->height); - } - if ( text->needs_calc_height ) { - calc_height (text); - gnome_canvas_item_request_update(item); - text->needs_calc_height = 0; - text->needs_recalc_bounds = 1; - } -} - -/* Update handler for the text item */ -static void -e_text_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags) -{ - EText *text; - double x1, y1, x2, y2; - ArtDRect i_bbox, c_bbox; - int i; - - text = E_TEXT (item); - - if (parent_class->update) - (* parent_class->update) (item, affine, clip_path, flags); - - if ( text->needs_recalc_bounds - || (flags & GNOME_CANVAS_UPDATE_AFFINE)) { - if (!item->canvas->aa) { - set_text_gc_foreground (text); - set_stipple (text, text->stipple, TRUE); - get_bounds (text, &x1, &y1, &x2, &y2); - if ( item->x1 != x1 || - item->x2 != x2 || - item->y1 != y1 || - 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; - text->needs_redraw = 1; - } - } else { - /* aa rendering */ - for (i = 0; i < 6; i++) - text->affine[i] = affine[i]; - get_bounds_item_relative (text, &i_bbox.x0, &i_bbox.y0, &i_bbox.x1, &i_bbox.y1); - art_drect_affine_transform (&c_bbox, &i_bbox, affine); - } - text->needs_recalc_bounds = 0; - } - if ( text->needs_redraw ) { - gnome_canvas_request_redraw (item->canvas, item->x1, item->y1, item->x2, item->y2); - text->needs_redraw = 0; - } -} - -/* Realize handler for the text item */ -static void -e_text_realize (GnomeCanvasItem *item) -{ - EText *text; - - text = E_TEXT (item); - - if (parent_class->realize) - (* parent_class->realize) (item); - - text->gc = gdk_gc_new (item->canvas->layout.bin_window); - - text->i_cursor = gdk_cursor_new (GDK_XTERM); - text->default_cursor = gdk_cursor_new (GDK_LEFT_PTR); - if (text->font == NULL) { - text->font = e_font_from_gdk_font (GTK_WIDGET(item->canvas)->style->font); - } -} - -/* Unrealize handler for the text item */ -static void -e_text_unrealize (GnomeCanvasItem *item) -{ - EText *text; - - text = E_TEXT (item); - - gdk_gc_unref (text->gc); - text->gc = NULL; - - gdk_cursor_destroy (text->i_cursor); - gdk_cursor_destroy (text->default_cursor); - - if (parent_class->unrealize) - (* parent_class->unrealize) (item); -} - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static double -get_line_xpos_item_relative (EText *text, struct line *line) -{ - double x; - - x = 0; - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - x -= text->max_width / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - x -= text->max_width; - break; - } - - switch (text->justification) { - case GTK_JUSTIFY_RIGHT: - x += text->max_width - line->width; - break; - - case GTK_JUSTIFY_CENTER: - x += (text->max_width - line->width) * 0.5; - break; - - default: - if (text->draw_borders) - x += BORDER_INDENT; - - /* For GTK_JUSTIFY_LEFT, we don't have to do anything. We do not support - * GTK_JUSTIFY_FILL, yet. - */ - break; - } - - return x; -} - -#if 0 -/* Calculates the y position of the first line of text. */ -static double -get_line_ypos_item_relative (EText *text) -{ - double y; - - y = 0; - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - y -= text->height / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - y -= text->height; - break; - } - - return y; -} -#endif - -/* Calculates the x position of the specified line of text, based on the text's justification */ -static int -get_line_xpos (EText *text, struct line *line) -{ - int x; - - x = text->cx; - - switch (text->justification) { - case GTK_JUSTIFY_RIGHT: - x += text->max_width - line->width; - break; - - case GTK_JUSTIFY_CENTER: - x += (text->max_width - line->width) / 2; - break; - - default: - if (text->draw_borders) - x += BORDER_INDENT; - /* For GTK_JUSTIFY_LEFT, we don't have to do anything. We do not support - * GTK_JUSTIFY_FILL, yet. - */ - break; - } - - - return x; -} - -static void -_get_tep(EText *text) -{ - if (!text->tep) { - text->tep = e_text_event_processor_emacs_like_new(); - gtk_object_ref (GTK_OBJECT (text->tep)); - gtk_object_sink (GTK_OBJECT (text->tep)); - text->tep_command_id = - gtk_signal_connect(GTK_OBJECT(text->tep), - "command", - GTK_SIGNAL_FUNC(e_text_command), - (gpointer) text); - } -} - -/* Draw handler for the text item */ -static void -e_text_draw (GnomeCanvasItem *item, GdkDrawable *drawable, - int x, int y, int width, int height) -{ - EText *text; - GdkRectangle rect, *clip_rect; - struct line *lines; - int i; - int xpos, ypos; - int start_char, end_char; - int sel_start, sel_end; - GdkRectangle sel_rect; - GdkGC *fg_gc; - GnomeCanvas *canvas; - - text = E_TEXT (item); - canvas = GNOME_CANVAS_ITEM(text)->canvas; - - fg_gc = GTK_WIDGET(canvas)->style->fg_gc[text->has_selection ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE]; - - if (text->draw_borders) { - gdouble thisx = 0, thisy = 0; - gdouble thiswidth, thisheight; - GtkWidget *widget = GTK_WIDGET(item->canvas); - - gtk_object_get(GTK_OBJECT(text), - "width", &thiswidth, - "height", &thisheight, - NULL); - gtk_paint_flat_box (widget->style, drawable, - GTK_WIDGET_STATE(widget), GTK_SHADOW_NONE, - NULL, widget, "entry_bg", - 0, 0, thiswidth, thisheight); - if (text->editing) { - thisx += 1; - thisy += 1; - thiswidth -= 2; - thisheight -= 2; - } - gtk_paint_shadow (widget->style, drawable, - GTK_STATE_NORMAL, GTK_SHADOW_IN, - NULL, widget, "entry", - thisx - x, thisy - y, thiswidth, thisheight); - - if (text->editing) { - gtk_paint_focus (widget->style, drawable, - NULL, widget, "entry", - - x, - y, thiswidth + 1, thisheight + 1); - } - } - - if (!text->text || !text->font) - return; - - lines = text->lines; - if ( !lines ) { - text->needs_split_into_lines = 1; - e_canvas_item_request_reflow (item); - } - - clip_rect = NULL; - if (text->clip) { - rect.x = text->clip_cx - x; - rect.y = text->clip_cy - y; - rect.width = text->clip_cwidth; - rect.height = text->clip_cheight; - - gdk_gc_set_clip_rectangle (text->gc, &rect); - gdk_gc_set_clip_rectangle (fg_gc, &rect); - clip_rect = ▭ - } - ypos = text->cy + e_font_ascent (text->font); - if (text->draw_borders) - ypos += BORDER_INDENT; - - if (text->editing) - ypos -= text->yofs_edit; - - if (text->stipple) - gnome_canvas_set_stipple_origin (item->canvas, text->gc); - - for (i = 0; i < text->num_lines; i++) { - xpos = get_line_xpos (text, lines); - if (text->editing) { - xpos -= text->xofs_edit; - start_char = unicode_index_to_offset (text->text, lines->text - text->text); - end_char = start_char + lines->length; - sel_start = text->selection_start; - sel_end = text->selection_end; - if (sel_start > sel_end ) { - sel_start ^= sel_end; - sel_end ^= sel_start; - sel_start ^= sel_end; - } - if ( sel_start < start_char ) - sel_start = start_char; - if ( sel_end > end_char ) - sel_end = end_char; - if ( sel_start < sel_end ) { - sel_rect.x = xpos - x + e_font_utf8_text_width (text->font, E_FONT_PLAIN, - lines->text, - sel_start - start_char); - sel_rect.y = ypos - y - e_font_ascent (text->font); - sel_rect.width = e_font_utf8_text_width (text->font, E_FONT_PLAIN, - lines->text + unicode_offset_to_index (lines->text, sel_start - start_char), - sel_end - sel_start); - sel_rect.height = e_font_ascent (text->font) + e_font_descent (text->font); - gtk_paint_flat_box(GTK_WIDGET(item->canvas)->style, - drawable, - text->has_selection ? - GTK_STATE_SELECTED : - GTK_STATE_ACTIVE, - GTK_SHADOW_NONE, - clip_rect, - GTK_WIDGET(item->canvas), - "text", - sel_rect.x, - sel_rect.y, - sel_rect.width, - sel_rect.height); - e_font_draw_utf8_text (drawable, - text->font, E_FONT_PLAIN, - text->gc, - xpos - x, - ypos - y, - lines->text, - sel_start - start_char); - e_font_draw_utf8_text (drawable, - text->font, E_FONT_PLAIN, - fg_gc, - xpos - x + e_font_utf8_text_width (text->font, E_FONT_PLAIN, - lines->text, - sel_start - start_char), - ypos - y, - lines->text + unicode_offset_to_index (lines->text, sel_start - start_char), - sel_end - sel_start); - e_font_draw_utf8_text (drawable, - text->font, E_FONT_PLAIN, - text->gc, - xpos - x + e_font_utf8_text_width (text->font, E_FONT_PLAIN, - lines->text, - sel_end - start_char), - ypos - y, - lines->text + unicode_offset_to_index (lines->text, sel_end - start_char), - end_char - sel_end); - } else { - e_font_draw_utf8_text (drawable, - text->font, E_FONT_PLAIN, - text->gc, - xpos - x, - ypos - y, - lines->text, - lines->length); - } - if (text->selection_start == text->selection_end && - text->selection_start >= start_char && - text->selection_start <= end_char && - text->show_cursor) { - gdk_draw_rectangle (drawable, - text->gc, - TRUE, - xpos - x + e_font_utf8_text_width (text->font, E_FONT_PLAIN, - lines->text, - sel_start - start_char), - ypos - y - e_font_ascent (text->font), - 1, - e_font_ascent (text->font) + e_font_descent (text->font)); - } - } else { - if (text->clip && text->use_ellipsis && lines->ellipsis_length < lines->length) { - e_font_draw_utf8_text (drawable, - text->font, E_FONT_PLAIN, - text->gc, - xpos - x, - ypos - y, - lines->text, - lines->ellipsis_length); - e_font_draw_utf8_text (drawable, - text->font, E_FONT_PLAIN, - text->gc, - xpos - x + lines->width - text->ellipsis_width, - ypos - y, - text->ellipsis ? text->ellipsis : "...", - text->ellipsis ? unicode_strlen (text->ellipsis, -1) : 3); - } else - e_font_draw_utf8_text (drawable, - text->font, E_FONT_PLAIN, - text->gc, - xpos - x, - ypos - y, - lines->text, - lines->length); - } - - ypos += e_font_ascent (text->font) + e_font_descent (text->font); - lines++; - } - - if (text->clip) { - gdk_gc_set_clip_rectangle (text->gc, NULL); - gdk_gc_set_clip_rectangle (fg_gc, NULL); - } -} - -/* Render handler for the text item */ -static void -e_text_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf) -{ -#if 0 - EText *text; - guint32 fg_color; - double xpos, ypos; - struct line *lines; - int i, j; - double affine[6]; - int dx, dy; - ArtPoint start_i, start_c; - - text = E_TEXT (item); - - if (!text->text || !text->font || !text->suckfont) - return; - - suckfont = text->suckfont; - - fg_color = text->rgba; - - gnome_canvas_buf_ensure_buf (buf); - - lines = text->lines; - if ( !lines ) - return; - - start_i.y = get_line_ypos_item_relative (text); - - art_affine_scale (affine, item->canvas->pixels_per_unit, item->canvas->pixels_per_unit); - for (i = 0; i < 6; i++) - affine[i] = text->affine[i]; - - for (i = 0; i < text->num_lines; i++) { - if (lines->length != 0) { - start_i.x = get_line_xpos_item_relative (text, lines); - art_affine_point (&start_c, &start_i, text->affine); - xpos = start_c.x; - ypos = start_c.y; - - for (j = 0; j < lines->length; j++) { - ETextSuckChar *ch; - - ch = &suckfont->chars[(unsigned char)((lines->text)[j])]; - - affine[4] = xpos; - affine[5] = ypos; - art_rgb_bitmap_affine ( - buf->buf, - buf->rect.x0, buf->rect.y0, buf->rect.x1, buf->rect.y1, - buf->buf_rowstride, - suckfont->bitmap + (ch->bitmap_offset >> 3), - ch->width, - suckfont->bitmap_height, - suckfont->bitmap_width >> 3, - fg_color, - affine, - ART_FILTER_NEAREST, NULL); - - dx = ch->left_sb + ch->width + ch->right_sb; - xpos += dx * affine[0]; - ypos += dx * affine[1]; - } - } - - dy = text->font->ascent + text->font->descent; - start_i.y += dy; - lines++; - } - - buf->is_bg = 0; -#endif -} - -/* Point handler for the text item */ -static double -e_text_point (GnomeCanvasItem *item, double x, double y, - int cx, int cy, GnomeCanvasItem **actual_item) -{ - EText *text; - int i; - struct line *lines; - int x1, y1, x2, y2; - int font_height; - int dx, dy; - double dist, best; - - text = E_TEXT (item); - - *actual_item = item; - - /* The idea is to build bounding rectangles for each of the lines of - * text (clipped by the clipping rectangle, if it is activated) and see - * whether the point is inside any of these. If it is, we are done. - * Otherwise, calculate the distance to the nearest rectangle. - */ - - if (text->font) - font_height = e_font_ascent (text->font) + e_font_descent (text->font); - else - font_height = 0; - - best = 1.0e36; - - lines = text->lines; - - if (text->fill_clip_rectangle) { - double clip_width; - double clip_height; - - /* Calculate the width and heights */ - calc_height (text); - calc_line_widths (text); - - if (text->clip_width < 0) - clip_width = text->max_width; - else - clip_width = text->clip_width; - - /* Get canvas pixel coordinates for clip rectangle position */ - clip_width = clip_width * item->canvas->pixels_per_unit; - if ( text->clip_height >= 0 ) - clip_height = text->clip_height * item->canvas->pixels_per_unit; - else - clip_height = text->height * item->canvas->pixels_per_unit; - - if (cx >= text->clip_cx && - cx <= text->clip_cx + clip_width && - cy >= text->clip_cy && - cy <= text->clip_cy + clip_height) - return 0; - else - return 1; - } - - for (i = 0; i < text->num_lines; i++) { - /* Compute the coordinates of rectangle for the current line, - * clipping if appropriate. - */ - - x1 = get_line_xpos (text, lines); - y1 = text->cy + i * font_height; - x2 = x1 + lines->width; - y2 = y1 + font_height; - - if (text->clip) { - if (x1 < text->clip_cx) - x1 = text->clip_cx; - - if (y1 < text->clip_cy) - y1 = text->clip_cy; - - if ( text->clip_width >= 0 ) { - if (x2 > (text->clip_cx + text->clip_width)) - x2 = text->clip_cx + text->clip_width; - } - - if ( text->clip_height >= 0 ) { - if (y2 > (text->clip_cy + text->clip_height)) - y2 = text->clip_cy + text->clip_height; - } - - if ((x1 >= x2) || (y1 >= y2)) - continue; - } - - /* Calculate distance from point to rectangle */ - - if (cx < x1) - dx = x1 - cx; - else if (cx >= x2) - dx = cx - x2 + 1; - else - dx = 0; - - if (cy < y1) - dy = y1 - cy; - else if (cy >= y2) - dy = cy - y2 + 1; - else - dy = 0; - - if ((dx == 0) && (dy == 0)) - return 0.0; - - dist = sqrt (dx * dx + dy * dy); - if (dist < best) - best = dist; - - /* Next! */ - - lines++; - } - - return best / item->canvas->pixels_per_unit; -} - -/* Bounds handler for the text item */ -static void -e_text_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2) -{ - EText *text; - double width, height; - - text = E_TEXT (item); - - *x1 = 0; - *y1 = 0; - - if (text->clip) { - width = text->clip_width; - if ( text->clip_height >= 0 ) - height = text->clip_height; - else height = text->height; - } else { - width = text->max_width / item->canvas->pixels_per_unit; - height = text->height / item->canvas->pixels_per_unit; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - *x1 -= width / 2.0; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - *x1 -= width; - break; - } - - switch (text->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - *y1 -= height / 2.0; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - *y1 -= height; - break; - } - - *x2 = *x1 + width; - *y2 = *y1 + height; -} - -static void -_get_xy_from_position (EText *text, gint position, gint *xp, gint *yp) -{ - if ( !text->lines ) - return; - if (xp || yp) { - struct line *lines = NULL; - int x, y; - double xd, yd; - int j; - x = get_line_xpos_item_relative (text, lines); - y = text->yofs; - y -= text->yofs_edit; - for (j = 0, lines = text->lines; j < text->num_lines; lines++, j++) { - if (lines->text > text->text + position) - break; - y += e_font_height (text->font); - } - lines --; - y -= e_font_descent (text->font); - - x += e_font_utf8_text_width (text->font, E_FONT_PLAIN, - lines->text, - position - unicode_index_to_offset (text->text, lines->text - text->text)); - x -= text->xofs_edit; - - xd = x; yd = y; - gnome_canvas_item_i2w (GNOME_CANVAS_ITEM(text), &xd, &yd); - gnome_canvas_w2c (GNOME_CANVAS_ITEM(text)->canvas, xd, yd, &x, &y); - - if (xp) - *xp = x; - if (yp) - *yp = y; - } -} - -static gint -_get_position_from_xy (EText *text, gint x, gint y) -{ - int i, j; - int ypos = text->yofs; - int xpos; - double xd, yd; - char *p; - unicode_char_t unival; - - struct line *lines; - - xd = x; yd = y; - gnome_canvas_c2w (GNOME_CANVAS_ITEM(text)->canvas, xd, yd, &xd, &yd); - gnome_canvas_item_w2i (GNOME_CANVAS_ITEM(text), &xd, &yd); - x = xd; y = yd; - - y += text->yofs_edit; - - if (text->draw_borders) - ypos += BORDER_INDENT; - - j = 0; - while (y > ypos) { - ypos += e_font_height (text->font); - j ++; - } - j--; - if (j >= text->num_lines) - j = text->num_lines - 1; - if (j < 0) - j = 0; - i = 0; - lines = text->lines; - - if ( !lines ) - return 0; - - lines += j; - x += text->xofs_edit; - xpos = get_line_xpos_item_relative (text, lines); - - for (i = 0, p = lines->text; i < lines->length; i++, p = unicode_get_utf8 (p, &unival)) { - int charwidth; - - charwidth = e_font_utf8_text_width (text->font, E_FONT_PLAIN, p, 1); - xpos += charwidth / 2; - if (xpos > x) { - break; - } - xpos += (charwidth + 1) / 2; - } - return unicode_index_to_offset (text->text, p - text->text); -} - -#define SCROLL_WAIT_TIME 30000 - -static gboolean -_blink_scroll_timeout (gpointer data) -{ - EText *text = E_TEXT(data); - gulong current_time; - gboolean scroll = FALSE; - gboolean redraw = FALSE; - - g_timer_elapsed(text->timer, ¤t_time); - - if (text->scroll_start + SCROLL_WAIT_TIME > 1000000) { - if (current_time > text->scroll_start - (1000000 - SCROLL_WAIT_TIME) && - current_time < text->scroll_start) - scroll = TRUE; - } else { - if (current_time > text->scroll_start + SCROLL_WAIT_TIME || - current_time < text->scroll_start) - scroll = TRUE; - } - if (scroll && text->button_down) { - if (text->lastx - text->clip_cx > text->clip_cwidth && - text->xofs_edit < text->max_width - text->clip_cwidth) { - text->xofs_edit += 4; - if (text->xofs_edit > text->max_width - text->clip_cwidth + 1) - text->xofs_edit = text->max_width - text->clip_cwidth + 1; - redraw = TRUE; - } - if (text->lastx - text->clip_cx < 0 && - text->xofs_edit > 0) { - text->xofs_edit -= 4; - if (text->xofs_edit < 0) - text->xofs_edit = 0; - redraw = TRUE; - } - - if (text->lasty - text->clip_cy > text->clip_cheight && - text->yofs_edit < text->height - text->clip_cheight) { - text->yofs_edit += 4; - if (text->yofs_edit > text->height - text->clip_cheight + 1) - text->yofs_edit = text->height - text->clip_cheight + 1; - redraw = TRUE; - } - if (text->lasty - text->clip_cy < 0 && - text->yofs_edit > 0) { - text->yofs_edit -= 4; - if (text->yofs_edit < 0) - text->yofs_edit = 0; - redraw = TRUE; - } - - if (redraw) { - ETextEventProcessorEvent e_tep_event; - e_tep_event.type = GDK_MOTION_NOTIFY; - e_tep_event.motion.state = text->last_state; - e_tep_event.motion.time = 0; - e_tep_event.motion.position = _get_position_from_xy(text, text->lastx, text->lasty); - _get_tep(text); - e_text_event_processor_handle_event (text->tep, - &e_tep_event); - text->scroll_start = current_time; - } - } - - if (!((current_time / 500000) % 2)) { - if (!text->show_cursor) - redraw = TRUE; - text->show_cursor = TRUE; - } else { - if (text->show_cursor) - redraw = TRUE; - text->show_cursor = FALSE; - } - if (redraw) { - text->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); - } - return TRUE; -} - -static gboolean -tooltip_event(GtkWidget *tooltip, GdkEvent *event, EText *text) -{ - gint ret_val = FALSE; - switch (event->type) { - case GDK_LEAVE_NOTIFY: - if (text->tooltip_window) { - gtk_widget_destroy (text->tooltip_window); - text->tooltip_window = NULL; - } - break; - case GDK_BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - if (event->type == GDK_BUTTON_RELEASE) { - if (text->tooltip_window) { - gtk_widget_destroy (text->tooltip_window); - text->tooltip_window = NULL; - } - } - /* Forward events to the text item */ - gtk_signal_emit_by_name (GTK_OBJECT (text), "event", event, - &ret_val); - default: - break; - } - return ret_val; -} - -static gboolean -_do_tooltip (gpointer data) -{ - EText *text = E_TEXT (data); - struct line *lines; - GtkWidget *canvas; - int i; - gdouble max_width; - gboolean cut_off; - double i2c[6]; - ArtPoint origin = {0, 0}; - ArtPoint pixel_origin; - int canvas_x, canvas_y; - GnomeCanvasItem *tooltip_text; - double tooltip_width; - double tooltip_height; - double tooltip_x; - double tooltip_y; -#if 0 - double x1, x2, y1, y2; -#endif - GnomeCanvasItem *rect; - - text->tooltip_count = 0; - - lines = text->lines; - - if (text->tooltip_window || text->editing || (!lines)) { - text->tooltip_timeout = 0; - return FALSE; - } - - cut_off = FALSE; - for ( lines = text->lines, i = 0; i < text->num_lines; lines++, i++ ) { - if (lines->length > lines->ellipsis_length) { - cut_off = TRUE; - break; - } - } - if ( ! cut_off ) { - text->tooltip_timeout = 0; - return FALSE; - } - - gnome_canvas_item_i2c_affine(GNOME_CANVAS_ITEM(text), i2c); - art_affine_point (&pixel_origin, &origin, i2c); - - gdk_window_get_origin (GTK_WIDGET(GNOME_CANVAS_ITEM(text)->canvas)->window, &canvas_x, &canvas_y); - pixel_origin.x += canvas_x; - pixel_origin.y += canvas_y; - pixel_origin.x -= (int) gtk_layout_get_hadjustment(GTK_LAYOUT(GNOME_CANVAS_ITEM(text)->canvas))->value; - pixel_origin.y -= (int) gtk_layout_get_vadjustment(GTK_LAYOUT(GNOME_CANVAS_ITEM(text)->canvas))->value; - - text->tooltip_window = gtk_window_new (GTK_WINDOW_POPUP); - gtk_container_set_border_width (GTK_CONTAINER (text->tooltip_window), 1); - - canvas = e_canvas_new (); - - - - - - - - gtk_container_add (GTK_CONTAINER (text->tooltip_window), canvas); - - /* Get the longest line length */ - max_width = 0.0; - for (lines = text->lines, i = 0; i < text->num_lines; lines++, i++) { - gdouble line_width; - - line_width = e_font_utf8_text_width (text->font, E_FONT_PLAIN, lines->text, lines->length); - max_width = MAX (max_width, line_width); - } - - rect = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)), - gnome_canvas_rect_get_type (), - "x1", (double) 0, - "y1", (double) 0, - "x2", (double) max_width + 4, - "y2", (double) text->height + 4, - "fill_color", "yellow", - NULL); - - /* fixme: */ - tooltip_text = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)), - e_text_get_type (), - "anchor", GTK_ANCHOR_NW, - "font_gdk", text->font, - "text", text->text, - "editable", FALSE, - "clip_width", text->max_lines != 1 ? text->clip_width : max_width, - "clip_height", text->max_lines != 1 ? -1 : (double)text->height, - "clip", TRUE, - "line_wrap", text->line_wrap, - "justification", text->justification, - NULL); - - - - if (text->draw_borders) - e_canvas_item_move_absolute(tooltip_text, 1 + BORDER_INDENT, 1 + BORDER_INDENT); - else - e_canvas_item_move_absolute(tooltip_text, 1, 1); - - - calc_height(E_TEXT(tooltip_text)); - calc_line_widths(E_TEXT(tooltip_text)); - gnome_canvas_item_set (tooltip_text, - "clip_height", (double) E_TEXT(tooltip_text)->height, - "clip_width", (double) E_TEXT(tooltip_text)->max_width, - NULL); - tooltip_width = E_TEXT(tooltip_text)->max_width; - tooltip_height = E_TEXT(tooltip_text)->height; - tooltip_x = 0; - tooltip_y = 0; - switch(E_TEXT(tooltip_text)->justification) { - case GTK_JUSTIFY_CENTER: - tooltip_x = - tooltip_width / 2; - break; - case GTK_JUSTIFY_RIGHT: - tooltip_x = tooltip_width / 2; - break; - case GTK_JUSTIFY_FILL: - case GTK_JUSTIFY_LEFT: - tooltip_x = 0; - break; - } - switch(E_TEXT(tooltip_text)->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - tooltip_y -= tooltip_height / 2.0; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - tooltip_y -= tooltip_height; - break; - } - switch(E_TEXT(tooltip_text)->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - tooltip_x -= tooltip_width / 2.0; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - tooltip_x -= tooltip_width; - break; - } -#if 0 - get_bounds(text, &x1, &y1, &x2, &y2); - if ( x1 < tooltip_x ) { - gnome_canvas_item_move(tooltip_text, tooltip_x - x1, 0); - tooltip_x = x1; - } - if ( y1 < tooltip_y ) { - gnome_canvas_item_move(tooltip_text, 0, tooltip_y - y1); - tooltip_y = y1; - } - if ( x2 > tooltip_x + tooltip_width ) - tooltip_width = x2 - tooltip_x; - if ( y2 > tooltip_y + tooltip_height ) - tooltip_height = y2 - tooltip_y; -#endif - - gnome_canvas_item_set(rect, - "x2", (double) tooltip_width + 4 + (text->draw_borders ? BORDER_INDENT * 2 : 0), - "y2", (double) tooltip_height + 4 + (text->draw_borders ? BORDER_INDENT * 2 : 0), - NULL); - - gtk_widget_set_usize (text->tooltip_window, - tooltip_width + 4 + (text->draw_borders ? BORDER_INDENT * 2 : 0), - tooltip_height + 4 + (text->draw_borders ? BORDER_INDENT * 2 : 0)); - gnome_canvas_set_scroll_region (GNOME_CANVAS(canvas), 0.0, 0.0, - tooltip_width + (text->draw_borders ? BORDER_INDENT * 2 : 0), - (double)tooltip_height + (text->draw_borders ? BORDER_INDENT * 2 : 0)); - gtk_widget_show (canvas); - gtk_widget_realize (text->tooltip_window); - gtk_signal_connect (GTK_OBJECT(text->tooltip_window), "event", - GTK_SIGNAL_FUNC(tooltip_event), text); - - gtk_widget_popup (text->tooltip_window, pixel_origin.x - 2 + tooltip_x, pixel_origin.y - 2 + tooltip_y); - - text->tooltip_timeout = 0; - return FALSE; -} - -static gboolean -_click (gpointer data) -{ - *(gint *)data = 0; - return FALSE; -} - -static gint -e_text_event (GnomeCanvasItem *item, GdkEvent *event) -{ - EText *text = E_TEXT(item); - ETextEventProcessorEvent e_tep_event; - - gint return_val = 0; - - e_tep_event.type = event->type; - switch (event->type) { - case GDK_FOCUS_CHANGE: - if (text->editable) { - GdkEventFocus *focus_event; - focus_event = (GdkEventFocus *) event; - if (focus_event->in) { - if(!text->editing) { - text->editing = TRUE; - if ( text->pointer_in ) { - if ( text->default_cursor_shown && (!text->draw_borders)) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->i_cursor); - text->default_cursor_shown = FALSE; - } - } - text->select_by_word = FALSE; - text->xofs_edit = 0; - text->yofs_edit = 0; - if (text->timeout_id == 0) - text->timeout_id = g_timeout_add(10, _blink_scroll_timeout, text); - text->timer = g_timer_new(); - g_timer_elapsed(text->timer, &(text->scroll_start)); - g_timer_start(text->timer); - } - } else { - text->editing = FALSE; - if ( (!text->default_cursor_shown) && (!text->draw_borders) ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->default_cursor); - text->default_cursor_shown = TRUE; - } - if (text->timeout_id) { - g_source_remove(text->timeout_id); - text->timeout_id = 0; - } - if (text->timer) { - g_timer_stop(text->timer); - g_timer_destroy(text->timer); - text->timer = NULL; - } - } - if ( text->line_wrap ) - text->needs_split_into_lines = 1; - else - text->needs_calc_line_widths = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM(text)); - } - return_val = 0; - break; - case GDK_KEY_PRESS: /* Fall Through */ - case GDK_KEY_RELEASE: - if (text->editing) { - GdkEventKey key = event->key; - e_tep_event.key.time = key.time; - e_tep_event.key.state = key.state; - e_tep_event.key.keyval = key.keyval; - e_tep_event.key.length = key.length; - e_tep_event.key.string = key.string; - _get_tep(text); - return e_text_event_processor_handle_event (text->tep, - &e_tep_event); - } - else - return 0; - break; - case GDK_BUTTON_PRESS: /* Fall Through */ - case GDK_BUTTON_RELEASE: - if (text->tooltip_timeout) { - gtk_timeout_remove (text->tooltip_timeout); - text->tooltip_timeout = 0; - } - if (text->tooltip_window) { - gtk_widget_destroy (text->tooltip_window); - text->tooltip_window = NULL; - } -#if 0 - if ((!text->editing) - && text->editable - && event->type == GDK_BUTTON_RELEASE - && event->button.button == 1) { - GdkEventButton button = event->button; - - e_canvas_item_grab_focus (item); - - e_tep_event.type = GDK_BUTTON_RELEASE; - 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(text, button.x, button.y); - _get_tep(text); - return_val = e_text_event_processor_handle_event (text->tep, - &e_tep_event); - e_tep_event.type = GDK_BUTTON_RELEASE; - } -#else - if ((!text->editing) - && text->editable - && (event->button.button == 1 || - event->button.button == 2)) { - e_canvas_item_grab_focus (item); - } -#endif - /* Create our own double and triple click events, - as gnome-canvas doesn't forward them to us */ - if (event->type == GDK_BUTTON_PRESS) { - if (text->dbl_timeout == 0 && - text->tpl_timeout == 0) { - text->dbl_timeout = gtk_timeout_add (200, - _click, - &(text->dbl_timeout)); - } else { - if (text->tpl_timeout == 0) { - e_tep_event.type = GDK_2BUTTON_PRESS; - text->tpl_timeout = gtk_timeout_add (200, _click, &(text->tpl_timeout)); - } else { - e_tep_event.type = GDK_3BUTTON_PRESS; - } - } - } - - if (text->editing) { - 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(text, button.x, button.y); - _get_tep(text); - return_val = e_text_event_processor_handle_event (text->tep, - &e_tep_event); - if (event->button.button == 1) { - if (event->type == GDK_BUTTON_PRESS) - text->button_down = TRUE; - else - text->button_down = FALSE; - } - text->lastx = button.x; - text->lasty = button.y; - text->last_state = button.state; - } - break; - case GDK_MOTION_NOTIFY: - if (text->editing) { - 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(text, motion.x, motion.y); - _get_tep(text); - return_val = e_text_event_processor_handle_event (text->tep, - &e_tep_event); - text->lastx = motion.x; - text->lasty = motion.y; - text->last_state = motion.state; - } - break; - case GDK_ENTER_NOTIFY: - { - GdkEventCrossing *crossing = (GdkEventCrossing *) event; - double x1, y1, x2, y2; - get_bounds (text, &x1, &y1, &x2, &y2); - if (crossing->x >= x1 && - crossing->y >= y1 && - crossing->x <= x2 && - crossing->y <= y2) { - if ( text->tooltip_count == 0 && text->clip) { - if (!text->tooltip_timeout) - text->tooltip_timeout = gtk_timeout_add (1000, _do_tooltip, text); - } - text->tooltip_count ++; - } - } - - text->pointer_in = TRUE; - if (text->editing || text->draw_borders) { - if ( text->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->i_cursor); - text->default_cursor_shown = FALSE; - } - } - break; - case GDK_LEAVE_NOTIFY: - if (text->tooltip_count > 0) - text->tooltip_count --; - if ( text->tooltip_count == 0 && text->clip) { - if ( text->tooltip_timeout ) { - gtk_timeout_remove (text->tooltip_timeout); - text->tooltip_timeout = 0; - } - } - - text->pointer_in = FALSE; - if (text->editing || text->draw_borders) { - if ( ! text->default_cursor_shown ) { - gdk_window_set_cursor(GTK_WIDGET(item->canvas)->window, text->default_cursor); - text->default_cursor_shown = TRUE; - } - } - break; - default: - break; - } - if (return_val) - return return_val; - if (GNOME_CANVAS_ITEM_CLASS(parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS(parent_class)->event(item, event); - else - return 0; -} - -/* fixme: */ - -static int -_get_position(EText *text, ETextEventProcessorCommand *command) -{ - int i; - int length; - int x, y; - unicode_char_t unival; - char *p; - - switch (command->position) { - - case E_TEP_VALUE: - return command->value; - - case E_TEP_SELECTION: - return text->selection_end; - - case E_TEP_START_OF_BUFFER: - return 0; - case E_TEP_END_OF_BUFFER: - return unicode_strlen (text->text, -1); - - case E_TEP_START_OF_LINE: - for (i = text->selection_end - 2; i > 0; i--) { - p = text->text + unicode_offset_to_index (text->text, i); - unicode_get_utf8 (p, &unival); - if (unival == '\n') { - i++; - break; - } - } - return i; - case E_TEP_END_OF_LINE: - length = unicode_strlen(text->text, -1); - for (i = text->selection_end + 1; i < length; i++) { - p = text->text + unicode_offset_to_index (text->text, i); - unicode_get_utf8 (p, &unival); - if (unival == '\n') { - break; - } - } - if (i > length) - i = length; - return i; - - case E_TEP_FORWARD_CHARACTER: - length = unicode_strlen (text->text, -1); - i = text->selection_end + 1; - if (i > length) - i = length; - return i; - case E_TEP_BACKWARD_CHARACTER: - i = text->selection_end - 1; - if (i < 0) - i = 0; - return i; - - case E_TEP_FORWARD_WORD: - length = unicode_strlen (text->text, -1); - for (i = text->selection_end + 1; i < length; i++) { - p = text->text + unicode_offset_to_index (text->text, i); - unicode_get_utf8 (p, &unival); - if (unicode_isspace (unival)) { - break; - } - } - if (i > length) - i = length; - return i; - case E_TEP_BACKWARD_WORD: - for (i = text->selection_end - 2; i > 0; i--) { - p = text->text + unicode_offset_to_index (text->text, i); - unicode_get_utf8 (p, &unival); - if (unicode_isspace (unival)) { - i++; - break; - } - } - if (i < 0) - i = 0; - return i; - - case E_TEP_FORWARD_LINE: - _get_xy_from_position(text, text->selection_end, &x, &y); - y += e_font_height (text->font); - return _get_position_from_xy(text, x, y); - case E_TEP_BACKWARD_LINE: - _get_xy_from_position(text, text->selection_end, &x, &y); - y -= e_font_height (text->font); - return _get_position_from_xy(text, x, y); - - case E_TEP_SELECT_WORD: - for (i = text->selection_end - 2; i > 0; i--) { - p = text->text + unicode_offset_to_index (text->text, i); - unicode_get_utf8 (p, &unival); - if (unicode_isspace (unival)) { - i++; - break; - } - } - if (i < 0) - text->selection_start = 0; - else - text->selection_start = i; - - length = unicode_strlen (text->text, -1); - for (i = text->selection_end + 1; i < length; i++) { - p = text->text + unicode_offset_to_index (text->text, i); - unicode_get_utf8 (p, &unival); - if (unicode_isspace (unival)) { - break; - } - } - if (i > length) - i = length; - return i; - - case E_TEP_SELECT_ALL: - text->selection_start = 0; - length = unicode_strlen (text->text, -1); - return length; - - case E_TEP_FORWARD_PARAGRAPH: - case E_TEP_BACKWARD_PARAGRAPH: - - case E_TEP_FORWARD_PAGE: - case E_TEP_BACKWARD_PAGE: - return text->selection_end; - default: - return text->selection_end; - } -} - -static void -_delete_selection(EText *text) -{ - if ( text->selection_start < text->selection_end ) { - e_text_model_delete(text->model, text->selection_start, text->selection_end - text->selection_start); - text->selection_end = text->selection_start; - } else { - e_text_model_delete(text->model, text->selection_end, text->selection_start - text->selection_end); - text->selection_start = text->selection_end; - } -} - -static void -_insert(EText *text, char *string, int value) -{ - if (value > 0) { - e_text_model_insert_length(text->model, text->selection_start, string, value); - - text->selection_start += value; - text->selection_end = text->selection_start; - } -} - -static void -e_text_command(ETextEventProcessor *tep, ETextEventProcessorCommand *command, gpointer data) -{ - EText *text = E_TEXT(data); - int sel_start, sel_end; - switch (command->action) { - case E_TEP_MOVE: - text->selection_start = _get_position(text, command); - text->selection_end = text->selection_start; - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_SELECT: - text->selection_end = _get_position(text, command); - sel_start = MIN(text->selection_start, text->selection_end); - sel_end = MAX(text->selection_start, text->selection_end); - if (sel_start != sel_end) { - e_text_supply_selection (text, command->time, GDK_SELECTION_PRIMARY, - text->text + unicode_offset_to_index (text->text, sel_start), sel_end - sel_start); - } else if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_DELETE: - if (text->selection_end == text->selection_start) { - text->selection_end = _get_position(text, command); - } - _delete_selection(text); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - - case E_TEP_INSERT: - if (text->selection_end != text->selection_start) { - _delete_selection(text); - } - _insert(text, command->string, command->value); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_COPY: - sel_start = MIN(text->selection_start, text->selection_end); - sel_end = MAX(text->selection_start, text->selection_end); - if (sel_start != sel_end) { - e_text_supply_selection (text, command->time, clipboard_atom, - text->text + unicode_offset_to_index (text->text, sel_start), sel_end - sel_start); - } - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_PASTE: - e_text_get_selection (text, clipboard_atom, command->time); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_GET_SELECTION: - e_text_get_selection (text, GDK_SELECTION_PRIMARY, command->time); - break; - case E_TEP_ACTIVATE: - gtk_signal_emit (GTK_OBJECT (text), e_text_signals[E_TEXT_ACTIVATE]); - if (text->timer) { - g_timer_reset(text->timer); - } - break; - case E_TEP_SET_SELECT_BY_WORD: - text->select_by_word = command->value; - break; - case E_TEP_GRAB: - gnome_canvas_item_grab (GNOME_CANVAS_ITEM(text), - GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, - text->i_cursor, - command->time); - break; - case E_TEP_UNGRAB: - gnome_canvas_item_ungrab (GNOME_CANVAS_ITEM(text), command->time); - break; - case E_TEP_NOP: - break; - } - - if (!text->button_down) { - int x; - int i; - struct line *lines = text->lines; - gdouble clip_width; - if ( !lines ) - return; - - for (lines = text->lines, i = 0; i < text->num_lines ; i++, lines ++) { - if (unicode_index_to_offset (text->text, lines->text - text->text) > text->selection_end) { - break; - } - } - lines --; - i --; - x = e_font_utf8_text_width(text->font, E_FONT_PLAIN, - lines->text, - text->selection_end - unicode_index_to_offset (text->text, lines->text - text->text)); - - - if (x < text->xofs_edit) { - text->xofs_edit = x; - } - - clip_width = text->clip_width; - if (clip_width >= 0 && text->draw_borders) { - clip_width -= 6; - if (clip_width < 0) - clip_width = 0; - } - - if (2 + x - clip_width > text->xofs_edit) { - text->xofs_edit = 2 + x - clip_width; - } - - if (e_font_height (text->font) * i < text->yofs_edit) - text->yofs_edit = e_font_height (text->font) * i; - - if (e_font_height (text->font) * (i + 1) - (text->clip_height != -1 ? text->clip_height : text->height) > text->yofs_edit) - text->yofs_edit = e_font_height (text->font) * (i + 1) - (text->clip_height != -1 ? text->clip_height : text->height); - } - - text->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); -} - -static void _invisible_destroy (GtkInvisible *invisible, - EText *text) -{ - text->invisible = NULL; -} - -static GtkWidget *e_text_get_invisible(EText *text) -{ - GtkWidget *invisible; - if (text->invisible) { - invisible = text->invisible; - } else { - invisible = gtk_invisible_new(); - text->invisible = invisible; - - gtk_selection_add_target (invisible, - GDK_SELECTION_PRIMARY, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_PRIMARY); - gtk_selection_add_target (invisible, - clipboard_atom, - GDK_SELECTION_TYPE_STRING, - E_SELECTION_CLIPBOARD); - - gtk_signal_connect (GTK_OBJECT(invisible), "selection_get", - GTK_SIGNAL_FUNC (_selection_get), - text); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_clear_event", - GTK_SIGNAL_FUNC (_selection_clear_event), - text); - gtk_signal_connect (GTK_OBJECT(invisible), "selection_received", - GTK_SIGNAL_FUNC (_selection_received), - text); - - gtk_signal_connect (GTK_OBJECT(invisible), "destroy", - GTK_SIGNAL_FUNC (_invisible_destroy), - text); - } - return invisible; -} - -static void -_selection_clear_event (GtkInvisible *invisible, - GdkEventSelection *event, - EText *text) -{ - if (event->selection == GDK_SELECTION_PRIMARY) { - g_free (text->primary_selection); - text->primary_selection = NULL; - text->primary_length = 0; - - text->has_selection = FALSE; - text->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM(text)); - - } else if (event->selection == clipboard_atom) { - g_free (text->clipboard_selection); - text->clipboard_selection = NULL; - text->clipboard_length = 0; - } -} - -static void -_selection_get (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint info, - guint time_stamp, - EText *text) -{ - switch (info) { - case E_SELECTION_PRIMARY: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, text->primary_selection, text->primary_length); - break; - case E_SELECTION_CLIPBOARD: - gtk_selection_data_set (selection_data, GDK_SELECTION_TYPE_STRING, - 8, text->clipboard_selection, text->clipboard_length); - break; - } -} - -static void -_selection_received (GtkInvisible *invisible, - GtkSelectionData *selection_data, - guint time, - EText *text) -{ - if (selection_data->length < 0 || selection_data->type != GDK_SELECTION_TYPE_STRING) { - return; - } else { - ETextEventProcessorCommand command; - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.string = selection_data->data; - command.value = selection_data->length; - command.time = time; - e_text_command(text->tep, &command, text); - } -} - -static void e_text_supply_selection (EText *text, guint time, GdkAtom selection, guchar *data, gint length) -{ - gboolean successful; - GtkWidget *invisible; - - invisible = e_text_get_invisible(text); - - if (selection == GDK_SELECTION_PRIMARY ) { - if (text->primary_selection) { - g_free (text->primary_selection); - } - text->primary_selection = g_strndup(data, length); - text->primary_length = length; - } else if (selection == clipboard_atom) { - if (text->clipboard_selection) { - g_free (text->clipboard_selection); - } - text->clipboard_selection = g_strndup(data, length); - text->clipboard_length = length; - } - - successful = gtk_selection_owner_set (invisible, - selection, - time); - - if (selection == GDK_SELECTION_PRIMARY) - text->has_selection = successful; -} - -static void -e_text_get_selection(EText *text, GdkAtom selection, guint32 time) -{ - GtkWidget *invisible; - invisible = e_text_get_invisible(text); - gtk_selection_convert(invisible, - selection, - GDK_SELECTION_TYPE_STRING, - time); -} - -#if 0 -static void -e_text_real_copy_clipboard (EText *text) -{ - guint32 time; - gint selection_start_pos; - gint selection_end_pos; - - g_return_if_fail (text != NULL); - g_return_if_fail (E_IS_TEXT (text)); - - time = gtk_text_get_event_time (text); - selection_start_pos = MIN (text->selection_start, text->selection_end); - selection_end_pos = MAX (text->selection_start, text->selection_end); - - if (selection_start_pos != selection_end_pos) - { - if (gtk_selection_owner_set (GTK_WIDGET (text->canvas), - clipboard_atom, - time)) - text->clipboard_text = ""; - } -} - -static void -e_text_real_paste_clipboard (EText *text) -{ - guint32 time; - - g_return_if_fail (text != NULL); - g_return_if_fail (E_IS_TEXT (text)); - - time = e_text_get_event_time (text); - if (text->editable) - gtk_selection_convert (GTK_WIDGET(text->widget), - clipboard_atom, - gdk_atom_intern ("COMPOUND_TEXT", FALSE), time); -} -#endif - - -#if 0 -/* Routines for sucking fonts from the X server */ - -static ETextSuckFont * -e_suck_font (GdkFont *font) -{ - ETextSuckFont *suckfont; - int i; - int x, y; - char text[1]; - int lbearing, rbearing, ch_width, ascent, descent; - GdkPixmap *pixmap; - GdkColor black, white; - GdkImage *image; - GdkGC *gc; - guchar *line; - int width, height; - int black_pixel, pixel; - - if (!font) - return NULL; - - suckfont = g_new (ETextSuckFont, 1); - - height = font->ascent + font->descent; - x = 0; - for (i = 0; i < 256; i++) { - text[0] = i; - gdk_text_extents (font, text, 1, - &lbearing, &rbearing, &ch_width, &ascent, &descent); - suckfont->chars[i].left_sb = lbearing; - suckfont->chars[i].right_sb = ch_width - rbearing; - suckfont->chars[i].width = rbearing - lbearing; - suckfont->chars[i].ascent = ascent; - suckfont->chars[i].descent = descent; - suckfont->chars[i].bitmap_offset = x; - x += (ch_width + 31) & -32; - } - - width = x; - - suckfont->bitmap_width = width; - suckfont->bitmap_height = height; - suckfont->ascent = font->ascent; - - pixmap = gdk_pixmap_new (NULL, suckfont->bitmap_width, - suckfont->bitmap_height, 1); - gc = gdk_gc_new (pixmap); - gdk_gc_set_font (gc, font); - - black_pixel = BlackPixel (gdk_display, DefaultScreen (gdk_display)); - black.pixel = black_pixel; - white.pixel = WhitePixel (gdk_display, DefaultScreen (gdk_display)); - gdk_gc_set_foreground (gc, &white); - gdk_draw_rectangle (pixmap, gc, 1, 0, 0, width, height); - - gdk_gc_set_foreground (gc, &black); - for (i = 0; i < 256; i++) { - text[0] = i; - gdk_draw_text (pixmap, font, gc, - suckfont->chars[i].bitmap_offset - suckfont->chars[i].left_sb, - font->ascent, - text, 1); - } - - /* The handling of the image leaves me with distinct unease. But this - * is more or less copied out of gimp/app/text_tool.c, so it _ought_ to - * work. -RLL - */ - - image = gdk_image_get (pixmap, 0, 0, width, height); - suckfont->bitmap = g_malloc0 ((width >> 3) * height); - - line = suckfont->bitmap; - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { - pixel = gdk_image_get_pixel (image, x, y); - if (pixel == black_pixel) - line[x >> 3] |= 128 >> (x & 7); - } - line += width >> 3; - } - - gdk_image_destroy (image); - - /* free the pixmap */ - gdk_pixmap_unref (pixmap); - - /* free the gc */ - gdk_gc_destroy (gc); - - return suckfont; -} - -static void -e_suck_font_free (ETextSuckFont *suckfont) -{ - g_free (suckfont->bitmap); - g_free (suckfont); -} -#endif - - - - - - - diff --git a/widgets/text/e-text.h b/widgets/text/e-text.h deleted file mode 100644 index 9d992fb58b..0000000000 --- a/widgets/text/e-text.h +++ /dev/null @@ -1,227 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* EText - Text item for evolution. - * Copyright (C) 2000 Helix Code, Inc. - * - * Author: Chris Lahey <clahey@umich.edu> - * - * A majority of code taken from: - * - * Text item type for GnomeCanvas widget - * - * GnomeCanvas is basically a port of the Tk toolkit's most excellent - * canvas widget. Tk is copyrighted by the Regents of the University - * of California, Sun Microsystems, and other parties. - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> */ - -#ifndef E_TEXT_H -#define E_TEXT_H - -#include <gnome.h> -#include "e-util/e-font.h" -#include "e-text-event-processor.h" -#include "e-text-model.h" - - -BEGIN_GNOME_DECLS - - -/* Text item for the canvas. Text items are positioned by an anchor point and an anchor direction. - * - * A clipping rectangle may be specified for the text. The rectangle is anchored at the text's anchor - * point, and is specified by clipping width and height parameters. If the clipping rectangle is - * enabled, it will clip the text. - * - * In addition, x and y offset values may be specified. These specify an offset from the anchor - * position. If used in conjunction with the clipping rectangle, these could be used to implement - * simple scrolling of the text within the clipping rectangle. - * - * The following object arguments are available: - * - * name type read/write description - * ------------------------------------------------------------------------------------------ - * text string RW The string of the text label - * font string W X logical font descriptor - * fontset string W X logical fontset descriptor - * font_gdk GdkFont* RW Pointer to a GdkFont - * anchor GtkAnchorType RW Anchor side for the text - * justification GtkJustification RW Justification for multiline text - * fill_color string W X color specification for text - * fill_color_gdk GdkColor* RW Pointer to an allocated GdkColor - * fill_stipple GdkBitmap* RW Stipple pattern for filling the text - * clip_width double RW Width of clip rectangle - * clip_height double RW Height of clip rectangle - * clip boolean RW Use clipping rectangle? - * fill_clip_rect boolean RW Whether the text item represents itself as being the size of the clipping rectangle. - * x_offset double RW Horizontal offset distance from anchor position - * y_offset double RW Vertical offset distance from anchor position - * text_width double R Used to query the width of the rendered text - * text_height double R Used to query the rendered height of the text - * width double RW A synonym for clip_width - * height double R A synonym for text_height - * - * These are currently ignored in the AA version: - * editable boolean RW Can this item be edited - * use_ellipsis boolean RW Whether to use ellipsises if text gets cut off. Meaningless if clip == false. - * ellipsis string RW The characters to use as ellipsis. NULL = "...". - * line_wrap boolean RW Line wrap when not editing. - * break_characters string RW List of characters to optionally break on. - * max_lines int RW Number of lines possible when doing line wrap. - * draw_borders boolean RW Whether to draw borders. - */ - -#define E_TYPE_TEXT (e_text_get_type ()) -#define E_TEXT(obj) (GTK_CHECK_CAST ((obj), E_TYPE_TEXT, EText)) -#define E_TEXT_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_TEXT, ETextClass)) -#define E_IS_TEXT(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_TEXT)) -#define E_IS_TEXT_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_TEXT)) - - -typedef struct _EText EText; -typedef struct _ETextClass ETextClass; - -#if 0 -typedef struct _ETextSuckFont ETextSuckFont; -typedef struct _ETextSuckChar ETextSuckChar; - -struct _ETextSuckChar { - int left_sb; - int right_sb; - int width; - int ascent; - int descent; - int bitmap_offset; /* in pixels */ -}; - -struct _ETextSuckFont { - guchar *bitmap; - gint bitmap_width; - gint bitmap_height; - gint ascent; - ETextSuckChar chars[256]; -}; -#endif - -struct _EText { - GnomeCanvasItem item; - - ETextModel *model; - gint model_changed_signal_id; - - char *text; /* Text to display */ - gpointer lines; /* Text split into lines (private field) */ - int num_lines; /* Number of lines of text */ - -#if 0 - GdkFont *font; /* Font for text */ -#else - EFont *font; -#endif - GtkAnchorType anchor; /* Anchor side for text */ - GtkJustification justification; /* Justification for text */ - - double clip_width; /* Width of optional clip rectangle */ - double clip_height; /* Height of optional clip rectangle */ - - double xofs, yofs; /* Text offset distance from anchor position */ - - gulong pixel; /* Fill color */ - GdkBitmap *stipple; /* Stipple for text */ - GdkGC *gc; /* GC for drawing text */ - - int cx, cy; /* Top-left canvas coordinates for text */ - int clip_cx, clip_cy; /* Top-left canvas coordinates for clip rectangle */ - int clip_cwidth, clip_cheight; /* Size of clip rectangle in pixels */ - int max_width; /* Maximum width of text lines */ - int width; /* Rendered text width in pixels */ - int height; /* Rendered text height in pixels */ - - guint clip : 1; /* Use clip rectangle? */ - guint fill_clip_rectangle : 1; /* Fill the clipping rectangle. */ - - /* Antialiased specific stuff follows */ -#if 0 - ETextSuckFont *suckfont; /* Sucked font */ -#endif - guint32 rgba; /* RGBA color for text */ - double affine[6]; /* The item -> canvas affine */ - - char *ellipsis; /* The ellipsis characters. NULL = "...". */ - double ellipsis_width; /* The width of the ellipsis. */ - gboolean use_ellipsis; /* Whether to use the ellipsis. */ - - gboolean editable; /* Item is editable */ - gboolean editing; /* Item is currently being edited */ - - int xofs_edit; /* Offset because of editing */ - int yofs_edit; /* Offset because of editing */ - - /* This needs to be reworked a bit once we get line wrapping. */ - int selection_start; /* Start of selection */ - int selection_end; /* End of selection */ - gboolean select_by_word; /* Current selection is by word */ - - /* This section is for drag scrolling and blinking cursor. */ - 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 */ - gint tep_command_id; - - GtkWidget *invisible; /* For selection handling */ - gboolean has_selection; /* TRUE if we have the selection */ - gchar *primary_selection; /* Primary selection text */ - gint primary_length; /* Primary selection text length */ - gchar *clipboard_selection; /* Clipboard selection text */ - gint clipboard_length; /* Clipboard selection text length*/ - - guint pointer_in : 1; /* Is the pointer currently over us? */ - guint default_cursor_shown : 1; /* Is the default cursor currently shown? */ - guint draw_borders : 1; /* Draw borders? */ - - guint line_wrap : 1; /* Do line wrap */ - gchar *break_characters; /* Characters to optionally break after */ - - gint max_lines; /* Max number of lines (-1 = infinite) */ - - GdkCursor *default_cursor; /* Default cursor (arrow) */ - GdkCursor *i_cursor; /* I beam cursor */ - - gint tooltip_timeout; /* Timeout for the tooltip */ - GtkWidget *tooltip_window; /* GtkWindow for displaying the tooltip */ - gint tooltip_count; /* GDK_ENTER_NOTIFY count. */ - - guint needs_redraw : 1; /* Needs redraw */ - guint needs_recalc_bounds : 1; /* Need recalc_bounds */ - guint needs_calc_height : 1; /* Need calc_height */ - guint needs_calc_line_widths : 1; /* Needs calc_line_widths */ - guint needs_split_into_lines : 1; /* Needs split_into_lines */ - - gint dbl_timeout; /* Double click timeout */ - gint tpl_timeout; /* Triple click timeout */ -}; - -struct _ETextClass { - GnomeCanvasItemClass parent_class; - - void (* changed) (EText *text); - void (* activate) (EText *text); -}; - - -/* Standard Gtk function */ -GtkType e_text_get_type (void); - - -END_GNOME_DECLS - -#endif |