#         $Id: dialog-ram.tcl,v 1.83 2004/06/10 14:25:53 escolano Exp $        
# dialog.tcl --
#
# This file defines the procedure tk_dialog, which creates a dialog
# box containing a bitmap, a message, and one or more buttons.
#
# SCCS: @(#) dialog.tcl 1.25 96/04/10 15:43:33
#
# Copyright (c) 1992-1993 The Regents of the University of California.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#

#
# tk_dialog:
#
# This procedure displays a dialog box, waits for a button in the dialog
# to be invoked, then returns the index of the selected button.
#
# Arguments:
# w -                Window to use for dialog top-level.
# title -        Title to display in dialog's decorative frame.
# text -        Message to display in dialog.
# bitmap -        Bitmap to display in dialog (empty string means none).
# default -        Index of button that is to display the default ring
#                (-1 means none). (-2 means 0 and button 2 returns -2)
# args -        One or more strings to display in buttons across the
#                bottom of the dialog box.

proc tk_dialogRAM {w title text bitmap default args} {
    eval [concat [list tk_dialogRAMFull $w $title $text "" $bitmap "" $default] $args]
}

proc tk_dialogRAMFull {w title text textsmall bitmap image default args} {
    global tkPriv tcl_platform GidPriv

    if { [winfo exists .gid.central.s] && ( [.gid.central.s disable windows] || \
	    [.gid.central.s info variables usemorewindows] == 0 ) } return

    if 0 {
	#if { $tcl_platform(platform) == "windows" && $default>= 0 && $textsmall == "" } {
	#}
	switch -- [string tolower $args] {
	    "ok" { set type ok }
	    "ok cancel" { set type okcancel }
	    "yes no" { set type yesno }
	    "yes no cancel" { set type  yesnocancel }
	    default { set type "" }
	}
	if { $type != "" } {
	    if { $w == "" } {
		if { [winfo exists .gid] } {
		    set parent ".gid"
		} else { set parent "." }
	    } else { regsub {[.][^.]*$} $w {} parent }
	    if {$parent == ""} {
		if { [winfo exists .gid] } {
		    set parent ".gid"
		} else { set parent "." }
	    }
	    set deft [lindex [string tolower $args] $default]
	    if { $bitmap != "error" && $bitmap != "info" && $bitmap != "question" && \
		    $bitmap != "warning" } { set bitmap question }
	    set retval [tk_messageBox -default $deft -icon $bitmap -message $text -parent $parent \
		    -title $title -type $type]
	    set ipos [lsearch [string tolower $args] $retval]
	    return $ipos
	}
    }

    if { $w == "" } { 
	if { [winfo exists .gid] } {
	    set w .gid.__dialogram
	} else { set w .__dialogram }
    }

    # 1. Create the top-level window and divide it into top
    # and bottom parts.

    while { [winfo exists $w] } { append w a }

    catch {destroy $w}
    toplevel $w -class OverlayWindow

    wm title $w $title
    wm iconname $w Dialog
    wm protocol $w WM_DELETE_WINDOW { }

    # The following command has been removed because if it is present
    # the dialog won't be posted if [winfo parent $w] is iconified.

    if { $tcl_platform(platform) == "windows" } {
	wm transient $w [winfo toplevel [winfo parent $w]]
    }

    if { $default == -2 } {
	set default 0
	bind $w <2> "set tkPriv(button) -2"
	bind $w <Control-x><Control-l> "set tkPriv(button) -2"
    }

    if { [llength $args] > 6 } {
	frame $w.bot3 -relief raised -bd 1
	pack $w.bot3 -side bottom -fill both
    }
    if { [llength $args] > 3 } {
	frame $w.bot2 -relief raised -bd 1
	pack $w.bot2 -side bottom -fill both
    }
    #frame $w.bot -relief raised -bd 1
    frame $w.bot -bg [CCColorActivo [$w cget -background]]
    pack $w.bot -side bottom -fill both

    if { $textsmall != "" } {
	label $w.ts -text $textsmall -font SmallFont
	pack $w.ts -side bottom -anchor w
    }

    frame $w.top -relief raised -bd 0
    pack $w.top -side top -fill both -expand 1

    # 2. Fill the top part with bitmap and message (use the option
    # database for -wraplength so that it can be overridden by
    # the caller).

#    option add *Dialog.msg.wrapLength 3i widgetDefault
    label $w.msg -justify left -text $text -wraplength 75m -font BigFont

    pack $w.msg -in $w.top -side right -expand 1 -fill both -padx 3m -pady 3m
    if {$image != ""} {
	label $w.bitmap -image $image
	pack $w.bitmap -in $w.top -side left -padx 3m -pady 3m
    } elseif {$bitmap != ""} {
	if {$bitmap == "gidquestionhead" } {
	    set image $bitmap
	    label $w.bitmap -image $image
	} else {
	    label $w.bitmap -bitmap $bitmap
	}
	pack $w.bitmap -in $w.top -side left -padx 3m -pady 3m
    }

    # 3. Create a row of buttons at the bottom of the dialog.

    set UnderLineList ""
    set i 0
    set lentext 8
    foreach but $args {
	regsub -all {([a-z0-9])([A-Z])} $but {\1 \2} but
	if { [string length $but] > $lentext } {
	    set lentext [string length $but]
	}
    }
    foreach but $args {
	regsub -all {([a-z0-9])([A-Z])} $but {\1 \2} but
	button $w.button$i -text $but -command "set tkPriv(button) $i" \
		-width $lentext -bd 1
	if { $i < 3 } {
	    pack $w.button$i -in $w.bot -side left -expand 1 \
		    -padx 3m -pady 2m
	} elseif { $i < 6 }  {
	    pack $w.button$i -in $w.bot2 -side left -expand 1 \
		    -padx 3m -pady 2m
	} else {
	    pack $w.button$i -in $w.bot3 -side left -expand 1 \
		    -padx 3m -pady 2m
	}

	bind $w.button$i <Return> "
	    $w.button$i configure -state active -relief sunken
	    update idletasks
	    after 100
	    set tkPriv(button) $i
	"
	if { [regexp -nocase cancel $but] || [regexp -nocase escape $but] || [regexp -nocase close $but] } "
	    bind $w <Escape> \"
	    $w.button$i configure -state active -relief sunken
	    update idletasks
	    after 100
	    set tkPriv(button) $i
	\""
	set lsize [string length $but]
	for {set j 0} {$j < $lsize} {incr j} {
	    set ichar [string tolower [string index $but $j]]
	    if { [lsearch -exact $UnderLineList $ichar] == -1 } {
		lappend UnderLineList $ichar
		$w.button$i conf -underline $j
	      # this catch is to deal with extrange language, like korean
	      catch {
		bind $w <KeyPress-[string toupper $ichar]> "
		   $w.button$i configure -state active -relief sunken
		   update idletasks
		   after 100
		   set tkPriv(button) $i
		"
		bind $w <KeyPress-[string tolower $ichar]> "
		   $w.button$i configure -state active -relief sunken
		   update idletasks
		   after 100
		   set tkPriv(button) $i
		"
	      }

		break
	    }
	}

	incr i
    }

    # 4. Create a binding for <Return> on the dialog if there is a
    # default button.

    # 5. Withdraw the window, then update all the geometry information
    # so we know how big it wants to be, then center the window in the
    # display and de-iconify it.

    if { [winfo parent $w] == ".gid" } {
	bind $w <Destroy> [list DestroyWinInDialogs $w GeomDialog]
    }
    if { [info exists GidPriv(GeomDialog)] && [winfo parent $w] == ".gid" } {
	WmGidGeom $w $GidPriv(GeomDialog)
    } else {
	wm withdraw $w
	update idletasks
	
	# extrange errors with updates
	if { ![winfo exists $w] } { return 0}
	if { $w != ".gid.__dialogram" } {
	    set pare [winfo toplevel [winfo parent $w]]
	    set x [expr [winfo x $pare]+[winfo width $pare ]/2- [winfo reqwidth $w]/2]
	    set y [expr [winfo y $pare]+[winfo height $pare ]/2- [winfo reqheight $w]]
	} else {
	    set x [expr [winfo screenwidth $w]/2 - [winfo reqwidth $w]/2 \
		    - [winfo vrootx [winfo parent $w]]]
	    set y [expr [winfo screenheight $w]/2 - [winfo reqheight $w]/2 \
		    - [winfo vrooty [winfo parent $w]]]
	}
	if { $x < 0 } { set x 0 }
	if { $y < 0 } { set y 0 }
	WmGidGeom $w +$x+$y
	update
	wm deiconify $w
    }

    # 6. Set a grab and claim the focus too.

    set oldFocus [focus]
    tkwait visibility $w
    set oldGrab [grab current $w]
    if {$oldGrab != ""} {
	set grabStatus [grab status $oldGrab]
    }
    grab $w
    if {$default >= 0} {
	focus $w.button$default
	after 100 catch [list "focus -force $w.button$default"]

    } else {
	focus $w
    }

    # 7. Wait for the user to respond, then restore the focus and
    # return the index of the selected button.  Restore the focus
    # before deleting the window, since otherwise the window manager
    # may take the focus away so we can't redirect it.  Finally,
    # restore any grab that was in effect.

    tkwait variable tkPriv(button)

    if { $oldFocus == "" || [catch {focus $oldFocus}] } {
	if { [winfo exists .gid] } {
	    focus [focus -lastfor .gid]
	}
    }

    destroy $w
    if {$oldGrab != ""} {
	if {$grabStatus == "global"} {
	    catch { grab -global $oldGrab }
	} else {
	    catch { grab $oldGrab }
	}
    }
    return $tkPriv(button)
}

