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

  Header h -text "FvwmIconBox" -frame:relief flat \
      -help "On this page you configure the FvwmIconBox module. This"\
      "module is used for iconifying windows to instead of the root."\
      "All windows having the 'NoIcon' attribute set will be minimized"\
      "to FvwmIconBox."
  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."
  CheckBox style -text "Grab all iconified windows" \
      -help "FvwmIconBox will only capture windows having the 'NoIcon'"\
      "style flag set. If you check this button I will set this for"\
      "you. The icons used in the window will be the ones specified on"\
      "the 'Styles of Windows' page."

  Line colL
  
  CheckBox winColB -text "Specify window" -help "Check this"\
      "button if you want to specify default colors of the window."
  Command winFore \
      -text "foreground" \
      -default [list "white" 0] \
      -setvalue {
	$widget configure -bg [lindex $winFore 0] -text "      "} \
      -invoke {ColorWidget $colorList [lindex $winFore 0] \
		   [lindex $winFore 1]} \
      -disable {$widget configure -relief flat } \
      -enable {$widget configure -relief raised } \
      -help "In this widget you can set the foreground color of the"\
      "FvwmIconBox window. This affect only the color of monochrome bitmaps"\
      "used as backgrounds."
  Command winBack \
      -text "background" \
      -default [list "black" 0] \
      -setvalue {
	$widget configure -bg [lindex $winBack 0] -text "      "} \
      -invoke {ColorWidget $colorList [lindex $winBack 0] \
		   [lindex $winBack 1]} \
      -disable {$widget configure -relief flat } \
      -enable {$widget configure -relief raised } \
      -help "In this widget you can set the default background color of the"\
      "FvwmIconBox window."
  Frame winColF -entries { winColB winFore winBack }
  Change {
    if {$changeElm == "winColB"} {
      if {$winColB == 1} {Enable winFore winBack
      } else {Disable winFore winBack}
    }
  }
  Save {
    if {$winColB == 1} {
      print "*FvwmIconBoxFore\t[hash2rgb [lindex $winFore 0]]"
      print "*FvwmIconBoxBack\t[hash2rgb [lindex $winBack 0]]"
    }
  }

  CheckBox icoColB -text "Specify icon" -help "Check this"\
      "button if you want to specify the colors of the icons."
  Command icoFore \
      -text "foreground" \
      -default [list "white" 0] \
      -setvalue {
	$widget configure -bg [lindex $icoFore 0] -text "      "} \
      -invoke {ColorWidget $colorList [lindex $icoFore 0] \
		   [lindex $icoFore 1]} \
      -disable {$widget configure -relief flat } \
      -enable {$widget configure -relief raised } \
      -help "In this widget you can set the foreground color of the icons."
  Command icoBack \
      -text "background" \
      -default [list "black" 0] \
      -setvalue {
	$widget configure -bg [lindex $icoBack 0] -text "      "} \
      -invoke {ColorWidget $colorList [lindex $icoBack 0] \
		   [lindex $icoBack 1]} \
      -disable {$widget configure -relief flat } \
      -enable {$widget configure -relief raised } \
      -help "In this widget you can set the background color of the icons."
  Frame icoColF -entries { icoColB icoFore icoBack }
  Change {
    if {$changeElm == "icoColB"} {
      if {$icoColB == 1} {Enable icoFore icoBack
      } else {Disable icoFore icoBack}
    }
  }
  Save {
    if {$icoColB == 1} {
      print "*FvwmIconBoxIconFore\t[hash2rgb [lindex $icoFore 0]]"
      print "*FvwmIconBoxIconBack\t[hash2rgb [lindex $icoBack 0]]"
    }
  }

  CheckBox hiColB -text "Specify hilight" -help "Check this"\
      "button if you want to specify the hilight colors of the icons."\
      "The hilight color is used for the icon under the cursor."
  Command hiFore \
      -text "foreground" \
      -default [list "white" 0] \
      -setvalue {
	$widget configure -bg [lindex $hiFore 0] -text "      "} \
      -invoke {ColorWidget $colorList [lindex $hiFore 0] \
		   [lindex $hiFore 1]} \
      -disable {$widget configure -relief flat } \
      -enable {$widget configure -relief raised } \
      -help "In this widget you can set the foreground hilight color."
  Command hiBack \
      -text "background" \
      -default [list "black" 0] \
      -setvalue {
	$widget configure -bg [lindex $hiBack 0] -text "      "} \
      -invoke {ColorWidget $colorList [lindex $hiBack 0] \
		   [lindex $hiBack 1]} \
      -disable {$widget configure -relief flat } \
      -enable {$widget configure -relief raised } \
      -help "In this widget you can set the background hilight color."
  Frame hiColF -entries { hiColB hiFore hiBack }
  Change {
    if {$changeElm == "hiColB"} {
      if {$hiColB == 1} {Enable hiFore hiBack
      } else {Disable hiFore hiBack}
    }
  }
  Save {
    if {$icoColB == 1} {
      print "*FvwmIconBoxIconHiFore\t[hash2rgb [lindex $hiFore 0]]"
      print "*FvwmIconBoxIconHiBack\t[hash2rgb [lindex $hiBack 0]]"
    }
  }

  CheckBox fontB -text "Specify font" -help "Check this button if you"\
      "want to set the font used for icon titles."
  Command font \
      -default "fixed" \
      -setvalue {buttonSetText $widget $font} \
      -invoke {FontWidget $font 0} \
      -disable {$widget configure -text "Not set"
	$widget configure -font fixed} \
      -enable {buttonSetText $widget $font} \
      -help "In this widget you can set the font to use for icon titles."
  Frame fontF -entries { fontB font }
  Change {
    if {$changeElm == "fontB"} {
      if {$fontB == 1} {Enable font} else {Disable font}
    }
  }
  Save {
    if {$fontB == 1} {print "*FvwmIconBoxFont\t$font"}
  }

  Window colFont -text "Configuration of Colors and Fonts" -entries {
    winColF icoColF hiColF fontF
  } -help "In this window you configure the colors and font to use."

  # Icon presentation
  CheckBox sortB -text "Sort icons alphabetically by" \
      -help "Check this option if you want the icons sorted. You can"\
      "then specify by which string the icons should be sorted on the"\
      "radio buttons below."
  Radio sortOrder -entryhelp {
    "Window name"    "Sort by the window title."
    "Icon name"      "Sort by the icon title."
    "Resource class" "Sort by resource class."
    "Resource name"  "Sort by resource name."
  }
  Change {
    if {$changeElm == "sortB"} {
      if {$sortB == 1} {Enable sortOrder} else {Disable sortOrder}
    }
  }
  Save {
    if {$sortB == 1} {
      set result "*FvwmIconBoxSortIcons\t"
      switch $sortOrder(name) \
	  "Window name"    {append result WindowName} \
	  "Icon name"      {append result IconName} \
	  "Resource class" {append result ResClass} \
	  "Resource name"  {append result ResName}
      print $result
    }
  }

  Int padding -text "Specify padding between icons:" \
      -textafter "pixels" \
      -help "Here you can specify the padding between icons in"\
      "pixels. Padding is the space between the icons."
  Change {if {$changeElm == "padding" && $padding == "-"} {set padding ""}}
  Save {if {$padding != ""} {print "*FvwmIconBoxPadding\t$padding"}}

  Line placeLn
  CheckBox placeB -text "Specify placement of icons" -help "Check this"\
      "option if you want to specify how the icons are placed in the"\
      "FvwmIconBox."
  Label primLb -text "Primary placement"
  CheckBox primL -text "Left-to-Right"
  CheckBox primR -text "Right-to-Left"
  CheckBox primT -text "Top-to-Bottom"
  CheckBox primB -text "Bottom-to-Top"
  Frame primF -orient top -entries { primLb primL primR primT primB }
  Label secoLb -text "Secondary placement"
  CheckBox secoL -text "Left-to-Right"
  CheckBox secoR -text "Right-to-Left"
  CheckBox secoT -text "Top-to-Bottom"
  CheckBox secoB -text "Bottom-to-Top"
  Frame secoF -orient top -entries { secoLb secoL secoR secoT secoB }
  Frame placeF -entries { primF secoF }
  Change {
    if {$changeElm == "placeB"} {
      if {$placeB == 1} {Enable primF secoF} else {Disable primF secoF}
    }
    if {[lsearch {primL primR primT primB} $changeElm] != -1} {
      foreach var {primL primR primT primB} {
	if {$var != $changeElm} {set $var 0} else {set $var 1}
      }
      if {[lsearch {primL primR} $changeElm] != -1 &&
	  ($secoL == 1 || $secoR == 1)} {
	set secoT 1
	set secoL 0
	set secoR 0
      }
      if {[lsearch {primT primB} $changeElm] != -1 &&
	  ($secoT == 1 || $secoB == 1)} {
	set secoL 1
	set secoT 0
	set secoB 0
      }
    }
    if {[lsearch {secoL secoR secoT secoB} $changeElm] != -1} {
      foreach var {secoL secoR secoT secoB} {
	if {$var != $changeElm} {set $var 0} else {set $var 1}
      }
      if {[lsearch {secoL secoR} $changeElm] != -1 &&
	  ($primL == 1 || $primR == 1)} {
	set primT 1
	set primL 0
	set primR 0
      }
      if {[lsearch {secoT secoB} $changeElm] != -1 &&
	  ($primT == 1 || $primB == 1)} {
	set primL 1
	set primT 0
	set primB 0
      }
    }
  }
  Save {
    if {$placeB == 1} {
      set result "*FvwmIconBoxPlacement\t"
      if {$primL == 1} {append result Left
      } elseif {$primR == 1} {append result Right
      } elseif {$primT == 1} {append result Top
      } elseif {$primB == 1} {append result Bottom}
      if {$secoL == 1} {append result " Left"
      } elseif {$secoR == 1} {append result " Right"
      } elseif {$secoT == 1} {append result " Top"
      } elseif {$secoB == 1} {append result " Bottom"}
      print $result
    }
  }

  Line moreL
  Int lines -text "Specify number of icons in the primary direction:" \
      -help "Here you can specify the number of icons placed in the"\
      "primary direction. If you haven't specified the placement of"\
      "icons the default is left-to-right, and this will be the number"\
      "of columns."
  Change {if {$changeElm == "lines" && $lines == "-"} {set lines ""}}
  Save {if {$lines != ""} {print "*FvwmIconBoxLines\t$lines"}}

  CheckBox maxISB -text "Specify maximum icon size to:" \
      -help "Check this option if you want to specify the maximum icon"\
      "size. The default is 48x48. If you specify zero as max height,"\
      "no icons will be shown at all."
  Int maxISW -text "Width" -help "Enter max width of icons."
  Int maxISH -text "Height" -help "Enter max height of icons."
  Frame maxISF -entries { maxISB maxISW maxISH }
  Change {
    if {$changeElm == "maxISW" && $maxISW == "-"} {set maxISW ""}
    if {$changeElm == "maxISH" && $maxISH == "-"} {set maxISH ""}
    if {$changeElm == "maxISB"} {
      if {$maxISB == 1} {Enable maxISW maxISH} else {Disable maxISW maxISH}
    }
  }
  Save {
    if {$maxISB == 1} {print "*FvwmIconBoxMaxIconSize\t${maxISW}x$maxISH"}
  }

  CheckBox hilight \
      -text "Hilight icon of the window having the keyboard focus" \
      -help "Check this option if you want the icon of the currently"\
      "active window to be hilighted."
  Save {if {$hilight == 1} {print "*FvwmIconBoxHilightFocusWin"}}

  Line styleL
  Entry winName -text "Window name" \
      -help "Here you enter the window name, class name or resource"\
      "name. Wildcards (*.?) are allowed."
  Entry iconName -text "Icon name" \
      -help "Here you enter the icon bitmap to use for this window in"\
      "FvwmIconBox."
  ExtEntry styles -text "Override Fvwm2 style settings" -entries {
    winName iconName
  } -help "Here you can specify icons to use for individual windows. It"\
      "is more flexible to specify this as normal Fvwm2 styles (see the"\
      "'Styles of Windows' page), however, since these settings will"\
      "affect all other uses of icons and icon names."
  Save {forevery styles {print "*FvwmIconBox\t$winName\t$iconName"}}

  Window presentW -text "Configuration of Icon Presentation" -entries {
    sortB sortOrder
    padding
    placeLn placeB placeF
    moreL
    lines
    maxISF
    hilight
    styleL styles
  } -help "In this window you configure how the icons are presented." \
      -pageEnd {
	if {$maxISB == 1 && ($maxISW == "" || $maxISH == "")} {
	  error "Invalid width and/or height in icon size of FvwmIconBox."
	}
	forevery styles {
	  if {$winName == "" || $iconName == ""} {
	    error "You must specify both window name and icon name, or delete\
 the tuple from the extended entry."
	  }
	}
      }

  CheckBox pixB -text "Specify a pixmap background" -help "Check this"\
      "option if you want to use a pixmap as a background for the"\
      "FvwmIconBox window."
  Entry pix -help "Here you can enter a name of the pixmap file to use."
  Frame pixF -entries { pixB pix }
  Change {
    if {$changeElm == "pixB"} {
      if {$pixB == 1} {Enable pix} else {Disable pix}
    }
  }
  Save {if {$pixB == 1} {print "*FvwmIconBoxPixmap\t$pix"}}

  Label geomL -text "Specify geometry:" -help "Here you can specify the"\
      "size and location of the window."
  Int geomW -text "Width"
  Int geomH -text "Height"
  Int geomX -text "X-pos"
  Int geomY -text "Y-pos"
  Frame geomF -entries { geomL geomW geomH geomX geomY }
  Change {
    if {$changeElm == "geomW" && $geomW == "-"} {set geomW ""}
    if {$changeElm == "geomH" && $geomH == "-"} {set geomH ""}
  }
  Save {
    if {$geomW != ""} {
      print "*FvwmIconBoxGeometry\t${geomW}x$geomH[signed \
             $geomX][signed $geomY]"
    }
  }

  Int scWidth -text "Set the width of scroll bars to:" \
      -textafter "pixels" \
      -help "Here you can specify the width of the scrollbars used"\
      "around the window."
  Change {if {$changeElm == "scWidth" && $scWidth == "-"} {set scWidth ""}}
  Save {if {$scWidth != ""} {print "*FvwmIconBoxSBWidth\t$scWidth"}}

  Int scPad -text "Set padding around the scroll bars to:" \
      -textafter "pixels" \
      -help "Here you can enter the space in pixels between the window"\
      "and the scroll bar, and the scroll bar and the outer border."
  Change {if {$changeElm == "scPad" && $scPad == "-"} {set scPad ""}}
  Save {if {$scPad != ""} {print "*FvwmIconBoxFrameWidth\t$scPad $scPad"}}

  Label hideSC -text "Hide one scroll bar:" \
      -help "You can hide either the horizontal or the vertical scroll"\
      "bar if you want, but you cannot hide both."
  CheckBox hideSCH -text "Horizontal" -help "Check this option if you"\
      "want to hide the horizontal scroll bar."
  CheckBox hideSCV -text "Vertical" -help "Check this option if you"\
      "want to hide the vertical scroll bar."
  Frame hideSCF -entries { hideSC hideSCH hideSCV }
  Change {
    if {$changeElm == "hideSCH" && $hideSCH == 1} {set hideSCV 0}
    if {$changeElm == "hideSCV" && $hideSCV == 1} {set hideSCH 0}
  }
  Save {
    if {$hideSCH == 1} {print "*FvwmIconBoxHideSC\tHorizontal"}
    if {$hideSCV == 1} {print "*FvwmIconBoxHideSC\tVertical"}
  }

  CheckBox currOnly -text "Display icons from the current desk only" \
      -help "Check this option if you want FvwmIconBox to display icons"\
      "of windows on the current desk only."
  Save {if {$currOnly == 1} {print "*FvwmIconBoxResolution\tDesk"}}

  CheckBox sWMIS -text "Set XA_WM_ICON_SIZE property of root window" \
      -help "You should probably check this option. I have no idea what"\
      "it does, however :("
  Save {if {$sWMIS == 1} {print "*FvwmIconBoxSetWMIconSize"}}

  Line globL1
  Line globL2
  Window globalW -text "Configuration of the Window" -entries {
    pixF
    geomF
    globL1
    scWidth
    scPad
    hideSCF
    globL2
    currOnly
    sWMIS
  } -help "In this window you configure how the main window will look." \
      -pageEnd {
	if {$geomW != "" || $geomH != "" || $geomX != "" || $geomY != ""} {
	  if {$geomW == "" || $geomH == "" || $geomX == "" || $geomY == ""} {
	    error "You must specify all or no geometry configuration for\
 FvwmIconBox."
	  }
	}
      }
  
  Label keyIdx -text "Description:" -label:relief groove
  Label keysymL -text Keysym -help "Select a keysym from the list, if"\
      "the desired keysym isn't present you can enter it yourself."
  ComboBox keysym -entries { Left Right Up Down
    F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 L1 L2 L3 L4 L5 L6 L7 L8 L9 L10
    a b c d e f g h i j k l m n o p q r s t u v w x y z
    A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
  } -help "Select a keysym from the list, if the desired keysym isn't" \
      "present you can enter it yourself."
  Frame keysymF -orient top -entries { keysymL keysym }
  Label KfuncLabel -text "Function to call" \
      -help "This is a list of the built-in functions you can bind to."
  global Builtins
  ComboBox KbuiltinCall -noedit 1 -default Next -entryhelp \
      [concat {
	Next  "Change the hilighted icon to the next."
	Prev  "Change the hilighted icon to the previous."
	Left  "Move the horizontal scroll bar to the left."
	Right "Move the horizontal scroll bar to the right."
	Up    "Move the vertical scroll bar up."
	Down  "Move the vertical scroll bar down."
      } $Builtins] \
      -help "Select a built-in function to call from this menu. Note that\
 there are extra FvwmIconBox commands at the top."
  Label KargLabel -text "Arguments" \
      -help "Any additional arguments are entered here (the syntax is your" \
      "responsibility) - see help for the individual commands."
  Entry keyArgs \
      -help "Any additional arguments are entered here (the syntax is your" \
      "responsibility) - see help for the individual commands."
  Frame keyFuncF -entries {KfuncLabel KbuiltinCall} -orient top
  Frame keyArgsF -entries {KargLabel keyArgs} -orient top
  ExtEntry Kresponses -entries { keyFuncF keyArgsF }
  Frame keyBindF -entries {keysymF Kresponses}

  ExtEntry keys -text "Key Bindings" -entries {
    keyIdx keyBindF
  } -index keyIdx -orient top -count 1 -packFrame:expand yes \
      -packFrame:fill x \
      -help "Here you configure the key bindings. Select a keysym"\
      "to bind, and then specify which command(s)"\
      "to execute on that event."
  Change {
    if {$changeElm == "keysym"} {
      set keyIdx "Key $keysym"
    }
  }
  Save {
    forevery keys {
      set resp ""
      forevery Kresponses {
	append resp ",$KbuiltinCall"
	if {$keyArgs != ""} {append resp " $keyArgs"}
      }
      if {$resp != ""} {
	print "*FvwmIconBoxKey\t$keysym [string range $resp 1 end]"
      } else {
	tk_dialog .keyDialog Warning "You had a key binding for\
 FvwmIconBox without any functions to call. This binding will be ignored." \
	    info 0 OK
      }
    }
  }

  Label mouseIdx -text "Description:" -label:relief groove
  Menu mouseBut -entries { 1 2 3 }
  Menu mouseAct -entries { Click DoubleClick }
  Frame mouseActionF -entries { mouseBut mouseAct }
  Label funcLabel -text "Function to call" \
      -help "This is a list of the built-in functions you can bind to."
  global Builtins
  ComboBox builtinCall -noedit 1 -default Beep -entryhelp $Builtins \
      -help "Select a built-in function to call from this menu"
  Label argLabel -text "Arguments" \
      -help "Any additional arguments are entered here (the syntax is your" \
      "responsibility) - see help for the individual commands."
  Entry mouseArgs \
      -help "Any additional arguments are entered here (the syntax is your" \
      "responsibility) - see help for the individual commands."
  Frame mouseFuncF -entries {funcLabel builtinCall} -orient top
  Frame mouseArgsF -entries {argLabel mouseArgs} -orient top
  ExtEntry responses -entries { mouseFuncF mouseArgsF }
  Frame mouseBindF -entries {mouseActionF responses}

  ExtEntry mice -text "Mouse Bindings" -entries {
    mouseIdx mouseBindF
  } -index mouseIdx -orient top -count 1 -packFrame:expand yes \
      -packFrame:fill x \
      -help "Here you configure the mouse bindings. Select a mouse"\
      "button and an action to bind, and then specify which command(s)"\
      "to execute on that event."
  Change {
    if {$changeElm == "mouseBut" || $changeElm == "mouseAct"} {
      set mouseIdx "Button $mouseBut(name), $mouseAct(name)"
    }
  }
  Save {
    forevery mice {
      set resp ""
      forevery responses {
	append resp ",$builtinCall"
	if {$mouseArgs != ""} {append resp " $mouseArgs"}
      }
      if {$resp != ""} {
	print "*FvwmIconBoxMouse\t$mouseBut(name) $mouseAct(name) [string \
               range $resp 1 end]"
      } else {
	tk_dialog .mouseDialog Warning "You had a mouse binding for\
 FvwmIconBox without any functions to call. This binding will be ignored." \
	    info 0 OK
      }
    }
  }

  Line bindL
  Window bindingW -text "Configuration of Key and Mouse Bindings" -entries {
    keys bindL mice
  } -help "In this window you configure the mouse bindings to use in"\
      "FvwmIconBox."

  Save {
    if {$style == 1} {print "Style \"*\"\tNoIcon"}
    if {$spawn == 1} {
      print "AddToFunc InitFunction \"I\" Module FvwmIconBox"
      print "AddToFunc RestartFunction \"I\" Module FvwmIconBox"
    }
  }
}
