| 1 | # Copyright 2010 Kevin Ryde | ||
| 2 | |||
| 3 | # This file is part of Chart. | ||
| 4 | # | ||
| 5 | # Chart is free software; you can redistribute it and/or modify it under the | ||
| 6 | # terms of the GNU General Public License as published by the Free Software | ||
| 7 | # Foundation; either version 3, or (at your option) any later version. | ||
| 8 | # | ||
| 9 | # Chart is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| 10 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 11 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| 12 | # details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License along | ||
| 15 | # with Chart. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | |||
| 17 | |||
| 18 | package App::Chart::Gtk2::Ex::TextViewBits; | ||
| 19 | use 5.010; | ||
| 20 | use strict; | ||
| 21 | use warnings; | ||
| 22 | |||
| 23 | # uncomment this to run the ### lines | ||
| 24 | #use Smart::Comments; | ||
| 25 | |||
| 26 | sub window_linenum { | ||
| 27 | my ($textview) = @_; | ||
| 28 | my ($x, $y) = $textview->window_to_buffer_coords ('text', 0, 0); | ||
| 29 | my ($win_iter, $line_top) = $textview->get_line_at_y ($y); | ||
| 30 | return $win_iter->get_line; | ||
| 31 | } | ||
| 32 | |||
| 33 | |||
| 34 | # TextBufferBits replace_lines() better | ||
| 35 | |||
| 36 | # sub replace_text { | ||
| 37 | # my ($textview, $str) = @_; | ||
| 38 | # ### TextViewBits replace_text() | ||
| 39 | # my $linenum = window_linenum ($textview); | ||
| 40 | # ### window linenum: $linenum | ||
| 41 | # | ||
| 42 | # my $textbuf = $textview->get_buffer; | ||
| 43 | # $textbuf->set_text ($str); | ||
| 44 | # | ||
| 45 | # # Had lots of trouble here. scroll_to_iter didn't take effect unless | ||
| 46 | # # called twice, and then stubbornly refused to put the last page visible. | ||
| 47 | # # scroll_to_mark works, but the first time through have to do a | ||
| 48 | # # place_cursor or else it starts off showing the end of the buffer instead | ||
| 49 | # # of the start. :-( | ||
| 50 | # # | ||
| 51 | # # Still not quite right if you do it too rapidly :-( | ||
| 52 | # # | ||
| 53 | # my $iter = $textbuf->get_iter_at_line ($linenum); | ||
| 54 | # $textbuf->place_cursor ($iter); | ||
| 55 | # my $mark = $textbuf->get_mark (__PACKAGE__); | ||
| 56 | # if ($mark) { $textbuf->move_mark ($mark, $iter); } | ||
| 57 | # else { $mark = $textbuf->create_mark (__PACKAGE__, $iter, 0); } | ||
| 58 | # $textview->scroll_to_mark ($mark, 0, 1, 0.0, 0.0); | ||
| 59 | # } | ||
| 60 | |||
| 61 | # =item C<< App::Chart::Gtk2::Ex::TextViewBits::replace_text ($textview, $str) >> | ||
| 62 | # | ||
| 63 | # Replace the text in C<$textview>'s buffer, preserving its window position. | ||
| 64 | |||
| 65 | |||
| 66 | 1; | ||
| 67 | __END__ | ||
| 68 | |||
| 69 | =for stopwords Ryde Chart | ||
| 70 | |||
| 71 | =head1 NAME | ||
| 72 | |||
| 73 | App::Chart::Gtk2::Ex::TextViewBits -- helpers for Gtk2::TextView widgets | ||
| 74 | |||
| 75 | =head1 SYNOPSIS | ||
| 76 | |||
| 77 | use App::Chart::Gtk2::Ex::TextViewBits; | ||
| 78 | |||
| 79 | =head1 FUNCTIONS | ||
| 80 | |||
| 81 | =over 4 | ||
| 82 | |||
| 83 | =item C<< App::Chart::Gtk2::Ex::TextViewBits::window_linenum ($textview) >> | ||
| 84 | |||
| 85 | Return the line number of the first visible or partly-visible line in | ||
| 86 | C<$textview>, numbered starting from 0 for the first line (the same as a | ||
| 87 | C<Gtk2::TextIter> uses). | ||
| 88 | |||
| 89 | =back | ||
| 90 | |||
| 91 | =head1 SEE ALSO | ||
| 92 | |||
| 93 | L<Gtk2::TextView>, L<Gtk2::Ex::WidgetBits> | ||
| 94 | |||
| 95 | =head1 HOME PAGE | ||
| 96 | |||
| 97 | L<http://user42.tuxfamily.org/chart/index.html> | ||
| 98 | |||
| 99 | =head1 LICENSE | ||
| 100 | |||
| 101 | Copyright 2010 Kevin Ryde | ||
| 102 | |||
| 103 | Chart is free software; you can redistribute it and/or modify | ||
| 104 | it under the terms of the GNU General Public License as published by the | ||
| 105 | Free Software Foundation; either version 3, or (at your option) any later | ||
| 106 | version. | ||
| 107 | |||
| 108 | Chart is distributed in the hope that it will be useful, but | ||
| 109 | WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
| 110 | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
| 111 | more details. | ||
| 112 | |||
| 113 | You should have received a copy of the GNU General Public License along with | ||
| 114 | Chart. If not, see L<http://www.gnu.org/licenses/>. | ||
| 115 | |||
| 116 | =cut |