proc tk_dialogRAMHelp {w title text bitmap HelpCommand default args} {
    global tkPriv tcl_platform GidPriv
    if { $w == "" } {
	if { [winfo exists .gid] } {
	    set w .gid.__dialogram
	} else { set w .__dialogram }
    }

    # 1. Create the top-level window and divide it into top
    # and bottom parts.

    while { [winfo exists $w] } { append w a }

    catch {destroy $w}
    toplevel $w -class OverlayWindow

    wm title $w $title
    wm iconname $w Dialog
    wm protocol $w WM_DELETE_WINDOW { }

    # The following command has been removed because if it is present
    # the dialog won't be posted if [winfo parent $w] is iconified.

    if { $tcl_platform(platform) == "windows" } {
	wm transient $w [winfo toplevel [winfo parent $w]]
    }

    if { $default == -2 } {
	set default 0
	bind $w <2> "set tkPriv(button) -2"
    }

    if { [llength $args] > 6 } {
	frame $w.bot3 -relief raised -bd 1
	pack $w.bot3 -side bottom -fill both
    }
    if { [llength $args] > 3 } {
	frame $w.bot2 -relief raised -bd 1
	pack $w.bot2 -side bottom -fill both
    }
    frame $w.bot -relief raised -bd 1 -bg [CCColorActivo [$w cget -background]]
    pack $w.bot -side bottom -fill both
    frame $w.top -relief raised -bd 1
    pack $w.top -side top -fill both -expand 1

    # 2. Fill the top part with bitmap and message (use the option
    # database for -wraplength so that it can be overridden by
    # the caller).

#    option add *Dialog.msg.wrapLength 3i widgetDefault
    label $w.msg -justify left -text $text -wraplength 75m -font BigFont

    pack $w.msg -in $w.top -side right -expand 1 -fill both -padx 3m -pady 3m
    if {$bitmap != ""} {
	button $w.bitmap -bitmap $bitmap -command $HelpCommand -bd 1
	pack $w.bitmap -in $w.top -side left -padx 3m -pady 3m -ipadx 2m -ipady 2m
    }

    # 3. Create a row of buttons at the bottom of the dialog.

    set UnderLineList ""
    set i 0
    set lentext 0
    foreach but $args {
	regsub -all {([a-z0-9])([A-Z])} $but {\1 \2} but
	if { [string length $but] > $lentext } {
	    set lentext [string length $but]
	}
    }
    foreach but $args {
	regsub -all {([a-z0-9])([A-Z])} $but {\1 \2} but
	button $w.button$i -text $but -command "set tkPriv(button) $i" \
		-width $lentext -bd 1
	if { $i < 3 } {
	    pack $w.button$i -in $w.bot -side left -expand 1 \
		    -padx 3m -pady 2m
	} elseif { $i < 6 }  {
	    pack $w.button$i -in $w.bot2 -side left -expand 1 \
		    -padx 3m -pady 2m
	} else {
	    pack $w.button$i -in $w.bot3 -side left -expand 1 \
		    -padx 3m -pady 2m
	}
	bind $w.button$i <Return> "
	    $w.button$i configure -state active -relief sunken
	    update idletasks
	    after 100
	    set tkPriv(button) $i
	"
	if { [regexp -nocase cancel $but] || [regexp -nocase escape $but] || [regexp -nocase close $but] } "
	    bind $w <Escape> \"
	    $w.button$i configure -state active -relief sunken
	    update idletasks
	    after 100
	    set tkPriv(button) $i
	\""
	set lsize [string length $but]
	for {set j 0} {$j < $lsize} {incr j} {
	    set ichar [string tolower [string index $but $j]]
	    if { [lsearch -exact $UnderLineList $ichar] == -1 } {
		lappend UnderLineList $ichar
		$w.button$i conf -underline $j
	      # this catch is to deal with extrange language, like korean
	      catch {
		bind $w <KeyPress-[string toupper $ichar]> "
		   $w.button$i configure -state active -relief sunken
		   update idletasks
		   after 100
		   set tkPriv(button) $i
		"
		bind $w <KeyPress-[string tolower $ichar]> "
		   $w.button$i configure -state active -relief sunken
		   update idletasks
		   after 100
		   set tkPriv(button) $i
		"
	      }

		break
	    }
	}

	incr i
    }

    if { [winfo exists $w.bot3] } { 
	set packin $w.bot3
    } elseif { [winfo exists $w.bot2] } { 
	set packin $w.bot2
    } else { set packin $w.bot }
    button $w.help -text [_ "Help"] -command $HelpCommand -bd 1
    pack $w.help -in $packin -side left -expand 1 \
		    -padx 3m -pady 2m


    # 4. Create a binding for <Return> on the dialog if there is a
    # default button.

    # 5. Withdraw the window, then update all the geometry information
    # so we know how big it wants to be, then center the window in the
    # display and de-iconify it.

    if { [winfo parent $w] == ".gid" } {
	bind $w <Destroy> [list DestroyWinInDialogs $w GeomDialog]
    }
    if { [info exists GidPriv(GeomDialog)] && [winfo parent $w] == ".gid" } {
	WmGidGeom $w $GidPriv(GeomDialog)
    } else {
	wm withdraw $w
	update idletasks
	
	# extrange errors with updates
	if { ![winfo exists $w] } { return 0}
	
	if { $w != ".gid.__dialogram" } {
	    set pare [winfo toplevel [winfo parent $w]]
	    set x [expr [winfo x $pare]+[winfo width $pare ]/2- [winfo reqwidth $w]/2]
	    set y [expr [winfo y $pare]+[winfo height $pare ]/2- [winfo reqheight $w]]
	} else {
	    set x [expr [winfo screenwidth $w]/2 - [winfo reqwidth $w]/2 \
		    - [winfo vrootx [winfo parent $w]]]
	    set y [expr [winfo screenheight $w]/2 - [winfo reqheight $w]/2 \
		    - [winfo vrooty [winfo parent $w]]]
	}
	if { $x < 0 } { set x 0 }
	if { $y < 0 } { set y 0 }
	WmGidGeom $w +$x+$y
	update
	wm deiconify $w
    }

    # 6. Set a grab and claim the focus too.

    set oldFocus [focus]
    tkwait visibility $w
    set oldGrab [grab current $w]
    if {$oldGrab != ""} {
	set grabStatus [grab status $oldGrab]
    }
    grab $w
    if {$default >= 0} {
	focus $w.button$default
	after 100 catch [list "focus -force $w.button$default"]

    } else {
	focus $w
    }

    # 7. Wait for the user to respond, then restore the focus and
    # return the index of the selected button.  Restore the focus
    # before deleting the window, since otherwise the window manager
    # may take the focus away so we can't redirect it.  Finally,
    # restore any grab that was in effect.

    tkwait variable tkPriv(button)

    if { $oldFocus == "" || [catch {focus $oldFocus}] } {
	if { [winfo exists .gid] } {
	    focus [focus -lastfor .gid]
	}
    }

    destroy $w
    if {$oldGrab != ""} {
	if {$grabStatus == "global"} {
	    grab -global $oldGrab
	} else {
	    grab $oldGrab
	}
    }
    return $tkPriv(button)
}



proc DestroyWinInDialogs { w geomname } {
    global GidPriv

    bind $w <Destroy> ""
    regexp {[-+]+[0-9]+[-+]+[0-9]+} [wm geom $w] GidPriv($geomname)
#     set GidPriv($geomname) [wm geom $w]
}


#
# This procedure displays a dialog box, with an entry, waits for a button in 
# the dialog to be invoked, then returns the entry.
# If cancel is pressed, it returns: --CANCEL--
#
# Arguments:
# w -                Window to use for dialog top-level.
# title -        Title to display in dialog's decorative frame.
# text -        Message to display in dialog.
# bitmap -        Bitmap to display in dialog (empty string means none).
# type -        Can be:
#                        word:    word without spaces
#                        any:     anything
#                        real:    real
#                        real+:   positive real
#                        int:     int
#                        int+:    positive int
#                        text:    text with spaces and '\n'
#                        textro:  text with spaces and '\n' read-only
# default -    default value for entry
# args -        One or more strings to display in buttons across the
#                bottom of the dialog box.

