# Program: xf
# Description: handle pie widgets
#
# $Header: Pie[2.3] Wed Mar 10 11:57:29 1993 garfield@garfield frozen $

global xfDefaultConf
set xfDefaultConf(pie) 4

##########
# Procedure: XFAdd.Pie
# Description: add a pie
# Arguments: xfW - the widget
#            xfName - a optional name
#            xfType - add or config
# Returns: none
# Sideeffects: none
##########
proc XFAdd.Pie {xfW xfName xfType} {
  global xfStatus

  XFEditSetStatus "Inserting Pie..."
  set xfName [XFMiscGetUniqueName $xfName pie]
  if {"$xfStatus(path)" == "."} {
    if {"$xfType" == "add"} {
      if {[catch "pie .$xfName" xfResult]} {
        XFProcError "$xfResult"
        XFEditSetStatus "Inserting Pie...aborted"
        return
      }
    } {
      if {[catch "pie .$xfName" xfResult]} {
        XFProcError "$xfResult"
        XFEditSetStatus "Inserting Pie...aborted"
        return
      }
    }

    XFMiscPositionWidget .$xfName
    XFMiscBindWidgetTree .$xfName
  } {
    if {"$xfType" == "add"} {
      if {[catch "pie $xfStatus(path).$xfName" xfResult]} {
        XFProcError "$xfResult"
        XFEditSetStatus "Inserting Pie...aborted"
        return
      }
    } {
      if {[catch "pie $xfStatus(path).$xfName" xfResult]} {
        XFProcError "$xfResult"
        XFEditSetStatus "Inserting Pie...aborted"
        return
      }
    }

    XFMiscPositionWidget $xfStatus(path).$xfName
    XFMiscBindWidgetTree $xfStatus(path).$xfName
  }

  incr xfStatus(elementCounter)
  XFEditSetPath $xfStatus(path)
  XFEditSetStatus "Inserting Pie...done"
}

##########
# Procedure: XFConfig.Pie4
# Description: configure a pie
# Arguments: xfW - the widget
#            xfType - config type (add or config)
#            xfClass - the class we configure
#            xfLeader - the leading window
# Returns: none
# Sideeffects: none
##########
proc XFConfig.Pie4 {xfW xfType xfClass {xfLeader ""}} {
  global xfStatus

  if {"$xfType" == "add"} {
    set xfName pie$xfStatus(elementCounter)
  } {
    set xfName [XFMiscPathName $xfW]
  }
  XFEditSetStatus "Calling parameter setting for Pie..."

  # build widget structure
  XFTmpltToplevel .xf${xfClass}Config4 400x600 \
    "Pie parameters:[XFMiscPathTail $xfW]" $xfLeader

  XFElementInit $xfW .xf${xfClass}Config4 $xfType $xfClass \
    XFPieSetPie4 parameters $xfName 4
  XFElementColor $xfW .xf${xfClass}Config4 $xfType $xfClass bg \
    background Background "Background" XFPieSetPie4
  XFElementBoolean $xfW .xf${xfClass}Config4 $xfType $xfClass explode \
    "Explode" XFPieSetPie4
  XFElementScale $xfW .xf${xfClass}Config4 $xfType $xfClass explodewidth \
    explodewidth Explodewidth "Explode width" "pixels" 250 XFPieSetPie4
  XFElementText $xfW .xf${xfClass}Config4 $xfType $xfClass interval \
    interval Interval "Interval" XFPieSetPie4
  XFElementScale $xfW .xf${xfClass}Config4 $xfType $xfClass keyboxsize \
    keyboxsize Keyboxsize "Keyboxsize" "pixels" 250 XFPieSetPie4
  XFElementText $xfW .xf${xfClass}Config4 $xfType $xfClass keyorder \
    keyorder Keyorder "Keyorder" XFPieSetPie4
  XFElementScale $xfW .xf${xfClass}Config4 $xfType $xfClass origin \
    origin Origin "Origin" "degree" 360 XFPieSetPie4
  XFElementScale $xfW .xf${xfClass}Config4 $xfType $xfClass radius \
    radius Radius "Radius" "pixels" 400 XFPieSetPie4
  XFElementText $xfW .xf${xfClass}Config4 $xfType $xfClass title \
    title Title "Text" XFPieSetPie4
  XFElementColor $xfW .xf${xfClass}Config4 $xfType $xfClass textcolor \
    textcolor Foreground "Text color" XFPieSetPie4
  XFElementCommand $xfW .xf${xfClass}Config4 $xfType

  # save current parameter
  XFElementSave $xfW $xfClass {background explode explodewidth interval keyboxsize keyorder origin radius title textcolor command}

  # packing
  pack append .xf${xfClass}Config4.params1 \
              .xf${xfClass}Config4.params1.params2 {left fill expand}
  pack append .xf${xfClass}Config4 \
              .xf${xfClass}Config4.pathname {top fill frame center} \
              .xf${xfClass}Config4.leave {bottom fill} \
              .xf${xfClass}Config4.additional {bottom fill} \
              .xf${xfClass}Config4.params1 {top fill expand}

  XFBindFormConnect .xf${xfClass}Config4.params1.params2 \
    "XFPieSetPie4 $xfW 0 $xfClass"

  XFEditSetStatus "Calling parameter setting for Pie...done"
}

