home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/wish
- # edit the line above, if wish is installed somewhere else. BK...
- set lib /usr/local/share/greyboard
- # edit the line above, if greyboard library is installed somewhere else
-
- # greyboard v0.7, copyright (c) A.Grozin, 1995, 1997, 1999
- # GNU General Public License
-
- global env host_name lib s_cur s_lst screen con_scr from_scr \
- main_x main_y main_Y help_x help_y mode save_file undo undo_info \
- col color bgcolor grey dark l_col r_col font bold italic size msg info \
- obj o_lst o_num o_cur t_lst t_num foc_t x y t0 timeout \
- allow_erase allow_erase_all allow_connect allow_disconnect allow_save \
- text_left text_sig text_time \
- c_allow_erase c_allow_erase_all c_allow_connect c_allow_disconnect c_allow_save \
- c_text_left c_text_sig c_text_time c_board_width c_board_height c_board_number c_timeout
-
- # screens
- set s_cur 0
- set s_lst {}
-
- # colors
- set color(0) #ff0000
- set color(1) #00ff00
- set color(2) #0000ff
- set color(3) #ffff00
- set color(4) #ff00ff
- set color(5) #00ffff
- set color(6) #ffffff
- set color(7) #000000
- set bgcolor #d9d9d9
- set grey #808080
- set dark #606060
-
- # main window size
- set main_x 480
- set main_y 360
- set main_Y 720
-
- # help window size
- set help_x 40
- set help_y 20
-
- # messages
- set msg(0) {{Drag the mouse with left button to draw a curve}}
- set msg(1) {{Click the left button to start a broken line}}
- set msg(2) {{Click the left button to start a text}}
- set msg(3) {{Select an object to delete}}
- set msg(4) {{Click the left button for next segment, right - for last one}}
- set msg(5) {{Click the left button to delete the selected object}}
- set msg(6) {{Click the left button to set the text cursor}}
-
- # beep timeout
- set timeout 60
-
- # objects
- set o_num 0
- set o_lst {}
- set t_num 0
- set t_lst {}
-
- set save_file "gb.ps"
-
- proc win {} {
- global s_cur s_lst env screen con_scr mode col color bgcolor grey dark\
- font bold italic size lib undo main_x main_y main_Y from_scr host_name t0
- set s $s_cur
- if [catch {set host_name greyboard@$env(HOSTNAME)}] {set host_name greyboard}
-
- if {$s==0} {
- wm title . $host_name
- frame .a0
- pack .a0
- set t0 [clock seconds]
- } else {
- if [catch "toplevel .a$s -screen $con_scr"] {Err_con $from_scr; return}
- wm title .a$s $host_name
- }
-
- # menu
- # ----
- frame .a$s.menu
- pack .a$s.menu -side top -fill x
-
- set m .a$s.menu.file.menu
- menubutton .a$s.menu.file -text "File" -underline 0 \
- -menu .a$s.menu.file.menu -bd 4 -relief raised
- menu $m -tearoff 0 -disabledforeground $dark
- $m add command -label "Connect..." -underline 0 -command "Connect $s"
- $m add command -label "Save..." -underline 0 -command "Save $s"
- $m add command -label "List..." -underline 0 -command "List $s"
- $m add command -label "Exit" -underline 1 -command "Exit $s"
-
- set m .a$s.menu.edit.menu
- menubutton .a$s.menu.edit -text "Edit" -underline 0 \
- -menu .a$s.menu.edit.menu -bd 4 -relief raised
- menu $m -tearoff 0 -disabledforeground $dark
- $m add command -label "Undo" -underline 0 -command "Undo $s"
- $m add command -label "More space" -underline 0 -command "More"
- $m add command -label "Beep" -underline 0 -command "Beep $s"
- $m add command -label "Clear all" -underline 6 -command "Clear $s"
-
- set m .a$s.menu.options.menu
- menubutton .a$s.menu.options -text Options -underline 0 \
- -menu .a$s.menu.options.menu -bd 4 -relief raised
- menu $m -tearoff 0 -disabledforeground $dark
- if {$s==0} { $m add command -label "Configuration..." -command "Config"
- $m add separator
- }
- $m add radiobutton -label "Times" -underline 0 -variable font($s) -value 0
- $m add radiobutton -label "Helvetica" -underline 0 -variable font($s) -value 1
- $m add radiobutton -label "Courier" -underline 0 -variable font($s) -value 2
- $m add separator
- $m add checkbutton -label "Bold" -underline 0 -variable bold($s)
- $m add checkbutton -label "Italic" -underline 0 -variable italic($s)
- $m add separator
- $m add radiobutton -label "10" -underline 0 -variable size($s) -value 10
- $m add radiobutton -label "12" -underline 0 -variable size($s) -value 12
- $m add radiobutton -label "14" -underline 0 -variable size($s) -value 14
- $m add radiobutton -label "18" -underline 0 -variable size($s) -value 18
- $m add radiobutton -label "24" -underline 0 -variable size($s) -value 24
- set bold($s) 0
- set italic($s) 0
- if {$s==0} {
- $m invoke 3
- $m invoke 11
- } else {
- $m invoke 1
- $m invoke 9
- }
-
- button .a$s.menu.help -text Help -underline 0 \
- -command "Help $s" -bd 4 -relief raised
- pack .a$s.menu.file .a$s.menu.edit .a$s.menu.options \
- -side left -padx 4 -pady 4
- pack .a$s.menu.help -side right -padx 4 -pady 4
-
- # tool bar
- # --------
- label .a$s.status -anchor w
- frame .a$s.tool
- pack .a$s.status -side bottom -fill x
- pack .a$s.tool -side bottom -fill x
- radiobutton .a$s.tool.curve -bitmap @$lib/curve -underline 0 -disabledforeground $dark \
- -variable mode($s) -value 0 -command "Mode $s" \
- -bd 4 -indicatoron 0 -selectcolor $bgcolor
- radiobutton .a$s.tool.line -bitmap @$lib/line -underline 0 -disabledforeground $dark \
- -variable mode($s) -value 1 -command "Mode $s" \
- -bd 4 -indicatoron 0 -selectcolor $bgcolor
- radiobutton .a$s.tool.text -bitmap @$lib/text -underline 0 -disabledforeground $dark \
- -variable mode($s) -value 2 -command "Mode $s" \
- -bd 4 -indicatoron 0 -selectcolor $bgcolor
- radiobutton .a$s.tool.del -bitmap @$lib/delete -underline 0 -disabledforeground $dark \
- -variable mode($s) -value 3 -command "Mode $s" \
- -bd 4 -indicatoron 0 -selectcolor $bgcolor
- pack .a$s.tool.curve .a$s.tool.line .a$s.tool.text .a$s.tool.del \
- -side left -padx 4 -pady 4
- set mode($s) 0
- bind .a$s.tool.curve <Enter> ".a$s.status configure \
- -text {Draw curves with mouse}"
- bind .a$s.tool.curve <Any-Leave> ".a$s.status configure \
- -text {}"
- bind .a$s.tool.line <Enter> ".a$s.status configure \
- -text {Draw broken straight lines with mouse}"
- bind .a$s.tool.line <Any-Leave> ".a$s.status configure \
- -text {}"
- bind .a$s.tool.text <Enter> ".a$s.status configure \
- -text {Type texts with keyboard}"
- bind .a$s.tool.text <Any-Leave> ".a$s.status configure \
- -text {}"
- bind .a$s.tool.del <Enter> ".a$s.status configure \
- -text {Delete objects with mouse}"
- bind .a$s.tool.del <Any-Leave> ".a$s.status configure \
- -text {}"
-
- # canvas
- # ------
- scrollbar .a$s.scroll -command ".a$s.c yview"
- pack .a$s.scroll -side right -fill y
- frame .a$s.color
- pack .a$s.color -side left -fill y
- for {set c 0} {$c<8} {incr c} {
- radiobutton .a$s.color.c$c -bitmap @$lib/f16x16 \
- -fg $color($c) -activeforeground $color($c) \
- -variable col($s) -value $c -command "Curs $s"\
- -bd 4 -indicatoron 0 -selectcolor $bgcolor
- pack .a$s.color.c$c -side top -padx 4 -pady 4
- }
- set col($s) [expr $s % 8]
- canvas .a$s.c -bd 4 -relief sunken -width $main_x -height $main_y -bg $grey \
- -scrollregion "0 0 $main_x $main_Y" -yscrollcommand ".a$s.scroll set" \
- -yscrollincrement 8
- pack .a$s.c -expand yes -fill both
- bind .a$s.c <Any-Leave> ".a$s.status configure -text {}"
-
- focus .a$s.c
- bind .a$s.c <Prior> ".a$s.c yview scroll -1 page"
- bind .a$s.c <Next> ".a$s.c yview scroll 1 page"
- bind .a$s.c <Up> ".a$s.c yview scroll -1 unit"
- bind .a$s.c <Down> ".a$s.c yview scroll 1 unit"
- bind .a$s.c <Alt-h> "Help $s"
- bind .a$s.c <Alt-c> "Connect $s"
- bind .a$s.c <Alt-s> "Save $s"
- bind .a$s.c <Alt-l> "List $s"
- bind .a$s.c <Alt-x> "after idle Exit $s"
- bind .a$s.c <Alt-u> "Undo $s"
- bind .a$s.c <Alt-m> "More"
- bind .a$s.c <Alt-Return> "More"
- bind .a$s.c <Alt-b> "Beep $s"
- bind .a$s.c <Alt-a> "Clear $s"
- Mode $s
- lappend s_lst $s
- set screen($s) $con_scr
- incr s_cur
- set undo($s) 0
- }
-
- proc Connect s {
- global screen con_scr from_scr
- set from_scr $s
- catch {destroy .con$s}
- catch {destroy .err$s}
- toplevel .con$s -screen $screen($s)
- wm title .con$s "Connect"
- frame .con$s.up
- frame .con$s.down
- pack .con$s.up -side top
- pack .con$s.down -side bottom -fill x
- label .con$s.up.label -text "Connect to "
- entry .con$s.up.entry -textvar con_scr -bd 4 -relief sunken
- pack .con$s.up.label .con$s.up.entry -side left -padx 4 -pady 4
- button .con$s.down.ok -text "OK" -bd 4 -relief raised \
- -command "win; destroy .con$s; return"
- button .con$s.down.cancel -text "Cancel" -bd 4 -relief raised \
- -command "destroy .con$s; return"
- pack .con$s.down.ok -side left
- pack .con$s.down.cancel -side right
- focus .con$s.up.entry
- bind .con$s.up.entry <Return> ".con$s.down.ok invoke"
- bind .con$s.up.entry <Escape> ".con$s.down.cancel invoke"
- }
-
- proc Err_con s {
- global screen con_scr
- catch {destroy .con$s}
- catch {destroy .err$s}
- toplevel .err$s -screen $screen($s)
- wm title .err$s "Error"
- frame .err$s.up
- pack .err$s.up -side top -fill x
- button .err$s.up.ok -text "Close" -bd 4 -relief raised \
- -command "destroy .err$s; return"
- pack .err$s.up.ok -side left
- label .err$s.down -text "Can't connect to $con_scr"
- pack .err$s.down -side bottom
- focus .err$s.up.ok
- bind .err$s.up.ok <Return> ".err$s.up.ok invoke"
- bind .err$s.up.ok <Escape> ".err$s.up.ok invoke"
- }
-
- proc Help s {
- global screen lib help_x help_y
- catch {destroy .help$s}
- toplevel .help$s -screen $screen($s)
- wm title .help$s "Help"
- frame .help$s.up
- pack .help$s.up -side top -fill x
- button .help$s.up.ok -text "Close" -bd 4 -relief raised \
- -command "destroy .help$s; return"
- pack .help$s.up.ok -side left
- text .help$s.text -bd 4 -relief sunken -height $help_y -width $help_x \
- -yscrollcommand ".help$s.scroll set"
- scrollbar .help$s.scroll -command ".help$s.text yview"
- pack .help$s.scroll -side right -fill y
- pack .help$s.text -expand yes -fill both
- set file [open "$lib/help" r]
- .help$s.text insert 0.0 [read $file]
- close $file
- focus .help$s
- bind .help$s <Return> ".help$s.up.ok invoke"
- bind .help$s <Escape> ".help$s.up.ok invoke"
- }
-
- proc Save s {
- global screen save_file
- catch {destroy .save$s}
- toplevel .save$s -screen $screen($s)
- wm title .save$s "Save"
- frame .save$s.up
- frame .save$s.down
- pack .save$s.up -side top
- pack .save$s.down -side bottom -fill x
- label .save$s.up.label -text "Save as "
- entry .save$s.up.entry -textvar save_file -bd 4 -relief sunken
- pack .save$s.up.label .save$s.up.entry -side left -padx 4 -pady 4
- button .save$s.down.ok -text "OK" -bd 4 -relief raised \
- -command "Save_file $s"
- button .save$s.down.cancel -text "Cancel" -bd 4 -relief raised \
- -command "destroy .save$s; return"
- pack .save$s.down.ok -side left
- pack .save$s.down.cancel -side right
- focus .save$s.up.entry
- bind .save$s.up.entry <Return> ".save$s.down.ok invoke"
- bind .save$s.up.entry <Escape> ".save$s.down.cancel invoke"
- }
-
- proc Save_file s {
- global save_file
- .a$s.c postscript -file $save_file
- destroy .save$s
- }
-
- proc List s {
- global screen s_lst col color grey
- set lmax 0
- foreach s1 $s_lst {
- set l [string length $screen($s1)]
- if {$l > $lmax} {set lmax $l}
- }
- set n [llength $s_lst]
- catch {destroy .lst$s}
- toplevel .lst$s -screen $screen($s)
- wm title .lst$s "List"
- frame .lst$s.up
- pack .lst$s.up -side top -fill x
- button .lst$s.up.ok -text "Close" -bd 4 -relief raised \
- -command "destroy .lst$s; return"
- pack .lst$s.up.ok -side left
- entry .lst$s.inp -bd 4 -relief sunken -bg $grey -fg $color($col($s))
- pack .lst$s.inp -side bottom
- frame .lst$s.txt
- pack .lst$s.txt -side bottom
- label .lst$s.txt.label -text "Send message "
- pack .lst$s.txt.label -side left
- button .lst$s.txt.button -text "To all" -bd 4 -relief raised \
- -command "Send_all $s"
- pack .lst$s.txt.button -side right
- text .lst$s.down -bd 4 -relief sunken -bg $grey -fg $color($col($s)) -height $n -width $lmax
- set delim ""
- foreach s1 $s_lst {
- .lst$s.down insert end $delim l$s1 $screen($s1) l$s1
- .lst$s.down tag configure l$s1 -foreground $color($col($s1))
- .lst$s.down tag bind l$s1 <1> "Send $s $s1"
- .lst$s.down tag bind l$s1 <Return> "Send $s $s1"
- set delim "\n"
- }
- pack .lst$s.down -side left
- focus .lst$s.inp
- bind .lst$s.inp <Return> ".lst$s.txt.button invoke"
- bind .lst$s.inp <Escape> ".lst$s.up.ok invoke"
- bind .lst$s.down <Escape> ".lst$s.up.ok invoke"
- }
-
- proc Send {s s1} {
- set message [.lst$s.inp get]
- if {$message==""} {
- bell -displayof .a$s1
- } else {
- Msg $s $s1 $message
- }
- set message {}
- }
-
- proc Send_all s {
- global s_lst
- set message [.lst$s.inp get]
- if {$message==""} {
- Beep $s
- } else {
- foreach s1 $s_lst {if {$s1!=$s} {Msg $s $s1 $message}}
- }
- set message {}
- }
-
- proc Msg {s s1 message} {
- global screen grey col color
- catch {destroy .msg$s1}
- toplevel .msg$s1 -screen $screen($s1)
- wm title .msg$s1 "Message"
- frame .msg$s1.up
- pack .msg$s1.up -side top
- button .msg$s1.up.button -text "Close" -bd 4 -relief raised \
- -command "destroy .msg$s1; return"
- pack .msg$s1.up.button -side left
- label .msg$s1.up.label -bg red -fg white -text "Message from $screen($s)"
- pack .msg$s1.up.label -side right
- label .msg$s1.down -bg $grey -fg $color($col($s)) -relief sunken -bd 4 \
- -text $message
- pack .msg$s1.down -side left
- focus .msg$s1.up.button
- bind .msg$s1.up.button <Return> ".msg$s1.up.button invoke"
- bind .msg$s1.up.button <Escape> ".msg$s1.up.button invoke"
- bell -displayof .a$s1
- }
-
- proc Exit s {
- global s_lst
- if {$s==0} {exit} else {
- destroy .a$s
- set i [lsearch -exact $s_lst $s]
- set s_lst [lreplace $s_lst $i $i]
- }
- }
-
- proc Config {} {
- global screen \
- c_allow_erase c_allow_erase_all c_allow_connect c_allow_disconnect c_allow_save \
- c_text_left c_text_sig c_text_time c_board_width c_board_height c_board_number c_timeout
- catch {destroy .cnf}
- toplevel .cnf -screen $screen(0)
- wm title .cnf "Configuration"
- # buttons
- frame .cnf.down
- pack .cnf.down -side bottom -fill x
- button .cnf.down.close -bd 4 -relief raised -text "Close" \
- -command "destroy .cnf; return"
- button .cnf.down.apply -bd 4 -relief raised -text "Apply" \
- -command "Config_all"
- button .cnf.down.save -bd 4 -relief raised -text "Save" \
- -command "Config_save"
- button .cnf.down.restore -bd 4 -relief raised -text "Restore" \
- -command "Config_restore"
- pack .cnf.down.close .cnf.down.apply -side left -padx 4 -pady 4 -anchor w
- pack .cnf.down.restore .cnf.down.save -side right -padx 4 -pady 4 -anchor e
- # Allow others
- frame .cnf.allow -bd 4 -relief sunken
- pack .cnf.allow -side left -padx 4 -pady 4
- label .cnf.allow.label -anchor w -text "Allow others to"
- checkbutton .cnf.allow.erase -bd 4 -relief raised -text "Erase" \
- -variable c_allow_erase
- checkbutton .cnf.allow.erase_all -bd 4 -relief raised -text "Erase all" \
- -variable c_allow_erase_all
- checkbutton .cnf.allow.connect -bd 4 -relief raised -text "Connect" \
- -variable c_allow_connect
- checkbutton .cnf.allow.disconnect -bd 4 -relief raised -text "Disconnect" \
- -variable c_allow_disconnect
- checkbutton .cnf.allow.save -bd 4 -relief raised -text "Save" \
- -variable c_allow_save
- pack .cnf.allow.label .cnf.allow.erase .cnf.allow.erase_all \
- .cnf.allow.connect .cnf.allow.disconnect .cnf.allow.save \
- -side top -padx 4 -pady 4 -anchor w
- # Texts
- frame .cnf.text -bd 4 -relief sunken
- pack .cnf.text -side left -padx 4 -pady 4 -anchor n
- label .cnf.text.label -anchor w -text "Texts"
- checkbutton .cnf.text.left -bd 4 -relief raised -text "Start at the left" \
- -variable c_text_left
- checkbutton .cnf.text.sig -bd 4 -relief raised -text "Insert signature" \
- -variable c_text_sig
- checkbutton .cnf.text.time -bd 4 -relief raised -text "Insert time" \
- -variable c_text_time
- pack .cnf.text.label .cnf.text.left .cnf.text.sig .cnf.text.time \
- -side top -padx 4 -pady 4 -anchor w
- # Board geometry
- frame .cnf.inp -bd 4 -relief flat
- pack .cnf.inp -side right -padx 4 -pady 4 -anchor n
- entry .cnf.inp.width -bd 4 -relief sunken -width 5 -textvar c_board_width
- entry .cnf.inp.height -bd 4 -relief sunken -width 5 -textvar c_board_height
- entry .cnf.inp.number -bd 4 -relief sunken -width 5 -textvar c_board_number
- entry .cnf.inp.time -bd 4 -relief sunken -width 5 -textvar c_timeout
- pack .cnf.inp.width .cnf.inp.height .cnf.inp.number .cnf.inp.time \
- -side top -padx 4 -pady 4 -anchor w
- frame .cnf.lab -bd 4 -relief flat
- pack .cnf.lab -side right -padx 4 -pady 4 -anchor n
- label .cnf.lab.width -bd 4 -relief flat -text "Board width"
- label .cnf.lab.height -bd 4 -relief flat -text "Board height"
- label .cnf.lab.number -bd 4 -relief flat -text "Board number"
- label .cnf.lab.time -bd 4 -relief flat -text "Beep timeout"
- pack .cnf.lab.width .cnf.lab.height .cnf.lab.number .cnf.lab.time \
- -side top -padx 4 -pady 5 -anchor w
- # keyboard bindings
- focus .cnf.inp.width
- bind .cnf.inp.width <Return> ".cnf.down.apply invoke"
- bind .cnf.inp.width <Escape> ".cnf.down.close invoke"
- bind .cnf.inp.height <Return> ".cnf.down.apply invoke"
- bind .cnf.inp.height <Escape> ".cnf.down.close invoke"
- bind .cnf.inp.number <Return> ".cnf.down.apply invoke"
- bind .cnf.inp.number <Escape> ".cnf.down.close invoke"
- bind .cnf.inp.time <Return> ".cnf.down.apply invoke"
- bind .cnf.inp.time <Escape> ".cnf.down.close invoke"
- }
-
- proc Config_restore {} {
- global env lib \
- c_allow_erase c_allow_erase_all c_allow_connect c_allow_disconnect c_allow_save \
- c_text_left c_text_sig c_text_time c_board_width c_board_height c_board_number c_timeout
- if [file exists "$env(HOME)/.greyboardrc"] {
- source "$env(HOME)/.greyboardrc"
- } else {
- source "$lib/greyboardrc"
- }
- }
-
- proc Config_save {} {
- global env \
- c_allow_erase c_allow_erase_all c_allow_connect c_allow_disconnect c_allow_save \
- c_text_left c_text_sig c_text_time c_board_width c_board_height c_board_number c_timeout
- if [Config_check] { bell; return }
- set file [open "$env(HOME)/.greyboardrc" w]
- puts $file "set c_allow_erase $c_allow_erase"
- puts $file "set c_allow_erase_all $c_allow_erase_all"
- puts $file "set c_allow_connect $c_allow_connect"
- puts $file "set c_allow_disconnect $c_allow_disconnect"
- puts $file "set c_allow_save $c_allow_save"
- puts $file "set c_text_left $c_text_left"
- puts $file "set c_text_sig $c_text_sig"
- puts $file "set c_text_time $c_text_time"
- puts $file "set c_board_width $c_board_width"
- puts $file "set c_board_height $c_board_height"
- puts $file "set c_board_number $c_board_number"
- puts $file "set c_timeout $c_timeout"
- close $file
- }
-
- proc Config_check {} {
- global c_board_width c_board_height c_board_number c_timeout
- if {![regexp {^[0-9]+$} $c_board_width]} {return 1}
- if {![regexp {^[0-9]+$} $c_board_height]} {return 1}
- if {![regexp {^[0-9]+$} $c_board_number]} {return 1}
- if {![regexp {^[0-9]+$} $c_timeout]} {return 1}
- if {[string length $c_board_width]>5} {return 1}
- if {[string length $c_board_height]>5} {return 1}
- if {[string length $c_board_number]>5} {return 1}
- if {[string length $c_timeout]>5} {return 1}
- if {$c_board_number==0} {return 1}
- return 0
- }
-
- proc Config_all {} {
- global s_lst mode main_x main_y main_Y timeout \
- allow_erase allow_erase_all allow_connect allow_disconnect allow_save \
- text_left text_sig text_time \
- c_allow_erase c_allow_erase_all c_allow_connect c_allow_disconnect c_allow_save \
- c_text_left c_text_sig c_text_time c_board_width c_board_height c_board_number c_timeout
- if [Config_check] { bell; return }
- # has geometry changed?
- set geom 0
- set c_board_Height [expr $c_board_height*$c_board_number]
- if {$c_board_width!=$main_x} {set geom 1}
- if {$c_board_height!=$main_y} {set geom 1}
- if {$c_board_Height!=$main_Y} {set geom 1}
- set main_x $c_board_width
- set main_y $c_board_height
- set main_Y $c_board_Height
- set text_left $c_text_left
- set text_sig $c_text_sig
- set text_time $c_text_time
- set timeout $c_timeout
- set allow_erase $c_allow_erase
- set allow_erase_all $c_allow_erase_all
- set allow_connect $c_allow_connect
- set allow_disconnect $c_allow_disconnect
- set allow_save $c_allow_save
- # configuring all windows
- foreach s1 $s_lst {
- if {$geom} {
- .a$s1.c configure -width $main_x -height $main_y -scrollregion "0 0 $main_x $main_Y"
- }
- if {$s1!=0} {
- set m .a$s1.menu.file.menu
- if {$allow_connect} {
- $m entryconfigure 0 -state normal
- bind .a$s1.c <Alt-c> "Connect $s1"
- } else {
- $m entryconfigure 0 -state disabled
- bind .a$s1.c <Alt-c> {}
- }
- if {$allow_save} {
- $m entryconfigure 1 -state normal
- bind .a$s1.c <Alt-s> "Save $s1"
- } else {
- $m entryconfigure 1 -state disabled
- bind .a$s1.c <Alt-s> {}
- }
- if {$allow_disconnect} {
- $m entryconfigure 3 -state normal
- bind .a$s1.c <Alt-x> "after idle Exit $s1"
- } else {
- $m entryconfigure 3 -state disabled
- bind .a$s1.c <Alt-x> {}
- }
- set m .a$s1.menu.edit.menu
- if {$allow_erase_all} {
- $m entryconfigure 3 -state normal
- bind .a$s1.c <Alt-a> "Clear $s1"
- } else {
- $m entryconfigure 3 -state disabled
- bind .a$s1.c <Alt-a> {}
- }
- if {$allow_erase} {
- .a$s1.tool.del configure -state normal
- } else {
- if {$mode($s1)==3} {
- set mode($s1) 0
- Mode $s1
- }
- .a$s1.tool.del configure -state disabled
- }
- }
- }
- }
-
- proc Mode s {
- global mode msg info o_lst t_lst
- set mods $mode($s)
- set info($s) $msg($mods)
- bind .a$s.c <Enter> ".a$s.status configure -text $info($s)"
- Curs $s
- foreach o $o_lst {
- .a$s.c bind o$o <Enter> {}
- .a$s.c bind o$o <Any-Leave> {}
- .a$s.c bind o$o <1> {}
- }
- foreach t $t_lst {
- .a$s.c bind t$t <Enter> {}
- .a$s.c bind t$t <Any-Leave> {}
- .a$s.c bind t$t <1> {}
- }
- set c .a$s.c
- catch {$c delete cur$s}
- bind $c <Motion> {}
- switch $mode($s) \
- 0 {bind $c <1> "Curve0 $s %x %y"
- bind $c <B1-Motion> "Curve1 $s %x %y"
- bind $c <ButtonRelease-1> "Curve2 $s %x %y"
- bind $c <3> ""} \
- 1 {bind $c <1> "Line0 $s %x %y"
- bind $c <B1-Motion> ""
- bind $c <ButtonRelease-1> {}
- bind $c <3> ""} \
- 2 {Text $s} \
- 3 {Delete $s}
- }
-
- proc Curs {s} {
- global mode col color lib
- set mods $mode($s)
- set cols $col($s)
- .a$s.c configure -cursor "@$lib/curs$mods $color($cols)"
- }
-
- proc Curve0 {s x0 y0} {
- global x y o_num o_cur o_lst obj
- set x($s) $x0
- set y($s) [.a$s.c canvasy $y0]
- set o_cur($s) $o_num
- lappend o_lst $o_num
- set obj($s) $o_num
- incr o_num
- }
-
- proc Curve1 {s x1 y1} {
- global x y col o_cur
- set y1 [.a$s.c canvasy $y1]
- seg $x($s) $y($s) $x1 $y1 $col($s) $o_cur($s)
- set x($s) $x1
- set y($s) $y1
- }
-
- proc Curve2 {s x1 y1} {
- global obj s_lst mode undo undo_info t0 timeout
- set o $obj($s)
- set undo($s) 1
- set undo_info($s) $o
- foreach s1 $s_lst {
- if {$mode($s1)==3} {
- .a$s1.c bind o$o <Enter> "o_enter $s1 $o"
- .a$s1.c bind o$o <Any-Leave> "o_leave $s1 $o"
- .a$s1.c bind o$o <1> "o_delete $s1 $o"
- }
- }
- set t1 [clock seconds]
- if {$t1-$t0>$timeout} {Beep $s}
- set t0 $t1
- }
-
- proc Line0 {s x0 y0} {
- global x y info msg col l_col o_num o_cur o_lst obj
- set x($s) $x0
- set y($s) [.a$s.c canvasy $y0]
- set l_col($s) $col($s)
- bind .a$s.c <1> "Line1 $s %x %y"
- bind .a$s.c <3> "Line2 $s %x %y"
- bind .a$s.c <Motion> "Line3 $s %x %y"
- set info($s) $msg(4)
- eval .a$s.status configure -text $info($s)
- bind .a$s.c <Enter> "Line3 $s %x %y; .a$s.status configure -text $info($s)"
- bind .a$s.c <Any-Leave> "catch {.a$s.c delete cur$s};
- .a$s.status configure -text {}"
- set o_cur($s) $o_num
- lappend o_lst $o_num
- set obj($s) $o_num
- incr o_num
- }
-
- proc Line1 {s x1 y1} {
- global x y l_col o_cur
- set y1 [.a$s.c canvasy $y1]
- seg $x($s) $y($s) $x1 $y1 $l_col($s) $o_cur($s)
- set x($s) $x1
- set y($s) $y1
- }
-
- proc Line2 {s x1 y1} {
- global x y l_col msg info o_cur s_lst mode obj undo undo_info t0 timeout
- set y1 [.a$s.c canvasy $y1]
- catch {.a$s.c delete cur$s}
- seg $x($s) $y($s) $x1 $y1 $l_col($s) $o_cur($s)
- bind .a$s.c <1> "Line0 $s %x %y"
- bind .a$s.c <3> ""
- bind .a$s.c <Motion> {}
- set info($s) $msg(1)
- eval .a$s.status configure -text $info($s)
- bind .a$s.c <Enter> ".a$s.status configure -text $info($s)"
- bind .a$s.c <Any-Leave> ".a$s.status configure -text {}"
- set o $obj($s)
- set undo($s) 1
- set undo_info($s) $o
- foreach s1 $s_lst {
- if {$mode($s1)==3} {
- .a$s1.c bind o$o <Enter> "o_enter $s1 $o"
- .a$s1.c bind o$o <Any-Leave> "o_leave $s1 $o"
- .a$s1.c bind o$o <1> "o_delete $s1 $o"
- }
- }
- set t1 [clock seconds]
- if {$t1-$t0>$timeout} {Beep $s}
- set t0 $t1
- }
-
- proc Line3 {s x1 y1} {
- global x y l_col color
- set y1 [.a$s.c canvasy $y1]
- catch {.a$s.c delete cur$s}
- .a$s.c create line $x($s) $y($s) $x1 $y1 -fill $color($l_col($s)) -tags cur$s
- }
-
- proc seg {x0 y0 x1 y1 c t} {
- global s_lst color
- foreach s $s_lst {.a$s.c create line $x0 $y0 $x1 $y1 -fill $color($c) -tags o$t}
- }
-
- proc Delete {s} {
- global o_lst t_lst
- bind .a$s.c <1> {}
- bind .a$s.c <B1-Motion> {}
- bind .a$s.c <ButtonRelease-1> {}
- bind .a$s.c <3> {}
- foreach o $o_lst {
- .a$s.c bind o$o <Enter> "o_enter $s $o"
- .a$s.c bind o$o <Any-Leave> "o_leave $s $o"
- .a$s.c bind o$o <1> "o_delete $s $o"
- }
- foreach t $t_lst {
- .a$s.c bind t$t <Enter> "td_enter $s $t"
- .a$s.c bind t$t <Any-Leave> "td_leave $s $t"
- .a$s.c bind t$t <1> "td_delete $s $t"
- }
- }
-
- proc o_enter {s o} {
- global r_col msg dark
- set r_col($s) [.a$s.c itemcget o$o -fill]
- .a$s.c itemconfigure o$o -fill $dark
- eval .a$s.status configure -text $msg(5)
- }
-
- proc o_leave {s o} {
- global r_col info
- .a$s.c itemconfigure o$o -fill $r_col($s)
- eval .a$s.status configure -text $info($s)
- }
-
- proc o_delete {s o} {
- global s_lst o_lst undo undo_info t0 timeout
- .a$s.c bind o$o <Enter> {}
- .a$s.c bind o$o <Any-Leave> {}
- .a$s.c bind o$o <1> {}
- set undo($s) 2
- set i_lst [.a$s.c find withtag o$o]
- set undo_info($s) {}
- foreach i $i_lst {lappend undo_info($s) [.a$s.c coords $i]}
- foreach s1 $s_lst {catch ".a$s1.c delete o$o"}
- set i [lsearch -exact $o_lst $o]
- set o_lst [lreplace $o_lst $i $i]
- set t1 [clock seconds]
- if {$t1-$t0>$timeout} {Beep $s}
- set t0 $t1
- }
-
- proc o_redraw s {
- global o_num o_lst col undo_info s_lst mode t0 timeout
- set o $o_num
- incr o_num
- lappend o_lst $o
- foreach i $undo_info($s) {
- seg [lindex $i 0] [lindex $i 1] [lindex $i 2] [lindex $i 3] $col($s) $o
- }
- foreach s1 $s_lst {
- if {$mode($s1)==3} {
- .a$s1.c bind o$o <Enter> "o_enter $s1 $o"
- .a$s1.c bind o$o <Any-Leave> "o_leave $s1 $o"
- .a$s1.c bind o$o <1> "o_delete $s1 $o"
- }
- }
- set t1 [clock seconds]
- if {$t1-$t0>$timeout} {Beep $s}
- set t0 $t1
- }
-
- proc td_enter {s t} {
- global r_col msg dark
- set r_col($s) [.a$s.c itemcget t$t -fill]
- .a$s.c itemconfigure t$t -fill $dark
- eval .a$s.status configure -text $msg(5)
- }
-
- proc td_leave {s t} {
- global r_col info
- .a$s.c itemconfigure t$t -fill $r_col($s)
- eval .a$s.status configure -text $info($s)
- }
-
- proc td_delete {s t} {
- global s_lst t_lst undo undo_info t0 timeout
- .a$s.c bind t$t <Enter> {}
- .a$s.c bind t$t <Any-Leave> {}
- .a$s.c bind t$t <1> {}
- set undo($s) 4
- set undo_info($s) [.a$s.c coords t$t]
- lappend undo_info($s) [.a$s.c itemcget t$t -text]
- foreach s1 $s_lst {catch ".a$s1.c delete t$t"}
- set i [lsearch -exact $t_lst $t]
- set t_lst [lreplace $t_lst $i $i]
- set t1 [clock seconds]
- if {$t1-$t0>$timeout} {Beep $s}
- set t0 $t1
- }
-
- proc Text {s} {
- global t_lst
- bind .a$s.c <1> "t_new $s %x %y"
- bind .a$s.c <B1-Motion> {}
- bind .a$s.c <ButtonRelease-1> {}
- bind .a$s.c <3> {}
- foreach t $t_lst {
- .a$s.c bind t$t <Enter> "t_enter $s $t"
- .a$s.c bind t$t <Any-Leave> "t_leave $s $t"
- }
- }
-
- proc t_new {s x y} {
- global s_lst t_num t_lst col color mode font bold italic size main_x \
- text_left text_sig text_time screen
- if {$text_left} {set x 4}
- set y [.a$s.c canvasy $y]
- set w [expr $main_x-$x-1]
- set t $t_num
- lappend t_lst $t
- incr t_num
- set t_col($t) $col($s)
- set c $col($s)
- set c $color($c)
- switch $font($s) \
- 0 {set f -*-times} \
- 1 {set f -*-helvetica} \
- 2 {set f -*-courier}
- if $bold($s) {set f $f-bold} else {set f $f-medium}
- if $italic($s) {
- if $font($s) {set f $f-o} else {set f $f-i}
- } else {
- set f $f-r
- }
- set f $f-*-*-$size($s)-*-*-*-*-*-*-*
- foreach s1 $s_lst {
- .a$s1.c create text $x $y -text "" -width $w -anchor nw \
- -tags t$t -fill $c -font $f
- if {$mode($s1)==2} {
- .a$s1.c bind t$t <Enter> "t_enter $s1 $t"
- .a$s1.c bind t$t <Any-Leave> "t_leave $s1 $t"
- } elseif {$mode($s1)==3} {
- .a$s1.c bind t$t <Enter> "td_enter $s1 $t"
- .a$s1.c bind t$t <Any-Leave> "td_leave $s1 $t"
- .a$s1.c bind t$t <1> "td_delete $s1 $t"
- }
- }
- t_focus $s $t 0 0
- if {$text_time} {t_ins $s [clock format [clock seconds] -format "\[%H:%M:%S\] "]}
- if {$text_sig} {t_ins $s "\[$screen($s)\] "}
- }
-
- proc t_enter {s t} {
- global msg
- eval .a$s.status configure -text $msg(6)
- bind .a$s.c <1> "t_focus $s $t %x %y"
- bind .a$s.c <B1-Motion> "t_select $s to $t %x %y"
- bind .a$s.c <3> "t_select $s adjust $t %x %y"
- }
-
- proc t_leave {s t} {
- global info
- eval .a$s.status configure -text $info($s)
- bind .a$s.c <1> "t_new $s %x %y"
- bind .a$s.c <B1-Motion> {}
- bind .a$s.c <3> {}
- }
-
- proc t_select {s c t x y} {
- set y [.a$s.c canvasy $y]
- .a$s.c select $c t$t @$x,$y
- }
-
- proc t_focus {s t x y} {
- global foc_t
- set y [.a$s.c canvasy $y]
- set i @$x,$y
- set foc_t($s) $t
- set i [.a$s.c index t$t $i]
- .a$s.c select clear
- .a$s.c select from t$t $i
- .a$s.c icursor t$t $i
- .a$s.c focus t$t
- focus .a$s.c
- .a$s.c bind t$t <Key> "t_key $s %A %s"
- .a$s.c bind t$t <Return> "t_ins $s \\n"
- .a$s.c bind t$t <BackSpace> "t_del $s 0"
- .a$s.c bind t$t <Control-d> "t_del $s 1"
- .a$s.c bind t$t <Left> "t_move $s 0"
- .a$s.c bind t$t <Right> "t_move $s 1"
- bind .a$s.c <2> "t_sel $s"
- }
-
- proc t_do {s i1 i2 str} {
- global foc_t s_lst undo undo_info t0 timeout
- set t $foc_t($s)
- set txt [.a$s.c itemcget t$t -text]
- set txt [string range $txt $i1 $i2]
- set i3 [expr $i1+[string length $str]-1]
- set undo($s) 3
- set undo_info($s) [list $i1 $i3 $txt]
- foreach s1 $s_lst {
- if {$i2 >= $i1} {catch {.a$s1.c dchars t$t $i1 $i2}}
- catch {.a$s1.c insert t$t $i1 $str}
- }
- set t1 [clock seconds]
- if {$t1-$t0>$timeout} {Beep $s}
- set t0 $t1
- }
-
- proc t_ins {s str} {
- global foc_t
- set t $foc_t($s)
- if ![catch {set i1 [.a$s.c index t$t sel.first]}] {
- set i2 [.a$s.c index t$t sel.last]
- t_do $s $i1 $i2 $str
- return}
- set i1 [.a$s.c index t$t insert]
- t_do $s $i1 [expr $i1-1] $str
- }
-
- proc t_key {s a x} {
- if {[string length $a] != 1} return
- if {$x > 1} return
- if {[string compare $a " "] < 0} return
- t_ins $s $a
- }
-
- proc t_sel s {
- if [catch {selection get} str] {
- if [catch {selection get -selection CLIPBOARD} str] return
- }
- if {$str == ""} return
- t_ins $s $str
- }
-
- proc t_del {s r} {
- global foc_t
- set t $foc_t($s)
- if ![catch {set i1 [.a$s.c index t$t sel.first]}] {
- set i2 [.a$s.c index t$t sel.last]
- t_do $s $i1 $i2 "" } \
- else {
- set i [.a$s.c index t$t insert]
- if $r {
- set e [.a$s.c index t$t end]
- if {$i<$e} {t_do $s $i $i ""}} \
- else {
- if {$i>0} {
- set i [expr $i-1]
- t_do $s $i $i ""}}}
- }
-
- proc t_move {s r} {
- global foc_t
- set t $foc_t($s)
- set i [.a$s.c index t$t insert]
- if $r {
- set e [.a$s.c index t$t end]
- if {$i<$e} {.a$s.c icursor t$t [expr $i+1]}
- } else {
- if {$i>0} {.a$s.c icursor t$t [expr $i-1]}
- }
- }
-
- proc t_redraw s {
- global undo_info t0 timeout
- set x [lindex $undo_info($s) 0]
- set y [lindex $undo_info($s) 1]
- set str [lindex $undo_info($s) 2]
- t_new $s $x $y
- t_ins $s $str
- set t1 [clock seconds]
- if {$t1-$t0>$timeout} {Beep $s}
- set t0 $t1
- }
-
- proc Undo {s} {
- global undo undo_info
- # undo($s) :
- # 0 - can't do
- # 1 - delete last line
- # 2 - redraw deleted line
- # 3 - undo text operation
- # 4 - redraw deleted text
- switch $undo($s) \
- 0 {return} \
- 1 {o_delete $s $undo_info($s)} \
- 2 {o_redraw $s} \
- 3 { set i1 [lindex $undo_info($s) 0]
- set i2 [lindex $undo_info($s) 1]
- set st [lindex $undo_info($s) 2]
- t_do $s $i1 $i2 $st} \
- 4 {t_redraw $s}
- set undo($s) 0
- set undo_info($s) {}
- }
-
- proc More {} {
- global s_lst main_x main_y main_Y
- set main_Y [expr $main_Y+$main_y]
- foreach s1 $s_lst {.a$s1.c configure -scrollregion "0 0 $main_x $main_Y"}
- }
-
- proc Beep s {
- global s_lst
- foreach s1 $s_lst {if {$s1!=$s} {bell -displayof .a$s1}}
- }
-
- proc Clear s {
- global screen
- catch {destroy .c_a$s}
- toplevel .c_a$s -screen $screen($s)
- wm title .c_a$s "Clear all"
- label .c_a$s.up -text \
- "There is no Undo for Clear all!\nAre you sure you want to delete everything?"
- frame .c_a$s.down
- pack .c_a$s.up -side top
- pack .c_a$s.down -side bottom -fill x
- button .c_a$s.down.ok -text "OK" -bd 4 -relief raised \
- -command "destroy .c_a$s; cl_all $s; return"
- button .c_a$s.down.cancel -text "Cancel" -bd 4 -relief raised \
- -command "destroy .c_a$s; return"
- pack .c_a$s.down.ok -side left
- pack .c_a$s.down.cancel -side right
- focus .c_a$s
- bind .c_a$s <Return> ".c_a$s.down.ok invoke"
- bind .c_a$s <Escape> ".c_a$s.down.cancel invoke"
- }
-
- proc cl_all s {
- global s_lst undo t0 timeout
- foreach s1 $s_lst {.a$s1.c delete all; set undo($s1) 0}
- set o_num 0
- set o_lst {}
- set t_num 0
- set t_lst {}
- set t1 [clock seconds]
- if {$t1-$t0>$timeout} {Beep $s}
- set t0 $t1
- }
-
- Config_restore; Config_all
- if [catch {set con_scr $env(DISPLAY)}] {set con_scr :0.0}
- win
-