proc tk_dialogEntryRAM {w title text bitmap type default {btnstxt ""} } {
    global tkPriv GidPriv tcl_platform

    if { $btnstxt == "" } {
	set args [list [_ "Ok"] [_ "Cancel"]]
    } else {
	set args $btnstxt
    }

    # 1. Create the top-level window and divide it into top, middle
    # and bottom parts.

    while { [winfo exists $w] } { append w a }
    catch {destroy $w}
    toplevel $w -class OverlayWindow

    wm title $w $title
    wm iconname $w Dialog
    wm protocol $w WM_DELETE_WINDOW { }

    if { $tcl_platform(platform) == "windows" } {
	wm transient $w [winfo toplevel [winfo parent $w]]
    }

    frame $w.bot -relief raised -bd 1 -bg [CCColorActivo [$w cget -background]]
    pack $w.bot -side bottom -fill both
    frame $w.top -relief raised -bd 1

    if { $type != "text" && $type != "textro"} {
	pack $w.top -side top -fill both -expand 1
    } else {
	pack $w.top -side top -fill both
    }

    frame $w.middle -relief raised -bd 1
    if { $type != "text" && $type != "textro"} {
	entry $w.middle.e -relief sunken -xscroll "$w.middle.xscroll set" \
		-textvariable GidPriv(entry) -bd 1
	if { $type == "password" } { $w.middle.e conf -show * }

	$w.middle.e del 0 end
	if { $default != "" } {
	    #kike,corrección si $default == "", no haría caso a la tecla retroceso
	      $w.middle.e ins end $default
	     $w.middle.e sel from 0 
	    $w.middle.e sel to end
	}

	scrollbar $w.middle.xscroll -relief sunken \
		-orient horizontal -command "$w.middle.e xview" \
		-bd 1 -elementborderwidth 1
#     pack $w.middle.xscroll -side bottom -fill x
#     pack $w.middle.e -side top

	grid $w.middle.e -sticky ew
	grid $w.middle.xscroll -sticky ew

	pack $w.middle

    } else {
	set GidPriv(entry) ""

	text $w.middle.t -relief sunken -width 40 -height 8 \
		-yscroll "$w.middle.yscroll set" -bd 1
	$w.middle.t delete 0.0 end
	$w.middle.t ins end $default
	#$w.middle.t tag add sel 0.0 end
	if { $type == "textro"} {
	    $w.middle.t conf -state disabled
	    bind $w.middle.t <1> "focus $w.middle.t"
	}

	scrollbar $w.middle.yscroll -relief sunken \
		-orient vertical -command "$w.middle.t yview" \
		-bd 1 -elementborderwidth 1

	# grid $w.middle.t $w.middle.yscroll -sticky ewns -ipady 3
	# 
	# grid rowconfigure $w.middle 0 -weight 1
	# grid rowconfigure $w.middle 1 -weight 1
	# grid columnconfigure $w.middle 0 -weight 1
	# grid columnconfigure $w.middle 1 -weight 0
	pack $w.middle.t -side left -expand 1 -fill both
	pack $w.middle.yscroll -expand 1 -fill y

	pack $w.middle -expand 1 -fill both
    }

    # 2. Fill the top part with bitmap and message (use the option
    # database for -wraplength so that it can be overridden by
    # the caller).

#    option add *Dialog.msg.wrapLength 3i widgetDefault
    label $w.msg -justify left -text $text -wraplength 75m -font BigFont

    pack $w.msg -in $w.top -side right -expand 1 -fill both -padx 3m -pady 3m
    if {$bitmap != ""} {
	if {$bitmap == "gidquestionhead" } {
	    set image $bitmap
	    label $w.bitmap -image $image
	} else {
	    label $w.bitmap -bitmap $bitmap
	}
	pack $w.bitmap -in $w.top -side left -padx 3m -pady 3m
    }

    if { $type != "text" && $type != "textro"} {
	bind $w <Return> "
	  $w.button0 configure -state active -relief sunken
	  update idletasks
	  after 100
	  set tkPriv(button) 0
	"
    }

    # 3. Create a row of buttons at the bottom of the dialog.

    set UnderLineList ""
    set i 0
    set default 0
    set lentext 0
    foreach but $args {
	if { [string length $but] > $lentext } {
	    set lentext [string length $but]
	}
    }
    foreach but $args {
	button $w.button$i -text $but -command "set tkPriv(button) $i" \
		-width $lentext -bd 1
	pack $w.button$i -in $w.bot -side left -expand 1 \
		-padx 3m -pady 2m

	bind $w.button$i <Return> "
	$w.button$i configure -state active -relief sunken
	update idletasks
	after 100
	set tkPriv(button) $i
	break
	"

	if { [regexp -nocase cancel $but] || [regexp -nocase escape $but] || [regexp -nocase close $but] } "
	    bind $w <Escape> \"
	    $w.button$i configure -state active -relief sunken
	    update idletasks
	    after 100
	    set tkPriv(button) $i
	\""
	incr i
    }

    # 5. Withdraw the window, then update all the geometry information
    # so we know how big it wants to be, then center the window in the
    # display and de-iconify it.

    if { [winfo parent $w] == ".gid" } {
	bind $w <Destroy> [list DestroyWinInDialogs $w GeomDialog]
    }

    if { [info exists GidPriv(GeomDialog)] && [winfo parent $w] == ".gid"} {
	WmGidGeom  $w $GidPriv(GeomDialog)
    } else {
	wm withdraw $w
	update idletasks
	
	
	# extrange errors with updates
	if { ![winfo exists $w] } { return 0}
	
	set pare [winfo toplevel [winfo parent $w]]
	set x [expr [winfo x $pare]+[winfo width $pare ]/2- [winfo reqwidth $w]/2]
	set y [expr [winfo y $pare]+[winfo height $pare ]/2- [winfo reqheight $w]]
	if { $x < 0 } { set x 0 }
	if { $y < 0 } { set y 0 }
	WmGidGeom $w +$x+$y
	update
	wm deiconify $w
    }

    # 6. Set a grab and claim the focus too.

    set oldFocus [focus]
    tkwait visibility $w
    set oldGrab [grab current $w]
    if {$oldGrab != ""} {
	set grabStatus [grab status $oldGrab]
    }
    grab $w
    
    if { $type != "text" && $type != "textro" } {
	focus $w.middle.e
	after 100 catch [list "focus -force $w.middle.e"]
    } else {
	focus $w.button0
	after 100 catch [list "focus -force $w.button0"]
    } 

    
#     elseif { $type == "textro" } {
#         focus $w.button0
#         after 100 catch [list "focus -force $w.button0"]
#     } else {
#         focus $w.middle.t 
#         after 100 catch [list "focus -force $w.middle.t"]
#     }
 
    # 7. Wait for the user to respond, then restore the focus and
    # return the index of the selected button.  Restore the focus
    # before deleting the window, since otherwise the window manager
    # may take the focus away so we can't redirect it.  Finally,
    # restore any grab that was in effect.

    while 1 {
	tkwait variable tkPriv(button)
	if { $tkPriv(button) == 1} { break }
	if { $type != "text" && $type != "textro" } {
	    set result [$w.middle.e get]
	} else {
	    set result [ $w.middle.t get 0.0 end]
	}
	switch $type {
	    word {
		set result [string trim $result]

		# if { ![regexp {^[  ]*[^ \t]+[  ]*$} $result] } {}
		
		if { [string first { } $result] != -1 } {
		    set errorRes "A single word must be entered"
		}            
	    }
	    real {
		if { ![regexp \
		        {^[  ]*([+-]?[0-9]*\.?[0-9]*([eE][+-]?[0-9]+)?)[  ]*$} \
		        $result] } {
		    set errorRes "One number must be entered"
		}           
	    }
	    real+ {
		if { ![regexp \
		        {^[  ]*([+]?[0-9]*\.?[0-9]*([eE][+-]?[0-9]+)?)[  ]*$} \
		        $result] } {
		    set errorRes "One positive number must be entered"
		}          
	    }
	    int {
		if { ![regexp \
		        {^[  ]*[+-]?[0-9]+[  ]*$} \
		        $result] } {
		    set errorRes "One integer number must be entered"
		}           
	    }
	    int+ {
		if { ![regexp \
		        {^[  ]*[+]?[0-9]*[1-9]+[0-9]*[  ]*$} \
		        $result] } {
		    set errorRes "One positive integer number must be entered"
		}           
	    }
	    text {
		set len [ string length $result]
		# para quitar el \n que anyade el get de antes al final.
		if { $len >= 2} {
		    set result [ string range $result 0 [ expr $len - 2]]
		} else {
		    #kike continue                
		set result "--NULL--"
		}
	    if { ( $result == "\"\"") } {
		set result "--NULL--"
	    }

#                 if { ( $result == "\"\"") || ( $result == "\'\'") } {
#                     WarnWin "res = /$result/"
#                     regsub -all \" $result {\"} textres
#                     regsub -all \' $textres {\'} result
#                     WarnWin "res = /$result/"
#                 }
		#regsub -all \n $result {\n} textres
		#regsub -all \t $textres {\t} result
		set GidPriv(entry) "$result"
	    }
	}
	if { [info exists errorRes] } {
	    tk_dialogRAM $w.tempwin {Error window} $errorRes error 0 [_ "Ok"]
	    unset errorRes
	} else { break }
    }

    if { $oldFocus == "" || [catch {focus $oldFocus}] } {
	if { [winfo exists .gid] } {
	    focus [focus -lastfor .gid]
	}
    }
    destroy $w
    if {$oldGrab != ""} {
	if {$grabStatus == "global"} {
	    grab -global $oldGrab
	} else {
	    grab $oldGrab
	}
    }
    if { $tkPriv(button) == 1} { return --CANCEL-- }
    if { [llength $GidPriv(entry)] > 1 } { 
	return "\"$GidPriv(entry)\"" 
    } else {
	return $GidPriv(entry)
    }
}


#
# This procedure displays a dialog box, with a combobox, waits for a button in 
# the dialog to be invoked, then returns the entry.
# If cancel is pressed, it returns: --CANCEL--
#
# Arguments:
# w -                Window to use for dialog top-level.
# title -        Title to display in dialog's decorative frame.
# text -        Message to display in dialog.
# bitmap -        Bitmap to display in dialog (empty string means none).
# AcceptNew     Can be: TCL_BOOLEAN or 2 (then, word must begin with a letter)
#                       3 (then, one positive number must be entered)
#
# args some words to add to the combo
#

