Init.tcl 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. # -*- mode: TCL; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: Init.tcl,v 1.18 2008/02/28 04:35:16 hobbs Exp $
  4. #
  5. # Init.tcl --
  6. #
  7. # Initializes the Tix library and performes version checking to ensure
  8. # the Tcl, Tk and Tix script libraries loaded matches with the binary
  9. # of the respective packages.
  10. #
  11. # Copyright (c) 1993-1999 Ioi Kim Lam.
  12. # Copyright (c) 2000-2001 Tix Project Group.
  13. # Copyright (c) 2004 ActiveState
  14. #
  15. # See the file "license.terms" for information on usage and redistribution
  16. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  17. #
  18. namespace eval ::tix {
  19. }
  20. proc tixScriptVersion {} { return $::tix_version }
  21. proc tixScriptPatchLevel {} { return $::tix_patchLevel }
  22. proc ::tix::Init {dir} {
  23. global tix env tix_library tcl_platform auto_path
  24. if {[info exists tix(initialized)]} {
  25. return
  26. }
  27. if {![info exists tix_library]} {
  28. # we're running from stand-alone module.
  29. set tix_library ""
  30. } elseif {[file isdir $tix_library]} {
  31. if {![info exists auto_path] ||
  32. [lsearch $auto_path $tix_library] == -1} {
  33. lappend auto_path $tix_library
  34. }
  35. }
  36. # STEP 1: Version checking
  37. #
  38. #
  39. package require Tcl 8.4
  40. package require -exact Tix 8.4.3
  41. # STEP 2: Initialize file compatibility modules
  42. #
  43. foreach file {
  44. fs.tcl
  45. Tix.tcl Event.tcl
  46. Balloon.tcl BtnBox.tcl
  47. CObjView.tcl ChkList.tcl
  48. ComboBox.tcl Compat.tcl
  49. Console.tcl Control.tcl
  50. DefSchm.tcl DialogS.tcl
  51. DirBox.tcl DirDlg.tcl
  52. DirList.tcl DirTree.tcl
  53. DragDrop.tcl DtlList.tcl
  54. EFileBox.tcl EFileDlg.tcl
  55. FileBox.tcl FileCbx.tcl
  56. FileDlg.tcl FileEnt.tcl
  57. FloatEnt.tcl
  58. Grid.tcl HList.tcl
  59. HListDD.tcl IconView.tcl
  60. LabEntry.tcl LabFrame.tcl
  61. LabWidg.tcl ListNBk.tcl
  62. Meter.tcl MultView.tcl
  63. NoteBook.tcl OldUtil.tcl
  64. OptMenu.tcl PanedWin.tcl
  65. PopMenu.tcl Primitiv.tcl
  66. ResizeH.tcl SGrid.tcl
  67. SHList.tcl SListBox.tcl
  68. STList.tcl SText.tcl
  69. SWidget.tcl SWindow.tcl
  70. Select.tcl Shell.tcl
  71. SimpDlg.tcl StackWin.tcl
  72. StatBar.tcl StdBBox.tcl
  73. StdShell.tcl TList.tcl
  74. Tree.tcl
  75. Utils.tcl VResize.tcl
  76. VStack.tcl VTree.tcl
  77. Variable.tcl WInfo.tcl
  78. } {
  79. uplevel \#0 [list source [file join $dir $file]]
  80. }
  81. # STEP 3: Initialize the Tix application context
  82. #
  83. tixAppContext tix
  84. # DO NOT DO THIS HERE !!
  85. # This causes the global defaults to be altered, which may not
  86. # be desirable. The user can call this after requiring Tix if
  87. # they wish to use different defaults.
  88. #
  89. #tix initstyle
  90. # STEP 4: Initialize the bindings for widgets that are implemented in C
  91. #
  92. foreach w {
  93. HList TList Grid ComboBox Control FloatEntry
  94. LabelEntry ScrolledGrid ScrolledListBox
  95. } {
  96. tix${w}Bind
  97. }
  98. rename ::tix::Init ""
  99. }
  100. # tixWidgetClassEx --
  101. #
  102. # This procedure is similar to tixWidgetClass, except it
  103. # performs a [subst] on the class declaration before evaluating
  104. # it. This gives us a chance to specify platform-specific widget
  105. # default without using a lot of ugly double quotes.
  106. #
  107. # The use of subst'able entries in the class declaration should
  108. # be restrained to widget default values only to avoid producing
  109. # unreadable code.
  110. #
  111. # Arguments:
  112. # name - The name of the class to declare.
  113. # classDecl - Various declarations about the class. See documentation
  114. # of tixWidgetClass for details.
  115. proc tixWidgetClassEx {name classDecl} {
  116. tixWidgetClass $name [uplevel [list subst $classDecl]]
  117. }
  118. #
  119. # Deprecated tix* functions
  120. #
  121. interp alias {} tixFileJoin {} file join
  122. interp alias {} tixStrEq {} string equal
  123. proc tixTrue {args} { return 1 }
  124. proc tixFalse {args} { return 0 }
  125. proc tixStringSub {var fromStr toStr} {
  126. upvar 1 var var
  127. set var [string map $var [list $fromStr $toStr]]
  128. }
  129. proc tixGetBoolean {args} {
  130. set len [llength [info level 0]]
  131. set nocomplain 0
  132. if {$len == 3} {
  133. if {[lindex $args 0] ne "-nocomplain"} {
  134. return -code error "wrong \# args:\
  135. must be [lindex [info level 0] 0] ?-nocomplain? string"
  136. }
  137. set nocomplain 1
  138. set val [lindex $args 1]
  139. } elseif {$len != 2} {
  140. return -code error "wrong \# args:\
  141. must be [lindex [info level 0] 0] ?-nocomplain? string"
  142. } else {
  143. set val [lindex $args 0]
  144. }
  145. if {[string is boolean -strict $val] || $nocomplain} {
  146. return [string is true -strict $val]
  147. } elseif {$nocomplain} {
  148. return 0
  149. } else {
  150. return -code error "\"$val\" is not a valid boolean"
  151. }
  152. }
  153. interp alias {} tixVerifyBoolean {} tixGetBoolean
  154. proc tixGetInt {args} {
  155. set len [llength [info level 0]]
  156. set nocomplain 0
  157. set trunc 0
  158. for {set i 1} {$i < $len-1} {incr i} {
  159. set arg [lindex $args 0]
  160. if {$arg eq "-nocomplain"} {
  161. set nocomplain 1
  162. } elseif {$arg eq "-trunc"} {
  163. set trunc 1
  164. } else {
  165. return -code error "wrong \# args: must be\
  166. [lindex [info level 0] 0] ?-nocomplain? ?-trunc? string"
  167. }
  168. }
  169. if {$i != $len-1} {
  170. return -code error "wrong \# args: must be\
  171. [lindex [info level 0] 0] ?-nocomplain? ?-trunc? string"
  172. }
  173. set val [lindex $args end]
  174. set code [catch {expr {round($val)}} res]
  175. if {$code} {
  176. if {$nocomplain} {
  177. return 0
  178. } else {
  179. return -code error "\"$val\" cannot be converted to integer"
  180. }
  181. }
  182. if {$trunc} {
  183. return [expr {int($val)}]
  184. } else {
  185. return $res
  186. }
  187. }
  188. proc tixFile {option filename} {
  189. set len [string length $option]
  190. if {$len > 1 && [string equal -length $len $option "tildesubst"]} {
  191. set code [catch {file normalize $filename} res]
  192. if {$code == 0} {
  193. set filename $res
  194. }
  195. } elseif {$len > 1 && [string equal -length $len $option "trimslash"]} {
  196. # normalize extra slashes
  197. set filename [file join $filename]
  198. if {$filename ne "/"} {
  199. set filename [string trimright $filename "/"]
  200. }
  201. } else {
  202. return -code error "unknown option \"$option\",\
  203. must be tildesubst or trimslash"
  204. }
  205. return $filename
  206. }
  207. interp alias {} tixRaiseWindow {} raise
  208. #proc tixUnmapWindow {w} { }
  209. #
  210. # if tix_library is not defined, we're running in SAM mode. ::tix::Init
  211. # will be called later by the Tix_Init() C code.
  212. #
  213. if {[info exists tix_library]} {
  214. ::tix::Init [file dirname [info script]]
  215. }