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

  Header h -text "FvwmPager" -frame:relief flat \
      -help "On this page you configure the FvwmPager module. This"\
      "module is used for navigating around the virtual desktops and"\
      "pages."
  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 pager1 -text "First desk to show" \
      -help "Here you enter the number of the first desk to show in the"\
      "pager. Desks are numbered from 0 and up."
  Int pager2 -text "Last desk to show" \
      -help "Here you enter the number of the last desk to show in the"\
      "pager. Desks are numbered from 0 and up."
  Frame pagerF -entries pager1 pager2
  Change {
    if {$changeElm == "spawn"} {
      if {$spawn == 1} {Enable pager1 pager2} else {Disable pager1 pager2}
    }
  }
  Line delim

  Int nor -text "Rows of desks:" \
      -help "Specify the number of rows to use when laying out the"\
      "desks."
  Change {if {$changeElm == "nor" && $nor == "-"} {set nor ""}}
  Save {if {$nor != ""} {print "*FvwmPagerRows\t$nor"}}

  Int noc -text "Columns of desks:" \
      -help "Specify the number of columns to use when laying out the"\
      "desks."
  Frame norcF -entries nor noc
  Change {if {$changeElm == "noc" && $noc == "-"} {set noc ""}}
  Save {if {$noc != ""} {print "*FvwmPagerColumns\t$noc"}}

  CheckBox redB -text "Reduction scale of the pager:" \
      -help "You can specify a reduction scale to use for the pager. If"\
      "you do this the size of desks and windows will become"\
      "1/reduction."
  Int red -help "Enter the reduction scale."
  Frame redF -entries redB red
  Change {if {$changeElm == "red" && $red == "-"} {set red ""}}
  Change {
    if {$changeElm == "redB"} {
      if {$redB == 1} {
	set pgeoB 0
	Disable pgeoW pgeoH pgeoX pgeoY
	Enable red
      } else {
	Disable red
      }
    }
  }
  PageEnd {if {$redB == 1 && $red == ""} {
    error "Invalid reduction scale for FvwmPager."
  }}
  Save {if {$redB == 1} {print "*FvwmPagerDeskTopScale\t$red"}}

  CheckBox pgeoB -text "Geometry of pager:" \
      -help "You can specify the geometry of the pager in standard X11"\
      "notation, if you don't want to use the reduction scale."
  Int pgeoW -text "Width" -help "Enter the width in pixels."
  Int pgeoH -text "Height" -help "Enter the height in pixels."
  Int pgeoX -text "X-coord" -help "Enter the X-coordinate."
  Int pgeoY -text "Y-coord" -help "Enter the Y-coordinate."
  Frame pgeoF -entries pgeoB pgeoW pgeoH pgeoX pgeoY
  Change {if {$changeElm == "pgeoW" && $pgeoW == "-"} {set pgeoW ""}}
  Change {if {$changeElm == "pgeoH" && $pgeoH == "-"} {set pgeoH ""}}
  Change {
    if {$changeElm == "pgeoB"} {
      if {$pgeoB == 1} {
	set redB 0
	Disable red
	Enable pgeoW pgeoH pgeoX pgeoY
      } else {
	Disable pgeoW pgeoH pgeoX pgeoY
      }
    }
  }
  PageEnd {
    if {$pgeoB == 1 && ($pgeoX != $pgeoY &&
			($pgeoX == ""  || $pgeoY == "" ||
			 $pgeoX == "-" || $pgeoY == "-")
			)} {
      error "You can only specify either both X-coord and Y-coord, or\
 none of them in geometry to FvwmPager."
    }
  }
  Save {
    if {$pgeoB == 1} {
      set geom ""
      if {$pgeoW != "" || $pgeoH != ""} {
	append geom "${pgeoW}x$pgeoH"
      }
      if {$pgeoX != ""} {
	append geom "[signed $pgeoX][signed $pgeoY]"
      }
      print "*FvwmPagerGeometry\t$geom"
    }
  }

  Label igeoL -text "Geometry of icon:"
  Int igeoW -text "Width"
  Int igeoH -text "Height"
  Int igeoX -text "X-coord"
  Int igeoY -text "Y-coord"
  Frame igeoF -entries igeoL igeoW igeoH igeoX igeoY
  Change {if {$changeElm == "igeoW" && $igeoW == "-"} {set igeoW ""}}
  Change {if {$changeElm == "igeoH" && $igeoH == "-"} {set igeoH ""}}
  PageEnd {
    if {$igeoX != $igeoY && ($igeoX == ""  || $igeoY == "" ||
			     $igeoX == "-" || $igeoY == "-")} {
      error "You can only specify either both X-coord and Y-coord, or\
 none of them in geometry to FvwmPager icon."
    }
  }
  Save {
    if {$igeoW != "" || $igeoH != "" || $igeoX != "" || $igeoY != ""} {
      set geom ""
      if {$igeoW != "" || $igeoH != ""} {
	append geom "${igeoW}x$igeoH"
      }
      if {$igeoX != ""} {
	append geom "[signed $igeoX][signed $igeoY]"
      }
      print "*FvwmPagerIconGeometry\t$geom"
    }
  }

  CheckBox stiB -text "Start pager iconic" \
      -help "If you check this option FvwmPager will start as an"\
      "icon. It is probably better to use the standard Fvwm2 style"\
      "settings in 'Styles of Windows'."
  Save {if {$stiB == 1} {print "*FvwmPagerStartIconic"}}

  Line fcLn
  CheckBox fcB -text "Specify foreground color" \
      -help "Check this option if you want to change the foreground"\
      "color of the pager window."
  Command fc \
      -default [list "black" 0] \
      -setvalue {
	$widget configure -bg [lindex $fc 0] -text "      "} \
      -invoke {ColorWidget $colorList [lindex $fc 0] \
		   [lindex $fc 1]} \
      -disable {$widget configure -relief flat } \
      -enable {$widget configure -relief raised } \
      -help "In this widget you configure the foreground color of the"\
      "pager. This color is used for the lines and desk labels."
  Frame fcF -entries fcB fc
  Change {
    if {$changeElm == "fcB"} {if {$fcB == 1} {Enable fc} else {Disable fc}}
  }
  Save {if {$fcB == 1} {print "*FvwmPagerFore\t[hash2rgb [lindex $fc 0]]"}}

  CheckBox bcB -text "Specify background color" \
      -help "Check this option if you want to change the background"\
      "color of the pager window."
  Command bc \
      -default [list "white" 0] \
      -setvalue {
	$widget configure -bg [lindex $bc 0] -text "      "} \
      -invoke {ColorWidget $colorList [lindex $bc 0] \
		   [lindex $bc 1]} \
      -disable {$widget configure -relief flat } \
      -enable {$widget configure -relief raised } \
      -help "In this widget you configure the background color of the"\
      "pager. This color is used for inactive pages and desk labels."
  Frame bcF -entries bcB bc
  Change {
    if {$changeElm == "bcB"} {if {$bcB == 1} {Enable bc} else {Disable bc}}
  }
  Save {if {$bcB == 1} {print "*FvwmPagerBack\t[hash2rgb [lindex $bc 0]]"}}

  CheckBox hcB -text "Specify hilight color" \
      -help "Check this option if you want to change the hilight"\
      "color of the pager window. This color is used for the active page"\
      "and desk label."
  Command hc \
      -default [list "grey" 0] \
      -setvalue {
	$widget configure -bg [lindex $hc 0] -text "      "} \
      -invoke {ColorWidget $colorList [lindex $hc 0] \
		   [lindex $hc 1]} \
      -disable {$widget configure -relief flat } \
      -enable {$widget configure -relief raised } \
      -help "In this widget you configure the hilight color of the pager."
  Frame hcF -entries hcB hc
  Change {
    if {$changeElm == "hcB"} {if {$hcB == 1} {Enable hc} else {Disable hc}}
  }
  Save {if {$hcB == 1} {print "*FvwmPagerHilight\t[hash2rgb [lindex $hc 0]]"}}

  CheckBox fnB -text "Specify font for desk labels" \
      -help "Here you can select a font to use for desk labels."
  CheckBox fnNB -text "Prevent desk labels" \
      -help "If you check this option no desk labels will be drawn at"\
      "all."
  Frame fnF1 -entries fnB fnNB
  Label fnL -text "    "
  Command fn \
      -default "fixed" \
      -setvalue {buttonSetText $widget $fn} \
      -invoke {FontWidget $fn 0} \
      -disable {$widget configure -text "Not set"
	$widget configure -font fixed} \
      -enable {buttonSetText $widget $fn} \
      -help "In this widget you configure the font to use for desk labels."
  Frame fnF -entries fnL fn
  Change {
    if {$changeElm == "fnB"} {
      if {$fnB == 1} {
	set fnNB 0
	Enable fn
      } else {
	Disable fn
      }
    }
    if {$changeElm == "fnNB"} {
      if {$fnNB == 1} {
	set fnB 0
	Disable fn
      }
    }
  }
  Save {if {$fnB ==  1} {print "*FvwmPagerFont\t$fn"}}
  Save {if {$fnNB == 1} {print "*FvwmPagerFont\tnone"}}

  CheckBox fnSB -text "Use window labels (you must specify a font too)" \
      -help "Here you can select a font to use for window labels."
  Label fnSL -text "    "
  Command fnS \
      -default "fixed" \
      -setvalue {buttonSetText $widget $fnS} \
      -invoke {FontWidget $fnS 0} \
      -disable {$widget configure -text "Not set"
	$widget configure -font fixed} \
      -enable {buttonSetText $widget $fnS} \
      -help "In this widget you configure the font to use for window labels."
  Frame fnSF -entries fnSL fnS
  Change {
    if {$changeElm == "fnSB"} {if {$fnSB == 1} {Enable fnS} else {Disable fnS}}
  }
  Save {if {$fnSB == 1} {print "*FvwmPagerSmallFont\t$fnS"}}

  ComboBox deskNo -entries 0 1 2 3 4 5 6 7 8 9 10 -help "Select desk to"\
      "configure." -default 0
  CheckBox plabB -text "Set label:" \
      -help "Check this option and type in the label you want."
  Entry plab -help "Enter a name to use as label for this desk."
  CheckBox pcolB -text "Set color:" \
      -help "Check this option and choose the color you want."
  Command pcol \
      -default [list "white" 0] \
      -setvalue {
	$widget configure -bg [lindex $pcol 0] -text "      "} \
      -invoke {ColorWidget $colorList [lindex $pcol 0] \
		   [lindex $pcol 1]} \
      -disable {$widget configure -relief flat } \
      -enable {$widget configure -relief raised } \
      -help "Select the color to use for this desk."
  ExtEntry plabcolE -entries deskNo plabB plab pcolB pcol \
      -text "Configure individual desks" \
      -help "Here you can configure the color and/or label of"\
      "individual desks."
  Change {
    if {$changeElm == "plabB"} {
      if {$plabB == 1} {Enable plab} else {Disable plab}
    }
    if {$changeElm == "pcolB"} {
      if {$pcolB == 1} {Enable pcol} else {Disable pcol}
    }
  }
  Save {
    forevery plabcolE {
      if {$deskNo == ""} {
	tk_dialog .deskWarn Warning "You had a desk configuration without\
 a desk number. This entry will be ignored." info 0 OK
      } else {
	if {$plabB == 1} {print "*FvwmPagerLabel\t$deskNo $plab"}
        if {$pcolB == 1} {print "*FvwmPagerDeskColor\t$deskNo\
 [hash2rgb [lindex $pcol 0]]"}
      }
    }
  }

  PageEnd {
    if {$spawn == 1 && ($pager1 == "" || $pager2 == "")} {
      error "You must specify which desks to show for FvwmPager."
    }
  }

  Save {
    if {$spawn == 1} {
      print "AddToFunc InitFunction \"I\" Module FvwmPager $pager1 $pager2"
      print "AddToFunc RestartFunction \"I\" Module FvwmPager $pager1 $pager2"
    }
  }
}