proc tk_dialogComboRAM {w title text bitmap AcceptNew args} {
    global tkPriv GidPriv tcl_platform

    # 1. Create the top-level window and divide it into top, middle
    # and bottom parts.

    while { [winfo exists $w] } { append w a }
    catch {destroy $w}
    toplevel $w -class OverlayWindow

    wm title $w $title
    wm iconname $w Dialog
    wm protocol $w WM_DELETE_WINDOW { }

    if { $tcl_platform(platform) == "windows" } {
	wm transient $w [winfo toplevel [winfo parent $w]]
    }

    frame $w.bot -relief raised -bd 0 -bg [CCColorActivo [$w cget -background]]
    pack $w.bot -side bottom -fill both
    # ramsan 6/02
    #frame $w.top -relief raised -bd 1
    frame $w.top -relief raised -bd 0
    pack $w.top -side top -fill both -expand 1

    frame $w.middle -relief raised -bd 0

    set GidPriv(entry) ""
    set iseditable $AcceptNew
    if { $iseditable > 1 } { set  iseditable 1 }
    # ramsan 6/02
#     combobox $w.middle.e -editable $iseditable \
#             -textvariable GidPriv(entry) -bd 1
    ComboBox $w.middle.e -editable $iseditable \
	-textvariable GidPriv(entry) -bd 1

    set last ""
    set values ""
    foreach i [lindex $args 0] {
	if { $i == $last } { continue }
	# ramsan 6/02
	lappend values $i
	#$w.middle.e add $i
	set last $i
    }
    $w.middle.e configure -values $values

    if { $AcceptNew == 0 || $AcceptNew == 3 } {
	set GidPriv(entry) [lindex [lindex $args 0] 0]
	# ramsan 6/02
#         $w.middle.e sel from 0
#         $w.middle.e sel to end
    }

    pack $w.middle.e -side top -padx 30 -fill x -expand 1 -pady 5
    pack $w.middle -fill x -expand 1 -pady 5


    # 2. Fill the top part with bitmap and message (use the option
    # database for -wraplength so that it can be overridden by
    # the caller).

    option add *Dialog.msg.wrapLength 3i widgetDefault
    label $w.msg -justify left -text $text -wraplength 75m -font BigFont

    pack $w.msg -in $w.top -side right -expand 1 -fill both -padx 3m -pady 3m
    if {$bitmap != ""} {
	if {$bitmap == "gidquestionhead" } {
	    set image $bitmap
	    label $w.bitmap -image $image
	} else {
	    label $w.bitmap -bitmap $bitmap
	}
	pack $w.bitmap -in $w.top -side left -padx 3m -pady 3m
    }

    bind $w <Return> "
       $w.button0 configure -state active -relief sunken
       update idletasks
       after 100
       set tkPriv(button) 0
    "

    # 3. Create a row of buttons at the bottom of the dialog.

    set UnderLineList ""
    set i 0

    set default 0
    set args [list [_ "Ok"] [_ "Cancel"]]
    set lentext 0
    foreach but $args {
	if { [string length $but] > $lentext } {
	    set lentext [string length $but]
	}
    }
    foreach but $args {
	button $w.button$i -text $but -command "set tkPriv(button) $i" \
		-width $lentext -bd 1
	pack $w.button$i -in $w.bot -side left -expand 1 \
		-padx 3m -pady 2m
	bind $w.button$i <Return> "
	    $w.button$i configure -state active -relief sunken
	    update idletasks
	    after 100
	    set tkPriv(button) $i
	    break
	"
	if { [regexp -nocase cancel $but] || [regexp -nocase escape $but] || [regexp -nocase close $but] } "
	    bind $w <Escape> \"
	    $w.button$i configure -state active -relief sunken
	    update idletasks
	    after 100
	    set tkPriv(button) $i
	\""
	incr i
    }

    # 5. Withdraw the window, then update all the geometry information
    # so we know how big it wants to be, then center the window in the
    # display and de-iconify it.

    if { [winfo parent $w] == ".gid" } {
	bind $w <Destroy> [list DestroyWinInDialogs $w GeomDialog]
    }
    if { [info exists GidPriv(GeomDialog)] && [winfo parent $w] == ".gid" } {
	WmGidGeom $w $GidPriv(GeomDialog)
    } else {
	wm withdraw $w
	update idletasks
	# extrange errors with updates
	if { ![winfo exists $w] } { return 0}
	
	set pare [winfo toplevel [winfo parent $w]]
	set x [expr [winfo x $pare]+[winfo width $pare ]/2- [winfo reqwidth $w]/2]
	set y [expr [winfo y $pare]+[winfo height $pare ]/2- [winfo reqheight $w]]
	if { $x < 0 } { set x 0 }
	if { $y < 0 } { set y 0 }
	WmGidGeom $w +$x+$y
	update
	wm deiconify $w
    }

    # 6. Set a grab and claim the focus too.

    set oldFocus [focus]
    tkwait visibility $w
    set oldGrab [grab current $w]
    if {$oldGrab != ""} {
	set grabStatus [grab status $oldGrab]
    }
    grab $w

    # ramsan 6/02
    focus $w.middle.e
    #focus [$w.middle.e cget entry]
    #     after 100 catch [list "focus -force $w.middle.e"]

 
    # 7. Wait for the user to respond, then restore the focus and
    # return the index of the selected button.  Restore the focus
    # before deleting the window, since otherwise the window manager
    # may take the focus away so we can't redirect it.  Finally,
    # restore any grab that was in effect.

    while 1 {
	tkwait variable tkPriv(button)
	if { $tkPriv(button) == 1} { break }
	# ramsan 6/02
	#set result [$w.middle.e get]
	set result $GidPriv(entry)
	
	if { ![regexp {^[          ]*[^ ]+[  ]*$} $result] } {
	    set errorRes [_ "A single word must be entered"]
	}
	if { $AcceptNew == 2 && ![regexp {^[a-zA-Z]} $result] } {
	    set errorRes [_ "Word must begin with a letter"]
	} elseif { $AcceptNew == 3 && ![regexp \
		{^[  ]*([+]?[0-9]*\.?[0-9]*([eE][+-]?[0-9]+)?)[  ]*$} \
		$result] } {
	    set errorRes [_ "One positive number must be entered"]
	}        
	if { [info exists errorRes] } {
	    tk_dialogRAM $w.tempwin [_ "Error window"] $errorRes error 0 [_ "Ok"]
	    unset errorRes
	} else { break }
    }
    
    catch {focus $oldFocus}
    destroy $w
    if {$oldGrab != ""} {
	if {$grabStatus == "global"} {
	    grab -global $oldGrab
	} else {
	    grab $oldGrab
	}
    }
    if { $tkPriv(button) == 1} { return --CANCEL-- }
    return $GidPriv(entry)
}


proc enter_link {w} {
    $w tag configure link -underline on -foreground #336699 
    $w configure -cursor hand2                          
}


proc leave_link {w} {
    $w tag configure link -underline off -foreground #336699 
    $w configure -cursor arrow                          
}

proc CallChooseProblemtype { button } {
    global GidPriv

    set retval [ChooseProblemtype $button]
    if { $retval != "--CANCEL--" } {
	set GidPriv(RegisterModule) $retval
	set GidPriv(RegisterModuletext) ""
	foreach i $GidPriv(RegisterModule) {
	    lappend GidPriv(RegisterModuletext) [file tail [file root $i]]
	}
	if { $GidPriv(RegisterModuletext) == "" } {
	    set GidPriv(RegisterModuletext) ...
	}
	GidHelp $GidPriv(RegisterModulewin) [join $GidPriv(RegisterModuletext) \n]
    }
}

image create photo filefind16 -data {
   R0lGODlhEAAQAIYAAPwCBCQmJDw+PBQSFAQCBMza3NTm5MTW1HyChOT29Ozq
   7MTq7Kze5Kzm7Oz6/NTy9Iza5GzGzKzS1Nzy9Nz29Kzq9HTGzHTK1Lza3AwK
   DLzu9JTi7HTW5GTCzITO1Mzq7Hza5FTK1ESyvHzKzKzW3DQyNDyqtDw6PIzW
   5HzGzAT+/Dw+RKyurNTOzMTGxMS+tJSGdATCxHRydLSqpLymnLSijBweHERC
   RNze3Pz69PTy9Oze1OTSxOTGrMSqlLy+vPTu5OzSvMymjNTGvNS+tMy2pMyu
   nMSefAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
   AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
   AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
   AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAAAA
   LAAAAAAQABAAAAe4gACCAAECA4OIiAIEBQYHBAKJgwIICQoLDA0IkZIECQ4P
   CxARCwSSAxITFA8VEBYXGBmJAQYLGhUbHB0eH7KIGRIMEBAgISIjJKaIJQQL
   FxERIialkieUGigpKRoIBCqJKyyLBwvJAioEyoICLS4v6QQwMQQyLuqLli8z
   NDU2BCf1lN3AkUPHDh49fAQAAEnGD1MCCALZEaSHkIUMBQS8wWMIkSJGhBzB
   mFEGgRsBUqpMiSgdAD+BAAAh/mhDcmVhdGVkIGJ5IEJNUFRvR0lGIFBybyB2
   ZXJzaW9uIDIuNQ0KqSBEZXZlbENvciAxOTk3LDE5OTguIEFsbCByaWdodHMg
   cmVzZXJ2ZWQuDQpodHRwOi8vd3d3LmRldmVsY29yLmNvbQA7
}

