﻿/*!
 * Ext JS Library 3.1.0
 * Copyright(c) 2006-2009 Ext JS, LLC
 * licensing@extjs.com
 * http://www.extjs.com/license
 */

Ext.ns('Ext.ux.grid');

Ext.ux.grid.LockingColumnModel = Ext.extend(Ext.grid.ColumnModel, {
	isLocked : function(colIndex){
		return this.config[colIndex].locked === true;
	},
	setLocked : function(colIndex, value, suppressEvent){
		if(this.isLocked(colIndex) == value){
			return;
		}
		this.config[colIndex].locked = value;
		if(!suppressEvent){
			this.fireEvent('columnlockchange', this, colIndex, value);
		}
	},
	getTotalLockedWidth : function(){
		var totalWidth = 0;
		for(var i = 0, len = this.config.length; i < len; i++){
			if(this.isLocked(i) && !this.isHidden(i)){
				totalWidth += this.getColumnWidth(i);
			}
		}
		return totalWidth;
	},
	getLockedCount : function(){
		for(var i = 0, len = this.config.length; i < len; i++){
			if(!this.isLocked(i)){
				return i;
			}
		}
	},
	moveColumn : function(oldIndex, newIndex){
		if(oldIndex < newIndex && this.isLocked(oldIndex) && !this.isLocked(newIndex)){
			this.setLocked(oldIndex, false, true);
		}else if(oldIndex > newIndex && !this.isLocked(oldIndex) && this.isLocked(newIndex)){
			this.setLocked(oldIndex, true, true);
		}
		Ext.ux.grid.LockingColumnModel.superclass.moveColumn.apply(this, arguments);
	}
});