
# <20180312.1430.32>

# Returns 3 if GUI font is different 1 if any other font is change 0 if no change

proc EditFont {font} {
  
  # We come here only when the user wants to change the font thus
  # mostly this code should not be loaded.
  global FontInfo FontInfos FontList  WhichFontToSet config FontSelDone FontApply glob
#  puts "entry"

  set FontList { ListBoxFont GuiFont BalloonHelpFont }
  set WhichFontToSet $font

  set FontInfos(BalloonHelpFont,gloss) [_ "BalloonHelpFont"]
  set FontInfos(BalloonHelpFont,help) \
      {[_b "This font is used in help balloons."]}
  set FontInfos(BalloonHelpFont,fg) $glob(gui,color_balloonHelp_fg)
  set FontInfos(BalloonHelpFont,bg) $glob(gui,color_balloonHelp_bg)
  set FontInfos(ListBoxFont,gloss) [_ "ListBoxFont"]
  set FontInfos(ListBoxFont,help) \
      {[_b "This font is used in list boxes and should be a fixed font."]}
  set FontInfos(ListBoxFont,bg) $glob(gui,color_bg)
  set FontInfos(ListBoxFont,fg) $glob(gui,color_fg)
  set FontInfos(GuiFont,gloss) [_ "GuiFont"]
  set FontInfos(GuiFont,help) {[_b "This font is used in buttons and labels."]}
  # save what we start with...
  set lListBoxFont $glob(gui,ListBoxFont)

  foreach font $FontList {
    set l$font $glob(gui,$font)
    catch {font delete $font}
    if {[catch {font actual $glob(gui,$font)} out] != 0} {
      # it must not exist, use the default...
      set $glob(gui,$font) TkDefaultFont
    }
    fontsel::FontToFontInfos $glob(gui,$font) $font
  }
  fontsel::SetFontInfoDefaults
  fontsel::CreateFonts
  fontsel::RecordDefaults
#  puts "$WhichFontToSet"
  trace add variable FontApply write ApplyNewFont
  fontsel::CreateFontControlPanel
  vwait FontSelDone
  trace remove variable FontApply write ApplyNewFont
  return [expr {$lGuiFont != $glob(gui,GuiFont) ? 3 : \
		    $lListBoxFont     != $glob(gui,ListBoxFont) ||\
		    $lBalloonHelpFont != $glob(gui,BalloonHelpFont)}]
}
proc ApplyNewFont {args} {
  global FontApply config glob
  # frputs args FontApply "[fontsel::FontToTcl $FontApply] "
  set glob(gui,$FontApply) [fontsel::FontToTcl $FontApply]
  ReConfigFont
}
