home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tk42r2x.zip / TclTk / lib / tk4.2 / tk.tcl < prev    next >
Text File  |  1999-07-27  |  5KB  |  156 lines

  1. # tk.tcl --
  2. #
  3. # Initialization script normally executed in the interpreter for each
  4. # Tk-based application.  Arranges class bindings for widgets.
  5. #
  6. # SCCS: @(#) tk.tcl 1.87 96/09/30 09:28:02
  7. #
  8. # Copyright (c) 1992-1994 The Regents of the University of California.
  9. # Copyright (c) 1994-1996 Sun Microsystems, Inc.
  10. #
  11. # See the file "license.terms" for information on usage and redistribution
  12. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  13.  
  14. # Insist on running with compatible versions of Tcl and Tk.
  15.  
  16. package require -exact Tk 4.2
  17. package require -exact Tcl 7.6
  18.  
  19. # Add Tk's directory to the end of the auto-load search path, if it
  20. # isn't already on the path:
  21.  
  22. if {[lsearch -exact $auto_path $tk_library] < 0} {
  23.     lappend auto_path $tk_library
  24. }
  25.  
  26. # Turn off strict Motif look and feel as a default.
  27.  
  28. set tk_strictMotif 0
  29.  
  30. # tkScreenChanged --
  31. # This procedure is invoked by the binding mechanism whenever the
  32. # "current" screen is changing.  The procedure does two things.
  33. # First, it uses "upvar" to make global variable "tkPriv" point at an
  34. # array variable that holds state for the current display.  Second,
  35. # it initializes the array if it didn't already exist.
  36. #
  37. # Arguments:
  38. # screen -        The name of the new screen.
  39.  
  40. proc tkScreenChanged screen {
  41.     set disp [file rootname $screen]
  42.     uplevel #0 upvar #0 tkPriv.$disp tkPriv
  43.     global tkPriv
  44.     if [info exists tkPriv] {
  45.     set tkPriv(screen) $screen
  46.     return
  47.     }
  48.     set tkPriv(afterId) {}
  49.     set tkPriv(buttons) 0
  50.     set tkPriv(buttonWindow) {}
  51.     set tkPriv(dragging) 0
  52.     set tkPriv(focus) {}
  53.     set tkPriv(grab) {}
  54.     set tkPriv(initPos) {}
  55.     set tkPriv(inMenubutton) {}
  56.     set tkPriv(listboxPrev) {}
  57.     set tkPriv(mouseMoved) 0
  58.     set tkPriv(oldGrab) {}
  59.     set tkPriv(popup) {}
  60.     set tkPriv(postedMb) {}
  61.     set tkPriv(pressX) 0
  62.     set tkPriv(pressY) 0
  63.     set tkPriv(screen) $screen
  64.     set tkPriv(selectMode) char
  65.     set tkPriv(window) {}
  66. }
  67.  
  68. # Do initial setup for tkPriv, so that it is always bound to something
  69. # (otherwise, if someone references it, it may get set to a non-upvar-ed
  70. # value, which will cause trouble later).
  71.  
  72. tkScreenChanged [winfo screen .]
  73.  
  74. # tkEventMotifBindings --
  75. # This procedure is invoked as a trace whenever tk_strictMotif is
  76. # changed.  It is used to turn on or turn off the motif virtual
  77. # bindings.
  78. #
  79. # Arguments:
  80. # n1 - the name of the variable being changed ("tk_strictMotif").
  81.  
  82. proc tkEventMotifBindings {n1 dummy dummy} {
  83.     upvar $n1 name
  84.     
  85.     if $name {
  86.     set op delete
  87.     } else {
  88.     set op add
  89.     }
  90.  
  91.     event $op <<Cut>> <Control-Key-w>
  92.     event $op <<Copy>> <Meta-Key-w> 
  93.     event $op <<Paste>> <Control-Key-y>
  94. }
  95.  
  96. #----------------------------------------------------------------------
  97. # Define the set of common virtual events.
  98. #----------------------------------------------------------------------
  99.  
  100. switch $tcl_platform(platform) {
  101.     "unix" {
  102.     event add <<Cut>> <Control-Key-x> <Key-F20> 
  103.     event add <<Copy>> <Control-Key-c> <Key-F16>
  104.     event add <<Paste>> <Control-Key-v> <Key-F18>
  105.     trace variable tk_strictMotif w tkEventMotifBindings
  106.     set tk_strictMotif $tk_strictMotif
  107.     }
  108.     "windows" {
  109.     event add <<Cut>> <Control-Key-x> <Shift-Key-Delete>
  110.     event add <<Copy>> <Control-Key-c> <Control-Key-Insert>
  111.     event add <<Paste>> <Control-Key-v> <Shift-Key-Insert>
  112.     }
  113.     "macintosh" {
  114.     event add <<Cut>> <Control-Key-x> <Key-F2> 
  115.     event add <<Copy>> <Control-Key-c> <Key-F3>
  116.     event add <<Paste>> <Control-Key-v> <Key-F4>
  117.     event add <<Clear>> <Clear>
  118.     }
  119. }
  120.  
  121. # ----------------------------------------------------------------------
  122. # Read in files that define all of the class bindings.
  123. # ----------------------------------------------------------------------
  124.  
  125. if {$tcl_platform(platform) != "macintosh"} {
  126.     source $tk_library/button.tcl
  127.     source $tk_library/entry.tcl
  128.     source $tk_library/listbox.tcl
  129.     source $tk_library/menu.tcl
  130.     source $tk_library/scale.tcl
  131.     source $tk_library/scrlbar.tcl
  132.     source $tk_library/text.tcl
  133. }
  134.  
  135. # ----------------------------------------------------------------------
  136. # Default bindings for keyboard traversal.
  137. # ----------------------------------------------------------------------
  138.  
  139. bind all <Tab> {focus [tk_focusNext %W]}
  140. bind all <Shift-Tab> {focus [tk_focusPrev %W]}
  141.  
  142. # tkCancelRepeat --
  143. # This procedure is invoked to cancel an auto-repeat action described
  144. # by tkPriv(afterId).  It's used by several widgets to auto-scroll
  145. # the widget when the mouse is dragged out of the widget with a
  146. # button pressed.
  147. #
  148. # Arguments:
  149. # None.
  150.  
  151. proc tkCancelRepeat {} {
  152.     global tkPriv
  153.     after cancel $tkPriv(afterId)
  154.     set tkPriv(afterId) {}
  155. }
  156.