home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BUG 11
/
BUGCD1998_02.ISO
/
email
/
sime
/
simdemo.z
/
xvt.tcl
< prev
Wrap
Text File
|
1997-12-09
|
22KB
|
743 lines
#############################################################################
proc calc_window_rect {parent left top right bottom} {
global windows
set parentrect [get_client_rect $parent]
set parent_width [expr [lindex $parentrect 2]-[lindex $parentrect 0]]
set parent_height [expr [lindex $parentrect 3]-[lindex $parentrect 1]]
set newleft [expr {[regsub -all {\$x} $left $parent_width blat] ? {$blat} : $left}]
set newright [expr {[regsub -all {\$x} $right $parent_width blat] ? {$blat} : $right}]
set newtop [expr {[regsub -all {\$y} $top $parent_height blat] ? {$blat} : $top}]
set newbottom [expr {[regsub -all {\$y} $bottom $parent_height blat] ? {$blat} : $bottom}]
return [list [expr $newleft] [expr $newtop] [expr $newright] [expr $newbottom]]
}
#############################################################################
proc winmapped win {
global windows
keylset windows($win) mapped 1
}
#############################################################################
proc windestroyed win {
global windows
if {[info exists windows($win)]} {
#the following line was added by Leo Pelland, April 12, 1995
# _xvt_close_win [keylget windows($win) windowptr]
unset windows($win)
}
}
#############################################################################
proc xvt_create_window {type rect title parent flags appdata} {
global windows
if {[info exists windows($title)]} {
return
}
# if parent is mapped, create it, otherwise just add to parent's kid
# list (which we do anyway) and have the parent event handler deal with it
set kids [keylget windows($parent) kidlist]
lappend kids $appdata
keylset windows($parent) kidlist $kids
_xvt_create_window $type $rect $title $parent $flags $appdata
}
#############################################################################
set ctl_id_ctr 200
proc next_control_id {} {global ctl_id_ctr; incr ctl_id_ctr; return $ctl_id_ctr;}
proc xvt_create_control {type rect title parent flags appdata} {
global windows
# if parent is mapped, create it, otherwise just add to parent's kid
# list (which we do anyway) and have the parent event handler deal with it
set kids [keylget windows($parent) kidlist]
lappend kids $appdata
keylset windows($parent) kidlist $kids
set ctl_id [next_control_id]
keylset windows($appdata) ctlid $ctl_id
_xvt_create_control $type $rect $title $parent $flags \
$appdata $ctl_id
}
#############################################################################
proc activate_control {win ctl} {
global windows
foreach i [keylget windows($win) kidlist] {
set itsid -1; catch { set itsid [keylget windows($i) ctlid] }
if {$itsid == $ctl} {
set cmd ""; catch { set cmd [keylget windows($i) command] }
if {$cmd != ""} {
eval $cmd
}
}
}
}
proc get_ctl_title ctl {
global windows
if {[keylget windows($ctl) type]=="listbutton"} {
return [listitem $ctl [listselected $ctl]]
}
return [_xvt_get_ctl_title [keylget windows([keylget windows($ctl) parent]) windowptr] \
[keylget windows($ctl) ctlid]]
}
proc set_ctl_title {ctl title} {
global windows
_xvt_set_ctl_title [keylget windows([keylget windows($ctl) parent]) windowptr] \
[keylget windows($ctl) ctlid] $title
}
proc raise win {
global windows
_xvt_raise [keylget windows($win) windowptr]
}
# HISTORY
# Created Dec 28, 1995 by ll:
# END HISTORY
proc select win {
global windows
_xvt_select_text [keylget windows($win) windowptr]
}
proc focus ctl {
global windows
set type [keylget windows($ctl) type]
if {($type == "txedit") || ($type == "txeditline")} {
_xvt_focus [keylget windows($ctl) windowptr]
} else {
_xvt_focus [keylget windows([keylget windows($ctl) parent]) windowptr] \
[keylget windows($ctl) ctlid]
}
}
#############################################################################
proc show_win win {
global windows
_xvt_show_win [keylget windows($win) windowptr] 1
}
proc hide_win win {
global windows
_xvt_show_win [keylget windows($win) windowptr] 0
}
proc close_win win {
global windows
_xvt_close_win [keylget windows($win) windowptr]
}
proc get_client_rect win {
global windows
return [_xvt_get_client_rect [keylget windows($win) windowptr]]
}
proc enable_win win {
global windows
_xvt_enable_win [keylget windows($win) windowptr] 1
}
proc disable_win win {
global windows
_xvt_enable_win [keylget windows($win) windowptr] 0
}
proc enable_control ctl {
global windows
_xvt_enable_ctl [keylget windows([keylget windows($ctl) parent]) windowptr] \
[keylget windows($ctl) ctlid] 1
}
proc disable_control ctl {
global windows
_xvt_enable_ctl [keylget windows([keylget windows($ctl) parent]) windowptr] \
[keylget windows($ctl) ctlid] 0
}
#############################################################################
defargs toplevel_opts {
{-title text "Untitled"}
{-left text 100 }
{-top text 100}
{-right text 400}
{-bottom text 400}
{-hasresize boolean false}
{-hasclose boolean true}
{-entercommand text ""}
}
proc toplevel {winname args} {
global windows
optargs $args toplevel_opts
set rect [calc_window_rect TASK_WIN $left $top $right $bottom]
set options 0
if {$hasresize=="true"} {incr options}
if {$hasclose=="true"} {incr options; incr options}
keylset windows($winname) winname $winname parent TASK_WIN left $left \
top $top right $right bottom $bottom title $title options $options \
mapped 0 kidlist {} type toplevel entercommand $entercommand
xvt_create_window W_DOC $rect $title TASK_WIN $options $winname
}
#############################################################################
defargs frame_opts {
{-parent text}
{-left text 0}
{-top text 0}
{-right text 0}
{-bottom text 0}
{-entercommand text ""}
}
proc frame {winname args} {
global windows
optargs $args frame_opts
set rect [calc_window_rect $parent $left $top $right $bottom]
keylset windows($winname) winname $winname parent $parent left $left \
top $top right $right bottom $bottom options 0 \
mapped 0 kidlist {} type frame entercommand $entercommand
xvt_create_window W_PLAIN $rect "" $parent 0 $winname
}
#############################################################################
defargs label_opts {
{-parent text}
{-title text ""}
{-left text}
{-top text}
{-right text}
{-bottom text}
}
proc label {winname args} {
global windows
optargs $args label_opts
set bottom [expr $top+[ideal_height label]]
set rect [calc_window_rect $parent $left $top $right $bottom]
keylset windows($winname) winname $winname parent $parent left $left \
top $top right $right bottom $bottom title $title options 0 \
mapped 0 kidlist {} type label
xvt_create_control WC_TEXT $rect $title $parent 0 $winname
}
#############################################################################
defargs button_opts {
{-parent text}
{-title text "Untitled"}
{-left text}
{-top text}
{-right text}
{-bottom text}
{-command text}
}
proc button {winname args} {
global windows
optargs $args button_opts
set bottom [expr $top+[ideal_height button]]
set rect [calc_window_rect $parent $left $top $right $bottom]
keylset windows($winname) winname $winname parent $parent left $left \
top $top right $right bottom $bottom title $title options 0 \
mapped 0 kidlist {} type button command $command
xvt_create_control WC_PUSHBUTTON $rect $title $parent 0 $winname
}
#############################################################################
defargs edit_opts {
{-parent text}
{-title text ""}
{-left text}
{-top text}
{-right text}
{-bottom text}
{-command text ""}
}
proc edit {winname args} {
global windows
optargs $args edit_opts
set bottom [expr $top+[ideal_height edit]]
set rect [calc_window_rect $parent $left $top $right $bottom]
keylset windows($winname) winname $winname parent $parent left $left \
top $top right $right bottom $bottom title $title options 0 \
mapped 0 kidlist {} type edit command $command
xvt_create_control WC_EDIT $rect $title $parent 0 $winname
}
#############################################################################
defargs checkbox_opts {
{-parent text}
{-title text "Check"}
{-left text}
{-top text}
{-right text}
{-bottom text}
{-variable text ""}
{-command text ""}
}
proc checkbox {winname args} {
global windows
optargs $args checkbox_opts
set bottom [expr $top+[ideal_height checkbox]]
set rect [calc_window_rect $parent $left $top $right $bottom]
keylset windows($winname) winname $winname parent $parent left $left \
top $top right $right bottom $bottom title $title options 0 \
mapped 0 kidlist {} type checkbox command "docheck $winname" \
usercmd $command variable $variable
xvt_create_control WC_CHECKBOX $rect $title $parent 0 $winname
}
proc docheck ctl {
global windows
set vbl [keylget windows($ctl) variable]
set val [_xvt_checkbox FLIP [keylget windows([keylget windows($ctl) parent]) windowptr] \
[keylget windows($ctl) ctlid]]
if {$vbl != ""} {
global $vbl
set $vbl $val
}
if {[keylget windows($ctl) usercmd] != ""} {
eval [keylget windows($ctl) usercmd]
}
}
proc check {ctl check} {
global windows
set vbl [keylget windows($ctl) variable]
set val [_xvt_checkbox SET [keylget windows([keylget windows($ctl) parent]) windowptr] \
[keylget windows($ctl) ctlid] $check]
if {$vbl != ""} {
global $vbl
set $vbl $val
}
}
proc checked ctl {
global windows
return [_xvt_checkbox GET [keylget windows([keylget windows($ctl) parent]) windowptr] \
[keylget windows($ctl) ctlid]]
}
#############################################################################
defargs tree_opts {
{-parent text}
{-left text}
{-top text}
{-right text}
{-bottom text}
}
proc tree {winname args} {
global windows
optargs $args label_opts
set rect [calc_window_rect $parent $left $top $right $bottom]
keylset windows($winname) winname $winname parent $parent left $left \
top $top right $right bottom $bottom \
mapped 0 kidlist {} type tree
xvt_create_control $rect $parent $winname
}
proc xvt_create_tree {rect parent winname} {
global windows
# if parent is mapped, create it, otherwise just add to parent's kid
# list (which we do anyway) and have the parent event handler deal with it
set kids [keylget windows($parent) kidlist]
lappend kids $appdata
keylset windows($parent) kidlist $kids
_xvt_create_tree $rect $parent $winname
}
#############################################################################
defargs radiobutton_opts {
{-parent text}
{-title text "Radio"}
{-left text}
{-top text}
{-right text}
{-bottom text}
{-variable text ""}
{-value text ""}
{-command text ""}
}
proc radiobutton {winname args} {
global windows radiovars
optargs $args radiobutton_opts
set bottom [expr $top+[ideal_height radiobutton]]
set rect [calc_window_rect $parent $left $top $right $bottom]
keylset windows($winname) winname $winname parent $parent left $left \
top $top right $right bottom $bottom title $title options 0 \
mapped 0 kidlist {} type radiobutton command "dochoose $winname" \
usercmd $command variable $variable value $value
if {[info exists radiovars($variable)]==0} {
set radiovars($variable) $winname
} else {
lappend radiovars($variable) $winname
}
xvt_create_control WC_RADIOBUTTON $rect $title $parent 0 $winname
}
proc dochoose ctl {
global windows radiovars
set vbl [keylget windows($ctl) variable]
set val [keylget windows($ctl) value]
set tmp ""; set cnt 0;
foreach i $radiovars($vbl) {
lappend tmp [keylget windows([keylget windows($i) parent]) windowptr]
lappend tmp [keylget windows($i) ctlid]
incr cnt
}
eval _xvt_radiobutton SET [keylget windows([keylget windows($ctl) parent]) windowptr] \
[keylget windows($ctl) ctlid] $cnt $tmp
if {$vbl != ""} {
global $vbl
set $vbl $val
}
if {[keylget windows($ctl) usercmd] != ""} {
eval [keylget windows($ctl) usercmd]
}
}
proc choose {ctl} {
dochoose $ctl
}
proc chosen ctl {
global windows
return [_xvt_radiobutton GET [keylget windows([keylget windows($ctl) parent]) windowptr] \
[keylget windows($ctl) ctlid]]
}
#############################################################################
defargs txedit_opts {
{-parent text}
{-left text}
{-top text}
{-right text}
{-bottom text}
{-command text ""}
}
proc txedit {winname args} {
global windows
optargs $args txedit_opts
set rect [calc_window_rect $parent $left $top $right $bottom]
keylset windows($winname) winname $winname parent $parent left $left \
top $top right $right bottom $bottom options 0 \
mapped 0 kidlist {} type txedit command $command
xvt_create_control TXEDIT $rect "" $parent 0 $winname
}
#############################################################################
defargs txeditline_opts {
{-parent text}
{-left text}
{-top text}
{-right text}
{-bottom text}
{-command text ""}
}
proc txeditline {winname args} {
global windows
optargs $args txeditline_opts
set rect [calc_window_rect $parent $left $top $right $bottom]
keylset windows($winname) winname $winname parent $parent left $left \
top $top right $right bottom $bottom options 0 \
mapped 0 kidlist {} type txeditline command $command
xvt_create_control TXEDITLINE $rect "" $parent 0 $winname
}
#############################################################################
defargs groupbox_opts {
{-parent text}
{-title text ""}
{-left text}
{-top text}
{-right text}
{-bottom text}
}
proc groupbox {winname args} {
global windows
optargs $args groupbox_opts
set rect [calc_window_rect $parent $left $top $right $bottom]
keylset windows($winname) winname $winname parent $parent left $left \
top $top right $right bottom $bottom title $title options 0 \
mapped 0 kidlist {} type groupbox
xvt_create_control WC_GROUPBOX $rect $title $parent 0 $winname
}
#############################################################################
defargs listbox_opts {
{-parent text}
{-left text}
{-top text}
{-right text}
{-bottom text}
{-command text ""}
}
proc listbox {winname args} {
global windows
optargs $args listbox_opts
set rect [calc_window_rect $parent $left $top $right $bottom]
keylset windows($winname) winname $winname parent $parent left $left \
top $top right $right bottom $bottom title "" options 0 \
mapped 0 kidlist {} type listbox command $command
xvt_create_control WC_LBOX $rect "" $parent 0 $winname
}
#############################################################################
defargs listbutton_opts {
{-parent text}
{-left text}
{-top text}
{-right text}
{-bottom text}
{-command text ""}
}
proc listbutton {winname args} {
global windows
optargs $args listbutton_opts
set rect [calc_window_rect $parent $left $top $right $bottom]
keylset windows($winname) winname $winname parent $parent left $left \
top $top right $right bottom $bottom title "" options 0 \
mapped 0 kidlist {} type listbutton command $command
xvt_create_control WC_LISTBUTTON $rect "" $parent 0 $winname
}
#############################################################################
defargs listedit_opts {
{-parent text}
{-left text}
{-top text}
{-right text}
{-bottom text}
{-command text ""}
}
proc listedit {winname args} {
global windows
optargs $args listedit_opts
set rect [calc_window_rect $parent $left $top $right $bottom]
keylset windows($winname) winname $winname parent $parent left $left \
top $top right $right bottom $bottom title "" options 0 \
mapped 0 kidlist {} type listedit command $command
xvt_create_control WC_LISTEDIT $rect "" $parent 0 $winname
}
#############################################################################
proc listadd {list index args} { global windows
eval _xvt_list add [keylget windows([keylget windows($list) parent]) windowptr] \
[keylget windows($list) ctlid] $index $args
}
proc listclear list { global windows
_xvt_list clear [keylget windows([keylget windows($list) parent]) windowptr] \
[keylget windows($list) ctlid]
}
proc listcount list { global windows
return [_xvt_list count [keylget windows([keylget windows($list) parent]) windowptr] \
[keylget windows($list) ctlid]]
}
proc listdel {list index} { global windows
_xvt_list delete [keylget windows([keylget windows($list) parent]) windowptr] \
[keylget windows($list) ctlid] $index
}
proc listitem {list index} { global windows
return [_xvt_list item [keylget windows([keylget windows($list) parent]) windowptr] \
[keylget windows($list) ctlid] $index]
}
proc listselected {list} { global windows
return [_xvt_list selected [keylget windows([keylget windows($list) parent]) windowptr] \
[keylget windows($list) ctlid]]
}
proc listselect {list index} { global windows
_xvt_list select [keylget windows([keylget windows($list) parent]) windowptr] \
[keylget windows($list) ctlid] $index 1
}
proc listunselect {list index} { global windows
_xvt_list select [keylget windows([keylget windows($list) parent]) windowptr] \
[keylget windows($list) ctlid] $index 0
}
proc listsuspend {list} { global windows
_xvt_list suspend [keylget windows([keylget windows($list) parent]) windowptr] \
[keylget windows($list) ctlid]
}
proc listresume {list} { global windows
_xvt_list resume [keylget windows([keylget windows($list) parent]) windowptr] \
[keylget windows($list) ctlid]
}
#############################################################################
keylset windows(TASK_WIN) winname TASK_WIN parent NULL left 0 \
top 0 right 640 bottom 400 mapped 1 kidlist {} type task
# by Leo Pelland in November 1994
proc focus_next_kid {win ctl} {
global windows
#note "in focus_next_kid in xvt.tcl: beginning, win = $win, ctl = $ctl"
# // set "last" to 0 to indicate that we have not yet found the control that
# // has the focus
set last 0
# // get the list of subwindows
set kidpresent [keylget windows($win) kidlist {}]
# // continue if we have subwindows
if {$kidpresent == 1} {
# // if no control has the focus, give the focus to the first valid control
set topwin [keylget windows($win) windowptr]
#note "topwin = $topwin, ctl = $ctl"
if { $topwin == $ctl} {set last 1}
#note "break 3"
# // loop through the windows to find the one who has the focus, then set
# // the focus to the next valid control
#note "break 4"
foreach i [keylget windows($win) kidlist] {
#note "focus next kid: begin of for loop, i = $i"
if {$last == 1} {
#note "last = 1"
set a [keylget windows($i) type]
# // if we are on a valid control window, give it the focus and exit
if {($a == "edit") || ($a == "txedit") || ($a == "txeditline")} {
#note "in focus_next_kid in xvt.tcl: focus now = $a"
focus $i
break
}
} else {
set b [keylget windows($i) windowptr]
#note "keep track of prev window, b = $b, ctl = $ctl"
# // set "last" to 1 if we are on the window which has the focus
if {$b == $ctl} {
#note "we are on the window who has the focus"
set last 1
}
}
}
}
}
# by Leo Pelland on March 22, 1995
proc focus_prev_kid {win ctl} {
global windows
# // set "first" to 1 to indicate that we don't have a valid previous control
set first 1
# // get the list of sub windows
set kidpresent [keylget windows($win) kidlist {}]
# // if we have some windows, continue
if {$kidpresent == 1} {
# // if no control has the focus, simply return
if {[keylget windows($win) windowptr] == $ctl} {break}
# // loop through the windows, find the one who has the focus and
# // then, give the focus the the previous control window
foreach i [keylget windows($win) kidlist] {
set current_control [keylget windows($i) windowptr]
if {$current_control == $ctl} {
# // if the first control has the focus or there is no valid previous
# // control, simply give control to the container who will decide what to do
if {$first == 1} {
go_to_container [keylget windows($win) windowptr]
break
}
# // give the focus to the previous valid control
focus $prev_control
break
} else {
# // get the control's type and if it's a valid control, assign it to
# // "prev_control" and set "first" to 0 to indicate that we have a
# // valid previous control
set a [keylget windows($i) type]
if {($a == "edit") || ($a == "txedit") || ($a == "txeditline")} {
set prev_control $i
set first 0
}
}
}
}
}
# by Leo Pelland on June 17, 1995
proc focus_last_kid {win} {
global windows
set focus_window "invalid"
# // get the list of subwindows
set kidpresent [keylget windows($win) kidlist {}]
# // continue if we have subwindows
if {$kidpresent == 1} {
# // loop through the windows to find the one who has the focus, then set
# // the focus to the next valid control
foreach i [keylget windows($win) kidlist] {
set a [keylget windows($i) type]
# // if we are on a valid control window, set it as the focus window
if {($a == "edit") || ($a == "txedit") || ($a == "txeditline")} {
set focus_window $i
}
}
}
# // if we have found a valid object, give it the focus
if {$focus_window != "invalid"} {focus $focus_window}
}
# by Leo Pelland on June 17, 1995
proc focus_first_kid {win} {
global windows
# // get the list of subwindows
set kidpresent [keylget windows($win) kidlist {}]
# // continue if we have subwindows
if {$kidpresent == 1} {
foreach i [keylget windows($win) kidlist] {
set a [keylget windows($i) type]
# // if we are on a valid control window, give it the focus and exit
if {($a == "edit") || ($a == "txedit") || ($a == "txeditline")} {
focus $i
break
}
}
}
}