1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| use Tk;
use strict;
use warnings;
my $mw = MainWindow->new;
my $hauteurEcran = $mw->screenheight();
my $largeurEcran = $mw->screenwidth();
$mw->configure(
-width => $largeurEcran,
-height => $hauteurEcran,
);
$mw->title("Test selection");
$mw->geometry(sprintf("%d",$largeurEcran) . "x" . sprintf("%d", $hauteurEcran) . "+0+0");
$mw->raise();
my $zoneTexte = $mw->Scrolled('Text',
-scrollbars => 'se',
-wrap => 'word',
-exportselection => 0,
)->place(
-anchor => 'nw',
-width => $largeurEcran,
-relheight => 0.95,
-relx => 0.0,
-rely => 0.05,
);
$zoneTexte->insert('end', "abc");
$zoneTexte->tagAdd('sel', '1.0', '1.0 lineend');
$zoneTexte->focus;
TagsTexteSelection($zoneTexte);
$zoneTexte->messageBox(-title => 'Test Selection',
-message => "Do you see the selection ?",
-type => 'OK',
);
MainLoop;
sub TagsTexteSelection {
my $WidgetText = shift;
# Creation des tags pour les textes sélectionnés ou non
$zoneTexte->tagConfigure('TextSelectionne',
-background => "red", # blue
-foreground => "green", # white
);
$zoneTexte->tagConfigure('TextNonSelectionne',
-background => $zoneTexte->cget( -background ),
-foreground => $zoneTexte->cget( -foreground ),
);
# Si ma zone de texte obtient le focus
$zoneTexte->bind("<FocusIn>",
sub {
my @Listes = $zoneTexte->tagRanges('TextSelectionne');
# On enleve le tag aux textes sélectionnés
$zoneTexte->tagRemove('TextSelectionne', @Listes);
}
);
# Si ma zone de texte perd le focus
$zoneTexte->bind("<FocusOut>",
sub {
# On attribut le tag aux textes sélectionnés
if ( $zoneTexte->tagRanges('sel') ) {
$zoneTexte->tagAdd('TextSelectionne', 'sel.first', 'sel.last');
}
}
);
return;
} |
Partager