#! /usr/bin/wish

# interface generated by SpecTcl version 1.2 from /home/msj/projects/SpecTcl/SpecTcl/menueditor.ui
#   root     is the parent window for this user interface

proc menueditor_ui {root args} {

	# this treats "." as a special case

	if {$root == "."} {
	    set base ""
	} else {
	    set base $root
	}
    
	frame $base.fr

	frame $base.fSeparator \
		-borderwidth 1 \
		-relief sunken \
		-width 2

	label $base.label#11 \
		-text Menus
	catch {
		$base.label#11 configure \
			-font -*-Helvetica-Bold-R-Normal-*-*-240-*-*-*-*-*-*
	}

	label $base.label#12 \
		-text {Menu Items}
	catch {
		$base.label#12 configure \
			-font -*-Helvetica-Bold-R-Normal-*-*-240-*-*-*-*-*-*
	}

	listbox $base.lbEntries \
		-exportselection 0 \
		-height 0 \
		-width 0

	button $base.view \
		-text Post/View

	label $base.lType \
		-text Type

	menubutton $base.mbType \
		-indicatoron 1 \
		-menu "$base.mbType.m" \
		-relief raised \
		-takefocus {} \
		-text cascade \
		-textvariable mbType.value

	button $base.add \
		-text Add

	button $base.new \
		-text New

	button $base.insert \
		-text Insert

	button $base.remove \
		-text Remove

	button $base.delete \
		-text Delete

	button $base.copy \
		-padx 0 \
		-text Copy
	catch {
		$base.copy configure \
			-font -*-Helvetica-Bold-R-Normal-*-*-120-*-*-*-*-*-*
	}

	button $base.replace \
		-default active \
		-text Replace

	checkbutton $base.cbTearoff \
		-text Tearoff \
		-variable cbTearoff.value

	button $base.dismiss \
		-command "destroy $root" \
		-text Dismiss


	# Add contents to menus

	# Geometry management

	grid $base.fr -in $root	-row 3 -column 4  \
		-columnspan 2 \
		-rowspan 4 \
		-sticky n
	grid $base.fSeparator -in $root	-row 1 -column 3  \
		-pady 5 \
		-rowspan 6 \
		-sticky ns
	grid $base.label#11 -in $root	-row 1 -column 1  \
		-columnspan 2 \
		-ipady 5
	grid $base.label#12 -in $root	-row 1 -column 4  \
		-columnspan 3 \
		-ipady 5
	grid $base.lbEntries -in $root	-row 2 -column 1  \
		-padx 5 \
		-pady 5 \
		-rowspan 5 \
		-sticky nesw
	grid $base.view -in $root	-row 2 -column 2  \
		-padx 5 \
		-sticky ew
	grid $base.lType -in $root	-row 2 -column 4 
	grid $base.mbType -in $root	-row 2 -column 5 
	grid $base.add -in $root	-row 2 -column 7  \
		-padx 5 \
		-sticky ew
	grid $base.new -in $root	-row 3 -column 2  \
		-padx 5 \
		-sticky ew
	grid $base.insert -in $root	-row 3 -column 7  \
		-padx 5 \
		-sticky ew
	grid $base.remove -in $root	-row 4 -column 2  \
		-padx 5 \
		-sticky ew
	grid $base.delete -in $root	-row 4 -column 7  \
		-padx 5 \
		-sticky ew
	grid $base.copy -in $root	-row 5 -column 2  \
		-padx 5 \
		-sticky ew
	grid $base.replace -in $root	-row 5 -column 7  \
		-padx 5 \
		-sticky ew
	grid $base.cbTearoff -in $root	-row 6 -column 2 
	grid $base.dismiss -in $root	-row 6 -column 7  \
		-padx 5 \
		-sticky esw

	# Resize behavior management

	grid rowconfigure $root 1 -weight 0 -minsize 30
	grid rowconfigure $root 2 -weight 0 -minsize 30
	grid rowconfigure $root 3 -weight 0 -minsize 30
	grid rowconfigure $root 4 -weight 0 -minsize 30
	grid rowconfigure $root 5 -weight 0 -minsize 30
	grid rowconfigure $root 6 -weight 1 -minsize 30
	grid columnconfigure $root 1 -weight 1 -minsize 30
	grid columnconfigure $root 2 -weight 0 -minsize 30
	grid columnconfigure $root 3 -weight 0 -minsize 30
	grid columnconfigure $root 4 -weight 0 -minsize 30
	grid columnconfigure $root 5 -weight 0 -minsize 30
	grid columnconfigure $root 6 -weight 0 -minsize 30
	grid columnconfigure $root 7 -weight 0 -minsize 30
# additional interface code
# Initialise
::menueditor::init $root

# Menu for $base.mbType
::menueditor::CreateTheOptionmenu $base.mbType.m

# Callbacks for buttons
$base.view config -command {::menueditor::view}
$base.new config -command {::menueditor::new}
$base.remove config -command {::menueditor::remove}
$base.copy config -command {::menueditor::copy}
$base.add config -command {::menueditor::add}
$base.insert config -command {::menueditor::insert}
$base.delete config -command {::menueditor::delete}
$base.replace config -command {::menueditor::replace}
$base.cbTearoff config -command {::menueditor::tearoff}

# Bindings
bind $root <Key-Up> {::menueditor::keyup} ;# Should have been "$base.up invoke"
bind $root <Key-Down> {::menueditor::keydown}
bind $root <Key-Left> {::menueditor::keyleft}
bind $root <Key-Right> {::menueditor::keyright}

# Fast button invoking
bind $root <Key-Return> "$base.replace invoke"
bind $root <Key-Insert> "$base.insert invoke"
bind $root <Key-Delete> "
   if {\"\[focus\]\"!=\"$base.lbEntries\" &&
       \"\[winfo type \[focus\]\]\"!=\"entry\"} {
      $base.delete invoke
   }
"
bind $root <Key-Escape> "$base.dismiss invoke"


# end additional interface code

}


# Allow interface to be run "stand-alone" for testing

catch {
    if [info exists embed_args] {
	# we are running in the plugin
	menueditor_ui .
    } else {
	# we are running in stand-alone mode
	if {$argv0 == [info script]} {
	    wm title . "Testing menueditor_ui"
	    menueditor_ui .
	}
    }
}
