﻿///<reference path="MicrosoftAjax.debug.js" > 
///<reference path="shared.js" > 
///<reference path="control.js" > 

            

SLx.CheckBox = function ( visual , xamlTemplate , templateParts ) 
{ 

    SLx.CheckBox.initializeBase (this , [visual, xamlTemplate,  templateParts ] );             
    
    if ( this._content != null ) 
        this._checkOffsetLeft  = this._content.get_left(); 
}, 


SLx.CheckBox.prototype = 
{ 

    //Measure needs to take into account checkbox size..    
    measure : function ( width , height ) 
    {    
        if ( ! this._isMeasureInvalidated && SLx.Application.Current.get_cacheLayout() ) 
        { 
            Sys.Debug.trace ( this.toString()  + "cached measure" ) ;
            return ;  
        } 
            
        if ( this._sizeToParent ) 
        {             
            this._calculateDesiredSizeonSizeToParent( width , height);                                      
        } 
        else if ( this._sizeToContent && this.get_hasContent() ) 
        {  
             var childSize = this._content.get_desiredSize (); 
             this._desiredSize.Width = childSize.Width + this._checkOffsetLeft ; 
             this._desiredSize.Height = childSize.Height ;               
        } 
        else 
        {         
            this._desiredSize.Width  = this.get_width () ; 
            this._desiredSize.Height  = this.get_height () ;             
        }        
        
        // We measure content becasue we will try to arrange it .. 
        // It is RISKY to measure with new  desiredSize... ..
        // 
        if ( this._content != null && !this._sizeToContent ) 
        { 
            this._content.measure ( this._desiredSize.Width, this._desiredSize.Height );  
        } 
        this._isMeasureInvalidated = false ;                
    }, 
    
     arrange : function (left, top, width, height ) 
    {            
        var moved =   (  this._visualElement["Canvas.Left"]   != left || this._visualElement["Canvas.Top"] != top ) ; 
        var sized =  ( this._visualElement["width"] != width  || this._visualElement["height"] != height  ); 
        
        
         Sys.Debug.assert ( sized == false || SLx.Warning.ArrangeResizes , "Does this imply a relationship is missing?" ); 
         if ( this._isArrangeInvalidated  || sized || moved )            
         {            
            SLx.CheckBox.callBaseMethod ( this , "arrange" , [left, top, width, height]  ) ;
                                
            SLx.VisualTreeHelper.arrangeContent  ( this._content , this ) ;            
            this._isArrangeInvalidated = false ;                 
        }
        else 
        { 
            Sys.Debug.trace ( this.toString() + " cached arrange" ); 
        }           
    },
    
       
    
    toString : function  () 
    { 
        return this._uniqueSystemId.toString ()  + "    " + Object.getTypeName(this) + "    " + this._id ; 
    }           
}  


SLx.CheckBox.DefaultTemplate =  [ 
{name : "CheckBox"       , ref : "_visualElement", type : "element" },
{name : "PART_Content"   , ref : "_content", type : "ContentPresenter" }
]; 


SLx.CheckBox.registerClass('SLx.CheckBox', SLx.ToggleButton ); 
