Code below, press the validate button to see the problem with line wrap and 'newline chars' as per my original post.
#!/usr/bin/perl
#
#Text widget word wrap problem demo
#
use strict;
use Tk;
use Tk::TFrame;
my $mw = MainWindow->new;
my $big_font = $mw->fontCreate(
-size => 11, -family => 'Terminal',
-weight => 'bold');
$mw->title("Demo App");
my $seg1_f = $mw->TFrame(-label => 'Segment 1', -relief => 'groove', -
+borderwidth => 2);
my $ts_box = $seg1_f->Text(-wrap => 'word', -width => 60, -height =>
+6,
-font => $big_font);
$ts_box->grid( -padx => 4, -pady => 4, -row => 0, -column => 4,
-sticky => "nsew", -rowspan =>
+ 4);
$ts_box->menu(undef);
$ts_box->tagConfigure("badc", -foreground => "red", -background => 'ye
+llow');
my $val = $seg1_f->Button(-text => "Validate", -command => [\&valida
+te_text, 4]);
$val->grid(-row => 0, -column => 3, -padx => 4, -pady => 5);
$seg1_f->grid(-row => 0, -column => 0, -sticky => "nsew",-padx => 2, -
+pady => 2);
$mw->resizable(0,0);
$ts_box->insert('end', "This is some test text with some invalid @ cha
+racters");
$ts_box->insert('end', " If you click the Validate button the bad char
+s &should be");
$ts_box->insert('end', " highlighted! Note that a newline character");
$ts_box->insert('end', "\n hightlights to the end of the line not just
+ the single");
$ts_box->insert('end', " character position. Is this a bug?");
MainLoop;
# Validate the text field
sub validate_text{
my $i_st;
my $idx;
my $cnt;
my $ch;
$ts_box->tagRemove('badc', '1.0', 'end');
my $wstring = $ts_box->get("1.0", "end");
$idx = length($wstring)-1;
if ($idx == 0) {return(0)}
$cnt = 0;
while ($idx != $cnt) {
$ch = substr($wstring, $cnt, 1);
if (!($ch =~ /[A-Za-z0-9 \/.,=?*+]/)) {
$i_st = sprintf("1.%d", $cnt); # bad char
$ts_box->tagAdd('badc', $i_st);
}
$cnt++;
}
}
|