# dblists2.tcl -- Ray R. Larson (mar 92)
# Create a "listbox" style display box from the data stored in a
# tuplearray. Takes two arguments.  The first is the global tuplearray name.
# The second is a set of arguments for use in creating the message
# to be displayed in the message box area of the window.

proc mkList2 {{tuple "junk"} {msgArgs {-text "Postgres Output List"}}} {
    if {[string compare "$tuple" "junk"] == 0} {error "mkList requires an tuplearray name"}
    set w [format ".%s_LIST" [string tolower $tuple]]
    catch {destroy $w}
    toplevel $w
    dpos $w
    global $tuple

    set tgroups [set [set tuple](GROUPS)]
    set gtuples [set [set tuple](TUPLES.0)]
    set attrlabels [set [set tuple](FIELDS.0)]

    # Create three frames in the main window. The top frame will hold the
    # message and the bottom one will hold the <next> & <quit> buttons.
    # The middle frame holds the labels and data elements of the
    # instances of the retrieved tuples from the tuplearray. Arrange them
    # one above the other, with any extra vertical space split between
    # them.

    frame $w.top -relief raised -border 1
    frame $w.mid -relief raised -border 1
    frame $w.bot -relief raised -border 1

    pack append $w $w.top {top fill expand} $w.mid {top fill expand} $w.bot {bottom fill}

    # Create the message widget and arrange for it to be centered in the
    # top frame.

    eval message $w.top.msg -justify center \
	    -font -*-times-medium-r-normal--*-180* -aspect 300 $msgArgs
    frame $w.top.lframe -borderwidth 1
    pack append $w.top.lframe \
         [label $w.top.lframe.tu -text "Number of Matching Items = $gtuples" -relief raised] \
              {top expand fillx filly}

    pack append $w.top $w.top.msg {top expand fillx filly} \
         $w.top.lframe {top expand fillx filly}

    #
    # Create a scrolling listbox in the middle frame
    #
    pack append $w.mid \
	[scrollbar $w.mid.scroll -relief sunken \
	    -command "$w.mid.list yview"] {right expand filly frame w} \
	[listbox $w.mid.list -yscroll "$w.mid.scroll set" -relief sunken -geometry {40x24}] \
	     {left expand filly }

    #
    # Load the tuples into the listbox
    #
    foreach i [lsort [array names $tuple]] {
       if {[string match "\[A-Z\]*" $i ] == 1} break
       set tval [set [set tuple]($i)]

       $w.mid.list insert end "$tval"
    }



    bind $w.mid.list <Double-1> "set currselection \[selection get\] "

    #
    # Create the quit button in the bottom frame.
    #
    button $w.bot.ok -text Quit -command "destroy $w" -pady 5\
           
    pack append $w.bot $w.bot.ok {bottom fillx filly}

}



