#
# QCad
# (c) Q Solutions 1998
#
#
#
#
# Log functions
#
#

proc Log {args} {

	set win ".log"
	if { ! [winfo exists $win] } { 
		toplevel $win
		wm withdraw $win
		pack [button $win.btn -text "Hide" -command LogHide] -anc nw -fill x -side bottom
		pack [scrollbar $win.scv -orient v -command "$win.text yview"] -fill y -anc nw -side left
		pack [text $win.text -wrap none -yscrollcommand "$win.scv set" \
				-xscrollcommand "$win.sch set"] -anc nw -fill both -expand 1
		pack [scrollbar $win.sch -orient h -command "$win.text xview"]  -fill x -anc nw -side bottom
		focus $win.btn
		bind $win.btn <Key> LogHide
		bind $win.text <1> LogHide
#		bind $win.text <3> LogHide
#		bind $win.text <2> LogHide
	}
	$win.text config -state normal
	eval $win.text insert end $args 
	$win.text insert end "\n"
	if { [$win.text index end] > 1000 } {
		$win.text delete 1.0 [expr int([$win.text index end] - 500)].0
		$win.text insert end "Log truncated\n\n"
	}
	$win.text see end
	$win.text config -state disabled
}

proc LogHide {args} {

	set win ".log"
	if { ! [winfo exists $win] } { return }
	wm withdraw $win
}

proc LogShow {args} {

	set win ".log"
	if { ! [winfo exists $win] } { return }
	wm deiconify $win
	raise $win
}

proc LogClear {args} {


	set win ".log"
	if { ! [winfo exists $win] } { return }
	$win.text config -state normal
	$win.text delete 1.0 end
	$win.text config -state disabled
}






