Show
Ignore:
Timestamp:
09/03/2007 09:23:43 AM (15 months ago)
Author:
tof
Message:

TSlider: Implement StepSize?

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/3.2-dev/framework/Web/UI/WebControls/TSlider.php

    r2189 r2190  
    5858         */ 
    5959        private $_handle; 
    60         /** 
    61          * @var string Custom handle class name 
    62          */ 
    63         private $_handleClass; 
    64         /** 
     60        /* 
    6561         * @var boolean Wether the data has changed during postback 
    6662         */ 
     
    8480        public function setDirection($value) 
    8581        { 
    86                 $this->setViewState('Direction', TPropertyValue::ensureEnum($value,TSliderDirection)); 
     82                $this->setViewState('Direction', TPropertyValue::ensureEnum($value,'TSliderDirection')); 
    8783        } 
    8884 
     
    104100 
    105101        /** 
    106          * @return string CssClass for an horizontal track of the slider control. Defaults to 'hslider' 
    107          */ 
    108         public function getHorizontalCssClass () 
    109         { 
    110                 return $this->getViewState('HorizontalCssClass', 'hslider'); 
    111         } 
    112  
    113         /** 
    114          * @param string CssClass for an horizontal track of the slider control. Defaults to 'hslider' 
    115          */ 
    116         public function setHorizontalCssClass ($value) 
    117         { 
    118                 $this->setViewState('HorizontalCssClass', $value, 'hslider'); 
    119         } 
    120  
    121         /** 
    122          * @return string CssClass for a vertical track of the slider control. Defaults to 'slider' 
    123          */ 
    124         public function getVerticalCssClass () 
    125         { 
    126                 return $this->getViewState('VerticalCssClass', 'vslider'); 
    127         } 
    128  
    129         /** 
    130          * @param string CssClass for a vertical track of the slider control. Defaults to 'vslider' 
    131          */ 
    132         public function setVerticalCssClass ($value) 
    133         { 
    134                 $this->setViewState('VerticalCssClass', $value, 'vslider'); 
    135         } 
    136  
    137         /** 
    138          * @return int Maximum value for the slider 
     102         * @return float Maximum value for the slider 
    139103         */ 
    140104        public function getMaxValue() 
     
    144108 
    145109        /** 
    146          * @param int Maximum value for slider 
     110         * @param float Maximum value for slider 
    147111         */ 
    148112        public function setMaxValue($value) 
    149113        { 
    150                 $value=TPropertyValue::ensureInteger($value); 
    151                 // Should I ensure the values are the same than the allowed values ? 
    152                 /* 
    153                 if (($values=$this->getValues())!==null && $value != max($values)) $value=max($values); 
    154                 */ 
    155                 $this->setViewState('MaxValue', $value,100); 
    156         } 
    157  
    158         /** 
    159          * @return int Minimum value for slider 
     114                $this->setViewState('MaxValue', TPropertyValue::ensureFloat($value),100); 
     115        } 
     116 
     117        /** 
     118         * @return float Minimum value for slider 
    160119         */ 
    161120        public function getMinValue() 
     
    165124 
    166125        /** 
    167          * @param int Minimum value for slider 
     126         * @param float Minimum value for slider 
    168127         */ 
    169128        public function setMinValue($value) 
    170129        { 
    171                 $value=TPropertyValue::ensureInteger($value); 
    172                 // Should I ensure the values are the same than the allowed values ? 
    173                 /* 
    174                 if (($values=$this->getValues())!==null && $value != min($values)) $value=min($values); 
    175                 */ 
    176                 $this->setViewState('MinValue', $value,0); 
    177         } 
    178  
     130                $this->setViewState('MinValue', TPropertyValue::ensureFloat($value),0); 
     131        } 
     132 
     133        /** 
     134         * @return float Step size. Defaults to 1 
     135         */ 
     136        public function getStepSize() 
     137        { 
     138                return $this->getViewState('StepSize', 1); 
     139        } 
     140         
     141        /** 
     142         * @param float Step size. Defaults to 1. 
     143         */ 
     144        public function setStepSize($value) 
     145        { 
     146                $this->setViewState('StepSize', $value, 1); 
     147        } 
     148         
    179149        /** 
    180150         * @return float current value of slider 
     
    208178                $value=TPropertyValue::ensureArray($value); 
    209179                $this->setViewState('Values', $value, null); 
    210                 // Should I ensure Min/MaxValue are correct ??? 
    211                 /*  
    212                 if ($this->getMinValue() < min($value)) $this->setMinValue(min($value)); 
    213                 if ($this->getMaxValue() > max($value)) $this->setMaxValue(max($value)); 
    214                 */  
    215         } 
    216  
    217         /** 
    218          * @return int number of decimals for the value. Defaults to 0 
    219          */ 
    220         public function getDecimals() 
    221         { 
    222                 return $this->getViewState("Decimals", 0); 
    223         } 
    224  
    225         /** 
    226          * @param int number of decimas for the value. Defaults to 0. 
    227          */ 
    228         public function setDecimals($value) 
    229         { 
    230                 $this->setViewState ('Decimals', TPropertyValue::ensureInteger($value), 0); 
    231         } 
     180        } 
     181 
    232182 
    233183        /** 
     
    254204        public function getHandleClass () 
    255205        { 
    256                 return $this->_handleClass?$this->_handleClass:TSliderHandle; 
     206                return $this->getViewState('HandleClass', 'TSliderHandle'); 
    257207        } 
    258208 
     
    267217                if ($handle instanceof TSliderHandle) 
    268218                { 
    269                         $this->_handleClass=$value; 
     219                        $this->setViewState('HandleClass', $value); 
    270220                        $this->_handle=$handle; 
    271221                } else { 
     
    325275        public function raisePostDataChangedEvent() 
    326276        { 
    327                 $this->onSliderChanged(null); 
    328         } 
    329  
    330         /** 
    331          * Raises <b>OnSliderChanged</b> event. 
     277                $this->onValueChanged(null); 
     278        } 
     279 
     280        /** 
     281         * Raises <b>OnValueChanged</b> event. 
    332282         * This method is invoked when the {@link getValue Value} 
    333283         * property changes on postback. 
     
    336286         * @param TEventParameter event parameter to be passed to the event handlers 
    337287         */ 
    338         public function onSliderChanged($param) 
    339         { 
    340                 if ($this->getDataChanged()) $this->raiseEvent('OnSliderChanged',$this,$param); 
     288        public function onValueChanged($param) 
     289        { 
     290                if ($this->getDataChanged()) $this->raiseEvent('OnValueChanged',$this,$param); 
    341291        } 
    342292 
     
    410360        protected function addAttributesToRender($writer) 
    411361        { 
    412  
     362                parent::addAttributesToRender($writer); 
    413363                $writer->addAttribute('id',$this->getClientID()); 
    414                 $class=($this->getDirection()==TSliderDirection::Horizontal)?$this->getHorizontalCssClass():$this->getVerticalCssClass(); 
    415                 $writer->addAttribute('class', $class); 
    416                 parent::addAttributesToRender($writer); 
     364                if ($this->getCssClass()==='')  
     365                        $writer->addAttribute('class', $this->getDirection()===TSliderDirection::Horizontal?'hslider':'vslider'); 
    417366        } 
    418367 
     
    469418 
    470419                // Slider Control options 
     420                $minValue=$this->getMinValue(); 
     421                $maxValue=$this->getMaxValue(); 
    471422                $options['axis'] = strtolower($this->getDirection()); 
    472                 $options['maximum'] = $this->getMaxValue(); 
    473                 $options['minimum'] = $this->getMinValue(); 
    474                 $options['range'] = 'javascript:$R('.$this->getMinValue().",".$this->getMaxValue().")"; 
     423                $options['maximum'] = $maxValue; 
     424                $options['minimum'] = $minValue; 
     425                $options['range'] = 'javascript:$R('.$minValue.",".$maxValue.")"; 
    475426                $options['sliderValue'] = $this->getValue(); 
    476427                $options['disabled'] = !$this->getEnabled(); 
    477428                if (($values=$this->getValues())) 
     429                { 
     430                        // Values are provided. Check if min/max are present in them 
     431                        if (!in_array($minValue, $values)) $values[]=$minValue; 
     432                        if (!in_array($maxValue, $values)) $values[]=$maxValue; 
     433                        // Remove all values outsize the range [min..max] 
     434                        foreach ($values as $idx=>$value) 
     435                        { 
     436                                if ($value < $minValue) unset ($values[$idx]); 
     437                                if ($value > $maxValue) unset ($values[$idx]); 
     438                        } 
     439                }  
     440                else 
     441                { 
     442                        // Values are not provided, generate automatically using stepsize 
     443                        $step=$this->getStepSize(); 
     444                        // We want at most 200 values, so, change the step if necessary 
     445                        if (($maxValue-$minValue)/$step > 200) 
     446                        { 
     447                                $step=($maxValue-$minValue)/200; 
     448                        } 
     449                        $values=array(); 
     450                        for ($i=$minValue;$i<=$maxValue;$i+=$step) 
     451                                $values[]=$i; 
     452                        // Add max if it's not in the array because of step 
     453                        if (!in_array($maxValue, $values)) $values[]=$maxValue; 
     454                }  
    478455                $options['values'] = TJavascript::Encode($values,false); 
    479                 $options['decimals'] = $this->getDecimals(); 
    480                          
    481456                if(!is_null($this->_clientScript)) 
    482457                        $options = array_merge($options,$this->_clientScript->getOptions()->toArray());