# $Header: /home/cvsroot/tcldb/wisql/Tlib/makeEZEhide,v 1.6 1998/03/22 21:54:01 de Exp $
# tcl procs saved on Tue Sep 05 09:33:03 PDT 1995

proc makeEZEhide {} {

global dbpipe1 sybmsg server uname base table 
global bitmapdir DB
  global MsgW

upvar #0 EZEcols cols
upvar #0 EZEshows shows
upvar #0 EZEkeys keys


#       First go get the primary key information for this table

        if {($base == "") || ($table == "")} {
                .m.mb.mkHide flash
                catch {setMsg $MsgW "EZhide cannot be used until you select a database and table"}
                return
        }

#	Better get the columns now

	if {[catch {set x [llength $cols]}]} {
		set cols {}
	}

#	If llength $cols is 0 then this was not done before so do it now
	if {[llength $cols] == 0} {
	${DB}getEZcols E
	}

#       If it ain't keyed, don't go dropping columns.
	set keyed [llength $keys]

        if {$keyed == 0} {
                catch {setMsg $MsgW "You cannot drop columns from the display when the table has no primary key.  Sorry."}
                return
        }


#	This is the algorithm:  how many columns are there?  Divide them
#	Limit the field names to 15 chars, draconically.  Make as many
#	stacks of 12 as you need.  

	set ccount [llength $cols]

#	a field entry and besides, they need some leading.  So...

	set fudge 6

	incr ccount $fudge

	set fullstacks [floor [expr {$ccount/12.0}]]
	set overflow [lindex [split [expr {$ccount/12.0}] .] 1]
	set stacks [lindex [split [expr {$fullstacks + 1}] .] 0]


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

#	set width 400
#	set height 300
#	wm geometry $w ${width}x${height}

#	frame $w.control -relief flat -border 0 -background antiquewhite
	
#	make as many stacks as needed

	loop i 0 $stacks {
		frame $w.stack$i -relief flat -border 0 -background antiquewhite
	}

	set font [getFont $w mediumhel]


	loop i 0 [expr {$ccount - $fudge}] {

		set stn [lindex [split [expr {$i/12.0}] .] 0]
		set col [lindex $cols $i]
		set lab [crange $col 0 14]

		checkbutton $w.stack$stn.$col -text "$lab"  -font $font -variable EZEshows($col) -relief groove  -border 1 -width 15 -anchor w -background antiquewhite -activebackground bisque -activeforeground magenta2 -selectcolor magenta2


		if {[lsearch $keys $col] >= 0} {
			set shows($col) 1
			$w.stack$stn.$col configure -state disabled
		}

		pack $w.stack$stn.$col  -side top -anchor n
	}

	button $w.stack$stn.showall -text "SEE ALL" -command "ezEhide ALL x" -padx 0 -pady 0 -background lavender -activebackground lavender -activeforeground magenta2
	button $w.stack$stn.hideall -text "SEE NONE" -command "ezEhide NONE x" -padx 0 -pady 0 -background lavender -activebackground lavender -activeforeground magenta2
	button $w.stack$stn.gotit -text "OK"  -command "ezEhide COMMIT $w" -padx 0 -pady 0 -background lemonchiffon -activebackground lemonchiffon -activeforeground magenta2

	pack $w.stack$stn.gotit -side top -expand true -fill x -ipady 5 
	pack $w.stack$stn.showall -side top -expand true -fill x -ipady 5   
	pack $w.stack$stn.hideall -side top -expand true -fill x -ipady 5 

#	pack $w.control -side top -expand true -fill x -ipady 20

	loop i 0 $stacks {
		pack $w.stack$i -side left -anchor n -expand true -fill both
	}

	update

	focus $w

}

