### Copyright (C) 1995, 1996, 1997 Jeppe Buk (buk@imada.sdu.dk)
### 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.

proc mouse {} {
  # Menus and Bindings / Mouse Bindings
  Desc "Definitions of mouse bindings"
  ShortDesc "Mouse bindings"

  Header h -text "Mouse Bindings" -frame:relief flat \
      -help "On this page you configure mouse bindings."
  Line l

  Label index -text "Desc:" -label:relief groove -packLabel:ipadx 5
  Menu button -text "Button no" -entries { Any 1 2 3 } \
      -packFrame:anchor nw \
      -help "Select which mouse button to bind to."

  ListBox mouseContext -text "Context" -entries {
    Any Root Window "Title bar" Sides Frame Icon "0 button" "1 button"\
	"2 button" "3 button" "4 button" "5 button" "6 button" "7 button" \
	"8 button" "9 button"} -width 8 \
      -selectmode multiple \
      -help "Select the context(s) in which to bind the mouse button."
  ListBox mouseModifier -text "Modifier" -entries {
    Any Control Shift Meta 1mod 2mod 3mod 4mod 5mod} -width 8 \
      -selectmode multiple \
      -help "Select the modifier(s) to press in conjunction with the mouse\
 button."
  Label funcLabel -text "Function to call" \
      -help "This is a list of the built-in functions you can bind the key to"
  global Builtins
  ComboBox builtinCall -noedit 1 -default Beep -entryhelp $Builtins \
      -help "Select a built-in function to call from this menu"

  Label argLabel -text "Arguments" \
      -help "Any additional arguments are entered here (the syntax is your" \
      "responsibility) - see help for the individual commands."
  Entry mouseArgs \
      -help "Any additional arguments are entered here (the syntax is your" \
      "responsibility) - see help for the individual commands."
  Frame called -entries {funcLabel builtinCall argLabel mouseArgs} -orient top

  Frame mouseFrame -entries {mouseContext mouseModifier called}
  ExtEntry mouse -lines 1 -count 1 -entries {index button mouseFrame} \
      -orient top -index index

  Label funcArgs -justify left -wraplength 400

  Change {
    if {$changeElm == "builtinCall"} {
      set bcindex -1
      set found "no"
      foreach bc $Builtins {
	incr bcindex
	if {$bc == $builtinCall} {
	  set found "yes"
	  break
	}
      }
      if {$found == "yes"} {
	set help [lindex $Builtins [expr $bcindex + 1]]
      } else {
	set help "\[Help not found\]"
      }
      set funcArgs "Help for function \"$builtinCall\":\n$help"
      eval "[pick [funcWithArgs $builtinCall] Enable Disable] argLabel mouseArgs"
    }
  }
  ShowPage {
    set funcArgs ""
  }
  
  Change {
    if {$changeElm == "mouseModifier" || $changeElm == "button" ||
	$changeElm == "mouseContext"} {
      set index "Button: [makeContextOrModifier $mouseModifier(name)] $button(name), Context: [makeContextOrModifier $mouseContext(name)]"
    }
  }

  PageEnd {
    forevery mouse {
      if { [llength $mouseContext(name)] == 0 } {
	error "You must specify context(s) in mouse binding."
      }
    }
  }

  Save {
    forevery mouse {
      set context [makeContextOrModifier $mouseContext(name)]
      set modifier [makeContextOrModifier $mouseModifier(name)]
      print "Mouse $button(index) $context $modifier $builtinCall $mouseArgs"
    }
  }
}