proc SearchOtherPasswords { w lst_modules text entry } {

    regexp {Name:\s+(\S+)} $text {} computername

    if { !$lst_modules } {
	set title [_ "Select GiD installation directory where the password is installed"]
    } else {
	set title [_ "Select GiD problemtype.gid directory where the password is installed"]
    }
    set dir [tk_chooseDirectory -initialdir $::GIDDEFAULT -parent $w -title $title \
		 -mustexist 1]
    if { $dir == "" } { return }

    if { !$lst_modules } {
	if { ![file exists [file join $dir scripts TemporalVariables]] } {
	    WarnWin [_ "Error: You must select the directory containing one installed GiD"] $w
	    return
	}
	set fin [open [file join $dir scripts TemporalVariables] r]
	set txt [read $fin]
	close $fin
	
	set rex "(?n)^$computername\\s+(\\S+)\\s.*Fecha caducidad: (.*)\\."
	set olderdate [clock seconds]
	set olderpass ""
	foreach "- pass date" [regexp -inline -all $rex $txt] {
	    foreach "m d y" $date break
	    set date [clock scan "$d $m $y"]
	    if { $date > $olderdate } {
		set olderdate $date
		set olderpass $pass
	    }
	}
	if { $olderpass == "" } {
	    WarnWin [_ "Could not find a valid password in this GiD"]
	    return
	}
	set newpass ""
	set i 0
	while 1 {
	    append newpass [string range $olderpass $i [expr {$i+3}]]-
	    incr i 4
	    if { $i >=[string length $olderpass]  } { break }
	}
	$entry delete 0 end
	$entry insert end [string trimright $newpass -]
    } else {
	if { ![file exists [file join $dir password.txt]] } {
	    WarnWin [_ "Error: You must select the directory containing the problemtype.gid"] $w
	    return
	}
	set fin [open [file join $dir password.txt] r]
	set txt [read $fin]
	close $fin
	
	set rex "(?n)^$computername\\s+(\\S+)"
	set olderpass ""
	foreach "- pass" [regexp -inline -all $rex $txt] {
	    set olderpass $pass
	}
	if { $olderpass == "" } {
	    WarnWin [_ "Could not find a valid password in this problemtype"]
	    return
	}
	$entry delete 0 end
	$entry insert end $olderpass
    }


}

proc tk_dialogEntryPASS {w title text bitmap type default { lst_modules 0}} {
    global tkPriv GidPriv tcl_platform

    # 1. Create the top-level window and divide it into top, middle
    # and bottom parts.

    while { [winfo exists $w] } { append w a }
    catch {destroy $w}
    toplevel $w -class OverlayWindow

    set GidPriv(PassW) $w
    #$w configure -background #EEEEEE

    wm title $w $title
    wm iconname $w Dialog
    wm protocol $w WM_DELETE_WINDOW { }

    if { $tcl_platform(platform) == "windows" } {
	wm transient $w [winfo toplevel [winfo parent $w]]
    }

    frame $w.bot -relief flat -bd 1  -bg [CCColorActivo [$w cget -background]]
    pack $w.bot -side bottom -fill x 
    frame $w.top -relief flat -bd 1  
    pack $w.top -side top -fill both -expand 1

    frame $w.middle -relief raised -bd 1
  
    entry $w.middle.e -relief sunken  -textvariable GidPriv(entry) -bd 1 -width 30
#              -xscroll "$w.middle.xscroll set"

    Button $w.middle.search -image filefind16 -relief link -command \
	[list SearchOtherPasswords $w $lst_modules $text $w.middle.e] -helptext \
	[_ "Use this button to copy the password from previously installed programs"]
	   
    $w.middle.e del 0 end
    $w.middle.e ins end $default
    $w.middle.e sel from 0 
    $w.middle.e sel to end

    if { $lst_modules} {
	set def_back [ $w cget -background]
	set realzado [ CCColorActivo $def_back]
	$w.middle conf -bd 0
	label $w.middle.l1 -text [_ "Choose a module:"]
	label $w.middle.l2 -text [_ "Enter the password:"]
	
	button $w.middle.om -textvar GidPriv(RegisterModuletext) -width 5 -anchor w -bd 1
	set GidPriv(RegisterModuletext) ...
	set GidPriv(RegisterModule) ""
	set GidPriv(RegisterModulewin) $w.middle.om
	GidHelp $w.middle.om ...

	$w.middle.om conf -command "CallChooseProblemtype $w.middle.om" -bd 1 -highlightthickness 1
	
	text $w.middle.msg -bd 4 -relief flat -width 20 -height 3 -wrap word -background $realzado
	$w.middle.msg ins end "This password is used to register the selected modules.\nTo register GiD, please select 'Register' in the 'Help' menu."
	$w.middle.msg conf -state disabled

	grid $w.middle.l1 -sticky e
	grid $w.middle.om -sticky ew -column 1 -row 0
	grid $w.middle.l2 -sticky e
	grid $w.middle.e -sticky ew -column 1 -row 1
	grid $w.middle.msg -sticky news -columnspan 3 -pady 2 -padx 2
	grid rowconfigure $w.middle 0 -weight 1
	grid rowconfigure $w.middle 1 -weight 1
	grid rowconfigure $w.middle 2 -weight 1
	grid columnconfigure $w.middle 1 -weight 1
	pack $w.middle -fill x -padx 5 -pady 5 -ipady 1 -expand 1 -anchor s 

    } else {
	#pack $w.middle.e -side top
	#pack $w.middle
	#label $w.middle.l1 -text [_ "Get it from:"]
	#button $w.middle.b1 -textvar GidPriv(PassWeb) -width 5 \
	#        -anchor w -bd 1 -command "VisitWeb $GidPriv(PassWeb)"
	#grid $w.middle.l1 $w.middle.b1 -sticky ew
	
	$w.middle conf -bd 0
	label $w.middle.l2 -text [_ "Enter the password:"]
	grid $w.middle.l2 $w.middle.e -sticky ew        
	grid columnconfigure $w.middle 1 -weight 1
	pack $w.middle -fill x -padx 5 -ipady 5 -expand 1  -anchor s  
    }

    grid  $w.middle.search -column 2 -row 0
    
    # 2. Fill the top part with bitmap and message (use the option
    # database for -wraplength so that it can be overridden by
    # the caller).

#    option add *Dialog.msg.wrapLength 3i widgetDefault
#    label $w.msg -justify left -text $text -wraplength 75m
    


    text $w.msg -width 30 -height 10 -wrap word -font NormalFont -bd 1

    
    $w.msg tag bind link <1> {VisitWeb $GidPriv(PassWeb)}
    $w.msg tag configure link -underline off -foreground #336699 
    $w.msg tag bind link <Any-Enter> "enter_link $w.msg"
   
    $w.msg tag bind link <Any-Leave> "leave_link $w.msg"



    $w.msg ins 0.0 $text
    $w.msg ins end "\n"  
    $w.msg ins end "or get it from:\n"
    if { $lst_modules} {
	$w.msg ins end "\t" 
	$w.msg ins end $GidPriv(ProgWeb) link
    } else {
	
	$w.msg ins end "\t" 
	$w.msg ins end $GidPriv(PassWeb) link
    }
    

    

    $w.msg conf -state disabled
    bind $w.msg <1> "focus $w.msg"


    pack $w.msg -in $w.top -side top -expand 1 -fill both -padx 1m -pady 1m
    if {$bitmap != ""} {
	if {$bitmap == "gidquestionhead" } {
	    set image $bitmap
	    label $w.bitmap -image $image
	} else {
	    label $w.bitmap -bitmap $bitmap
	}
	#pack $w.bitmap -in $w.top -side left -padx 3m -pady 3m
    }

    bind $w <Return> "
       $w.button0 configure -state active -relief sunken
       update idletasks
       after 100
       set tkPriv(button) 0
    "

    # 3. Create a row of buttons at the bottom of the dialog.

    set UnderLineList ""
    set i 0

    set default 0
    set args [list [_ "Ok"] [_ "Evaluation"] [_ "Cancel"]]
    # mierda de variable no inicializada, set colgaba GiD
    set lentext 0

    foreach but $args {
	if { [string length $but] > $lentext } {
	    set lentext [string length $but]
	}
    }
    foreach but $args {
	button $w.button$i -text $but -command "set tkPriv(button) $i" \
		-width [expr $lentext - 4] -bd 1
	pack $w.button$i -in $w.bot -side left -expand 1 \
		-padx 3m -pady 2m -fill x
	bind $w.button$i <Return> "
	    $w.button$i configure -state active -relief sunken
	    update idletasks
	    after 100
	    set tkPriv(button) $i
	    break
	"
	if { [regexp -nocase cancel $but] || [regexp -nocase escape $but] || [regexp -nocase close $but] } "
	    bind $w <Escape> \"
	    $w.button$i configure -state active -relief sunken
	    update idletasks
	    after 100
	    set tkPriv(button) $i
	\""
	incr i
    }

    # 5. Withdraw the window, then update all the geometry information
    # so we know how big it wants to be, then center the window in the
    # display and de-iconify it.

    wm withdraw $w
    update idletasks
    

    # extrange errors with updates
    if { ![winfo exists $w] } { return 0}

    set pare [winfo toplevel [winfo parent $w]]
    set x [expr [winfo x $pare]+[winfo width $pare ]/2- [winfo reqwidth $w]/2]
    set y [expr [winfo y $pare]+[winfo height $pare ]/2- [winfo reqheight $w]/2]
    if { $x < 0 } { set x 0 }
    if { $y < 0 } { set y 0 }
    WmGidGeom $w +$x+$y
    update
    wm deiconify $w

    # 6. Set a grab and claim the focus too.

    set oldFocus [focus]
    set oldGrab [grab current $w]
    if {$oldGrab != ""} {
	set grabStatus [grab status $oldGrab]
    }
    grab $w

    focus $w.middle.e
    after 100 catch [list "focus -force $w.middle.e"]
 
    # 7. Wait for the user to respond, then restore the focus and
    # return the index of the selected button.  Restore the focus
    # before deleting the window, since otherwise the window manager
    # may take the focus away so we can't redirect it.  Finally,
    # restore any grab that was in effect.

    while 1 {
	tkwait variable tkPriv(button)
	if { $tkPriv(button) == 1} { break }
	set result [$w.middle.e get]
	switch $type {
	    word {
		if { ![regexp {^[  ]*[^ \t]+[  ]*$} $result] } {
		    set errorRes "A single word must be entered"
		}            
	    }
	    real {
		if { ![regexp \
		        {^[  ]*([+-]?[0-9]*\.?[0-9]*([eE][+-]?[0-9]+)?)[  ]*$} \
		        $result] } {
		    set errorRes "One number must be entered"
		}           
	    }
	    real+ {
		if { ![regexp \
		        {^[  ]*([+]?[0-9]*\.?[0-9]*([eE][+-]?[0-9]+)?)[  ]*$} \
		        $result] } {
		    set errorRes "One positive number must be entered"
		}          
	    }
	    int {
		if { ![regexp \
		        {^[  ]*[+-]?[0-9]+[  ]*$} \
		        $result] } {
		    set errorRes "One integer number must be entered"
		}           
	    }
	    int+ {
		if { ![regexp \
		        {^[  ]*[+]?[0-9]*[1-9]+[0-9]*[  ]*$} \
		        $result] } {
		    set errorRes "One positive integer number must be entered"
		}           
	    }
	}
	if { [info exists errorRes] } {
	    tk_dialogRAM $w.tempwin {Error window} $errorRes error 0 [_ "Ok"]
	    unset errorRes
	} else { break }
    }

    catch {focus $oldFocus}
    destroy $w
    if {$oldGrab != ""} {
	if {$grabStatus == "global"} {
	    grab -global $oldGrab
	} else {
	    grab $oldGrab
	}
    } 

    if { $lst_modules} {
	if { $tkPriv(button) == 2 } { 
	    return --CANCEL-- 
	} elseif { ( $tkPriv(button) == 1) && ( $GidPriv(RegisterModule) != "") } { 
	    return "--ACADEMIC-- $GidPriv(RegisterModule)"
	} elseif { ( $tkPriv(button) == 0) && ( $GidPriv(RegisterModule) != "") } { 
	    return "$GidPriv(entry) $GidPriv(RegisterModule)"
	} 
    } else {
	if { $tkPriv(button) == 0} { 
	    regsub -all -- {-} $GidPriv(entry) {} retval
	    regsub -all -- {\n} $retval {} retval2
	    regsub -all -- { } $retval2 {} retval
	    return $retval
	} elseif { $tkPriv(button) == 1} { 
	    return --ACADEMIC--
	} elseif { $tkPriv(button) == 2} { 
	    return --CANCEL-- 
	}
    }
}

