### 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 FvwmBacker {} {
  # Modules / FvwmBacker
  Desc "Configuration of the FvwmBacker module"
  ShortDesc "FvwmBacker"

  Header h -text "FvwmBacker" -frame:relief flat \
      -help "On this page you configure the FvwmBacker module. This"\
      "module is used for having different backgrounds on each virtual desk."
  Line l
  CheckBox spawn -text "Spawn this module when Fvwm2 starts" \
      -help "If you check this option the module will be spawned from"\
      "the two functions 'InitFunction' and 'RestartFunction'. You will"\
      "not have to insert them yourself then."

  Int desk -text "Set background for desk no." -help "Here you specify"\
      "which desktop you wish to configure the background of."
  CheckBox colorB -text "Specify a color"
  Command color \
      -default [list "#000000" 0] \
      -setvalue {
	$widget configure -bg [lindex $color 0] -text "      "} \
      -invoke {ColorWidget $colorList [lindex $color 0] \
		   [lindex $color 1]} \
      -disable {$widget configure -relief flat } \
      -enable {$widget configure -relief raised } \
      -inactive {$widget configure -relief flat -bg black }
  Frame colorF -entries { colorB color }
  CheckBox commandB -text "Specify a command"
  Entry command
  Frame commandF -entries { commandB command }
  ExtEntry backs -entries { desk colorF commandF } -orient top \
      -text "Backgrounds for virtual desks" \
      -index desk

  Change {
    if {$changeElm == "colorB"} {
      if {$colorB == 1} {
	Enable color
	set commandB 0
	Disable command
      } else {
	Disable color
      }
    }
    if {$changeElm == "commandB"} {
      if {$commandB == 1} {
	Enable command
	set colorB 0
	Disable color
      } else {
	Disable command
      }
    }
  }

  PageEnd {
    forevery backs {
      if {$commandB == 1 && $command == ""} {
	error "You must specify a command to set the background"
      } elseif {$desk == "" || $desk < 0} {
	error "Invalid desk no."
      }
    }
  }

  Save {
    forevery backs {
      if {$colorB == 1} {set cmd "-solid [hash2rgb [lindex $color 0]]"
      } else {set cmd $command}
      print "*FvwmBackerDesk $desk $cmd"
    }
    if {$spawn == 1} {
      print "AddToFunc InitFunction \"I\" Module FvwmBacker"
      print "AddToFunc RestartFunction \"I\" Module FvwmBacker"
    }
  }
}
