# dlgValue.tcl --
#
#        Este fichero implementa el código Tcl para crear y manipular una
#        ventana donde se edita un valor.
#
# Copyright (c) 1999 CIMNE
#

package provide dlgValue 0.1
namespace eval dlgValue {
    namespace export Show
    variable Action 0
    variable EntryValue ""
}

proc dlgValue::Accept { w } {
    variable Action

    set Action 1
    destroy $w
}

proc dlgValue::Dismiss { w } {
    variable Action

    set Action 0
    destroy $w
}

proc dlgValue::Position { w } {
    set wParent [winfo parent $w]
    set xParent [winfo rootx $wParent]
    set yParent [winfo rooty $wParent]
    set sxParent [winfo width $wParent]
    set syParent [winfo height $wParent]
    set sxw [winfo width $w]
    set syw [winfo height $w]

    set xPos [expr $xParent + ($sxParent - $sxw) / 2]
    set yPos [expr $yParent + ($syParent - $syw) / 2]
    wm geometry $w =+$xPos+$yPos
}
proc dlgValue::Show { {Title "Data Entry"} {Label "Label"} {InitialValue ""} \
			  {wParent ""} } {
    variable Action
    variable EntryValue $InitialValue

    set w $wParent.dlgValue

    toplevel $w -class Dialog

    wm title $w $Title
    set FData [frame $w.fdataEntry]
    set LEntry [label $FData.labelAsk -text [_ "Name:"]]
    set DEntry [entry $FData.dataEntry -textvariable dlgValue::EntryValue]
    
    set FButtons [frame $w.buttons]
    set BDismiss [button $FButtons.dismiss -text [_ "Dismiss"] \
		      -command "dlgValue::Dismiss $w"]
    set BAccept [button $FButtons.accept -text [_ "Accept"] \
		     -command "dlgValue::Accept $w"]
    pack $FData $FButtons -side top
    pack $BAccept $BDismiss -side left
    pack $LEntry $DEntry -side left -fill x
    dlgValue::Position $w
    tkwait visibility $w
    focus $DEntry
    grab $w
    tkwait window $w

    return "$Action $EntryValue"
}
