# $Header: /home/cvsroot/tcldb/wisql/Tlib/verticalForm,v 1.7 1998/08/03 20:05:21 de Exp $
# tcl procs saved on Tue Sep 05 09:33:21 PDT 1995

proc verticalForm {} {

global base table DB
global bitmapdir

upvar #0 EZEcols cols
upvar #0 EZEcolatts colatts
upvar #0 EZEshows shows
upvar #0 EZEnrec nrec
upvar #0 EZEcci cci
upvar #0 EZEforf forf
upvar #0 EZEvform vf
upvar #0 EZEhform hf
upvar #0 EZEprivs privs

#	You can't use v form until you have Found some records, but you
#	can use it if you have not picked a particular record, because
#	cci is set to 0 by default

        if {$nrec == 0} {
                $hf.ctrl.verti flash
                $hf.data.msg configure -text "Vertical Form cannot be used until you select some records."
                return
        }

        set w $vf
        catch {destroy $w}
        toplevel $w -class Dialog
        wm title $w "EZeditV"
        wm iconname $w "EZeditV!"
  	wm iconbitmap $w @$bitmapdir/vform.xbm

        set width 700
        set height 550
	wm minsize $w ${width} ${height}
        wm geometry $w ${width}x${height}


#	Note that ezw is the "parent" actually a peer window, the ezEdit
#	window from which we were launched and with which we share data.

	frame $w.control -height 50 -relief groove -border 2 -background antiquewhite

	set font [getFont $w messagehel]
  	message $w.msg -text "" -justify center -aspect 4000  -relief sunken -border 1  -font $font -background antiquewhite
	bind $w.msg <Control-1> "ezHelp Messages; break"

	frame $w.data -relief groove -border 2 -background antiquewhite

	canvas $w.data.can -yscrollcommand "$w.data.sbv set" -background antiquewhite -width 650 -height 500

	frame $w.data.can.fr  -background antiquewhite
	frame $w.data.can.fr.fields   -border 1 -background antiquewhite
	frame $w.data.can.fr.types    -border 1 -background antiquewhite
	frame $w.data.can.fr.old      -border 1 -background antiquewhite
	frame $w.data.can.fr.new      -border 1 -background antiquewhite

	scrollbar $w.data.sbv -width 15 -orient vert  -command "$w.data.can yview" -relief sunken -background ivory -activebackground mistyrose -troughcolor bisque
	bind $w.data.sbv <Control-1> "ezHelp Scrollbars; break"

        button $w.control.done -text "QUIT" -relief  raised -border 1  -command "destroy $w" -padx 0 -pady 0 -background white -foreground red -activebackground black -activeforeground yellow
        button $w.control.delete -text "DELETE" -relief  raised -border 1  -command "changeData del $w {}" -padx 0 -pady 0 -background lemonchiffon -activebackground lemonchiffon -activeforeground magenta2
	button $w.control.ins -text "INSERT" -relief  raised -border 1  -command "changeData ins $w {}" -padx 0 -pady 0 -background lemonchiffon -activebackground lemonchiffon -activeforeground magenta2
        button $w.control.change -text "CHANGE" -relief  raised -border 1  -command "changeData upd $w {}" -padx 0 -pady 0 -background lemonchiffon -activebackground lemonchiffon -activeforeground magenta2
        button $w.control.next -text "NEXT" -relief  raised -border 1  -command "ezEselect {} 1 {}" -padx 0 -pady 0 -background lavender -activebackground lavender -activeforeground magenta2
        button $w.control.prev -text "PREV" -relief  raised -border 1  -command "ezEselect {} \"-1\" {}" -padx 0 -pady 0 -background lavender -activebackground lavender -activeforeground magenta2
	button $w.control.copy -text "COPY" -relief raised -border 1  -command "vertCopy" -padx 0 -pady 0 -background azure -activebackground azure -activeforeground magenta2

#
	menubutton $w.control.help -text "Help..." -menu $w.control.help.m  -relief raised -border 1 -padx 0 -pady 0 -background lavender -activebackground lavender -activeforeground magenta2
	menu $w.control.help.m -background lavender
	$w.control.help.m add command -label "General" -command "ezHelp EZVgen" -background lavender -activebackground lavender -activeforeground magenta2
	$w.control.help.m add command -label "FastKeys" -command "ezHelp EZVkeys" -background lavender -activebackground lavender -activeforeground magenta2
	$w.control.help.m add command -label "HowTo" -command "ezHelp EZVhow" -background lavender -activebackground lavender -activeforeground magenta2
#
	if {[string first U $privs] < 0} {
	$w.control.change configure -state disabled
	}
	if {[string first I $privs] < 0} {
	$w.control.ins configure -state disabled
	}
	if {[string first D $privs] < 0} {
	$w.control.delete configure -state disabled
	}

	bind $w.control.delete <Control-3> "changeData del $w show"
	bind $w.control.change <Control-3> "changeData upd $w show"
	bind $w.control.ins <Control-3> "changeData ins $w show"

	bind $w.control.done <Control-1> "ezHelp Quit; break"
	bind $w.control.delete <Control-1> "ezHelp EZEdel; break"
	bind $w.control.ins <Control-1> "ezHelp EZEins; break"
	bind $w.control.change <Control-1> "ezHelp EZEchg; break"
	bind $w.control.next <Control-1> "ezHelp EZEnext; break"
	bind $w.control.prev <Control-1> "ezHelp EZEprev; break"
	bind $w.control.copy <Control-1> "ezHelp EZEcopy; break"
	bind $w.control.help <Control-1> "ezHelp ToolHlp; break"

	pack $w.control.copy -side left -ipadx 10 -padx 5
  	pack $w.control.change -side left -ipadx 10
    	pack $w.control.ins -side left -ipadx 10
    	pack $w.control.delete -side left -ipadx 10
    	pack $w.control.next -side left -ipadx 10 -padx 5
    	pack $w.control.prev -side left -ipadx 10
    	pack $w.control.help -side left -ipadx 10 -padx 10
    	pack $w.control.done -side right -ipadx 10


	label $w.data.can.fr.fields.fh -text "Fields:" -anchor w  -background antiquewhite
	label $w.data.can.fr.types.th -text "Datatypes:" -anchor w  -background antiquewhite
	label $w.data.can.fr.old.oh -text "Original Data:" -anchor w  -background antiquewhite
	label $w.data.can.fr.new.nh -text "New Data:" -anchor w  -background antiquewhite

	pack $w.data.can.fr.fields.fh -side top -ipady 10 -expand true -fill x
	pack $w.data.can.fr.old.oh -side top -ipady 10 -expand true -fill x
	pack $w.data.can.fr.new.nh -side top -ipady 10 -expand true -fill x
	pack $w.data.can.fr.types.th -side top -ipady 10 -expand true -fill x

	set permitted ""

#	Now, here we have to check on the h form to see if the user has
#	concealed one of the columns.  sigh.  so get the packing list
#	from the data master frame in the h form.

#	set mapped_ezecols [pack info $hf.data.pic.win]
#	echo "This is the packing list:  $mapped_ezecols"

	set noinsert 0
	set i 0
	foreach c $cols {

	if {$shows($c)} {
	
	set t [keylget colatts($c) type]
	set s [keylget colatts($c) size]

        case $t in {
        {char varchar} {
                set ts [format "%s(%s)" $t $s]
        } {default} {
                set ts $t
        }
        }


	label $w.data.can.fr.types.$c -text "$ts" -anchor w  -background antiquewhite
	label $w.data.can.fr.fields.$c -text "$c" -anchor w -background antiquewhite
	entry $w.data.can.fr.old.$c  -width 30   -relief groove -border 1 -background antiquewhite
	entry $w.data.can.fr.new.$c -relief sunken -border 2 -width 30 -background ivory

	bind $w.data.can.fr.fields.$c <Control-1> "ezHelp fieldname; break"
	bind $w.data.can.fr.fields.$c <Control-2> "dataHelp $table $c; break"
	bind $w.data.can.fr.types.$c <Control-1> "ezHelp datatype; break"
	bind $w.data.can.fr.old.$c <Control-1> "ezHelp EZEold; break"
	bind $w.data.can.fr.new.$c <Control-1> "ezHelp EZEnew; break"
	
	if {[lsearch $forf $c] >= 0} {
		$w.data.can.fr.old.$c configure -background black  -foreground white
		$w.data.can.fr.new.$c configure -background black  -foreground white
		$w.data.can.fr.new.$c configure -state disabled
	} else {
		lappend permitted $c
	}

	pack $w.data.can.fr.fields.$c -side top -ipady 3 -expand true -fill x
	pack $w.data.can.fr.old.$c -side top -ipady 3 -expand true -fill x
	pack $w.data.can.fr.new.$c -side top -ipady 3 -expand true -fill x
	pack $w.data.can.fr.types.$c -side top -ipady 3 -expand true -fill x

	} else {
		set noinsert 1
	}

	incr i
	}

#	You can't insert if you are hiding columns.  Not permitted.

	if {$noinsert} {
		$w.control.ins configure -state disabled
	}

	set pi [llength $permitted]
	set lastc [expr {$pi - 1}]
	loop j 0 $pi {
		if {$j < $lastc} {
		eval bind $w.data.can.fr.new.[lindex $permitted $j] <Tab>  \"focus $w.data.can.fr.new.[lindex $permitted [expr {$j + 1}]]\"
		eval bind $w.data.can.fr.new.[lindex $permitted $j] <Return>  \"focus $w.data.can.fr.new.[lindex $permitted [expr {$j + 1}]]\"
		}
		if {$j > 0} {
		eval bind $w.data.can.fr.new.[lindex $permitted $j] <Shift-Tab>  \"focus $w.data.can.fr.new.[lindex $permitted [expr {$j - 1}]]\"
		eval bind $w.data.can.fr.new.[lindex $permitted $j] <Shift-Return>  \"focus $w.data.can.fr.new.[lindex $permitted [expr {$j - 1}]]\"
		}
	}
	eval bind $w.data.can.fr.new.[lindex $permitted 0] <Shift-Tab>  \"focus $w.data.can.fr.new.[lindex $permitted $lastc]\"
	eval bind $w.data.can.fr.new.[lindex $permitted 0] <Shift-Return>  \"focus $w.data.can.fr.new.[lindex $permitted $lastc]\"
	eval bind $w.data.can.fr.new.[lindex $permitted $lastc] <Tab>  \"focus $w.data.can.fr.new.[lindex $permitted 0]\"
	eval bind $w.data.can.fr.new.[lindex $permitted $lastc] <Return>  \"focus $w.data.can.fr.new.[lindex $permitted 0]\"

	
	pack $w.data.can.fr.fields -side left -expand true -fill y
  	pack $w.data.can.fr.old -side left -expand true -fill y
  	pack $w.data.can.fr.new -side left -expand true -fill y
  	pack $w.data.can.fr.types -side left -expand true -fill y
 

	$w.data.can create window 2 2 -anchor nw -window $w.data.can.fr
	pack $w.data.can -side left -expand true -fill both

	pack $w.control -side top -ipady 10 -fill x
  	pack $w.msg -side top -expand true -fill x 
	pack $w.data.sbv -side right -expand true -fill y
  	pack $w.data -side top -expand true -fill both

	vertPage

	update

	set datah [winfo height $w.data.can.fr]
	set dataw [winfo width $w.data.can.fr]

#	puts stderr "Data frame height width:  $datah $dataw"
#	set realh [expr {$datah + 105}]
#	puts stderr "Desired total window height:  $realh"
#	if {$realh < $height} {set realh $height}
#        puts stderr "wm geometry $w ${width}x${realh}"
#        wm geometry $w ${width}x${realh}
#	puts stderr "canvas scrollregion -10 -10 [expr $dataw + 20] [expr $datah + 20]"

	eval $w.data.can configure -scrollregion \{-10 -10 [expr $dataw + 20] [expr $datah + 20]\}

#	Paint the current data into the form

        foreach c $cols {
                if {$shows($c)} {
                        set first $c
                        break
                }
        }

	focus $w.data.can.fr.new.$first


}

