I am trying to do a bit of syntax highlighting. I am using gtk_text_buffer_create_tag and gtk_text_buffer_insert_with_tags to syntax-highlight the intial text (from file). That works fine. The program needs to identify existing syntax tokens in order to do appropriate syntax checking should the user decide to go back and amend them and I am having problems with this. Find a token-tag from current position: [code] static int findtagfromcursor ( GtkTextBuffer * buf ) { GtkTextMark * mark = gtk_text_buffer_get_insert (buf); GtkTextIter curiter ; gtk_text_buffer_get_iter_at_mark (buf, &curiter, mark); int k = 0 ; while ( k < NUMTOKENS ) { if ( gtk_text_iter_has_tag ( &curiter , tags [ k ] ) ) { return k ; } k++ ; } return -1 ; } [/code] The tags array is set by calls to gtk_text_buffer_create_tag when the text is read in. Initialisation: [code] GtkWidget * e = gtk_text_view_new ( ) ; GtkTextBuffer * buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (e)); gtk_text_view_set_editable ( (GtkTextView *)e , true ) ; g_signal_connect_after ( G_OBJECT (e) , "button-press-event" , G_CALLBACK (buttonpresscb) , buf ) ; [/code] Skeleton callback: [code] static gboolean buttonpresscb ( GtkWidget * w, GdkEventButton *event, char * data ) { GtkTextBuffer * buf = (GtkTextBuffer *)data ; int tokenix = findtagfromcursor ( buf ) ; if ( tokenix != -1 ) { printf ( "MTOKEN %s(%d): \n" tokenlkup [ tokenix ] , tokenix ) ; } else { printf ( "MTOKEN %d: \n" , tokenix ) ; } return false; } [/code] Textview text: text text ... TOKEN2TEXT text text... TOKEN0TEXT text text ... TOKEN1TEXT 'text text...' is unadorned text. TOKEN0TEXT, TOKEN1TEXT, TOKEN2TEXT ... are categories of text associated with different visual attributes. The program identifies these with numbers 0,1,2 internally. When the user clicks on a token the program needs to identify the token. When I click TOKEN2TEXT the callback reports no-token (-1). Then when I click TOKEN0TEXT it reports the TOKEN2TEXT (2) and when I click TOKEN1TEXT it reports TOKEN0TEXT (0) and so on. I thought this is because buttonpresscb is called before the text handler that changes the current text position to the mouse-click position, so I changed the connect call to g_signal_connect_after ( G_OBJECT (e) , "but... ). That did not work. I received no buttonpress events at all. Why? I am totally stuck, so would be most grateful for advice. |