TextView scrolling/cursor problems



Hello list, 

I am new here and quite new to gtkmm and have found the docs, especially 
the book, very useful so far. Unfortunately the book doesn't cover 
everything (Iterators in a TextBuffer for example) so I have a few 
questions that can hopefully be answered by one of the more experienced 
gtkmm users :)

What is the best way to create a TextView (non-editable, no cursor 
visible, in a ScrolledWindow) that scrolls automatically when text is 
inserted? I've gathered something like the following basically works:

// Get current mark at insert (cursor) position 
cur_mark = textviewBuffer->get_insert();

// Get iterator from mark
iter = textviewBuffer->get_iter_at_mark(cur_mark);

// Insert text and save iterator (although not used anymore?)
iter = textviewBuffer->insert(iter, "Text portion with many lines");

// Get current mark at insert position
cur_mark = textviewBuffer->get_insert();

// Scroll to mark
textview->scroll_to(cur_mark, 0.0);

This gets a mark from the current cursor position, an iterator from that 
mark, inserts text at that interator position, saves the resulting 
iterator (which isn't used again though). Then the mark gets updated 
from the new cursor position and scrolling to that mark occurs.

This can be repeated (without the first call to get_insert()) and works 
fine for inserting text and scrolling to the end of it.

However, and here's my problem, when clicking somewhere in the TextView  
the cursor position gets set to where I clicked. Calling get_insert(), 
get_iter_at_mark() and insert() afterwards put the new text right where 
I clicked in the TextView.

This of course not the behaviour I want from the TextView and 
TextViewBuffer. How can I avoid that? I want new text to be inserted 
only at the bottom of the view, no matter whether I click the TextView 
or not, like seen in countless other GTK applications. Or are there 
other (better) ways to have an autoscrolling TextView?

Help and ideas would be appreciated!

Thanks in advance!

Andreas
-- 
Andreas "daff" Ntaflos 
daff AT dword DOT org
Vienna, Austria 

GPG Fingerprint: 	6234 2E8E 5C81 C6CB E5EC  7E65 397C E2A8 090C A9B4
GPG Public Key ID: 	090CA9B4
GPG Public Key:		http://daffit.meownz.info/publickey/andreas_ntaflos.asc

Attachment: pgpsuYcaANAh5.pgp
Description: PGP signature



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