# Voreinstellungsmenü für Briefe / Letter
#
# Copyright (C) 2000  G. Lamprecht, W. Lotz, R. Weibezahn; IWD, Bremen University

############################################################################################
############################################################################################
# noch erledigen: 
# -  locals_english/letter.vst  erstellen
# -  Hilfetext-Dateien erstellen
############################################################################################
############################################################################################

proc mv  {} {

proc mvanzeige {s1} {
 global Wm vv lettext letter letoptions letback letbackalw mvFoc
 set cmd [lindex $letter 0]
 if [winfo exists $Wm.b.ad] {
   if {$cmd==""}	{$Wm.b.ad configure -text "$vv(mvbad1)"} \
   else			{$Wm.b.ad configure -text "$vv(mvbad2)  $lettext"}
 }
 if {($s1=="disp")&&($mvFoc!=0)} {mvopt}
 $Wm.cb delete 0 end; $Wm.cb insert end "$letoptions"
 if {$s1!=""} {
   set t "$s1\n\n$lettext\n\n $vv(ausg2)  $letter\n $vv(ausg3)  $letoptions"
   if {$letbackalw==1} {set b "letback: $letback"} {set b "letbackalw: $letbackalw"}
   writescr0 $Wm.d.tt "$t\n\n $b\n"
 }
}

proc mvsel {s} {global Wm vv mvsep
 mvfocus $Wm.d.tt; set_letter_vars "$mvsep" "$s"; mvanzeige "$vv(mv1)"; knoepfe
}

proc mvfocus {w} {global Wm mvFoc; if {$mvFoc==1} {mvopt}; if {$w!=""} {focus $w} {Focus $Wm}}

proc mvopt {} {global Wm vv letoptions mvFoc
    set letoptions [$Wm.cb get]; writescr0 $Wm.d.tt "$vv(aus4)\n $letoptions\n"; set mvFoc 0
}

proc mvWmae {} {global Wm; mvfocus ""; destros $Wm; knoepfe; unlock_list}


global vv Wm lettext mvsep mvFoc XTEMPATH HOME language vst_dir

toplevel_init $Wm "$vv(mvvor)" 0 0;  set tyh 18;  set mvFoc 0


# Bereich a fuer erste Buttons

insertTopButtons $Wm mv_h mvWmae
button $Wm.a.g -text "$vv(ag)" -command \
	{mvfocus $Wm.d.tt; vstr_letter; mvanzeige "$vv(ausg1)"; knoepfe}
Bind3HF $Wm.a.g mv_grund $Wm.d.tt
pack configure $Wm.a.g -side left -padx 3 -pady 3


# Bereich bv fuer eigene Einstellungen

frame  $Wm.bv;  pack configure $Wm.bv -pady 13 -anchor w
label  $Wm.bv.dv -text "$vv(bvdv)" -width 23 -anchor w
Bind3HF $Wm.bv.dv z_voreinst1 $Wm.d.tt
button $Wm.bv.va -text "$vv(bvva)" -command {mvfocus ""; mvanzeige "$vv(aus0)"}
Bind3HF $Wm.bv.va z_voreinst1 $Wm.d.tt
pack configure $Wm.bv.dv $Wm.bv.va -side left


# Bereich b fuer Anzeigen

frame $Wm.b; pack configure $Wm.b -anchor w
label $Wm.b.ad -width 90 -anchor w; pack configure $Wm.b.ad -anchor w
Bind3HF $Wm.b.ad mv_anzeig $Wm.d.tt

# Bereich c fuer Wechsel

frame $Wm.c; pack configure $Wm.c -anchor w
frame $Wm.c.ipp; pack configure $Wm.c.ipp -pady 1 -side left;#letter program
frame $Wm.c.ira; pack configure $Wm.c.ira -pady 1 -side left;#letter in background

set mvsep [getsep letter.vst]
set dli ""; set ct 0; set cxtlerr 0; set ter ""
foreach le [vst2list letter.vst 1 $mvsep "$lettext" mvsel_v] {
  incr ct
  set prog [getvalue $le 1 $mvsep]
  if {("[getvalue $le 1 $mvsep]"=="xtem_letter")} {
    set opt [RegsubHOMEetc [getvalue $le 4 $mvsep]]
      set ins 1; set d0 [lindex $opt 0]; set d1 [lindex $opt 1]; set f $d1/[lindex $opt 2].vst
      CheckCreateXtemlettersDemo $d1
      if {![file isdirectory $d0]} {set ins 0; set ter "$ter  $vv(fs20) '$d0' $vv(anf)\n"}
      if {![file isdirectory $d1]} {set ins 0; set ter "$ter  $vv(fs20) '$d1' $vv(anf)\n"}
      if {![file isfile $f]} {set ins 0; set ter "$ter  $vv(aus5) '$f' $vv(anf)\n"}
      if {$ins==0} {incr cxtlerr; set ter "$ter  (letter.vst, $vv(aein) $ct: $prog $opt)\n\n"}
      if {$ins==1} {lappend dli $le}
  } else {
    lappend dli $le
  }
}
CreateLSBox $Wm.c.ipp $vv(mvcl) top 55 8 2 mv_progsel $Wm.d.tt $mvsep $dli mvsel "" mvWmae
if ![winfo exists $Wm.c.ipp.f.f.li] {destroy $Wm.b}
CreateRBBox $Wm.c.ira $vv(mvcr) "" top 10 2 mv_texpost $Wm.d.tt letback \
    {mvanzeige disp; knoepfe; mvfocus $Wm.d.tt} mvWmae ""

# Ausgabe und Veraendern des Optionen-Strings

label $Wm.ca -anchor sw -text "$vv(mvca)"; pack configure $Wm.ca -anchor sw -ipady 5
Bind3HF $Wm.ca mv_optedi $Wm.d.tt
entry $Wm.cb -width 80 -relief sunken;  pack configure $Wm.cb -anchor nw -padx 4
bind  $Wm.cb <Button-1> {mvfocus $Wm.cb; set mvFoc 1}
Bind3HF $Wm.cb mv_optedi $Wm.d.tt
bind  $Wm.cb <Return> {mvopt; mvfocus $Wm.d.tt}


InsertTextFrame $Wm $tyh "" "" ""

if {$cxtlerr>0} \
    {writescr $Wm.d.tt "$vv(errf) $vst_dir/letter.vst\n\n$ter$vv(aign); $vv(adm)"; mybell 2}
mvChkBackWidg; mvanzeige ""; set mvFoc 0
}
