1#!/bin/sh
2# the next line restarts using wish \
3exec wish "$0" "$@"
4
5# Copyright (c) 2005-2007 Keith Nash.
6#
7# See the file "license.terms" for information on usage and redistribution
8# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
9
10### This demo explores the ntext options
11### For a short example, see ntextExample.tcl
12### To explore ntext indentation, try ntextDemoIndent.tcl
13
14# This string defines the text that will be displayed in each widget:
15set message {QOTW:  "C/C++, which is used by 16% of users, is the most popular programming language, but Tcl, used by 0%, seems to be the language of choice for the highest scoring users."
16
17example code {alph {bet {b}} {gam {c}}} {
18    # Example code rich in punctuation
19    if {!($alph eq "a" && $bet eq "b")} {
20        puts "$gam $::messages::demo(d)"
21    }
22}
23
24Try editing the text with the keyboard and mouse; compare the bindings for Text (left panel) and Ntext (right panel).
25
26Try word-by-word navigation (Control key with left cursor or right cursor key); try word selection (double click); try these for the different word-break detection options (selected below).
27
28The classicMouseSelect and classicAnchor options are discussed in the man page for ntextBindings.}
29# End of string for widget text.
30
31package require ntext
32
33# Whether Shift-Button-1 ignores changes made by the kbd to the insert mark:
34set ::ntext::classicMouseSelect 0
35
36# Whether Shift-Button-1 has a variable or fixed anchor:
37set ::ntext::classicAnchor      0
38
39# Whether the traditional "extra" bindings are activated:
40set ::ntext::classicExtras      1
41
42# Whether to use new or classic word boundary detection:
43set ::ntext::classicWordBreak   0
44
45# Set to 0 to align wrapped display lines with the first display line of the logical line:
46set ::ntext::classicWrap        1
47
48pack [frame .rhf] -side right -anchor nw
49pack [text .rhf.new ]
50bindtags .rhf.new {.rhf.new Ntext . all}
51
52.rhf.new configure -wrap word -undo 1
53.rhf.new configure -width 42 -height 29 -font {{Courier} -15} -bg white
54.rhf.new insert end "  I use the Ntext bindings.\n\n$message"
55.rhf.new edit separator
56
57pack [frame .lhf] -side left -anchor ne
58pack [text .lhf.classic ]
59.lhf.classic configure -width 42 -height 29 -wrap word -undo 1 -font {{Courier} -15} -bg #FFFFEE
60.lhf.classic insert end "  I use the (default) Text bindings.\n\n$message"
61.lhf.classic edit separator
62pack [label  .lhf.m -text "(The controls do not apply\nto the left-hand text widget)"]
63
64pack [frame .rhf.h] -fill x
65pack [radiobutton .rhf.h.on  -text "On " -variable ::ntext::classicMouseSelect -value 1] -side right
66pack [radiobutton .rhf.h.off -text "Off" -variable ::ntext::classicMouseSelect -value 0] -side right
67pack [label  .rhf.h.l -text "classicMouseSelect: "] -side right
68
69pack [frame .rhf.g] -anchor ne
70pack [radiobutton .rhf.g.on  -text "On " -variable ::ntext::classicAnchor -value 1] -side right
71pack [radiobutton .rhf.g.off -text "Off" -variable ::ntext::classicAnchor -value 0] -side right
72pack [label  .rhf.g.l -text "classicAnchor: "] -side right
73
74pack [frame .rhf.k] -anchor ne
75pack [radiobutton .rhf.k.on  -text "On " -variable ::ntext::classicExtras -value 1] -side right
76pack [radiobutton .rhf.k.off -text "Off" -variable ::ntext::classicExtras -value 0] -side right
77pack [label  .rhf.k.l -text "classicExtras: "] -side right
78
79pack [frame .rhf.j] -anchor ne
80set wordBreakChoice new
81pack [radiobutton .rhf.j.wind -text "On (Windows)" -variable wordBreakChoice -value "windows" -command {setPattern}] -side right
82pack [radiobutton .rhf.j.unix -text "On (Unix)" -variable wordBreakChoice -value "unix" -command {setPattern}] -side right
83pack [radiobutton .rhf.j.off  -text "Off" -variable wordBreakChoice -value "new" -command {setPattern}] -side right
84pack [label  .rhf.j.l -text "classicWordBreak: "] -side right
85
86proc setPattern {} {
87    global wordBreakChoice
88    set platform $::tcl_platform(platform)
89
90    if {$wordBreakChoice eq "unix"} {
91        set ::tcl_platform(platform) unix
92        set ::ntext::classicWordBreak 1
93    } elseif {$wordBreakChoice eq "windows"} {
94        set ::tcl_platform(platform) windows
95        set ::ntext::classicWordBreak 1
96    } else {
97        set ::ntext::classicWordBreak 0
98    }
99
100    ::ntext::initializeMatchPatterns
101    set ::tcl_platform(platform) $platform
102}
103