proc tk_messageBoxRAM { args } {

    global tkPriv tcl_platform

    set w tkPrivMsgBox
    upvar #0 $w data

    #
    # The default value of the title is space (" ") not the empty string
    # because for some window managers, a 
    #                wm title .foo ""
    # causes the window title to be "foo" instead of the empty string.
    #
    set specs {
	{-default "" "" ""}
	{-icon "" "" "info"}
	{-message "" "" ""}
	{-parent "" "" .}
	{-title "" "" " "}
	{-type "" "" "ok"}
    }

    tclParseConfigSpec $w $specs "" $args

    if {[lsearch {info warning error question} $data(-icon)] == -1} {
	error "invalid icon \"$data(-icon)\", must be error, info, question or warning"
    }
    if {$tcl_platform(platform) == "macintosh"} {
	if {$data(-icon) == "error"} {
	    set data(-icon) "stop"
	} elseif {$data(-icon) == "warning"} {
	    set data(-icon) "caution"
	} elseif {$data(-icon) == "info"} {
	    set data(-icon) "note"
	}
    }

    if ![winfo exists $data(-parent)] {
	error "bad window path name \"$data(-parent)\""
    }

    case $data(-type) {
	abortretryignore {
	    set buttons {
		{abort  -width 6 -text [_ "Abort"] -under 0}
		{retry  -width 6 -text [_ "Retry"] -under 0}
		{ignore -width 6 -text [_ "Ignore"] -under 0}
	    }
	}
	ok {
	    set buttons {
		{ok -width 6 -text [_ "Ok"] -under 0}
	    }
	    if {$data(-default) == ""} {
		set data(-default) "ok"
	    }
	}
	okcancel {
	    set buttons {
		{ok     -width 6 -text [_ "Ok"]     -under 0}
		{cancel -width 6 -text [_ "Cancel"] -under 0}
	    }
	}
	retrycancel {
	    set buttons {
		{retry  -width 6 -text [_ "Retry"]  -under 0}
		{cancel -width 6 -text [_ "Cancel"] -under 0}
	    }
	}
	yesno {
	    set buttons {
		{yes    -width 6 -text [_ "Yes"] -under 0}
		{no     -width 6 -text [_ "No"]  -under 0}
	    }
	}
	yesnocancel {
	    set buttons {
		{yes    -width 6 -text [_ "Yes"] -under 0}
		{no     -width 6 -text [_ "No"]  -under 0}
		{cancel -width 6 -text [_ "Cancel"] -under 0}
	    }
	}
	default {
	    error "invalid message box type \"$data(-type)\", must be abortretryignore, ok, okcancel, retrycancel, yesno or yesnocancel"
	}
    }

    if [string compare $data(-default) ""] {
	set valid 0
	foreach btn $buttons {
	    if ![string compare [lindex $btn 0] $data(-default)] {
		set valid 1
		break
	    }
	}
	if !$valid {
	    error "invalid default button \"$data(-default)\""
	}
    }

    # 2. Set the dialog to be a child window of $parent
    #
    #
    if [string compare $data(-parent) .] {
	set w $data(-parent).__tk__messagebox
    } else {
	set w .__tk__messagebox
    }

    # 3. Create the top-level window and divide it into top
    # and bottom parts.

    catch {destroy $w}
    toplevel $w -class Dialog
    wm title $w $data(-title)
    wm iconname $w Dialog
    wm protocol $w WM_DELETE_WINDOW { }
    wm transient $w $data(-parent)
    if {$tcl_platform(platform) == "macintosh"} {
	unsupported1 style $w dBoxProc
    }

    frame $w.bot
    pack $w.bot -side bottom -fill both 
    frame $w.top
    pack $w.top -side top -fill both -expand 1
    if {$tcl_platform(platform) != "macintosh"} {
	$w.bot configure -relief raised -bd 1
	$w.top configure -relief raised -bd 1
    }

    # 4. Fill the top part with bitmap and message (use the option
    # database for -wraplength so that it can be overridden by
    # the caller).

    option add *Dialog.msg.wrapLength 3i widgetDefault
    label $w.msg -justify left -text $data(-message) -font BigFont

    pack $w.msg -in $w.top -side right -expand 1 -fill both -padx 3m -pady 3m
    if {$data(-icon) != ""} {
	label $w.bitmap -bitmap $data(-icon)
	pack $w.bitmap -in $w.top -side left -padx 3m -pady 3m
    }

    # 5. Create a row of buttons at the bottom of the dialog.

    set i 0
    foreach but $buttons {
	set name [lindex $but 0]
	set opts [lrange $but 1 end]
	if ![string compare $opts {}] {
	    # Capitalize the first letter of $name
	    set capName \
		[string toupper \
		    [string index $name 0]][string range $name 1 end]
	    set opts [list -text $capName]
	}

	eval button $w.$name $opts -command [list "set tkPriv(button) $name"] -bd 1

	if ![string compare $name $data(-default)] {
	    $w.$name configure -default active
	}
	pack $w.$name -in $w.bot -side left -expand 1 \
	    -padx 3m -pady 2m

	# create the binding for the key accelerator, based on the underline
	#
	set underIdx [$w.$name cget -under]
	if {$underIdx >= 0} {
	    set key [string index [$w.$name cget -text] $underIdx]
	    bind $w <Alt-[string tolower $key]>  "$w.$name invoke"
	    bind $w <Alt-[string toupper $key]>  "$w.$name invoke"
	}
	incr i
    }

    # 6. Create a binding for <Return> on the dialog if there is a
    # default button.

    if [string compare $data(-default) ""] {
	bind $w <Return> "tkButtonInvoke $w.$data(-default)"
    }

    # 7. Withdraw the window, then update all the geometry information
    # so we know how big it wants to be, then center the window in the
    # display and de-iconify it.

    wm withdraw $w
    update idletasks
    set x [expr [winfo screenwidth $w]/2 - [winfo reqwidth $w]/2 \
	    - [winfo vrootx [winfo parent $w]]]
    set y [expr [winfo screenheight $w]/2 - [winfo reqheight $w]/2 \
	    - [winfo vrooty [winfo parent $w]]]
    wm geom $w +$x+$y
    wm deiconify $w

    # 8. Set a grab and claim the focus too.

    set oldFocus [focus]
    set oldGrab [grab current $w]
    if {$oldGrab != ""} {
	set grabStatus [grab status $oldGrab]
    }
    grab $w
    if [string compare $data(-default) ""] {
	focus $w.$data(-default)
	after 100 catch [list "focus -force $w.$data(-default)"]
    } else {
	focus $w
    }

    # 9. Wait for the user to respond, then restore the focus and
    # return the index of the selected button.  Restore the focus
    # before deleting the window, since otherwise the window manager
    # may take the focus away so we can't redirect it.  Finally,
    # restore any grab that was in effect.

    tkwait variable tkPriv(button)
    catch {focus $oldFocus}
    destroy $w
    if {$oldGrab != ""} {
	if {$grabStatus == "global"} {
	    grab -global $oldGrab
	} else {
	    grab $oldGrab
	}
    }
    return $tkPriv(button)
}

