aboutsummaryrefslogtreecommitdiffstats
path: root/widgets
diff options
context:
space:
mode:
authorIain Holmes <ih@csd.abdn.ac.uk>2000-02-21 00:17:08 +0800
committeriholmes <iholmes@localhost>2000-02-21 00:17:08 +0800
commit113c276df87402803382f26ee6eb1994e2e9f4ff (patch)
tree0457fbb0d3cfdfe2b32a647b47680c08262d2bd1 /widgets
parent410ce5daf579edd0b8fd4d2bd7bdd8cd61a89ad8 (diff)
downloadgsoc2013-evolution-113c276df87402803382f26ee6eb1994e2e9f4ff.tar
gsoc2013-evolution-113c276df87402803382f26ee6eb1994e2e9f4ff.tar.gz
gsoc2013-evolution-113c276df87402803382f26ee6eb1994e2e9f4ff.tar.bz2
gsoc2013-evolution-113c276df87402803382f26ee6eb1994e2e9f4ff.tar.lz
gsoc2013-evolution-113c276df87402803382f26ee6eb1994e2e9f4ff.tar.xz
gsoc2013-evolution-113c276df87402803382f26ee6eb1994e2e9f4ff.tar.zst
gsoc2013-evolution-113c276df87402803382f26ee6eb1994e2e9f4ff.zip
Show the text of the item, in a tooltip style. (e_text_event): Add a
2000-02-20 Iain Holmes <ih@csd.abdn.ac.uk> * widgets/e-text/e-text.[ch] (_do_tooltip): Show the text of the item, in a tooltip style. (e_text_event): Add a timeout on the Enter and remove it on the Leave events. * e-text-test.c: New file to test e-text items. svn path=/trunk/; revision=1866
Diffstat (limited to 'widgets')
-rw-r--r--widgets/e-text/e-text-test.c104
-rw-r--r--widgets/e-text/e-text.c51
-rw-r--r--widgets/e-text/e-text.h3
-rw-r--r--widgets/text/e-text-test.c104
-rw-r--r--widgets/text/e-text.c51
-rw-r--r--widgets/text/e-text.h3
6 files changed, 314 insertions, 2 deletions
diff --git a/widgets/e-text/e-text-test.c b/widgets/e-text/e-text-test.c
new file mode 100644
index 0000000000..ae43d41611
--- /dev/null
+++ b/widgets/e-text/e-text-test.c
@@ -0,0 +1,104 @@
+/*
+ ETextTest: E-Text item test program
+ Copyright (C)2000: Iain Holmes <ih@csd.abdn.ac.uk>
+
+ This code is licensed under the GPL
+*/
+
+#include "e-text.h"
+#include <gnome.h>
+
+void
+quit_cb (GtkWidget *widget,
+ gpointer data)
+{
+ gtk_main_quit ();
+}
+
+void
+change_text_cb (GtkEntry *entry,
+ EText *text)
+{
+ gchar *str;
+
+ str = gtk_entry_get_text (entry);
+ gnome_canvas_item_set (GNOME_CANVAS_ITEM (text),
+ "text", str,
+ NULL);
+}
+
+void
+change_font_cb (GtkEntry *entry,
+ EText *text)
+{
+ gchar *font;
+
+ font = gtk_entry_get_text (entry);
+ gnome_canvas_item_set (GNOME_CANVAS_ITEM (text),
+ "font", font,
+ NULL);
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ GtkWidget *window, *canvas, *scroller, *vbox, *text, *font;
+ GtkWidget *frame;
+ GnomeCanvasItem *item;
+
+ gnome_init ("ETextTest", "0.0.1", argc, argv);
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title (GTK_WINDOW (window), "EText Test");
+ gtk_signal_connect (GTK_OBJECT (window), "destroy",
+ GTK_SIGNAL_FUNC (quit_cb), NULL);
+
+ gtk_widget_push_visual (gdk_rgb_get_visual ());
+ gtk_widget_push_colormap (gdk_rgb_get_cmap ());
+ canvas = gnome_canvas_new ();
+ gtk_widget_pop_visual ();
+ gtk_widget_pop_colormap ();
+ scroller = gtk_scrolled_window_new (NULL, NULL);
+ vbox = gtk_vbox_new (FALSE, 2);
+
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+ gtk_box_pack_start (GTK_BOX (vbox), scroller, TRUE, TRUE, 2);
+ gtk_container_add (GTK_CONTAINER (scroller), canvas);
+
+ frame = gtk_frame_new ("Text");
+ text = gtk_entry_new ();
+ gtk_container_add (GTK_CONTAINER (frame), text);
+ gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
+
+ frame = gtk_frame_new ("Font");
+ font = gtk_entry_new ();
+ gtk_container_add (GTK_CONTAINER (frame), font);
+ gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
+
+ item = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)),
+ e_text_get_type (),
+ "text", "Hello World! This is a really long string to test out the ellipsis stuff.",
+ "x", 10.0,
+ "y", 10.0,
+ "font", "-adobe-helvetica-medium-r-normal--12-*-72-72-p-*-iso8859-1",
+ "fill_color", "black",
+ "anchor", GTK_ANCHOR_NW,
+ "use_ellipsis", TRUE,
+ "ellipsis", "...",
+ "editable", TRUE,
+ "line_wrap", TRUE,
+ "max_lines", 3,
+ "clip_width", 150.0,
+ NULL);
+
+ gtk_signal_connect (GTK_OBJECT (text), "activate",
+ GTK_SIGNAL_FUNC (change_text_cb), item);
+ gtk_signal_connect (GTK_OBJECT (font), "activate",
+ GTK_SIGNAL_FUNC (change_font_cb), item);
+
+ gnome_canvas_set_scroll_region (GNOME_CANVAS (canvas), 0.0, 0.0, 400.0, 400.0);
+ gtk_widget_show_all (window);
+ gtk_main ();
+
+ return 0;
+}
diff --git a/widgets/e-text/e-text.c b/widgets/e-text/e-text.c
index 8dde3bbaed..2e3e7c158a 100644
--- a/widgets/e-text/e-text.c
+++ b/widgets/e-text/e-text.c
@@ -332,7 +332,7 @@ e_text_destroy (GtkObject *object)
EText *text;
g_return_if_fail (object != NULL);
- g_return_if_fail (GNOME_IS_CANVAS_TEXT (object));
+ g_return_if_fail (E_IS_TEXT (object));
text = E_TEXT (object);
@@ -1823,6 +1823,48 @@ _blink_scroll_timeout (gpointer data)
return TRUE;
}
+static gboolean
+_do_tooltip (gpointer data)
+{
+ EText *text = E_TEXT (data);
+ struct line *lines;
+ GtkWidget *label, *vbox;
+ gint x, y, pointer_x, pointer_y, scr_w, scr_h, tip_w, tip_h;
+ int i;
+
+ lines = text->lines;
+
+ scr_w = gdk_screen_width ();
+ scr_h = gdk_screen_height ();
+ gdk_window_get_pointer (NULL, &pointer_x, &pointer_y, NULL);
+
+ text->tooltip_window = gtk_window_new (GTK_WINDOW_POPUP);
+ vbox = gtk_vbox_new (TRUE, 0);
+ for (i = 0; i < text->num_lines; i++) {
+ gchar *linetext;
+
+ linetext = g_strndup (lines->text, lines->length);
+ label = gtk_label_new (linetext);
+ g_free (linetext);
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+ gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
+ lines++;
+ }
+
+ gtk_widget_show_all (vbox);
+ gtk_container_add (GTK_CONTAINER (text->tooltip_window), vbox);
+ gtk_widget_realize (text->tooltip_window);
+ tip_w = text->tooltip_window->allocation.width;
+ tip_h = text->tooltip_window->allocation.height;
+
+ /* Stay on screen */
+ x = pointer_x + tip_w <= scr_w ? pointer_x : scr_w - tip_w;
+ y = pointer_y + tip_h + 1 <= scr_h ? pointer_y + 1: pointer_y - tip_h;
+ gtk_widget_popup (text->tooltip_window, x, y);
+
+ return FALSE;
+}
+
static gint
e_text_event (GnomeCanvasItem *item, GdkEvent *event)
{
@@ -1951,6 +1993,7 @@ e_text_event (GnomeCanvasItem *item, GdkEvent *event)
}
break;
case GDK_ENTER_NOTIFY:
+ text->tooltip_timeout = gtk_timeout_add (3000, _do_tooltip, text);
text->pointer_in = TRUE;
if (text->editing) {
if ( text->default_cursor_shown ) {
@@ -1960,6 +2003,12 @@ e_text_event (GnomeCanvasItem *item, GdkEvent *event)
}
break;
case GDK_LEAVE_NOTIFY:
+ gtk_timeout_remove (text->tooltip_timeout);
+ if (text->tooltip_window) {
+ gtk_widget_destroy (text->tooltip_window);
+ text->tooltip_window = NULL;
+ }
+
text->pointer_in = FALSE;
if (text->editing) {
if ( ! text->default_cursor_shown ) {
diff --git a/widgets/e-text/e-text.h b/widgets/e-text/e-text.h
index 1254e0fd1c..c44589d3ae 100644
--- a/widgets/e-text/e-text.h
+++ b/widgets/e-text/e-text.h
@@ -173,6 +173,9 @@ struct _EText {
GdkCursor *default_cursor; /* Default cursor (arrow) */
GdkCursor *i_cursor; /* I beam cursor */
+
+ gint tooltip_timeout; /* Timeout for the tooltip */
+ GtkWidget *tooltip_window; /* GtkWindow for displaying the tooltip */
};
struct _ETextClass {
diff --git a/widgets/text/e-text-test.c b/widgets/text/e-text-test.c
new file mode 100644
index 0000000000..ae43d41611
--- /dev/null
+++ b/widgets/text/e-text-test.c
@@ -0,0 +1,104 @@
+/*
+ ETextTest: E-Text item test program
+ Copyright (C)2000: Iain Holmes <ih@csd.abdn.ac.uk>
+
+ This code is licensed under the GPL
+*/
+
+#include "e-text.h"
+#include <gnome.h>
+
+void
+quit_cb (GtkWidget *widget,
+ gpointer data)
+{
+ gtk_main_quit ();
+}
+
+void
+change_text_cb (GtkEntry *entry,
+ EText *text)
+{
+ gchar *str;
+
+ str = gtk_entry_get_text (entry);
+ gnome_canvas_item_set (GNOME_CANVAS_ITEM (text),
+ "text", str,
+ NULL);
+}
+
+void
+change_font_cb (GtkEntry *entry,
+ EText *text)
+{
+ gchar *font;
+
+ font = gtk_entry_get_text (entry);
+ gnome_canvas_item_set (GNOME_CANVAS_ITEM (text),
+ "font", font,
+ NULL);
+}
+
+int
+main (int argc,
+ char **argv)
+{
+ GtkWidget *window, *canvas, *scroller, *vbox, *text, *font;
+ GtkWidget *frame;
+ GnomeCanvasItem *item;
+
+ gnome_init ("ETextTest", "0.0.1", argc, argv);
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title (GTK_WINDOW (window), "EText Test");
+ gtk_signal_connect (GTK_OBJECT (window), "destroy",
+ GTK_SIGNAL_FUNC (quit_cb), NULL);
+
+ gtk_widget_push_visual (gdk_rgb_get_visual ());
+ gtk_widget_push_colormap (gdk_rgb_get_cmap ());
+ canvas = gnome_canvas_new ();
+ gtk_widget_pop_visual ();
+ gtk_widget_pop_colormap ();
+ scroller = gtk_scrolled_window_new (NULL, NULL);
+ vbox = gtk_vbox_new (FALSE, 2);
+
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+ gtk_box_pack_start (GTK_BOX (vbox), scroller, TRUE, TRUE, 2);
+ gtk_container_add (GTK_CONTAINER (scroller), canvas);
+
+ frame = gtk_frame_new ("Text");
+ text = gtk_entry_new ();
+ gtk_container_add (GTK_CONTAINER (frame), text);
+ gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
+
+ frame = gtk_frame_new ("Font");
+ font = gtk_entry_new ();
+ gtk_container_add (GTK_CONTAINER (frame), font);
+ gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
+
+ item = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)),
+ e_text_get_type (),
+ "text", "Hello World! This is a really long string to test out the ellipsis stuff.",
+ "x", 10.0,
+ "y", 10.0,
+ "font", "-adobe-helvetica-medium-r-normal--12-*-72-72-p-*-iso8859-1",
+ "fill_color", "black",
+ "anchor", GTK_ANCHOR_NW,
+ "use_ellipsis", TRUE,
+ "ellipsis", "...",
+ "editable", TRUE,
+ "line_wrap", TRUE,
+ "max_lines", 3,
+ "clip_width", 150.0,
+ NULL);
+
+ gtk_signal_connect (GTK_OBJECT (text), "activate",
+ GTK_SIGNAL_FUNC (change_text_cb), item);
+ gtk_signal_connect (GTK_OBJECT (font), "activate",
+ GTK_SIGNAL_FUNC (change_font_cb), item);
+
+ gnome_canvas_set_scroll_region (GNOME_CANVAS (canvas), 0.0, 0.0, 400.0, 400.0);
+ gtk_widget_show_all (window);
+ gtk_main ();
+
+ return 0;
+}
diff --git a/widgets/text/e-text.c b/widgets/text/e-text.c
index 8dde3bbaed..2e3e7c158a 100644
--- a/widgets/text/e-text.c
+++ b/widgets/text/e-text.c
@@ -332,7 +332,7 @@ e_text_destroy (GtkObject *object)
EText *text;
g_return_if_fail (object != NULL);
- g_return_if_fail (GNOME_IS_CANVAS_TEXT (object));
+ g_return_if_fail (E_IS_TEXT (object));
text = E_TEXT (object);
@@ -1823,6 +1823,48 @@ _blink_scroll_timeout (gpointer data)
return TRUE;
}
+static gboolean
+_do_tooltip (gpointer data)
+{
+ EText *text = E_TEXT (data);
+ struct line *lines;
+ GtkWidget *label, *vbox;
+ gint x, y, pointer_x, pointer_y, scr_w, scr_h, tip_w, tip_h;
+ int i;
+
+ lines = text->lines;
+
+ scr_w = gdk_screen_width ();
+ scr_h = gdk_screen_height ();
+ gdk_window_get_pointer (NULL, &pointer_x, &pointer_y, NULL);
+
+ text->tooltip_window = gtk_window_new (GTK_WINDOW_POPUP);
+ vbox = gtk_vbox_new (TRUE, 0);
+ for (i = 0; i < text->num_lines; i++) {
+ gchar *linetext;
+
+ linetext = g_strndup (lines->text, lines->length);
+ label = gtk_label_new (linetext);
+ g_free (linetext);
+ gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
+ gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
+ lines++;
+ }
+
+ gtk_widget_show_all (vbox);
+ gtk_container_add (GTK_CONTAINER (text->tooltip_window), vbox);
+ gtk_widget_realize (text->tooltip_window);
+ tip_w = text->tooltip_window->allocation.width;
+ tip_h = text->tooltip_window->allocation.height;
+
+ /* Stay on screen */
+ x = pointer_x + tip_w <= scr_w ? pointer_x : scr_w - tip_w;
+ y = pointer_y + tip_h + 1 <= scr_h ? pointer_y + 1: pointer_y - tip_h;
+ gtk_widget_popup (text->tooltip_window, x, y);
+
+ return FALSE;
+}
+
static gint
e_text_event (GnomeCanvasItem *item, GdkEvent *event)
{
@@ -1951,6 +1993,7 @@ e_text_event (GnomeCanvasItem *item, GdkEvent *event)
}
break;
case GDK_ENTER_NOTIFY:
+ text->tooltip_timeout = gtk_timeout_add (3000, _do_tooltip, text);
text->pointer_in = TRUE;
if (text->editing) {
if ( text->default_cursor_shown ) {
@@ -1960,6 +2003,12 @@ e_text_event (GnomeCanvasItem *item, GdkEvent *event)
}
break;
case GDK_LEAVE_NOTIFY:
+ gtk_timeout_remove (text->tooltip_timeout);
+ if (text->tooltip_window) {
+ gtk_widget_destroy (text->tooltip_window);
+ text->tooltip_window = NULL;
+ }
+
text->pointer_in = FALSE;
if (text->editing) {
if ( ! text->default_cursor_shown ) {
diff --git a/widgets/text/e-text.h b/widgets/text/e-text.h
index 1254e0fd1c..c44589d3ae 100644
--- a/widgets/text/e-text.h
+++ b/widgets/text/e-text.h
@@ -173,6 +173,9 @@ struct _EText {
GdkCursor *default_cursor; /* Default cursor (arrow) */
GdkCursor *i_cursor; /* I beam cursor */
+
+ gint tooltip_timeout; /* Timeout for the tooltip */
+ GtkWidget *tooltip_window; /* GtkWindow for displaying the tooltip */
};
struct _ETextClass {