### 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 buttonsAndCursors {} {
  # Look-and-Feel / Configuration of Buttons
  Desc "Change the style of buttons and mouse cursors"
  ShortDesc "Buttons and cursors"

  ########################################################################
  # Button styles
  #
  Header butH -text "Button Configuration" -frame:relief flat
  Help butH \
      "On this page you configure the appearance of the title bar buttons."
  Line butL

  for {set i 0} {$i <= 9} {incr i} {
    Label lab$i -text " $i"
    CheckBox but$i
    Help but$i "Here you select to change button no. $i."
    Help lab$i "Here you select to change button no. $i."
    Frame fram$i -entries " lab$i but$i " -orient top
  }
  Label empty -text "" -help ""
  Label butNo -text "Button no:"
  Label space -text "    " -help "" -packFrame:expand no
  Frame framL -entries { empty butNo } -orient top
  Frame butS -entries { framL
    fram1 fram3 fram5 fram7 fram9 space
    fram0 fram8 fram6 fram4 fram2 }

  Help butNo "Here you select which button to change."

  Change {
    if {[regexp "but(\[0-9\])" $changeElm all no] && $changeElm == $all} {
      if {[set but$no] == 1} {
        for {set i 0} {$i <= 9} {incr i} {
          if {$i != $no} {set but$i 0}
        }
      }
    }
  }

  # User shape
  Header coordH -text "Enter button decoration coordinates" \
      -frame:relief flat
  Line coordL
  Int coordX -text "X coordinate"
  Int coordY -text "Y coordinate"
  Radio shade -entries { shadow highlight }
  ExtEntry coord -entries { coordX coordY shade }
  CheckBox butB -text "User style" -pack:expand no
  Window butW -text "Coordinates" -entries { coordH coordL coord }
  Frame butF -entries { butB butW }

  # Pixmap
  CheckBox pixB -text "Pixmap" -pack:expand no
  Entry pixEup -text "up:"
  Entry pixEdown -text "down:"
  Frame pixE -entries { pixB pixEup pixEdown }
  Label pixRlabel -text "    Draw a button 'below' the pixmap?" \
      -packFrame:expand no
  Radio pixRbut -entries { "yes" "no" } -default "yes"
  Frame pixR -entries { pixRlabel pixRbut }
  Frame pixF -entries { pixE pixR } -orient top
  ExtEntry but -entries { butS butF pixF } -count 1 -orient top \
      -packFrame:expand yes -packFrame:fill x

  set userHelp1 [concat \
                     "When selecting user defined buttons, you can specify coordinates" \
                     "in a polygon. The coordinates are in percents of the button" \
                     "width/height, and must therefore be between 0 and 100." ]
  set userHelp2 [concat \
                     "Further more you can specify the shade of the line going to the" \
                     "specified point (shadow or highlight)." ]
  # concat eats newline...
  set userHelp "$userHelp1\n\n$userHelp2"
  
  Help coordH $userHelp
  Help coordX "Here you specify the X-coordinate of the point"
  Help coordY "Here you specify the Y-coordinate of the point"
  Help shade "Here you specify the shade of the line going to this point"
  Help butB $userHelp
  Help butW $userHelp

  set pixmapHelp1 [concat \
                       "When selecting pixmap buttons, you can specify one or two" \
                       "pixmaps to use as the button. If you only specify the 'up'" \
                       "pixmap, this pixmap will be used for the button in any state." \
                       "Optionally, you can specify the 'down' pixmap, which will be" \
                       "used for the button in the 'down' state."]
  set pixmapHelp2 [concat \
                       "You can also specify whether to draw a button 'below' the pixmap." \
                       "If you select this, FVWM will first draw the button, and then" \
                       "only letting the pixmap fill the face of the button. If not," \
                       "FVWM will let the pixmap fill the entire area meant for the" \
                       "button." ]
  # concat eats newline...
  set pixmapHelp "$pixmapHelp1\n\n$pixmapHelp2"

  Help pixB $pixmapHelp
  Help pixEup "Here you can enter a pixmap for the 'up' state."
  Help pixEdown "Here you can enter a pixmap for the 'down' state."
  Help pixRlabel "Here you select, whether FVWM will draw a button."
  Help pixRbut "Here you select, whether FVWM will draw a button."

  Change {
    if {$changeElm == "butB"} {
      if {$butB == 1} {
        set pixB 0
        Disable pixEup pixEdown pixR
        Enable butW
      } else {
        Disable butW
      }
    }
    if {$changeElm == "pixB"} {
      if {$pixB == 1} {
        set butB 0
        Disable butW
        Enable pixEup pixR
        if { $pixEup != "" } { Enable pixEdown }
      } else {
        Disable pixEup pixEdown pixR
      }
    }
    if { $changeElm == "pixEup" } {
      if { $pixEup == "" } { Disable pixEdown } else { Enable pixEdown }
    }
  }

  Save {
    forevery but {
      set no -1
      for { set i 0 } { $i < 10 } { incr i } {
        if { [set but$i] == 1 } { set no $i }
      }
      if { $butB == 1 && $no != -1 } {
        # User style
        set coords 0
        set buttonStyle ""
        forevery coord {
          if { $coordX != "" && $coordY != "" } {
            append buttonStyle " ${coordX}x${coordY}@$shade(index)"
            incr coords
          }
        }
        if { $coords > 0 } {
          print "ButtonStyle\t$no $coords$buttonStyle"
        } else {
          error "No coordinates set for button $no"
        }
      }
      if { $pixB == 1 && $no != -1 && $pixEup != "" } {
        # Pixmap
        set buttonStyle "Pixmap $pixEup"
        if { $pixRbut(name) == "no" } { append buttonStyle " -- Flat" }
        print "ButtonStyle\t$no $buttonStyle"
        if { $pixEdown != "" } {
	  set buttonStyle "Pixmap $pixEdown"
          if { $pixRbut(name) == "no" } { append buttonStyle " -- Flat" }
          print "ButtonStyle\t$no ActiveDown $buttonStyle"
	}
      }
    }
  }
  #
  ########################################################################
}