proc WarnWin { text { par .gid}} {

    if { $par == "."} {
	set w .__WarnWin
    } elseif { ![winfo exists $par] } {
	set w .__WarnWin
    } else {
	set w $par.__WarnWin
    }
    tk_dialogRAM  $w Warning $text warning 0 [_ "Ok"]
}

proc WarnWinText { text { title "Warning"}} {
    
    # Traducir el valor por defecto
    if { $title == "Warning" } {
	set title [_ "Warning"]
    }

    if { [winfo exists .gid] } {
	set w .gid.warning
    } else {
	set w .warning 
    }
    if { ! [winfo exists $w] } {
	if {[info exist GidPriv(UseInitWindow)] && $::GidPriv(UseInitWindow)} {
	    InitWindow $w $title WarnWinTextWindowGeom
	} else {
	    toplevel $w
	    wm title $w $title
	}
	#text with scrolls only if required
	frame $w.fr
	scrollbar $w.fr.scrolly -command "$w.fr.t yview" \
		-orient vertical -relief sunken
	scrollbar $w.fr.scrollx -command "$w.fr.t xview"\
		-orient horizontal -relief sunken                
	text $w.fr.t -font SmallFont -yscrollcommand "$w.fr.scrolly set" \
		-xscrollcommand "$w.fr.scrollx set" -wrap none
	
	grid $w.fr.t -row 1 -column 1 -sticky nsew
	grid $w.fr.scrolly -row 1 -column 2 -sticky ns
	grid $w.fr.scrollx -row 2 -column 1 -sticky ew
	grid rowconf $w.fr 1 -weight 1
	grid columnconf $w.fr 1 -weight 1
	grid $w.fr -sticky nsew -padx 5 -pady 5
	
	grid remove $w.fr.scrolly
	grid remove $w.fr.scrollx
	bind $w.fr.t <Configure> "ConfigureTextScroll $w.fr.t $w.fr.scrollx $w.fr.scrolly"

	#text must be a text or cavas widget and sx,sy scrollbar widgets
	proc ConfigureTextScroll { text sx sy } {
	    foreach i "x y" {
		if { ![info exists s${i}] || ![winfo exists [set s${i}]] } { continue }
		foreach "${i}1 ${i}2" [$text ${i}view] break
		
		if { [set ${i}1] == 0 && [set ${i}2] == 1 } {
		    after idle grid remove [set s${i}]
		} else {
		    after idle grid [set s${i}]
		}
	    }
	}
	
	#lower buttons
	set def_back [$w cget -background]
	frame $w.frmButtons -bg [CCColorActivo $def_back]
	button $w.frmButtons.btnclose -text [_ "Close"] \
		-command "destroy $w" \
		-underline 0 -width 6

	grid $w.frmButtons -sticky ews -columnspan 7
	grid $w.frmButtons.btnclose -padx 5 -pady 6
	grid columnconf $w 0 -weight 1
	grid rowconfigure $w 0 -weight 1
    
	focus $w.frmButtons.btnclose
	bind $w <Alt-c> "tkButtonInvoke $w.frmButtons.btnclose"
	bind $w <Escape> "tkButtonInvoke $w.frmButtons.btnclose"
    }
    
    $w.fr.t insert end "$text\n"
    $w.fr.t see end
    ConfigureTextScroll $w.fr.t $w.fr.scrollx $w.fr.scrolly
    update
}

proc CloseWarnWinText { } {
    set w .gid.warning
    if { [winfo exists $w] } {
	destroy $w
    } else {
	set w .warning
	if { [winfo exists $w] } {
	    destroy $w
	}
    }
}

# To Debug GiD tcl whitout a window.
proc DebugInit { filename } {
    global GidPriv
    #open and close to try to write and clear it
    if [catch {open $filename w} f] {
	puts stderr "Cannot open $filename: $f"
	set GidPriv(DebugFilename) ""
    } else {
	set GidPriv(DebugFilename) $filename
	close $f
	file delete $filename
    }
    set GidPriv(DebugInitTime) [ clock seconds]
    set GidPriv(DebugLastTime) $GidPriv(DebugInitTime)
    set tstr [ clock format $GidPriv(DebugInitTime) -format "%H:%M:%S %d.%m.%Y"]
    DebugText "$tstr ----- DebugInit $filename -----"
}

# DebugPrint texto
#    imprime texto en el archivo del DebugInit

proc DebugPrint { text } {
    global GidPriv
    if { $GidPriv(Configuration) != "debug" } {
	return 
    }
    if { ![info exists GidPriv(DebugFilename)] || $GidPriv(DebugFilename) == "" } {
	return
    }
    set f [open $GidPriv(DebugFilename) a]
    puts $f $text
    close $f
}

# DebugText -time -abs -rel -level texto
#    imprime texto en el archivo del DebugInit
#           -time -> imprime el tiempo desde el DebugInit
#           -time -abs -> imprime el tiempo y fecha absolutos & desde el DebugInit
#           -time -rel -> imprime el tiempo desde el ultimo -time -rel & desde el DebugInit
#           -level -> identa el mensaje segun el nivel de pila: num_espacios = 2 * [ info level]

proc DebugText { args} {
    global GidPriv

    if { $GidPriv(Configuration) != "debug" } {
	return 
    }
    if { ![info exists GidPriv(DebugFilename)] || $GidPriv(DebugFilename) == "" } {
	return
    }
    set txt ""
    set inf_time 0
    set inf_abs_time 0
    set inf_rel_time 0
    set inf_level 0
    foreach a $args {
	if { "[ string index $a 0]" == "-"} {
	    set a [ string range $a 1 end]
	    if { ![ string compare -nocase $a "time"]} {
		set inf_time 1
	    } elseif { ![ string compare -nocase -length 3 $a "abs"]} {
		set inf_abs_time 1
	    } elseif { ![ string compare -nocase -length 3 $a "rel"]} {
		set inf_rel_time 1
	    } elseif { ![ string compare -nocase $a "level"]} {
		set inf_level 1
	    }
	} else {
	    if { "$txt" != ""} {
		append txt " $a"
	    } else {
		set txt $a
	    }
	}
    }

    set time_str ""
    if { $inf_time} {
	set tt [ clock seconds]

	# el -3600 es para que al haecr el format con 0 segundos quede 00:00:00
	set dd [ expr $tt - $GidPriv(DebugInitTime) -3600]
	set time_str [ clock format $dd -format "%H:%M:%S"]

	if { $inf_abs_time} {
	    set tstr [ clock format $tt -format "%H:%M:%S %d.%m.%Y"]
	    append time_str " $tstr"
	}

	if { $inf_rel_time} {
	    set dd [ expr $tt - $GidPriv(DebugLastTime) -3600]
	    set dstr [ clock format $dd -format "%H:%M:%S"]
	    append time_str " $dstr"
	    set GidPriv(DebugLastTime) $tt
	}
	append time_str " "
    }

    set level_str ""
    if { $inf_level} {
	set num_espacios [ expr 2 * [ info level]]
	set identacion [ string repeat " " $num_espacios]
	set level_str $identacion
    }

    DebugPrint "$time_str$level_str$txt"
}

#proc DebugTextLevel { text} {
#    set num_espacios [ expr 2 * [ info level]]
#    set identacion [ string repeat " " $num_espacios]
#    DebugText "$identacion$text"
#}
#
#proc DebugAbsTextTime { text } {
#    global GidPriv
#    set tt [ clock seconds]
#    set tstr [ clock format $tt -format "%H:%M:%S %d.%m.%Y"]
#    DebugText "$tstr   $text"
#}
#
#proc DebugTextTime { text } {
#    global GidPriv
#    set tt [ clock seconds]
#    set tstr [ clock format $tt -format "%H:%M:%S %d.%m.%Y"]
#    # el -3600 es para que al haecr el format con 0 segundos quede 00:00:00
#    set dd [ expr $tt - $GidPriv(DebugInitTime) -3600]
#    set dstr [ clock format $dd -format "%H:%M:%S"]
#    #DebugText "$tstr $dstr   $text"
#    DebugText "$dstr   $text"
#}
#
#proc DebugTextTimeLevel { text} {
#    global GidPriv
#    set tt [ clock seconds]
#    set tstr [ clock format $tt -format "%H:%M:%S %d.%m.%Y"]
#    # el -3600 es para que al haecr el format con 0 segundos quede 00:00:00
#    set dd [ expr $tt - $GidPriv(DebugInitTime) - 3600]
#    set dstr [ clock format $dd -format "%H:%M:%S"]
#    set num_espacios [ expr 2 * [ info level]]
#    set identacion [ string repeat " " $num_espacios]
#    #DebugText "$tstr $dstr $identacion$text"
#    DebugText "$dstr $identacion$text"
#}

