You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xap-commits@incubator.apache.org by mt...@apache.org on 2007/01/06 20:12:18 UTC

svn commit: r493559 - in /incubator/xap/trunk/src/xap: bridges/dojo/WindowBridge.js util/LayoutUtils.js widgets/dojo/Window.js

Author: mturyn
Date: Sat Jan  6 12:12:17 2007
New Revision: 493559

URL: http://svn.apache.org/viewvc?view=rev&rev=493559
Log:
http://issues.apache.org/jira/browse/XAP-221
1.) Implemented "centered" attribute.

http://issues.apache.org/jira/browse/XAP-87
http://issues.apache.org/jira/browse/XAP-186
2.) Fixed height/width setting issues---an earlier fix was injuring "start minimised", as it created "minimised" 
windows the size of non-minimised ones.  Also, fixed setting so that changing the dimension of
a minimised or maximised window will now not change its current value, but should change
the dimension when the window is restored (by altering the "previous" struct, so that the restore will
see the new values).

Added:
    incubator/xap/trunk/src/xap/util/LayoutUtils.js
Modified:
    incubator/xap/trunk/src/xap/bridges/dojo/WindowBridge.js
    incubator/xap/trunk/src/xap/widgets/dojo/Window.js

Modified: incubator/xap/trunk/src/xap/bridges/dojo/WindowBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/dojo/WindowBridge.js?view=diff&rev=493559&r1=493558&r2=493559
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/dojo/WindowBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/dojo/WindowBridge.js Sat Jan  6 12:12:17 2007
@@ -28,6 +28,8 @@
 Xap.require("xap.util.Event");
 Xap.require('xap.bridges.dojo.DojoWidgetBridge');
 Xap.require("xap.xml.XmlTokens") ;
+Xap.require("xap.util.LayoutUtils") ;
+
 
  /**
  * @fileoverview
@@ -51,12 +53,13 @@
 	this.superclass.init.call(this);
 	
 	var peer = this.getPeer() ;
-	
-	
-	peer.resizeTo(200,200) ;
 	if( !peer.previous ){
 		peer.previous = {} ;
-	}
+	}	
+
+	peer.resizeTo(200,200) ;
+
+
 
 	dojo.event.connect(peer,"maximizeWindow",this,"onMaximize");
 	dojo.event.connect(peer,"minimizeWindow",this,"onMinimize");
@@ -73,33 +76,42 @@
 
 
 
-	
+	// (on start-up, set[Min|Max]imizedAttribute() gets
+	// called if either of those attributes are set to
+	// xap.xml.XmlTokens.TRUE, but neither works at that time, so do it by hand:)	
 	// Set max xor min, if desired, as early as possible:
-	if( this.getElement().getAttribute(xap.xml.XmlTokens.MINIMIZED) == "true"){
+	if( this.getElement().getAttribute(xap.xml.XmlTokens.MINIMIZED) == xap.xml.XmlTokens.TRUE){
 		this.setMinimizedAttribute(xap.xml.XmlTokens.TRUE) ;
-	} else if( this.getElement().getAttribute(xap.xml.XmlTokens.MAXIMIZED) == "true"){
+	} else if( this.getElement().getAttribute(xap.xml.XmlTokens.MAXIMIZED) == xap.xml.XmlTokens.TRUE){
 		if( this.getPeer().windowState == xap.xml.XmlTokens.MINIMIZED){
 			this.wasMaximisedFromMinimized = true ;
 		}	
 		this.setMaximizedAttribute(xap.xml.XmlTokens.TRUE) ;
 	} 
-	// (on start-up, set[Min|Max]imizedAttribute() gets
-	// called if either of those attributes are set to
-	// "true", but neither works.)
-	
+
 	// Yet another place where an attribute
 	// doesn't change the start-up DOM unless we
 	// enforce it as late as possible:
 	var h = this.getElement().getAttribute("height") ;
 	var w = this.getElement().getAttribute("width") ;
+
+	var defaultSize = "100px" ;
+
+	if( !w || w== ""){
+		// For lack of anything better---at
+		// least you can fit the sizing icons 
+		// in the title-bar this way:
+		w = defaultSize ;
+	}
 	
-	if( h && h!= ""){
-		this.setHeightAttribute(h) ;
+	if( !h || h== ""){
+		h = defaultSize ;
 	}
-	if( w && w!= ""){
-		this.setWidthAttribute(w) ;
-	}	
+		
 	
+	this.setHeightAttribute(h) ;	
+	this.setWidthAttribute(w) ;		
+
 }
 
 xap.bridges.dojo.WindowBridge.prototype.getPeerString = function(){
@@ -116,7 +128,7 @@
  
 
 xap.bridges.dojo.WindowBridge.prototype.getNewAllowedAttributes = function(){
-	return ["maximized","minimized","resizable"];
+	return ["maximized","minimized","resizable","centered"];
 }	
 
 
@@ -227,15 +239,6 @@
 	}
 }
 
-/** XML attribute set method for "width" */
-xap.bridges.dojo.WindowBridge.prototype.setWidthAttribute = function(value){
-	this.getPeer().setWidth(value) ;
-}
-
-/** XML attribute set method for "height" */
-xap.bridges.dojo.WindowBridge.prototype.setHeightAttribute = function(value){
-	this.getPeer().setHeight(value) ;
-}
 
 
 /** XML attribute set method for "maximized" */
