head	1.7;
access;
symbols
	core-8-5-9:1.7
	core-8-5-8:1.7
	macosx-cocoa-merge:1.7
	macosx-cocoa-premerge:1.7
	macosx-carbon-freeze:1.7
	core-8-5-7:1.7
	core-8-5-6:1.7
	core-8-6-b1:1.7
	core-8-6-a3:1.7
	core-8-5-5:1.7
	core-8-6-a2:1.7
	core-8-5-4:1.7
	core-8-5-3:1.7
	core-8-6-a1:1.7
	core-8-4-19:1.1
	core-8-5-branch:1.7.0.2
	core-8-5-2:1.7
	core-8-4-18:1.1
	core-8-5-1:1.7
	core-8-4-17:1.1
	core-8-5-0:1.7
	core-8-5-b3:1.6
	core-8-5-b2:1.5
	core-8-4-16:1.1
	core-8-5-b1:1.4
	core-stablilizer-merge:1.4
	core-stabilizer-branch:1.4.0.2
	core-stabilizer-merge:1.7
	core-8-4-15:1.1
	core-8-5-a6:1.4
	core-8-5-a5:1.4
	core-8-4-14:1.1
	core-8-5-a4:1.4
	core-8-4-13:1.1
	core-8-4-12:1.1
	core-8-4-11:1.1
	core-8-5-a3:1.4
	core-8-4-10:1.1
	core-8-4-9-branch:1.1.0.8
	core-8-5-a2:1.3
	core-8-4-9:1.1
	core-8-4-8:1.1
	core-8-4-7:1.1
	core-8-5-a1:1.2
	core-8-4-6:1.1
	core-8-4-5:1.1
	mistachkin-dev-branch:1.2.0.2
	core-8-4-4:1.1
	core-8-4-3:1.1
	core-8-4-branch:1.1.0.6
	core-8-4-2:1.1
	core-8-4-1:1.1
	core-8-4-0:1.1
	macosx-8-4-merge-2002-08-31-trunk:1.1
	macosx-8-4-premerge-2002-08-31-branch:1.1.2.1
	macosx-8-4-premerge-2002-08-31-trunk:1.1
	macosx-8-4-merge-2002-08-30-branch:1.1.2.1
	macosx-8-4-merge-2002-08-30-trunk:1.1
	macosx-8-4-merge-2002-08-20-branch:1.1.2.1
	macosx-8-4-merge-2002-08-20-trunk:1.1
	core-8-4-b2:1.1
	core-8-4-b1:1.1
	macosx-premerge-6-9-02:1.1.2.1
	core-8-4-win-speedup:1.1.0.4
	core-8-4-a4:1.1
	macosx-8-4-branch:1.1.0.2;
locks; strict;
comment	@# @;


1.7
date	2007.12.13.15.27.07;	author dgp;	state Exp;
branches;
next	1.6;

1.6
date	2007.10.31.16.37.23;	author dkf;	state Exp;
branches;
next	1.5;

1.5
date	2007.10.17.18.55.05;	author das;	state Exp;
branches;
next	1.4;

1.4
date	2004.12.21.11.56.35;	author dkf;	state Exp;
branches
	1.4.2.1;
next	1.3;

1.3
date	2004.06.28.22.36.18;	author dkf;	state Exp;
branches;
next	1.2;

1.2
date	2003.08.20.23.02.18;	author hobbs;	state Exp;
branches;
next	1.1;

1.1
date	2001.11.19.14.02.29;	author dkf;	state Exp;
branches
	1.1.2.1
	1.1.4.1;
next	;

1.1.2.1
date	2002.02.05.02.25.16;	author wolfsuit;	state Exp;
branches;
next	;

1.1.4.1
date	2002.04.02.20.58.50;	author hobbs;	state Exp;
branches;
next	;

1.4.2.1
date	2007.10.19.14.35.33;	author dgp;	state Exp;
branches;
next	1.4.2.2;

1.4.2.2
date	2007.11.01.16.37.21;	author dgp;	state Exp;
branches;
next	;


desc
@@


1.7
log
@merge stable branch onto HEAD
@
text
@# entry3.tcl --
#
# This demonstration script creates several entry widgets whose
# permitted input is constrained in some way.  It also shows off a
# password entry.
#
# RCS: @@(#) $Id: entry3.tcl,v 1.4.2.2 2007/11/01 16:37:21 dgp Exp $

if {![info exists widgetDemo]} {
    error "This script should be run from the \"widget\" demo."
}

package require Tk

set w .entry3
catch {destroy $w}
toplevel $w
wm title $w "Constrained Entry Demonstration"
wm iconname $w "entry3"
positionWindow $w

