incubator-xap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mtu...@apache.org
Subject svn commit: r547656 - /incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js
Date Fri, 15 Jun 2007 12:41:22 GMT
Author: mturyn
Date: Fri Jun 15 05:41:21 2007
New Revision: 547656

URL: http://svn.apache.org/viewvc?view=rev&rev=547656
Log:
some fixes.  a timeout was added for _fixColumnwidths... we should look into removing

Modified:
    incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js

Modified: incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js?view=diff&rev=547656&r1=547655&r2=547656
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js (original)
+++ incubator/xap/trunk/codebase/src/xap/widgets/dojo/TreeTable.js Fri Jun 15 05:41:21 2007
@@ -17,6 +17,8 @@
  *
  */
  
+ // MMs latest.
+ // + gates against null nodes
 
 
 Xap.provide("xap.widgets.dojo.TreeTable");
@@ -137,141 +139,149 @@
 	 * After a table has been built to the screen go through and make sure
 	 * the widths of columns and headers match up.
 	 */
-	_resizeTable: function(){
+	_resizeTable: function() {
+	
+		// Need to do this manually for IE.
+		// TODO: Figure out why this is so.
+		var naturalWidthPx = 0 ; 
+	
+		// clear timeout as soon as we get here
+		window.clearTimeout(this._resizeTableTask);
+		this._resizeTableTask = null;
 	
-		var tableWidth = 0;
-		
 		//don't user tbody.childNodes[0] here because in the case
 		//where we need to fix up IE we want to fixup and THEN remove
 		//and re-add rows in the new order.
-		var firstRow = this._rows.length>0?this._rows[0].domNode:null;
+		var firstRow = (this._rows.length > 0) ? this._rows[0].domNode : null;
 
-		// Spacing gets screwed-up under IE if the first row isn't complete,
-		// so complete it if need be:
-		var len = -1 ;
-		if( dojo.render.html.ie
-				&& firstRow 
-				&& this._columns 
-				&& (len=this._columns.length)>1
-			){
-			while(firstRow.childNodes.length<len){
-				var filler = document.createElement("td");
-				filler.style.backgroundColor = "transparent" ;
-				firstRow.appendChild(filler) ;
+		for (var i = 0; i < this._columns.length; i++) {
+			
+			// not set any width
+			var width = 0;
+			
+			/* if the user explicitly set, we use those */
+			if ( this._columns[i]._headerWidth ) {
+				var setHeaderWidth = this._getSizeFromString (this._columns[i]._headerWidth);
+				if(setHeaderWidth) { width = setHeaderWidth; }
+			} 
+			// get maximum value
+			if( this._columns[i]._sStatedWidth) {
+				var setColumnWidth = this._getSizeFromString (this._columns[i]._sStatedWidth);
+				if(setColumnWidth) { width = Math.max(width, setColumnWidth); }
 			}
-		}
-
-		var tableWidth = 0;
-		// No need to test for these each iteration:
-		var hasHeaders = this.headerRow && this.headerRow.childNodes ;
-		var hasFirstRow = firstRow && firstRow.childNodes ;	
-		var hasHeaderTable = this.headerTable && this.headerTable.childNodes ;
-		var hasBodyTable = this.table && this.table.childNodes ;		
-		
-		for (var i=0; i<this._columns.length;i++){
-					
-			var headerWidth = 0;
-			var columnWidth  = 0;
-			var setWidth = 0;
-			var node = null ;
+						
 			//In IE get/set of column width dynamically doesn't seem to work 
 			//too well so use first row instead
 			if (dojo.render.html.ie){
-				if( hasHeaders && (node = this.headerRow.childNodes[i])){
-					headerWidth = node.offsetWidth ;				
+				if(width === 0 
+					&& this.headerRow
+					&& this.headerRow.childNodes[i]					
+					) {
+					width = this.headerRow.childNodes[i].offsetWidth;
+				}
+				if (firstRow && firstRow.childNodes[i]) {
+					firstRow.childNodes[i].style.width = width + 'px';
 				}
-				node = null ;
-				if ( hasFirstRow && (node = firstRow.childNodes[i]) ){
-					columnWidth = node.offsetWidth ;
+			} else {
+				if(width === 0
+					&& this.headerTable				
+					&& this.headerTable.childNodes[i]				
+				) {
+					width = this.headerTable.childNodes[i].offsetWidth;
 				}
+				this.table.childNodes[i].style.width = width + 'px';
 			}
-			else{
-				if( hasHeaderTable
-						&& (node = this.headerTable.childNodes[i])
-						){			
-					headerWidth 
-						= node.offsetWidth ;
-				}
-				node=null;
-				if( hasBodyTable
-					&& (node = this.table.childNodes[i])){
-					columnWidth 
-						= node.offsetWidth ;				
+			
+			// save final width
+			this._columns[i]._calculatedWidth = width;
+
+			naturalWidthPx += width ;
+
+		} // end for(...)
+		
+		// Unset-width tables' widths are screwed up under IE:
+		if( dojo.render.html.ie 
+			&& (typeof this._resetWidth == "undefined")
+		 ){
+			dojo.html.setContentBox(this.domNode,{width:naturalWidthPx+25}) ;					
+		 	this.scrollDiv.style.width="100%" ;	
+		 	if(typeof this._resetHeight == "undefined"){
+				this.domNode.style.height
+					= this.table.offsetHeight 
+						+this.headerTable.offsetHeight + 25 +"px" ;
+		 		this.scrollDiv.style.height = "100%" ;
+		 	}		
+		}	
+
+		// delay call to _fixColumnWidths
+		dojo.lang.setTimeout(this, this._fixColumnWidths, 1000);
+	},
+	
+	_fixColumnWidths : function(){
+		var tableWidth = 0;
+		var firstRow = (this._rows.length > 0) ? this._rows[0].domNode : null;
+		for (var i = 0; i< this._columns.length; i++) {
+		
+			// this is header width
+			var calculatedWidth = this._columns[i]._calculatedWidth;
+			var contentWidth = 0;
+			
+			if (dojo.render.html.ie){
+				
+				if( firstRow && firstRow.childNodes[i]){
+					contentWidth = firstRow.childNodes[i].offsetWidth;
+				}
+				if(contentWidth > calculatedWidth) { 
+					calculatedWidth = contentWidth; 
+				}
+				if( this.headerRow && this.headerRow.childNodes[i]){
+					dojo.html.setMarginBox( this.headerRow.childNodes[i], {width: calculatedWidth} ) ;
+				}
+				if (firstRow && firstRow.childNodes[i]){
+					dojo.html.setMarginBox( firstRow.childNodes[i], {width: calculatedWidth} ) ;
+				}
+			} else {
+				if( this.table
+					&& this.table.childNodes[i]
+					){
+					contentWidth =  this.table.childNodes[i].offsetWidth;
+				}
+				if(contentWidth > calculatedWidth){
+					calculatedWidth = contentWidth;
+				}
+				
+				if( this.headerTable
+					&& this.headerTable.childNodes[i]
+				){
+					this.headerTable.childNodes[i].style.width = calculatedWidth + 'px';
+				}
+				if( this.table
+					&& this.table.childNodes[i]
+				){				
+					this.table.childNodes[i].style.width = calculatedWidth + 'px';
 				}
 			}
 			
-			/* if the user explicitly set the column width or
-			   its header's width , we use those (preferring
-			   as usual the last value parsed, that is, 
-			   the header's):
-			*/
-
-			var setWidth = this._columns[i].getBestWidth() ;
-		
-			// We want to set the column width to the explicitly-given value
-			// if it should be available from the column or its header); if
-			// a value is not available so, we'll use the greater of the 
-			// extant cell or column widths.  Note that we need to look
-			// up the explicitly-set ones in case the table is hidden when created
-			var preferredColumnWidth = setWidth ;
-			if( !setWidth ){
-				preferredColumnWidth = headerWidth>columnWidth ? headerWidth:columnWidth;	
-				preferredColumnWidth += "px" ;
+			// MM: not sure if we need that 
+			if (
+				this.headerRow
+				&& this.headerRow.childNodes[i]
+				&& this.headerRow.childNodes[i].childNodes[0]			
+				) {
+				this.headerRow.childNodes[i].childNodes[0].style.width  = "100%";
 			}
-			var preferredColumnWidthPx = parseInt(preferredColumnWidth) ;
-			this._columns[i].setStatedWidth(preferredColumnWidth) ;
-			if(this.columnsSizer 
-				&& this.columnsSizer.children
-					&& this.columnsSizer.children[i]
-				){
-				this.columnsSizer.children[i].sizeShare = preferredColumnWidthPx ;
-			}	
-			tableWidth += preferredColumnWidthPx ;
+			tableWidth += calculatedWidth;
 		}
-		
 		//if we don't fix the width here then when we want the table
 		//to scroll horizontally it doesn't work very well, sizes
 		//too small
-
-		this.headerTable.style.tableLayout = "auto";
-		this.table.style.tableLayout = "auto";	
-
-
 		this.table.style.width = tableWidth + "px";
 		this.headerTable.style.width = tableWidth + "px";
 		
-		
-		this._fixColumnWidths();
 		this.headerTable.style.tableLayout = "fixed";
-		this.table.style.tableLayout = "fixed";		
-				
-		window.clearTimeout(this._resizeTableTask);
-		this._resizeTableTask = null;
+		this.table.style.tableLayout = "fixed";	
 	},
 	
-	_fixColumnWidths: function(){
-		var firstRow = this._rows.length>0?this._rows[0].domNode:null;
-var arr = new Array(0) ;		
-		for (var i=0; i<this._columns.length;i++){
-			// Note: ends with "px":
-			var width = this._columns[i].getBestWidth();
-			// These next two originally were just called under IE,
-			// and the columns set under Firefox.  The columns came
-			// out better under IE than under Firefox, so we switched 
-			// to the IE way:					
-			if( this.headerRow && this.headerRow.childNodes[i]){
-				dojo.html.setMarginBox( this.headerRow.childNodes[i],
-										{width: parseInt(width)} 
-										) ;
-			}
-			if (firstRow && firstRow.childNodes[i]){
-				dojo.html.setMarginBox( firstRow.childNodes[i],
-					{width: parseInt(width)} ) ;					
-			}
-			if (this.headerRow.childNodes[i] && this.headerRow.childNodes[i].childNodes[0])
-				this.headerRow.childNodes[i].childNodes[0].style.width  = '100%';
-		}	
-	},
 	
 	/**
 	 * Rebuilds just the real table part of table, not
@@ -462,13 +472,19 @@
 	* Support for dynamic sizing 
 	*/	
 	setHeight:function(value){
-		if (this.domNode) this.domNode.style.height = value;
+		if (this.domNode){
+			this.domNode.style.height = value ;
+			this._resetHeight = value ;
+		}
 		this.onResized();
 	},
 	
 
 	setWidth:function(value){
-		if (this.domNode) this.domNode.style.width = value;
+		if (this.domNode){
+			this.domNode.style.width = value;
+			this._resetWidth = value ;
+		}
 //		this.onResized();
 	},
 	



Mime
View raw message