gtk_text_view_get_iter_at_location and scrolling?



I use 
        gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(view), &iter, &x,
&y);
        
I then get the word at that location either side of the iter (up to
g_unichar_isspace(ch) == TRUE). 
This works fine *UNTIL* the buffer is large enough to need the scrollwindow.
At this point, the x and y still come back ok, but the text under the cursor
is the *SAME* text that the would be there if there scrollwindow was at the
top.  For some reason it is not refreshing.  To scroll down, I am using the
following method (to always scroll down on text input).

        mark = gtk_text_buffer_create_mark(buffer, NULL, &iter, FALSE);
        gtk_text_view_scroll_mark_onscreen(textview, mark);
        gtk_text_buffer_delete_mark(buffer, mark);¸

Here is the function callback for the motion notify event:

        gboolean on_textview_find_space(gunichar ch, gpointer user_data)
        {
            if(g_unichar_isspace(ch) == TRUE)
                return TRUE;

            return FALSE;
        }

        gboolean on_textview_motion_notify_event(GtkWidget *widget,
GdkEventMotion *event, gpointer user_data)
        {
          gint x = 0;
          gint y = 0;
          GdkModifierType state = 0;
          GdkWindow *window = NULL;

          GtkTextIter iter;
          GtkTextIter iter_start;
          GtkTextIter iter_end;
  
          gboolean found_start = FALSE;
          gboolean found_end = FALSE;
        
          gchar *buf = NULL;
        
          if(event->is_hint)
          {
              window = gdk_window_get_pointer(event->window, &x, &y,
&state);
          }
          else
          {
              x = event->x;
              y = event->y;
              state = event->state;
          }
          
          gtk_text_view_get_iter_at_location(textview, &iter, x, y);
         
          if(g_unichar_isspace(gtk_text_iter_get_char(&iter)) == TRUE)
          {
              g_message("iter is a space");
              return TRUE;
          }
        
          iter_start = iter;
          iter_end = iter;
        
          /* search for next space */
          found_start = gtk_text_iter_backward_find_char(&iter_start,
on_textview_find_space, NULL, NULL);
          found_end = gtk_text_iter_forward_find_char(&iter_end,
on_textview_find_space, NULL, NULL);
        
          if(found_start == FALSE && found_end == FALSE)
          {
              g_warning("on_textview_motion_notify_event: could not find
start and end space");
              return TRUE;
          }
        
          if(gtk_text_iter_is_start(&iter_start) == FALSE)
              gtk_text_iter_forward_char(&iter_start);
          
          if((buf = gtk_text_buffer_get_slice(buffer, &iter_start,
&iter_end, FALSE)) == NULL)
          {
              g_warning("on_textview_motion_notify_event: buf returned was
NULL");
              return TRUE;
          }
          
          g_message("word:'%s'", buf);
          
          if(supportIsURI(buf) != uriTypeUnknown)
          {
              GdkCursor *cursor = NULL;
              cursor = gdk_cursor_new(GDK_HAND2);
              gdk_window_set_cursor (event->window, cursor);
              
              /* clean up */
              gdk_cursor_unref(cursor);
          }  
          else
          {
              /* return to parent window's cursor */
              gdk_window_set_cursor(event->window, NULL);
          }
        
          /* clean up */
          if(buf != NULL) g_free(buf);
        
          return TRUE;
        }

Does the the textview need updating or refreshing in some way??
Also, this does the exact same thing if I do not scroll to the end and
instead insert the text (so that all new entries appear at the top).

I am using GTK 2.0.6 (as with RedHat 8.0).  

Regards,
Martyn



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