label $w.msg -font $font -wraplength 5i -justify left -text "Four different\
	entries are displayed below.  You can add characters by pointing,\
	clicking and typing, though each is constrained in what it will\
	accept.  The first only accepts 32-bit integers or the empty string\
	(checking when focus leaves it) and will flash to indicate any\
	problem.  The second only accepts strings with fewer than ten\
	characters and sounds the bell when an attempt to go over the limit\
	is made.  The third accepts US phone numbers, mapping letters to\
	their digit equivalent and sounding the bell on encountering an\
	illegal character or if trying to type over a character that is not\
	a digit.  The fourth is a password field that accepts up to eight\
	characters (silently ignoring further ones), and displaying them as\
	asterisk characters."

## See Code / Dismiss buttons
set btns [addSeeDismiss $w.buttons $w]
pack $btns -side bottom -fill x

# focusAndFlash --
# Error handler for entry widgets that forces the focus onto the
# widget and makes the widget flash by exchanging the foreground and
# background colours at intervals of 200ms (i.e. at approximately
# 2.5Hz).
#
# Arguments:
# W -		Name of entry widget to flash
# fg -		Initial foreground colour
# bg -		Initial background colour
# count -	Counter to control the number of times flashed

proc focusAndFlash {W fg bg {count 9}} {
    focus -force $W
    if {$count<1} {
	$W configure -foreground $fg -background $bg
    } else {
	if {$count%2} {
	    $W configure -foreground $bg -background $fg
	} else {
	    $W configure -foreground $fg -background $bg
	}
	after 200 [list focusAndFlash $W $fg $bg [expr {$count-1}]]
    }
}

labelframe $w.l1 -text "Integer Entry"
# Alternatively try using {string is digit} for arbitrary length numbers,
# and not just 32-bit ones.
entry $w.l1.e -validate focus -vcmd {string is integer %P}
$w.l1.e configure -invalidcommand \
	"focusAndFlash %W [$w.l1.e cget -fg] [$w.l1.e cget -bg]"
pack $w.l1.e -fill x -expand 1 -padx 1m -pady 1m

labelframe $w.l2 -text "Length-Constrained Entry"
entry $w.l2.e -validate key -invcmd bell -vcmd {expr {[string length %P]<10}}
pack $w.l2.e -fill x -expand 1 -padx 1m -pady 1m

### PHONE NUMBER ENTRY ###
# Note that the source to this is quite a bit longer as the behaviour
# demonstrated is a lot more ambitious than with the others.

# Initial content for the third entry widget
set entry3content "1-(000)-000-0000"
# Mapping from alphabetic characters to numbers.  This is probably
# wrong, but it is the only mapping I have; the UK doesn't really go
# for associating letters with digits for some reason.
set phoneNumberMap {}
foreach {chars digit} {abc 2 def 3 ghi 4 jkl 5 mno 6 pqrs 7 tuv 8 wxyz 9} {
    foreach char [split $chars ""] {
	lappend phoneNumberMap $char $digit [string toupper $char] $digit
    }
}

# validatePhoneChange --
# Checks that the replacement (mapped to a digit) of the given
# character in an entry widget at the given position will leave a
# valid phone number in the widget.
#
# W -	  The entry widget to validate
# vmode - The widget's validation mode
# idx -	  The index where replacement is to occur
# char -  The character (or string, though that will always be
#	  refused) to be overwritten at that point.

proc validatePhoneChange {W vmode idx char} {
    global phoneNumberMap entry3content
    if {$idx == -1} {return 1}
    after idle [list $W configure -validate $vmode -invcmd bell]
    if {
	!($idx<3 || $idx==6 || $idx==7 || $idx==11 || $idx>15) &&
	[string match {[0-9A-Za-z]} $char]
    } then {
	$W delete $idx
	$W insert $idx [string map $phoneNumberMap $char]
	after idle [list phoneSkipRight $W -1]
	return 1
    }
    return 0
}

# phoneSkipLeft --
# Skip over fixed characters in a phone-number string when moving left.
#
# Arguments:
# W -	The entry widget containing the phone-number.

proc phoneSkipLeft {W} {
    set idx [$W index insert]
    if {$idx == 8} {
	# Skip back two extra characters
	$W icursor [incr idx -2]
    } elseif {$idx == 7 || $idx == 12} {
	# Skip back one extra character
	$W icursor [incr idx -1]
    } elseif {$idx <= 3} {
	# Can't move any further
	bell
	return -code break
    }
}

# phoneSkipRight --
# Skip over fixed characters in a phone-number string when moving right.
#
# Arguments:
# W -	The entry widget containing the phone-number.
# add - Offset to add to index before calculation (used by validation.)

proc phoneSkipRight {W {add 0}} {
    set idx [$W index insert]
    if {$idx+$add == 5} {
	# Skip forward two extra characters
	$W icursor [incr idx 2]
    } elseif {$idx+$add == 6 || $idx+$add == 10} {
	# Skip forward one extra character
	$W icursor [incr idx]
    } elseif {$idx+$add == 15 && !$add} {
	# Can't move any further
	bell
	return -code break
    }
}

labelframe $w.l3 -text "US Phone-Number Entry"
entry $w.l3.e -validate key  -invcmd bell  -textvariable entry3content \
	-vcmd {validatePhoneChange %W %v %i %S}
