Re: A question about "event" signal of GtkTextTag



On Tue, 2002-05-28 at 07:45, Dongho Shin wrote:
> Here is a sample test program which shows the problem.

[snip]

The problem is that GtkTextView doesn't send motion-notify events to the
tags at all. Whether this is on purpose or not, I'm not sure...

The solution is to bind the "motion-notify" signal of the TextView
itself, then proxy it to any tags under the mouse, or just handle the
cursor-flipping from inside the textview's signal (which is a faster and
better solution, as you aren't wasting time for any tags you don't want
to).

As I said earlier, I've done this, and it works, though it spits out a
lot of g_warning() msgs:

(gnomechat:22654): Gtk-CRITICAL **: file gtktextiter.c: line 3525
(gtk_text_iter_set_line_offset): assertion `char_on_line <=
chars_in_line' failed

I don't know why exactly...

Anyways, here's the code:

static gboolean
text_view_motion_notify_event (GtkWidget * widget, GdkEventMotion
*event, gpointer data)
{
	static GdkCursor *hand_cursor = NULL;
	static GdkCursor *ibar_cursor = NULL;
	static GtkTextTag *tag = NULL;

	GtkTextView *view = GTK_TEXT_VIEW (widget);
	GtkTextWindowType type;
	GtkTextIter iter;
	GdkWindow *win;
	gint x,
	  y,
	  buf_x,
	  buf_y;

	type = gtk_text_view_get_window_type (view, event->window);

	if (type != GTK_TEXT_WINDOW_TEXT)
		return FALSE;

	/* Get where the pointer really is */
	win = gtk_text_view_get_window (view, type);
	gdk_window_get_pointer (win, &x, &y, NULL);

	/* Get the iter where the cursor is at */
	gtk_text_view_window_to_buffer_coords (view, type, x, y, &buf_x,
&buf_y);
	gtk_text_view_get_iter_at_location (view, &iter, buf_x, buf_y);

	/* Get the tag we're interested in -- I use a static var for
	   this & the cursors to speed things up slightly. */
	if (!tag)
		tag = gtk_text_tag_table_lookup (table,
			style_names[VIEWER_STYLE_LINK]);
	if (!hand_cursor)
		hand_cursor = gdk_cursor_new (GDK_HAND2);
	if (!ibar_cursor)
		ibar_cursor = gdk_cursor_new (GDK_XTERM);

	if (gtk_text_iter_has_tag (&iter, tag))
	{
		gdk_window_set_cursor (win, hand_cursor);
	}
	else
	{
		gdk_window_set_cursor (win, ibar_cursor);
	}

	return FALSE;
}

Peace,

    Jim Cape
    http://ignore-your.tv/

    "No cause, no God, no abstract idea can justify the mass
     slaughter of innocents."
        -- Edward Said




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]