##########
# Procedure: XFSaveSpecial.Pie
# Description: save pie
# Arguments: xfW - the widget
# Returns: none
# Sideeffects: none
##########
proc XFSaveSpecial.Pie {xfW} {

  if {"[$xfW get]" != ""} {
    return "\n  $xfW set [$xfW get]"
  }
  return ""
}

##########
# Procedure: XFPieSetPie4
# Description: set pie parameters
# Arguments: xfW - the widget
#            xfType - the type of setting (1 = set always, 0 = set
#                     only if permanent apply is on)
#            xfClass - the class we configure
#            xfParam1 - ignored parameter
# Returns: none
# Sideeffects: none
##########
proc XFPieSetPie4 {xfW xfType xfClass {xfParam1 ""}} {
  global xfConf
  global xfMisc

  if {$xfType == 0 && !$xfConf(applyParameters)} {
    return
  }
  if {"[info commands $xfW]" == ""} {
    return
  }
  XFMiscSetSymbolicName $xfW \
    [.xf${xfClass}Config4.params1.params2.symname.symname get]

  XFMiscSetResource $xfW background \
    [.xf${xfClass}Config4.params1.params2.bg.bg get]
  XFMiscSetResource $xfW command \
    [XFMiscGetText .xf${xfClass}Config4.params1.params2.command.command.command]
  XFMiscSetResource $xfW explode $xfMisc(explode)
  XFMiscSetResource $xfW explodewidth \
    [.xf${xfClass}Config4.params1.params2.explodewidth.explodewidth get]
  if {"[.xf${xfClass}Config4.params1.params2.interval.interval get]" != ""} {
    XFMiscSetResource $xfW interval \
      [.xf${xfClass}Config4.params1.params2.interval.interval get]
  } {
    XFMiscSetResource $xfW interval 0
  }
  XFMiscSetResource $xfW keyboxsize \
    [.xf${xfClass}Config4.params1.params2.keyboxsize.keyboxsize get]
  XFMiscSetResource $xfW keyorder \
    [.xf${xfClass}Config4.params1.params2.keyorder.keyorder get]
  XFMiscSetResource $xfW origin \
    [.xf${xfClass}Config4.params1.params2.origin.origin get]
  XFMiscSetResource $xfW radius \
    [.xf${xfClass}Config4.params1.params2.radius.radius get]
  if {"[.xf${xfClass}Config4.params1.params2.textcolor.textcolor get]" != ""} {
    XFMiscSetResource $xfW textcolor \
      [.xf${xfClass}Config4.params1.params2.textcolor.textcolor get]
  }
  XFMiscSetResource $xfW title \
    [.xf${xfClass}Config4.params1.params2.title.title get]
}

# eof