# Click to focus goes to the first editable character...
bind $w.l3.e <FocusIn> {
    if {"%d" ne "NotifyAncestor"} {
	%W icursor 3
	after idle {%W selection clear}
    }
}
bind $w.l3.e <Left>  {phoneSkipLeft  %W}
bind $w.l3.e <Right> {phoneSkipRight %W}
pack $w.l3.e -fill x -expand 1 -padx 1m -pady 1m

labelframe $w.l4 -text "Password Entry"
entry $w.l4.e -validate key -show "*" -vcmd {expr {[string length %P]<=8}}
pack $w.l4.e -fill x -expand 1 -padx 1m -pady 1m

lower [frame $w.mid]
grid $w.l1 $w.l2 -in $w.mid -padx 3m -pady 1m -sticky ew
grid $w.l3 $w.l4 -in $w.mid -padx 3m -pady 1m -sticky ew
grid columnconfigure $w.mid {0 1} -uniform 1
pack $w.msg -side top
pack $w.mid -fill both -expand 1
@


1.6
log
@Improved description/comments so that people better understand what is being
validated, following suggestion from Don Porter.
@
text
@d7 1
a7 1
# RCS: @@(#) $Id$
@


1.5
log
@more GOOBE
@
text
@d7 1
a7 1
# RCS: @@(#) $Id: entry3.tcl,v 1.4 2004/12/21 11:56:35 dkf Exp $
d25 1
a25 1
	accept.  The first only accepts integers or the empty string\
d67 2
@


1.4
log
@Coding style improvements for the widget demo. [FRQ 815118]
@
text
@d7 1
a7 1
# RCS: @@(#) $Id$
a21 1

a184 1
pack $w.buttons -side bottom -fill x -pady 2m
@


1.4.2.1
log
@merge updates from HEAD
@
text
@d7 1
a7 1
# RCS: @@(#) $Id: entry3.tcl,v 1.4 2004/12/21 11:56:35 dkf Exp $
d22 1
d186 1
@


1.4.2.2
log
@merge updates from HEAD
@
text
@d7 1
a7 1
# RCS: @@(#) $Id: entry3.tcl,v 1.4.2.1 2007/10/19 14:35:33 dgp Exp $
d25 1
a25 1
	accept.  The first only accepts 32-bit integers or the empty string\
a66 2
# Alternatively try using {string is digit} for arbitrary length numbers,
# and not just 32-bit ones.
@


1.3
log
@Fix minor mistake
@
text
@d13 2
@


1.2
log
@	* library/demos/widget:      Redo code view dialog, use named fonts,
	* library/demos/arrow.tcl:   add basic see/dismiss routine with
	* library/demos/bind.tcl:    images for better look & feel
	* library/demos/bitmap.tcl:
	* library/demos/button.tcl:
	* library/demos/check.tcl:
	* library/demos/clrpick.tcl:
	* library/demos/colors.tcl:
	* library/demos/cscroll.tcl:
	* library/demos/ctext.tcl:
	* library/demos/entry1.tcl:
	* library/demos/entry2.tcl:
	* library/demos/entry3.tcl:
	* library/demos/filebox.tcl:
	* library/demos/floor.tcl:
	* library/demos/form.tcl:
	* library/demos/hscale.tcl:
	* library/demos/icon.tcl:
	* library/demos/image1.tcl:
	* library/demos/image2.tcl:
	* library/demos/items.tcl:
	* library/demos/label.tcl:
	* library/demos/labelframe.tcl:
	* library/demos/menu.tcl:
	* library/demos/menubu.tcl:
	* library/demos/paned1.tcl:
	* library/demos/paned2.tcl:
	* library/demos/plot.tcl:
	* library/demos/puzzle.tcl:
	* library/demos/radio.tcl:
	* library/demos/ruler.tcl:
	* library/demos/sayings.tcl:
	* library/demos/search.tcl:
	* library/demos/spin.tcl:
	* library/demos/states.tcl:
	* library/demos/style.tcl:
	* library/demos/text.tcl:
	* library/demos/twind.tcl:
	* library/demos/unicodeout.tcl:
	* library/demos/vscale.tcl:
@
text
@d1 1
a1 1
# entry2.tcl --
@


1.1
log
@Some neatening up of the widget demo launcher, and a new validated entry demo
@
text
@d35 3
a37 5
frame $w.buttons
button $w.buttons.dismiss -text Dismiss -command "destroy $w"
button $w.buttons.code -text "See Code" -command "showCode $w"
pack $w.buttons.dismiss $w.buttons.code -side left -expand 1

@


1.1.4.1
log
@sync with head
@
text
@@


1.1.2.1
log
@Merge with current TOT
Added support for the wm stackorder command
Fixed crash when selecting Menu items in the Application menu that we didn't
put there.
Added first bits of the use of CG for low-level drawing.  The line-drawing works,
the rest doesn't yet.  You have to set the file static useCGDrawing to 1 and
rebuild to activate this code.
@
text
@@

