### Copyright (C) 1995, 1996, 1997 Jeppe Buk (buk@imada.ou.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.
###
### Sun Feb 22 1998 Japanized by Mashio Motoyama <moto@ba.mbn.or.jp>
###

proc mouse {} {
  # メニューとバインド / マウス・バインディング
  Desc "マウス・バインディングの定義"
  ShortDesc "マウスバインディング"

  Header h -text "マウス・バインディング" -frame:relief flat \
      -help "このページではマウス・バインディングの定義を行います。"
  Line l

  Label index -text "Desc:" -label:relief groove -packLabel:ipadx 5
  Menu button -text "ボタン番号" -entries { Any 1 2 3 } \
      -packFrame:anchor nw \
      -help "どのマウスボタンにバインドするか選択します。"

  ListBox mouseContext -text "コンテキスト" -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 "この機能を割り当てるコンテキストを選択します。"
  ListBox mouseModifier -text "モディファイア" -entries {
    Any Control Shift Meta 1mod 2mod 3mod 4mod 5mod} -width 8 \
      -selectmode multiple \
      -help "このマウスボタンと組み合わせて使う装飾キーを選択します。\
 button."
  Label funcLabel -text "呼び出す関数" \
      -help "バインド可能な組み込み関数の一覧です。"
  global Builtins
  ComboBox builtinCall -noedit 1 -default Beep -entryhelp $Builtins \
      -help "このメニューから呼び出す組み込み関数を選択します。"

  Label argLabel -text "引数" \
      -help "付加的な引数を記述します(その文法はあなたの自身が責任を持って下さい)。そのコマンドのヘルプを見て下さい。"
  Entry mouseArgs \
      -help "付加的な引数を記述します(その文法はあなたの自身が責任を持って下さい)。そのコマンドのヘルプを見て下さい。"
  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 "\"$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"
    }
  }
}
