Re: Get current cursor position?
| From: | Steph Fox | Date: | Sun, 09 Apr 2006 00:55:31 +0000 |
| Subject: | Re: Get current cursor position? | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-6849@lists.php.net to get a copy of this message | ||
Hi Sean, and welcome to PHP-GTK corner.
I didn't know the answer to this one either, I just spent forever playing. It looks like $iter->get_offset() is the baby - the 'offset' part refers to the position in the text buffer (aka the whole thing). It's easy enough to initialize the iter. What you _can't_ do is insert text on the fly programmatically though, as far as I can work out. GTK+ gets upset about it.
Messing around script:
<?php
function cb($buffer, $iter, $mark) {
echo $iter->get_offset()."\n";
echo $iter->get_line()."\n\n";
var_dump($buffer->get_insert());
var_dump($mark); // these two are different marks, but we can't see properties. How useful are they? Dunno yet.
}
$window = new GtkWindow();
$window->connect_simple('destroy', array('gtk', 'main_quit'));
$textview = new GtkTextView();
$buffer = $textview->get_buffer();
$buffer->connect('mark-set', 'cb');
$buffer->set_text('Hello world');
$end = $buffer->get_end_iter();
echo $end->get_offset()."\n"; // the useful part
echo $end->get_line()."\n\n"; // possibly another useful part
var_dump($buffer->get_mark('insert'));
$buffer->insert_at_cursor("\nHello again");
var_dump($buffer->get_insert()); /* this is equivalent to get_mark('insert') */
$window->add($textview);
$window->show_all();
Gtk::main();
?>
- Steph
----- Original Message ----- From: "Sean Coates" <sean@caedmon.net>
To: <php-gtk-general@lists.php.net>
Sent: Sunday, April 09, 2006 1:15 AM
Subject: [PHP-GTK] Get current cursor position?
Hello, I'm toying with php-gtk2. I'd like to determine the current cursor position of a GtkTextView; something like ->get_iter_at_cursor() would be excellent. Is there a way to do this? S -- PHP-GTK General Mailing List (http://gtk.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php __________ NOD32 1.1380 (20060125) Information __________ This message was checked by NOD32 antivirus system. http://www.eset.com