@@ -319,6 +322,59 @@
 
 xap.bridges.dojo.WindowBridge.prototype.setVisibleAttribute = function( val ){
 	this.getPeer().setVisible(! (val==xap.xml.XmlTokens.FALSE) );	
+}
+
+
+/** XML attribute set method for "width" */
+xap.bridges.dojo.WindowBridge.prototype.setWidthAttribute = function(value){
+	this.getPeer().setWidth(value) ;
+	if( this.isCentered() ){
+		this.center() ;
+	}
+}
+
+/** XML attribute set method for "height" */
+xap.bridges.dojo.WindowBridge.prototype.setHeightAttribute = function(value){
+	this.getPeer().setHeight(value) ;
+	if( this.isCentered() ){
+		this.center() ;
+	}		
+}
+
+/** XML attribute set method for "height" */
+xap.bridges.dojo.WindowBridge.prototype.setXAttribute = function(value){
+	if( !this.isCentered() ){
+		xap.bridges.dojo.DojoWidgetBridge.prototype.setXAttribute.call(this,value) ;
+	}
+}
+
+xap.bridges.dojo.WindowBridge.prototype.setCenteredAttribute = function( val ){
+	if( val == xap.xml.XmlTokens.TRUE ){
+		this.center() ;
+	} else {
+		// use whatever explicit x/y we might have:
+		var x = this.getElement().getAttribute("x") ;
+		var y = this.getElement().getAttribute("y") ;
+		
+		if( x && x!= "" && x!= "null"){
+			this.setXAttribute(x) ;
+		}
+		if( y && y!= "" && y!= "null"){
+			this.setYAttribute(y) ;
+		}				
+	}
+}
+
+
+xap.bridges.dojo.WindowBridge.prototype.center = function(){
+		var node = this.getRootDomNode() ;
+		// if the parent is null, will use the body:
+		xap.util.LayoutUtils.centerWithin(node, node.parentNode) ;
+}
+
+
+xap.bridges.dojo.WindowBridge.prototype.isCentered = function(){
+	return this.getElement().getAttribute("centered") == xap.xml.XmlTokens.TRUE ;
 }
 
 

