File: preProcess

package info (click to toggle)
libcdk-perl 4.9.10-4
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 912 kB
  • ctags: 410
  • sloc: perl: 6,419; sh: 27; makefile: 4
file content (58 lines) | stat: -rwxr-xr-x 1,096 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/perl -w
# $Id: preProcess,v 1.2 2002/07/27 20:11:17 tom Exp $

#
# Purpose:
#	To demonstrate the preProcess method.

#
# Load in the Cdk Extension.
#
use Cdk;
Cdk::init();

# Create a new entry object.
my $title = ["", "Type in anything but the dreaded letter 'G'!", ""];
my $entry = new Cdk::Entry ('Label' => "Type Anything: ",
				'Title' => $title,
				'Width' => 20,
				'Min' => 0,
				'Max' => 256);

# Set up the pre and post processing.
$entry->preProcess ('Function' => sub {preProcessCB (@_, $entry);});

# Activate the object.
my $info = $entry->activate();

# Check the results.
if (!defined $info)
{
   popupLabel (["<C>You hit escape, nothing returned."]);
}
else
{
   popupLabel (["<C>You typed in ($info)"]);
}

# Exit Cdk.
Cdk::end();

#
# This example will set the pre process function so it
# will not accept the letter g.
#
sub preProcessCB
{
   my ($input, $entry) = @_;

   # Check the letter.
   if (uc $input eq "G")
   {
      Cdk::Beep();
      popupLabel (["<C>I Told You </B>NOT<!B> To Do That"]);
      $entry->draw();
      return 0;
   }
   return 1;
}