#   Copyright (C) 1987-2005 by Jeffery P. Hansen
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Last edit by hansen on Mon Dec  8 15:33:16 2003
#


menu .pop_wire -tearoff 0
.pop_wire add command -label [m gatprop] -command act_popupWireProps
.pop_wire add command -label [m addwireseg] -command act_popupWireAddStub

menu .pop_MIgate -tearoff 0
.pop_MIgate add command -label [m gatprop] -command act_editProps
.pop_MIgate add command -label [m gataddin] -command act_addIn
.pop_MIgate add checkbutton -label [m b.anchor] -variable pop_anchor -command act_popupAnchor
.pop_MIgate add cascade -label [m gatsettech] -menu .pop_MIgate.settech
.pop_MIgate add separator
.pop_MIgate add command -label [m b.delete] -command act_delete

menu .pop_gate -tearoff 0
.pop_gate add command -label [m gatprop] -command act_editProps
.pop_gate add checkbutton -label [m b.anchor] -variable pop_anchor -command act_popupAnchor
.pop_gate add cascade -label [m gatsettech] -menu .pop_gate.settech
.pop_gate add separator
.pop_gate add command -label [m b.delete] -command act_delete

menu .pop_joint3 -tearoff 0
.pop_joint3 add checkbutton -label [m b.anchor] -variable pop_anchor -command act_popupAnchor
.pop_joint3 add command -label [m addwireseg] -command act_popupWireAddStub

menu .pop_joint4 -tearoff 0
.pop_joint4 add checkbutton -label [m b.anchor] -variable pop_anchor -command act_popupAnchor

menu .pop_multi -tearoff 0
.pop_multi add checkbutton -label [m b.anchor] -variable pop_anchor -command act_popupAnchor
.pop_multi add command -label [m b.delete] -command act_delete
.pop_multi add cascade -label [m gatsettech] -menu .pop_multi.settech

menu .pop_block -tearoff 0
.pop_block add command -label [m modopen] -command act_openMod
.pop_block add command -label [m gatprop] -command act_editProps
.pop_block add command -label [m modseti] -command act_setBlockDesc
.pop_block add checkbutton -label [m b.anchor] -variable pop_anchor -command act_popupAnchor
.pop_block add separator
.pop_block add command -label "[m gatiochg]" -command act_popupBlockChgPort
.pop_block add command -label "[m gataddin]..." -command act_popupBlockAddIn
.pop_block add command -label "[m gataddout]..." -command act_popupBlockAddOut
.pop_block add command -label "[m gataddinout]..." -command act_popupBlockAddInOut
.pop_block add separator
.pop_block add command -label [m b.delete] -command act_delete

menu .pop_canv -tearoff 0
.pop_canv add cascade -menu .pop_canv.make -label [m make]
.pop_canv add cascade -menu .pop_canv.tool -label [m tool]
.pop_canv add separator
.pop_canv add command -label [m modclose] -command act_closeMod
tkg_makeMakeMenu .pop_canv.make
.pop_canv.make configure -tearoff 0
tkg_makeToolMenu .pop_canv.tool
.pop_canv.tool configure -tearoff 0

menu .pop_simu -tearoff 0
.pop_simu add command -label [m simend] -underline [ul 0] -command act_endSimulator -accelerator "Ctl-S e"
.pop_simu add separator
.pop_simu add command -label [m simrun] -underline [ul 0] -command act_simRun -accelerator "Ctl-S g" 
.pop_simu add command -label [m simpause] -underline [ul 0] -command act_simStop  -accelerator "Ctl-S s"
.pop_simu add command -label [m simstep] -underline [ul 0] -command act_simStep -accelerator "Space"
.pop_simu add command -label [m simcycle] -underline [ul 5] -command act_simCycle -accelerator "Tab"
.pop_simu add command -label [m simbreak] -underline [ul 0] -command act_editBreakpoints -accelerator "Ctl-S k"
.pop_simu add command -label [m simscript] -underline [ul 1] -command act_doSimScript -accelerator "Ctl-S x"
.pop_simu add separator
.pop_simu add command -label [m simload] -underline [ul 1] -command act_simLoadMem -accelerator "Ctl-S l"
.pop_simu add command -label [m simdump] -underline [ul 1] -command act_simDumpMem -accelerator "Ctl-S d"
.pop_simu add separator
.pop_simu add command -label [m modclose] -command act_closeMod


menu .pop_notmove -tearoff 0
.pop_notmove add cascade -menu .pop_notmove.tool -label [m tool]
.pop_notmove add command -label [m modclose] -command act_closeMod
tkg_makeToolMenu .pop_notmove.tool
.pop_notmove.tool configure -tearoff 0

proc tkg_popupCommand {w x y s Px Py} {
  global pop_anchor pop_tech

  tkg_buttonPress .frame.cf.canvas $x $y $s
  set ptype [gat_setpop $x $y]
  set pop_anchor [gat_anchor]
  set pop_tech [gat_getTech]
  tkg_buttonRelease .frame.cf.canvas $x $y $s

  catch { tk_popup .pop_$ptype $Px $Py }
}


tkg_gatewin .frame.cf.canvas   -width $tkg_initialWidth -height $tkg_initialHeight -takefocus 0 \
 -xscrollcommand ".horz set" -yscrollcommand ".vert set" -bg white
pack .frame.cf.canvas -side top -fill both -expand 1



bind .frame.cf.canvas <Button-1> 	{ action -Press { tkg_buttonPress .frame.cf.canvas %x %y %s } }
bind .frame.cf.canvas <Double-Button-1>	{ continueAction -DblPress { tkg_buttonDoublePress .frame.cf.canvas %x %y %s } }
bind .frame.cf.canvas <ButtonRelease-1>	{ continueAction - { tkg_buttonRelease .frame.cf.canvas %x %y %s } }
bind .frame.cf.canvas <B1-Motion>	{ continueAction -Motion { tkg_buttonMotion .frame.cf.canvas %x %y %s } }
bind .frame.cf.canvas <Button-1>	{+ focus .mbar }

bind .frame.cf.canvas <Button-3>	{ action -Select { tkg_popupCommand %W %x %y %s %X %Y} }


