From d09d8de870b6697c8a8b262e7e077b871a69b315 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 10 Dec 2012 08:09:59 -0500 Subject: Consolidate base utility libraries into libeutil. Evolution consists of entirely too many small utility libraries, which increases linking and loading time, places a burden on higher layers of the application (e.g. modules) which has to remember to link to all the small in-tree utility libraries, and makes it difficult to generate API documentation for these utility libraries in one Gtk-Doc module. Merge the following utility libraries under the umbrella of libeutil, and enforce a single-include policy on libeutil so we can reorganize the files as desired without disrupting its pseudo-public API. libemail-utils/libemail-utils.la libevolution-utils/libevolution-utils.la filter/libfilter.la widgets/e-timezone-dialog/libetimezonedialog.la widgets/menus/libmenus.la widgets/misc/libemiscwidgets.la widgets/table/libetable.la widgets/text/libetext.la This also merges libedataserverui from the Evolution-Data-Server module, since Evolution is its only consumer nowadays, and I'd like to make some improvements to those APIs without concern for backward-compatibility. And finally, start a Gtk-Doc module for libeutil. It's going to be a project just getting all the symbols _listed_ much less _documented_. But the skeletal structure is in place and I'm off to a good start. --- widgets/text/Makefile.am | 44 - widgets/text/e-reflow-model.c | 411 ---- widgets/text/e-reflow-model.h | 125 -- widgets/text/e-reflow.c | 1732 ---------------- widgets/text/e-reflow.h | 140 -- widgets/text/e-text-model-repos.c | 74 - widgets/text/e-text-model-repos.h | 54 - widgets/text/e-text-model.c | 642 ------ widgets/text/e-text-model.h | 108 - widgets/text/e-text.c | 3405 -------------------------------- widgets/text/e-text.h | 232 --- widgets/text/gal-a11y-e-text-factory.c | 103 - widgets/text/gal-a11y-e-text-factory.h | 48 - widgets/text/gal-a11y-e-text.c | 1141 ----------- widgets/text/gal-a11y-e-text.h | 55 - 15 files changed, 8314 deletions(-) delete mode 100644 widgets/text/Makefile.am delete mode 100644 widgets/text/e-reflow-model.c delete mode 100644 widgets/text/e-reflow-model.h delete mode 100644 widgets/text/e-reflow.c delete mode 100644 widgets/text/e-reflow.h delete mode 100644 widgets/text/e-text-model-repos.c delete mode 100644 widgets/text/e-text-model-repos.h delete mode 100644 widgets/text/e-text-model.c delete mode 100644 widgets/text/e-text-model.h delete mode 100644 widgets/text/e-text.c delete mode 100644 widgets/text/e-text.h delete mode 100644 widgets/text/gal-a11y-e-text-factory.c delete mode 100644 widgets/text/gal-a11y-e-text-factory.h delete mode 100644 widgets/text/gal-a11y-e-text.c delete mode 100644 widgets/text/gal-a11y-e-text.h (limited to 'widgets/text') diff --git a/widgets/text/Makefile.am b/widgets/text/Makefile.am deleted file mode 100644 index 9f8e852dd0..0000000000 --- a/widgets/text/Makefile.am +++ /dev/null @@ -1,44 +0,0 @@ -privsolib_LTLIBRARIES = libetext.la - -libetext_la_CPPFLAGS = \ - $(AM_CPPFLAGS) \ - -I$(top_srcdir) \ - -I$(top_srcdir)/widgets \ - $(EVOLUTION_DATA_SERVER_CFLAGS) \ - $(GNOME_PLATFORM_CFLAGS) \ - -DG_LOG_DOMAIN=\"e-text\" - -libetext_la_SOURCES = \ - e-text-model-repos.c \ - e-text-model.c \ - e-text.c \ - e-reflow.c \ - e-reflow-model.c \ - gal-a11y-e-text-factory.c \ - gal-a11y-e-text.c - -libetextincludedir = $(privincludedir)/text - -libetextinclude_HEADERS = \ - e-text-model-repos.h \ - e-text-model.h \ - e-text.h \ - e-reflow.h \ - e-reflow-model.h \ - gal-a11y-e-text-factory.h \ - gal-a11y-e-text.h - -libetext_la_LDFLAGS = -avoid-version $(NO_UNDEFINED) - -libetext_la_LIBADD = \ - $(top_builddir)/a11y/libevolution-a11y.la \ - $(top_builddir)/e-util/libeutil.la \ - $(top_builddir)/widgets/misc/libemiscwidgets.la \ - $(top_builddir)/libgnomecanvas/libgnomecanvas.la \ - $(top_builddir)/libemail-utils/libemail-utils.la \ - $(EVOLUTION_DATA_SERVER_LIBS) \ - $(GNOME_PLATFORM_LIBS) \ - $(REGEX_LIBS) \ - $(MATH_LIB) - --include $(top_srcdir)/git.mk diff --git a/widgets/text/e-reflow-model.c b/widgets/text/e-reflow-model.c deleted file mode 100644 index 1f7aa5e105..0000000000 --- a/widgets/text/e-reflow-model.c +++ /dev/null @@ -1,411 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Chris Lahey - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "e-util/e-util.h" - -#include "e-reflow-model.h" - -G_DEFINE_TYPE (EReflowModel, e_reflow_model, G_TYPE_OBJECT) - -#define d(x) - -d (static gint depth = 0;) - -enum { - MODEL_CHANGED, - COMPARISON_CHANGED, - MODEL_ITEMS_INSERTED, - MODEL_ITEM_CHANGED, - MODEL_ITEM_REMOVED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = { 0, }; - -/** - * e_reflow_model_set_width: - * @e_reflow_model: The e-reflow-model to operate on - * @width: The new value for the width of each item. - */ -void -e_reflow_model_set_width (EReflowModel *e_reflow_model, - gint width) -{ - EReflowModelClass *class; - - g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model)); - - class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model); - g_return_if_fail (class->set_width != NULL); - - class->set_width (e_reflow_model, width); -} - -/** - * e_reflow_model_count: - * @e_reflow_model: The e-reflow-model to operate on - * - * Returns: the number of items in the reflow model. - */ -gint -e_reflow_model_count (EReflowModel *e_reflow_model) -{ - EReflowModelClass *class; - - g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), 0); - - class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model); - g_return_val_if_fail (class->count != NULL, 0); - - return class->count (e_reflow_model); -} - -/** - * e_reflow_model_height: - * @e_reflow_model: The e-reflow-model to operate on - * @n: The item number to get the height of. - * @parent: The parent GnomeCanvasItem. - * - * Returns: the height of the nth item. - */ -gint -e_reflow_model_height (EReflowModel *e_reflow_model, - gint n, - GnomeCanvasGroup *parent) -{ - EReflowModelClass *class; - - g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), 0); - - class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model); - g_return_val_if_fail (class->height != NULL, 0); - - return class->height (e_reflow_model, n, parent); -} - -/** - * e_reflow_model_incarnate: - * @e_reflow_model: The e-reflow-model to operate on - * @n: The item to create. - * @parent: The parent GnomeCanvasItem to create a child of. - * - * Create a GnomeCanvasItem to represent the nth piece of data. - * - * Returns: the new GnomeCanvasItem. - */ -GnomeCanvasItem * -e_reflow_model_incarnate (EReflowModel *e_reflow_model, - gint n, - GnomeCanvasGroup *parent) -{ - EReflowModelClass *class; - - g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), NULL); - - class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model); - g_return_val_if_fail (class->incarnate != NULL, NULL); - - return class->incarnate (e_reflow_model, n, parent); -} - -/** - * e_reflow_model_create_cmp_cache: - * @e_reflow_model: The e-reflow-model to operate on - * - * Creates a compare cache for quicker sorting. The sorting function - * may not depend on the cache, but it should benefit from it if available. - * - * Returns: Newly created GHashTable with cached compare values. This will be - * automatically freed with g_hash_table_destroy() when no longer needed. - **/ -GHashTable * -e_reflow_model_create_cmp_cache (EReflowModel *e_reflow_model) -{ - EReflowModelClass *class; - - g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), NULL); - - class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model); - - if (class->create_cmp_cache == NULL) - return NULL; - - return class->create_cmp_cache (e_reflow_model); -} - -/** - * e_reflow_model_compare: - * @e_reflow_model: The e-reflow-model to operate on - * @n1: The first item to compare - * @n2: The second item to compare - * @cmp_cache: #GHashTable of cached compare values, created by - * e_reflow_model_create_cmp_cache(). This can be NULL, when - * caching is not available, even when @e_reflow_model defines - * the create_cmp_cache function. - * - * Compares item n1 and item n2 to see which should come first. - * - * Returns: strcmp like semantics for the comparison value. - */ -gint -e_reflow_model_compare (EReflowModel *e_reflow_model, - gint n1, - gint n2, - GHashTable *cmp_cache) -{ - EReflowModelClass *class; - - g_return_val_if_fail (E_IS_REFLOW_MODEL (e_reflow_model), 0); - - class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model); - g_return_val_if_fail (class->compare != NULL, 0); - - return class->compare (e_reflow_model, n1, n2, cmp_cache); -} - -/** - * e_reflow_model_reincarnate: - * @e_reflow_model: The e-reflow-model to operate on - * @n: The item to create. - * @item: The item to reuse. - * - * Update item to represent the nth piece of data. - */ -void -e_reflow_model_reincarnate (EReflowModel *e_reflow_model, - gint n, - GnomeCanvasItem *item) -{ - EReflowModelClass *class; - - g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model)); - - class = E_REFLOW_MODEL_GET_CLASS (e_reflow_model); - g_return_if_fail (class->reincarnate != NULL); - - class->reincarnate (e_reflow_model, n, item); -} - -static void -e_reflow_model_class_init (EReflowModelClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - - class->set_width = NULL; - class->count = NULL; - class->height = NULL; - class->incarnate = NULL; - class->reincarnate = NULL; - - class->model_changed = NULL; - class->comparison_changed = NULL; - class->model_items_inserted = NULL; - class->model_item_removed = NULL; - class->model_item_changed = NULL; - - signals[MODEL_CHANGED] = g_signal_new ( - "model_changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EReflowModelClass, model_changed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[COMPARISON_CHANGED] = g_signal_new ( - "comparison_changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EReflowModelClass, comparison_changed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[MODEL_ITEMS_INSERTED] = g_signal_new ( - "model_items_inserted", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EReflowModelClass, model_items_inserted), - NULL, NULL, - e_marshal_NONE__INT_INT, - G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_INT); - - signals[MODEL_ITEM_CHANGED] = g_signal_new ( - "model_item_changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EReflowModelClass, model_item_changed), - NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, G_TYPE_INT); - - signals[MODEL_ITEM_REMOVED] = g_signal_new ( - "model_item_removed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EReflowModelClass, model_item_removed), - NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, G_TYPE_INT); -} - -static void -e_reflow_model_init (EReflowModel *e_reflow_model) -{ -} - -#if d(!)0 -static void -print_tabs (void) -{ - gint i; - for (i = 0; i < depth; i++) - g_print ("\t"); -} -#endif - -/** - * e_reflow_model_changed: - * @e_reflow_model: the reflow model to notify of the change - * - * Use this function to notify any views of this reflow model that - * the contents of the reflow model have changed. This will emit - * the signal "model_changed" on the @e_reflow_model object. - * - * It is preferable to use the e_reflow_model_item_changed() signal to - * notify of smaller changes than to invalidate the entire model, as - * the views might have ways of caching the information they render - * from the model. - */ -void -e_reflow_model_changed (EReflowModel *e_reflow_model) -{ - g_return_if_fail (e_reflow_model != NULL); - g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model)); - - d (print_tabs ()); - d (g_print ("Emitting model_changed on model 0x%p.\n", e_reflow_model)); - d (depth++); - g_signal_emit (e_reflow_model, signals[MODEL_CHANGED], 0); - d (depth--); -} - -/** - * e_reflow_model_comparison_changed: - * @e_reflow_model: the reflow model to notify of the change - * - * Use this function to notify any views of this reflow model that the - * sorting has changed. The actual contents of the items hasn't, so - * there's no need to re-query the model for the heights of the - * individual items. - */ -void -e_reflow_model_comparison_changed (EReflowModel *e_reflow_model) -{ - g_return_if_fail (e_reflow_model != NULL); - g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model)); - - d (print_tabs ()); - d (g_print ( - "Emitting comparison_changed on model 0x%p.\n", - e_reflow_model)); - d (depth++); - g_signal_emit (e_reflow_model, signals[COMPARISON_CHANGED], 0); - d (depth--); -} - -/** - * e_reflow_model_items_inserted: - * @e_reflow_model: The model changed. - * @position: The position the items were insert in. - * @count: The number of items inserted. - * - * Use this function to notify any views of the reflow model that a number - * of items have been inserted. - **/ -void -e_reflow_model_items_inserted (EReflowModel *e_reflow_model, - gint position, - gint count) -{ - g_return_if_fail (e_reflow_model != NULL); - g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model)); - - d (print_tabs ()); - d (depth++); - g_signal_emit ( - e_reflow_model, - signals[MODEL_ITEMS_INSERTED], 0, - position, count); - d (depth--); -} - -/** - * e_reflow_model_item_removed: - * @e_reflow_model: The model changed. - * @n: The position from which the items were removed. - * - * Use this function to notify any views of the reflow model that an - * item has been removed. - **/ -void -e_reflow_model_item_removed (EReflowModel *e_reflow_model, - gint n) -{ - g_return_if_fail (e_reflow_model != NULL); - g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model)); - - d (print_tabs ()); - d (depth++); - g_signal_emit (e_reflow_model, signals[MODEL_ITEM_REMOVED], 0, n); - d (depth--); -} - -/** - * e_reflow_model_item_changed: - * @e_reflow_model: the reflow model to notify of the change - * @item: the item that was changed in the model. - * - * Use this function to notify any views of the reflow model that the - * contents of item @item have changed in model such that the height - * has changed or the item needs to be reincarnated. This function - * will emit the "model_item_changed" signal on the @e_reflow_model - * object - */ -void -e_reflow_model_item_changed (EReflowModel *e_reflow_model, - gint n) -{ - g_return_if_fail (e_reflow_model != NULL); - g_return_if_fail (E_IS_REFLOW_MODEL (e_reflow_model)); - - d (print_tabs ()); - d (g_print ("Emitting item_changed on model 0x%p, n=%d.\n", e_reflow_model, n)); - d (depth++); - g_signal_emit (e_reflow_model, signals[MODEL_ITEM_CHANGED], 0, n); - d (depth--); -} diff --git a/widgets/text/e-reflow-model.h b/widgets/text/e-reflow-model.h deleted file mode 100644 index 33cad68da0..0000000000 --- a/widgets/text/e-reflow-model.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Chris Lahey - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef _E_REFLOW_MODEL_H_ -#define _E_REFLOW_MODEL_H_ - -#include - -/* Standard GObject macros */ -#define E_TYPE_REFLOW_MODEL \ - (e_reflow_model_get_type ()) -#define E_REFLOW_MODEL(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_REFLOW_MODEL, EReflowModel)) -#define E_REFLOW_MODEL_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_REFLOW_MODEL, EReflowModelClass)) -#define E_IS_REFLOW_MODEL(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_REFLOW_MODEL)) -#define E_IS_REFLOW_MODEL_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_REFLOW_MODEL)) -#define E_REFLOW_MODEL_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_REFLOW_MODEL, EReflowModelClass)) - -G_BEGIN_DECLS - -typedef struct _EReflowModel EReflowModel; -typedef struct _EReflowModelClass EReflowModelClass; - -struct _EReflowModel { - GObject parent; -}; - -struct _EReflowModelClass { - GObjectClass parent_class; - - /* - * Virtual methods - */ - void (*set_width) (EReflowModel *etm, gint width); - - gint (*count) (EReflowModel *etm); - gint (*height) (EReflowModel *etm, gint n, GnomeCanvasGroup *parent); - GnomeCanvasItem *(*incarnate) (EReflowModel *etm, gint n, GnomeCanvasGroup *parent); - GHashTable * (*create_cmp_cache) (EReflowModel *etm); - gint (*compare) (EReflowModel *etm, gint n1, gint n2, GHashTable *cmp_cache); - void (*reincarnate) (EReflowModel *etm, gint n, GnomeCanvasItem *item); - - /* - * Signals - */ - - /* - * These all come after the change has been made. - * Major structural changes: model_changed - * Changes to the sorting of elements: comparison_changed - * Changes only in an item: item_changed - */ - void (*model_changed) (EReflowModel *etm); - void (*comparison_changed) (EReflowModel *etm); - void (*model_items_inserted) (EReflowModel *etm, gint position, gint count); - void (*model_item_removed) (EReflowModel *etm, gint position); - void (*model_item_changed) (EReflowModel *etm, gint n); -}; - -GType e_reflow_model_get_type (void); - -/**/ -void e_reflow_model_set_width (EReflowModel *e_reflow_model, - gint width); -gint e_reflow_model_count (EReflowModel *e_reflow_model); -gint e_reflow_model_height (EReflowModel *e_reflow_model, - gint n, - GnomeCanvasGroup *parent); -GnomeCanvasItem *e_reflow_model_incarnate (EReflowModel *e_reflow_model, - gint n, - GnomeCanvasGroup *parent); -GHashTable * e_reflow_model_create_cmp_cache (EReflowModel *e_reflow_model); -gint e_reflow_model_compare (EReflowModel *e_reflow_model, - gint n1, - gint n2, - GHashTable *cmp_cache); -void e_reflow_model_reincarnate (EReflowModel *e_reflow_model, - gint n, - GnomeCanvasItem *item); - -/* - * Routines for emitting signals on the e_reflow - */ -void e_reflow_model_changed (EReflowModel *e_reflow_model); -void e_reflow_model_comparison_changed (EReflowModel *e_reflow_model); -void e_reflow_model_items_inserted (EReflowModel *e_reflow_model, - gint position, - gint count); -void e_reflow_model_item_removed (EReflowModel *e_reflow_model, - gint n); -void e_reflow_model_item_changed (EReflowModel *e_reflow_model, - gint n); - -G_END_DECLS - -#endif /* _E_REFLOW_MODEL_H_ */ diff --git a/widgets/text/e-reflow.c b/widgets/text/e-reflow.c deleted file mode 100644 index faad196c83..0000000000 --- a/widgets/text/e-reflow.c +++ /dev/null @@ -1,1732 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Chris Lahey - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#include -#include - -#include "text/e-text.h" -#include -#include "e-util/e-util.h" -#include "e-util/e-unicode.h" - -#include "misc/e-canvas.h" -#include "misc/e-canvas-utils.h" -#include "e-reflow.h" -#include "misc/e-selection-model-simple.h" - -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, cairo_t *cr, - gint x, gint y, gint width, gint height); -static void e_reflow_update (GnomeCanvasItem *item, const cairo_matrix_t *i2c, gint flags); -static GnomeCanvasItem *e_reflow_point (GnomeCanvasItem *item, gdouble x, gdouble y, gint cx, gint cy); -static void e_reflow_reflow (GnomeCanvasItem *item, gint flags); -static void set_empty (EReflow *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) - -G_DEFINE_TYPE (EReflow, e_reflow, GNOME_TYPE_CANVAS_GROUP) - -enum { - PROP_0, - PROP_MINIMUM_WIDTH, - PROP_WIDTH, - PROP_HEIGHT, - PROP_EMPTY_MESSAGE, - PROP_MODEL, - PROP_COLUMN_WIDTH -}; - -enum { - SELECTION_EVENT, - COLUMN_WIDTH_CHANGED, - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = {0, }; - -static GHashTable * -er_create_cmp_cache (gpointer user_data) -{ - EReflow *reflow = user_data; - return e_reflow_model_create_cmp_cache (reflow->model); -} - -static gint -er_compare (gint i1, - gint i2, - GHashTable *cmp_cache, - gpointer user_data) -{ - EReflow *reflow = user_data; - return e_reflow_model_compare (reflow->model, i1, i2, cmp_cache); -} - -static gint -e_reflow_pick_line (EReflow *reflow, - gdouble x) -{ - x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH; - x /= reflow->column_width + E_REFLOW_FULL_GUTTER; - return x; -} - -static gint -er_find_item (EReflow *reflow, - GnomeCanvasItem *item) -{ - gint i; - for (i = 0; i < reflow->count; i++) { - if (reflow->items[i] == item) - return i; - } - return -1; -} - -static void -e_reflow_resize_children (GnomeCanvasItem *item) -{ - EReflow *reflow; - gint i; - gint count; - - reflow = E_REFLOW (item); - - count = reflow->count; - for (i = 0; i < count; i++) { - if (reflow->items[i]) - gnome_canvas_item_set ( - reflow->items[i], - "width", (gdouble) reflow->column_width, - NULL); - } -} - -static inline void -e_reflow_update_selection_row (EReflow *reflow, - gint row) -{ - if (reflow->items[row]) { - g_object_set ( - reflow->items[row], - "selected", e_selection_model_is_row_selected (E_SELECTION_MODEL (reflow->selection), row), - NULL); - } else if (e_selection_model_is_row_selected (E_SELECTION_MODEL (reflow->selection), row)) { - reflow->items[row] = e_reflow_model_incarnate (reflow->model, row, GNOME_CANVAS_GROUP (reflow)); - g_object_set ( - reflow->items[row], - "selected", e_selection_model_is_row_selected (E_SELECTION_MODEL (reflow->selection), row), - "width", (gdouble) reflow->column_width, - NULL); - } -} - -static void -e_reflow_update_selection (EReflow *reflow) -{ - gint i; - gint count; - - count = reflow->count; - for (i = 0; i < count; i++) { - e_reflow_update_selection_row (reflow, i); - } -} - -static void -selection_changed (ESelectionModel *selection, - EReflow *reflow) -{ - e_reflow_update_selection (reflow); -} - -static void -selection_row_changed (ESelectionModel *selection, - gint row, - EReflow *reflow) -{ - e_reflow_update_selection_row (reflow, row); -} - -static gboolean -do_adjustment (gpointer user_data) -{ - gint row; - GtkLayout *layout; - GtkAdjustment *adjustment; - gdouble page_size; - gdouble value, min_value, max_value; - EReflow *reflow = user_data; - - row = reflow->cursor_row; - if (row == -1) - return FALSE; - - layout = GTK_LAYOUT (GNOME_CANVAS_ITEM (reflow)->canvas); - adjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (layout)); - - value = gtk_adjustment_get_value (adjustment); - page_size = gtk_adjustment_get_page_size (adjustment); - - if ((!reflow->items) || (!reflow->items[row])) - return TRUE; - min_value = reflow->items[row]->x2 - page_size; - max_value = reflow->items[row]->x1; - - if (value < min_value) - value = min_value; - - if (value > max_value) - value = max_value; - - if (value != gtk_adjustment_get_value (adjustment)) - gtk_adjustment_set_value (adjustment, value); - - reflow->do_adjustment_idle_id = 0; - - return FALSE; -} - -static void -cursor_changed (ESelectionModel *selection, - gint row, - gint col, - EReflow *reflow) -{ - gint count = reflow->count; - gint old_cursor = reflow->cursor_row; - - if (old_cursor < count && old_cursor >= 0) { - if (reflow->items[old_cursor]) { - g_object_set ( - reflow->items[old_cursor], - "has_cursor", FALSE, - NULL); - } - } - - reflow->cursor_row = row; - - if (row < count && row >= 0) { - if (reflow->items[row]) { - g_object_set ( - reflow->items[row], - "has_cursor", TRUE, - NULL); - } else { - reflow->items[row] = e_reflow_model_incarnate (reflow->model, row, GNOME_CANVAS_GROUP (reflow)); - g_object_set ( - reflow->items[row], - "has_cursor", TRUE, - "width", (gdouble) reflow->column_width, - NULL); - } - } - - if (reflow->do_adjustment_idle_id == 0) - reflow->do_adjustment_idle_id = g_idle_add (do_adjustment, reflow); - -} - -static void -incarnate (EReflow *reflow) -{ - gint column_width; - gint first_column; - gint last_column; - gint first_cell; - gint last_cell; - gint i; - GtkLayout *layout; - GtkAdjustment *adjustment; - gdouble value; - gdouble page_size; - - layout = GTK_LAYOUT (GNOME_CANVAS_ITEM (reflow)->canvas); - adjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (layout)); - - value = gtk_adjustment_get_value (adjustment); - page_size = gtk_adjustment_get_page_size (adjustment); - - column_width = reflow->column_width; - - first_column = value - 1 + E_REFLOW_BORDER_WIDTH; - first_column /= column_width + E_REFLOW_FULL_GUTTER; - - last_column = value + page_size + 1 - E_REFLOW_BORDER_WIDTH - E_REFLOW_DIVIDER_WIDTH; - last_column /= column_width + E_REFLOW_FULL_GUTTER; - last_column++; - - if (first_column >= 0 && first_column < reflow->column_count) - first_cell = reflow->columns[first_column]; - else - first_cell = 0; - - if (last_column >= 0 && last_column < reflow->column_count) - last_cell = reflow->columns[last_column]; - else - last_cell = reflow->count; - - for (i = first_cell; i < last_cell; i++) { - gint unsorted = e_sorter_sorted_to_model (E_SORTER (reflow->sorter), i); - if (reflow->items[unsorted] == NULL) { - if (reflow->model) { - reflow->items[unsorted] = e_reflow_model_incarnate (reflow->model, unsorted, GNOME_CANVAS_GROUP (reflow)); - g_object_set ( - reflow->items[unsorted], - "selected", e_selection_model_is_row_selected (E_SELECTION_MODEL (reflow->selection), unsorted), - "width", (gdouble) reflow->column_width, - NULL); - } - } - } - reflow->incarnate_idle_id = 0; -} - -static gboolean -invoke_incarnate (gpointer user_data) -{ - EReflow *reflow = user_data; - incarnate (reflow); - return FALSE; -} - -static void -queue_incarnate (EReflow *reflow) -{ - if (reflow->incarnate_idle_id == 0) - reflow->incarnate_idle_id = - g_idle_add_full (25, invoke_incarnate, reflow, NULL); -} - -static void -reflow_columns (EReflow *reflow) -{ - GSList *list; - gint count; - gint start; - gint i; - gint column_count, column_start; - gdouble running_height; - - if (reflow->reflow_from_column <= 1) { - start = 0; - column_count = 1; - column_start = 0; - } - else { - /* we start one column before the earliest new entry, - * so we can handle the case where the new entry is - * inserted at the start of the column */ - column_start = reflow->reflow_from_column - 1; - start = reflow->columns[column_start]; - column_count = column_start + 1; - } - - list = NULL; - - running_height = E_REFLOW_BORDER_WIDTH; - - count = reflow->count - start; - for (i = start; i < count; i++) { - gint unsorted = e_sorter_sorted_to_model (E_SORTER (reflow->sorter), i); - if (i != 0 && running_height + reflow->heights[unsorted] + E_REFLOW_BORDER_WIDTH > reflow->height) { - list = g_slist_prepend (list, GINT_TO_POINTER (i)); - column_count++; - running_height = E_REFLOW_BORDER_WIDTH * 2 + reflow->heights[unsorted]; - } else - running_height += reflow->heights[unsorted] + E_REFLOW_BORDER_WIDTH; - } - - reflow->column_count = column_count; - reflow->columns = g_renew (int, reflow->columns, column_count); - column_count--; - - for (; list && column_count > column_start; column_count--) { - GSList *to_free; - reflow->columns[column_count] = GPOINTER_TO_INT (list->data); - to_free = list; - list = list->next; - g_slist_free_1 (to_free); - } - reflow->columns[column_start] = start; - - queue_incarnate (reflow); - - reflow->need_reflow_columns = FALSE; - reflow->reflow_from_column = -1; -} - -static void -item_changed (EReflowModel *model, - gint i, - EReflow *reflow) -{ - if (i < 0 || i >= reflow->count) - return; - - reflow->heights[i] = e_reflow_model_height (reflow->model, i, GNOME_CANVAS_GROUP (reflow)); - if (reflow->items[i] != NULL) - e_reflow_model_reincarnate (model, i, reflow->items[i]); - e_sorter_array_clean (reflow->sorter); - reflow->reflow_from_column = -1; - reflow->need_reflow_columns = TRUE; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (reflow)); -} - -static void -item_removed (EReflowModel *model, - gint i, - EReflow *reflow) -{ - gint c; - gint sorted; - - if (i < 0 || i >= reflow->count) - return; - - sorted = e_sorter_model_to_sorted (E_SORTER (reflow->sorter), i); - for (c = reflow->column_count - 1; c >= 0; c--) { - gint start_of_column = reflow->columns[c]; - - if (start_of_column <= sorted) { - if (reflow->reflow_from_column == -1 - || reflow->reflow_from_column > c) { - reflow->reflow_from_column = c; - } - break; - } - } - - if (reflow->items[i]) - g_object_run_dispose (G_OBJECT (reflow->items[i])); - - memmove (reflow->heights + i, reflow->heights + i + 1, (reflow->count - i - 1) * sizeof (gint)); - memmove (reflow->items + i, reflow->items + i + 1, (reflow->count - i - 1) * sizeof (GnomeCanvasItem *)); - - reflow->count--; - - reflow->heights[reflow->count] = 0; - reflow->items[reflow->count] = NULL; - - reflow->need_reflow_columns = TRUE; - set_empty (reflow); - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (reflow)); - - e_sorter_array_set_count (reflow->sorter, reflow->count); - - e_selection_model_simple_delete_rows (E_SELECTION_MODEL_SIMPLE (reflow->selection), i, 1); -} - -static void -items_inserted (EReflowModel *model, - gint position, - gint count, - EReflow *reflow) -{ - gint i, oldcount; - - if (position < 0 || position > reflow->count) - return; - - oldcount = reflow->count; - - reflow->count += count; - - if (reflow->count > reflow->allocated_count) { - while (reflow->count > reflow->allocated_count) - reflow->allocated_count += 256; - reflow->heights = g_renew (int, reflow->heights, reflow->allocated_count); - reflow->items = g_renew (GnomeCanvasItem *, reflow->items, reflow->allocated_count); - } - memmove (reflow->heights + position + count, reflow->heights + position, (reflow->count - position - count) * sizeof (gint)); - memmove (reflow->items + position + count, reflow->items + position, (reflow->count - position - count) * sizeof (GnomeCanvasItem *)); - for (i = position; i < position + count; i++) { - reflow->items[i] = NULL; - reflow->heights[i] = e_reflow_model_height (reflow->model, i, GNOME_CANVAS_GROUP (reflow)); - } - - e_selection_model_simple_set_row_count (E_SELECTION_MODEL_SIMPLE (reflow->selection), reflow->count); - if (position == oldcount) - e_sorter_array_append (reflow->sorter, count); - else - e_sorter_array_set_count (reflow->sorter, reflow->count); - - for (i = position; i < position + count; i++) { - gint sorted = e_sorter_model_to_sorted (E_SORTER (reflow->sorter), i); - gint c; - - for (c = reflow->column_count - 1; c >= 0; c--) { - gint start_of_column = reflow->columns[c]; - - if (start_of_column <= sorted) { - if (reflow->reflow_from_column == -1 - || reflow->reflow_from_column > c) { - reflow->reflow_from_column = c; - } - break; - } - } - } - - reflow->need_reflow_columns = TRUE; - set_empty (reflow); - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (reflow)); -} - -static void -model_changed (EReflowModel *model, - EReflow *reflow) -{ - gint i; - gint count; - gint oldcount; - - count = reflow->count; - oldcount = count; - - for (i = 0; i < count; i++) { - if (reflow->items[i]) - g_object_run_dispose (G_OBJECT (reflow->items[i])); - } - g_free (reflow->items); - g_free (reflow->heights); - reflow->count = e_reflow_model_count (model); - reflow->allocated_count = reflow->count; - reflow->items = g_new (GnomeCanvasItem *, reflow->count); - reflow->heights = g_new (int, reflow->count); - - count = reflow->count; - for (i = 0; i < count; i++) { - reflow->items[i] = NULL; - reflow->heights[i] = e_reflow_model_height (reflow->model, i, GNOME_CANVAS_GROUP (reflow)); - } - - e_selection_model_simple_set_row_count (E_SELECTION_MODEL_SIMPLE (reflow->selection), count); - e_sorter_array_set_count (reflow->sorter, reflow->count); - - reflow->need_reflow_columns = TRUE; - if (oldcount > reflow->count) - reflow_columns (reflow); - set_empty (reflow); - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (reflow)); -} - -static void -comparison_changed (EReflowModel *model, - EReflow *reflow) -{ - e_sorter_array_clean (reflow->sorter); - reflow->reflow_from_column = -1; - reflow->need_reflow_columns = TRUE; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (reflow)); -} - -static void -set_empty (EReflow *reflow) -{ - if (reflow->count == 0) { - if (reflow->empty_text) { - if (reflow->empty_message) { - gnome_canvas_item_set ( - reflow->empty_text, - "width", reflow->minimum_width, - "text", reflow->empty_message, - NULL); - e_canvas_item_move_absolute ( - reflow->empty_text, - reflow->minimum_width / 2, - 0); - } else { - g_object_run_dispose (G_OBJECT (reflow->empty_text)); - reflow->empty_text = NULL; - } - } else { - if (reflow->empty_message) { - reflow->empty_text = gnome_canvas_item_new ( - GNOME_CANVAS_GROUP (reflow), - e_text_get_type (), - "width", reflow->minimum_width, - "clip", TRUE, - "use_ellipsis", TRUE, - "justification", GTK_JUSTIFY_CENTER, - "text", reflow->empty_message, - NULL); - e_canvas_item_move_absolute ( - reflow->empty_text, - reflow->minimum_width / 2, - 0); - } - } - } else { - if (reflow->empty_text) { - g_object_run_dispose (G_OBJECT (reflow->empty_text)); - reflow->empty_text = NULL; - } - } -} - -static void -disconnect_model (EReflow *reflow) -{ - if (reflow->model == NULL) - return; - - g_signal_handler_disconnect ( - reflow->model, - reflow->model_changed_id); - g_signal_handler_disconnect ( - reflow->model, - reflow->comparison_changed_id); - g_signal_handler_disconnect ( - reflow->model, - reflow->model_items_inserted_id); - g_signal_handler_disconnect ( - reflow->model, - reflow->model_item_removed_id); - g_signal_handler_disconnect ( - reflow->model, - reflow->model_item_changed_id); - g_object_unref (reflow->model); - - reflow->model_changed_id = 0; - reflow->comparison_changed_id = 0; - reflow->model_items_inserted_id = 0; - reflow->model_item_removed_id = 0; - reflow->model_item_changed_id = 0; - reflow->model = NULL; -} - -static void -disconnect_selection (EReflow *reflow) -{ - if (reflow->selection == NULL) - return; - - g_signal_handler_disconnect ( - reflow->selection, - reflow->selection_changed_id); - g_signal_handler_disconnect ( - reflow->selection, - reflow->selection_row_changed_id); - g_signal_handler_disconnect ( - reflow->selection, - reflow->cursor_changed_id); - g_object_unref (reflow->selection); - - reflow->selection_changed_id = 0; - reflow->selection_row_changed_id = 0; - reflow->cursor_changed_id = 0; - reflow->selection = NULL; -} - -static void -connect_model (EReflow *reflow, - EReflowModel *model) -{ - if (reflow->model != NULL) - disconnect_model (reflow); - - if (model == NULL) - return; - - reflow->model = g_object_ref (model); - - reflow->model_changed_id = g_signal_connect ( - reflow->model, "model_changed", - G_CALLBACK (model_changed), reflow); - - reflow->comparison_changed_id = g_signal_connect ( - reflow->model, "comparison_changed", - G_CALLBACK (comparison_changed), reflow); - - reflow->model_items_inserted_id = g_signal_connect ( - reflow->model, "model_items_inserted", - G_CALLBACK (items_inserted), reflow); - - reflow->model_item_removed_id = g_signal_connect ( - reflow->model, "model_item_removed", - G_CALLBACK (item_removed), reflow); - - reflow->model_item_changed_id = g_signal_connect ( - reflow->model, "model_item_changed", - G_CALLBACK (item_changed), reflow); - - model_changed (model, reflow); -} - -static void -adjustment_changed (GtkAdjustment *adjustment, - EReflow *reflow) -{ - queue_incarnate (reflow); -} - -static void -disconnect_adjustment (EReflow *reflow) -{ - if (reflow->adjustment == NULL) - return; - - g_signal_handler_disconnect ( - reflow->adjustment, - reflow->adjustment_changed_id); - g_signal_handler_disconnect ( - reflow->adjustment, - reflow->adjustment_value_changed_id); - - g_object_unref (reflow->adjustment); - - reflow->adjustment_changed_id = 0; - reflow->adjustment_value_changed_id = 0; - reflow->adjustment = NULL; -} - -static void -connect_adjustment (EReflow *reflow, - GtkAdjustment *adjustment) -{ - if (reflow->adjustment != NULL) - disconnect_adjustment (reflow); - - if (adjustment == NULL) - return; - - reflow->adjustment = g_object_ref (adjustment); - - reflow->adjustment_changed_id = g_signal_connect ( - adjustment, "changed", - G_CALLBACK (adjustment_changed), reflow); - - reflow->adjustment_value_changed_id = g_signal_connect ( - adjustment, "value_changed", - G_CALLBACK (adjustment_changed), reflow); -} - -#if 0 -static void -set_scroll_adjustments (GtkLayout *layout, - GtkAdjustment *hadj, - GtkAdjustment *vadj, - EReflow *reflow) -{ - connect_adjustment (reflow, hadj); -} - -static void -connect_set_adjustment (EReflow *reflow) -{ - reflow->set_scroll_adjustments_id = g_signal_connect ( - GNOME_CANVAS_ITEM (reflow)->canvas, "set_scroll_adjustments", - G_CALLBACK (set_scroll_adjustments), reflow); -} -#endif - -static void -disconnect_set_adjustment (EReflow *reflow) -{ - if (reflow->set_scroll_adjustments_id != 0) { - g_signal_handler_disconnect ( - GNOME_CANVAS_ITEM (reflow)->canvas, - reflow->set_scroll_adjustments_id); - reflow->set_scroll_adjustments_id = 0; - } -} - -static void -column_width_changed (EReflow *reflow) -{ - g_signal_emit (reflow, signals[COLUMN_WIDTH_CHANGED], 0, reflow->column_width); -} - -/* Virtual functions */ -static void -e_reflow_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - GnomeCanvasItem *item; - EReflow *reflow; - - item = GNOME_CANVAS_ITEM (object); - reflow = E_REFLOW (object); - - switch (property_id) { - case PROP_HEIGHT: - reflow->height = g_value_get_double (value); - reflow->need_reflow_columns = TRUE; - e_canvas_item_request_reflow (item); - break; - case PROP_MINIMUM_WIDTH: - reflow->minimum_width = g_value_get_double (value); - if (item->flags & GNOME_CANVAS_ITEM_REALIZED) - set_empty (reflow); - e_canvas_item_request_reflow (item); - break; - case PROP_EMPTY_MESSAGE: - g_free (reflow->empty_message); - reflow->empty_message = g_strdup (g_value_get_string (value)); - if (item->flags & GNOME_CANVAS_ITEM_REALIZED) - set_empty (reflow); - break; - case PROP_MODEL: - connect_model (reflow, (EReflowModel *) g_value_get_object (value)); - break; - case PROP_COLUMN_WIDTH: - if (reflow->column_width != g_value_get_double (value)) { - GtkLayout *layout; - GtkAdjustment *adjustment; - gdouble old_width = reflow->column_width; - gdouble step_increment; - gdouble page_size; - - layout = GTK_LAYOUT (item->canvas); - adjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (layout)); - page_size = gtk_adjustment_get_page_size (adjustment); - - reflow->column_width = g_value_get_double (value); - step_increment = (reflow->column_width + - E_REFLOW_FULL_GUTTER) / 2; - gtk_adjustment_set_step_increment ( - adjustment, step_increment); - gtk_adjustment_set_page_increment ( - adjustment, page_size - step_increment); - e_reflow_resize_children (item); - e_canvas_item_request_reflow (item); - - reflow->need_column_resize = TRUE; - gnome_canvas_item_request_update (item); - - if (old_width != reflow->column_width) - column_width_changed (reflow); - } - break; - } -} - -static void -e_reflow_get_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - EReflow *reflow; - - reflow = E_REFLOW (object); - - switch (property_id) { - case PROP_MINIMUM_WIDTH: - g_value_set_double (value, reflow->minimum_width); - break; - case PROP_WIDTH: - g_value_set_double (value, reflow->width); - break; - case PROP_HEIGHT: - g_value_set_double (value, reflow->height); - break; - case PROP_EMPTY_MESSAGE: - g_value_set_string (value, reflow->empty_message); - break; - case PROP_MODEL: - g_value_set_object (value, reflow->model); - break; - case PROP_COLUMN_WIDTH: - g_value_set_double (value, reflow->column_width); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -static void -e_reflow_dispose (GObject *object) -{ - EReflow *reflow = E_REFLOW (object); - - g_free (reflow->items); - g_free (reflow->heights); - g_free (reflow->columns); - - reflow->items = NULL; - reflow->heights = NULL; - reflow->columns = NULL; - reflow->count = 0; - reflow->allocated_count = 0; - - if (reflow->incarnate_idle_id) - g_source_remove (reflow->incarnate_idle_id); - reflow->incarnate_idle_id = 0; - - if (reflow->do_adjustment_idle_id) - g_source_remove (reflow->do_adjustment_idle_id); - reflow->do_adjustment_idle_id = 0; - - disconnect_model (reflow); - disconnect_selection (reflow); - - g_free (reflow->empty_message); - reflow->empty_message = NULL; - - if (reflow->sorter) { - g_object_unref (reflow->sorter); - reflow->sorter = NULL; - } - - G_OBJECT_CLASS (e_reflow_parent_class)->dispose (object); -} - -static void -e_reflow_realize (GnomeCanvasItem *item) -{ - EReflow *reflow; - GtkAdjustment *adjustment; - gdouble page_increment; - gdouble step_increment; - gdouble page_size; - gint count; - gint i; - - reflow = E_REFLOW (item); - - if (GNOME_CANVAS_ITEM_CLASS (e_reflow_parent_class)->realize) - (* GNOME_CANVAS_ITEM_CLASS (e_reflow_parent_class)->realize) (item); - - reflow->arrow_cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW); - reflow->default_cursor = gdk_cursor_new (GDK_LEFT_PTR); - - count = reflow->count; - for (i = 0; i < count; i++) { - if (reflow->items[i]) - gnome_canvas_item_set ( - reflow->items[i], - "width", reflow->column_width, - NULL); - } - - set_empty (reflow); - - reflow->need_reflow_columns = TRUE; - e_canvas_item_request_reflow (item); - - adjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (item->canvas)); - -#if 0 - connect_set_adjustment (reflow); -#endif - connect_adjustment (reflow, adjustment); - - page_size = gtk_adjustment_get_page_size (adjustment); - step_increment = (reflow->column_width + E_REFLOW_FULL_GUTTER) / 2; - page_increment = page_size - step_increment; - gtk_adjustment_set_step_increment (adjustment, step_increment); - gtk_adjustment_set_page_increment (adjustment, page_increment); -} - -static void -e_reflow_unrealize (GnomeCanvasItem *item) -{ - EReflow *reflow; - - reflow = E_REFLOW (item); - - g_object_unref (reflow->arrow_cursor); - g_object_unref (reflow->default_cursor); - reflow->arrow_cursor = NULL; - reflow->default_cursor = NULL; - - g_free (reflow->columns); - reflow->columns = NULL; - - disconnect_set_adjustment (reflow); - disconnect_adjustment (reflow); - - if (GNOME_CANVAS_ITEM_CLASS (e_reflow_parent_class)->unrealize) - (* GNOME_CANVAS_ITEM_CLASS (e_reflow_parent_class)->unrealize) (item); -} - -static gboolean -e_reflow_event (GnomeCanvasItem *item, - GdkEvent *event) -{ - EReflow *reflow; - gint return_val = FALSE; - - reflow = E_REFLOW (item); - - switch (event->type) - { - case GDK_KEY_PRESS: - return_val = e_selection_model_key_press (reflow->selection, (GdkEventKey *) event); - break; -#if 0 - if (event->key.keyval == GDK_Tab || - event->key.keyval == GDK_KEY_KP_Tab || - event->key.keyval == GDK_ISO_Left_Tab) { - gint i; - gint count; - count = reflow->count; - for (i = 0; i < count; i++) { - gint unsorted = e_sorter_sorted_to_model (E_SORTER (reflow->sorter), i); - GnomeCanvasItem *item = reflow->items[unsorted]; - EFocus has_focus; - if (item) { - g_object_get ( - item, - "has_focus", &has_focus, - NULL); - if (has_focus) { - if (event->key.state & GDK_SHIFT_MASK) { - if (i == 0) - return FALSE; - i--; - } else { - if (i == count - 1) - return FALSE; - i++; - } - - unsorted = e_sorter_sorted_to_model (E_SORTER (reflow->sorter), i); - if (reflow->items[unsorted] == NULL) { - reflow->items[unsorted] = e_reflow_model_incarnate (reflow->model, unsorted, GNOME_CANVAS_GROUP (reflow)); - } - - item = reflow->items[unsorted]; - gnome_canvas_item_set ( - item, - "has_focus", (event->key.state & GDK_SHIFT_MASK) ? E_FOCUS_END : E_FOCUS_START, - NULL); - return TRUE; - } - } - } - } -#endif - case GDK_BUTTON_PRESS: - switch (event->button.button) - { - case 1: - { - GdkEventButton *button = (GdkEventButton *) event; - gdouble n_x; - n_x = button->x; - n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH; - n_x = fmod (n_x,(reflow->column_width + E_REFLOW_FULL_GUTTER)); - - if (button->y >= E_REFLOW_BORDER_WIDTH && button->y <= reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER) { - /* don't allow to drag the first line*/ - if (e_reflow_pick_line (reflow, button->x) == 0) - return TRUE; - reflow->which_column_dragged = e_reflow_pick_line (reflow, button->x); - reflow->start_x = reflow->which_column_dragged * (reflow->column_width + E_REFLOW_FULL_GUTTER) - E_REFLOW_DIVIDER_WIDTH / 2; - reflow->temp_column_width = reflow->column_width; - reflow->column_drag = TRUE; - - gnome_canvas_item_grab ( - item, - GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, - reflow->arrow_cursor, - button->device, - button->time); - - reflow->previous_temp_column_width = -1; - reflow->need_column_resize = TRUE; - gnome_canvas_item_request_update (item); - return TRUE; - } - } - break; - case 4: - { - GtkLayout *layout; - GtkAdjustment *adjustment; - gdouble new_value; - - layout = GTK_LAYOUT (item->canvas); - adjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (layout)); - new_value = gtk_adjustment_get_value (adjustment); - new_value -= gtk_adjustment_get_step_increment (adjustment); - gtk_adjustment_set_value (adjustment, new_value); - } - break; - case 5: - { - GtkLayout *layout; - GtkAdjustment *adjustment; - gdouble new_value; - gdouble page_size; - gdouble upper; - - layout = GTK_LAYOUT (item->canvas); - adjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (layout)); - new_value = gtk_adjustment_get_value (adjustment); - new_value += gtk_adjustment_get_step_increment (adjustment); - upper = gtk_adjustment_get_upper (adjustment); - page_size = gtk_adjustment_get_page_size (adjustment); - if (new_value > upper - page_size) - new_value = upper - page_size; - gtk_adjustment_set_value (adjustment, new_value); - } - break; - } - break; - case GDK_BUTTON_RELEASE: - if (reflow->column_drag) { - gdouble old_width = reflow->column_width; - GdkEventButton *button = (GdkEventButton *) event; - GtkAdjustment *adjustment; - GtkLayout *layout; - gdouble value; - - layout = GTK_LAYOUT (item->canvas); - adjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (layout)); - value = gtk_adjustment_get_value (adjustment); - - reflow->temp_column_width = reflow->column_width + - (button->x - reflow->start_x) / (reflow->which_column_dragged - e_reflow_pick_line (reflow, value)); - if (reflow->temp_column_width < 50) - reflow->temp_column_width = 50; - reflow->column_drag = FALSE; - if (old_width != reflow->temp_column_width) { - gdouble page_increment; - gdouble step_increment; - gdouble page_size; - - page_size = gtk_adjustment_get_page_size (adjustment); - gtk_adjustment_set_value (adjustment, value + e_reflow_pick_line (reflow, value) * (reflow->temp_column_width - reflow->column_width)); - reflow->column_width = reflow->temp_column_width; - step_increment = (reflow->column_width + E_REFLOW_FULL_GUTTER) / 2; - page_increment = page_size - step_increment; - gtk_adjustment_set_step_increment (adjustment, step_increment); - gtk_adjustment_set_page_increment (adjustment, page_increment); - e_reflow_resize_children (item); - e_canvas_item_request_reflow (item); - gnome_canvas_request_redraw (item->canvas, 0, 0, reflow->width, reflow->height); - column_width_changed (reflow); - } - 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 (reflow->column_drag) { - gdouble old_width = reflow->temp_column_width; - GdkEventMotion *motion = (GdkEventMotion *) event; - GtkAdjustment *adjustment; - GtkLayout *layout; - gdouble value; - - layout = GTK_LAYOUT (item->canvas); - adjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (layout)); - value = gtk_adjustment_get_value (adjustment); - - reflow->temp_column_width = reflow->column_width + - (motion->x - reflow->start_x) / (reflow->which_column_dragged - e_reflow_pick_line (reflow, value)); - if (reflow->temp_column_width < 50) - reflow->temp_column_width = 50; - if (old_width != reflow->temp_column_width) { - reflow->need_column_resize = TRUE; - gnome_canvas_item_request_update (item); - } - return TRUE; - } else { - GdkEventMotion *motion = (GdkEventMotion *) event; - GdkWindow *window; - gdouble n_x; - - n_x = motion->x; - n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH; - n_x = fmod (n_x,(reflow->column_width + E_REFLOW_FULL_GUTTER)); - - window = gtk_widget_get_window (GTK_WIDGET (item->canvas)); - - if (motion->y >= E_REFLOW_BORDER_WIDTH && motion->y <= reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER) { - if (reflow->default_cursor_shown) { - gdk_window_set_cursor (window, reflow->arrow_cursor); - reflow->default_cursor_shown = FALSE; - } - } else - if (!reflow->default_cursor_shown) { - gdk_window_set_cursor (window, reflow->default_cursor); - reflow->default_cursor_shown = TRUE; - } - - } - break; - case GDK_ENTER_NOTIFY: - if (!reflow->column_drag) { - GdkEventCrossing *crossing = (GdkEventCrossing *) event; - GdkWindow *window; - gdouble n_x; - - n_x = crossing->x; - n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH; - n_x = fmod (n_x,(reflow->column_width + E_REFLOW_FULL_GUTTER)); - - window = gtk_widget_get_window (GTK_WIDGET (item->canvas)); - - if (crossing->y >= E_REFLOW_BORDER_WIDTH && crossing->y <= reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER) { - if (reflow->default_cursor_shown) { - gdk_window_set_cursor (window, reflow->arrow_cursor); - reflow->default_cursor_shown = FALSE; - } - } - } - break; - case GDK_LEAVE_NOTIFY: - if (!reflow->column_drag) { - GdkEventCrossing *crossing = (GdkEventCrossing *) event; - GdkWindow *window; - gdouble n_x; - - n_x = crossing->x; - n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH; - n_x = fmod (n_x,(reflow->column_width + E_REFLOW_FULL_GUTTER)); - - window = gtk_widget_get_window (GTK_WIDGET (item->canvas)); - - if (!(crossing->y >= E_REFLOW_BORDER_WIDTH && crossing->y <= reflow->height - E_REFLOW_BORDER_WIDTH && n_x < E_REFLOW_FULL_GUTTER)) { - if (!reflow->default_cursor_shown) { - gdk_window_set_cursor (window, reflow->default_cursor); - reflow->default_cursor_shown = TRUE; - } - } - } - break; - default: - break; - } - if (return_val) - return return_val; - else if (GNOME_CANVAS_ITEM_CLASS (e_reflow_parent_class)->event) - return (* GNOME_CANVAS_ITEM_CLASS (e_reflow_parent_class)->event) (item, event); - else - return FALSE; -} - -static void -e_reflow_draw (GnomeCanvasItem *item, - cairo_t *cr, - gint x, - gint y, - gint width, - gint height) -{ - GtkStyleContext *style_context; - GtkWidget *widget; - gint x_rect, y_rect, width_rect, height_rect; - gdouble running_width; - EReflow *reflow = E_REFLOW (item); - GdkRGBA color; - gint i; - gdouble column_width; - - if (GNOME_CANVAS_ITEM_CLASS (e_reflow_parent_class)->draw) - GNOME_CANVAS_ITEM_CLASS (e_reflow_parent_class)->draw (item, cr, x, y, width, height); - column_width = reflow->column_width; - 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 = 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); - - widget = GTK_WIDGET (item->canvas); - style_context = gtk_widget_get_style_context (widget); - - cairo_save (cr); - - gtk_style_context_get_background_color ( - style_context, GTK_STATE_FLAG_ACTIVE, &color); - gdk_cairo_set_source_rgba (cr, &color); - - for (; i < reflow->column_count; i++) { - if (running_width > x + width) - break; - x_rect = running_width; - - gtk_render_background ( - style_context, cr, - (gdouble) x_rect - x, - (gdouble) y_rect - y, - (gdouble) width_rect, - (gdouble) height_rect); - - running_width += E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH; - } - - cairo_restore (cr); - - if (reflow->column_drag) { - GtkAdjustment *adjustment; - GtkLayout *layout; - gdouble value; - gint start_line; - - layout = GTK_LAYOUT (item->canvas); - adjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (layout)); - value = gtk_adjustment_get_value (adjustment); - - start_line = e_reflow_pick_line (reflow, value); - i = x - start_line * (column_width + E_REFLOW_FULL_GUTTER); - running_width = start_line * (column_width + E_REFLOW_FULL_GUTTER); - column_width = 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; - y_rect = E_REFLOW_BORDER_WIDTH; - width_rect = E_REFLOW_DIVIDER_WIDTH; - height_rect = 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); - - cairo_save (cr); - - gtk_style_context_get_color ( - style_context, GTK_STATE_FLAG_NORMAL, &color); - gdk_cairo_set_source_rgba (cr, &color); - - for (; i < reflow->column_count; i++) { - if (running_width > x + width) - break; - x_rect = running_width; - cairo_rectangle ( - cr, - x_rect - x, - y_rect - y, - width_rect - 1, - height_rect - 1); - cairo_fill (cr); - running_width += E_REFLOW_DIVIDER_WIDTH + E_REFLOW_BORDER_WIDTH + column_width + E_REFLOW_BORDER_WIDTH; - } - - cairo_restore (cr); - } -} - -static void -e_reflow_update (GnomeCanvasItem *item, - const cairo_matrix_t *i2c, - gint flags) -{ - EReflow *reflow; - gdouble x0, x1, y0, y1; - - reflow = E_REFLOW (item); - - if (GNOME_CANVAS_ITEM_CLASS (e_reflow_parent_class)->update) - GNOME_CANVAS_ITEM_CLASS (e_reflow_parent_class)->update (item, i2c, flags); - - x0 = item->x1; - y0 = item->y1; - x1 = item->x2; - y1 = item->y2; - if (x1 < x0 + reflow->width) - x1 = x0 + reflow->width; - if (y1 < y0 + reflow->height) - y1 = y0 + reflow->height; - item->x2 = x1; - item->y2 = y1; - - if (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); - reflow->need_height_update = FALSE; - } else if (reflow->need_column_resize) { - GtkLayout *layout; - GtkAdjustment *adjustment; - gint x_rect, y_rect, width_rect, height_rect; - gint start_line; - gdouble running_width; - gint i; - gdouble column_width; - gdouble value; - - layout = GTK_LAYOUT (item->canvas); - adjustment = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (layout)); - value = gtk_adjustment_get_value (adjustment); - start_line = e_reflow_pick_line (reflow, value); - - if (reflow->previous_temp_column_width != -1) { - running_width = start_line * (reflow->column_width + E_REFLOW_FULL_GUTTER); - column_width = 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 = reflow->height - (E_REFLOW_BORDER_WIDTH * 2); - - for (i = 0; i < 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 (reflow->temp_column_width != -1) { - running_width = start_line * (reflow->column_width + E_REFLOW_FULL_GUTTER); - column_width = 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 = reflow->height - (E_REFLOW_BORDER_WIDTH * 2); - - for (i = 0; i < 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; - } - } - - reflow->previous_temp_column_width = reflow->temp_column_width; - reflow->need_column_resize = FALSE; - } -} - -static GnomeCanvasItem * -e_reflow_point (GnomeCanvasItem *item, - gdouble x, - gdouble y, - gint cx, - gint cy) -{ - GnomeCanvasItem *child = NULL; - - if (GNOME_CANVAS_ITEM_CLASS (e_reflow_parent_class)->point) - child = GNOME_CANVAS_ITEM_CLASS (e_reflow_parent_class)->point (item, x, y, cx, cy); - - return child ? child : item; -#if 0 - if (y >= E_REFLOW_BORDER_WIDTH && y <= reflow->height - E_REFLOW_BORDER_WIDTH) { - gfloat n_x; - n_x = x; - n_x += E_REFLOW_BORDER_WIDTH + E_REFLOW_DIVIDER_WIDTH; - n_x = fmod (n_x, (reflow->column_width + E_REFLOW_FULL_GUTTER)); - if (n_x < E_REFLOW_FULL_GUTTER) { - *actual_item = item; - return 0; - } - } - return distance; -#endif -} - -static void -e_reflow_reflow (GnomeCanvasItem *item, - gint flags) -{ - EReflow *reflow = E_REFLOW (item); - gdouble old_width; - gdouble running_width; - gdouble running_height; - gint next_column; - gint i; - - if (!(item->flags & GNOME_CANVAS_ITEM_REALIZED)) - return; - - if (reflow->need_reflow_columns) { - reflow_columns (reflow); - } - - old_width = reflow->width; - - running_width = E_REFLOW_BORDER_WIDTH; - running_height = E_REFLOW_BORDER_WIDTH; - - next_column = 1; - - for (i = 0; i < reflow->count; i++) { - gint unsorted = e_sorter_sorted_to_model (E_SORTER (reflow->sorter), i); - if (next_column < reflow->column_count && i == reflow->columns[next_column]) { - running_height = E_REFLOW_BORDER_WIDTH; - running_width += reflow->column_width + E_REFLOW_FULL_GUTTER; - next_column++; - } - - if (unsorted >= 0 && reflow->items[unsorted]) { - e_canvas_item_move_absolute ( - GNOME_CANVAS_ITEM (reflow->items[unsorted]), - (gdouble) running_width, - (gdouble) running_height); - running_height += reflow->heights[unsorted] + E_REFLOW_BORDER_WIDTH; - } - } - reflow->width = running_width + reflow->column_width + E_REFLOW_BORDER_WIDTH; - if (reflow->width < reflow->minimum_width) - reflow->width = reflow->minimum_width; - if (old_width != reflow->width) - e_canvas_item_request_parent_reflow (item); -} - -static gint -e_reflow_selection_event_real (EReflow *reflow, - GnomeCanvasItem *item, - GdkEvent *event) -{ - gint row; - gint return_val = TRUE; - switch (event->type) { - case GDK_BUTTON_PRESS: - switch (event->button.button) { - case 1: /* Fall through. */ - case 2: - row = er_find_item (reflow, item); - if (event->button.button == 1) { - reflow->maybe_did_something = - e_selection_model_maybe_do_something (reflow->selection, row, 0, event->button.state); - reflow->maybe_in_drag = TRUE; - } else { - e_selection_model_do_something (reflow->selection, row, 0, event->button.state); - } - break; - case 3: - row = er_find_item (reflow, item); - e_selection_model_right_click_down (reflow->selection, row, 0, 0); - break; - default: - return_val = FALSE; - break; - } - break; - case GDK_BUTTON_RELEASE: - if (event->button.button == 1) { - if (reflow->maybe_in_drag) { - reflow->maybe_in_drag = FALSE; - if (!reflow->maybe_did_something) { - row = er_find_item (reflow, item); - e_selection_model_do_something (reflow->selection, row, 0, event->button.state); - } - } - } - break; - case GDK_KEY_PRESS: - return_val = e_selection_model_key_press (reflow->selection, (GdkEventKey *) event); - break; - default: - return_val = FALSE; - break; - } - - return return_val; -} - -static void -e_reflow_class_init (EReflowClass *class) -{ - GObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - object_class = (GObjectClass *) class; - item_class = (GnomeCanvasItemClass *) class; - - object_class->set_property = e_reflow_set_property; - object_class->get_property = e_reflow_get_property; - object_class->dispose = e_reflow_dispose; - - /* 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; - - class->selection_event = e_reflow_selection_event_real; - class->column_width_changed = NULL; - - g_object_class_install_property ( - object_class, - PROP_MINIMUM_WIDTH, - g_param_spec_double ( - "minimum_width", - "Minimum width", - "Minimum Width", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_WIDTH, - g_param_spec_double ( - "width", - "Width", - "Width", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READABLE)); - - g_object_class_install_property ( - object_class, - PROP_HEIGHT, - g_param_spec_double ( - "height", - "Height", - "Height", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_EMPTY_MESSAGE, - g_param_spec_string ( - "empty_message", - "Empty message", - "Empty message", - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_MODEL, - g_param_spec_object ( - "model", - "Reflow model", - "Reflow model", - E_TYPE_REFLOW_MODEL, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - object_class, - PROP_COLUMN_WIDTH, - g_param_spec_double ( - "column_width", - "Column width", - "Column width", - 0.0, G_MAXDOUBLE, 150.0, - G_PARAM_READWRITE)); - - signals[SELECTION_EVENT] = g_signal_new ( - "selection_event", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EReflowClass, selection_event), - NULL, NULL, - e_marshal_INT__OBJECT_BOXED, - G_TYPE_INT, 2, - G_TYPE_OBJECT, - GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE); - - signals[COLUMN_WIDTH_CHANGED] = g_signal_new ( - "column_width_changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EReflowClass, column_width_changed), - NULL, NULL, - g_cclosure_marshal_VOID__DOUBLE, - G_TYPE_NONE, 1, - G_TYPE_DOUBLE); -} - -static void -e_reflow_init (EReflow *reflow) -{ - reflow->model = NULL; - reflow->items = NULL; - reflow->heights = NULL; - reflow->count = 0; - - reflow->columns = NULL; - reflow->column_count = 0; - - reflow->empty_text = NULL; - reflow->empty_message = NULL; - - reflow->minimum_width = 10; - reflow->width = 10; - reflow->height = 10; - - reflow->column_width = 150; - - reflow->column_drag = FALSE; - - reflow->need_height_update = FALSE; - reflow->need_column_resize = FALSE; - reflow->need_reflow_columns = FALSE; - - reflow->maybe_did_something = FALSE; - reflow->maybe_in_drag = FALSE; - - reflow->default_cursor_shown = TRUE; - reflow->arrow_cursor = NULL; - reflow->default_cursor = NULL; - - reflow->cursor_row = -1; - - reflow->incarnate_idle_id = 0; - reflow->do_adjustment_idle_id = 0; - reflow->set_scroll_adjustments_id = 0; - - reflow->selection = E_SELECTION_MODEL (e_selection_model_simple_new ()); - reflow->sorter = e_sorter_array_new (er_create_cmp_cache, er_compare, reflow); - - g_object_set ( - reflow->selection, - "sorter", reflow->sorter, - NULL); - - reflow->selection_changed_id = g_signal_connect ( - reflow->selection, "selection_changed", - G_CALLBACK (selection_changed), reflow); - - reflow->selection_row_changed_id = g_signal_connect ( - reflow->selection, "selection_row_changed", - G_CALLBACK (selection_row_changed), reflow); - - reflow->cursor_changed_id = g_signal_connect ( - reflow->selection, "cursor_changed", - G_CALLBACK (cursor_changed), reflow); - - e_canvas_item_set_reflow_callback (GNOME_CANVAS_ITEM (reflow), e_reflow_reflow); -} diff --git a/widgets/text/e-reflow.h b/widgets/text/e-reflow.h deleted file mode 100644 index 979857ea5c..0000000000 --- a/widgets/text/e-reflow.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Chris Lahey - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_REFLOW_H -#define E_REFLOW_H - -#include -#include -#include -#include - -/* Standard GObject macros */ -#define E_TYPE_REFLOW \ - (e_reflow_get_type ()) -#define E_REFLOW(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_REFLOW, EReflow)) -#define E_REFLOW_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_REFLOW, EReflowClass)) -#define E_IS_REFLOW(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_REFLOW)) -#define E_IS_REFLOW_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_REFLOW)) -#define E_REFLOW_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_REFLOW, EReflowClass)) - -G_BEGIN_DECLS - -typedef struct _EReflow EReflow; -typedef struct _EReflowClass EReflowClass; -typedef struct _EReflowPrivate EReflowPrivate; - -struct _EReflow { - GnomeCanvasGroup parent; - - /* item specific fields */ - EReflowModel *model; - guint model_changed_id; - guint comparison_changed_id; - guint model_items_inserted_id; - guint model_item_removed_id; - guint model_item_changed_id; - - ESelectionModel *selection; - guint selection_changed_id; - guint selection_row_changed_id; - guint cursor_changed_id; - ESorterArray *sorter; - - GtkAdjustment *adjustment; - guint adjustment_changed_id; - guint adjustment_value_changed_id; - guint set_scroll_adjustments_id; - - gint *heights; - GnomeCanvasItem **items; - gint count; - gint allocated_count; - - gint *columns; - gint column_count; /* Number of columnns */ - - GnomeCanvasItem *empty_text; - gchar *empty_message; - - gdouble minimum_width; - gdouble width; - gdouble height; - - gdouble column_width; - - gint incarnate_idle_id; - gint do_adjustment_idle_id; - - /* These are all for when the column is being dragged. */ - gdouble start_x; - gint which_column_dragged; - gdouble temp_column_width; - gdouble previous_temp_column_width; - - gint cursor_row; - - gint reflow_from_column; - - guint column_drag : 1; - - guint need_height_update : 1; - guint need_column_resize : 1; - guint need_reflow_columns : 1; - - guint default_cursor_shown : 1; - - guint maybe_did_something : 1; - guint maybe_in_drag : 1; - GdkCursor *arrow_cursor; - GdkCursor *default_cursor; -}; - -struct _EReflowClass -{ - GnomeCanvasGroupClass parent_class; - - gint (*selection_event) (EReflow *reflow, GnomeCanvasItem *item, GdkEvent *event); - void (*column_width_changed) (EReflow *reflow, gdouble width); -}; - -/* - * 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. - */ -GType e_reflow_get_type (void); - -G_END_DECLS - -#endif /* E_REFLOW_H */ diff --git a/widgets/text/e-text-model-repos.c b/widgets/text/e-text-model-repos.c deleted file mode 100644 index b56a213215..0000000000 --- a/widgets/text/e-text-model-repos.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Jon Trowbridge - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "e-text-model-repos.h" - -#define MODEL_CLAMP(model, pos) (CLAMP((pos), 0, strlen((model)->text))) - -gint -e_repos_absolute (gint pos, - gpointer data) -{ - EReposAbsolute *info = (EReposAbsolute *) data; - g_return_val_if_fail (data, -1); - - pos = info->pos; - if (pos < 0) { - gint len = e_text_model_get_text_length (info->model); - pos += len + 1; - } - - return e_text_model_validate_position (info->model, pos); -} - -gint -e_repos_insert_shift (gint pos, - gpointer data) -{ - EReposInsertShift *info = (EReposInsertShift *) data; - g_return_val_if_fail (data, -1); - - if (pos >= info->pos) - pos += info->len; - - return e_text_model_validate_position (info->model, pos); -} - -gint -e_repos_delete_shift (gint pos, - gpointer data) -{ - EReposDeleteShift *info = (EReposDeleteShift *) data; - g_return_val_if_fail (data, -1); - - if (pos > info->pos + info->len) - pos -= info->len; - else if (pos > info->pos) - pos = info->pos; - - return e_text_model_validate_position (info->model, pos); -} diff --git a/widgets/text/e-text-model-repos.h b/widgets/text/e-text-model-repos.h deleted file mode 100644 index f6d50a1111..0000000000 --- a/widgets/text/e-text-model-repos.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * e-text-model-repos.h - Standard ETextModelReposFn definitions - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Jon Trowbridge - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_TEXT_MODEL_REPOS_H -#define E_TEXT_MODEL_REPOS_H - -#include "e-text-model.h" - -typedef struct { - ETextModel *model; - gint pos; /* Position to move to. Negative values count from the end buffer. - (i.e. -1 puts cursor at the end, -2 one character from end, etc.) */ -} EReposAbsolute; - -gint e_repos_absolute (gint pos, gpointer data); - -typedef struct { - ETextModel *model; - gint pos; /* Location of first inserted character. */ - gint len; /* Number of characters inserted. */ -} EReposInsertShift; - -gint e_repos_insert_shift (gint pos, gpointer data); - -typedef struct { - ETextModel *model; - gint pos; /* Location of first deleted character. */ - gint len; /* Number of characters deleted. */ -} EReposDeleteShift; - -gint e_repos_delete_shift (gint pos, gpointer data); - -#endif diff --git a/widgets/text/e-text-model.c b/widgets/text/e-text-model.c deleted file mode 100644 index 5027b3a3f7..0000000000 --- a/widgets/text/e-text-model.c +++ /dev/null @@ -1,642 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Chris Lahey - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#undef PARANOID_DEBUGGING - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#include - -#include "e-util/e-util.h" - -#include "e-text-model.h" -#include "e-text-model-repos.h" - -#define E_TEXT_MODEL_GET_PRIVATE(obj) \ - (G_TYPE_INSTANCE_GET_PRIVATE \ - ((obj), E_TYPE_TEXT_MODEL, ETextModelPrivate)) - -enum { - E_TEXT_MODEL_CHANGED, - E_TEXT_MODEL_REPOSITION, - E_TEXT_MODEL_OBJECT_ACTIVATED, - E_TEXT_MODEL_CANCEL_COMPLETION, - E_TEXT_MODEL_LAST_SIGNAL -}; - -static guint signals[E_TEXT_MODEL_LAST_SIGNAL] = { 0 }; - -struct _ETextModelPrivate { - GString *text; -}; - -static gint e_text_model_real_validate_position - (ETextModel *, gint pos); -static const gchar * - e_text_model_real_get_text (ETextModel *model); -static gint e_text_model_real_get_text_length - (ETextModel *model); -static void e_text_model_real_set_text (ETextModel *model, - const gchar *text); -static void e_text_model_real_insert (ETextModel *model, - gint postion, - const gchar *text); -static void e_text_model_real_insert_length (ETextModel *model, - gint postion, - const gchar *text, - gint length); -static void e_text_model_real_delete (ETextModel *model, - gint postion, - gint length); - -G_DEFINE_TYPE (ETextModel, e_text_model, G_TYPE_OBJECT) - -static void -e_text_model_finalize (GObject *object) -{ - ETextModelPrivate *priv; - - priv = E_TEXT_MODEL_GET_PRIVATE (object); - - g_string_free (priv->text, TRUE); - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (e_text_model_parent_class)->finalize (object); -} - -static void -e_text_model_class_init (ETextModelClass *class) -{ - GObjectClass *object_class; - - g_type_class_add_private (class, sizeof (ETextModelPrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->finalize = e_text_model_finalize; - - signals[E_TEXT_MODEL_CHANGED] = g_signal_new ( - "changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETextModelClass, changed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[E_TEXT_MODEL_REPOSITION] = g_signal_new ( - "reposition", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETextModelClass, reposition), - NULL, NULL, - e_marshal_NONE__POINTER_POINTER, - G_TYPE_NONE, 2, - G_TYPE_POINTER, - G_TYPE_POINTER); - - signals[E_TEXT_MODEL_OBJECT_ACTIVATED] = g_signal_new ( - "object_activated", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETextModelClass, object_activated), - NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, - G_TYPE_INT); - - signals[E_TEXT_MODEL_CANCEL_COMPLETION] = g_signal_new ( - "cancel_completion", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETextModelClass, cancel_completion), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - /* No default signal handlers. */ - class->changed = NULL; - class->reposition = NULL; - class->object_activated = NULL; - - class->validate_pos = e_text_model_real_validate_position; - - class->get_text = e_text_model_real_get_text; - class->get_text_len = e_text_model_real_get_text_length; - class->set_text = e_text_model_real_set_text; - class->insert = e_text_model_real_insert; - class->insert_length = e_text_model_real_insert_length; - class->delete = e_text_model_real_delete; - - /* We explicitly don't define default handlers for these. */ - class->objectify = NULL; - class->obj_count = NULL; - class->get_nth_obj = NULL; -} - -static void -e_text_model_init (ETextModel *model) -{ - model->priv = E_TEXT_MODEL_GET_PRIVATE (model); - model->priv->text = g_string_new (""); -} - -static gint -e_text_model_real_validate_position (ETextModel *model, - gint pos) -{ - gint len = e_text_model_get_text_length (model); - - if (pos < 0) - pos = 0; - else if (pos > len) - pos = len; - - return pos; -} - -static const gchar * -e_text_model_real_get_text (ETextModel *model) -{ - if (model->priv->text) - return model->priv->text->str; - else - return ""; -} - -static gint -e_text_model_real_get_text_length (ETextModel *model) -{ - return g_utf8_strlen (model->priv->text->str, -1); -} - -static void -e_text_model_real_set_text (ETextModel *model, - const gchar *text) -{ - EReposAbsolute repos; - gboolean changed = FALSE; - - if (text == NULL) { - changed = (*model->priv->text->str != '\0'); - - g_string_set_size (model->priv->text, 0); - - } else if (*model->priv->text->str == '\0' || - strcmp (model->priv->text->str, text)) { - - g_string_assign (model->priv->text, text); - - changed = TRUE; - } - - if (changed) { - e_text_model_changed (model); - repos.model = model; - repos.pos = -1; - e_text_model_reposition (model, e_repos_absolute, &repos); - } -} - -static void -e_text_model_real_insert (ETextModel *model, - gint position, - const gchar *text) -{ - e_text_model_insert_length (model, position, text, strlen (text)); -} - -static void -e_text_model_real_insert_length (ETextModel *model, - gint position, - const gchar *text, - gint length) -{ - EReposInsertShift repos; - gint model_len = e_text_model_real_get_text_length (model); - gchar *offs; - const gchar *p; - gint byte_length, l; - - if (position > model_len) - return; - - offs = g_utf8_offset_to_pointer (model->priv->text->str, position); - - for (p = text, l = 0; - l < length; - p = g_utf8_next_char (p), l++); - - byte_length = p - text; - - g_string_insert_len ( - model->priv->text, - offs - model->priv->text->str, - text, byte_length); - - e_text_model_changed (model); - - repos.model = model; - repos.pos = position; - repos.len = length; - - e_text_model_reposition (model, e_repos_insert_shift, &repos); -} - -static void -e_text_model_real_delete (ETextModel *model, - gint position, - gint length) -{ - EReposDeleteShift repos; - gint byte_position, byte_length; - gchar *offs, *p; - gint l; - - offs = g_utf8_offset_to_pointer (model->priv->text->str, position); - byte_position = offs - model->priv->text->str; - - for (p = offs, l = 0; - l < length; - p = g_utf8_next_char (p), l++); - - byte_length = p - offs; - - g_string_erase ( - model->priv->text, - byte_position, byte_length); - - e_text_model_changed (model); - - repos.model = model; - repos.pos = position; - repos.len = length; - - e_text_model_reposition (model, e_repos_delete_shift, &repos); -} - -void -e_text_model_changed (ETextModel *model) -{ - ETextModelClass *class; - - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - class = E_TEXT_MODEL_GET_CLASS (model); - - /* - Objectify before emitting any signal. - While this method could, in theory, do pretty much anything, it is meant - for scanning objects and converting substrings into embedded objects. - */ - if (class->objectify != NULL) - class->objectify (model); - - g_signal_emit (model, signals[E_TEXT_MODEL_CHANGED], 0); -} - -void -e_text_model_cancel_completion (ETextModel *model) -{ - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - g_signal_emit (model, signals[E_TEXT_MODEL_CANCEL_COMPLETION], 0); -} - -void -e_text_model_reposition (ETextModel *model, - ETextModelReposFn fn, - gpointer repos_data) -{ - g_return_if_fail (E_IS_TEXT_MODEL (model)); - g_return_if_fail (fn != NULL); - - g_signal_emit ( - model, signals[E_TEXT_MODEL_REPOSITION], 0, fn, repos_data); -} - -gint -e_text_model_validate_position (ETextModel *model, - gint pos) -{ - ETextModelClass *class; - - g_return_val_if_fail (E_IS_TEXT_MODEL (model), 0); - - class = E_TEXT_MODEL_GET_CLASS (model); - - if (class->validate_pos != NULL) - pos = class->validate_pos (model, pos); - - return pos; -} - -const gchar * -e_text_model_get_text (ETextModel *model) -{ - ETextModelClass *class; - - g_return_val_if_fail (E_IS_TEXT_MODEL (model), NULL); - - class = E_TEXT_MODEL_GET_CLASS (model); - - if (class->get_text == NULL) - return ""; - - return class->get_text (model); -} - -gint -e_text_model_get_text_length (ETextModel *model) -{ - ETextModelClass *class; - - g_return_val_if_fail (E_IS_TEXT_MODEL (model), 0); - - class = E_TEXT_MODEL_GET_CLASS (model); - - if (class->get_text_len (model)) { - - gint len = class->get_text_len (model); - -#ifdef PARANOID_DEBUGGING - const gchar *str = e_text_model_get_text (model); - gint len2 = str ? g_utf8_strlen (str, -1) : 0; - if (len != len) - g_error ("\"%s\" length reported as %d, not %d.", str, len, len2); -#endif - - return len; - - } else { - /* Calculate length the old-fashioned way... */ - const gchar *str = e_text_model_get_text (model); - return str ? g_utf8_strlen (str, -1) : 0; - } -} - -void -e_text_model_set_text (ETextModel *model, - const gchar *text) -{ - ETextModelClass *class; - - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - class = E_TEXT_MODEL_GET_CLASS (model); - - if (class->set_text != NULL) - class->set_text (model, text); -} - -void -e_text_model_insert (ETextModel *model, - gint position, - const gchar *text) -{ - ETextModelClass *class; - - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - if (text == NULL) - return; - - class = E_TEXT_MODEL_GET_CLASS (model); - - if (class->insert != NULL) - class->insert (model, position, text); -} - -void -e_text_model_insert_length (ETextModel *model, - gint position, - const gchar *text, - gint length) -{ - ETextModelClass *class; - - g_return_if_fail (E_IS_TEXT_MODEL (model)); - g_return_if_fail (length >= 0); - - if (text == NULL || length == 0) - return; - - class = E_TEXT_MODEL_GET_CLASS (model); - - if (class->insert_length != NULL) - class->insert_length (model, position, text, length); -} - -void -e_text_model_prepend (ETextModel *model, - const gchar *text) -{ - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - if (text == NULL) - return; - - e_text_model_insert (model, 0, text); -} - -void -e_text_model_append (ETextModel *model, - const gchar *text) -{ - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - if (text == NULL) - return; - - e_text_model_insert (model, e_text_model_get_text_length (model), text); -} - -void -e_text_model_delete (ETextModel *model, - gint position, - gint length) -{ - ETextModelClass *class; - gint txt_len; - - g_return_if_fail (E_IS_TEXT_MODEL (model)); - g_return_if_fail (length >= 0); - - txt_len = e_text_model_get_text_length (model); - if (position + length > txt_len) - length = txt_len - position; - - if (length <= 0) - return; - - class = E_TEXT_MODEL_GET_CLASS (model); - - if (class->delete != NULL) - class->delete (model, position, length); -} - -gint -e_text_model_object_count (ETextModel *model) -{ - ETextModelClass *class; - - g_return_val_if_fail (E_IS_TEXT_MODEL (model), 0); - - class = E_TEXT_MODEL_GET_CLASS (model); - - if (class->obj_count == NULL) - return 0; - - return class->obj_count (model); -} - -const gchar * -e_text_model_get_nth_object (ETextModel *model, - gint n, - gint *len) -{ - ETextModelClass *class; - - g_return_val_if_fail (E_IS_TEXT_MODEL (model), NULL); - - if (n < 0 || n >= e_text_model_object_count (model)) - return NULL; - - class = E_TEXT_MODEL_GET_CLASS (model); - - if (class->get_nth_obj == NULL) - return NULL; - - return class->get_nth_obj (model, n, len); -} - -gchar * -e_text_model_strdup_nth_object (ETextModel *model, - gint n) -{ - const gchar *obj; - gint len = 0; - - g_return_val_if_fail (E_IS_TEXT_MODEL (model), NULL); - - obj = e_text_model_get_nth_object (model, n, &len); - - if (obj) { - gint byte_len; - byte_len = g_utf8_offset_to_pointer (obj, len) - obj; - return g_strndup (obj, byte_len); - } - else { - return NULL; - } -} - -void -e_text_model_get_nth_object_bounds (ETextModel *model, - gint n, - gint *start, - gint *end) -{ - const gchar *txt = NULL, *obj = NULL; - gint len = 0; - - g_return_if_fail (E_IS_TEXT_MODEL (model)); - - txt = e_text_model_get_text (model); - obj = e_text_model_get_nth_object (model, n, &len); - - g_return_if_fail (obj != NULL); - - if (start) - *start = g_utf8_pointer_to_offset (txt, obj); - if (end) - *end = (start ? *start : 0) + len; -} - -gint -e_text_model_get_object_at_offset (ETextModel *model, - gint offset) -{ - ETextModelClass *class; - - g_return_val_if_fail (E_IS_TEXT_MODEL (model), -1); - - if (offset < 0 || offset >= e_text_model_get_text_length (model)) - return -1; - - class = E_TEXT_MODEL_GET_CLASS (model); - - /* If an optimized version has been provided, we use it. */ - if (class->obj_at_offset != NULL) { - return class->obj_at_offset (model, offset); - - } else { - /* If not, we fake it.*/ - - gint i, N, pos0, pos1; - - N = e_text_model_object_count (model); - - for (i = 0; i < N; ++i) { - e_text_model_get_nth_object_bounds (model, i, &pos0, &pos1); - if (pos0 <= offset && offset < pos1) - return i; - } - - } - - return -1; -} - -gint -e_text_model_get_object_at_pointer (ETextModel *model, - const gchar *s) -{ - g_return_val_if_fail (E_IS_TEXT_MODEL (model), -1); - g_return_val_if_fail (s != NULL, -1); - - return e_text_model_get_object_at_offset ( - model, s - e_text_model_get_text (model)); -} - -void -e_text_model_activate_nth_object (ETextModel *model, - gint n) -{ - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_TEXT_MODEL (model)); - g_return_if_fail (n >= 0); - g_return_if_fail (n < e_text_model_object_count (model)); - - g_signal_emit (model, signals[E_TEXT_MODEL_OBJECT_ACTIVATED], 0, n); -} - -ETextModel * -e_text_model_new (void) -{ - ETextModel *model = g_object_new (E_TYPE_TEXT_MODEL, NULL); - return model; -} diff --git a/widgets/text/e-text-model.h b/widgets/text/e-text-model.h deleted file mode 100644 index 4b0a4475cb..0000000000 --- a/widgets/text/e-text-model.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Chris Lahey - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_TEXT_MODEL_H -#define E_TEXT_MODEL_H - -#include - -G_BEGIN_DECLS - -#define E_TYPE_TEXT_MODEL (e_text_model_get_type ()) -#define E_TEXT_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_TEXT_MODEL, ETextModel)) -#define E_TEXT_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_TEXT_MODEL, ETextModelClass)) -#define E_IS_TEXT_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_TEXT_MODEL)) -#define E_IS_TEXT_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), E_TYPE_TEXT_MODEL)) -#define E_TEXT_MODEL_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), E_TYPE_TEXT_MODEL_TYPE, ETextModelClass)) - -typedef struct _ETextModel ETextModel; -typedef struct _ETextModelClass ETextModelClass; -typedef struct _ETextModelPrivate ETextModelPrivate; - -typedef gint (*ETextModelReposFn) (gint, gpointer); - -struct _ETextModel { - GObject item; - - ETextModelPrivate *priv; -}; - -struct _ETextModelClass { - GObjectClass parent_class; - - /* Signal */ - void (* changed) (ETextModel *model); - void (* reposition) (ETextModel *model, ETextModelReposFn fn, gpointer repos_fn_data); - void (* object_activated) (ETextModel *model, gint obj_num); - void (* cancel_completion) (ETextModel *model); - - /* Virtual methods */ - - gint (* validate_pos) (ETextModel *model, gint pos); - - const gchar *(* get_text) (ETextModel *model); - gint (* get_text_len) (ETextModel *model); - void (* set_text) (ETextModel *model, const gchar *text); - void (* insert) (ETextModel *model, gint position, const gchar *text); - void (* insert_length) (ETextModel *model, gint position, const gchar *text, gint length); - void (* delete) (ETextModel *model, gint position, gint length); - - void (* objectify) (ETextModel *model); - gint (* obj_count) (ETextModel *model); - const gchar *(* get_nth_obj) (ETextModel *model, gint n, gint *len); - gint (* obj_at_offset) (ETextModel *model, gint offset); -}; - -GType e_text_model_get_type (void); - -ETextModel *e_text_model_new (void); - -void e_text_model_changed (ETextModel *model); -void e_text_model_cancel_completion (ETextModel *model); - -void e_text_model_reposition (ETextModel *model, ETextModelReposFn fn, gpointer repos_data); -gint e_text_model_validate_position (ETextModel *model, gint pos); - -/* Functions for manipulating the underlying text. */ - -const gchar *e_text_model_get_text (ETextModel *model); -gint e_text_model_get_text_length (ETextModel *model); -void e_text_model_set_text (ETextModel *model, const gchar *text); -void e_text_model_insert (ETextModel *model, gint position, const gchar *text); -void e_text_model_insert_length (ETextModel *model, gint position, const gchar *text, gint length); -void e_text_model_prepend (ETextModel *model, const gchar *text); -void e_text_model_append (ETextModel *model, const gchar *text); -void e_text_model_delete (ETextModel *model, gint position, gint length); - -/* Functions for accessing embedded objects. */ - -gint e_text_model_object_count (ETextModel *model); -const gchar *e_text_model_get_nth_object (ETextModel *model, gint n, gint *len); -gchar *e_text_model_strdup_nth_object (ETextModel *model, gint n); -void e_text_model_get_nth_object_bounds (ETextModel *model, gint n, gint *start_pos, gint *end_pos); -gint e_text_model_get_object_at_offset (ETextModel *model, gint offset); -gint e_text_model_get_object_at_pointer (ETextModel *model, const gchar *c); -void e_text_model_activate_nth_object (ETextModel *model, gint n); - -G_END_DECLS - -#endif diff --git a/widgets/text/e-text.c b/widgets/text/e-text.c deleted file mode 100644 index f75c4ca8b9..0000000000 --- a/widgets/text/e-text.c +++ /dev/null @@ -1,3405 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-text.c - Text item for evolution. - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - * Authors: - * Chris Lahey - * Jon Trowbridge - * - * 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 - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - -#include -#include - -#include "gal-a11y-e-text.h" -#include "misc/e-canvas.h" -#include "misc/e-canvas-utils.h" -#include "e-util/e-unicode.h" -#include -#include "e-util/e-text-event-processor-emacs-like.h" -#include "e-util/e-util.h" - -#include "e-text.h" - -G_DEFINE_TYPE (EText, e_text, GNOME_TYPE_CANVAS_ITEM) - -enum { - E_TEXT_CHANGED, - E_TEXT_ACTIVATE, - E_TEXT_KEYPRESS, - E_TEXT_POPULATE_POPUP, - E_TEXT_LAST_SIGNAL -}; - -static GQuark e_text_signals[E_TEXT_LAST_SIGNAL] = { 0 }; - -/* Object argument IDs */ -enum { - PROP_0, - PROP_MODEL, - PROP_EVENT_PROCESSOR, - PROP_TEXT, - PROP_BOLD, - PROP_STRIKEOUT, - PROP_ANCHOR, - PROP_JUSTIFICATION, - PROP_CLIP_WIDTH, - PROP_CLIP_HEIGHT, - PROP_CLIP, - PROP_FILL_CLIP_RECTANGLE, - PROP_X_OFFSET, - PROP_Y_OFFSET, - PROP_FILL_COLOR, - PROP_FILL_COLOR_GDK, - PROP_FILL_COLOR_RGBA, - PROP_TEXT_WIDTH, - PROP_TEXT_HEIGHT, - PROP_EDITABLE, - PROP_USE_ELLIPSIS, - PROP_ELLIPSIS, - PROP_LINE_WRAP, - PROP_BREAK_CHARACTERS, - PROP_MAX_LINES, - PROP_WIDTH, - PROP_HEIGHT, - PROP_ALLOW_NEWLINES, - PROP_CURSOR_POS, - PROP_IM_CONTEXT, - PROP_HANDLE_POPUP -}; - -static void e_text_command (ETextEventProcessor *tep, - ETextEventProcessorCommand *command, - gpointer data); - -static void e_text_text_model_changed (ETextModel *model, - EText *text); -static void e_text_text_model_reposition (ETextModel *model, - ETextModelReposFn fn, - gpointer repos_data, - gpointer data); - -static void _get_tep (EText *text); - -static void calc_height (EText *text); - -static gboolean show_pango_rectangle (EText *text, PangoRectangle rect); - -static void e_text_do_popup (EText *text, - GdkEvent *event_button, - gint position); - -static void e_text_update_primary_selection (EText *text); -static void e_text_paste (EText *text, GdkAtom selection); -static void e_text_insert (EText *text, const gchar *string); -static void e_text_reset_im_context (EText *text); - -static void reset_layout_attrs (EText *text); - -/* IM Context Callbacks */ -static void e_text_commit_cb (GtkIMContext *context, - const gchar *str, - EText *text); -static void e_text_preedit_changed_cb (GtkIMContext *context, - EText *text); -static gboolean e_text_retrieve_surrounding_cb (GtkIMContext *context, - EText *text); -static gboolean e_text_delete_surrounding_cb (GtkIMContext *context, - gint offset, - gint n_chars, - EText *text); - -static GdkAtom clipboard_atom = GDK_NONE; - -static void -disconnect_im_context (EText *text) -{ - if (!text || !text->im_context) - return; - - g_signal_handlers_disconnect_matched ( - text->im_context, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, text); - text->im_context_signals_registered = FALSE; -} - -/* Dispose handler for the text item */ -static void -e_text_dispose (GObject *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) - g_signal_handler_disconnect ( - text->model, - text->model_changed_signal_id); - text->model_changed_signal_id = 0; - - if (text->model_repos_signal_id) - g_signal_handler_disconnect ( - text->model, - text->model_repos_signal_id); - text->model_repos_signal_id = 0; - - if (text->model) - g_object_unref (text->model); - text->model = NULL; - - if (text->tep_command_id) - g_signal_handler_disconnect ( - text->tep, - text->tep_command_id); - text->tep_command_id = 0; - - if (text->tep) - g_object_unref (text->tep); - text->tep = NULL; - - g_free (text->revert); - text->revert = NULL; - - 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->dbl_timeout) { - g_source_remove (text->dbl_timeout); - text->dbl_timeout = 0; - } - - if (text->tpl_timeout) { - g_source_remove (text->tpl_timeout); - text->tpl_timeout = 0; - } - - if (text->layout) { - g_object_unref (text->layout); - text->layout = NULL; - } - - if (text->im_context) { - disconnect_im_context (text); - g_object_unref (text->im_context); - text->im_context = NULL; - } - - if (text->font_desc) { - pango_font_description_free (text->font_desc); - text->font_desc = NULL; - } - - /* Chain up to parent's dispose() method. */ - G_OBJECT_CLASS (e_text_parent_class)->dispose (object); -} - -static void -insert_preedit_text (EText *text) -{ - PangoAttrList *attrs = NULL; - PangoAttrList *preedit_attrs = NULL; - gchar *preedit_string = NULL; - GString *tmp_string = g_string_new (NULL); - gint length = 0, cpos = 0; - gboolean new_attrs = FALSE; - - if (text->layout == NULL || !GTK_IS_IM_CONTEXT (text->im_context)) - return; - - text->text = e_text_model_get_text (text->model); - length = strlen (text->text); - - g_string_prepend_len (tmp_string, text->text,length); - - /* we came into this function only when text->preedit_len was not 0 - * so we can safely fetch the preedit string */ - gtk_im_context_get_preedit_string ( - text->im_context, &preedit_string, &preedit_attrs, NULL); - - if (preedit_string && g_utf8_validate (preedit_string, -1, NULL)) { - - text->preedit_len = strlen (preedit_string); - - cpos = g_utf8_offset_to_pointer ( - text->text, text->selection_start) - text->text; - - g_string_insert (tmp_string, cpos, preedit_string); - - reset_layout_attrs (text); - - attrs = pango_layout_get_attributes (text->layout); - if (!attrs) { - attrs = pango_attr_list_new (); - new_attrs = TRUE; - } - - pango_layout_set_text (text->layout, tmp_string->str, tmp_string->len); - - pango_attr_list_splice (attrs, preedit_attrs, cpos, text->preedit_len); - - if (new_attrs) { - pango_layout_set_attributes (text->layout, attrs); - pango_attr_list_unref (attrs); - } - } else - text->preedit_len = 0; - - if (preedit_string) - g_free (preedit_string); - if (preedit_attrs) - pango_attr_list_unref (preedit_attrs); - if (tmp_string) - g_string_free (tmp_string, TRUE); -} - -static void -reset_layout_attrs (EText *text) -{ - PangoAttrList *attrs = NULL; - gint object_count; - - if (text->layout == NULL) - return; - - object_count = e_text_model_object_count (text->model); - - if (text->bold || text->strikeout || object_count > 0) { - gint length = 0; - gint i; - - attrs = pango_attr_list_new (); - - for (i = 0; i < object_count; i++) { - gint start_pos, end_pos; - PangoAttribute *attr; - - attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE); - - e_text_model_get_nth_object_bounds ( - text->model, i, &start_pos, &end_pos); - - attr->start_index = g_utf8_offset_to_pointer ( - text->text, start_pos) - text->text; - attr->end_index = g_utf8_offset_to_pointer ( - text->text, end_pos) - text->text; - - pango_attr_list_insert (attrs, attr); - } - - if (text->bold || text->strikeout) - length = strlen (text->text); - - if (text->bold) { - PangoAttribute *attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD); - attr->start_index = 0; - attr->end_index = length; - - pango_attr_list_insert_before (attrs, attr); - } - if (text->strikeout) { - PangoAttribute *attr = pango_attr_strikethrough_new (TRUE); - attr->start_index = 0; - attr->end_index = length; - - pango_attr_list_insert_before (attrs, attr); - } - } - - pango_layout_set_attributes (text->layout, attrs); - - if (attrs) - pango_attr_list_unref (attrs); - - calc_height (text); -} - -static void -create_layout (EText *text) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (text); - - if (text->layout) - return; - - text->layout = gtk_widget_create_pango_layout ( - GTK_WIDGET (item->canvas), text->text); - if (text->line_wrap) - pango_layout_set_width ( - text->layout, text->clip_width < 0 - ? -1 : text->clip_width * PANGO_SCALE); - reset_layout_attrs (text); -} - -static void -reset_layout (EText *text) -{ - GnomeCanvasItem *item = GNOME_CANVAS_ITEM (text); - - if (text->layout == NULL) { - create_layout (text); - } - else { - GtkStyle *style; - - style = gtk_widget_get_style (GTK_WIDGET (item->canvas)); - - if (text->font_desc) { - pango_font_description_free (text->font_desc); - } - text->font_desc = pango_font_description_new (); - if (!pango_font_description_get_size_is_absolute (style->font_desc)) - pango_font_description_set_size ( - text->font_desc, - pango_font_description_get_size (style->font_desc)); - else - pango_font_description_set_absolute_size ( - text->font_desc, - pango_font_description_get_size (style->font_desc)); - pango_font_description_set_family ( - text->font_desc, - pango_font_description_get_family (style->font_desc)); - pango_layout_set_font_description (text->layout, text->font_desc); - - pango_layout_set_text (text->layout, text->text, -1); - reset_layout_attrs (text); - } - - if (!text->button_down) { - PangoRectangle strong_pos, weak_pos; - gchar *offs = g_utf8_offset_to_pointer (text->text, text->selection_start); - - pango_layout_get_cursor_pos ( - text->layout, offs - text->text, - &strong_pos, &weak_pos); - - if (strong_pos.x != weak_pos.x || - strong_pos.y != weak_pos.y || - strong_pos.width != weak_pos.width || - strong_pos.height != weak_pos.height) - show_pango_rectangle (text, weak_pos); - - show_pango_rectangle (text, strong_pos); - } -} - -static void -e_text_text_model_changed (ETextModel *model, - EText *text) -{ - gint model_len = e_text_model_get_text_length (model); - text->text = e_text_model_get_text (model); - - /* Make sure our selection doesn't extend past the bounds of our text. */ - text->selection_start = CLAMP (text->selection_start, 0, model_len); - text->selection_end = CLAMP (text->selection_end, 0, model_len); - - text->needs_reset_layout = 1; - text->needs_split_into_lines = 1; - text->needs_redraw = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (text)); - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (text)); - - g_signal_emit (text, e_text_signals[E_TEXT_CHANGED], 0); -} - -static void -e_text_text_model_reposition (ETextModel *model, - ETextModelReposFn fn, - gpointer repos_data, - gpointer user_data) -{ - EText *text = E_TEXT (user_data); - gint model_len = e_text_model_get_text_length (model); - - text->selection_start = fn (text->selection_start, repos_data); - text->selection_end = fn (text->selection_end, repos_data); - - /* Our repos function should make sure we don't overrun the buffer, but it never - * hurts to be paranoid. */ - text->selection_start = CLAMP (text->selection_start, 0, model_len); - text->selection_end = CLAMP (text->selection_end, 0, model_len); - - if (text->selection_start > text->selection_end) { - gint tmp = text->selection_start; - text->selection_start = text->selection_end; - text->selection_end = tmp; - } -} - -static void -get_bounds (EText *text, - gdouble *px1, - gdouble *py1, - gdouble *px2, - gdouble *py2) -{ - GnomeCanvasItem *item; - gdouble wx, wy, clip_width, clip_height; - - 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, wy, &text->cx, &text->cy); - gnome_canvas_w2c (item->canvas, wx, wy, &text->clip_cx, &text->clip_cy); - - if (text->clip_width < 0) - clip_width = text->width; - else - clip_width = text->clip_width; - - if (text->clip_height < 0) - clip_height = text->height; - else - clip_height = text->clip_height; - - /* Get canvas pixel coordinates for clip rectangle position */ - text->clip_cwidth = clip_width; - text->clip_cheight = clip_height; - - text->text_cx = text->cx; - text->text_cy = text->cy; - - /* 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->width; - *py2 = text->cy + text->height; - } -} - -static void -calc_height (EText *text) -{ - GnomeCanvasItem *item; - gint old_height; - gint old_width; - gint width = 0; - gint height = 0; - - item = GNOME_CANVAS_ITEM (text); - - /* Calculate text dimensions */ - - old_height = text->height; - old_width = text->width; - - if (text->layout) - pango_layout_get_pixel_size (text->layout, &width, &height); - - text->height = height; - text->width = width; - - if (old_height != text->height || old_width != text->width) - e_canvas_item_request_parent_reflow (item); -} - -static void -calc_ellipsis (EText *text) -{ -/* FIXME: a pango layout per calc_ellipsis sucks */ - gint width; - PangoLayout *layout = gtk_widget_create_pango_layout ( - GTK_WIDGET (GNOME_CANVAS_ITEM (text)->canvas), - text->ellipsis ? text->ellipsis : "..."); - pango_layout_get_size (layout, &width, NULL); - - text->ellipsis_width = width; - - g_object_unref (layout); -} - -static void -split_into_lines (EText *text) -{ - text->num_lines = pango_layout_get_line_count (text->layout); -} - -/* Set_arg handler for the text item */ -static void -e_text_set_property (GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) -{ - GnomeCanvasItem *item; - EText *text; - GdkColor color = { 0, 0, 0, 0, }; - GdkColor *pcolor; - - gboolean needs_update = 0; - gboolean needs_reflow = 0; - - item = GNOME_CANVAS_ITEM (object); - text = E_TEXT (object); - - switch (property_id) { - case PROP_MODEL: - - if (text->model_changed_signal_id) - g_signal_handler_disconnect ( - text->model, - text->model_changed_signal_id); - - if (text->model_repos_signal_id) - g_signal_handler_disconnect ( - text->model, - text->model_repos_signal_id); - - g_object_unref (text->model); - text->model = E_TEXT_MODEL (g_value_get_object (value)); - g_object_ref (text->model); - - text->model_changed_signal_id = g_signal_connect ( - text->model, "changed", - G_CALLBACK (e_text_text_model_changed), text); - - text->model_repos_signal_id = g_signal_connect ( - text->model, "reposition", - G_CALLBACK (e_text_text_model_reposition), text); - - text->text = e_text_model_get_text (text->model); - g_signal_emit (text, e_text_signals[E_TEXT_CHANGED], 0); - - text->needs_split_into_lines = 1; - needs_reflow = 1; - break; - - case PROP_EVENT_PROCESSOR: - if (text->tep && text->tep_command_id) - g_signal_handler_disconnect ( - text->tep, - text->tep_command_id); - if (text->tep) { - g_object_unref (text->tep); - } - text->tep = E_TEXT_EVENT_PROCESSOR (g_value_get_object (value)); - g_object_ref (text->tep); - - text->tep_command_id = g_signal_connect ( - text->tep, "command", - G_CALLBACK (e_text_command), text); - - if (!text->allow_newlines) - g_object_set ( - text->tep, - "allow_newlines", FALSE, - NULL); - break; - - case PROP_TEXT: - e_text_model_set_text (text->model, g_value_get_string (value)); - break; - - case PROP_BOLD: - text->bold = g_value_get_boolean (value); - - text->needs_redraw = 1; - text->needs_recalc_bounds = 1; - if (text->line_wrap) - text->needs_split_into_lines = 1; - else { - text->needs_calc_height = 1; - } - needs_update = 1; - needs_reflow = 1; - break; - - case PROP_STRIKEOUT: - text->strikeout = g_value_get_boolean (value); - text->needs_redraw = 1; - needs_update = 1; - break; - - case PROP_JUSTIFICATION: - text->justification = g_value_get_enum (value); - text->needs_redraw = 1; - needs_update = 1; - break; - - case PROP_CLIP_WIDTH: - text->clip_width = fabs (g_value_get_double (value)); - calc_ellipsis (text); - if (text->line_wrap) { - if (text->layout) - pango_layout_set_width ( - text->layout, text->clip_width < 0 - ? -1 : text->clip_width * PANGO_SCALE); - text->needs_split_into_lines = 1; - } else { - text->needs_calc_height = 1; - } - needs_reflow = 1; - break; - - case PROP_CLIP_HEIGHT: - text->clip_height = fabs (g_value_get_double (value)); - text->needs_recalc_bounds = 1; - /* toshok: kind of a hack - set needs_reset_layout - * here so when something about the style/them - * changes, we redraw the text at the proper size/with - * the proper font. */ - text->needs_reset_layout = 1; - needs_reflow = 1; - break; - - case PROP_CLIP: - text->clip = g_value_get_boolean (value); - calc_ellipsis (text); - if (text->line_wrap) - text->needs_split_into_lines = 1; - else { - text->needs_calc_height = 1; - } - needs_reflow = 1; - break; - - case PROP_FILL_CLIP_RECTANGLE: - text->fill_clip_rectangle = g_value_get_boolean (value); - needs_update = 1; - break; - - case PROP_X_OFFSET: - text->xofs = g_value_get_double (value); - text->needs_recalc_bounds = 1; - needs_update = 1; - break; - - case PROP_Y_OFFSET: - text->yofs = g_value_get_double (value); - text->needs_recalc_bounds = 1; - needs_update = 1; - break; - - case PROP_FILL_COLOR: - if (g_value_get_string (value)) - gdk_color_parse (g_value_get_string (value), &color); - - text->rgba = ((color.red & 0xff00) << 16 | - (color.green & 0xff00) << 8 | - (color.blue & 0xff00) | - 0xff); - text->rgba_set = TRUE; - text->needs_redraw = 1; - needs_update = 1; - break; - - case PROP_FILL_COLOR_GDK: - pcolor = g_value_get_boxed (value); - if (pcolor) { - color = *pcolor; - } - - text->rgba = ((color.red & 0xff00) << 16 | - (color.green & 0xff00) << 8 | - (color.blue & 0xff00) | - 0xff); - text->rgba_set = TRUE; - text->needs_redraw = 1; - needs_update = 1; - break; - - case PROP_FILL_COLOR_RGBA: - text->rgba = g_value_get_uint (value); - color.red = ((text->rgba >> 24) & 0xff) * 0x101; - color.green = ((text->rgba >> 16) & 0xff) * 0x101; - color.blue = ((text->rgba >> 8) & 0xff) * 0x101; - text->rgba_set = TRUE; - text->needs_redraw = 1; - needs_update = 1; - break; - - case PROP_EDITABLE: - text->editable = g_value_get_boolean (value); - text->needs_redraw = 1; - needs_update = 1; - break; - - case PROP_USE_ELLIPSIS: - text->use_ellipsis = g_value_get_boolean (value); - needs_reflow = 1; - break; - - case PROP_ELLIPSIS: - if (text->ellipsis) - g_free (text->ellipsis); - - text->ellipsis = g_strdup (g_value_get_string (value)); - calc_ellipsis (text); - needs_reflow = 1; - break; - - case PROP_LINE_WRAP: - text->line_wrap = g_value_get_boolean (value); - if (text->line_wrap) { - if (text->layout) { - pango_layout_set_width ( - text->layout, text->width < 0 - ? -1 : text->width * PANGO_SCALE); - } - } - text->needs_split_into_lines = 1; - needs_reflow = 1; - break; - - case PROP_BREAK_CHARACTERS: - if (text->break_characters) { - g_free (text->break_characters); - text->break_characters = NULL; - } - if (g_value_get_string (value)) - text->break_characters = g_strdup (g_value_get_string (value)); - text->needs_split_into_lines = 1; - needs_reflow = 1; - break; - - case PROP_MAX_LINES: - text->max_lines = g_value_get_int (value); - text->needs_split_into_lines = 1; - needs_reflow = 1; - break; - - case PROP_WIDTH: - text->clip_width = fabs (g_value_get_double (value)); - calc_ellipsis (text); - if (text->line_wrap) { - if (text->layout) { - pango_layout_set_width ( - text->layout, text->width < 0 ? - -1 : text->width * PANGO_SCALE); - } - text->needs_split_into_lines = 1; - } - else { - text->needs_calc_height = 1; - } - needs_reflow = 1; - break; - - case PROP_ALLOW_NEWLINES: - text->allow_newlines = g_value_get_boolean (value); - _get_tep (text); - g_object_set ( - text->tep, - "allow_newlines", g_value_get_boolean (value), - NULL); - break; - - case PROP_CURSOR_POS: { - ETextEventProcessorCommand command; - - command.action = E_TEP_MOVE; - command.position = E_TEP_VALUE; - command.value = g_value_get_int (value); - command.time = GDK_CURRENT_TIME; - e_text_command (text->tep, &command, text); - break; - } - - case PROP_IM_CONTEXT: - if (text->im_context) { - disconnect_im_context (text); - g_object_unref (text->im_context); - } - - text->im_context = g_value_get_object (value); - if (text->im_context) - g_object_ref (text->im_context); - - text->need_im_reset = TRUE; - break; - - case PROP_HANDLE_POPUP: - text->handle_popup = g_value_get_boolean (value); - break; - - default: - return; - } - - 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_property (GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) -{ - EText *text; - - text = E_TEXT (object); - - switch (property_id) { - case PROP_MODEL: - g_value_set_object (value, text->model); - break; - - case PROP_EVENT_PROCESSOR: - _get_tep (text); - g_value_set_object (value, text->tep); - break; - - case PROP_TEXT: - g_value_set_string (value, text->text); - break; - - case PROP_BOLD: - g_value_set_boolean (value, text->bold); - break; - - case PROP_STRIKEOUT: - g_value_set_boolean (value, text->strikeout); - break; - - case PROP_JUSTIFICATION: - g_value_set_enum (value, text->justification); - break; - - case PROP_CLIP_WIDTH: - g_value_set_double (value, text->clip_width); - break; - - case PROP_CLIP_HEIGHT: - g_value_set_double (value, text->clip_height); - break; - - case PROP_CLIP: - g_value_set_boolean (value, text->clip); - break; - - case PROP_FILL_CLIP_RECTANGLE: - g_value_set_boolean (value, text->fill_clip_rectangle); - break; - - case PROP_X_OFFSET: - g_value_set_double (value, text->xofs); - break; - - case PROP_Y_OFFSET: - g_value_set_double (value, text->yofs); - break; - - case PROP_FILL_COLOR_RGBA: - g_value_set_uint (value, text->rgba); - break; - - case PROP_TEXT_WIDTH: - g_value_set_double (value, text->width); - break; - - case PROP_TEXT_HEIGHT: - g_value_set_double (value, text->height); - break; - - case PROP_EDITABLE: - g_value_set_boolean (value, text->editable); - break; - - case PROP_USE_ELLIPSIS: - g_value_set_boolean (value, text->use_ellipsis); - break; - - case PROP_ELLIPSIS: - g_value_set_string (value, text->ellipsis); - break; - - case PROP_LINE_WRAP: - g_value_set_boolean (value, text->line_wrap); - break; - - case PROP_BREAK_CHARACTERS: - g_value_set_string (value, text->break_characters); - break; - - case PROP_MAX_LINES: - g_value_set_int (value, text->max_lines); - break; - - case PROP_WIDTH: - g_value_set_double (value, text->clip_width); - break; - - case PROP_HEIGHT: - g_value_set_double ( - value, text->clip && - text->clip_height != -1 ? - text->clip_height : text->height); - break; - - case PROP_ALLOW_NEWLINES: - g_value_set_boolean (value, text->allow_newlines); - break; - - case PROP_CURSOR_POS: - g_value_set_int (value, text->selection_start); - break; - - case PROP_IM_CONTEXT: - g_value_set_object (value, text->im_context); - break; - - case PROP_HANDLE_POPUP: - g_value_set_boolean (value, text->handle_popup); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); - break; - } -} - -/* Update handler for the text item */ -static void -e_text_reflow (GnomeCanvasItem *item, - gint flags) -{ - EText *text; - - text = E_TEXT (item); - - if (text->needs_reset_layout) { - reset_layout (text); - text->needs_reset_layout = 0; - text->needs_calc_height = 1; - } - - if (text->needs_split_into_lines) { - split_into_lines (text); - - text->needs_split_into_lines = 0; - text->needs_calc_height = 1; - } - - 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, - const cairo_matrix_t *i2c, - gint flags) -{ - EText *text; - gdouble x1, y1, x2, y2; - - text = E_TEXT (item); - - if (GNOME_CANVAS_ITEM_CLASS (e_text_parent_class)->update) - GNOME_CANVAS_ITEM_CLASS (e_text_parent_class)->update ( - item, i2c, flags); - - if (text->needs_recalc_bounds - || (flags & GNOME_CANVAS_UPDATE_AFFINE)) { - 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; - item->canvas->need_repick = TRUE; - } - if (!text->fill_clip_rectangle) - item->canvas->need_repick = TRUE; - 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 (GNOME_CANVAS_ITEM_CLASS (e_text_parent_class)->realize) - (* GNOME_CANVAS_ITEM_CLASS (e_text_parent_class)->realize) (item); - - create_layout (text); - - text->i_cursor = gdk_cursor_new (GDK_XTERM); - text->default_cursor = gdk_cursor_new (GDK_LEFT_PTR); -} - -/* Unrealize handler for the text item */ -static void -e_text_unrealize (GnomeCanvasItem *item) -{ - EText *text; - - text = E_TEXT (item); - - g_object_unref (text->i_cursor); - text->i_cursor = NULL; - g_object_unref (text->default_cursor); - text->default_cursor = NULL; - - if (GNOME_CANVAS_ITEM_CLASS (e_text_parent_class)->unrealize) - (* GNOME_CANVAS_ITEM_CLASS (e_text_parent_class)->unrealize) (item); -} - -static void -_get_tep (EText *text) -{ - if (!text->tep) { - text->tep = e_text_event_processor_emacs_like_new (); - - text->tep_command_id = g_signal_connect ( - text->tep, "command", - G_CALLBACK (e_text_command), text); - } -} - -static void -draw_pango_rectangle (cairo_t *cr, - gint x1, - gint y1, - PangoRectangle rect) -{ - gint width = rect.width / PANGO_SCALE; - gint height = rect.height / PANGO_SCALE; - - if (width <= 0) - width = 1; - if (height <= 0) - height = 1; - - cairo_rectangle ( - cr, x1 + rect.x / PANGO_SCALE, - y1 + rect.y / PANGO_SCALE, width, height); - cairo_fill (cr); -} - -static gboolean -show_pango_rectangle (EText *text, - PangoRectangle rect) -{ - gint x1 = rect.x / PANGO_SCALE; - gint x2 = (rect.x + rect.width) / PANGO_SCALE; - - gint y1 = rect.y / PANGO_SCALE; - gint y2 = (rect.y + rect.height) / PANGO_SCALE; - - gint new_xofs_edit = text->xofs_edit; - gint new_yofs_edit = text->yofs_edit; - - gint clip_width, clip_height; - - clip_width = text->clip_width; - clip_height = text->clip_height; - - if (x1 < new_xofs_edit) - new_xofs_edit = x1; - - if (y1 < new_yofs_edit) - new_yofs_edit = y1; - - if (clip_width >= 0) { - if (2 + x2 - clip_width > new_xofs_edit) - new_xofs_edit = 2 + x2 - clip_width; - } else { - new_xofs_edit = 0; - } - - if (clip_height >= 0) { - if (y2 - clip_height > new_yofs_edit) - new_yofs_edit = y2 - clip_height; - } else { - new_yofs_edit = 0; - } - - if (new_xofs_edit < 0) - new_xofs_edit = 0; - if (new_yofs_edit < 0) - new_yofs_edit = 0; - - if (new_xofs_edit != text->xofs_edit || - new_yofs_edit != text->yofs_edit) { - text->xofs_edit = new_xofs_edit; - text->yofs_edit = new_yofs_edit; - return TRUE; - } - - return FALSE; -} - -/* Draw handler for the text item */ -static void -e_text_draw (GnomeCanvasItem *item, - cairo_t *cr, - gint x, - gint y, - gint width, - gint height) -{ - EText *text; - gint xpos, ypos; - GnomeCanvas *canvas; - GtkWidget *widget; - GtkStyle *style; - GtkStateType state; - - text = E_TEXT (item); - canvas = GNOME_CANVAS_ITEM (text)->canvas; - widget = GTK_WIDGET (canvas); - state = gtk_widget_get_state (widget); - style = gtk_widget_get_style (widget); - - cairo_save (cr); - - if (!text->rgba_set) { - gdk_cairo_set_source_color (cr, &style->fg[state]); - } else { - cairo_set_source_rgba ( - cr, - ((text->rgba >> 24) & 0xff) / 255.0, - ((text->rgba >> 16) & 0xff) / 255.0, - ((text->rgba >> 8) & 0xff) / 255.0, - ( text->rgba & 0xff) / 255.0); - } - - /* Insert preedit text only when im_context signals are connected & - * text->preedit_len is not zero */ - if (text->im_context_signals_registered && text->preedit_len) - insert_preedit_text (text); - - /* Need to reset the layout to cleanly clear the preedit buffer when - * typing in CJK & using backspace on the preedit */ - if (!text->preedit_len) - reset_layout (text); - - if (!pango_layout_get_text (text->layout)) { - cairo_restore (cr); - return; - } - - xpos = text->text_cx; - ypos = text->text_cy; - - xpos = xpos - x + text->xofs; - ypos = ypos - y + text->yofs; - - cairo_save (cr); - - if (text->clip) { - cairo_rectangle ( - cr, xpos, ypos, - text->clip_cwidth - text->xofs, - text->clip_cheight - text->yofs); - cairo_clip (cr); - } - - if (text->editing) { - xpos -= text->xofs_edit; - ypos -= text->yofs_edit; - } - - cairo_move_to (cr, xpos, ypos); - pango_cairo_show_layout (cr, text->layout); - - if (text->editing) { - if (text->selection_start != text->selection_end) { - cairo_region_t *clip_region = cairo_region_create (); - gint indices[2]; - GtkStateType state; - - state = GTK_STATE_ACTIVE; - - indices[0] = MIN ( - text->selection_start, - text->selection_end); - indices[1] = MAX ( - text->selection_start, - text->selection_end); - - /* convert these into byte indices */ - indices[0] = g_utf8_offset_to_pointer ( - text->text, indices[0]) - text->text; - indices[1] = g_utf8_offset_to_pointer ( - text->text, indices[1]) - text->text; - - clip_region = gdk_pango_layout_get_clip_region ( - text->layout, xpos, ypos, indices, 1); - gdk_cairo_region (cr, clip_region); - cairo_clip (cr); - cairo_region_destroy (clip_region); - - gdk_cairo_set_source_color (cr, &style->base[state]); - cairo_paint (cr); - - gdk_cairo_set_source_color (cr, &style->text[state]); - cairo_move_to (cr, xpos, ypos); - pango_cairo_show_layout (cr, text->layout); - } else { - if (text->show_cursor) { - PangoRectangle strong_pos, weak_pos; - gchar *offs; - - offs = g_utf8_offset_to_pointer ( - text->text, text->selection_start); - - pango_layout_get_cursor_pos ( - text->layout, offs - text->text + - text->preedit_len, &strong_pos, - &weak_pos); - draw_pango_rectangle (cr, xpos, ypos, strong_pos); - if (strong_pos.x != weak_pos.x || - strong_pos.y != weak_pos.y || - strong_pos.width != weak_pos.width || - strong_pos.height != weak_pos.height) - draw_pango_rectangle (cr, xpos, ypos, weak_pos); - } - } - } - - cairo_restore (cr); - cairo_restore (cr); -} - -/* Point handler for the text item */ -static GnomeCanvasItem * -e_text_point (GnomeCanvasItem *item, - gdouble x, - gdouble y, - gint cx, - gint cy) -{ - EText *text; - gdouble clip_width; - gdouble clip_height; - - text = E_TEXT (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->clip_width < 0) - clip_width = text->width; - else - clip_width = text->clip_width; - - if (text->clip_height < 0) - clip_height = text->height; - else - clip_height = text->clip_height; - - if (cx < text->clip_cx || - cx > text->clip_cx + clip_width || - cy < text->clip_cy || - cy > text->clip_cy + clip_height) - return NULL; - - if (text->fill_clip_rectangle || !text->text || !*text->text) - return item; - - cx -= text->cx; - - if (pango_layout_xy_to_index (text->layout, cx, cy, NULL, NULL)) - return item; - - return NULL; -} - -/* Bounds handler for the text item */ -static void -e_text_bounds (GnomeCanvasItem *item, - gdouble *x1, - gdouble *y1, - gdouble *x2, - gdouble *y2) -{ - EText *text; - gdouble width, height; - - text = E_TEXT (item); - - *x1 = 0; - *y1 = 0; - - width = text->width; - height = text->height; - - if (text->clip) { - if (text->clip_width >= 0) - width = text->clip_width; - if (text->clip_height >= 0) - height = text->clip_height; - } - - *x2 = *x1 + width; - *y2 = *y1 + height; -} - -static gint -get_position_from_xy (EText *text, - gint x, - gint y) -{ - gint index; - gint trailing; - - x -= text->xofs; - y -= text->yofs; - - if (text->editing) { - x += text->xofs_edit; - y += text->yofs_edit; - } - - x -= text->cx; - y -= text->cy; - - pango_layout_xy_to_index ( - text->layout, x * PANGO_SCALE, - y * PANGO_SCALE, &index, &trailing); - - return g_utf8_pointer_to_offset (text->text, text->text + index + trailing); -} - -#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 && text->clip) { - gint old_xofs_edit = text->xofs_edit; - gint old_yofs_edit = text->yofs_edit; - - if (text->clip_cwidth >= 0 && - text->lastx - text->clip_cx > text->clip_cwidth && - text->xofs_edit < text->width - text->clip_cwidth) { - text->xofs_edit += 4; - if (text->xofs_edit > text->width - text->clip_cwidth + 1) - text->xofs_edit = text->width - text->clip_cwidth + 1; - } - if (text->lastx - text->clip_cx < 0 && - text->xofs_edit > 0) { - text->xofs_edit -= 4; - if (text->xofs_edit < 0) - text->xofs_edit = 0; - } - - if (text->clip_cheight >= 0 && - 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; - } - if (text->lasty - text->clip_cy < 0 && - text->yofs_edit > 0) { - text->yofs_edit -= 4; - if (text->yofs_edit < 0) - text->yofs_edit = 0; - } - - if (old_xofs_edit != text->xofs_edit || - old_yofs_edit != text->yofs_edit) { - 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; - redraw = TRUE; - } - } - - 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 void -start_editing (EText *text) -{ - if (text->editing) - return; - - e_text_reset_im_context (text); - - g_free (text->revert); - text->revert = g_strdup (text->text); - - text->editing = TRUE; - if (text->pointer_in) { - GdkWindow *window; - - window = gtk_widget_get_window ( - GTK_WIDGET (GNOME_CANVAS_ITEM (text)->canvas)); - - if (text->default_cursor_shown) { - gdk_window_set_cursor (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); -} - -void -e_text_stop_editing (EText *text) -{ - if (!text->editing) - return; - - g_free (text->revert); - text->revert = NULL; - - text->editing = FALSE; - if (!text->default_cursor_shown) { - GdkWindow *window; - - window = gtk_widget_get_window ( - GTK_WIDGET (GNOME_CANVAS_ITEM (text)->canvas)); - gdk_window_set_cursor (window, text->default_cursor); - text->default_cursor_shown = TRUE; - } - if (text->timer) { - g_timer_stop (text->timer); - g_timer_destroy (text->timer); - text->timer = NULL; - } - - text->need_im_reset = TRUE; - text->preedit_len = 0; - text->preedit_pos = 0; -} - -void -e_text_cancel_editing (EText *text) -{ - if (text->revert) - e_text_model_set_text (text->model, text->revert); - e_text_stop_editing (text); -} - -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; - GdkWindow *window; - gint return_val = 0; - - if (!text->model) - return 0; - - window = gtk_widget_get_window (GTK_WIDGET (item->canvas)); - - 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->im_context) { - if (!text->im_context_signals_registered) { - g_signal_connect ( - text->im_context, "commit", - G_CALLBACK (e_text_commit_cb), text); - g_signal_connect ( - text->im_context, "preedit_changed", - G_CALLBACK (e_text_preedit_changed_cb), text); - g_signal_connect ( - text->im_context, "retrieve_surrounding", - G_CALLBACK (e_text_retrieve_surrounding_cb), text); - g_signal_connect ( - text->im_context, "delete_surrounding", - G_CALLBACK (e_text_delete_surrounding_cb), text); - text->im_context_signals_registered = TRUE; - } - gtk_im_context_focus_in (text->im_context); - } - - start_editing (text); - - /* So we'll redraw and the - * cursor will be shown. */ - text->show_cursor = FALSE; - } else { - if (text->im_context) { - gtk_im_context_focus_out (text->im_context); - disconnect_im_context (text); - text->need_im_reset = TRUE; - } - - e_text_stop_editing (text); - if (text->timeout_id) { - g_source_remove (text->timeout_id); - text->timeout_id = 0; - } - if (text->show_cursor) { - text->show_cursor = FALSE; - text->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (text)); - } - } - if (text->line_wrap) - text->needs_split_into_lines = 1; - e_canvas_item_request_reflow (GNOME_CANVAS_ITEM (text)); - } - return_val = 0; - break; - case GDK_KEY_PRESS: - - /* Handle S-F10 key binding here. */ - - if (event->key.keyval == GDK_KEY_F10 - && (event->key.state & GDK_SHIFT_MASK) - && text->handle_popup) { - - /* Simulate a GdkEventButton here, so that we can - * call e_text_do_popup directly */ - - GdkEvent *button_event; - - button_event = gdk_event_new (GDK_BUTTON_PRESS); - button_event->button.time = event->key.time; - button_event->button.button = 0; - e_text_do_popup (text, button_event, 0); - return 1; - } - - /* Fall Through */ - - case GDK_KEY_RELEASE: - - if (text->editing) { - GdkEventKey key; - gint ret; - - if (text->im_context && - gtk_im_context_filter_keypress ( - text->im_context, - (GdkEventKey *) event)) { - text->need_im_reset = TRUE; - return 1; - } - - key = event->key; - e_tep_event.key.time = key.time; - e_tep_event.key.state = key.state; - e_tep_event.key.keyval = key.keyval; - - /* This is probably ugly hack, but we - * have to handle UTF-8 input somehow. */ - e_tep_event.key.string = e_utf8_from_gtk_event_key ( - GTK_WIDGET (item->canvas), - key.keyval, key.string); - if (e_tep_event.key.string != NULL) { - e_tep_event.key.length = strlen (e_tep_event.key.string); - } else { - e_tep_event.key.length = 0; - } - - _get_tep (text); - ret = e_text_event_processor_handle_event (text->tep, &e_tep_event); - - if (event->type == GDK_KEY_PRESS) - g_signal_emit ( - text, e_text_signals[E_TEXT_KEYPRESS], 0, - e_tep_event.key.keyval, e_tep_event.key.state); - - if (e_tep_event.key.string) - g_free ((gpointer) e_tep_event.key.string); - - return ret; - } - break; - case GDK_BUTTON_PRESS: /* Fall Through */ - case GDK_BUTTON_RELEASE: - if ((!text->editing) - && text->editable - && (event->button.button == 1 || - event->button.button == 2)) { - e_canvas_item_grab_focus (item, TRUE); - start_editing (text); - } - - /* We follow convention and emit popup events on right-clicks. */ - if (event->type == GDK_BUTTON_PRESS && event->button.button == 3) { - if (text->handle_popup) { - e_text_do_popup ( - text, event, - get_position_from_xy ( - text, event->button.x, - event->button.y)); - return 1; - } - else { - break; - } - } - - /* 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 = g_timeout_add ( - 200, _click, &(text->dbl_timeout)); - } else { - if (text->tpl_timeout == 0) { - e_tep_event.type = GDK_2BUTTON_PRESS; - text->tpl_timeout = g_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); - e_tep_event.button.device = - gdk_event_get_device (event); - _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: - text->pointer_in = TRUE; - if (text->editing) { - if (text->default_cursor_shown) { - gdk_window_set_cursor (window, text->i_cursor); - text->default_cursor_shown = FALSE; - } - } - break; - case GDK_LEAVE_NOTIFY: - text->pointer_in = FALSE; - if (text->editing) { - if (!text->default_cursor_shown) { - gdk_window_set_cursor ( - window, text->default_cursor); - text->default_cursor_shown = TRUE; - } - } - break; - default: - break; - } - if (return_val) - return return_val; - if (GNOME_CANVAS_ITEM_CLASS (e_text_parent_class)->event) - return GNOME_CANVAS_ITEM_CLASS (e_text_parent_class)->event (item, event); - else - return 0; -} - -void -e_text_copy_clipboard (EText *text) -{ - gint selection_start_pos; - gint selection_end_pos; - - selection_start_pos = MIN (text->selection_start, text->selection_end); - selection_end_pos = MAX (text->selection_start, text->selection_end); - - /* convert sel_start/sel_end to byte indices */ - selection_start_pos = g_utf8_offset_to_pointer ( - text->text, selection_start_pos) - text->text; - selection_end_pos = g_utf8_offset_to_pointer ( - text->text, selection_end_pos) - text->text; - - gtk_clipboard_set_text ( - gtk_widget_get_clipboard ( - GTK_WIDGET (GNOME_CANVAS_ITEM (text)->canvas), - GDK_SELECTION_CLIPBOARD), - text->text + selection_start_pos, - selection_end_pos - selection_start_pos); -} - -void -e_text_delete_selection (EText *text) -{ - gint sel_start, sel_end; - - 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_model_delete (text->model, sel_start, sel_end - sel_start); - text->need_im_reset = TRUE; -} - -void -e_text_cut_clipboard (EText *text) -{ - e_text_copy_clipboard (text); - e_text_delete_selection (text); -} - -void -e_text_paste_clipboard (EText *text) -{ - ETextEventProcessorCommand command; - - command.action = E_TEP_PASTE; - command.position = E_TEP_SELECTION; - command.string = ""; - command.value = 0; - e_text_command (text->tep, &command, text); -} - -void -e_text_select_all (EText *text) -{ - ETextEventProcessorCommand command; - - command.action = E_TEP_SELECT; - command.position = E_TEP_SELECT_ALL; - command.string = ""; - command.value = 0; - e_text_command (text->tep, &command, text); -} - -static void -primary_get_cb (GtkClipboard *clipboard, - GtkSelectionData *selection_data, - guint info, - gpointer data) -{ - EText *text = E_TEXT (data); - gint sel_start, sel_end; - - sel_start = MIN (text->selection_start, text->selection_end); - sel_end = MAX (text->selection_start, text->selection_end); - - /* convert sel_start/sel_end to byte indices */ - sel_start = g_utf8_offset_to_pointer (text->text, sel_start) - text->text; - sel_end = g_utf8_offset_to_pointer (text->text, sel_end) - text->text; - - if (sel_start != sel_end) { - gtk_selection_data_set_text ( - selection_data, - text->text + sel_start, - sel_end - sel_start); - } -} - -static void -primary_clear_cb (GtkClipboard *clipboard, - gpointer data) -{ -#ifdef notyet - /* XXX */ - gtk_editable_select_region ( - GTK_EDITABLE (entry), entry->current_pos, entry->current_pos); -#endif -} - -static void -e_text_update_primary_selection (EText *text) -{ - static const GtkTargetEntry targets[] = { - { (gchar *) "UTF8_STRING", 0, 0 }, - { (gchar *) "UTF-8", 0, 0 }, - { (gchar *) "STRING", 0, 0 }, - { (gchar *) "TEXT", 0, 0 }, - { (gchar *) "COMPOUND_TEXT", 0, 0 } - }; - GtkClipboard *clipboard; - - clipboard = gtk_widget_get_clipboard ( - GTK_WIDGET (GNOME_CANVAS_ITEM (text)->canvas), - GDK_SELECTION_PRIMARY); - - if (text->selection_start != text->selection_end) { - if (!gtk_clipboard_set_with_owner ( - clipboard, targets, G_N_ELEMENTS (targets), - primary_get_cb, primary_clear_cb, G_OBJECT (text))) - primary_clear_cb (clipboard, text); - } else { - if (gtk_clipboard_get_owner (clipboard) == G_OBJECT (text)) - gtk_clipboard_clear (clipboard); - } -} - -static void -paste_received (GtkClipboard *clipboard, - const gchar *text, - gpointer data) -{ - EText *etext = E_TEXT (data); - - if (text && g_utf8_validate (text, strlen (text), NULL)) { - if (etext->selection_end != etext->selection_start) - e_text_delete_selection (etext); - - e_text_insert (etext, text); - } - - g_object_unref (etext); -} - -static void -e_text_paste (EText *text, - GdkAtom selection) -{ - g_object_ref (text); - gtk_clipboard_request_text ( - gtk_widget_get_clipboard ( - GTK_WIDGET (GNOME_CANVAS_ITEM (text)->canvas), - selection), paste_received, text); -} - -typedef struct { - EText *text; - GdkEvent *event; - gint position; -} PopupClosure; - -static void -popup_menu_detach (GtkWidget *attach_widget, - GtkMenu *menu) -{ -} - -static void -popup_menu_placement_cb (GtkMenu *menu, - gint *x, - gint *y, - gboolean *push_in, - gpointer user_data) -{ - EText *text = E_TEXT (user_data); - GnomeCanvasItem *item = &text->item; - GnomeCanvas *parent = item->canvas; - - if (parent) { - GdkWindow *window; - - window = gtk_widget_get_window (GTK_WIDGET (parent)); - gdk_window_get_origin (window, x, y); - *x += item->x1 + text->width / 2; - *y += item->y1 + text->height / 2; - } - - return; -} - -static void -popup_targets_received (GtkClipboard *clipboard, - GtkSelectionData *data, - gpointer user_data) -{ - PopupClosure *closure = user_data; - EText *text = closure->text; - GdkEvent *event = closure->event; - gint position = closure->position; - GtkWidget *popup_menu = gtk_menu_new (); - GtkWidget *menuitem, *submenu; - guint event_button = 0; - guint32 event_time; - - gdk_event_get_button (event, &event_button); - event_time = gdk_event_get_time (event); - - g_free (closure); - - gtk_menu_attach_to_widget ( - GTK_MENU (popup_menu), - GTK_WIDGET (GNOME_CANVAS_ITEM (text)->canvas), - popup_menu_detach); - - /* cut menu item */ - menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_CUT, NULL); - gtk_widget_show (menuitem); - gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), menuitem); - g_signal_connect_swapped ( - menuitem, "activate", - G_CALLBACK (e_text_cut_clipboard), text); - gtk_widget_set_sensitive ( - menuitem, text->editable && - (text->selection_start != text->selection_end)); - - /* copy menu item */ - menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_COPY, NULL); - gtk_widget_show (menuitem); - gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), menuitem); - g_signal_connect_swapped ( - menuitem, "activate", - G_CALLBACK (e_text_copy_clipboard), text); - gtk_widget_set_sensitive (menuitem, text->selection_start != text->selection_end); - - /* paste menu item */ - menuitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_PASTE, NULL); - gtk_widget_show (menuitem); - gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), menuitem); - g_signal_connect_swapped ( - menuitem, "activate", - G_CALLBACK (e_text_paste_clipboard), text); - gtk_widget_set_sensitive ( - menuitem, text->editable && - gtk_selection_data_targets_include_text (data)); - - menuitem = gtk_menu_item_new_with_label (_("Select All")); - gtk_widget_show (menuitem); - gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), menuitem); - g_signal_connect_swapped ( - menuitem, "activate", - G_CALLBACK (e_text_select_all), text); - gtk_widget_set_sensitive (menuitem, strlen (text->text) > 0); - - menuitem = gtk_separator_menu_item_new (); - gtk_widget_show (menuitem); - gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), menuitem); - - if (text->im_context && GTK_IS_IM_MULTICONTEXT (text->im_context)) { - menuitem = gtk_menu_item_new_with_label (_("Input Methods")); - gtk_widget_show (menuitem); - submenu = gtk_menu_new (); - gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), submenu); - - gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), menuitem); - - gtk_im_multicontext_append_menuitems ( - GTK_IM_MULTICONTEXT (text->im_context), - GTK_MENU_SHELL (submenu)); - } - - g_signal_emit ( - text, - e_text_signals[E_TEXT_POPULATE_POPUP], - 0, - event, - position, - popup_menu); - - /* If invoked by S-F10 key binding, button will be 0. */ - if (event_button == 0) { - gtk_menu_popup ( - GTK_MENU (popup_menu), NULL, NULL, - popup_menu_placement_cb, (gpointer) text, - event_button, GDK_CURRENT_TIME); - } else { - gtk_menu_popup ( - GTK_MENU (popup_menu), NULL, NULL, - NULL, NULL, - event_button, event_time); - } - - g_object_unref (text); - gdk_event_free (event); -} - -static void -e_text_do_popup (EText *text, - GdkEvent *button_event, - gint position) -{ - PopupClosure *closure = g_new (PopupClosure, 1); - - closure->text = g_object_ref (text); - closure->event = gdk_event_copy (button_event); - closure->position = position; - - gtk_clipboard_request_contents ( - gtk_widget_get_clipboard ( - GTK_WIDGET (GNOME_CANVAS_ITEM (text)->canvas), - GDK_SELECTION_CLIPBOARD), - gdk_atom_intern ("TARGETS", FALSE), - popup_targets_received, - closure); -} - -static void -e_text_reset_im_context (EText *text) -{ - if (text->need_im_reset && text->im_context) { - text->need_im_reset = FALSE; - gtk_im_context_reset (text->im_context); - } -} - -/* fixme: */ - -static gint -next_word (EText *text, - gint start) -{ - gchar *p = g_utf8_offset_to_pointer (text->text, start); - gint length; - - length = g_utf8_strlen (text->text, -1); - - if (start >= length) { - return length; - } else { - p = g_utf8_next_char (p); - start++; - - while (p && *p) { - gunichar unival = g_utf8_get_char (p); - if (g_unichar_isspace (unival)) { - return start + 1; - } - else { - p = g_utf8_next_char (p); - start++; - } - } - } - - return g_utf8_pointer_to_offset (text->text, p); -} - -static gint -find_offset_into_line (EText *text, - gint offset_into_text, - gchar **start_of_line) -{ - gchar *p; - - p = g_utf8_offset_to_pointer (text->text, offset_into_text); - - if (p == text->text) { - if (start_of_line) - *start_of_line = (gchar *)text->text; - return 0; - } - else { - p = g_utf8_find_prev_char (text->text, p); - - while (p && p > text->text) { - if (*p == '\n') { - if (start_of_line) - *start_of_line = p+1; - return offset_into_text - - g_utf8_pointer_to_offset ( - text->text, p + 1); - } - p = g_utf8_find_prev_char (text->text, p); - } - - if (start_of_line) - *start_of_line = (gchar *)text->text; - return offset_into_text; - } -} - -/* direction = TRUE (move forward), FALSE (move backward) - * Any error shall return length (text->text) or 0 or - * text->selection_end (as deemed fit) */ -static gint -_get_updated_position (EText *text, - gboolean direction) -{ - PangoLogAttr *log_attrs = NULL; - gint n_attrs; - gchar *p = NULL; - gint new_pos = 0; - gint length = 0; - - /* Basic sanity test, return whatever position we are currently at. */ - g_return_val_if_fail (text->layout != NULL, text->selection_end); - - length = g_utf8_strlen (text->text, -1); - - /* length checks to make sure we are not wandering - * off into nonexistant memory... */ - if ((text->selection_end >= length) && (TRUE == direction)) /* forward */ - return length; - /* checking for -ve value wont hurt! */ - if ((text->selection_end <= 0) && (FALSE == direction)) /* backward */ - return 0; - - /* check for validness of full text->text */ - if (!g_utf8_validate (text->text, -1, NULL)) - return text->selection_end; - - /* get layout's PangoLogAttr to facilitate moving when - * moving across grapheme cluster as in indic langs */ - pango_layout_get_log_attrs (text->layout, &log_attrs, &n_attrs); - - /* Fetch the current gchar index in the line & keep moving - * forward until we can display cursor */ - p = g_utf8_offset_to_pointer (text->text, text->selection_end); - - new_pos = text->selection_end; - while (1) - { - /* check before moving forward/backwards - * if we have more chars to move or not */ - if (TRUE == direction) - p = g_utf8_next_char (p); - else - p = g_utf8_prev_char (p); - - /* validate the new string & return with original position if check fails */ - if (!g_utf8_validate (p, -1, NULL)) - break; /* will return old value of new_pos */ - - new_pos = g_utf8_pointer_to_offset (text->text, p); - - /* if is_cursor_position is set, cursor can appear in front of character. - * i.e. this is a grapheme boundary AND make some sanity checks */ - if ((new_pos >=0) && (new_pos < n_attrs) && - (log_attrs[new_pos].is_cursor_position)) - break; - else if ((new_pos < 0) || (new_pos >= n_attrs)) - { - new_pos = text->selection_end; - break; - } - } - - if (log_attrs) - g_free (log_attrs); - - return new_pos; -} - -static gint -_get_position (EText *text, - ETextEventProcessorCommand *command) -{ - gint length, obj_num; - gunichar unival; - gchar *p = NULL; - gint new_pos = 0; - - switch (command->position) { - - case E_TEP_VALUE: - new_pos = command->value; - break; - - case E_TEP_SELECTION: - new_pos = text->selection_end; - break; - - case E_TEP_START_OF_BUFFER: - new_pos = 0; - break; - - case E_TEP_END_OF_BUFFER: - new_pos = strlen (text->text); - break; - - case E_TEP_START_OF_LINE: - - if (text->selection_end >= 1) { - - p = g_utf8_offset_to_pointer (text->text, text->selection_end); - if (p != text->text) { - p = g_utf8_find_prev_char (text->text, p); - while (p && p > text->text) { - if (*p == '\n') { - new_pos = g_utf8_pointer_to_offset (text->text, p) + 1; - break; - } - p = g_utf8_find_prev_char (text->text, p); - } - } - } - - break; - - case E_TEP_END_OF_LINE: - new_pos = -1; - length = g_utf8_strlen (text->text, -1); - - if (text->selection_end >= length) { - new_pos = length; - } else { - - p = g_utf8_offset_to_pointer (text->text, text->selection_end); - - while (p && *p) { - if (*p == '\n') { - new_pos = g_utf8_pointer_to_offset (text->text, p); - p = NULL; - } else - p = g_utf8_next_char (p); - } - } - - if (new_pos == -1) - new_pos = g_utf8_pointer_to_offset (text->text, p); - - break; - - case E_TEP_FORWARD_CHARACTER: - length = g_utf8_strlen (text->text, -1); - - if (text->selection_end >= length) - new_pos = length; - else - /* get updated position to display cursor */ - new_pos = _get_updated_position (text, TRUE); - - break; - - case E_TEP_BACKWARD_CHARACTER: - new_pos = 0; - if (text->selection_end >= 1) - /* get updated position to display cursor */ - new_pos = _get_updated_position (text, FALSE); - - break; - - case E_TEP_FORWARD_WORD: - new_pos = next_word (text, text->selection_end); - break; - - case E_TEP_BACKWARD_WORD: - new_pos = 0; - if (text->selection_end >= 1) { - gint pos = text->selection_end; - - p = g_utf8_find_prev_char ( - text->text, g_utf8_offset_to_pointer ( - text->text, text->selection_end)); - pos--; - - if (p != text->text) { - p = g_utf8_find_prev_char (text->text, p); - pos--; - - while (p && p > text->text) { - unival = g_utf8_get_char (p); - if (g_unichar_isspace (unival)) { - new_pos = pos + 1; - p = NULL; - } - else { - p = g_utf8_find_prev_char (text->text, p); - pos--; - } - } - } - } - - break; - - case E_TEP_FORWARD_LINE: { - gint offset_into_line; - - offset_into_line = find_offset_into_line (text, text->selection_end, NULL); - if (offset_into_line == -1) - return text->selection_end; - - /* now we search forward til we hit a \n, and then - * offset_into_line more characters */ - p = g_utf8_offset_to_pointer (text->text, text->selection_end); - while (p && *p) { - if (*p == '\n') - break; - p = g_utf8_next_char (p); - } - if (p && *p == '\n') { - /* now we loop forward offset_into_line - * characters, or until we hit \n or \0 */ - - p = g_utf8_next_char (p); - while (offset_into_line > 0 && p && *p != '\n' && *p != '\0') { - p = g_utf8_next_char (p); - offset_into_line--; - } - } - - /* at this point, p points to the new location, - * convert it to an offset and we're done */ - new_pos = g_utf8_pointer_to_offset (text->text, p); - break; - } - case E_TEP_BACKWARD_LINE: { - gint offset_into_line; - - offset_into_line = find_offset_into_line ( - text, text->selection_end, &p); - - if (offset_into_line == -1) - return text->selection_end; - - /* p points to the first character on our line. if we - * have a \n before it, skip it and scan til we hit - * the next one */ - if (p != text->text) { - p = g_utf8_find_prev_char (text->text, p); - if (*p == '\n') { - p = g_utf8_find_prev_char (text->text, p); - while (p > text->text) { - if (*p == '\n') { - p++; - break; - } - p = g_utf8_find_prev_char (text->text, p); - } - } - } - - /* at this point 'p' points to the start of the - * previous line, move forward 'offset_into_line' - * times. */ - - while (offset_into_line > 0 && p && *p != '\n' && *p != '\0') { - p = g_utf8_next_char (p); - offset_into_line--; - } - - /* at this point, p points to the new location, - * convert it to an offset and we're done */ - new_pos = g_utf8_pointer_to_offset (text->text, p); - break; - } - case E_TEP_SELECT_WORD: - /* This is a silly hack to cause double-clicking on an object - * to activate that object. - * (Normally, double click == select word, which is why this is here.) */ - - obj_num = e_text_model_get_object_at_offset ( - text->model, text->selection_start); - if (obj_num != -1) { - e_text_model_activate_nth_object (text->model, obj_num); - new_pos = text->selection_start; - break; - } - - if (text->selection_end < 1) { - new_pos = 0; - break; - } - - p = g_utf8_offset_to_pointer (text->text, text->selection_end); - - p = g_utf8_find_prev_char (text->text, p); - - while (p && p > text->text) { - unival = g_utf8_get_char (p); - if (g_unichar_isspace (unival)) { - p = g_utf8_next_char (p); - break; - } - p = g_utf8_find_prev_char (text->text, p); - } - - if (!p) - text->selection_start = 0; - else - text->selection_start = g_utf8_pointer_to_offset (text->text, p); - - text->selection_start = - e_text_model_validate_position ( - text->model, text->selection_start); - - length = g_utf8_strlen (text->text, -1); - if (text->selection_end >= length) { - new_pos = length; - break; - } - - p = g_utf8_offset_to_pointer (text->text, text->selection_end); - while (p && *p) { - unival = g_utf8_get_char (p); - if (g_unichar_isspace (unival)) { - new_pos = g_utf8_pointer_to_offset (text->text, p); - break; - } else - p = g_utf8_next_char (p); - } - - if (!new_pos) - new_pos = g_utf8_strlen (text->text, -1); - - return new_pos; - - case E_TEP_SELECT_ALL: - text->selection_start = 0; - new_pos = g_utf8_strlen (text->text, -1); - break; - - case E_TEP_FORWARD_PARAGRAPH: - case E_TEP_BACKWARD_PARAGRAPH: - - case E_TEP_FORWARD_PAGE: - case E_TEP_BACKWARD_PAGE: - new_pos = text->selection_end; - break; - - default: - new_pos = text->selection_end; - break; - } - - new_pos = e_text_model_validate_position (text->model, new_pos); - - return new_pos; -} - -static void -e_text_insert (EText *text, - const gchar *string) -{ - gint len = strlen (string); - - if (len > 0) { - gint utf8len = 0; - - if (!text->allow_newlines) { - const gchar *i; - gchar *new_string = g_malloc (len + 1); - gchar *j = new_string; - - for (i = string; *i; i = g_utf8_next_char (i)) { - if (*i != '\n') { - gunichar c; - gint charlen; - - c = g_utf8_get_char (i); - charlen = g_unichar_to_utf8 (c, j); - j += charlen; - utf8len++; - } - } - *j = 0; - e_text_model_insert_length ( - text->model, text->selection_start, - new_string, utf8len); - g_free (new_string); - } - else { - utf8len = g_utf8_strlen (string, -1); - e_text_model_insert_length ( - text->model, text->selection_start, - string, utf8len); - } - } -} - -static void -capitalize (EText *text, - gint start, - gint end, - ETextEventProcessorCaps type) -{ - gboolean first = TRUE; - const gchar *p = g_utf8_offset_to_pointer (text->text, start); - const gchar *text_end = g_utf8_offset_to_pointer (text->text, end); - gint utf8len = text_end - p; - - if (utf8len > 0) { - gchar *new_text = g_new0 (char, utf8len * 6); - gchar *output = new_text; - - while (p && *p && p < text_end) { - gunichar unival = g_utf8_get_char (p); - gunichar newval = unival; - - switch (type) { - case E_TEP_CAPS_UPPER: - newval = g_unichar_toupper (unival); - break; - case E_TEP_CAPS_LOWER: - newval = g_unichar_tolower (unival); - break; - case E_TEP_CAPS_TITLE: - if (g_unichar_isalpha (unival)) { - if (first) - newval = g_unichar_totitle (unival); - else - newval = g_unichar_tolower (unival); - first = FALSE; - } else { - first = TRUE; - } - break; - } - g_unichar_to_utf8 (newval, output); - output = g_utf8_next_char (output); - - p = g_utf8_next_char (p); - } - *output = 0; - - e_text_model_delete (text->model, start, utf8len); - e_text_model_insert_length (text->model, start, new_text, utf8len); - g_free (new_text); - } -} - -static void -e_text_command (ETextEventProcessor *tep, - ETextEventProcessorCommand *command, - gpointer data) -{ - EText *text = E_TEXT (data); - gboolean scroll = TRUE; - gboolean use_start = TRUE; - - 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); - } - - text->need_im_reset = TRUE; - use_start = TRUE; - break; - case E_TEP_SELECT: - text->selection_start = - e_text_model_validate_position ( - text->model, text->selection_start); /* paranoia */ - text->selection_end = _get_position (text, command); - - e_text_update_primary_selection (text); - - text->need_im_reset = TRUE; - use_start = FALSE; - - break; - case E_TEP_DELETE: - if (text->selection_end == text->selection_start) { - text->selection_end = _get_position (text, command); - } - e_text_delete_selection (text); - if (text->timer) { - g_timer_reset (text->timer); - } - - text->need_im_reset = TRUE; - use_start = FALSE; - - break; - - case E_TEP_INSERT: - if (g_utf8_validate (command->string, command->value, NULL)) { - if (text->selection_end != text->selection_start) { - e_text_delete_selection (text); - } - e_text_insert (text, command->string); - if (text->timer) { - g_timer_reset (text->timer); - } - text->need_im_reset = TRUE; - } - break; - case E_TEP_COPY: - e_text_copy_clipboard (text); - - if (text->timer) { - g_timer_reset (text->timer); - } - scroll = FALSE; - break; - case E_TEP_PASTE: - e_text_paste (text, GDK_NONE); - if (text->timer) { - g_timer_reset (text->timer); - } - text->need_im_reset = TRUE; - break; - case E_TEP_GET_SELECTION: - e_text_paste (text, GDK_SELECTION_PRIMARY); - break; - case E_TEP_ACTIVATE: - g_signal_emit (text, e_text_signals[E_TEXT_ACTIVATE], 0); - 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: - e_canvas_item_grab ( - E_CANVAS (GNOME_CANVAS_ITEM (text)->canvas), - GNOME_CANVAS_ITEM (text), - GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, - text->i_cursor, - command->device, - command->time, - NULL, - NULL); - scroll = FALSE; - break; - case E_TEP_UNGRAB: - e_canvas_item_ungrab ( - E_CANVAS (GNOME_CANVAS_ITEM (text)->canvas), - GNOME_CANVAS_ITEM (text), - command->time); - scroll = FALSE; - break; - case E_TEP_CAPS: - if (text->selection_start == text->selection_end) { - capitalize ( - text, text->selection_start, - next_word (text, text->selection_start), - command->value); - } else { - gint selection_start = MIN ( - text->selection_start, text->selection_end); - gint selection_end = MAX ( - text->selection_start, text->selection_end); - capitalize ( - text, selection_start, - selection_end, command->value); - } - break; - case E_TEP_NOP: - scroll = FALSE; - break; - } - - e_text_reset_im_context (text); - - /* it's possible to get here without ever having been realized - * by our canvas (if the e-text started completely obscured.) - * so let's create our layout object if we don't already have - * one. */ - if (!text->layout) - create_layout (text); - - /* We move cursor only if scroll is TRUE */ - if (scroll && !text->button_down) { - /* XXX do we really need the @trailing logic here? if - * we don't we can scrap the loop and just use - * pango_layout_index_to_pos */ - PangoLayoutLine *cur_line = NULL; - gint selection_index; - PangoLayoutIter *iter = pango_layout_get_iter (text->layout); - - /* check if we are using selection_start or selection_end for moving? */ - selection_index = use_start ? text->selection_start : text->selection_end; - - /* convert to a byte index */ - selection_index = g_utf8_offset_to_pointer ( - text->text, selection_index) - text->text; - - do { - PangoLayoutLine *line = pango_layout_iter_get_line (iter); - - if (selection_index >= line->start_index && - selection_index <= line->start_index + line->length) { - /* found the line with the start of the selection */ - cur_line = line; - break; - } - - } while (pango_layout_iter_next_line (iter)); - - if (cur_line) { - gint xpos, ypos; - gdouble clip_width, clip_height; - /* gboolean trailing = FALSE; */ - PangoRectangle pango_pos; - - if (selection_index > 0 && selection_index == - cur_line->start_index + cur_line->length) { - selection_index--; - /* trailing = TRUE; */ - } - - pango_layout_index_to_pos (text->layout, selection_index, &pango_pos); - - pango_pos.x = PANGO_PIXELS (pango_pos.x); - pango_pos.y = PANGO_PIXELS (pango_pos.y); - pango_pos.width = (pango_pos.width + PANGO_SCALE / 2) / PANGO_SCALE; - pango_pos.height = (pango_pos.height + PANGO_SCALE / 2) / PANGO_SCALE; - - /* scroll for X */ - xpos = pango_pos.x; /* + (trailing ? 0 : pango_pos.width);*/ - - if (xpos + 2 < text->xofs_edit) { - text->xofs_edit = xpos; - } - - clip_width = text->clip_width; - - if (xpos + pango_pos.width - clip_width > text->xofs_edit) { - text->xofs_edit = xpos + pango_pos.width - clip_width; - } - - /* scroll for Y */ - if (pango_pos.y + 2 < text->yofs_edit) { - ypos = pango_pos.y; - text->yofs_edit = ypos; - } - else { - ypos = pango_pos.y + pango_pos.height; - } - - if (text->clip_height < 0) - clip_height = text->height; - else - clip_height = text->clip_height; - - if (ypos - clip_height > text->yofs_edit) { - text->yofs_edit = ypos - clip_height; - } - - } - - pango_layout_iter_free (iter); - } - - text->needs_redraw = 1; - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (text)); -} - -/* Class initialization function for the text item */ -static void -e_text_class_init (ETextClass *class) -{ - GObjectClass *gobject_class; - GnomeCanvasItemClass *item_class; - - gobject_class = (GObjectClass *) class; - item_class = (GnomeCanvasItemClass *) class; - - gobject_class->dispose = e_text_dispose; - gobject_class->set_property = e_text_set_property; - gobject_class->get_property = e_text_get_property; - - 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->event = e_text_event; - - class->changed = NULL; - class->activate = NULL; - - e_text_signals[E_TEXT_CHANGED] = g_signal_new ( - "changed", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETextClass, changed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - e_text_signals[E_TEXT_ACTIVATE] = g_signal_new ( - "activate", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETextClass, activate), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - e_text_signals[E_TEXT_KEYPRESS] = g_signal_new ( - "keypress", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETextClass, keypress), - NULL, NULL, - e_marshal_NONE__INT_INT, - G_TYPE_NONE, 2, - G_TYPE_UINT, - G_TYPE_UINT); - - e_text_signals[E_TEXT_POPULATE_POPUP] = g_signal_new ( - "populate_popup", - G_OBJECT_CLASS_TYPE (gobject_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ETextClass, populate_popup), - NULL, NULL, - e_marshal_NONE__POINTER_INT_OBJECT, - G_TYPE_NONE, 3, - G_TYPE_POINTER, - G_TYPE_INT, - GTK_TYPE_MENU); - - g_object_class_install_property ( - gobject_class, - PROP_MODEL, - g_param_spec_object ( - "model", - "Model", - "Model", - E_TYPE_TEXT_MODEL, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_EVENT_PROCESSOR, - g_param_spec_object ( - "event_processor", - "Event Processor", - "Event Processor", - E_TEXT_EVENT_PROCESSOR_TYPE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_TEXT, - g_param_spec_string ( - "text", - "Text", - "Text", - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_BOLD, - g_param_spec_boolean ( - "bold", - "Bold", - "Bold", - FALSE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_STRIKEOUT, - g_param_spec_boolean ( - "strikeout", - "Strikeout", - "Strikeout", - FALSE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_JUSTIFICATION, - g_param_spec_enum ( - "justification", - "Justification", - "Justification", - GTK_TYPE_JUSTIFICATION, - GTK_JUSTIFY_LEFT, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_CLIP_WIDTH, - g_param_spec_double ( - "clip_width", - "Clip Width", - "Clip Width", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_CLIP_HEIGHT, - g_param_spec_double ( - "clip_height", - "Clip Height", - "Clip Height", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_CLIP, - g_param_spec_boolean ( - "clip", - "Clip", - "Clip", - FALSE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_FILL_CLIP_RECTANGLE, - g_param_spec_boolean ( - "fill_clip_rectangle", - "Fill clip rectangle", - "Fill clip rectangle", - FALSE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_X_OFFSET, - g_param_spec_double ( - "x_offset", - "X Offset", - "X Offset", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_Y_OFFSET, - g_param_spec_double ( - "y_offset", - "Y Offset", - "Y Offset", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_FILL_COLOR, - g_param_spec_string ( - "fill_color", - "Fill color", - "Fill color", - NULL, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - gobject_class, - PROP_FILL_COLOR_GDK, - g_param_spec_boxed ( - "fill_color_gdk", - "GDK fill color", - "GDK fill color", - GDK_TYPE_COLOR, - G_PARAM_WRITABLE)); - - g_object_class_install_property ( - gobject_class, - PROP_FILL_COLOR_RGBA, - g_param_spec_uint ( - "fill_color_rgba", - "GDK fill color", - "GDK fill color", - 0, G_MAXUINT, 0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_TEXT_WIDTH, - g_param_spec_double ( - "text_width", - "Text width", - "Text width", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READABLE)); - - g_object_class_install_property ( - gobject_class, - PROP_TEXT_HEIGHT, - g_param_spec_double ( - "text_height", - "Text height", - "Text height", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READABLE)); - - g_object_class_install_property ( - gobject_class, - PROP_EDITABLE, - g_param_spec_boolean ( - "editable", - "Editable", - "Editable", - FALSE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_USE_ELLIPSIS, - g_param_spec_boolean ( - "use_ellipsis", - "Use ellipsis", - "Use ellipsis", - FALSE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_ELLIPSIS, - g_param_spec_string ( - "ellipsis", - "Ellipsis", - "Ellipsis", - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_LINE_WRAP, - g_param_spec_boolean ( - "line_wrap", - "Line wrap", - "Line wrap", - FALSE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_BREAK_CHARACTERS, - g_param_spec_string ( - "break_characters", - "Break characters", - "Break characters", - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, PROP_MAX_LINES, - g_param_spec_int ( - "max_lines", - "Max lines", - "Max lines", - 0, G_MAXINT, 0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_WIDTH, - g_param_spec_double ( - "width", - "Width", - "Width", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_HEIGHT, - g_param_spec_double ( - "height", - "Height", - "Height", - 0.0, G_MAXDOUBLE, 0.0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_ALLOW_NEWLINES, - g_param_spec_boolean ( - "allow_newlines", - "Allow newlines", - "Allow newlines", - FALSE, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_CURSOR_POS, - g_param_spec_int ( - "cursor_pos", - "Cursor position", - "Cursor position", - 0, G_MAXINT, 0, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_IM_CONTEXT, - g_param_spec_object ( - "im_context", - "IM Context", - "IM Context", - GTK_TYPE_IM_CONTEXT, - G_PARAM_READWRITE)); - - g_object_class_install_property ( - gobject_class, - PROP_HANDLE_POPUP, - g_param_spec_boolean ( - "handle_popup", - "Handle Popup", - "Handle Popup", - FALSE, - G_PARAM_READWRITE)); - - if (!clipboard_atom) - clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE); - - gal_a11y_e_text_init (); -} - -/* Object initialization function for the text item */ -static void -e_text_init (EText *text) -{ - text->model = e_text_model_new (); - text->text = e_text_model_get_text (text->model); - text->preedit_len = 0; - text->preedit_pos = 0; - text->layout = NULL; - - text->revert = NULL; - - text->model_changed_signal_id = g_signal_connect ( - text->model, "changed", - G_CALLBACK (e_text_text_model_changed), text); - - text->model_repos_signal_id = g_signal_connect ( - text->model, "reposition", - G_CALLBACK (e_text_text_model_reposition), text); - - 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->pointer_in = FALSE; - text->default_cursor_shown = TRUE; - text->line_wrap = FALSE; - text->break_characters = NULL; - text->max_lines = -1; - text->dbl_timeout = 0; - text->tpl_timeout = 0; - - text->bold = FALSE; - text->strikeout = FALSE; - - text->allow_newlines = TRUE; - - text->last_type_request = -1; - text->last_time_request = 0; - text->queued_requests = NULL; - - text->im_context = NULL; - text->need_im_reset = FALSE; - text->im_context_signals_registered = FALSE; - - text->handle_popup = FALSE; - text->rgba_set = FALSE; - - e_canvas_item_set_reflow_callback (GNOME_CANVAS_ITEM (text), e_text_reflow); -} - -/* IM Context Callbacks */ -static void -e_text_commit_cb (GtkIMContext *context, - const gchar *str, - EText *text) -{ - if (g_utf8_validate (str, strlen (str), NULL)) { - if (text->selection_end != text->selection_start) - e_text_delete_selection (text); - e_text_insert (text, str); - g_signal_emit (text, e_text_signals[E_TEXT_KEYPRESS], 0, 0, 0); - } -} - -static void -e_text_preedit_changed_cb (GtkIMContext *context, - EText *etext) -{ - gchar *preedit_string = NULL; - gint cursor_pos; - - gtk_im_context_get_preedit_string ( - context, &preedit_string, - NULL, &cursor_pos); - - cursor_pos = CLAMP (cursor_pos, 0, g_utf8_strlen (preedit_string, -1)); - etext->preedit_len = strlen (preedit_string); - etext->preedit_pos = g_utf8_offset_to_pointer ( - preedit_string, cursor_pos) - preedit_string; - g_free (preedit_string); - - g_signal_emit (etext, e_text_signals[E_TEXT_KEYPRESS], 0, 0, 0); -} - -static gboolean -e_text_retrieve_surrounding_cb (GtkIMContext *context, - EText *text) -{ - gtk_im_context_set_surrounding ( - context, text->text, strlen (text->text), - g_utf8_offset_to_pointer (text->text, MIN ( - text->selection_start, text->selection_end)) - text->text); - - return TRUE; -} - -static gboolean -e_text_delete_surrounding_cb (GtkIMContext *context, - gint offset, - gint n_chars, - EText *text) -{ - e_text_model_delete ( - text->model, - MIN (text->selection_start, text->selection_end) + offset, - n_chars); - - return TRUE; -} diff --git a/widgets/text/e-text.h b/widgets/text/e-text.h deleted file mode 100644 index b3099f1a64..0000000000 --- a/widgets/text/e-text.h +++ /dev/null @@ -1,232 +0,0 @@ -/* - * e-text.h - Text item for evolution. - * - * This program 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 program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Chris Lahey - * Jon Trowbridge - * - * 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 - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_TEXT_H -#define E_TEXT_H - -#include - -#include -#include -#include - -G_BEGIN_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 - * bold boolean RW Bold? - * 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 - * clip_width gdouble RW Width of clip rectangle - * clip_height gdouble 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 gdouble RW Horizontal offset distance from anchor position - * y_offset gdouble RW Vertical offset distance from anchor position - * text_width gdouble R Used to query the width of the rendered text - * text_height gdouble R Used to query the rendered height of the text - * width gdouble RW A synonym for clip_width - * height gdouble 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 gint RW Number of lines possible when doing line wrap. - */ - -#define E_TYPE_TEXT (e_text_get_type ()) -#define E_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_TEXT, EText)) -#define E_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_TEXT, ETextClass)) -#define E_IS_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_TEXT)) -#define E_IS_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), E_TYPE_TEXT)) - -typedef struct _EText EText; -typedef struct _ETextClass ETextClass; - -struct _EText { - GnomeCanvasItem item; - - ETextModel *model; - gint model_changed_signal_id; - gint model_repos_signal_id; - - const gchar *text; /* Text to display --- from the ETextModel */ - gint preedit_len; /* preedit length to display */ - gint preedit_pos; /* preedit cursor position */ - PangoLayout *layout; - gint num_lines; /* Number of lines of text */ - - gchar *revert; /* Text to revert to */ - - GtkJustification justification; /* Justification for text */ - - gdouble clip_width; /* Width of optional clip rectangle */ - gdouble clip_height; /* Height of optional clip rectangle */ - - gdouble xofs, yofs; /* Text offset distance from anchor position */ - - gint cx, cy; /* Top-left canvas coordinates for text */ - gint text_cx, text_cy; /* Top-left canvas coordinates for text */ - gint clip_cx, clip_cy; /* Top-left canvas coordinates for clip rectangle */ - gint clip_cwidth, clip_cheight; /* Size of clip rectangle in pixels */ - gint max_width; /* Maximum width of text lines */ - gint width; /* Rendered text width in pixels */ - gint height; /* Rendered text height in pixels */ - - guint32 rgba; /* RGBA color for text */ - gboolean rgba_set; /* whether RGBA is set */ - - gchar *ellipsis; /* The ellipsis characters. NULL = "...". */ - gdouble ellipsis_width; /* The width of the ellipsis. */ - - gint xofs_edit; /* Offset because of editing */ - gint yofs_edit; /* Offset because of editing */ - - /* This needs to be reworked a bit once we get line wrapping. */ - gint selection_start; /* Start of selection IN BYTES */ - gint selection_end; /* End of selection IN BYTES */ - gboolean select_by_word; /* Current selection is by word */ - - /* This section is for drag scrolling and blinking cursor. */ - 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; - - gboolean has_selection; /* TRUE if we have the selection */ - - guint clip : 1; /* Use clip rectangle? */ - guint fill_clip_rectangle : 1; /* Fill the clipping rectangle. */ - - guint pointer_in : 1; /* Is the pointer currently over us? */ - guint default_cursor_shown : 1; /* Is the default cursor currently shown? */ - - guint line_wrap : 1; /* Do line wrap */ - - guint needs_redraw : 1; /* Needs redraw */ - guint needs_recalc_bounds : 1; /* Need recalc_bounds */ - guint needs_calc_height : 1; /* Need calc_height */ - guint needs_split_into_lines : 1; /* Needs split_into_lines */ - guint needs_reset_layout : 1; /* Needs split_into_lines */ - - guint bold : 1; - guint strikeout : 1; - - guint tooltip_owner : 1; - guint allow_newlines : 1; - - guint use_ellipsis : 1; /* Whether to use the ellipsis. */ - - guint editable : 1; /* Item is editable */ - guint editing : 1; /* Item is currently being edited */ - - 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 */ - gint tooltip_count; /* GDK_ENTER_NOTIFY count. */ - - gint dbl_timeout; /* Double click timeout */ - gint tpl_timeout; /* Triple click timeout */ - - gint last_type_request; /* Last selection type requested. */ - guint32 last_time_request; /* The time of the last selection request. */ - GdkAtom last_selection_request; /* The time of the last selection request. */ - GList *queued_requests; /* Queued selection requests. */ - - GtkIMContext *im_context; - gboolean need_im_reset; - gboolean im_context_signals_registered; - - gboolean handle_popup; - - PangoFontDescription *font_desc; -}; - -struct _ETextClass { - GnomeCanvasItemClass parent_class; - - void (* changed) (EText *text); - void (* activate) (EText *text); - void (* keypress) (EText *text, guint keyval, guint state); - void (* populate_popup) (EText *text, GdkEvent *button_event, gint pos, GtkMenu *menu); - void (* style_set) (EText *text, GtkStyle *previous_style); -}; - -/* Standard Gtk function */ -GType e_text_get_type (void); -void e_text_cancel_editing (EText *text); -void e_text_stop_editing (EText *text); - -void e_text_delete_selection (EText *text); -void e_text_cut_clipboard (EText *text); -void e_text_copy_clipboard (EText *text); -void e_text_paste_clipboard (EText *text); -void e_text_select_all (EText *text); - -G_END_DECLS - -#endif diff --git a/widgets/text/gal-a11y-e-text-factory.c b/widgets/text/gal-a11y-e-text-factory.c deleted file mode 100644 index 8e33b38562..0000000000 --- a/widgets/text/gal-a11y-e-text-factory.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Christopher James Lahey - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include "text/e-text.h" -#include "gal-a11y-e-text-factory.h" -#include "gal-a11y-e-text.h" - -static AtkObjectFactoryClass *parent_class; -#define PARENT_TYPE (ATK_TYPE_OBJECT_FACTORY) - -/* Static functions */ - -static GType -gal_a11y_e_text_factory_get_accessible_type (void) -{ - return GAL_A11Y_TYPE_E_TEXT; -} - -static AtkObject * -gal_a11y_e_text_factory_create_accessible (GObject *obj) -{ - AtkObject *atk_object; - - g_return_val_if_fail (E_IS_TEXT (obj), NULL); - - atk_object = g_object_new (GAL_A11Y_TYPE_E_TEXT, NULL); - atk_object_initialize (atk_object, obj); - - return atk_object; -} - -static void -gal_a11y_e_text_factory_class_init (GalA11yETextFactoryClass *class) -{ - AtkObjectFactoryClass *factory_class = ATK_OBJECT_FACTORY_CLASS (class); - - parent_class = g_type_class_ref (PARENT_TYPE); - - factory_class->create_accessible = gal_a11y_e_text_factory_create_accessible; - factory_class->get_accessible_type = gal_a11y_e_text_factory_get_accessible_type; -} - -static void -gal_a11y_e_text_factory_init (GalA11yETextFactory *factory) -{ -} - -/** - * gal_a11y_e_text_factory_get_type: - * @void: - * - * Registers the &GalA11yETextFactory class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &GalA11yETextFactory class. - **/ -GType -gal_a11y_e_text_factory_get_type (void) -{ - static GType type = 0; - - if (!type) { - GTypeInfo info = { - sizeof (GalA11yETextFactoryClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) gal_a11y_e_text_factory_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GalA11yETextFactory), - 0, - (GInstanceInitFunc) gal_a11y_e_text_factory_init, - NULL /* value_text */ - }; - - type = g_type_register_static (PARENT_TYPE, "GalA11yETextFactory", &info, 0); - } - - return type; -} diff --git a/widgets/text/gal-a11y-e-text-factory.h b/widgets/text/gal-a11y-e-text-factory.h deleted file mode 100644 index 1e66d34ff8..0000000000 --- a/widgets/text/gal-a11y-e-text-factory.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Christopher James Lahey - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __GAL_A11Y_E_TEXT_FACTORY_H__ -#define __GAL_A11Y_E_TEXT_FACTORY_H__ - -#include - -#define GAL_A11Y_TYPE_E_TEXT_FACTORY (gal_a11y_e_text_factory_get_type ()) -#define GAL_A11Y_E_TEXT_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAL_A11Y_TYPE_E_TEXT_FACTORY, GalA11yETextFactory)) -#define GAL_A11Y_E_TEXT_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAL_A11Y_TYPE_E_TEXT_FACTORY, GalA11yETextFactoryClass)) -#define GAL_A11Y_IS_E_TEXT_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAL_A11Y_TYPE_E_TEXT_FACTORY)) -#define GAL_A11Y_IS_E_TEXT_FACTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAL_A11Y_TYPE_E_TEXT_FACTORY)) - -typedef struct _GalA11yETextFactory GalA11yETextFactory; -typedef struct _GalA11yETextFactoryClass GalA11yETextFactoryClass; - -struct _GalA11yETextFactory { - AtkObjectFactory object; -}; - -struct _GalA11yETextFactoryClass { - AtkObjectFactoryClass parent_class; -}; - -/* Standard Glib function */ -GType gal_a11y_e_text_factory_get_type (void); - -#endif /* __GAL_A11Y_E_TEXT_FACTORY_H__ */ diff --git a/widgets/text/gal-a11y-e-text.c b/widgets/text/gal-a11y-e-text.c deleted file mode 100644 index 44b069d3a7..0000000000 --- a/widgets/text/gal-a11y-e-text.c +++ /dev/null @@ -1,1141 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Christopher James Lahey - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include - -#include "a11y/gal-a11y-util.h" -#include "text/e-text.h" -#include "text/e-text-model-repos.h" - -#include "gal-a11y-e-text.h" -#include "gal-a11y-e-text-factory.h" - -static GObjectClass *parent_class; -static AtkComponentIface *component_parent_iface; -static GType parent_type; -static gint priv_offset; -static GQuark quark_accessible_object = 0; -#define PARENT_TYPE (parent_type) - -struct _GalA11yETextPrivate { - gint dummy; -}; - -static void -et_dispose (GObject *object) -{ - if (parent_class->dispose) - parent_class->dispose (object); -} - -/* Static functions */ - -static void -et_get_extents (AtkComponent *component, - gint *x, - gint *y, - gint *width, - gint *height, - AtkCoordType coord_type) -{ - EText *item = E_TEXT (atk_gobject_accessible_get_object ( - ATK_GOBJECT_ACCESSIBLE (component))); - gdouble real_width; - gdouble real_height; - gint fake_width; - gint fake_height; - - if (component_parent_iface && - component_parent_iface->get_extents) - component_parent_iface->get_extents (component, - x, - y, - &fake_width, - &fake_height, - coord_type); - - g_object_get ( - item, - "text_width", &real_width, - "text_height", &real_height, - NULL); - - if (width) - *width = real_width; - if (height) - *height = real_height; -} - -static const gchar * -et_get_full_text (AtkText *text) -{ - GObject *obj; - EText *etext; - ETextModel *model; - const gchar *full_text; - - obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text)); - if (obj == NULL) - return ""; - - etext = E_TEXT (obj); - g_object_get (etext, "model", &model, NULL); - - full_text = e_text_model_get_text (model); - - return full_text; -} - -static void -et_set_full_text (AtkEditableText *text, - const gchar *full_text) -{ - GObject *obj; - EText *etext; - ETextModel *model; - - obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text)); - if (obj == NULL) - return; - - etext = E_TEXT (obj); - g_object_get (etext, "model", &model, NULL); - - e_text_model_set_text (model, full_text); -} - -static gchar * -et_get_text (AtkText *text, - gint start_offset, - gint end_offset) -{ - gint start, end, real_start, real_end, len; - const gchar *full_text = et_get_full_text (text); - if (full_text == NULL) - return NULL; - len = g_utf8_strlen (full_text, -1); - - start = MIN (MAX (0, start_offset), len); - end = MIN (MAX (-1, end_offset), len); - - if (end_offset == -1) - end = strlen (full_text); - else - end = g_utf8_offset_to_pointer (full_text, end) - full_text; - - start = g_utf8_offset_to_pointer (full_text, start) - full_text; - - real_start = MIN (start, end); - real_end = MAX (start, end); - - return g_strndup (full_text + real_start, real_end - real_start); -} - -static gboolean -is_a_seperator (gunichar c) -{ - return g_unichar_ispunct (c) || g_unichar_isspace (c); -} - -static gint -find_word_start (const gchar *text, - gint begin_offset, - gint step) -{ - gint offset; - gchar *at_offset; - gunichar current, previous; - gint len; - - offset = begin_offset; - len = g_utf8_strlen (text, -1); - - while (offset > 0 && offset < len) { - at_offset = g_utf8_offset_to_pointer (text, offset); - current = g_utf8_get_char_validated (at_offset, -1); - at_offset = g_utf8_offset_to_pointer (text, offset - 1); - previous = g_utf8_get_char_validated (at_offset, -1); - if ((!is_a_seperator (current)) && is_a_seperator (previous)) - break; - offset += step; - } - - return offset; -} - -static gint -find_word_end (const gchar *text, - gint begin_offset, - gint step) -{ - gint offset; - gchar *at_offset; - gunichar current, previous; - gint len; - - offset = begin_offset; - len = g_utf8_strlen (text, -1); - - while (offset > 0 && offset < len) { - at_offset = g_utf8_offset_to_pointer (text, offset); - current = g_utf8_get_char_validated (at_offset, -1); - at_offset = g_utf8_offset_to_pointer (text, offset - 1); - previous = g_utf8_get_char_validated (at_offset, -1); - if (is_a_seperator (current) && (!is_a_seperator (previous))) - break; - offset += step; - } - - return offset; -} - -static gint -find_sentence_start (const gchar *text, - gint begin_offset, - gint step) -{ - gint offset, last_word_end, len; - gchar *at_offset; - gunichar ch; - gint i; - - offset = find_word_start (text, begin_offset, step); - len = g_utf8_strlen (text, -1); - - while (offset > 0 && offset 0 && offset < len) { - at_offset = g_utf8_offset_to_pointer (text, offset - 1); - previous = g_utf8_get_char_validated (at_offset, -1); - if (previous == '.' || previous == '!' || previous == '?') - break; - offset += step; - } - - return offset; -} - -static gint -find_line_start (const gchar *text, - gint begin_offset, - gint step) -{ - gint offset; - gchar *at_offset; - gunichar previous; - gint len; - - offset = begin_offset; - len = g_utf8_strlen (text, -1); - - while (offset > 0 && offset < len) { - at_offset = g_utf8_offset_to_pointer (text, offset - 1); - previous = g_utf8_get_char_validated (at_offset, -1); - if (previous == '\n' || previous == '\r') - break; - offset += step; - } - - return offset; -} - -static gint -find_line_end (const gchar *text, - gint begin_offset, - gint step) -{ - gint offset; - gchar *at_offset; - gunichar current; - gint len; - - offset = begin_offset; - len = g_utf8_strlen (text, -1); - - while (offset >= 0 && offset < len) { - at_offset = g_utf8_offset_to_pointer (text, offset); - current = g_utf8_get_char_validated (at_offset, -1); - if (current == '\n' || current == '\r') - break; - offset += step; - } - - return offset; -} - -static gchar * -et_get_text_after_offset (AtkText *text, - gint offset, - AtkTextBoundary boundary_type, - gint *start_offset, - gint *end_offset) -{ - gint start, end, len; - const gchar *full_text = et_get_full_text (text); - g_return_val_if_fail (full_text, NULL); - - switch (boundary_type) - { - case ATK_TEXT_BOUNDARY_CHAR: - start = offset + 1; - end = offset + 2; - break; - case ATK_TEXT_BOUNDARY_WORD_START: - start = find_word_start (full_text, offset + 1, 1); - end = find_word_start (full_text, start + 1, 1); - break; - case ATK_TEXT_BOUNDARY_WORD_END: - start = find_word_end (full_text, offset + 1, 1); - end = find_word_end (full_text, start + 1, 1); - break; - case ATK_TEXT_BOUNDARY_SENTENCE_START: - start = find_sentence_start (full_text, offset + 1, 1); - end = find_sentence_start (full_text, start + 1, 1); - break; - case ATK_TEXT_BOUNDARY_SENTENCE_END: - start = find_sentence_end (full_text, offset + 1, 1); - end = find_sentence_end (full_text, start + 1, 1); - break; - case ATK_TEXT_BOUNDARY_LINE_START: - start = find_line_start (full_text, offset + 1, 1); - end = find_line_start (full_text, start + 1, 1); - break; - case ATK_TEXT_BOUNDARY_LINE_END: - start = find_line_end (full_text, offset + 1, 1); - end = find_line_end (full_text, start + 1, 1); - break; - default: - return NULL; - } - - len = g_utf8_strlen (full_text, -1); - if (start_offset) - *start_offset = MIN (MAX (0, start), len); - if (end_offset) - *end_offset = MIN (MAX (0, end), len); - return et_get_text (text, start, end); -} - -static gchar * -et_get_text_at_offset (AtkText *text, - gint offset, - AtkTextBoundary boundary_type, - gint *start_offset, - gint *end_offset) -{ - gint start, end, len; - const gchar *full_text = et_get_full_text (text); - g_return_val_if_fail (full_text, NULL); - - switch (boundary_type) - { - case ATK_TEXT_BOUNDARY_CHAR: - start = offset; - end = offset + 1; - break; - case ATK_TEXT_BOUNDARY_WORD_START: - start = find_word_start (full_text, offset - 1, -1); - end = find_word_start (full_text, offset, 1); - break; - case ATK_TEXT_BOUNDARY_WORD_END: - start = find_word_end (full_text, offset, -1); - end = find_word_end (full_text, offset + 1, 1); - break; - case ATK_TEXT_BOUNDARY_SENTENCE_START: - start = find_sentence_start (full_text, offset - 1, -1); - end = find_sentence_start (full_text, offset, 1); - break; - case ATK_TEXT_BOUNDARY_SENTENCE_END: - start = find_sentence_end (full_text, offset, -1); - end = find_sentence_end (full_text, offset + 1, 1); - break; - case ATK_TEXT_BOUNDARY_LINE_START: - start = find_line_start (full_text, offset - 1, -1); - end = find_line_start (full_text, offset, 1); - break; - case ATK_TEXT_BOUNDARY_LINE_END: - start = find_line_end (full_text, offset, -1); - end = find_line_end (full_text, offset + 1, 1); - break; - default: - return NULL; - } - - len = g_utf8_strlen (full_text, -1); - if (start_offset) - *start_offset = MIN (MAX (0, start), len); - if (end_offset) - *end_offset = MIN (MAX (0, end), len); - return et_get_text (text, start, end); -} - -static gunichar -et_get_character_at_offset (AtkText *text, - gint offset) -{ - const gchar *full_text = et_get_full_text (text); - gchar *at_offset; - - at_offset = g_utf8_offset_to_pointer (full_text, offset); - return g_utf8_get_char_validated (at_offset, -1); -} - -static gchar * -et_get_text_before_offset (AtkText *text, - gint offset, - AtkTextBoundary boundary_type, - gint *start_offset, - gint *end_offset) -{ - gint start, end, len; - const gchar *full_text = et_get_full_text (text); - g_return_val_if_fail (full_text, NULL); - - switch (boundary_type) - { - case ATK_TEXT_BOUNDARY_CHAR: - start = offset - 1; - end = offset; - break; - case ATK_TEXT_BOUNDARY_WORD_START: - end = find_word_start (full_text, offset - 1, -1); - start = find_word_start (full_text, end - 1, -1); - break; - case ATK_TEXT_BOUNDARY_WORD_END: - end = find_word_end (full_text, offset, -1); - start = find_word_end (full_text, end - 1, -1); - break; - case ATK_TEXT_BOUNDARY_SENTENCE_START: - end = find_sentence_start (full_text, offset, -1); - start = find_sentence_start (full_text, end - 1, -1); - break; - case ATK_TEXT_BOUNDARY_SENTENCE_END: - end = find_sentence_end (full_text, offset, -1); - start = find_sentence_end (full_text, end - 1, -1); - break; - case ATK_TEXT_BOUNDARY_LINE_START: - end = find_line_start (full_text, offset, -1); - start = find_line_start (full_text, end - 1, -1); - break; - case ATK_TEXT_BOUNDARY_LINE_END: - end = find_line_end (full_text, offset, -1); - start = find_line_end (full_text, end - 1, -1); - break; - default: - return NULL; - } - - len = g_utf8_strlen (full_text, -1); - if (start_offset) - *start_offset = MIN (MAX (0, start), len); - if (end_offset) - *end_offset = MIN (MAX (0, end), len); - return et_get_text (text, start, end); -} - -static gint -et_get_caret_offset (AtkText *text) -{ - GObject *obj; - EText *etext; - gint offset; - - g_return_val_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (text), -1); - obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text)); - if (obj == NULL) - return -1; - - g_return_val_if_fail (E_IS_TEXT (obj), -1); - etext = E_TEXT (obj); - - g_object_get (etext, "cursor_pos", &offset, NULL); - return offset; -} - -static AtkAttributeSet * -et_get_run_attributes (AtkText *text, - gint offset, - gint *start_offset, - gint *end_offset) -{ - /* Unimplemented */ - return NULL; -} - -static AtkAttributeSet * -et_get_default_attributes (AtkText *text) -{ - /* Unimplemented */ - return NULL; -} - -static void -et_get_character_extents (AtkText *text, - gint offset, - gint *x, - gint *y, - gint *width, - gint *height, - AtkCoordType coords) -{ - GObject *obj; - EText *etext; - GnomeCanvas *canvas; - gint x_widget, y_widget, x_window, y_window; - GdkWindow *window; - GtkWidget *widget; - PangoRectangle pango_pos; - - g_return_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (text)); - obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text)); - if (obj == NULL) - return; - g_return_if_fail (E_IS_TEXT (obj)); - etext = E_TEXT (obj); - canvas = GNOME_CANVAS_ITEM (etext)->canvas; - widget = GTK_WIDGET (canvas); - window = gtk_widget_get_window (widget); - gdk_window_get_origin (window, &x_widget, &y_widget); - - pango_layout_index_to_pos (etext->layout, offset, &pango_pos); - pango_pos.x = PANGO_PIXELS (pango_pos.x); - pango_pos.y = PANGO_PIXELS (pango_pos.y); - pango_pos.width = (pango_pos.width + PANGO_SCALE / 2) / PANGO_SCALE; - pango_pos.height = (pango_pos.height + PANGO_SCALE / 2) / PANGO_SCALE; - - *x = pango_pos.x + x_widget; - *y = pango_pos.y + y_widget; - - *width = pango_pos.width; - *height = pango_pos.height; - - *x += etext->xofs; - *y += etext->yofs; - - if (etext->editing) { - *x -= etext->xofs_edit; - *y -= etext->yofs_edit; - } - - *x += etext->cx; - *y += etext->cy; - - if (coords == ATK_XY_WINDOW) { - window = gdk_window_get_toplevel (window); - gdk_window_get_origin (window, &x_window, &y_window); - *x -= x_window; - *y -= y_window; - } - else if (coords == ATK_XY_SCREEN) { - } - else { - *x = 0; - *y = 0; - *height = 0; - *width = 0; - } -} - -static gint -et_get_character_count (AtkText *text) -{ - const gchar *full_text = et_get_full_text (text); - - return g_utf8_strlen (full_text, -1); -} - -static gint -et_get_offset_at_point (AtkText *text, - gint x, - gint y, - AtkCoordType coords) -{ - GObject *obj; - EText *etext; - GnomeCanvas *canvas; - gint x_widget, y_widget, x_window, y_window; - GdkWindow *window; - GtkWidget *widget; - gint index; - gint trailing; - - g_return_val_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (text), -1); - obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text)); - if (obj == NULL) - return -1; - g_return_val_if_fail (E_IS_TEXT (obj), -1); - etext = E_TEXT (obj); - canvas = GNOME_CANVAS_ITEM (etext)->canvas; - widget = GTK_WIDGET (canvas); - window = gtk_widget_get_window (widget); - gdk_window_get_origin (window, &x_widget, &y_widget); - - if (coords == ATK_XY_SCREEN) { - x = x - x_widget; - y = y - y_widget; - } - else if (coords == ATK_XY_WINDOW) { - window = gdk_window_get_toplevel (window); - gdk_window_get_origin (window, &x_window, &y_window); - x = x - x_widget + x_window; - y = y - y_widget + y_window; - } - else - return -1; - - x -= etext->xofs; - y -= etext->yofs; - - if (etext->editing) { - x += etext->xofs_edit; - y += etext->yofs_edit; - } - - x -= etext->cx; - y -= etext->cy; - - pango_layout_xy_to_index ( - etext->layout, - x * PANGO_SCALE - PANGO_SCALE / 2, - y * PANGO_SCALE - PANGO_SCALE / 2, - &index, - &trailing); - - return g_utf8_pointer_to_offset (etext->text, etext->text + index + trailing); -} - -static gint -et_get_n_selections (AtkText *text) -{ - EText *etext; - GObject *obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text)); - - if (obj == NULL) - return -1; - etext = E_TEXT (obj); - - if (etext->selection_start != - etext->selection_end) - return 1; - return 0; -} - -static gchar * -et_get_selection (AtkText *text, - gint selection_num, - gint *start_offset, - gint *end_offset) -{ - gint start, end, real_start, real_end, len; - EText *etext; - if (selection_num == 0) { - const gchar *full_text = et_get_full_text (text); - if (full_text == NULL) - return NULL; - len = g_utf8_strlen (full_text, -1); - etext = E_TEXT (atk_gobject_accessible_get_object ( - ATK_GOBJECT_ACCESSIBLE (text))); - start = MIN (etext->selection_start, etext->selection_end); - end = MAX (etext->selection_start, etext->selection_end); - start = MIN (MAX (0, start), len); - end = MIN (MAX (0, end), len); - if (start != end) { - if (start_offset) - *start_offset = start; - if (end_offset) - *end_offset = end; - real_start = g_utf8_offset_to_pointer (full_text, start) - full_text; - real_end = g_utf8_offset_to_pointer (full_text, end) - full_text; - return g_strndup (full_text + real_start, real_end - real_start); - } - } - - return NULL; -} - -static gboolean -et_add_selection (AtkText *text, - gint start_offset, - gint end_offset) -{ - GObject *obj; - EText *etext; - - g_return_val_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (text), FALSE); - obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text)); - if (obj == NULL) - return FALSE; - g_return_val_if_fail (E_IS_TEXT (obj), FALSE); - etext = E_TEXT (obj); - - g_return_val_if_fail (start_offset >= 0, FALSE); - g_return_val_if_fail (start_offset >= -1, FALSE); - if (end_offset == -1) - end_offset = et_get_character_count (text); - - if (start_offset != end_offset) { - gint real_start, real_end; - real_start = MIN (start_offset, end_offset); - real_end = MAX (start_offset, end_offset); - etext->selection_start = real_start; - etext->selection_end = real_end; - - gnome_canvas_item_grab_focus (GNOME_CANVAS_ITEM (etext)); - gnome_canvas_item_request_update (GNOME_CANVAS_ITEM (etext)); - - g_signal_emit_by_name (ATK_OBJECT (text), "text_selection_changed"); - - return TRUE; - } - - return FALSE; -} - -static gboolean -et_remove_selection (AtkText *text, - gint selection_num) -{ - GObject *obj; - EText *etext; - - g_return_val_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (text), FALSE); - obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text)); - if (obj == NULL) - return FALSE; - g_return_val_if_fail (E_IS_TEXT (obj), FALSE); - etext = E_TEXT (obj); - - if (selection_num == 0 - && etext->selection_start != etext->selection_end) { - etext->selection_end = etext->selection_start; - g_signal_emit_by_name (ATK_OBJECT (text), "text_selection_changed"); - return TRUE; - } - - return FALSE; -} - -static gboolean -et_set_selection (AtkText *text, - gint selection_num, - gint start_offset, - gint end_offset) -{ - GObject *obj; - - g_return_val_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (text), FALSE); - obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text)); - if (obj == NULL) - return FALSE; - g_return_val_if_fail (E_IS_TEXT (obj), FALSE); - if (selection_num == 0) - return et_add_selection (text, start_offset, end_offset); - return FALSE; -} - -static gboolean -et_set_caret_offset (AtkText *text, - gint offset) -{ - GObject *obj; - EText *etext; - - g_return_val_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (text), FALSE); - obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text)); - if (obj == NULL) - return FALSE; - - g_return_val_if_fail (E_IS_TEXT (obj), FALSE); - etext = E_TEXT (obj); - - if (offset < -1) - return FALSE; - else { - ETextEventProcessorCommand command; - - if (offset == -1) - offset = et_get_character_count (text); - - command.action = E_TEP_MOVE; - command.position = E_TEP_VALUE; - command.value = offset; - command.time = GDK_CURRENT_TIME; - g_signal_emit_by_name (etext->tep, "command", &command); - return TRUE; - } -} - -static gboolean -et_set_run_attributes (AtkEditableText *text, - AtkAttributeSet *attrib_set, - gint start_offset, - gint end_offset) -{ - /* Unimplemented */ - return FALSE; -} - -static void -et_set_text_contents (AtkEditableText *text, - const gchar *string) -{ - et_set_full_text (text, string); -} - -static void -et_insert_text (AtkEditableText *text, - const gchar *string, - gint length, - gint *position) -{ - /* Utf8 unimplemented */ - gchar *result; - - const gchar *full_text = et_get_full_text (ATK_TEXT (text)); - if (full_text == NULL) - return; - - result = g_strdup_printf ( - "%.*s%.*s%s", *position, full_text, - length, string, full_text + *position); - - et_set_full_text (text, result); - - *position += length; - - g_free (result); -} - -static void -et_copy_text (AtkEditableText *text, - gint start_pos, - gint end_pos) -{ - GObject *obj; - EText *etext; - - g_return_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (text)); - obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text)); - if (obj == NULL) - return; - - g_return_if_fail (E_IS_TEXT (obj)); - etext = E_TEXT (obj); - - if (start_pos != end_pos) { - etext->selection_start = start_pos; - etext->selection_end = end_pos; - e_text_copy_clipboard (etext); - } -} - -static void -et_delete_text (AtkEditableText *text, - gint start_pos, - gint end_pos) -{ - GObject *obj; - EText *etext; - - g_return_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (text)); - obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text)); - if (obj == NULL) - return; - - g_return_if_fail (E_IS_TEXT (obj)); - etext = E_TEXT (obj); - - etext->selection_start = start_pos; - etext->selection_end = end_pos; - - e_text_delete_selection (etext); -} - -static void -et_cut_text (AtkEditableText *text, - gint start_pos, - gint end_pos) -{ - et_copy_text (text, start_pos, end_pos); - et_delete_text (text, start_pos, end_pos); -} - -static void -et_paste_text (AtkEditableText *text, - gint position) -{ - GObject *obj; - EText *etext; - - g_return_if_fail (ATK_IS_GOBJECT_ACCESSIBLE (text)); - obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (text)); - if (obj == NULL) - return; - - g_return_if_fail (E_IS_TEXT (obj)); - etext = E_TEXT (obj); - - g_object_set (etext, "cursor_pos", position, NULL); - e_text_paste_clipboard (etext); -} - -static void -et_atk_component_iface_init (AtkComponentIface *iface) -{ - iface->get_extents = et_get_extents; -} - -static void -et_atk_text_iface_init (AtkTextIface *iface) -{ - iface->get_text = et_get_text; - iface->get_text_after_offset = et_get_text_after_offset; - iface->get_text_at_offset = et_get_text_at_offset; - iface->get_character_at_offset = et_get_character_at_offset; - iface->get_text_before_offset = et_get_text_before_offset; - iface->get_caret_offset = et_get_caret_offset; - iface->get_run_attributes = et_get_run_attributes; - iface->get_default_attributes = et_get_default_attributes; - iface->get_character_extents = et_get_character_extents; - iface->get_character_count = et_get_character_count; - iface->get_offset_at_point = et_get_offset_at_point; - iface->get_n_selections = et_get_n_selections; - iface->get_selection = et_get_selection; - iface->add_selection = et_add_selection; - iface->remove_selection = et_remove_selection; - iface->set_selection = et_set_selection; - iface->set_caret_offset = et_set_caret_offset; -} - -static void -et_atk_editable_text_iface_init (AtkEditableTextIface *iface) -{ - iface->set_run_attributes = et_set_run_attributes; - iface->set_text_contents = et_set_text_contents; - iface->insert_text = et_insert_text; - iface->copy_text = et_copy_text; - iface->cut_text = et_cut_text; - iface->delete_text = et_delete_text; - iface->paste_text = et_paste_text; -} - -static void -_et_reposition_cb (ETextModel *model, - ETextModelReposFn fn, - gpointer repos_data, - gpointer user_data) -{ - AtkObject *accessible; - AtkText *text; - - accessible = ATK_OBJECT (user_data); - text = ATK_TEXT (accessible); - - if (fn == e_repos_delete_shift) { - EReposDeleteShift *info = (EReposDeleteShift *) repos_data; - g_signal_emit_by_name (text, "text-changed::delete", info->pos, info->len); - } - else if (fn == e_repos_insert_shift) { - EReposInsertShift *info = (EReposInsertShift *) repos_data; - g_signal_emit_by_name (text, "text-changed::insert", info->pos, info->len); - } -} - -static void -_et_command_cb (ETextEventProcessor *tep, - ETextEventProcessorCommand *command, - gpointer user_data) -{ - AtkObject *accessible; - AtkText *text; - - accessible = ATK_OBJECT (user_data); - text = ATK_TEXT (accessible); - - switch (command->action) { - case E_TEP_MOVE: - g_signal_emit_by_name (text, "text-caret-moved", et_get_caret_offset (text)); - break; - case E_TEP_SELECT: - g_signal_emit_by_name (text, "text-selection-changed"); - break; - default: - break; - } -} - -static void -et_real_initialize (AtkObject *obj, - gpointer data) -{ - EText *etext; - - ATK_OBJECT_CLASS (parent_class)->initialize (obj, data); - - g_return_if_fail (GAL_A11Y_IS_E_TEXT (obj)); - g_return_if_fail (E_IS_TEXT (data)); - - etext = E_TEXT (data); - - /* Set up signal callbacks */ - g_signal_connect ( - etext->model, "reposition", - G_CALLBACK (_et_reposition_cb), obj); - - if (etext->tep) - g_signal_connect_after ( - etext->tep, "command", - (GCallback) _et_command_cb, obj); - - obj->role = ATK_ROLE_TEXT; -} - -static void -et_class_init (GalA11yETextClass *class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (class); - AtkObjectClass *atk_class = ATK_OBJECT_CLASS (class); - - quark_accessible_object = - g_quark_from_static_string ("gtk-accessible-object"); - parent_class = g_type_class_ref (PARENT_TYPE); - component_parent_iface = - g_type_interface_peek (parent_class, ATK_TYPE_COMPONENT); - object_class->dispose = et_dispose; - atk_class->initialize = et_real_initialize; -} - -static void -et_init (GalA11yEText *a11y) -{ -} - -/** - * gal_a11y_e_text_get_type: - * @void: - * - * Registers the &GalA11yEText class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &GalA11yEText class. - **/ -GType -gal_a11y_e_text_get_type (void) -{ - static GType type = 0; - - if (!type) { - AtkObjectFactory *factory; - - GTypeInfo info = { - sizeof (GalA11yETextClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) et_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (GalA11yEText), - 0, - (GInstanceInitFunc) et_init, - NULL /* value_text */ - }; - - static const GInterfaceInfo atk_component_info = { - (GInterfaceInitFunc) et_atk_component_iface_init, - (GInterfaceFinalizeFunc) NULL, - NULL - }; - static const GInterfaceInfo atk_text_info = { - (GInterfaceInitFunc) et_atk_text_iface_init, - (GInterfaceFinalizeFunc) NULL, - NULL - }; - static const GInterfaceInfo atk_editable_text_info = { - (GInterfaceInitFunc) et_atk_editable_text_iface_init, - (GInterfaceFinalizeFunc) NULL, - NULL - }; - - factory = atk_registry_get_factory ( - atk_get_default_registry (), GNOME_TYPE_CANVAS_ITEM); - parent_type = atk_object_factory_get_accessible_type (factory); - - type = gal_a11y_type_register_static_with_private ( - PARENT_TYPE, "GalA11yEText", &info, 0, - sizeof (GalA11yETextPrivate), &priv_offset); - - g_type_add_interface_static ( - type, ATK_TYPE_COMPONENT, &atk_component_info); - g_type_add_interface_static ( - type, ATK_TYPE_TEXT, &atk_text_info); - g_type_add_interface_static ( - type, ATK_TYPE_EDITABLE_TEXT, &atk_editable_text_info); - } - - return type; -} - -void -gal_a11y_e_text_init (void) -{ - if (atk_get_root ()) - atk_registry_set_factory_type ( - atk_get_default_registry (), - E_TYPE_TEXT, - gal_a11y_e_text_factory_get_type ()); - -} - diff --git a/widgets/text/gal-a11y-e-text.h b/widgets/text/gal-a11y-e-text.h deleted file mode 100644 index adf2833a19..0000000000 --- a/widgets/text/gal-a11y-e-text.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Christopher James Lahey - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __GAL_A11Y_E_TEXT_H__ -#define __GAL_A11Y_E_TEXT_H__ - -#include - -#define GAL_A11Y_TYPE_E_TEXT (gal_a11y_e_text_get_type ()) -#define GAL_A11Y_E_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAL_A11Y_TYPE_E_TEXT, GalA11yEText)) -#define GAL_A11Y_E_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAL_A11Y_TYPE_E_TEXT, GalA11yETextClass)) -#define GAL_A11Y_IS_E_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAL_A11Y_TYPE_E_TEXT)) -#define GAL_A11Y_IS_E_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAL_A11Y_TYPE_E_TEXT)) - -typedef struct _GalA11yEText GalA11yEText; -typedef struct _GalA11yETextClass GalA11yETextClass; -typedef struct _GalA11yETextPrivate GalA11yETextPrivate; - -/* This struct should actually be larger as this isn't what we derive from. - * The GalA11yETextPrivate comes right after the parent class structure. - **/ -struct _GalA11yEText { - AtkObject object; -}; - -struct _GalA11yETextClass { - AtkObject parent_class; -}; - -/* Standard Glib function */ -GType gal_a11y_e_text_get_type (void); - -void gal_a11y_e_text_init (void); - -#endif /* __GAL_A11Y_E_TEXT_H__ */ -- cgit v1.2.3