gtk--: gtktext key_press



Hi,
       
I'm making a little editor in gtk--, and am having trouble doing the
current line/column statis stuff. The problem is, that the textbox seems
to update after my 'update_line' method is called and so it's always
behind.  If I call it from a method connected to 'text changed' and only
press keys that actually enter something into the text box, it works
fine.  Hopefully the below couple snippets will show what I'm doing
wrong.  

// class declaration
class MyEditText : public Gtk_Text

// my connect line
connect_to_method(key_press_event, this, &key_press);

// my key_press method
gint key_press(GdkEventKey *event) { cout << "keypress\n";
update_line(); return 1; }

// and my update line method
void MyEditText::update_line(void)  
{  
        gchar *ch = get_chars(0, get_point());
        cout << "point is " << get_point() << endl; // this always seems
to be
one behind actual point
        guint i=0, j=1, k=0;
        while(ch[i])
        {
                if(ch[i] == '\n') 
                        {  j++;  k = i;  }
                i++;
        }
        iLine = j;
        iCol = i-k;
        
        lblLine->set(dec(iLine));
        lblCol->set(dec(iCol));
        lblBytes->set(dec(get_length()));
        //cout << "line: " << iLine << " col: " << iCol << endl; 
}


--
Thanks,
Tom



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