

proc AddFontSizes { combo } {

    set sizes "8 9 10 11 12 14 16 18 20 22 24 26 28 36 48 72"
    foreach i $sizes {
	$combo add $i
    }
}

proc ChangeFont { font label name1 name2 op } {
    global ChangeVarInfo
    catch {
	$label conf -font [list $ChangeVarInfo($font,family) \
		$ChangeVarInfo($font,size) $ChangeVarInfo($font,weight) \
		$ChangeVarInfo($font,slant)]
    }
}

proc pref_fonts_ui {root args} {
    global ChangeVarInfo
	# this treats "." as a special case

	if {$root == "."} {
	    set base ""
	} else {
	    set base $root
	}
        set fontnames "NormalFont FixedFont BigFont CommentsFont LabelsFont"
	set fontlabels [list [_ "Normal Font"] [_ "Fixed Font"] [_ "Big Font"] [_ "Comments Font"] [_ "Labels / Dimensions Font"]]
	foreach i $fontnames lname $fontlabels {
	    set fw [string tolower $i]
	    frame $base.f1$fw -bd 2 -relief ridge

	    label $base.l1$fw -text $lname

	    set def_fnt [ font actual [ $base.l1$fw cget -font]]
	    set def_back [ CCGetRGB $base.l1$fw [ $base.l1$fw cget -background]]

	    combobox $base.cb1$fw -textvariable ChangeVarInfo($i,family)
	    set ChangeVarInfo($i,combo) $base.cb1$fw
	    combobox $base.cb2$fw -textvariable ChangeVarInfo($i,size) \
		    -width 3
	    AddFontSizes $base.cb2$fw
	   
	    if { [ lsearch [ font names] Weight_$i] == -1} {
		font create Weight_$i
	    }
	    eval [ concat font conf Weight_$i $def_fnt]
	    SwitchButton $base.mb1$fw \
		    "global ChangeVarInfo; set ChangeVarInfo($i,weight) bold;   font conf Weight_$i -weight bold" \
		    "global ChangeVarInfo; set ChangeVarInfo($i,weight) normal; font conf Weight_$i -weight normal" \
		    -text B -bd 1 -width 1 -padx 4 -pady 1 -font Weight_$i -activebackground [ CCColorActivo $def_back]

	    if { [ lsearch [ font names] Slant_$i] == -1} {
		font create Slant_$i
	    }
	    eval [ concat font conf Slant_$i $def_fnt]
	    SwitchButton $base.mb2$fw \
		    "global ChangeVarInfo; set ChangeVarInfo($i,slant) italic; font conf Slant_$i -slant italic" \
		    "global ChangeVarInfo; set ChangeVarInfo($i,slant) roman;  font conf Slant_$i -slant roman" \
		    -text I -bd 1 -width 1 -padx 4 -pady 1 -font Slant_$i -activebackground [ CCColorActivo $def_back]

	    foreach j "family size weight slant" {
		trace variable ChangeVarInfo($i,$j) w \
			"ChangeFont $i $base.l1$fw"
	    }
	    grid $base.l1$fw -in $base.f1$fw -row 1 -column 1 -sticky w \
		    -columnspan 4
	    grid $base.cb1$fw -in $base.f1$fw -row 2 -column 1 -sticky we
	    grid $base.cb2$fw -in $base.f1$fw -row 2 -column 2 -sticky w -padx 2
	    # grid $base.mb1$fw -in $base.f1$fw -row 3 -column 1 -sticky w
	    # grid $base.mb2$fw -in $base.f1$fw -row 3 -column 2 -sticky w
	    grid $base.mb1$fw -in $base.f1$fw -row 2 -column 3 -sticky w -padx 2
	    grid $base.mb2$fw -in $base.f1$fw -row 2 -column 4 -sticky w -padx 2
	    # grid rowconfigure $base.f1$fw 1 -weight 1 -minsize 40
	    # grid rowconfigure $base.f1$fw 2 -weight 1 -minsize 2
	    # grid rowconfigure $base.f1$fw 3 -weight 1 -minsize 2
	    grid rowconfigure $base.f1$fw 1 -weight 1 -minsize 40
	    grid rowconfigure $base.f1$fw 2 -weight 1
	    #grid columnconfigure $base.f1$fw 1 -weight 1 -minsize 2
	    grid columnconfigure $base.f1$fw 1 -weight 1
	}

	set irow 1
	foreach i "NormalFont FixedFont BigFont CommentsFont LabelsFont" {
	    set fw [string tolower $i]
	    grid $base.f1$fw -in $root -row $irow -column 1 -sticky ew \
		    -padx 6 -pady 3
	    incr irow
	}
	grid rowconfigure $root 1 -weight 1 -minsize 2
	grid rowconfigure $root 2 -weight 1 -minsize 2
	grid rowconfigure $root 3 -weight 1 -minsize 2
	grid rowconfigure $root 4 -weight 1 -minsize 2
	grid columnconfigure $root 1 -weight 1 -minsize 200


	GidHelp "$base.f1normalfont [grid slaves $base.f1normalfont]" \
        	[_ "This is the font normally used inside GiD."]

	GidHelp "$base.f1fixedfont [grid slaves $base.f1fixedfont]" \
	        [_ "This font must have the same spacing for every letter. It is\
		used in places where this property is necessary."]

	GidHelp "$base.f1bigfont [grid slaves $base.f1bigfont]" \
	        [_ "This font is used in some dialog boxes."]

	GidHelp "$base.f1commentsfont [grid slaves $base.f1commentsfont]" \
         	[_ "This font is used to draw Comments on the graphic window."]

	GidHelp "$base.f1labelsfont [grid slaves $base.f1labelsfont]" \
         	[_ "This font is used to draw Labels and Dimensions on the graphic window."]

# additional interface code
# end additional interface code

}


# Allow interface to be run "stand-alone" for testing

catch {
    if {$argv0 == [info script]} {
	wm title . [_ "Testing pref_general"]
	pref_general_ui .
    }
}
