3 # Initialization script normally executed in the interpreter for each
4 # Tk-based application. Arranges class bindings for widgets.
6 # SCCS: @(#) tk.tcl 1.98 97/10/28 15:21:04
8 # Copyright (c) 1992-1994 The Regents of the University of California.
9 # Copyright (c) 1994-1996 Sun Microsystems, Inc.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 # Insist on running with compatible versions of Tcl and Tk.
16 package require -exact Tk 8.0
17 package require -exact Tcl 8.0
19 # Add Tk's directory to the end of the auto-load search path, if it
20 # isn't already on the path:
22 if {[info exists auto_path]} {
23 if {[lsearch -exact $auto_path $tk_library] < 0} {
24 lappend auto_path $tk_library
28 # Turn off strict Motif look and feel as a default.
33 # This procedure is invoked by the binding mechanism whenever the
34 # "current" screen is changing. The procedure does two things.
35 # First, it uses "upvar" to make global variable "tkPriv" point at an
36 # array variable that holds state for the current display. Second,
37 # it initializes the array if it didn't already exist.
40 # screen - The name of the new screen.
42 proc tkScreenChanged screen {
43 set x [string last . $screen]
45 set disp [string range $screen 0 [expr $x - 1]]
50 uplevel #0 upvar #0 tkPriv.$disp tkPriv
54 if [info exists tkPriv] {
55 set tkPriv(screen) $screen
58 set tkPriv(activeMenu) {}
59 set tkPriv(activeItem) {}
60 set tkPriv(afterId) {}
62 set tkPriv(buttonWindow) {}
63 set tkPriv(dragging) 0
66 set tkPriv(initPos) {}
67 set tkPriv(inMenubutton) {}
68 set tkPriv(listboxPrev) {}
69 set tkPriv(menuBar) {}
70 set tkPriv(mouseMoved) 0
71 set tkPriv(oldGrab) {}
73 set tkPriv(postedMb) {}
77 set tkPriv(screen) $screen
78 set tkPriv(selectMode) char
79 if {[string compare $tcl_platform(platform) "unix"] == 0} {
87 # Do initial setup for tkPriv, so that it is always bound to something
88 # (otherwise, if someone references it, it may get set to a non-upvar-ed
89 # value, which will cause trouble later).
91 tkScreenChanged [winfo screen .]
93 # tkEventMotifBindings --
94 # This procedure is invoked as a trace whenever tk_strictMotif is
95 # changed. It is used to turn on or turn off the motif virtual
99 # n1 - the name of the variable being changed ("tk_strictMotif").
101 proc tkEventMotifBindings {n1 dummy dummy} {
110 event $op <<Cut>> <Control-Key-w>
111 event $op <<Copy>> <Meta-Key-w>
112 event $op <<Paste>> <Control-Key-y>
115 #----------------------------------------------------------------------
116 # Define the set of common virtual events.
117 #----------------------------------------------------------------------
119 switch $tcl_platform(platform) {
121 event add <<Cut>> <Control-Key-x> <Key-F20>
122 event add <<Copy>> <Control-Key-c> <Key-F16>
123 event add <<Paste>> <Control-Key-v> <Key-F18>
124 trace variable tk_strictMotif w tkEventMotifBindings
125 set tk_strictMotif $tk_strictMotif
128 event add <<Cut>> <Control-Key-x> <Shift-Key-Delete>
129 event add <<Copy>> <Control-Key-c> <Control-Key-Insert>
130 event add <<Paste>> <Control-Key-v> <Shift-Key-Insert>
133 event add <<Cut>> <Control-Key-x> <Key-F2>
134 event add <<Copy>> <Control-Key-c> <Key-F3>
135 event add <<Paste>> <Control-Key-v> <Key-F4>
136 event add <<Clear>> <Clear>
140 # ----------------------------------------------------------------------
141 # Read in files that define all of the class bindings.
142 # ----------------------------------------------------------------------
144 if {$tcl_platform(platform) != "macintosh"} {
145 source $tk_library/button.tcl
146 source $tk_library/entry.tcl
147 source $tk_library/listbox.tcl
148 source $tk_library/menu.tcl
149 source $tk_library/scale.tcl
150 source $tk_library/scrlbar.tcl
151 source $tk_library/text.tcl
154 # ----------------------------------------------------------------------
155 # Default bindings for keyboard traversal.
156 # ----------------------------------------------------------------------
158 bind all <Tab> {tkTabToWindow [tk_focusNext %W]}
159 bind all <Shift-Tab> {tkTabToWindow [tk_focusPrev %W]}
162 # This procedure is invoked to cancel an auto-repeat action described
163 # by tkPriv(afterId). It's used by several widgets to auto-scroll
164 # the widget when the mouse is dragged out of the widget with a
170 proc tkCancelRepeat {} {
172 after cancel $tkPriv(afterId)
173 set tkPriv(afterId) {}
177 # This procedure moves the focus to the given widget. If the widget
178 # is an entry, it selects the entire contents of the widget.
181 # w - Window to which focus should be set.
183 proc tkTabToWindow {w} {
184 if {"[winfo class $w]" == "Entry"} {
185 $w select range 0 end