<?php
require_once("vcl/vcl.inc.php");
//Includes
use_unit("comctrls.inc.php");
use_unit("buttons.inc.php");
use_unit("openchart/openchart.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Index extends Page
{
    public 
$sbBackground null;
    public 
$sbOutlineColor null;
    public 
$sbColor null;
    public 
$sbYAxisGridColorPicker null;
    public 
$gbXAxis null;
    public 
$sbYAxisColorPicker null;
    public 
$sbXAxisGridColor null;
    public 
$ColorSelector null;
    public 
$sbXAxisColorPicker null;
    public 
$edLoadMessage null;
    public 
$Label29 null;
    public 
$edHint null;
    public 
$Label28 null;
    public 
$edLegendText null;
    public 
$Label27 null;
    public 
$edBackground null;
    public 
$edTitle null;
    public 
$Label26 null;
    public 
$Label25 null;
    public 
$cbAnimate null;
    public 
$udRangeMax null;
    public 
$udRangeMin null;
    public 
$Label24 null;
    public 
$cbShowInRight null;
    public 
$udYSteps null;
    public 
$cbYOffset null;
    public 
$edYGridColor null;
    public 
$udYTickLength null;
    public 
$edYColor null;
    public 
$udYStroke null;
    public 
$edYLegend null;
    public 
$edOutlineColor null;
    public 
$Label10 null;
    public 
$Label9 null;
    public 
$edWidth null;
    public 
$Label8 null;
    public 
$edStartAngle null;
    public 
$Label7 null;
    public 
$edHaloSize null;
    public 
$Label6 null;
    public 
$edFunFactor null;
    public 
$Label5 null;
    public 
$edDotSize null;
    public 
$Label4 null;
    public 
$edAlpha null;
    public 
$GroupBox3 null;
    public 
$GroupBox2 null;
    public 
$Label23 null;
    public 
$Label22 null;
    public 
$Label21 null;
    public 
$Label20 null;
    public 
$Label19 null;
    public 
$Label18 null;
    public 
$Label17 null;
    public 
$cbXVertical null;
    public 
$udX3D null;
    public 
$udXSteps null;
    public 
$cbXOffset null;
    public 
$edXGridColor null;
    public 
$udXTickHeight null;
    public 
$edXColor null;
    public 
$udXStroke null;
    public 
$Label16 null;
    public 
$Label15 null;
    public 
$Label14 null;
    public 
$Label13 null;
    public 
$Label12 null;
    public 
$Label11 null;
    public 
$Label3 null;
    public 
$cbType null;
    public 
$edXLegend null;
    public 
$Label2 null;
    public 
$Label1 null;
    public 
$btnRefresh null;
    public 
$edColor null;
    public 
$OpenChart1 null;

    
/**
    * Returns an array with the coordinates to show the color picker
    *
    * @param object $object Button to use to get the coordinates
    * @param boolean $right Align the dialog to the right
    * @param boolean $bottom Align the dialog to the bottom
    * @return array
    */
    
function getButtonCoords($object$right=false$bottom=false)
    {
      
$left=$object->Parent->Left+$object->Left;
      if (
$right)
      {
        
$left=$left $this->ColorSelector->Width+$object->Width;
        if (
$left<$this->gbXAxis->Left$left=$this->gbXAxis->Left;
      }

      
$top=$object->Parent->Top+$object->Top+$object->Height-1;
      if (
$bottom)
      {
        
$top=$top-$this->ColorSelector->Height-$object->Height;
      }
      return(array(
0=>$left,1=>$top));
    }

    
/**
    * A color picker call, common routine to show the picker at the right position
    * and set which field must be udpated
    */
    
function sbBackgroundJSClick($sender$params)
    {
      
$coords=$this->getButtonCoords($senderfalsetrue);
    
?>
        //Sets which edit field is going to take the value
        editField=findObj('edBackground');
        var div=findObj('ColorSelector_outer');
        div.style.left="<?php echo $coords[0]; ?>px";
        div.style.top="<?php echo $coords[1]; ?>px";
        ColorSelector.setVisibility(true);
    <?php

    
}

    
/**
    * A color picker call, common routine to show the picker at the right position
    * and set which field must be udpated
    */
    
function sbOutlineColorJSClick($sender$params)
    {
      
$coords=$this->getButtonCoords($senderfalsetrue);
    
?>
        //Sets which edit field is going to take the value
        editField=findObj('edOutlineColor');
        var div=findObj('ColorSelector_outer');
        div.style.left="<?php echo $coords[0]; ?>px";
        div.style.top="<?php echo $coords[1]; ?>px";
        ColorSelector.setVisibility(true);
    <?php

    
}

    
/**
    * A color picker call, common routine to show the picker at the right position
    * and set which field must be udpated
    */
    
function sbColorJSClick($sender$params)
    {
      
$coords=$this->getButtonCoords($senderfalsetrue);
    
?>
        //Sets which edit field is going to take the value
        editField=findObj('edColor');
        var div=findObj('ColorSelector_outer');
        div.style.left="<?php echo $coords[0]; ?>px";
        div.style.top="<?php echo $coords[1]; ?>px";
        ColorSelector.setVisibility(true);
    <?php

    
}

    
/**
    * A color picker call, common routine to show the picker at the right position
    * and set which field must be udpated
    */
    
function sbYAxisGridColorPickerJSClick($sender$params)
    {
      
$coords=$this->getButtonCoords($sendertrue);
    
?>
        //Sets which edit field is going to take the value
        editField=findObj('edYGridColor');
        var div=findObj('ColorSelector_outer');
        div.style.left="<?php echo $coords[0]; ?>px";
        div.style.top="<?php echo $coords[1]; ?>px";
        ColorSelector.setVisibility(true);
    <?php

    
}

    
/**
    * A color picker call, common routine to show the picker at the right position
    * and set which field must be udpated
    */
    
function sbYAxisColorPickerJSClick($sender$params)
    {
      
$coords=$this->getButtonCoords($sendertrue);
    
?>
        //Sets which edit field is going to take the value
        editField=findObj('edYColor');
        var div=findObj('ColorSelector_outer');
        div.style.left="<?php echo $coords[0]; ?>px";
        div.style.top="<?php echo $coords[1]; ?>px";
        ColorSelector.setVisibility(true);
    <?php

    
}

    
/**
    * A color picker call, common routine to show the picker at the right position
    * and set which field must be udpated
    */
    
function sbXAxisGridColorJSClick($sender$params)
    {
      
$coords=$this->getButtonCoords($sender);
    
?>
        //Sets which edit field is going to take the value
        editField=findObj('edXGridColor');
        var div=findObj('ColorSelector_outer');
        div.style.left="<?php echo $coords[0]; ?>px";
        div.style.top="<?php echo $coords[1]; ?>px";
        ColorSelector.setVisibility(true);
    <?php
    
}

    
/**
    * A color picker call, common routine to show the picker at the right position
    * and set which field must be udpated
    */
    
function sbXAxisColorPickerJSClick($sender$params)
    {
      
$coords=$this->getButtonCoords($sender);
    
?>
        //Sets which edit field is going to take the value
        editField=findObj('edXColor');
        var div=findObj('ColorSelector_outer');
        div.style.left="<?php echo $coords[0]; ?>px";
        div.style.top="<?php echo $coords[1]; ?>px";
        ColorSelector.setVisibility(true);
    <?php

    
}

    
/**
    * Called when the color on the selector is changed
    */
    
function ColorSelectorJSChange($sender$params)
    {
    
?>
      //Get the new color and set the edit field with that value
      newColor="#"+qx.lang.String.pad(ColorSelector.getRed().toString(16).toUpperCase(), 2) + qx.lang.String.pad(ColorSelector.getGreen().toString(16).toUpperCase(), 2) + qx.lang.String.pad(ColorSelector.getBlue().toString(16).toUpperCase(), 2);
      editField.value=newColor;

      //Hide the color selector
      ColorSelector.setVisibility(false);

      //Moves the div the original point to prevent a bug in firefox
      var div=findObj('ColorSelector_outer');
      div.style.left="0px";
      div.style.height="0px";
    <?php

    
}

    
/**
    * This event is called when a point in the chart is clicked, allowing you
    * to call any javascript
    */
    
function Serie1Click($sender$params)
    {
    
?>
      alert('Clicked on item:'+arguments[0]);
    <?php

    
}

    function 
btnRefreshClick($sender$params)
    {
      
//When the button is clicked, lets set the values to the right properties
      
$this->OpenChart1->XLegend=$this->edXLegend->Text;
      
$this->OpenChart1->XAxis->Stroke=$this->udXStroke->Position;
      
$this->OpenChart1->XAxis->Color=$this->edXColor->Text;
      
$this->OpenChart1->XAxis->TickHeight=$this->udXTickHeight->Position;
      
$this->OpenChart1->XAxis->GridColor=$this->edXGridColor->Text;
      
$this->OpenChart1->XAxis->Offset=$this->cbXOffset->Checked;
      
$this->OpenChart1->XAxis->Steps=$this->udXSteps->Position;
      
$this->OpenChart1->XAxis->set3D($this->udX3D->Position);
      
$this->OpenChart1->XAxis->Vertical=$this->cbXVertical->Checked;

      
$this->OpenChart1->YLegend=$this->edYLegend->Text;
      
$this->OpenChart1->YAxis->Stroke=$this->udYStroke->Position;
      
$this->OpenChart1->YAxis->Color=$this->edYColor->Text;
      
$this->OpenChart1->YAxis->TickLength=$this->udYTickLength->Position;
      
$this->OpenChart1->YAxis->GridColor=$this->edYGridColor->Text;
      
$this->OpenChart1->YAxis->Offset=$this->cbYOffset->Checked;
      
$this->OpenChart1->YAxis->Steps=$this->udYSteps->Position;
      
$this->OpenChart1->YAxis->RangeMin=$this->udRangeMin->Position;
      
$this->OpenChart1->YAxis->RangeMax=$this->udRangeMax->Position;
      
$this->OpenChart1->YAxis->ShowInRight=$this->cbShowInRight->Checked;

      
$this->OpenChart1->Title=$this->edTitle->Text;
      
$this->OpenChart1->BackgroundColor=$this->edBackground->Text;

      
$this->OpenChart1->LoadingMessage=$this->edLoadMessage->Text;
    }

    
/**
    * This event is called by the serie to allow you customize every aspect
    * by code
    */
    
function Serie1Customize($sender$params)
    {
        
//Set the parameters with the settings on the form
        
$params['Width']=$this->edWidth->Text;
        
$params['Alpha']=$this->edAlpha->Text;
        
$params['Hint']=$this->edHint->Text;
        
$params['OutlineColor']=$this->edOutlineColor->Text;
        
$params['DotSize']=$this->edDotSize->Text;
        
$params['HaloSize']=$this->edHaloSize->Text;

        if (
$this->edLegendText!='')
        {
          
$params['KeyText']=$this->edLegendText->Text;
          
$params['KeySize']=1;
        }
        else
        {
          
$params['KeyText']='';
          
$params['KeySize']=0;
        }

        if (
$this->cbAnimate->Checked)
        {
          
$params['Animate']='true';
        }
        else
        {
          
$params['Animate']='false';
        }
        
$params['FunFactor']=$this->edFunFactor->Text;
        
$params['StartAngle']=$this->edStartAngle->Text;
        
$params['Color']=$this->edColor->Text;
        
$params['Type']=$this->cbType->Items[$this->cbType->ItemIndex];

        
//Return the new params
        
return($params);
    }


    
/**
    * This event is called by the serie to get the data, if no Datasource is
    * attached.
    */
    
function Serie1GetData($sender$params)
    {
        
//Generate a random number of values
        
$maxvalues rand(1020);
        
$values = array();

        
//And each point, with a random between the minimum and maximum of the scale
        
for($i 1$i <= $maxvalues$i++)
        {
            
$values[ ] = rand($this->OpenChart1->YAxis->RangeMin$this->OpenChart1->YAxis->RangeMax);
        }
        return(
$values);
    }

}

global 
$application;

global 
$Index;

//Creates the form
$Index = new Index($application);

//Read from resource file
$Index->loadResource(__FILE__);

//Shows the form
$Index->show();

?>