class ToggleButtons(parentObj, name) of CONTAINER(parentObj, name) custom
   with (this)
      left = 26
      top = 16
      width = 42
      height = 198
      metric = 6	// Pixels
      borderstyle = 2
      transparent = true
   endwith
  
   this.APPOINTIN = new PUSHBUTTON(this)
   with (this.APPOINTIN)
      height = 38
      left = 1
      top = 1
      width = 38
      toggle = true
      value = false
      text = ""
      onClick = class::onChange
      upBitmap = "FILENAME :Images:appointin.gif"
      speedtip = 'Appointment In'
      pageno = 0
      group = false
   endwith


   this.APPOINTOUT = new PUSHBUTTON(this)
   with (this.APPOINTOUT)
      height = 38
      left = 1
      top = 40
      width = 38
      onClick = class::onChange
      toggle = true
      value = false
      text = ""
      upBitmap = "FILENAME :Images:appointout.gif"
      speedtip = 'Appointment Out'
      pageno = 0
      group = false
   endwith


   this.PHONEIN = new PUSHBUTTON(this)
   with (this.PHONEIN)
      height = 38
      left = 1
      top = 79
      width = 38
      toggle = true
      onClick = class::onChange
      speedtip = 'Incoming Call'
      value = false
      text = ""
      upBitmap = "FILENAME :Images:Phonein.gif"
      pageno = 0
      group = false
   endwith


   this.PHONEOUT = new PUSHBUTTON(this)
   with (this.PHONEOUT)
      height = 38
      left = 1
      top = 118
      width = 38
      toggle = true
      value = false
      speedtip = 'Outgoing Call'
      onClick = class::onChange
      text = ""
      upBitmap = "FILENAME :Images:phoneout.GIF"
      pageno = 0
      group = false
   endwith


   this.TODO = new PUSHBUTTON(this)
   with (this.TODO)
      height = 38
      left = 1
      top = 157
      width = 38
      toggle = true
      value = false
      onClick = class::onChange
      speedtip = 'To Do'
      text = ""
      upBitmap = "FILENAME :Images:hammer.gif"
      pageno = 0
      group = false
   endwith

   ////// One wouldn't normally do an "init event" like this here, but
   ////// this can't be re-opened in the Visual tools, so there's no
   ////// chance of this being overwritten
   this.oNotifyField  = ""
   this.setup()

   function setup
      ////// Make a name/value array of button names and references
      this.aButtons = new AssocArray()
      with (this)
         aButtons["Appt In"] = this.APPOINTIN
         aButtons["Appt Out"] = this.APPOINTOUT
         aButtons["Phone In"] = this.PHONEIN
         aButtons["Phone Out"] = this.PHONEOUT
         aButtons["To Do"] = this.TODO

         ////// Make TaskType custom property of each button for use
         ////// with Get and SetTask  These names are being stored to
         ////// match the values being stored in the table "type" field.

         aButtons["Appt In"].TaskName = "Appt In"
         aButtons["Appt Out"].TaskName = "Appt Out"
         aButtons["Phone In"].TaskName = "Phone In"
         aButtons["Phone Out"].TaskName = "Phone Out"
         aButtons["To Do"].TaskName = "To Do"

         ////// This is a workaround for an onClick problem with
         ////// toggle pushbuttons. They're not keeping their value
         ////// properly when set programatically. Therefore, we need
         ////// to toggle the value ourselves and use the pb.value
         ////// property only for setting toggled/untoggled

         aButtons["Appt In"].oldValue = false
         aButtons["Appt Out"].oldValue = false
         aButtons["Phone In"].oldValue = false
         aButtons["Phone Out"].oldValue = false
         aButtons["To Do"].oldValue = false

      endwith
   ////// Method		NotifyOfTaskChange/////////////////////////////////
   ////// Purpose:	Udate outside field value when change occurs here /
   ////// Called:		Only from pushbutton on this container ////////////

   function onChange

      // if control is registered, update its  value with taskname

      bValue = iif(this.oldValue,false,true) // workaround for value

      if not form.DataMod1.Appoints1.rowset.endOfSet
         If type('this.parent.oNotifyField') = 'O'
            this.parent.oNotifyField.value = iif(this.value,this.taskName,'')
         endif
      endif

      ////// Check all other toggle buttons and make sure no others are
      ////// pressed, but only if this one was -pressed-, not "unclicked"
  
      cKey = this.parent.aButtons.firstKey
                                    // Traverse buttons
      for n = 1 to this.parent.aButtons.count()

          if this.parent.aButtons[cKey] # this // if not this button
                
          //   msgbox('setting false:'+cKey+':')
             this.parent.aButtons[cKey].value = false
          else

             this.value = iif(this.oldValue, false, true)

          endif

          cKey = this.parent.aButtons.nextKey(cKey)
      next
  
      
      return iif(this.value,this.taskName,'')

   ////// Method;		getTask() /////////////////////////////////////////
   ////// Purpose:	Allows outside objects to query for current task //
      
   function getTask
      private n

      cKey = this.aButtons.firstKey

      for n = 1 to this.aButtons.count()

         if this.aButtons[cKey].value  // if this button toggled
         								// send back taskname
            return this.aButtons[cKey].TaskName
         endif

         cKey = this.aButtons.nextKey(cKey)

      next

      return ""  // no buttons toggles

   ////// Method: 	setTask(cNewTask) /////////////////////////////////
   ////// Purpose:	Allows outside objects to set the desired toggle
   ////// Param		cNewTask - specify task desired. It must be in the
   //////            aButtons taskname list ////////////////////////////

   function setTask(cCurrentTask)

      private n

      cTask = trim(cCurrentTask) // Work with trim value
   
      cKey = this.aButtons.firstKey       // set first key
      
      for n = 1 to this.aButtons.count()  // traverse array

                                          // if match, toggle
         if upper(this.aButtons[cKey].taskName) = upper(cTask)
            this.aButtons[cKey].value = true
            this.aButtons.oldValue = true  // workaround for value bug
         else                             // else, untoggle
            this.aButtons[cKey].value = false
            this.aButtons.oldValue = false
         endif

         cKey = this.aButtons.nextKey(cKey)
      next

      return true

   ////// Method: 	RegisterField(oFieldRef) ///////////////////////////
   ////// Purpose:	To datalink this control to a data-entry field /////
   ////// Param:		oFieldRef - a reference to field with a value property

   function registerField(oFieldRef)
      private oRef
      oRef = oFieldRef
      if type('oRef') = 'O' and type('oRef.value') = 'C'
         this.oNotifyField = oFieldRef
      endif

   endclass
