### 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 menus {} {
  # Menus and Bindings / Popup Menus
  Desc "Definitions of popup menus"
  ShortDesc "Popup menus"

  Header h -text "Popup Menus" -frame:relief flat \
      -help "On this page you define your own popup menus"
  Line l

  Entry pixmapDD -text "Global default pixmap for menus" \
      -help "Here you may enter the name of a pixmap to use as the default" \
            "pixmap for menu entries (except titles and separators), if no" \
	    "other pixmap is specified on a per-menu or per-entry basis."
  Radio placeDD -entries { "Left" "Top" } \
      -help "Select 'Left' if you want the pixmap at the left of the text, " \
            "and 'Top' if you want it above it."
  Frame f_pixmapDD -entries { pixmapDD placeDD }

  Line lineDD

  Entry popupName -text "Name of the popup menu" \
      -help "Here you enter the name of the menu."

  Entry pixmapD -text "Default pixmap for this menu" \
      -help "Here you may enter the name of a pixmap to use as the default" \
            "in this menu (overloads the global setting above)."
  Radio placeD -entries { "Left" "Top" } \
      -help "Select 'Left' if you want the pixmap at the left of the text, " \
            "and 'Top' if you want it above it."

  Frame f_pixmapD -entries { pixmapD placeD }

  Radio place -entries { "L" "T" } \
      -help "Select 'L' if you want the pixmap at the left of the text, " \
            "and 'T' if you want it above it." \
      -packSubFrame:side top
  Entry pixmap -text "Pixmap" \
      -help "Here you may enter the name of a pixmap to use in the menu" \
      -packLabel:side top
  Entry name -text "Name" \
     -help "Enter the name on the menu here" \
     -packLabel:side top
  global Builtins
  ComboBox builtinCall -noedit 1 -text "Builtin" -default Beep \
      -entryhelp $Builtins \
      -help "Select a built-in command to call from this menu" \
      -packLabel:side top
  Entry arguments -text "Arguments" \
      -help "Any additional arguments are entered here (the syntax is your" \
      "responsibility) - see help for the individual commands." \
      -packLabel:side top

  ExtEntry popupEntry -entries {place pixmap name builtinCall arguments} \
      -count 5
  ExtEntry popup -lines 1 -entries { popupName f_pixmapD popupEntry } \
      -orient top -index popupName -count 1

  Label funcArgs -justify left -wraplength 600
  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] arguments"
    }
  }
  ShowPage {
    set funcArgs ""
  }

  Change {
    if {$changeElm == "pixmap"} {
      if {$pixmap == ""} {Disable place} else {Enable place}
    }
    if {$changeElm == "pixmapD"} {
      if {$pixmapD == ""} {Disable placeD} else {Enable placeD}
    }
    if {$changeElm == "pixmapDD"} {
      if {$pixmapDD == ""} {Disable placeDD} else {Enable placeDD}
    }
  }

  Save {
    forevery popup {
      if {$popupName != {}} {
	print "AddToMenu \"$popupName\""
	forevery popupEntry {
	  if { $pixmap != "" && $place(name) == "L" } {
	    set Gname "%$pixmap%$name"
	  } elseif { $pixmap != "" && $place(name) == "T" } {
	    set Gname "*$pixmap*$name"
	  } elseif { $builtinCall != "Title" && $builtinCall != "Nop" } {
	    # Titles and Nops shouldn't use default pixmaps
	    if { $pixmapD != "" && $placeD(name) == "Left" } {
	      set Gname "%$pixmapD%$name"
	    } elseif { $pixmapD != "" && $placeD(name) == "Top" } {
	      set Gname "*$pixmapD*$name"
	    } elseif { $pixmapDD != "" && $placeDD(name) == "Left" } {
	      set Gname "%$pixmapDD%$name"
	    } elseif { $pixmapDD != "" && $placeDD(name) == "Top" } {
	      set Gname "*$pixmapDD*$name"
	    } else {
	      set Gname $name
	    }
	  } else {
	    set Gname $name
	  }
	  print "+\t\"$Gname\"\t$builtinCall $arguments"
	}
      }
    }
  }
}
