# $Source: /usr/local/SimSoft/Sfx3D/src/gts/gts09.tcl,v $
# $Revision: 1.2 $
# $Author: baum $
# $Date: 2001/11/29 15:18:10 $
#
# Login name of the user who locked the revision
# $Locker:  $
# Tag name used to checkout the file
# $Name: Release-14 $
# State assigned to revision
# $State: Exp $
#
#
# $Log: gts09.tcl,v $
# Revision 1.2  2001/11/29 15:18:10  baum
# -Realzeitsteuerung eingebaut
# -Handsteuerung eingebaut
#

option add *BalloonInfo*background #ffff80 
option add *BalloonInfo*foreground black  widgetDefault
option add *BalloonInfo.info.wrapLength 4i widgetDefault
option add *BalloonInfo.info.justify left widgetDefault
if {$platform == "windows"} {
option add *BalloonInfo.info.font  "Helvetica 8" 
} else {
  option add *BalloonInfo.info.font  "Helvetica 10" 
}
           
toplevel .balloonInfo -class BalloonInfo \
         -background black -borderwidth 1 -relief flat
label    .balloonInfo.arrow -anchor nw -text " "
pack     .balloonInfo.arrow -side left -fill y
label    .balloonInfo.info -text " \n "
pack     .balloonInfo.info -side left -fill y
wm overrideredirect .balloonInfo 1
wm withdraw .balloonInfo
set BInfo(balloonInfo) 0

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc BalloonInfo_show { mausX mausY nr typ x y z w } {
  global GTS BInfo
  set BInfo(balloonInfo) 1
  set name $GTS($typ,Name)
  set msg [format "Baustein %d Typ:%s\nPosition:X=%sm, Y=%sm, Z=%sm, W=%s°"\
           $nr $name $x $y $z $w]      
  .balloonInfo.info configure -text $msg
  set x [expr [winfo rootx .action.draw.drawZ.togl] + $mausX]
  set y [expr [winfo rooty .action.draw.drawZ.togl] + $mausY - \
              [winfo height .balloonInfo]]
  wm deiconify .balloonInfo
  wm geometry .balloonInfo +$x+$y
  update
  raise .balloonInfo
}
## ENDE BalloonInfo_show

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc BalloonInfo_cancel { } {
  global BInfo
  if { $BInfo(balloonInfo) == "1" } { 
    wm withdraw .balloonInfo 
    set BInfo(balloonInfo) 0
  }
}
## ENDE BalloonInfo_cancel

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc dialog_icon { win } {
  global DlgXPos DlgYPos
  scan [wm geometry $win] "%dx%d+%d+%d" w h DlgXPos DlgYPos
  wm withdraw $win
}
## ENDE dialog_icon

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc dialog_deicon { win } {
  global DlgXPos DlgYPos
  wm deiconify $win         
  dialog_pos $win
  raise $win
  grab set $win
}
## ENDE dialog_deicon

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc dialog_destroy { win } {
  global DlgXPos DlgYPos Confirm
  scan [wm geometry $win] "%dx%d+%d+%d" w h DlgXPos DlgYPos
  unset Confirm($win)
  wm withdraw $win         
  catch { destroy $win }
}
## ENDE dialog_deicon

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc dialog_label { win label lweite {side "top"} } {
  set count 0
  set w "$win.[incr count]"
  while {[winfo exist $w]} { set w "$win.[incr count]" }
  frame $w
  label $w.label -text $label -anchor w
  
  pack $w.label -side left  -anchor w -padx 2
  pack $w -side $side -expand no -fill x -padx 5 -pady 5
  return $w.label
}
## ENDE Dialog_label

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc dialog_entry { win label lweite einheit eweite vorgabe {cmd "None"} {cmd1 ""} {side "top"}} {
  set count 0
  set w "$win.[incr count]"
  while {[winfo exist $w]} { set w "$win.[incr count]" }
  frame $w
  set exp "no"
  if { $eweite < 0 } { 
    set exp "yes" 
    set eweite [expr ($eweite * -1)]
  }

  if {$lweite > 0} {
    tixLabelEntry $w.e -label $label -options { label.anchor w }
    [$w.e subwidget label] config -width $lweite
    [$w.e subwidget entry] config -width $eweite
    set ef [$w.e subwidget entry]
    $ef config -width $eweite
  } else {
    entry $w.e -width $eweite
    set ef $w.e
  }
  $ef delete 0 end
  $ef insert 0 $vorgabe
  label $w.einheit -text $einheit -anchor w
  
  if {[lsearch $cmd "String"] != -1} {
     bind $ef <KeyPress> { if {[IstString %A %W] == 0 } { bell; break } }
     bind $ef <KeyPress-Delete>    { setButtonStatus %W }
     bind $ef <KeyPress-BackSpace> { setButtonStatus %W }
  } elseif {[lsearch $cmd "Float"] != -1} {
     bind $ef <KeyPress>   { if {[IstFloat %A %W] == 0 } { bell; break } }  
     bind $ef <KeyRelease> { if {[%W get]         == ""} { %W insert 0 "0.0" } }
     bind $ef <KeyPress-Delete>    { setButtonStatus %W }
     bind $ef <KeyPress-BackSpace> { setButtonStatus %W }
  } elseif {[lsearch $cmd "Int"] != -1} {
     bind $ef <KeyPress>   { if {[IstInt %A %W ""] == 0 } { bell; break } }
     bind $ef <KeyRelease> { if {[%W get]           == ""} { %W insert 0 "0" } }
     bind $ef <KeyPress-Delete>    { setButtonStatus %W }
     bind $ef <KeyPress-BackSpace> { setButtonStatus %W }
  } elseif {[lsearch $cmd "-Int"] != -1} {
     bind $ef <KeyPress>   { if {[IstInt %A %W "-"] == 0 } { bell; break } }  
     bind $ef <KeyRelease> { if {[%W get]            == ""} { %W insert 0 "0" } }
     bind $ef <KeyPress-Delete>    { setButtonStatus %W }
     bind $ef <KeyPress-BackSpace> { setButtonStatus %W }
  } elseif {[lsearch $cmd "None"] != -1} {
  } else {
    put_win "Fehler in dialog_add: $cmd ->Falscher Eingabetyp!\n"
  }  
  global BSTATUS
  set BSTATUS($ef) $cmd1
  pack $w.e       -side left  -expand $exp -fill x -anchor w -padx 2
  pack $w.einheit -side left  -anchor w -padx 2
  pack $w -side $side -expand no -fill x -padx 5 -pady 5
  return $ef
}
## ENDE Dialog_entry

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc dialog_entry_getlabel { fname } {
  set stelle [expr ([string last "." $fname] - 1)]
  set str [string range $fname 0 $stelle]
  set stelle [expr ([string last "." $str] - 1)]
  set nstr [string range $str 0 $stelle]
  return $nstr
}
## ENDE dialog_entry_getlabel

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc dialog_create { fname class {ok ""} {cancel ""}} {
  set count 0
  set win ".dialog[incr count]"
  while {[winfo exist $win]} {
    set win ".dialog[incr count]"
  }

  toplevel $win -class class
  wm title $win $fname
  global Confirm  
  tixButtonBox $win.box -orientation horizontal -relief groove -padx 5 -pady 7
  if {!($ok == "")} {
    $win.box add ok     -text $ok     -underline 0 -command "set Confirm($win) 1" -width 10
  }    
  if {!($cancel == "")} {
    $win.box add cancel -text $cancel -underline 0 -command "set Confirm($win) 0" -width 10
  }
  $win.box add hilfe  -text Hilfe   -underline 0  -width 10 \
                      -command { put_win "Hilfe nicht verfuegbar\n" }  
  pack $win.box -side bottom -fill x
  wm resizable $win 0 0
  after idle dialog_pos $win
  return $win
}
## ENDE dialog_create

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc dialog_wait { win { conf 0 }} {
  global DlgXPos DlgYPos Confirm
  grab  set $win
  set Confirm($win) $conf
  vwait Confirm($win)
  grab release $win
  scan [wm geometry $win] "%dx%d+%d+%d" w h DlgXPos DlgYPos
}
## ENDE dialog_wait

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc dialog_pos { win } {
  global DlgXPos DlgYPos
  update idletasks
  set w [winfo reqwidth $win]
  set h [winfo reqheight $win]
  set W [winfo screenwidth  .]
  set H [winfo screenheight .]
  
  set xmax [expr $DlgXPos + $w + 10]
  set ymax [expr $DlgYPos + $h + 10]
  if { $xmax > $W } { set DlgXPos [expr $W - $w - 10] }
  if { $ymax > $H } { set DlgYPos [expr $H - $h - 10] }
  if { $DlgXPos < 0 } { set DlgXPos 3 }
  if { $DlgYPos < 0 } { set DlgYPos 3 }
  wm geometry $win "+$DlgXPos+$DlgYPos"
  update
}
## ENDE dialog_pos

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc dialog_focus { win } {
  focus $win
  $win selection from 0
  $win selection to end
  $win icursor end
}
## ENDE dialog_focus

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc dialog_lbox { win {weite "20"} {hoehe "10"} } {
  set count 0
  set w "$win.lb[incr count]"
  while {[winfo exist $w]} { set w "$win.lb[incr count]" }
  
  listbox $w -relief raised -width $weite -height $hoehe -borderwidth 2 \
                 -yscrollcommand "$win.scrolly set"
  scrollbar $win.scrolly -command "$w yview"
  pack $win.scrolly -side right -fill y
  pack $w  -fill both -expand yes

  return $w
}
## ENDE dialog_lbox


# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc dialog_add_nbook { nbook npage pname } {
   $nbook add $npage -label $pname 
   set f [$nbook subwidget $npage]
  return $f
}
## ENDE dialog_add_nbook

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc dialog_nbook { win } {
  set count 0
  set w "$win.nb[incr count]"
  while {[winfo exist $w]} { set w "$win.nb[incr count]" }
  
  tixNoteBook $w -ipadx 5 -ipady 5
  pack $w -expand yes -fill both -padx 5 -pady 5 -side top
  return $w
}
## ENDE dialog_nbook

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc dialog_lframe { win lfname { side "top" }} {
  set count 0
  set w "$win.lf[incr count]"
  while {[winfo exist $w]} { set w "$win.lf[incr count]" }
  
  tixLabelFrame $w -label $lfname -labelside acrosstop \
      -options {
         label.padX 5
         label.padY 5
       }
  pack $w -side $side -expand yes -fill both -padx 5 -pady 5
  set f [$w subwidget frame]
  return $f
}
## ENDE dialog_lframe

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc dialog_scrollhlist { win kopfzeile { side "top" }} {
  set count 0
  set w "$win.shl[incr count]"
  while {[winfo exist $w]} { set w "$win.shl[incr count]" }
  
  set anzspalten 0
  set breite     0
  foreach i $kopfzeile {
    set breite [expr $breite + [lindex $i 1]]
    incr anzspalten 
  }
  tixScrolledHList $w -option  "hlist.columns $anzspalten
                                hlist.header  true 
                                hlist.height  9 
                                hlist.width   $breite"
  
  pack $w -expand yes -fill both -padx 10 -pady 10 -side $side
  set f [$w subwidget hlist]
        
  set style(header) [tixDisplayStyle text  -refwindow $f \
      -fg black -anchor c  -padx 4 -pady 2\
      -font [tix option get bold_font ]]

  set spalte 0
  foreach i $kopfzeile {
    $f header create $spalte -itemtype text -text [lindex $i 0] -style $style(header)
    $f column width $spalte -char [lindex $i 1]
    incr spalte
  }
  return $f
}
## ENDE dialog_scrollhlist

# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
proc dialog_combobox { win cmd hoehe { side "top" }} {
  set count 0
  set w "$win.cb[incr count]"
  while {[winfo exist $w]} { set w "$win.cbl[incr count]" }
  
  tixComboBox $w  -dropdown true\
      -command $cmd  -editable false \
      -options "listbox.height $hoehe
                label.anchor e"
  pack $w -side top -expand no -fill x -pady 5 -padx 5 -anchor w 
  return $w
}
## ENDE dialog_combobox