namespace eval TipWin {
    variable _mostrar
    variable _wid
    variable _id        1
    variable _imagen
}

proc TipWin::Close { title_org} {
    variable _wid

    regsub -all { } $title_org {_} pp
    regsub -all {\.} $pp {_} title

    if { ![ info exist _wid($title)] || ![ winfo exist $_wid($title)]} {
	return
    }

    destroy $_wid($title)
    
}

proc TipWin::CambiaMostrar { title_org w} {
    variable _mostrar

    regsub -all { } $title_org {_} pp
    regsub -all {\.} $pp {_} title

    if { $_mostrar($title)} {
	set _mostrar($title) 0
    } else {
	set _mostrar($title) 1
    }
    $w toggle
}

proc TipWin::CreateWindow { par show_cb title_org args} {
    variable _mostrar
    variable _wid
    variable _id

    regsub -all { } $title_org {_} pp
    regsub -all {\.} $pp {_} title

    if { ![ info exist _mostrar($title)] } {
	set _mostrar($title) 1
    }

    if { !$_mostrar($title)} {
	return
    } else {
	if { [ info exist _wid($title)] && [ winfo exist $_wid($title)]} {
	    raise _wid($title)
	}
    }

    if { "$par" == "."} {
	     set w .__Tip_Win$_id
    } else {
	set w $par.__Tip_Win$_id
    }
    incr _id

    set _wid($title) $w

    toplevel $w    

    wm title $w $title_org

    set def_back [ $w cget -background]
    set realzado [ CCColorActivo $def_back]

    frame $w.f -bd 0

    set max_w 0
    set txt_w 0
    set txt_h 1
    set txt [ join $args]
    set n_txt [ string length $txt]
    for { set i 0} { $i < $n_txt} { incr i} {
	     incr txt_w
	     if { "[ string index $txt $i]" == "\n"} {
		 incr txt_h
		 if { $txt_w > $max_w} { set max_w $txt_w}
		 set txt_w 0
	     }
    }
    if { $txt_w > $max_w} { set max_w $txt_w}

    text $w.f.t -bd 4 -relief flat -wrap word -background $realzado \
	    -width $max_w -height $txt_h
    $w.f.t ins end $txt
    $w.f.t conf -state disabled
    grid $w.f.t -sticky nwes -padx 4 -pady 8

    if { $show_cb} {
	checkbutton $w.f.cb -text [_ "Show this message again"] -variable TipWin::_mostrar($title) 
	#            -command "TipWin::CambiaMostrar $title $w.f.cb"
	grid $w.f.cb -sticky we -padx 4 -pady 8
    }

    # marco de los botones
    frame $w.but -bd 0 -background $realzado

    button $w.but.close -text [_ "Close"] -command "TipWin::Close $title" -takefocus 0 -bd 1
    grid $w.but.close -sticky ews -padx 4 -pady 10

    #enpaquetamos marcos
    grid $w.f -sticky news -padx 0 -pady 0
    grid $w.but -sticky wes

    grid columnconfigure $w 0 -weight 1
    grid rowconfigure $w 0 -weight 1

    AjustaPosicion $w $par

}


proc TipWin::CreateHelpButton { w title args} {
    variable _imagen
    global GIDDEFAULT

    if { ![ info exist _imagen(help)]} {
	set _imagen(help) [ image create photo -file [ file join $GIDDEFAULT bitmaps help.gif]]
    }

    button $w -bd 1 -image $_imagen(help) -command "TipWin::CreateWindow . 0 \"$title\" $args"
}



# This file defines the procedure tk_optionMenuRAM, similar to 
# the standard tk_optionMenu, but separating labels and commands
# to be used in multilingual codes.
# Creates an option button and its associated menu.
#
# ::tk_optionMenuRAM --
# This procedure creates an option button named $w and an associated
# menu.  Together they provide the functionality of Motif option menus:
# they can be used to select one of many values, and the current value
# appears in the global variable varName, as well as in the text of
# the option menubutton.  The name of the menu is returned as the
# procedure's result, so that the caller can use it to change configuration
# options on the menu or otherwise manipulate it.
#
# Arguments:
# w -                        The name to use for the menubutton.
# varname -                Global variable to hold the currently selected value.
# labels -                list of labels to show as menu options.
# values -                list of values (internal commands untranslated).

proc ::tk_optionMenuRAM {w varname labels values} {    
  if { ![info exists ::$varname] } {
    set ::$varname [lindex $values 0]
  }
  
  #RAMSAN & KIKE
  if { [set idx [lsearch $values [set ::$varname]]] == -1 } {
    set idx 0
  }
  set ::GidPriv(tkopt,$w,text) [lindex $labels $idx]
  if { ![winfo exists $w] } {
    menubutton $w -text [lindex $labels $idx] -textvariable ::GidPriv(tkopt,$w,text) -indicatoron 1 -menu $w.menu \
	-relief raised -bd 2 -highlightthickness 2 -anchor c \
	-direction flush
    bind $w <Destroy> "unset ::GidPriv(tkopt,$w,text)"
  } else {
    $w conf -text [lindex $labels $idx] -textvariable ::GidPriv(tkopt,$w,text) -indicatoron 1 -menu $w.menu \
	-relief raised -bd 2 -highlightthickness 2 -anchor c \
	-direction flush
  }
  menu $w.menu -tearoff 0
  foreach i $labels j $values {
    $w.menu add radiobutton -label $i -value $j -variable ::$varname  \
	-command "set ::GidPriv(tkopt,$w,text) [list $i]"
  }

  set cmd [list tk_optionMenuRAMselectlabel $labels $values ::GidPriv(tkopt,$w,text) ::$varname]
  trace add variable ::$varname write $cmd
  bind $w <Destroy> [list trace remove variable ::$varname write $cmd]

  return $w.menu
}


proc tk_optionMenuRAMselectlabel { labels values menutextvariable fullvarname varname field args } {
    if { [info exists ::$fullvarname] } {
	set idx [lsearch $values [set ::$fullvarname]]
    } else {
	set idx -1
    }
    
    if { $idx != -1 } {
	set $menutextvariable [lindex $labels $idx]
    } else {
	#set $menutextvariable ""
	set $menutextvariable [set ::$fullvarname]
    }
}




namespace eval GiDSelectRowWindow {
    variable _w
    variable _list
    variable _seleccion
}

proc GiDSelectRowWindow::Close { } {
    variable _w

    destroy $_w
}

proc GiDSelectRowWindow::GetSelection { } {
    variable _list
    variable _seleccion

    set _seleccion [$_list curselection]
    if { "$_seleccion" != ""} {
	set _seleccion [ $_list get $_seleccion]
	GiDSelectRowWindow::Close
    } else {
	WarnWin [_ "Please, select first one sysinfo"] $_list
    }
}

# -np- GiDSelectRowWindow::Create { {{18 "type" left} {18 "description" left}} {"local machine" 123456789abcdef} {"usb key 1" aaaaaaaabbbbbbbb} {"usb key 2" 7878787812093467}} "Sysinfo selection" "Select one of the following sysinfos to register GiD"
# tabla datos: una lista de listas (filas) de listas(elementos de cada columna), 
# donde la primera contiene el tamaño titulo y justificacion para cada columna
proc GiDSelectRowWindow::Create { tabla_datos title msg { parent .gid}} {
    variable _w
    variable _list
    variable _seleccion
   
    set _w $parent.row_window
    set w $_w

    catch { destroy $w }

    InitWindow $w $title GiDSelectRowWindowGeom

    frame $w.f1

    if { "$msg" != ""} {
	label $w.f1.l1 -text "$msg" \
	    -height 1 -font BoldFont -justify left -anchor w
    }

    set sw  [ ScrolledWindow $w.f1.lf \
	    -auto both -relief groove -borderwidth 2]

    set cols {}
    #
    set cab [ lindex $tabla_datos 0]
    foreach c $cab {
	foreach e $c {
	    lappend cols $e
	}
    }
    
    set _list [ tablelist::tablelist $sw.lb \
	    -exportselection 0 \
	    -columns $cols \
	    -labelcommand tablelist::sortByColumn \
	    -background white \
	    -selectbackground navy -selectforeground white \
	    -stretch end  \
	    -highlightthickness 0]
    #-selectmode extended
    $sw setwidget $_list
    
    if { "$msg" != ""} {
	grid $w.f1.l1    -     -sticky ew
    }
    grid $sw         -     -sticky nsew
    grid columnconf $w.f1 1 -weight 1
    grid rowconf $w.f1 1 -weight 1

    set def_back [$w cget -background]
    frame $w.buts -bg [CCColorActivo $def_back]

    button $w.buts.b1 -text [_ "Select"] -bd 1 -command "GiDSelectRowWindow::GetSelection"
    button $w.buts.b2 -text [_ "Cancel"] -bd 1 -command "GiDSelectRowWindow::Close"

    grid $w.buts.b1 $w.buts.b2 -padx 4 -pady 10

    grid $w.f1 -sticky nsew
    grid $w.buts -sticky ew
    grid columnconf $w 0 -weight 1
    grid rowconf $w 0 -weight 1

    update idletasks
    if { "$msg" != ""} {
	#$w.f1.l1 conf -wraplength [winfo reqwidth $w]
    }
    
    update
    
    # a rellenar datos
    $_list delete 0 end
    for { set i 1} { $i < [ llength $tabla_datos]} { incr i} {
	set f [ lindex $tabla_datos $i]
	$_list insert end $f
    }

    set _seleccion ""
    tkwait window $_w
    return $_seleccion

}
