home *** CD-ROM | disk | FTP | other *** search
/ Internet File Formats / InternetFileFormatsCD.bin / text / latex / mac / alpha60.hqx / Tcl / SystemCode / win.tcl < prev    next >
Encoding:
Text File  |  1995-07-14  |  8.3 KB  |  363 lines

  1. #=============================================================================
  2. #    Window handling routines. All procs are bound in AlphaBits.tcl.
  3. #=============================================================================
  4.  
  5. proc shrinkHigh {} {
  6.     global tileTop
  7.     set text [getGeometry]
  8.     set left [lindex $text 0]
  9.     set top [lindex $text 1]
  10.     set width [lindex $text 2]
  11.     sizeWin 510 150
  12.     moveWin $left $tileTop
  13. }
  14.  
  15. proc shrinkLow {} {
  16.     global tileHeight tileLeft tileTop
  17.     sizeWin 510 150
  18.     moveWin $tileLeft [expr $tileTop + $tileHeight - 150]
  19. }
  20.  
  21. proc singlePage {} {shrinkFull}
  22.  
  23. proc shrinkFull {} {
  24.     global tileTop tileHeight tileLeft
  25.     moveWin $tileLeft $tileTop
  26.     sizeWin 510 $tileHeight
  27. }
  28.  
  29. proc shrinkLeft {} {
  30.     global tileWidth tileTop tileHeight tileLeft
  31.     
  32.     set margin 4
  33.     set width [expr ($tileWidth/2)-$margin]
  34.     set text [getGeometry]
  35.     set width [expr ($tileWidth/2)-$margin]
  36.     set width [expr {$width + $margin / 2}]
  37.     moveWin $tileLeft $tileTop
  38.     sizeWin $width $tileHeight
  39. }
  40.  
  41. proc shrinkRight {} {
  42.     global tileWidth tileTop tileHeight tileLeft
  43.     
  44.     set margin 4
  45.     set width [expr ($tileWidth/2)-$margin]
  46.     set text [getGeometry]
  47.     set width [expr ($tileWidth/2)-$margin]
  48.     set width [expr {$width + $margin / 2}]
  49.     moveWin [expr $tileLeft + $width + $margin] $tileTop
  50.     sizeWin $width $tileHeight
  51. }
  52.  
  53. proc swapWithNext {} {
  54.     set files [winNames -f]
  55.     if {[llength $files] < 2} return
  56.     bringToFront [lindex $files 1]
  57. }
  58.     
  59.  
  60.  
  61. proc nextWindow {} {
  62.     global winActive 
  63.     set files [winNames -f]
  64.     if {[llength $files] < 2} {return}
  65.     set f [lindex $files 0]
  66.     set aind [lsearch $winActive $f]
  67.     if {$aind < 0} {error "No win '$f'"}
  68.     set rng [lrange $winActive 0 [expr $aind-1]]
  69.     set winActive [concat [lrange $winActive $aind end] $rng]
  70.     set winActive [lrange $winActive 1 end]
  71.     lappend winActive $f
  72.     bringToFront [lindex $winActive 0]
  73. }
  74.  
  75.  
  76. proc prevWindow {} {
  77.     global winActive 
  78.     set files [winNames -f]
  79.     if {[llength $files] < 2} {return}
  80.     set f [lindex $files 0]
  81.     set aind [lsearch $winActive $f]
  82.     if {$aind < 0} {error "No win '$f'"}
  83.     set rng [lrange $winActive 0 [expr $aind-1]]
  84.     set winActive [concat [lrange $winActive $aind end] $rng]
  85.     set f2 [lindex [lrange $winActive end end] 0]
  86.     set winActive [lreplace $winActive end end]
  87.     set winActive [linsert $winActive 0 $f2]
  88.     bringToFront $f2
  89. }
  90.  
  91. proc bufferOtherWindow {} {
  92.     global tileHeight tileTop tileWidth
  93.     global numWinsToTile
  94.     set margin 22
  95.     set win [lindex [winNames -f] 0]
  96.     set numWins 2
  97.     set hor 2
  98.     set height [expr ($tileHeight/$numWins)-$margin]
  99.     set height [expr {$height + $margin / $numWins}]
  100.     set width $tileWidth
  101.     set ver $tileTop
  102.     
  103.     if {[llength [winNames]] < 2} {message "No other window!"; return}
  104.     set next [nextWin]
  105.     set res [statusPrompt "Window other half ($next): " winComp]
  106.     if {![string length $res]} {
  107.         set res $next
  108.     }
  109.     
  110.     set geo [getGeometry]
  111.     if {([lindex $geo 2] != $width) || ([lindex $geo 3] != $height) || ([lindex $geo 0] != $hor) || (([lindex $geo 1] != $ver) && ([lindex $geo 1] != [expr $ver + $height + $margin]))} {
  112.         moveWin $win 1000 0
  113.         sizeWin $win $width $height
  114.         moveWin $win $hor $ver
  115.         incr ver [expr $height + $margin]
  116.     } else {
  117.         if {[lindex $geo 1] == $ver} {
  118.             incr ver [expr $height + $margin]
  119.         } 
  120.     }
  121.     
  122.     set geo [getGeometry $res]
  123.     if {([lindex $geo 0] != $hor) || ([lindex $geo 1] != $ver) || ([lindex $geo 2] != $width) || ([lindex $geo 3] != $height)} {
  124.         moveWin $res 1000 0
  125.         sizeWin $res $width $height
  126.         moveWin $res $hor $ver
  127.     }
  128.     bringToFront $res
  129. }
  130.  
  131.         
  132.     
  133.         
  134.  
  135. proc winvertically {} {
  136.     global tileHeight tileTop tileWidth
  137.     global numWinsToTile
  138.     set margin 22
  139.     set names [winNames -f]
  140.     set numWins [llength $names]
  141.     if ($numWins<=1) return
  142.     if ($numWins>$numWinsToTile) {set numWins $numWinsToTile}
  143.     set height [expr ($tileHeight/$numWins)-$margin]
  144.     set height [expr {$height + $margin / $numWins}]
  145.     set width $tileWidth
  146.     set ver $tileTop
  147.     if {$numWins == 0} {return}
  148.  
  149.     for {set i 0} {$i < $numWins} {incr i} {
  150.         moveWin [lindex $names $i] 1000 0
  151.         sizeWin [lindex $names $i] $width $height
  152.     }
  153.  
  154.     for {set i 0} {$i < $numWins} {incr i} {
  155.         moveWin [lindex $names $i] 2 $ver
  156.         set ver [expr $ver+$margin+$height]
  157.     }
  158. }
  159.  
  160. proc winhorizontally {} {
  161.     global tileHeight tileWidth tileTop numWinsToTile
  162.  
  163.     set names [winNames -f]
  164.     set numWins [llength $names]
  165.     if ($numWins<=1) return
  166.     if ($numWins>$numWinsToTile) {set numWins $numWinsToTile}
  167.     set margin 4
  168.     set width [expr ($tileWidth/$numWins)-$margin]
  169.     set width [expr {$width + $margin / $numWins}]
  170.     set height $tileHeight
  171.     set hor 2
  172.     if {$numWins == 0} {return}
  173.  
  174.     for {set i 0} {$i < $numWins} {incr i} {
  175.         moveWin [lindex $names $i] 1000 0
  176.         sizeWin [lindex $names $i] $width $height
  177.     }
  178.  
  179.     for {set i 0} {$i < $numWins} {incr i} {
  180.         moveWin [lindex $names $i] $hor $tileTop
  181.         set hor [expr $hor+$width+$margin]
  182.     }
  183. }
  184.  
  185. proc wintiled {} {
  186.     global tileHeight tileWidth numWinsToTile tileTop
  187.     set xPan 8
  188.     set yPan 10
  189.     set xMarg 2
  190.     set yMarg $tileTop
  191.     set yMax 50
  192.     set names [winNames -f]
  193.     set numWins [llength $names]
  194.     if ($numWins<1) return
  195.     set line 0    
  196.     set height [expr $tileHeight-$yPan*($numWins-1)]
  197.     set width [expr $tileWidth-$xPan*($numWins-1)]
  198.     
  199.     for {set i 0} {$i < $numWins} {incr i} {
  200.         moveWin [lindex $names $i] [expr $xMarg+$i*$xPan] [expr $yMarg+$line]
  201.         set line [expr $line+$yPan]
  202.         if ($line>$yMax) {set line 0}
  203.         sizeWin [lindex $names $i] $width $height
  204.     }
  205. }
  206.  
  207.  
  208. proc winoverlay {} {
  209.     global defHeight defWidth numWinsToTile tileTop
  210.     set names [winNames -f]
  211.     set numWins [llength $names]
  212.     if ($numWins<1) return
  213.     for {set i 0} {$i < $numWins} {incr i} {
  214.         moveWin [lindex $names $i] 2 $tileTop
  215.         sizeWin [lindex $names $i] $defWidth $defHeight
  216.     }
  217. }
  218.  
  219.  
  220. proc threeQuarters {} {
  221.     global tileHeight tileWidth tileTop
  222.  
  223.     if {[llength [set nms [winNames -f]]] <= 2} return
  224.     set one [lindex $nms 0]
  225.     set two [lindex $nms 1]
  226.     set margin 22
  227.     set height [expr ($tileHeight - $margin) / 4]
  228.  
  229.     moveWin $one 1000 0
  230.     sizeWin $one $tileWidth [expr 3 * $height]
  231.     moveWin $two 1000 0
  232.     sizeWin $two $tileWidth $height
  233.  
  234.     set ver $tileTop
  235.     moveWin $one 2 $ver
  236.     moveWin $two 2 [expr $ver + 3 * $height + $margin]
  237. }
  238. bind '3' <Q> threeQuarters
  239.  
  240.  
  241. proc chooseAWindow {} {
  242.     set name [listpick [lsort -ignore [winNames]]]
  243.     if {[string length $name]} {
  244.         bringToFront $name
  245.         if [icon -q] { icon -f $name -o }
  246.        }
  247. }
  248.  
  249.  
  250. proc nextWin {} {
  251.     global winActive 
  252.     set files [winNames -f]
  253.     if {[llength $files] < 2} {return ""}
  254.     set f [lindex $files 0]
  255.     set aind [lsearch $winActive $f]
  256.     if {$aind < 0} {error "No win '$f'"}
  257.     if {[incr aind] < [llength $winActive]} {
  258.         return [file tail [lindex $winActive $aind]]
  259.     } else {
  260.         return [file tail [lindex $winActive 0]]
  261.     }
  262. }
  263.  
  264. proc winComp {curr c} {
  265.     if {$c != "\t"} {return $c}
  266.     
  267.     set matches {}
  268.     foreach w [winNames] {
  269.         if {[string match "$curr*" $w]} {
  270.             lappend matches $w
  271.         }
  272.     }
  273.     if {![llength $matches]} {
  274.         beep
  275.     } else {
  276.         return [string range [largestPrefix $matches] [string length $curr] end]
  277.     }
  278.     return ""
  279. }
  280.  
  281. proc killWindowStatus {} {
  282.     if {[llength [winNames]] >= 2} {
  283.         set next [nextWin]
  284.         set res [statusPrompt "Kill window ($next): " winComp]
  285.     } else {
  286.         set next ""
  287.         set res [statusPrompt "Kill window: " winComp]
  288.     }
  289.  
  290.     if {[string length $res]} {
  291.         catch {bringToFront $res; killWindow}
  292.     } elseif {[string length $next]} {
  293.         catch {bringToFront $next; killWindow}
  294.     }
  295. }
  296.  
  297. proc chooseWindowStatus {} {
  298.     if {[llength [winNames]] < 2} {message "No other window!"; return}
  299.     set next [nextWin]
  300.     set res [statusPrompt "Window ($next): " winComp]
  301.     if {[string length $res]} {
  302.         catch {bringToFront $res}
  303.     } else {
  304.         catch {bringToFront $next}
  305.     }
  306. }
  307. # bind f9 chooseWindowStatus
  308.  
  309. proc iconify {} { 
  310.     icon -t 
  311.     if {[icon -q]} {
  312.         nextWindow
  313.     }
  314. }
  315.  
  316.  
  317.  
  318. proc zoom {} {
  319.     global nzmState tileHeight tileWidth zoomedGeo tileTop tileLeft
  320.     
  321.     set win [lindex [winNames -f] 0]
  322.     if {[info exists nzmState($win)]} {
  323.         if {[getGeometry] == $zoomedGeo} {
  324.             set state $nzmState($win)
  325.             moveWin [lindex $state 0] [lindex $state 1]
  326.             sizeWin [lindex $state 2] [lindex $state 3]
  327.             unset nzmState($win)
  328.             return
  329.         }
  330.     } 
  331.  
  332.     set nzmState($win) [getGeometry]
  333.     moveWin $tileLeft $tileTop
  334.     sizeWin $tileWidth $tileHeight
  335.  
  336.     if {![info exists zoomedGeo]} {
  337.         set zoomedGeo [getGeometry]
  338.     }
  339. }
  340.  
  341. #================================================================================
  342.  
  343. proc otherThing {} {
  344.     set win [lindex [winNames -f] 0]
  345.     getWinInfo -w $win arr
  346.     if {$arr(split)} {
  347.         otherPane
  348.     } else {
  349.         swapWithNext
  350.     }
  351. }
  352.  
  353. proc winAttribute {att {win {}}} {
  354.     if {![string length $win]} {
  355.         set win [lindex [winNames -f] 0]
  356.     }
  357.     getWinInfo -w $win arr
  358.     return $arr($att)
  359. }
  360.  
  361.  
  362.  
  363.