Added: incubator/xap/trunk/src/xap/util/LayoutUtils.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/util/LayoutUtils.js?view=auto&rev=493559
==============================================================================
--- incubator/xap/trunk/src/xap/util/LayoutUtils.js (added)
+++ incubator/xap/trunk/src/xap/util/LayoutUtils.js Sat Jan  6 12:12:17 2007
@@ -0,0 +1,79 @@
+/*
+ * Copyright  2007 The Apache Software Foundation.
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+ 
+Xap.provide("xap.util.LayoutUtils");
+//dojo.require("dojo.widget.*");
+//dojo.require("dojo.dom");
+//dojo.require("dojo.html");
+dojo.require("dojo.style");
+//dojo.require("dojo.event");
+//TODO like many classes exception handling here needs to be
+//more thought out.
+
+/**
+ * @fileoverview A class that helps add some functionality to working 
+ * with node and window layout.
+ *
+ * @author mturyn
+ */
+ 
+/**
+ * There is no need to ever construct a LayoutUtils object
+ * at this time, just use the static methods.
+ * 
+ * @class LayoutUtils provides methods to implement some common
+ * functions needed to handle node layout. (At least in some JS versions)
+ * This can probably mostly be implemented using dojo.style calls.
+ * 
+ * @constructor
+ */
+xap.util.LayoutUtils = function(){}
+
+/**
+ * Centers a node within a given other node; or the document body.
+ * Note that no guaranties of relative size are given; the node to be 
+ * centered might be larger than the frame---but it's the one that
+ * may have its style changed.
+ * @param nodeToCenter{XNode} the node to be centered
+ * @param frameNode{XNode} the node within which to center, or the 
+ * document body if absent or null.
+ *
+**/
+xap.util.LayoutUtils.centerWithin = function(nodeToCenter,frameNode){
+	var theFrame = document.body ;
+	if( frameNode ){
+		theFrame = frameNode ;
+	}
+	
+	var frameTop = theFrame.offsetTop ;
+	var frameLeft = theFrame.offsetLeft ;
+	var frameWidth = theFrame.offsetWidth ;
+	var frameHeight = theFrame.offsetHeight ;
+	
+	
+	var nodeTop = nodeToCenter.offsetTop ;
+	var nodeLeft = nodeToCenter.offsetLeft ;
+	var nodeWidth = nodeToCenter.offsetWidth ;
+	var nodeHeight = nodeToCenter.offsetHeight ;	
+	
+	var oldPosition = nodeToCenter.style.position ;
+	nodeToCenter.style.position = "absolute" ;
+
+	nodeToCenter.style.top = (frameTop + Math.round((frameHeight-nodeHeight)/2))+"px" ;
+	nodeToCenter.style.left = (frameLeft + Math.round((frameWidth-nodeWidth)/2))+"px" ;
+	nodeToCenter.style.position = oldPosition ;
+}

Modified: incubator/xap/trunk/src/xap/widgets/dojo/Window.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/widgets/dojo/Window.js?view=diff&rev=493559&r1=493558&r2=493559
==============================================================================
--- incubator/xap/trunk/src/xap/widgets/dojo/Window.js (original)
+++ incubator/xap/trunk/src/xap/widgets/dojo/Window.js Sat Jan  6 12:12:17 2007
@@ -226,16 +226,34 @@
 	},
 	
 	setHeight: function(val){
-	// get value in pixels by resizing dom node first:
-		this.domNode.style.height = val ;
-		this.resizeTo(this.domNode.clientWidth,this.domNode.clientHeight) ;	
-		this.resizeWindow() ;
+		if( this.windowState == "maximized" 
+			 || this.windowState == "minimized"
+			){
+			// Do nothing now, but prepare for next
+			// time this window is in a "normal"
+			// state:
+			this.previous.height = val ;			
+		} else {
+			// get value in pixels by resizing dom node first:
+			this.domNode.style.height = val ;
+			this.resizeTo(this.domNode.clientWidth,this.domNode.clientHeight) ;	
+			this.resizeWindow() ;
+		}
 	},
 	
 	setWidth: function(val){
-		this.domNode.style.width = val ;
-		this.resizeTo(this.domNode.clientWidth,this.domNode.clientHeight) ;		
-		this.resizeWindow() ;
+		if( this.windowState == "maximized" 
+			 || this.windowState == "minimized"
+			){
+			// Do nothing now, but prepare for next
+			// time this window is in a "normal"
+			// state:
+			this.previous.width = val ;			
+		} else {	
+			this.domNode.style.width = val ;
+			this.resizeTo(this.domNode.clientWidth,this.domNode.clientHeight) ;		
+			this.resizeWindow() ;
+		}
 	}
 });