home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / tcl / xf2.3-p / xf2 / xf2.3 / src / xfmisc.tcl < prev    next >
Encoding:
Text File  |  1994-01-18  |  54.8 KB  |  1,979 lines

  1. # Program: xf
  2. # Description: misc routines
  3. #
  4. # $Header: xfmisc.tcl[2.7] Wed Mar 10 12:07:02 1993 garfield@garfield frozen $
  5.  
  6. ##########
  7. # Procedure: XFIncludeModule
  8. # Description: Module load procedure
  9. # Arguments: moduleName - the module to load
  10. # Returns: none
  11. # Sideeffects: Tcl code is read
  12. ##########
  13. proc XFIncludeModule {{moduleName ""}} {
  14.   global env
  15.   global xfLoadInfo
  16.   global xfLoadPath
  17.   global xfStatus
  18.  
  19.   foreach p [split $xfLoadPath :] {
  20.     if {[file exists "$p/$moduleName"]} {
  21.       if {![file readable "$p/$moduleName"]} {
  22.         puts stderr "Cannot read $p/$moduleName (permission denied)"
  23.         continue
  24.       }
  25.       if {$xfLoadInfo} {
  26.         puts stdout "Loading $p/$moduleName..."
  27.       }
  28.       source "$p/$moduleName"
  29.       return 1
  30.     }
  31.     # first see if we have a load command
  32.     if {[info exists env(XF_VERSION_SHOW)]} {
  33.       set xfCommand $env(XF_VERSION_SHOW)
  34.       regsub -all {\$xfFileName} $xfCommand $p/$moduleName xfCommand
  35.       if {$xfLoadInfo} {
  36.         puts stdout "Loading $p/$moduleName...($xfCommand)"
  37.       }
  38.       if {[catch "exec $xfCommand" contents]} {
  39.         continue
  40.       } {
  41.         eval $contents
  42.         return 1
  43.       }
  44.     }
  45.     # are we able to load versions from wish ?
  46.     if {[catch "afbind $p/$moduleName" aso]} {
  47.       # try to use xf version load command
  48.       global xfVersion
  49.       if {[info exists xfVersion(showDefault)]} {
  50.         set xfCommand $xfVersion(showDefault)
  51.       } {
  52.     # our last hope
  53.         set xfCommand "vcat -q $p/$moduleName"
  54.       }
  55.       regsub -all {\$xfFileName} $xfCommand $p/$moduleName xfCommand
  56.       if {$xfLoadInfo} {
  57.         puts stdout "Loading $p/$moduleName...($xfCommand)"
  58.       }
  59.       if {[catch "exec $xfCommand" contents]} {
  60.         continue
  61.       } {
  62.         eval $contents
  63.         return 1
  64.       }
  65.     } {
  66.       # yes we can load versions directly
  67.       if {[catch "$aso open r" inFile]} {
  68.         puts stderr "Cannot open $p/[$aso attr af_bound] (permission denied)"
  69.         continue
  70.       }
  71.       if {$xfLoadInfo} {
  72.         puts stdout "Loading $p/[$aso attr af_bound]..."
  73.       }
  74.       if {[catch "read \{$inFile\}" contents]} {
  75.         puts stderr "Cannot read $p/[$aso attr af_bound] (permission denied)"
  76.         close $inFile
  77.         continue
  78.       }
  79.       close $inFile
  80.       eval $contents
  81.       return 1
  82.     }
  83.   }
  84.   puts stderr "Cannot load module $moduleName -- check your xf load path"
  85.   puts stderr "Specify a xf load path with the environment variable:"
  86.   puts stderr "  XF_LOAD_PATH (e.g \"export XF_LOAD_PATH=.\")"
  87.   catch "destroy ."
  88.   catch "exit 0"
  89. }
  90.  
  91. ##########
  92. # Procedure: XFMiscAutoSave
  93. # Description: Auto save
  94. # Arguments: xfPassedInterval - the interval when this after
  95. #                               call was activated
  96. # Returns: none
  97. # Sideeffects: none
  98. ##########
  99. proc XFMiscAutoSave {xfPassedInterval} {
  100.   global xfConf
  101.   global xfPath
  102.   global xfStatus
  103.  
  104.   # save interval was changed
  105.   if {$xfConf(saveInterval) != $xfPassedInterval} {
  106.     return
  107.   }
  108.   if {$xfConf(saveInterval) > 0} {
  109.     if {$xfConf(maxSaveId) < 1} {
  110.       XFEditSetStatus "Saving recommended..."
  111.       return
  112.     }
  113.     if {$xfStatus(saveId) >= $xfConf(maxSaveId)} {
  114.       set xfStatus(saveId) 0
  115.     }
  116.  
  117.     update idletask
  118.     toplevel .xfAutoSaving
  119.     wm title .xfAutoSaving "Auto saving XF..."
  120.     label .xfAutoSaving.mess1 \
  121.       -anchor c \
  122.       -background $xfConf(flash) \
  123.       -font $xfConf(fontMessage) \
  124.       -text "Auto saving to: $xfPath(tmp)/as$xfStatus(uniqueId)$xfStatus(saveId)..."
  125.     pack append .xfAutoSaving .xfAutoSaving.mess1 {top fill expand}
  126.     update idletask
  127.  
  128.     XFEditSetStatus "Auto saving to: $xfPath(tmp)/as$xfStatus(uniqueId)$xfStatus(saveId)..."
  129.     catch "XFSave $xfPath(tmp)/as$xfStatus(uniqueId)$xfStatus(saveId)"
  130.     XFEditSetStatus "Auto saving to: $xfPath(tmp)/as$xfStatus(uniqueId)$xfStatus(saveId)...done"
  131.     destroy .xfAutoSaving
  132.  
  133.     incr xfStatus(saveId) 1
  134.     after [expr $xfConf(saveInterval)*60000] XFMiscAutoSave $xfConf(saveInterval)
  135.   }
  136. }
  137.  
  138. ##########
  139. # Procedure: XFMiscBind
  140. # Description: bind global acceletators to widget
  141. # Arguments: xfW - the widget
  142. #            args - the help page for this widget
  143. # Returns: none
  144. # Sideeffects: none
  145. ##########
  146. proc XFMiscBind {xfW args} {
  147.   global xfBind
  148.  
  149.   if {("[info commands $xfW]" == "" && "$xfW" != ".")  ||
  150.       [string match ".xf*" $xfW] ||
  151.       ([string match "xf*" [winfo name $xfW]] && "$xfW" != ".")} {
  152.     return
  153.   }
  154.  
  155.   # settings for the workspace
  156.   if {[catch "bind $xfW $xfBind(select) \"# xf ignore me 9
  157. XFEditSetPath %W\"" xfResult]} {
  158.     puts stderr "$xfResult"
  159.   }
  160.   if {[catch "bind $xfW $xfBind(showName) \"# xf ignore me 9
  161. XFBindShowName %W %x %y\"" xfResult]} {
  162.     puts stderr "$xfResult"
  163.   }
  164.   if {[catch "bind $xfW $xfBind(removeName) \"# xf ignore me 9
  165. XFBindRemoveName\"" xfResult]} {
  166.     puts stderr "$xfResult"
  167.   }
  168.   if {[catch "bind $xfW $xfBind(configure) \"# xf ignore me 9
  169. XFProcConfParametersDefault %W\"" xfResult]} {
  170.     puts stderr "$xfResult"
  171.   }
  172.   if {[catch "bind $xfW $xfBind(placing) \"# xf ignore me 9
  173. XFLayoutPosPress %W %X %Y %x %y\"" xfResult]} {
  174.     puts stderr "$xfResult"
  175.   }
  176.   if {[catch "bind $xfW $xfBind(placingMotion) \"# xf ignore me 9
  177. XFLayoutPosMove %W %X %Y %x %y\"" xfResult]} {
  178.     puts stderr "$xfResult"
  179.   }
  180.   if {[catch "bind $xfW $xfBind(placingRelease) \"# xf ignore me 9
  181. XFLayoutPosRelease %W %X %Y %x %y\"" xfResult]} {
  182.     puts stderr "$xfResult"
  183.   }
  184. }
  185.  
  186. ##########
  187. # Procedure: XFMiscBindWidgetTree
  188. # Description: set the bindings for all widgets in the specified
  189. #              tree to the default values
  190. # Arguments: xfW - the current widget
  191. #            args - the help page for this widget
  192. # Returns: none
  193. # Sideeffects: none
  194. ##########
  195. proc XFMiscBindWidgetTree {xfW args} {
  196.   global xfNoSpecialBind
  197.   global xfPath
  198.  
  199.   if {"[info commands $xfW]" == "" && "$xfW" != "."} {
  200.     return
  201.   }
  202.   XFMiscBind $xfW $args
  203.   set xfClass [winfo class $xfW]
  204.   if {[lsearch $xfNoSpecialBind $xfClass] != -1} {
  205.     if {"[info procs XFAdd.$xfClass]" == ""} {
  206.       if {[file exists "$xfPath(elements)/$xfClass"]} {
  207.         source "$xfPath(elements)/$xfClass"
  208.       } {
  209.         foreach xfPathElement [split $xfPath(additionals) :] {
  210.           if {[XFMiscIsDir $xfPathElement]} {
  211.             if {[file exists "$xfPathElement/$xfClass"]} {
  212.               source "$xfPathElement/$xfClass"
  213.               break
  214.             }
  215.           }
  216.         }
  217.       }
  218.     }
  219.   }
  220.   if {"[info proc XFBind.$xfClass]" != ""} {
  221.     XFBind.$xfClass $xfW
  222.   }
  223.   foreach xfCounter [winfo children $xfW] {
  224.     XFMiscBindWidgetTree $xfCounter $args
  225.   }
  226. }
  227.  
  228. ##########
  229. # Procedure: XFMiscCallExternalEditor
  230. # Description: call external editor in background
  231. # Arguments: xfType - the type of procedure editing
  232. #            {xfProcName} - the procedure we edit
  233. # Returns: none
  234. # Sideeffects: none
  235. ##########
  236. proc XFMiscCallExternalEditor {xfType {xfProcName ""}} {
  237.   global xfPath
  238.   global xfStatus
  239.  
  240.   if {"$xfType" == "StartupSrc"} {
  241.     set xfEditFile $xfPath(tmp)/start$xfStatus(editors)$xfStatus(uniqueId).tcl
  242.     set xfShortName starts$xfStatus(editors).tcl
  243.   } {
  244.     if {"$xfType" == "EndSrc"} {
  245.       set xfEditFile $xfPath(tmp)/end$xfStatus(editors)$xfStatus(uniqueId).tcl
  246.       set xfShortName ends$xfStatus(editors).tcl
  247.     } {
  248.       if {"$xfType" == "cmds"} {
  249.         set xfEditFile $xfPath(tmp)/cmds$xfStatus(editors)$xfStatus(uniqueId).tcl
  250.         set xfShortName cmdss$xfStatus(editors).tcl
  251.       } {
  252.         set xfEditFile $xfPath(tmp)/$xfType$xfStatus(editors)$xfStatus(uniqueId).tcl
  253.         set xfShortName ${xfType}s$xfStatus(editors).tcl
  254.       }
  255.     }
  256.   }
  257.  
  258.   incr xfStatus(editors) 1
  259.   if {[catch "open $xfEditFile w" xfOutFile]} {
  260.     XFProcError "$xfOutFile"
  261.   } {
  262.     set xfArguments ""
  263.     set xfBodyList ""
  264.     if {"$xfProcName" != "" &&
  265.         "[info proc $xfProcName]" != ""} {
  266.       set xfBodyList [string trimright [info body $xfProcName]]
  267.       set xfArgList [info args $xfProcName]
  268.       foreach xfCounter $xfArgList {
  269.         if {[info default $xfProcName $xfCounter xfDefault]} {
  270.           set xfArguments "$xfArguments \{$xfCounter \"$xfDefault\"\}"
  271.         } {
  272.           set xfArguments "$xfArguments $xfCounter"
  273.         }
  274.       }
  275.     }
  276.     puts $xfOutFile "proc $xfProcName \{$xfArguments\} \{"
  277.     if {[string index $xfBodyList 0] == "\n"} {
  278.       puts $xfOutFile "[string range $xfBodyList 1 end]"
  279.     } {
  280.       puts $xfOutFile "$xfBodyList"
  281.     }
  282.     puts $xfOutFile "\}"
  283.     close $xfOutFile
  284.  
  285.    # call external editor
  286.    XFMiscCallExternalEditor1 $xfEditFile $xfShortName $xfType $xfProcName
  287.   }
  288. }
  289.  
  290. ##########
  291. # Procedure: XFMiscCallExternalEditor1
  292. # Description: call external editor in background
  293. # Arguments: xfFileName - the filename to edit
  294. #            xfShortName - the short file name
  295. #            xfType - the type of edit procedure that called this proc
  296. #            {xfProcName} - the procedure we edit
  297. # Returns: none
  298. # Sideeffects: none
  299. ##########
  300. proc XFMiscCallExternalEditor1 {xfFileName xfShortName xfType {xfProcName ""}} {
  301.   global xfEditing
  302.  
  303.   set xfAskUser 0
  304.   if {"$xfProcName" != ""} {
  305.     foreach xfCounter [array names xfEditing] {
  306.       if {"$xfEditing($xfCounter)" == "$xfProcName"} {
  307.         set xfAskUser 1
  308.         if {[XFProcYesNo "You are already editing the procedure:\n$xfProcName\nStill call the editor ?"]} {
  309.           XFMiscCallExternalEditor2 $xfFileName $xfShortName \
  310.             $xfType $xfProcName
  311.           return
  312.         }
  313.       }
  314.     }
  315.     set xfEditing($xfProcName) $xfProcName
  316.   }
  317.   if {!$xfAskUser} {
  318.     XFMiscCallExternalEditor2 $xfFileName $xfShortName $xfType $xfProcName
  319.   }
  320. }
  321.  
  322. ##########
  323. # Procedure: XFMiscCallExternalEditor2
  324. # Description: actually call external editor in background
  325. # Arguments: xfFileName - the filename to edit
  326. #            xfShortName - the short file name
  327. #            xfType - the type of edit procedure that called this proc
  328. #            {xfProcName} - the procedure we edit
  329. # Returns: none
  330. # Sideeffects: none
  331. ##########
  332. proc XFMiscCallExternalEditor2 {xfFileName xfShortName xfType {xfProcName ""}} {
  333.   global xfConf
  334.   global xfPath
  335.   global xfStatus
  336.  
  337.   set xfTmpEditorCmd $xfConf(externalEditor)
  338.   regsub -all {\$xfFileName} $xfConf(externalEditor) $xfFileName xfTmpEditorCmd
  339.   if {[catch "open $xfPath(tmp)/$xfShortName$xfStatus(uniqueId) w" xfOutFile]} {
  340.     XFProcError "$xfOutFile"
  341.   } {
  342.     puts $xfOutFile "wm withdraw ."
  343.     puts $xfOutFile "while {1} {"
  344.     if {"$xfConf(externalEditor)" == "point"} {
  345.       puts $xfOutFile "  if {\[catch \"send point OpenWindow $xfFileName\"\]} {"
  346.       puts $xfOutFile "    catch \"exec true; exec $xfTmpEditorCmd\""
  347.       puts $xfOutFile "  }"
  348.     } {
  349.       puts $xfOutFile "  catch \"exec true; exec $xfTmpEditorCmd\""
  350.     }
  351.     puts $xfOutFile "  if {\[catch \"send \\\"[winfo name .]\\\" winfo name .\" xfResult\]} {"
  352.     puts $xfOutFile "    puts stderr \"XF was aborted during edit session.\""
  353.     puts $xfOutFile "    puts stderr \"I got: \$xfResult\""
  354.     puts $xfOutFile "    if {\$tkVersion < 3.3} {"
  355.     puts $xfOutFile "      catch \"destroy .\""
  356.     puts $xfOutFile "    }"
  357.     puts $xfOutFile "    catch \"exit 0\""
  358.     puts $xfOutFile "  }"
  359.     puts $xfOutFile "  if {\[file exists $xfFileName\] &&"
  360.     puts $xfOutFile "      \[file size $xfFileName\] > 1} {"
  361.     if {"$xfType" == "cmplt"} {
  362.       puts $xfOutFile "    catch \"send \\\"[winfo name .]\\\" XFMiscClearInterpreter\""
  363.     }
  364.     puts $xfOutFile "    if {\[catch \"send \\\"[winfo name .]\\\" source $xfFileName\" xfResult\]} {"
  365.     puts $xfOutFile "      puts stderr \"Error when loading $xfFileName\\nI got:\$xfResult\""
  366.     puts $xfOutFile "      continue"
  367.     puts $xfOutFile "    }"
  368.     if {"$xfType" == "procs"} {
  369.       puts $xfOutFile "    catch \"send \\\"[winfo name .]\\\" XFMiscSetInfo procs .xfInfoProc.procs.procs 0\""
  370.     }
  371.     if {"$xfType" == "cmds"} {
  372.       puts $xfOutFile "    catch \"send \\\"[winfo name .]\\\" XFMiscSetInfo commands .xfInfoCmd.commands.commands 0\""
  373.     }
  374.     if {"$xfType" == "cmplt"} {
  375.       puts $xfOutFile "    catch \"send \\\"[winfo name .]\\\" XFMiscBindWidgetTree .\""
  376.       puts $xfOutFile "    catch \"send \\\"[winfo name .]\\\" XFEditSetShowWindows\""
  377.       puts $xfOutFile "    catch \"send \\\"[winfo name .]\\\" XFEditSetPath .\""
  378.     }
  379.     puts $xfOutFile "  }"
  380.     puts $xfOutFile "  catch \"exec rm $xfFileName\""
  381.     puts $xfOutFile "  catch \"exec rm $xfFileName~\""
  382.     puts $xfOutFile "  catch \"exec rm $xfPath(tmp)/$xfShortName$xfStatus(uniqueId)\""
  383.     puts $xfOutFile "  catch \"exec rm $xfPath(tmp)/$xfShortName$xfStatus(uniqueId)~\""
  384.     puts $xfOutFile "  catch \"send \\\"[winfo name .]\\\" \\\"global xfEditing;" nonewline
  385.     puts $xfOutFile "  unset \\\{xfEditing($xfProcName)\\\}\\\"\""
  386.     puts $xfOutFile "  if {\$tkVersion < 3.3} {"
  387.     puts $xfOutFile "    catch \"destroy .\""
  388.     puts $xfOutFile "  }"
  389.     puts $xfOutFile "  catch \"exit 0\""
  390.     puts $xfOutFile "}"
  391.     close $xfOutFile
  392.  
  393.     catch "exec true; exec $xfConf(interpreterEdit) -geometry 4000x4000 -name edit$xfShortName -file $xfPath(tmp)/$xfShortName$xfStatus(uniqueId) &"
  394.   }
  395. }
  396.  
  397. ##########
  398. # Procedure: XFMiscClearInterpreter
  399. # Description: remove all procedures and windows
  400. # Arguments: none
  401. # Returns: none
  402. # Sideeffects: none
  403. ##########
  404. proc XFMiscClearInterpreter {} {
  405.   global internalAliasList
  406.   global autoLoadList
  407.   global moduleList
  408.   global symbolicName
  409.   global xfConf
  410.   global xfEditing
  411.   global xfStatus
  412.  
  413.   foreach xfCounter [info procs ShowWindow.*] {
  414.     rename $xfCounter {}
  415.   }
  416.   foreach xfCounter [info procs DetroyWindow.*] {
  417.     rename $xfCounter {}
  418.   }
  419.   foreach xfCounter [info globals xfShowWindow.*] {
  420.     global $xfCounter
  421.     unset $xfCounter
  422.   }
  423.   foreach xfCounter [info procs *] {
  424.     if {![XFMiscIsXFElement $xfCounter] &&
  425.         ![XFMiscIsXFSpecialElement $xfCounter]} {
  426.       rename $xfCounter {}
  427.     }
  428.   }
  429.   foreach xfCounter [info globals *] {
  430.     if {![XFMiscIsXFElement $xfCounter]} {
  431.       global $xfCounter
  432.       unset $xfCounter
  433.     }
  434.   }
  435.  
  436.   # initialize variables
  437.   foreach xfName [array names moduleList] {
  438.     unset moduleList($xfName)
  439.   }
  440.   foreach xfName [array names autoLoadList] {
  441.     unset autoLoadList($xfName)
  442.   }
  443.   foreach xfName [array names symbolicName] {
  444.     unset symbolicName($xfName)
  445.   }
  446.   set moduleList(main.tcl) ""
  447.   set autoLoadList(main.tcl) 0
  448.   set symbolicName(root) .
  449.   set internalAliasList ""
  450.   set xfConf(programName) "main.tcl"
  451.   set xfConf(programNameOld) "main.tcl"
  452.   set xfEditing(xfInternal) "xfInternal"
  453.   set xfStatus(elementCounter) 0
  454.   set xfStatus(path) .
  455.   set xfStatus(pasteScriptDisplayed) 0
  456.   set xfStatus(pasteTreeDisplayed) 0
  457.  
  458.   # delete subwindows
  459.   foreach xfCounter [winfo children .] {
  460.     if {"$xfCounter" != ".xfEdit" &&
  461.         "$xfCounter" != ".xfYesNo"} {
  462.       catch "XFDestroy $xfCounter"
  463.     }
  464.   }
  465.   wm title . xf
  466.  
  467.   XFEditSetShowWindows
  468.   XFEditSetPath .
  469.   update
  470. }
  471.  
  472. ##########
  473. # Procedure: XFMiscClearList
  474. # Description: clear listbox widget
  475. # Arguments: xfW - the widget
  476. # Returns: none
  477. # Sideeffects: none
  478. ##########
  479. proc XFMiscClearList {xfW} {
  480.  
  481.   if {[$xfW size] > 0} {
  482.     $xfW delete 0 end
  483.   }
  484. }
  485.  
  486. ##########
  487. # Procedure: XFMiscClearText
  488. # Description: clear text widget
  489. # Arguments: xfW - the widget
  490. # Returns: none
  491. # Sideeffects: none
  492. ##########
  493. proc XFMiscClearText {xfW} {
  494.  
  495.   set xfStatus [lindex [$textWidget config -state] 4]
  496.   $textWidget config -state normal
  497.   $textWidget delete 1.0 end
  498.   $textWidget config -state $xfStatus
  499. }
  500.  
  501. ##########
  502. # Procedure: XFMiscCorrectLevel
  503. # Description: check if given string contains a level indicator
  504. #              and this level indicator allows displaying/saving
  505. # Arguments: xfType - the type of string we check (bind or proc)
  506. #            xfString - the string to check
  507. # Returns: 1 if string is allowd for displaying/saving, 0 otherwise
  508. # Sideeffects: none
  509. ##########
  510. proc XFMiscCorrectLevel {xfType xfString} {
  511.   global xfBindSaveLevel
  512.   global xfBindShowLevel
  513.   global xfProcSaveLevel
  514.   global xfProcShowLevel
  515.  
  516.   set xfTmpString [string trimleft $xfString]
  517.   if {[string match "# xf ignore me 9*" $xfTmpString]} {
  518.     return 0
  519.   }
  520.   if {[string match "# xf ignore me*" $xfTmpString]} {
  521.     set xfLevel [string index $xfTmpString 15]
  522.     if {"$xfType" == "bindsave"} {
  523.       return $xfBindSaveLevel($xfLevel)
  524.     } {
  525.       if {"$xfType" == "bindshow"} {
  526.         return $xfBindShowLevel($xfLevel)
  527.       } {
  528.         if {"$xfType" == "procsave"} {
  529.           return $xfProcSaveLevel($xfLevel)
  530.         } {
  531.           return $xfProcShowLevel($xfLevel)
  532.         }
  533.       }
  534.     }
  535.   }
  536.   return 1
  537. }
  538.  
  539. ##########
  540. # Procedure: XFMiscDeleteMenuChilds
  541. # Description: delete all children of the given menu
  542. # Arguments: xfW - the menu widget
  543. # Returns: none
  544. # Sideeffects: none
  545. ##########
  546. proc XFMiscDeleteMenuChilds {xfW} {
  547.   global tkVersion
  548.  
  549.   if {$tkVersion >= 3.0} {
  550.     $xfW delete 0 last
  551.   } {
  552.     set xfTmpLast [$xfW index last]
  553.     if {"$xfTmpLast" == "none"} {
  554.       set xfTmpLast -1
  555.     }
  556.     while {$xfTmpLast >= 0} {
  557.       $xfW delete 0
  558.       incr xfTmpLast -1
  559.     }
  560.   }
  561. }
  562.  
  563. ##########
  564. # Procedure: XFMiscExpandRegexp
  565. # Description: expand characters with special meaning
  566. # Arguments: xfExpression - the string
  567. # Returns: string - the expanded regular expression
  568. # Sideeffects: none
  569. ##########
  570. proc XFMiscExpandRegexp {xfExpression} {
  571.  
  572.   # replace period
  573.   set xfPosition 0
  574.   set xfResult ""
  575.   while {$xfPosition < [string length $xfExpression]} {
  576.     set xfCurrent [string index $xfExpression $xfPosition]
  577.     if {[string match $xfCurrent "."] &&
  578.         ![string match $xfCurrent "\*"]} {
  579.       append xfResult "\\$xfCurrent"
  580.     } {
  581.       append xfResult $xfCurrent
  582.     }
  583.     incr xfPosition 1
  584.   }
  585.   return $xfResult
  586. }
  587.  
  588. ##########
  589. # Procedure: XFMiscFlash
  590. # Description: flash the widget
  591. # Arguments: xfW - the widget
  592. # Returns: none
  593. # Sideeffects: none
  594. ##########
  595. proc XFMiscFlash {xfW} {
  596.   global xfConf
  597.  
  598.   if {"[info commands $xfW]" == ""} {
  599.     return
  600.   }
  601.   if {"$xfW" != "."} {
  602.     if {"[winfo class $xfW]" == "Frame"} {
  603.       if {"[lindex [$xfW config -geometry] 4]" == "30x30" &&
  604.           "[pack info $xfW]" != ""} {
  605.         $xfW config -geometry ""
  606.       }
  607.     }
  608.     set xfSaveBackColor [lindex [$xfW configure -background] 4]
  609.     catch "$xfW configure -background $xfConf(flash)"
  610.     update
  611.     catch "$xfW configure -background \"$xfSaveBackColor\""
  612.     update
  613.     catch "$xfW configure -background $xfConf(flash)"
  614.     update
  615.     catch "$xfW configure -background \"$xfSaveBackColor\""
  616.     update
  617.   }
  618. }
  619.  
  620. ##########
  621. # Procedure: XFMiscGetUniqueName
  622. # Description: create a unique name for a newly inserted widget
  623. # Arguments: xfName - the element name
  624. #            xfType - the type we want to create
  625. #            {xfW} - the parent widget
  626. # Returns: the created unique name
  627. # Sideeffects: none
  628. ##########
  629. proc XFMiscGetUniqueName {xfName xfType {xfW ""}} {
  630.   global xfConf
  631.   global xfInputBox
  632.   global xfStatus
  633.  
  634.   if {"$xfW" == ""} {
  635.     set xfW $xfStatus(path)
  636.   }
  637.   if {"$xfName" == ""} {
  638.     set xfName $xfType$xfStatus(elementCounter)
  639.   }
  640.   if {$xfConf(getWidgetName)} {
  641.     set xfTextBox(.xfWidgetName,inputOne) $xfName
  642.   }
  643.   if {"$xfW" == "."} {
  644.     set xfRepeat 1
  645.     while {$xfRepeat} {
  646.       set xfRepeat 0
  647.       if {$xfConf(getWidgetName)} {
  648.         auto_load XFInputBoxOne
  649.         set xfInputBox(toplevelName) ".xfWidgetName"
  650.         set xfInputBox(erase) 0
  651.         set xfInputBox(.xfWidgetName,inputOne) $xfName
  652.         set xfName [string trim [XFProcInputBoxOne "Enter widget name:" 400x100 "XF widget name"]]
  653.         set xfInputBox(toplevelName) ".xfTextBox"
  654.         if {"$xfName" == ""} {
  655.           error ""
  656.         }
  657.       }
  658.       foreach xfCounter [winfo children .] {
  659.         if {".$xfName" == "$xfCounter"} {
  660.           set xfRepeat 1
  661.           if {!$xfConf(getWidgetName)} {
  662.             set xfName $xfType$xfStatus(elementCounter)
  663.             incr xfStatus(elementCounter)
  664.           }
  665.         }
  666.       }
  667.       foreach xfCounter [info commands ShowWindow.*] {
  668.         if {".$xfName" == "[string range $xfCounter 10 end]"} {
  669.           set xfRepeat 1
  670.           if {!$xfConf(getWidgetName)} {
  671.             set xfName $xfType$xfStatus(elementCounter)
  672.             incr xfStatus(elementCounter)
  673.           }
  674.         }
  675.       }
  676.     }
  677.   } {
  678.     set xfRepeat 1
  679.     while {$xfRepeat} {
  680.       set xfRepeat 0
  681.       if {$xfConf(getWidgetName)} {
  682.         auto_load XFInputBoxOne
  683.         set xfInputBox(toplevelName) ".xfWidgetName"
  684.         set xfInputBox(erase) 0
  685.         set xfInputBox(.xfWidgetName,inputOne) $xfName
  686.         set xfName [string trim [XFProcInputBoxOne "Enter widget name:" 400x100 "XF widget name"]]
  687.         set xfInputBox(toplevelName) ".xfTextBox"
  688.         if {"$xfName" == ""} {
  689.           error ""
  690.         }
  691.       }
  692.       foreach xfCounter [winfo children $xfW] {
  693.         if {"$xfW.$xfName" == "$xfCounter"} {
  694.           set xfRepeat 1
  695.           if {!$xfConf(getWidgetName)} {
  696.             set xfName $xfType$xfStatus(elementCounter)
  697.             incr xfStatus(elementCounter)
  698.           }
  699.         }
  700.       }
  701.       foreach xfCounter [info commands ShowWindow.*] {
  702.         if {"$xfW.$xfName" == "[string range $xfCounter 10 end]"} {
  703.           set xfRepeat 1
  704.           if {!$xfConf(getWidgetName)} {
  705.             set xfName $xfType$xfStatus(elementCounter)
  706.             incr xfStatus(elementCounter)
  707.           }
  708.         }
  709.       }
  710.     }
  711.   }
  712.   return $xfName
  713. }
  714.  
  715. ##########
  716. # Procedure: XFMiscGetText
  717. # Description: get current contents of text widget
  718. # Arguments: xfW - the text widget
  719. # Returns: the entered text in the text widget
  720. # Sideeffects: none
  721. ##########
  722. proc XFMiscGetText {xfW} {
  723.  
  724.   if {"[winfo class $xfW]" == "Text"} {
  725.     return [$xfW get 1.0 end]
  726.   } {
  727.     if {"[winfo class $xfW]" == "TkEmacs" ||
  728.         "[winfo class $xfW]" == "Entry"} {
  729.       return [$xfW get]
  730.     }
  731.   }
  732. }
  733.  
  734. ##########
  735. # Procedure: XFMiscHandleHiding
  736. # Description: handle hiding of procedures
  737. # Arguments: xfType - the procedure type we handle
  738. #            xfW - the list widget to update
  739. #            xfName - the procedure ti hide/unhide
  740. # Returns: none
  741. # Sideeffects: none
  742. ##########
  743. proc XFMiscHandleHiding {xfType xfW xfName} {
  744.   global xfStatus
  745.   global hiddenProcs
  746.   global hiddenBodys
  747.  
  748.   if {$xfStatus(hiddenProcs)} {
  749.     if {[info exists hiddenProcs($xfName)]} {
  750.       catch "proc $xfName $hiddenBodys($xfName)" res
  751.       unset hiddenProcs($xfName)
  752.       unset hiddenBodys($xfName)
  753.       XFMiscSetInfo hidden$xfType $xfW 1
  754.     }
  755.   } {
  756.     if {"[info procs $xfName]" != ""} {
  757.       set xfArguments ""
  758.       set xfBodyList ""
  759.       set xfBodyList [string trimright [info body $xfName]]
  760.       set xfArgList [info args $xfName]
  761.       foreach xfCounter $xfArgList {
  762.         if {[info default $xfName $xfCounter xfDefault]} {
  763.           append xfArguments " \{$xfCounter \"$xfDefault\"\}"
  764.         } {
  765.           append xfArguments " $xfCounter"
  766.         }
  767.       }
  768.       set hiddenProcs($xfName) ""
  769.       if {[string index $xfBodyList 0] == "\n"} {
  770.         set hiddenBodys($xfName) " {$xfArguments} {[string range $xfBodyList 1 end]}"
  771.       } {
  772.         set hiddenBodys($xfName) " {$xfArguments} {$xfBodyList}"
  773.       }
  774.       rename $xfName {}
  775.       XFMiscSetInfo $xfType $xfW 1
  776.     }
  777.   }
  778. }
  779.  
  780. ##########
  781. # Procedure: XFMiscInitElement
  782. # Description: set the default parameters of a element
  783. # Arguments: xfW - the root widget
  784. # Arguments: xfName - the element name
  785. # Returns: none
  786. # Sideeffects: none
  787. ##########
  788. proc XFMiscInitElement {xfW xfName} {
  789.   global xfStatus
  790.  
  791.   XFMiscSetResource $xfW.params1.params2.$xfName.label$xfName width \
  792.     $xfStatus(elementWidth)
  793.   XFMiscSetResource $xfW.params1.params2.$xfName.label$xfName anchor e
  794.   XFMiscSetResource $xfW.params1.params2.$xfName.label$xfName relief flat
  795.   XFMiscSetResource $xfW.params1.params2.$xfName.$xfName relief sunken
  796. }
  797.  
  798. ##########
  799. # Procedure: XFMiscInsertText
  800. # Description: insert text into contents of text widget
  801. # Arguments: xfW - the text widget
  802. #            xfContents - the text to insert
  803. # Returns: none
  804. # Sideeffects: none
  805. ##########
  806. proc XFMiscInsertText {xfW {xfContents ""}} {
  807.  
  808.   if {"[winfo class $xfW]" == "Text" ||
  809.       "[winfo class $xfW]" == "TkEmacs" ||
  810.       "[winfo class $xfW]" == "Entry"} {
  811.     set xfOldStatus [lindex [$xfW config -state] 4]
  812.     $xfW config -state normal
  813.     $xfW insert insert $xfContents
  814.     $xfW config -state $xfOldStatus
  815.   }
  816. }
  817.  
  818. ##########
  819. # Procedure: XFMiscInsertTextIntoWidget
  820. # Description: insert text into a specified widget
  821. # Arguments: xfW - the widget
  822. #            xfText - the text
  823. # Returns: none
  824. # Sideeffects: none
  825. ##########
  826. proc XFMiscInsertTextIntoWidget {xfW xfText} {
  827.   global tkVersion
  828.   
  829.   if {$tkVersion >= 3.0} {
  830.     if {[winfo exists $xfW]} {
  831.       XFMiscInsertText $xfW $xfText
  832.     }
  833.   } {
  834.     if {"[info commands $xfW]" != ""} {
  835.       XFMiscInsertText $xfW $xfText
  836.     }
  837.   }
  838. }
  839.  
  840. ##########
  841. # Procedure: XFMiscInModule
  842. # Description: check if element is in module
  843. # Arguments: xfName - the name of the module item
  844. # Returns: 0 - module is not in module list
  845. #          1 - module is in module list
  846. # Sideeffects: none
  847. ##########
  848. proc XFMiscInModule {xfName} {
  849.   global moduleList
  850.   global xfConf
  851.  
  852.   XFMiscUpdateModuleList
  853.   foreach xfModName [array names moduleList] {
  854.     foreach xfCounter [set moduleList($xfModName)] {
  855.       if {[lsearch [set moduleList($xfModName)] $xfName] >= 0} {
  856.         if {"$xfModName" == "$xfConf(programName)"} {
  857.           return 0
  858.         } {
  859.           return 1
  860.         }
  861.       }
  862.     }
  863.   }
  864.   return 0
  865. }
  866.  
  867. ##########
  868. # Procedure: XFMiscIsDir
  869. # Description: check if path is a directory
  870. # Arguments: xfPathName - the path to check
  871. # Returns: 1 if its a directory, otherwise 0
  872. # Sideeffects: none
  873. ##########
  874. proc XFMiscIsDir {xfPathName} {
  875.  
  876.   if {[file isdirectory $xfPathName]} {
  877.     return 1
  878.   } {
  879.     catch "file type $xfPathName" xfType
  880.     if {"$xfType" == "link"} {
  881.       if {[catch "file readlink $xfPathName" xfLinkName]} {
  882.         return 0
  883.       }
  884.       catch "file type $xfLinkName" xfType
  885.       while {"$xfType" == "link"} {
  886.         if {[catch "file readlink $xfLinkName" xfLinkName]} {
  887.           return 0
  888.         }
  889.         catch "file type $xfLinkName" xfType
  890.       }
  891.       return [file isdirectory $xfLinkName]
  892.     }
  893.   }
  894.   return 0
  895. }
  896.  
  897. ##########
  898. # Procedure: XFMiscIsFile
  899. # Description: check if filename is a file
  900. # Arguments: xfFileName - the path to check
  901. # Returns: 1 if its a file, otherwise 0
  902. # Sideeffects: none
  903. ##########
  904. proc XFMiscIsFile {xfFileName} {
  905.  
  906.   if {[file isfile $xfFileName]} {
  907.     return 1
  908.   } {
  909.     catch "file type $xfFileName" xfType
  910.     if {"$xfType" == "link"} {
  911.       if {[catch "file readlink $xfFileName" xfLinkName]} {
  912.         return 0
  913.       }
  914.       catch "file type $xfLinkName" xfType
  915.       while {"$xfType" == "link"} {
  916.         if {[catch "file readlink $xfLinkName" xfLinkName]} {
  917.           return 0
  918.         }
  919.         catch "file type $xfLinkName" xfType
  920.       }
  921.       return [file isfile $xfLinkName]
  922.     }
  923.   }
  924.   return 0
  925. }
  926.  
  927. ##########
  928. # Procedure: XFMiscIsSymlink
  929. # Description: check if path is a symbolic link
  930. # Arguments: xfPathName - the path to check
  931. # Returns: 1 if its a directory, otherwise 0
  932. # Sideeffects: none
  933. ##########
  934. proc XFMiscIsSymlink {xfPathName} {
  935.  
  936.   catch "file type $xfPathName" xfType
  937.   if {"$xfType" == "link"} {
  938.     return 1
  939.   }
  940.   return 0
  941. }
  942.  
  943. ##########
  944. # Procedure: XFMiscIsXFElement
  945. # Description: check if element is a valid (application specific) element
  946. # Arguments: xfName - the name of the module item
  947. # Returns: 0 - name is not a xf element
  948. #          1 - name is a xf element
  949. # Sideeffects: none
  950. ##########
  951. proc XFMiscIsXFElement {xfName} {
  952.   global xfStartupGlobal
  953.   global xfStartupProcs
  954.  
  955.   case $xfName in {
  956.     {tk_* xf* .xf* XF*} {
  957.       return 1
  958.     }
  959.     {ShowWindow* DestroyWindow* StartupSrc* MiddleSrc* EndSrc*} {
  960.       return 1
  961.     }
  962.     {auto_*} {
  963.       if {"$xfName" == "auto_execok" ||
  964.           "$xfName" == "auto_load" ||
  965.           "$xfName" == "auto_mkindex" ||
  966.           "$xfName" == "auto_oldpath" ||
  967.           "$xfName" == "auto_reset" ||
  968.           "$xfName" == "auto_execs" ||
  969.           "$xfName" == "auto_index" ||
  970.           "$xfName" == "auto_path"} {
  971.         return 1
  972.       }
  973.     }
  974.     {InitGlobals PreloadPixmaps autoLoadList moduleList internalAliasList preloadList symbolicName} {
  975.       return 1
  976.     }
  977.     {button checkbutton entry frame label listbox menu menubutton message radiobutton scrollbar scale text toplevel argc argv destroy env errorCode errorInfo exit parray postedMenu selectedButton tkVersion tkerror unknown} {
  978.       return 1
  979.     }
  980.   }
  981.   if {"$xfName" != "." && [string match ".*" $xfName] &&
  982.       [winfo exists $xfName]} {
  983.     if {[string match "xf*" [winfo name $xfName]]} {
  984.       return 1
  985.     }
  986.   }
  987.   if {[lsearch $xfStartupProcs $xfName] != -1 ||
  988.       [lsearch $xfStartupGlobal $xfName] != -1} {
  989.     return 1
  990.   }
  991.   return 0
  992. }
  993.  
  994. ##########
  995. # Procedure: XFMiscIsXFSpecialElement
  996. # Description: check if element is a special xf element
  997. # Arguments: xfName - the name of the module item
  998. # Returns: 0 - name is not a xf element
  999. #          1 - name is a xf element
  1000. # Sideeffects: none
  1001. ##########
  1002. proc XFMiscIsXFSpecialElement {xfName} {
  1003.  
  1004.   if {"$xfName" == "Alias" ||
  1005.       "$xfName" == "Unalias" ||
  1006.       "$xfName" == "GetSelection" ||
  1007.       "$xfName" == "MenuPopupAdd" ||
  1008.       "$xfName" == "MenuPopupHandle" ||
  1009.       "$xfName" == "MenuPopupPost" ||
  1010.       "$xfName" == "MenuPopupMotion" ||
  1011.       "$xfName" == "MenuPopupRelease" ||
  1012.       "$xfName" == "NoFunction" ||
  1013.       "$xfName" == "SymbolicName" ||
  1014.       "$xfName" == "SN"} {
  1015.     return 1
  1016.   }
  1017.   return 0
  1018. }
  1019.  
  1020. ##########
  1021. # Procedure: XFMiscParseGeometry
  1022. # Description: split a x style geometry into a list
  1023. # Arguments: xfGeometry - the geometry
  1024. #            xfW - the toplevel
  1025. # Returns: a list containing the geometry
  1026. # Sideeffects: none
  1027. ##########
  1028. proc XFMiscParseGeometry {xfGeometry {xfW ""}} {
  1029.  
  1030.   set xfCounter [string length $xfGeometry]
  1031.   set xfEnd $xfCounter
  1032.   set xfRootX 0
  1033.   set xfRootY 0
  1034.   set xfRootWidth 0
  1035.   set xfRootHeight 0
  1036.   if {[string first "+" $xfGeometry] != -1 ||
  1037.       [string first "-" $xfGeometry] != -1} {
  1038.     while {$xfCounter >= 0} {
  1039.       if {[string compare [string index $xfGeometry $xfCounter] +] == 0 ||
  1040.           [string compare [string index $xfGeometry $xfCounter] -] == 0} {
  1041.         set xfRootY [string range $xfGeometry $xfCounter end]
  1042.         set xfEnd $xfCounter
  1043.         break
  1044.       }
  1045.       incr xfCounter -1
  1046.     }
  1047.     while {$xfCounter >= 0} {
  1048.       if {[string compare [string index $xfGeometry $xfCounter] +] != 0 &&
  1049.           [string compare [string index $xfGeometry $xfCounter] -] != 0} {
  1050.         break
  1051.       }
  1052.       incr xfCounter -1
  1053.       incr xfEnd -1
  1054.     }
  1055.     while {$xfCounter >= 0} {
  1056.       if {[string compare [string index $xfGeometry $xfCounter] +] == 0 ||
  1057.           [string compare [string index $xfGeometry $xfCounter] -] == 0} {
  1058.         set xfRootX [string range $xfGeometry $xfCounter $xfEnd]
  1059.         set xfEnd $xfCounter
  1060.         break
  1061.       }
  1062.       incr xfCounter -1
  1063.     }
  1064.     while {$xfCounter >= 0} {
  1065.       if {[string compare [string index $xfGeometry $xfCounter] +] != 0 &&
  1066.           [string compare [string index $xfGeometry $xfCounter] -] != 0} {
  1067.         break
  1068.       }
  1069.       incr xfCounter -1
  1070.       incr xfEnd -1
  1071.     }
  1072.   } {
  1073.     set xfRootX [winfo rootx $xfW]
  1074.     set xfRootY [winfo rooty $xfW]
  1075.   }
  1076.   if {[string first "x" $xfGeometry] != -1} {
  1077.     while {$xfCounter >= 0} {
  1078.       if {"[string index $xfGeometry $xfCounter]" == "x"} {
  1079.         set xfRootHeight [string range $xfGeometry [expr $xfCounter+1] $xfEnd]
  1080.         set xfEnd $xfCounter
  1081.         break
  1082.       }
  1083.       incr xfCounter -1
  1084.     }
  1085.     while {$xfCounter >= 0} {
  1086.       if {"[string index $xfGeometry $xfCounter]" != "x"} {
  1087.         break
  1088.       }
  1089.       incr xfCounter -1
  1090.       incr xfEnd -1
  1091.     }
  1092.     set xfRootWidth [string range $xfGeometry 0 $xfEnd]
  1093.   } {
  1094.     set xfRootWidth [winfo reqwidth $xfW]
  1095.     set xfRootHeight [winfo reqwidth $xfW]
  1096.   }
  1097.   return [list $xfRootWidth $xfRootHeight $xfRootX $xfRootY]
  1098. }
  1099.  
  1100. ##########
  1101. # Procedure: XFMiscPathName
  1102. # Description: cut the path from the widget name
  1103. # Arguments: xfW - the widget
  1104. # Returns: none
  1105. # Sideeffects: none
  1106. ##########
  1107. proc XFMiscPathName {xfW} {
  1108.  
  1109.   if {[string last . $xfW] >= 0} {
  1110.     set xfResult [string range $xfW [expr [string last . $xfW]+1] end]
  1111.     return $xfResult
  1112.   } {
  1113.     return $xfW
  1114.   }
  1115. }
  1116.  
  1117. ##########
  1118. # Procedure: XFMiscPathTail
  1119. # Description: cut the tail of a path from the widget name
  1120. # Arguments: xfW - the widget
  1121. # Returns: none
  1122. # Sideeffects: none
  1123. ##########
  1124. proc XFMiscPathTail {xfW} {
  1125.  
  1126.   set xfResult [split $xfW .]
  1127.   if {"$xfW" == "."} {
  1128.     return .
  1129.   } {
  1130.     if {[llength $xfResult] > 3} {
  1131.       return ....[lindex $xfResult [expr [llength $xfResult]-2]].[lindex $xfResult [expr [llength $xfResult]-1]]
  1132.     } {
  1133.       if {[llength $xfResult] == 3} {
  1134.         return .[lindex $xfResult [expr [llength $xfResult]-2]].[lindex $xfResult [expr [llength $xfResult]-1]]
  1135.       } {
  1136.         if {[llength $xfResult] == 2} {
  1137.           return .[lindex $xfResult [expr [llength $xfResult]-1]]
  1138.         } {
  1139.           return .
  1140.         }
  1141.       }
  1142.     }
  1143.   }
  1144. }
  1145.  
  1146. ##########
  1147. # Procedure: XFMiscPositionWidget
  1148. # Description: position a newly created widget
  1149. # Arguments: xfW - the widget
  1150. #            {xfPackerOptions} - options for the packer
  1151. #            {xfPlacerOptions} - options for the placer
  1152. # Returns: none
  1153. # Sideeffects: none
  1154. ##########
  1155. proc XFMiscPositionWidget {xfW {xfPackerOptions ""} {xfPlacerOptions ""}} {
  1156.   global xfConf
  1157.  
  1158.   if {"[winfo class [winfo parent $xfW]]" == "Canvas"} {
  1159.     [winfo parent $xfW] create window 0 0 -anchor nw -window $xfW
  1160.     return
  1161.   }
  1162.  
  1163.   if {"$xfConf(geometry)" == "packer"} {
  1164.     if {"$xfPackerOptions" == ""} {
  1165.       set xfPackString ""
  1166.       set xfCildClass ""
  1167.       if {"[pack info [winfo parent $xfW]]" != ""} {
  1168.         set xfChildClass [winfo class [lindex [pack info [winfo parent $xfW]] 0]]
  1169.       }
  1170.       set xfTmpPacking [lindex [pack info [winfo parent $xfW]] 1]
  1171.       if {"$xfTmpPacking" != ""} {
  1172.         foreach xfElement $xfTmpPacking {
  1173.           case $xfElement {
  1174.             {top} {
  1175.               append xfPackString "top "
  1176.             }
  1177.             {left} {
  1178.               append xfPackString "left "
  1179.             }
  1180.             {right} {
  1181.               append xfPackString "right "
  1182.             }
  1183.             {bottom} {
  1184.               append xfPackString "bottom "
  1185.             }
  1186.             {fillx} {
  1187.               append xfPackString "fillx "
  1188.             }
  1189.             {filly} {
  1190.               append xfPackString "filly "
  1191.             }
  1192.             {fill} {
  1193.               append xfPackString "fill "
  1194.             }
  1195.             {expand} {
  1196.               if {"$xfChildClass" != "" &&
  1197.                   "$xfChildClass" == "[winfo class $xfW]"} {
  1198.                 append xfPackString "expand "
  1199.               }
  1200.             }
  1201.           }
  1202.         }
  1203.       }
  1204.       if {"$xfPackString" == ""} {
  1205.         if {"[winfo class [winfo parent $xfW]]" == "XFForm"} {
  1206.           pack append [winfo parent $xfW] \
  1207.             $xfW {top fillx}
  1208.         } {
  1209.           pack append [winfo parent $xfW] \
  1210.             $xfW {top}
  1211.         }
  1212.       } {
  1213.         pack append [winfo parent $xfW] \
  1214.           $xfW $xfPackString
  1215.       }
  1216.     } {
  1217.       pack append [winfo parent $xfW] \
  1218.         $xfW "$xfPackerOptions"
  1219.     }
  1220.   } {
  1221.     if {"$xfPackerOptions" == ""} {
  1222.       place $xfW -x 0 -y 0
  1223.     } {
  1224.       eval place $xfW $xfPackerOptions
  1225.     }
  1226.   }
  1227. }
  1228.  
  1229. ##########
  1230. # Procedure: XFMiscPutFileInList
  1231. # Description: fill a list with the contents of the file
  1232. # Arguments: xfW - the widget
  1233. #            xfFileName - filename to read
  1234. # Returns: none
  1235. # Sideeffects: none
  1236. ##########
  1237. proc XFMiscPutFileInList {xfW xfFileName} {
  1238.  
  1239.   # check file existance
  1240.   if {[catch "open $xfFileName r" xfInFile]} {
  1241.     XFProcError "$xfInFile"
  1242.   } {
  1243.     set xfFileContents [read $xfFileName]
  1244.     close $xfInFile
  1245.     foreach xfLine [split $xfFileContents "\n"] {
  1246.       $xfW insert end $xfLine
  1247.     }
  1248.   }
  1249. }
  1250.  
  1251. ##########
  1252. # Procedure: XFMiscPutFileInText
  1253. # Description: fill a text with the contents of the file
  1254. # Arguments: xfW - the widget
  1255. #            xfFileName - filename to read
  1256. # Returns: none
  1257. # Sideeffects: none
  1258. ##########
  1259. proc XFMiscPutFileInText {xfW xfFileName} {
  1260.  
  1261.   # check file existance
  1262.   if {[catch "open $xfFileName r" xfInFile]} {
  1263.     XFProcError "$xfInFile"
  1264.   } {
  1265.     $xfW insert end "[read $xfInFile]"
  1266.     close $xfInFile
  1267.   }
  1268. }
  1269.  
  1270. ##########
  1271. # Procedure: XFMiscQuit
  1272. # Description: quit xf
  1273. # Arguments: xfRetVal - return value
  1274. # Returns: none
  1275. # Sideeffects: none
  1276. ##########
  1277. proc XFMiscQuit {{xfRetVal 0}} {
  1278.   global xfConf
  1279.   global xfPath
  1280.   global xfStatus
  1281.  
  1282.   if {$xfConf(saveOptions)} {
  1283.     XFProcOptionsSaveOptions
  1284.   }
  1285.   if {$xfConf(savePositions)} {
  1286.     XFProcOptionsSavePositions
  1287.   }
  1288.  
  1289.   foreach xfCounter [winfo children .] {
  1290.     catch "XFDestroy $xfCounter"
  1291.   }
  1292.   catch "send \"XF-tutorial\" \"catch \\\"destroy .\\\"; catch \\\"exit 0\\\"\""
  1293.   catch "exec rm $xfPath(tmp)/cb$xfStatus(uniqueId)"
  1294.   catch "exec rm $xfPath(tmp)/tb$xfStatus(uniqueId)"
  1295.   catch "exec rm $xfPath(tmp)/lc$xfStatus(uniqueId)"
  1296.   catch "exec rm $xfPath(tmp)/tr$xfStatus(uniqueId).grl"  
  1297.   catch "exec rm $xfPath(tmp)/et$xfStatus(uniqueId)"
  1298.   catch "exec rm $xfPath(tmp)/st$xfStatus(uniqueId)"
  1299.  
  1300.   set xfCounter 0
  1301.   while {$xfCounter < $xfConf(maxSaveId)} {
  1302.     if {[file exists $xfPath(tmp)/as$xfStatus(uniqueId)$xfCounter]} {
  1303.       catch "exec rm $xfPath(tmp)/as$xfStatus(uniqueId)$xfCounter"
  1304.     }
  1305.     if {[file exists $xfPath(tmp)/as$xfStatus(uniqueId)$xfCounter~]} {
  1306.       catch "exec rm $xfPath(tmp)/as$xfStatus(uniqueId)$xfCounter~"
  1307.     }
  1308.     incr xfCounter 1
  1309.   }
  1310.  
  1311.   flush stdout
  1312.   flush stderr
  1313.  
  1314.   catch "XFDestroy ."
  1315.   XFExit $xfRetVal
  1316. }
  1317.  
  1318. ##########
  1319. # Procedure: XFMiscReadTree
  1320. # Description: read the complete widget tree
  1321. # Arguments: xfW - the current widget
  1322. #            xfList - the list to fill
  1323. #            xfType - read all, or only descendants
  1324. #            xfSymbol - read symbolic names or not (sym)
  1325. # Returns: none
  1326. # Sideeffects: none
  1327. ##########
  1328. proc XFMiscReadTree {xfW xfList {xfType ""} {xfSymbol 0}} {
  1329.   global symbolicName
  1330.  
  1331.   XFMiscClearList $xfList
  1332.   set xfCounter 1
  1333.   if {"[winfo class $xfW]" != "Toplevel"} {
  1334.     set xfRoot [string range $xfW 0 [string first . [string range $xfW 1 end]]]
  1335.   } {
  1336.     set xfRoot $xfW
  1337.   }
  1338.   if {"$xfRoot" == ""} {
  1339.     set xfRoot .
  1340.   } {
  1341.     if {"[winfo class $xfRoot]" != "Toplevel"} {
  1342.       set xfRoot .
  1343.     }
  1344.   }
  1345.   if {$xfSymbol == 0} {
  1346.     $xfList insert end "1 $xfRoot"
  1347.   } {
  1348.     set xfCounter3 ""
  1349.     foreach xfCounter2 [array names symbolicName] {
  1350.       set xfArrayName ""
  1351.       append xfArrayName symbolicName ( $xfCounter2 )
  1352.       if {"$xfRoot" == "[set $xfArrayName]"} {
  1353.         set xfCounter3 $xfCounter2
  1354.         break
  1355.       }
  1356.     }
  1357.     if {"$xfCounter3" != ""} {
  1358.       $xfList insert end "1 $xfRoot = $xfCounter3"
  1359.     } {
  1360.       $xfList insert end "1 $xfRoot"
  1361.     }
  1362.   }
  1363.   XFMiscReadTreeBuild $xfRoot $xfList $xfType 2 $xfSymbol
  1364.  
  1365.   set xfCounter 0
  1366.   set xfLength [$xfList size]
  1367.   while {$xfCounter < $xfLength} {
  1368.     if {"[lindex [$xfList get $xfCounter] 1]" == "$xfW"} {
  1369.       $xfList select from $xfCounter
  1370.       $xfList select to $xfCounter
  1371.     }
  1372.     incr xfCounter 1
  1373.   }
  1374. }
  1375.  
  1376. ##########
  1377. # Procedure: XFMiscReadTreeBuild
  1378. # Description: read the complete widget tree and enter it into list
  1379. # Arguments: xfW - the current widget
  1380. #            xfList - the list to fill
  1381. #            xfType - read all, or only descendants
  1382. #            xfLevel - the level
  1383. #            xfSymbol - read symbolic names or not (sym)
  1384. # Returns: none
  1385. # Sideeffects: none
  1386. ##########
  1387. proc XFMiscReadTreeBuild {xfW xfList xfType xfLevel {xfSymbol 0}} {
  1388.   global symbolicName
  1389.  
  1390.   set xfCounter 0
  1391.   set xfOffset ""
  1392.   while {$xfCounter < $xfLevel} {
  1393.     append xfOffset "  "
  1394.     incr xfCounter 1
  1395.   }
  1396.   foreach xfCounter [winfo children $xfW] {
  1397.     if {![string match ".xf*" $xfCounter] &&
  1398.         ![string match "xf*" [winfo name $xfCounter]]} {
  1399.       if {"[winfo class $xfCounter]" != "Toplevel" || "$xfType" == "all"} {
  1400.         if {$xfSymbol == 0} {
  1401.           $xfList insert end "$xfLevel$xfOffset$xfCounter"
  1402.         } {
  1403.           set xfCounter3 ""
  1404.           foreach xfCounter2 [array names symbolicName] {
  1405.             set xfArrayName ""
  1406.             append xfArrayName symbolicName ( $xfCounter2 )
  1407.             if {"$xfCounter" == "[set $xfArrayName]"} {
  1408.               set xfCounter3 $xfCounter2
  1409.               break
  1410.             }
  1411.           }
  1412.           if {"$xfCounter3" != ""} {
  1413.             $xfList insert end "$xfLevel$xfOffset$xfCounter = $xfCounter3"
  1414.           } {
  1415.             $xfList insert end "$xfLevel$xfOffset$xfCounter"
  1416.           }
  1417.         }
  1418.         XFMiscReadTreeBuild $xfCounter $xfList $xfType \
  1419.           [expr $xfLevel+1] $xfSymbol
  1420.       }
  1421.     }
  1422.   }
  1423. }
  1424.  
  1425. ##########
  1426. # Procedure: XFMiscRemoveBindWidgetTree
  1427. # Description: remove the bindings for all widgets in the specified
  1428. #              tree
  1429. # Arguments: xfW - the current widget
  1430. #            xfType - all to remove bindings for all widgets (notall else)
  1431. # Returns: none
  1432. # Sideeffects: none
  1433. ##########
  1434. proc XFMiscRemoveBindWidgetTree {xfW xfType} {
  1435.   global xfBind
  1436.  
  1437.   if {(![string match ".xf*" $xfW] ||
  1438.        ![string match "xf*" [winfo name $xfW]]) ||
  1439.       "$xfW" == "." || "$xfType" == "all"} {
  1440.     catch "bind $xfW $xfBind(configure) \"\""
  1441.     catch "bind $xfW $xfBind(placing) \"\""
  1442.     catch "bind $xfW $xfBind(placingMotion) \"\""
  1443.     catch "bind $xfW $xfBind(placingRelease) \"\""
  1444.     catch "bind $xfW $xfBind(select) \"\""
  1445.     catch "bind $xfW $xfBind(showName) \"\""
  1446.     catch "bind $xfW $xfBind(removeName) \"\""
  1447.   }
  1448.   foreach xfCounter [winfo children $xfW] {
  1449.     if {(![string match ".xf*" $xfCounter] &&
  1450.          ![string match "xf*" [winfo name $xfCounter]]) ||
  1451.         "$xfType" == "all"} {
  1452.       XFMiscRemoveBindWidgetTree $xfCounter $xfType
  1453.     }
  1454.   }
  1455. }
  1456.  
  1457. ##########
  1458. # Procedure: XFMiscSaveError
  1459. # Description: save the error message passed as parameter
  1460. # Arguments: xfMessage - the error message
  1461. #            xfInfo - the error info
  1462. #            xfCode - the error code
  1463. # Returns: none
  1464. # Sideeffects: none
  1465. ##########
  1466. proc XFMiscSaveError {xfMessage {xfInfo ""} {xfCode ""}} {
  1467.   global env
  1468.   global xfPath
  1469.   global xfStatus
  1470.  
  1471.   catch "exec chmod a+w $xfPath(tmp)/xferrors$xfStatus(uniqueId)"
  1472.   catch "exec chmod a+r $xfPath(tmp)/xferrors$xfStatus(uniqueId)"
  1473.   if {![catch "open $xfPath(tmp)/xferrors$xfStatus(uniqueId) a" xfOutFile]} {
  1474.     catch "exec chmod a+w $xfPath(tmp)/xferrors$xfStatus(uniqueId)"
  1475.     catch "exec chmod a+r $xfPath(tmp)/xferrors$xfStatus(uniqueId)"
  1476.     set xfIdString ""
  1477.     if {[info exists env(USER)]} {
  1478.       append xfIdString "$env(USER)"
  1479.     }
  1480.     if {[info exists env(HOST)]} {
  1481.       append xfIdString "@$env(HOST)"
  1482.     }
  1483.     append xfIdString "; [exec date]"
  1484.     puts $xfOutFile "#################:$xfIdString\n$xfMessage\n\n"
  1485.     close $xfOutFile
  1486.   }
  1487. }
  1488.  
  1489. ##########
  1490. # Procedure: XFMiscSetInfo
  1491. # Description: set the contents of the info list
  1492. # Arguments: xfType - what should be displayed (procs, globals, commands)
  1493. #            xfList - the list we want to feed
  1494. #            xfSet - the type of setting (1 = set always, 0 = set
  1495. #                    only if permanent apply is on)
  1496. # Returns: none
  1497. # Sideeffects: none
  1498. ##########
  1499. proc XFMiscSetInfo {xfType xfList xfSet} {
  1500.   global hiddenProcs
  1501.   global xfConf
  1502.   global xfStatus
  1503.  
  1504.   if {!$xfSet && !$xfStatus(rescanInfo)} {
  1505.     return
  1506.   }
  1507.   XFMiscClearList $xfList
  1508.   if {"$xfType" == "hiddenprocs" ||
  1509.       "$xfType" == "hiddencommands"} {
  1510.     if {[info exists hiddenProcs]} {
  1511.       set xfElementList [array names hiddenProcs]
  1512.     } {
  1513.       set xfElementList ""
  1514.     }
  1515.   } {
  1516.     set xfElementList [lsort [info $xfType]]
  1517.   }
  1518.  
  1519.   set xfResult $xfStatus(includeExclude)
  1520.   foreach xfInfoCounter $xfElementList {
  1521.     if {"$xfStatus(includeExcludeString)" != ""} {
  1522.       if {[catch "regexp \{$xfStatus(includeExcludeString)\} $xfInfoCounter" xfResult]} {
  1523.         set xfResult 0
  1524.       }
  1525.     } {
  1526.         set xfResult 1
  1527.     }
  1528.     if {$xfResult == $xfStatus(includeExclude)} {
  1529.       case $xfType in {
  1530.         {globals} {
  1531.           if {[XFMiscIsXFElement $xfInfoCounter]} {
  1532.             continue
  1533.           }
  1534.           global $xfInfoCounter
  1535.           if {[catch "array names $xfInfoCounter" xfResult]} {
  1536.             if {"[string trim $xfInfoCounter]" != ""} {
  1537.               $xfList insert end $xfInfoCounter
  1538.             }
  1539.           } {
  1540.             foreach xfCounter2 [lsort [array names $xfInfoCounter]] {
  1541.               set xfArrayName ""
  1542.               append xfArrayName $xfInfoCounter ( $xfCounter2 )
  1543.               if {"[string trim $xfArrayName]" != ""} {
  1544.                 $xfList insert end $xfArrayName
  1545.               }
  1546.             }
  1547.           }
  1548.           continue
  1549.         }
  1550.         {procs | commands | hiddenprocs | hiddencommands} {
  1551.           if {[XFMiscIsXFElement $xfInfoCounter]} {
  1552.             continue
  1553.           }
  1554.           if {"$xfType" == "procs"} {
  1555.             if {"$xfInfoCounter" == "destroy" ||
  1556.                 "$xfInfoCounter" == "exit"} {
  1557.               continue
  1558.             }
  1559.           }
  1560.           if {"[info procs $xfInfoCounter]" != ""} {
  1561.             if {![XFMiscCorrectLevel procshow [info body $xfInfoCounter]]} {
  1562.               continue
  1563.             }
  1564.           }
  1565.           $xfList insert end $xfInfoCounter
  1566.           continue
  1567.         }
  1568.       }
  1569.     }
  1570.   }
  1571.  
  1572.   set xfInfoCounter 0
  1573.   set xfListLength [$xfList size]
  1574.   if {"$xfListLength" == "none"} {
  1575.     set xfListLength -1
  1576.   }
  1577.   case $xfType in {
  1578.     {commands | hiddencommands} {
  1579.       set xfCurrentName $xfStatus(cmdName)
  1580.       set xfCurrentIndex $xfStatus(cmdIndex)
  1581.     }
  1582.     {globals} {
  1583.       set xfCurrentName $xfStatus(globalName)
  1584.       set xfCurrentIndex $xfStatus(globalIndex)
  1585.     }
  1586.     {procs | hiddenprocs} {
  1587.       set xfCurrentName $xfStatus(procName)
  1588.       set xfCurrentIndex $xfStatus(procIndex)
  1589.     }
  1590.   }
  1591.   while {$xfInfoCounter < $xfListLength} {
  1592.     if {"$xfCurrentName" == "[$xfList get $xfInfoCounter]"} {
  1593.       $xfList select from $xfInfoCounter
  1594.       $xfList select to $xfInfoCounter
  1595.       return
  1596.     }
  1597.     incr xfInfoCounter 1
  1598.   }
  1599.   if {$xfCurrentIndex < $xfListLength} {
  1600.     $xfList select from $xfCurrentIndex
  1601.     $xfList select to $xfCurrentIndex
  1602.   } {
  1603.     if {$xfListLength >= 0} {
  1604.       $xfList select from $xfListLength
  1605.       $xfList select to $xfListLength
  1606.     }
  1607.   }
  1608. }
  1609.  
  1610. ##########
  1611. # Procedure: XFMiscSetRootPos
  1612. # Description: set position of root window
  1613. # Arguments: xfName - the widget to place
  1614. #            xfGeometry - the geometry to set
  1615. #            xfLeader - the leading window
  1616. # Returns: none
  1617. # Sideeffects: none
  1618. ##########
  1619. proc XFMiscSetRootPos {xfName xfGeometry xfLeader} {
  1620.  
  1621.   set xfTmpGeometry [XFMiscParseGeometry $xfGeometry $xfName]
  1622.   set xfLeaderWidth [winfo width $xfLeader]
  1623.   set xfLeaderHeight [winfo height $xfLeader]
  1624.   set xfWidth [lindex $xfTmpGeometry 0]
  1625.   set xfHeight [lindex $xfTmpGeometry 1]
  1626.   set xfXPos [lindex $xfTmpGeometry 2]
  1627.   set xfYPos [lindex $xfTmpGeometry 3]
  1628.   if {$xfWidth == 0 || $xfHeight == 0} {
  1629.     set xfTmpGeometry [XFMiscParseGeometry [winfo geometry $xfLeader]]
  1630.     set xfWidth [lindex $xfTmpGeometry 0]
  1631.     set xfHeight [lindex $xfTmpGeometry 1]
  1632.   }
  1633.   if {$xfXPos == 0 || $xfYPos == 0} {
  1634.     set xfTmpGeometry [XFMiscParseGeometry [winfo geometry $xfLeader]]
  1635.     set xfXPos [lindex $xfTmpGeometry 2]
  1636.     set xfYPos [lindex $xfTmpGeometry 3]
  1637.   }
  1638.   if {$xfXPos == 0 || $xfYPos == 0} {
  1639.     set xfXPos [winfo x $xfLeader]
  1640.     set xfYPos [winfo y $xfLeader]
  1641.   }
  1642.  
  1643.   if {$xfWidth < $xfLeaderWidth} {
  1644.     set xfWidth $xfLeaderWidth
  1645.   }
  1646.   if {$xfHeight < $xfLeaderHeight} {
  1647.     set xfHeight $xfLeaderHeight
  1648.   }
  1649.   wm geometry $xfName ${xfWidth}x${xfHeight}+${xfXPos}+${xfYPos}
  1650. }
  1651.  
  1652. ##########
  1653. # Procedure: XFMiscSetSymbolicName
  1654. # Description: set the symbolic name
  1655. # Arguments: xfW - the widget
  1656. #            xfName - the new symbolic name
  1657. # Returns: none
  1658. # Sideeffects: none
  1659. ##########
  1660. proc XFMiscSetSymbolicName {xfW {xfName ""}} {
  1661.   global symbolicName
  1662.  
  1663.   # first check if a name is in use
  1664.   if {"$xfName" != ""} {
  1665.     set xfArrayName ""
  1666.     append xfArrayName symbolicName ( $xfName )
  1667.     if {![catch "set \"$xfArrayName\"" xfTmpName]} {
  1668.       if {"$xfW" != "$xfTmpName"} {
  1669.         if {"[info commands $xfTmpName]" != ""} {
  1670.           XFProcError "The symbolic name:\n$xfName\nis already in use for:\n$xfTmpName"
  1671.           return
  1672.         } {
  1673.           XFProcError "The symbolic name:\n$xfName\nwas already in use for:\n$xfTmpName\nThis widget was destroyed or is not visible. $xfW now uses this name!"
  1674.         }
  1675.       }
  1676.     }
  1677.   }
  1678.   # first remove old name
  1679.   foreach xfCounter [array names symbolicName] {
  1680.     set xfArrayName ""
  1681.     append xfArrayName symbolicName ( $xfCounter )
  1682.     if {"$xfW" == "[set "$xfArrayName"]"} {
  1683.       unset $xfArrayName
  1684.     }
  1685.   }
  1686.   if {"$xfName" != ""} {
  1687.     set xfArrayName ""
  1688.     append xfArrayName symbolicName ( $xfName )
  1689.     set $xfArrayName $xfW
  1690.   }
  1691. }
  1692.  
  1693. ##########
  1694. # Procedure: XFMiscSetText
  1695. # Description: set contents of text widget
  1696. # Arguments: xfW - the widget
  1697. #            xfContents - the new text
  1698. # Returns: none
  1699. # Sideeffects: none
  1700. ##########
  1701. proc XFMiscSetText {xfW {xfContents ""}} {
  1702.  
  1703.   if {"[winfo class $xfW]" == "Text"} {
  1704.     set xfOldStatus [lindex [$xfW config -state] 4]
  1705.     $xfW config -state normal
  1706.     $xfW delete 1.0 end
  1707.     $xfW insert 1.0 $xfContents
  1708.     $xfW config -state $xfOldStatus
  1709.   } {
  1710.     if {"[winfo class $xfW]" == "TkEmacs"} {
  1711.       $xfW delete top end
  1712.       $xfW insert top $xfContents
  1713.     } {
  1714.       if {"[winfo class $xfW]" == "Entry"} {
  1715.         set xfOldStatus [lindex [$xfW config -state] 4]
  1716.         $xfW config -state normal
  1717.         $xfW delete 0 end
  1718.         $xfW insert 0 $xfContents
  1719.         $xfW config -state $xfOldStatus
  1720.       }
  1721.     }
  1722.   }
  1723. }
  1724.  
  1725. ##########
  1726. # Procedure: XFMiscSetTextHeight
  1727. # Description: set height of text widget
  1728. # Arguments: xfW - the widget
  1729. #            xfHeight - the height in lines (or something near to this)
  1730. # Returns: none
  1731. # Sideeffects: none
  1732. ##########
  1733. proc XFMiscSetTextHeight {xfW xfHeight} {
  1734.  
  1735.   if {"[winfo class [lindex $xfW 0]]" == "Text"} {
  1736.     [lindex $xfW 0] configure \
  1737.       -height $xfHeight
  1738.   } {
  1739.     if {"[winfo class [lindex $xfW 0]]" == "TkEmacs"} {
  1740.       set xfTmpVal [lindex [[lindex $xfW 0] configure -geometry] 4]
  1741.       set xfTmpGeometry "[string range $xfTmpVal 0 [string first x $xfTmpVal]][expr [expr 2+$xfHeight]*14]"
  1742.       [lindex $xfW 0] configure \
  1743.         -geometry $xfTmpGeometry
  1744.     }
  1745.   }
  1746. }
  1747.  
  1748. ##########
  1749. # Procedure: XFMiscSetTextFont
  1750. # Description: set font of text widget
  1751. # Arguments: xfW - the widget
  1752. #            xfFont - the new font
  1753. # Returns: none
  1754. # Sideeffects: none
  1755. ##########
  1756. proc XFMiscSetTextFont {xfW xfFont} {
  1757.  
  1758.   if {"[winfo class $xfW]" == "Text" ||
  1759.       "[winfo class $xfW]" == "TkEmacs" ||
  1760.       "[winfo class $xfW]" == "Entry"} {
  1761.     catch "$xfW configure -font $xfFont"
  1762.   }
  1763. }
  1764.  
  1765. ##########
  1766. # Procedure: XFMiscSetResource
  1767. # Description: set the resource
  1768. # Arguments: xfW - the widget
  1769. #            xfName - the resource name
  1770. #            xfValue - the new value
  1771. # Returns: none
  1772. # Sideeffects: none
  1773. ##########
  1774. proc XFMiscSetResource {xfW xfName xfValue} {
  1775.   global xfConf
  1776.  
  1777.   if {"[info commands $xfW]" == ""} {
  1778.     return
  1779.   }
  1780.   case [winfo class $xfW] in {
  1781.     {Scale} {
  1782.       if {"$xfName" == "command"} {
  1783.         if {"$xfValue" == ""} {
  1784.           set xfValue NoFunction
  1785.         }
  1786.       }
  1787.     }
  1788.     {Scrollbar} {
  1789.       if {"$xfName" == "command"} {
  1790.         if {"$xfValue" == ""} {
  1791.           set xfValue NoFunction
  1792.         }
  1793.       }
  1794.     }
  1795.     {default} {
  1796.       if {"$xfName" == "activebackground" ||
  1797.           "$xfName" == "activeforeground" ||
  1798.           "$xfName" == "background" ||
  1799.           "$xfName" == "bitmap" ||
  1800.           "$xfName" == "disabledforeground" ||
  1801.           "$xfName" == "font" ||
  1802.           "$xfName" == "foreground" ||
  1803.           "$xfName" == "selector" ||
  1804.           "$xfName" == "variable"} {
  1805.         if {"$xfValue" == ""} {
  1806.           return
  1807.         }
  1808.       }
  1809.       if {"$xfName" == "scrollcommand" ||
  1810.           "$xfName" == "xscrollcommand" ||
  1811.           "$xfName" == "yscrollcommand"} {
  1812.         if {"$xfValue" == ""} {
  1813.           set xfValue NoFunction
  1814.         }
  1815.       }
  1816.       if {"$xfName" == "bitmap"} {
  1817.         if {"[string index $xfValue 0]" != "@" &&
  1818.             [file exists $xfValue]} {
  1819.           set xfValue "@$xfValue"
  1820.         }
  1821.       }
  1822.     }
  1823.   }
  1824.   if {$xfW != "."} {
  1825.     if {$xfConf(encloseConfigure)} {
  1826.       if {[catch "$xfW configure -$xfName {$xfValue}" xfResult]} {
  1827.         XFProcError "$xfW\n$xfResult"
  1828.       }
  1829.     } {
  1830.       if {[catch "$xfW configure -$xfName \"$xfValue\"" xfResult]} {
  1831.        XFProcError "$xfW\n$xfResult"
  1832.       }
  1833.     }
  1834.   }
  1835. }
  1836.  
  1837. ##########
  1838. # Procedure: XFMiscSetResourceToTree
  1839. # Description: set the resource to a complete widget tree
  1840. # Arguments: xfW - the widget
  1841. #            xfName - the resource name
  1842. #            xfValue - the new value
  1843. # Returns: none
  1844. # Sideeffects: none
  1845. ##########
  1846. proc XFMiscSetResourceToTree {xfW xfName xfValue} {
  1847.   global xfConf
  1848.  
  1849.   if {$xfW != "."} {
  1850.     if {$xfConf(encloseConfigure)} {
  1851.       catch "$xfW configure -$xfName {$xfValue}"
  1852.     } {
  1853.       catch "$xfW configure -$xfName \"$xfValue\""
  1854.     }
  1855.   }
  1856.   foreach counter [winfo children $xfW] {
  1857.     XFMiscSetResourceToTree $counter $xfName $xfValue
  1858.   }
  1859. }
  1860.  
  1861. ##########
  1862. # Procedure: XFMiscSetTextIntoWidget
  1863. # Description: insert text into a specified widget
  1864. # Arguments: xfW - the widget
  1865. #            xfText - the text
  1866. # Returns: none
  1867. # Sideeffects: none
  1868. ##########
  1869. proc XFMiscSetTextIntoWidget {xfW xfText} {
  1870.   global tkVersion
  1871.  
  1872.   if {$tkVersion >= 3.0} {
  1873.     if {[winfo exists $xfW]} {
  1874.       XFMiscSetText $xfW $xfText
  1875.     }
  1876.   } {
  1877.     if {"[info commands $xfW]" != ""} {
  1878.       XFMiscSetText $xfW $xfText
  1879.     }
  1880.   }
  1881. }
  1882.  
  1883. ##########
  1884. # Procedure: XFMiscToplevelRemove
  1885. # Description: remove toplevel
  1886. # Arguments: xfW - the toplevel to remove
  1887. # Returns: none
  1888. # Sideeffects: none
  1889. ##########
  1890. proc XFMiscToplevelRemove {xfW} {
  1891.  
  1892.   XFSaveAsProc $xfW
  1893.   XFEditSetShowWindows
  1894.   XFEditSetPath .
  1895. }
  1896.  
  1897. ##########
  1898. # Procedure: XFMiscToplevelShow
  1899. # Description: show toplevel
  1900. # Arguments: xfW - the toplevel to show
  1901. # Returns: none
  1902. # Sideeffects: none
  1903. ##########
  1904. proc XFMiscToplevelShow {xfW} {
  1905.  
  1906.   eval ShowWindow.$xfW
  1907.   XFEditSetShowWindows
  1908.   XFEditSetPath .
  1909. }
  1910.  
  1911. ##########
  1912. # Procedure: XFMiscUpdateModuleList
  1913. # Description: update the module list
  1914. # Arguments: none
  1915. # Returns: none
  1916. # Sideeffects: none
  1917. ##########
  1918. proc XFMiscUpdateModuleList {} {
  1919.   global autoLoadList
  1920.   global moduleList
  1921.   global xfConf
  1922.  
  1923.   if {"$xfConf(programName)" != "$xfConf(programNameOld)"} {
  1924.     foreach xfCounter [array names moduleList] {
  1925.       if {"$xfConf(programNameOld)" == "$xfCounter"} {
  1926.         if {[info exists moduleList($xfConf(programNameOld))]} {
  1927.           set moduleList($xfConf(programName)) \
  1928.             [set moduleList($xfConf(programNameOld))]
  1929.           unset moduleList($xfConf(programNameOld))
  1930.         }
  1931.         if {[info exists autoLoadList($xfConf(programNameOld))]} {
  1932.           set autoLoadList($xfConf(programName)) \
  1933.             [set autoLoadList($xfConf(programNameOld))]
  1934.           unset autoLoadList($xfConf(programNameOld))
  1935.         }
  1936.       }
  1937.     }
  1938.     set $xfConf(programNameOld) $xfConf(programName)
  1939.   }
  1940.   if {[catch "set moduleList($xfConf(programName))"]} {
  1941.     set moduleList($xfConf(programName)) ""
  1942.   }
  1943.   if {[catch "set autoLoadList($xfConf(programName))"]} {
  1944.     set autoLoadList($xfConf(programName)) 0
  1945.   }
  1946. }
  1947.  
  1948. proc XFMenuBarInit {xfMenuBarUserFile xfMenuBarFile} {
  1949. ##########
  1950. # Procedure: XFMenuBarInit
  1951. # Description: initialize the configuration of menubuttons and
  1952. #              menus of specified pathnames
  1953. # Arguments: xfMenuBarUserFile - the user specific loadfile
  1954. #            xfMenuBarFile - the default loadfile
  1955. # Returns: none
  1956. # Sideeffects: none
  1957. ##########
  1958.  
  1959.   global xfMenuBar
  1960.  
  1961.   set xfMenuBar(initialized) 1
  1962.   set xfMenuBar(file) $xfMenuBarFile
  1963.   set xfMenuBar(userFile) $xfMenuBarUserFile
  1964.   if {[file exists $xfMenuBar(userFile)]} {
  1965.     if {[catch "source \"$xfMenuBar(userFile)\"" xfMenuBarResult]} {
  1966.       puts stderr $xfMenuBarResult
  1967.     }
  1968.   } {
  1969.     if {[file exists $xfMenuBar(file)]} {
  1970.       if {[catch "source \"$xfMenuBar(file)\"" xfMenuBarResult]} {
  1971.         puts stderr $xfMenuBarResult
  1972.       }
  1973.     }
  1974.   }
  1975. }
  1976.  
  1977. # eof
  1978.  
  1979.