#
# QCad
# (c) Q Solutions 1998
#
#
#
#
# Text processing 
#

proc textKey { name } {
  upvar #0 $name data

	set c $data(Canvas)
	set tag $data(edit,objTag)
	set K $data(eventkey)
	set k $data(eventascii)

	#puts "K: $K $k"
  switch $K {
    BackSpace {
       set dp [expr [$c index $tag insert] - 1]
       if {$dp >= 0} {
          $c dchars $tag $dp $dp
       }
    }
    Delete {      
       set dp [expr [$c index $tag insert] ]
       $c dchars $tag $dp $dp
    }
    Home  { $c icursor $tag 0 }
    End   { $c icursor $tag end }
    Left  { $c icursor $tag [expr [$c index $tag insert] - 1] }
    Right { $c icursor $tag [expr [$c index $tag insert] + 1]  }

    Return { $c insert $tag insert "\n" }
    xEscape { textEditEnd $name 0}              
    Up -
    Down -
    Prior -
    Next { }
    Break  { $c insert $tag insert "\n" }
    default {
  	  set k [string range $k end end]
      if {[string compare "$k" " "] > -1} {
         $c insert $tag insert "$k"
  	  }
  	}
  }
}

proc textEditEnd { name flag}  {

	upvar #0 $name data

	set c $data(Canvas)

	set id $data(edit,textobj)
	$c lower $id Grid
	$c focus {}
	$c bind $id <Key> {}
	$c bind $id <Control-Key-Return> {}
	$c bind $id <Alt-Key> {}

}





