aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/text/e-text-model-test.c
diff options
context:
space:
mode:
authorJon Trowbridge <trow@gnu.org>2001-01-27 06:10:51 +0800
committerJon Trowbridge <trow@src.gnome.org>2001-01-27 06:10:51 +0800
commit8c1c8274963543c45ba3717d1156d9edaa78cdc2 (patch)
treeb9e8c027f4a578657f240bcb09fd132b36cfc7ee /widgets/text/e-text-model-test.c
parent19791220710c9d632ac5836a3a1163bc00675a9d (diff)
downloadgsoc2013-evolution-8c1c8274963543c45ba3717d1156d9edaa78cdc2.tar.gz
gsoc2013-evolution-8c1c8274963543c45ba3717d1156d9edaa78cdc2.tar.zst
gsoc2013-evolution-8c1c8274963543c45ba3717d1156d9edaa78cdc2.zip
Added; a new test program that demonstrates objects in ETexts.
2001-01-26 Jon Trowbridge <trow@gnu.org> * gal/e-text/e-text-model-test.c: Added; a new test program that demonstrates objects in ETexts. * gal/e-text/e-text-model-uri.c: Added; a text model that converts URIs in the text into objects that are passed off to the GNOME URI handler when activated. This is actually still extremely broken; I got it just working enough to test out my EText changes. * gal/e-text/e-text.c: A whole lot of changes, designed to make ETextModel objects render properly. The basic idea of the changes is pretty simple, though. (text_width_with_objects): First of all, this function is an alternative to e_font_utf8_text_width that takes into the account the embedded \1s in the text string and properly accounts for the width of the object strings. (unicode_strlen_with_objects): Next, this function finds the proper strlen of a string, expanding the \1s. (text_draw_with_objects): Finally, this is just a replacement for e_font_draw_utf8_text that does the right thing for objects. I've gone through all of e-text.c and replace calls by those original functions with my new object-enabled alternatives. (split_into_lines): Some tweaking to get line breaking to work properly. Made \1 into a "break character", so that we can break lines between multiple adjacent objects. (Which seemed like the right thing to do, but there may be cases where that is undesireable.) (_get_position_from_xy): Fixed to properly handle embedded objects, and to get the right selection semantics for objects. (Or at least semantics that feel right to me.) Also fixed a bug that caused selection, etc. to not work properly if the text was anchored anywhere other than with GTK_ANCHOR_NORTH*. (_get_position): Hacked to cause objects to activate when they are double-clicked. There is probably a better way to do this. * gal/e-text/e-text-model.c (e_text_model_real_object_count): Provide a default implementation of an object counter. Derived classes might want to override this for efficiency reasons. (e_text_model_strdup_expanded_text): Added. Allocates and returns a string contains the model's text with the objects "expanded" within. * gal/e-text/e-text-model.h: Added obj_count, get_nth_obj, and activate_nth_obj virtual methods to ETextModelClass. svn path=/trunk/; revision=7842
Diffstat (limited to 'widgets/text/e-text-model-test.c')
-rw-r--r--widgets/text/e-text-model-test.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/widgets/text/e-text-model-test.c b/widgets/text/e-text-model-test.c
new file mode 100644
index 0000000000..0c758cd4ba
--- /dev/null
+++ b/widgets/text/e-text-model-test.c
@@ -0,0 +1,67 @@
+/*
+ ETextModelTest
+*/
+
+#include <gnome.h>
+#include <gal/widgets/e-canvas.h>
+#include "e-text-model.h"
+#include "e-text-model-uri.h"
+#include "e-text.h"
+
+static void
+describe_model (ETextModel *model)
+{
+ gint i, N;
+ g_return_if_fail (E_IS_TEXT_MODEL (model));
+
+ N = e_text_model_object_count (model);
+
+ g_print ("text: %s\n", e_text_model_get_text (model));
+ if (N > 0) {
+ gchar *s = e_text_model_strdup_expanded_text (model);
+ g_print ("expd: %s\n", s);
+ g_free (s);
+ }
+ g_print ("objs: %d\n", N);
+
+ for (i=0; i<N; ++i)
+ g_print ("obj%d: %s\n", i, e_text_model_get_nth_object (model, i));
+}
+
+int
+main (int argc, gchar **argv)
+{
+ GtkWidget *win, *canvas;
+ GnomeCanvasItem *item;
+ ETextModel *model;
+
+ gnome_init ("ETextModelTest", "0.0", argc, argv);
+
+ model = e_text_model_uri_new ();
+ e_text_model_set_text (model, "My favorite website is http://www.ximian.com. My next favorite is http://www.gnome.org.");
+
+ win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+ gtk_widget_push_visual (gdk_rgb_get_visual ());
+ gtk_widget_push_colormap (gdk_rgb_get_cmap ());
+ canvas = e_canvas_new ();
+ gtk_widget_pop_visual ();
+ gtk_widget_pop_colormap ();
+
+ item = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)),
+ e_text_get_type (),
+ "model", model,
+ "font", "-adobe-helvetica-medium-r-normal--12-120-75-75-p-67-iso8859-1",
+ "anchor", GTK_ANCHOR_SOUTH_WEST,
+ "line_wrap", TRUE,
+ "width", 150.0,
+ "editable", TRUE,
+ NULL);
+
+ gtk_container_add (GTK_CONTAINER (win), canvas);
+ gtk_widget_show_all (win);
+
+ gtk_main ();
+
+ return 0;
+}