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 jm...@apache.org on 2007/04/06 08:54:12 UTC
svn commit: r526107 - in /incubator/xap/trunk:
codebase/src/xap/bridges/dojo/WindowBridge.js
codebase/src/xap/widgets/dojo/Window.js
samples/WebContent/examples/widgets/window.xal
Author: jmargaris
Date: Fri Apr 6 01:54:11 2007
New Revision: 526107
URL: http://svn.apache.org/viewvc?view=rev&rev=526107
Log:
bunch of cleanup for dojo .4 upgrade issues
Modified:
incubator/xap/trunk/codebase/src/xap/bridges/dojo/WindowBridge.js
incubator/xap/trunk/codebase/src/xap/widgets/dojo/Window.js
incubator/xap/trunk/samples/WebContent/examples/widgets/window.xal
Modified: incubator/xap/trunk/codebase/src/xap/bridges/dojo/WindowBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/bridges/dojo/WindowBridge.js?view=diff&rev=526107&r1=526106&r2=526107
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/bridges/dojo/WindowBridge.js (original)
+++ incubator/xap/trunk/codebase/src/xap/bridges/dojo/WindowBridge.js Fri Apr 6 01:54:11 2007
@@ -55,15 +55,7 @@
xap.bridges.dojo.WindowBridge.superclass.init.call(this);
var peer = this.getPeer() ;
-
- if(!peer.previous){
- peer.previous = new Object() ;
- }
-
- peer.resizeTo(200,200) ;
-
-
-
+
dojo.event.connect(peer,"maximizeWindow",this,"onMaximize");
dojo.event.connect(peer,"minimizeWindow",this,"onMinimize");
dojo.event.connect(peer,"closeWindow",this,"onClose");
@@ -74,21 +66,17 @@
dojo.event.connectBefore(peer,"closeWindow",this,"onClosing");
dojo.event.connectBefore(peer,"restoreWindow",this,"onRestoring");
+ //TODO move this to peer?
dojo.event.connectBefore(peer.titleBar,"ondblclick",this,"toggleMaximized");
- // (on start-up, set[Min|Max]imizedAttribute() gets
- // called if either of those attributes are set to
- // true, but neither works at that time, so do it by hand:)
- // Set max xor min, if desired, as early as possible:
+ //during the initialization process setting min/max
+ //and w/h doesn't work so well so set them again here.
if( this.getElement().getAttribute('minimized') == 'true'){
this.setMinimizedAttribute('true') ;
} else if( this.getElement().getAttribute('maximized') == 'true'){
- if( this.getPeer().windowState == 'minimized'){
- this.wasMaximisedFromMinimized = true ;
- }
this.setMaximizedAttribute('true') ;
}
@@ -97,30 +85,11 @@
// enforce it as late as possible:
var h = this.getElement().getAttribute("height") ;
var w = this.getElement().getAttribute("width") ;
-
- var defaultSize = "100px" ;
-
- // Find the "natural" width:
- if( (!w || w=="" ||w=="null") && peer && peer.titleBarText ){
- peer.titleBarText.innerHTML = peer.title ;
- w = peer.titleBarText.clientWidth ;
- }
-
-
- 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== ""){
- h = defaultSize ;
- }
-
- this.setHeightAttribute(h) ;
- this.setWidthAttribute(w) ;
+ h = h || "100px";
+ w = w || "200px";
+ peer.setWidth(w);
+ peer.setHeight(h);
if( this.isCentered() ){
// does nothing until body grows larger than [0,0] in extent:
@@ -129,6 +98,10 @@
}
+xap.bridges.dojo.WindowBridge.prototype.getPeerString = function(){
+ return "Window" ;
+}
+
//use only in a separate thread, since if the body never gets
// big enough....:
xap.bridges.dojo.WindowBridge.prototype.delayedCenter = function(){
@@ -139,11 +112,6 @@
this.center() ;
}
-
-xap.bridges.dojo.WindowBridge.prototype.getPeerString = function(){
- return "Window" ;
-}
-
/**
*
@@ -190,19 +158,6 @@
xap.bridges.dojo.WindowBridge.superclass.mapAllowedInitialPropertiesFromXalToDojo.call(this, propertyMap, attrHolder);
}
-xap.bridges.dojo.WindowBridge.prototype.addChild = function(childHandler, index){
- this.getPeer().containerNode.parentNode.removeChild(this.getPeer().containerNode);
- this.getPeer().domNode.appendChild(childHandler.getRootDomNode());
- this.getPeer().containerNode = childHandler.getRootDomNode();
- this.getPeer()._childPeer = childHandler.getPeer();
-
- //IMPORTANT remove this later, workaround only
- childHandler.getRootDomNode().style.overflow = "hidden";
-
- //with this set to hidden the shadow won't appear,
- //but if set to visible the contentArea sizing is messed up
- this.getPeer().domNode.style.overflow = "hidden";
-}
@@ -229,6 +184,7 @@
if (!xap.util.Event.getPreventDefault(evt)){
this.fireEvent("onClose");
}
+ this.getElement().parentNode.removeChild(this.getElement());
}
xap.bridges.dojo.WindowBridge.prototype.onRestore = function( evt ){
@@ -265,22 +221,21 @@
}
}
-
+/**
+ *
+ * setXxxAttribute
+ *
+ *
+ */
/** XML attribute set method for "maximized" */
xap.bridges.dojo.WindowBridge.prototype.setMaximizedAttribute = function(value){
if( value == 'true'){
- if( this.getPeer().windowState == 'minimized'){
- this.wasMaximisedFromMinimized = true ;
- }
- if (this.getElement().getAttribute('maximizable')
- != 'false'
- ){
+ if (this.getElement().getAttribute('maximizable')!= 'false'){
this.getPeer().maximizeWindow({});
- this.writeBackAttribute('minimized','false');
- this.writeBackAttribute('maximized','true');
+ this.writeBackAttribute('minimized','false');
}
- } else {
+ } else if (this.getPeer().windowState == 'maximized'){
this.restoreWindow() ;
}
}
@@ -288,68 +243,43 @@
/** XML attribute set method for "minimized" */
xap.bridges.dojo.WindowBridge.prototype.setMinimizedAttribute = function(value){
if( value == 'true'){
- if (this.getElement().getAttribute('minimizable')
- != 'false'
- ){
+ if (this.getElement().getAttribute('minimizable')!= 'false'){
this.getPeer().minimizeWindow({});
+ this.writeBackAttribute('maximized','false');
}
- this.writeBackAttribute('minimized','true');
- this.writeBackAttribute('maximized','false');
- } else {
+ } else if (this.getPeer().windowState == 'minimized'){
this.restoreWindow() ;
- }
+ }
}
xap.bridges.dojo.WindowBridge.prototype.toggleMaximized = function(){
if (this.getPeer().windowState != 'maximized'){
- this.setMaximizedAttribute( 'true' ) ;
- this.writeBackAttribute('minimized','false');
- this.writeBackAttribute('maximized','true');
- } else {
+ this.setMaximizedAttribute( 'true' ) ;
+ } else if (this.getPeer().windowState == 'maximized'){
this.restoreWindow() ;
- }
+ }
}
/**
- * "Restore" == go back to last state, which means minimised if
- * that were the state from which we maximised.
+ * Restore always goes back to a non-min/max state.
**/
xap.bridges.dojo.WindowBridge.prototype.restoreWindow = function(){
- if (
- (this.getPeer().windowState == 'maximized')
- && this.wasMaximisedFromMinimized
- ){
- this.wasMaximisedFromMinimized = false ;
- // go back to minimised:
- this.setMinimizedAttribute('true') ;
- } else {
- this.getPeer().restoreWindow({}) ;
- this.writeBackAttribute('minimized','false');
- this.writeBackAttribute('maximized','false');
- }
+ this.getPeer().restoreWindow({}) ;
+ this.writeBackAttribute('minimized','false');
+ this.writeBackAttribute('maximized','false');
}
xap.bridges.dojo.WindowBridge.prototype.setResizableAttribute = function(val){
if( val && val != "false"){
- this.getPeer().enableResizeHandle() ;
- this.writeBackAttribute('resizable','true');
+ this.getPeer().enableResizeHandle() ;
this.resizable='true' ;
} else if (!val || val=="false"){
- this.getPeer().disableResizeHandle() ;
-
- //IMPORTANT why are these being written back? Aren't they jus set already?
- this.writeBackAttribute('resizable','false');
+ this.getPeer().disableResizeHandle() ;
this.resizable='false' ;
}
}
-
-
-xap.bridges.dojo.WindowBridge.prototype.setVisibleAttribute = function( val ){
- this.getPeer().setVisible(! (val=='false') );
-}
-
/** XML attribute set method for "width" */
xap.bridges.dojo.WindowBridge.prototype.setWidthAttribute = function(value){
Modified: incubator/xap/trunk/codebase/src/xap/widgets/dojo/Window.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/codebase/src/xap/widgets/dojo/Window.js?view=diff&rev=526107&r1=526106&r2=526107
==============================================================================
--- incubator/xap/trunk/codebase/src/xap/widgets/dojo/Window.js (original)
+++ incubator/xap/trunk/codebase/src/xap/widgets/dojo/Window.js Fri Apr 6 01:54:11 2007
@@ -38,22 +38,21 @@
*/
xap.widgets.dojo.Window = function(){
dojo.widget.FloatingPane.call(this);
+ this._visible = true;
+ this.previous = {};
+ //hardcode an initial height/width
+
}
dojo.inherits(xap.widgets.dojo.Window,dojo.widget.FloatingPane);
dojo.lang.extend(xap.widgets.dojo.Window, {
widgetType: "Window",
- _visible:true ,
postCreate: function(){
xap.widgets.dojo.Window.superclass.postCreate.call(this);
- this.aquireResizeHandleObject() ;
- this.resizeBar.style.padding="2px" ;
- this.resizeBar.style.borderTop="2px ridge silver" ;
- this.resizeBar.style.borderBottom="2px ridge silver" ;
- this.resizeBar.style.borderLeft="1px ridge silver" ;
- this.resizeBar.style.borderRight="1px ridge silver" ;
-
+ this.containerNode.style.padding = "0px";
+ this.containerNode.style.overflow = "hidden";
+ this.domNode.style.overflow = "hidden";
// Keep icons from leaving trails over the extending title bar:
@@ -62,10 +61,24 @@
// Paranoically sure let us be that the icons are redisplayed:
dojo.event.connect(this.resizeBar._resizeHandle,"endSizing",this,"endResizing");
+ },
+
+
+ onResized: function(){
+ if (this.containerNode.firstChild){
+ dojo.widget.html.layout(this.containerNode,
+ [
+ {domNode: this.containerNode.firstChild, layoutAlign: "client"}
+ ] );
+ }
+ xap.widgets.dojo.Window.superclass.onResized.call(this);
+ },
+
+ addChild:function(child){
+ xap.widgets.dojo.Window.superclass.addChild.call(this,child);
- // Fix the title text DIV's width:
- this.resetTitleTextBox() ;
-
+ //TODO we shouldn't really need to do this
+ child.domNode.style.overflow = "hidden";
},
minimizeWindow:function(evt) {
@@ -97,7 +110,7 @@
this.minimizeAction.style.display="none";
var restoreParent = this.restoreAction.parentNode;
- var nextNode = this.restoreAction.nextSibling ;
+ var nextNode = this.minimizeAction ;
restoreParent.removeChild(this.restoreAction);
restoreParent.insertBefore(this.restoreAction,nextNode);
@@ -107,6 +120,49 @@
this.positionMinimizedWindow() ;
},
+
+
+ maximizeWindow:function(evt){
+ this.containerNode.style.visibility = "visible" ;
+ if (evt && xap.util.Event.getPreventDefault(evt)){
+ return;
+ }
+
+ if (this.windwState == "normal"){
+ this.setPrevious() ;
+ }
+
+ var restoreParent = this.restoreAction.parentNode;
+ restoreParent.removeChild(this.restoreAction);
+ restoreParent.insertBefore(this.restoreAction,this.minimizeAction);
+
+ xap.widgets.dojo.Window.superclass.maximizeWindow.call(this,evt);
+
+ },
+
+ restoreWindow:function(evt){
+ this.containerNode.style.visibility = "visible" ;
+ if (evt && xap.util.Event.getPreventDefault(evt)){
+ return;
+ }
+ this.resizeBar.style.visibility="visible" ;
+
+ var event = evt ;
+ if(!evt){
+ event = {} ;
+ }
+
+ //lie and pretend we were maximized before, need this for
+ //supercllass call to work correctly.
+ this.windowState = "maximized";
+ xap.widgets.dojo.Window.superclass.restoreWindow.call(this,event);
+
+ //hide restore and maybe re-show minimize
+ this.restoreAction.style.display="none";
+ this.minimizeAction.style.display=this.displayMinimizeAction ? "" : "none";
+
+ },
+
//Let's play window-manager:
positionMinimizedWindow:function(){
var parent = this.domNode.parentNode ;
@@ -175,24 +231,6 @@
},
- restoreWindow:function(evt){
- this.containerNode.style.visibility = "visible" ;
- if (evt && xap.util.Event.getPreventDefault(evt)){
- return;
- }
- this.resizeBar.style.visibility="visible" ;
-
- var event = evt ;
- if(!evt){
- event = {} ;
- }
-
- xap.widgets.dojo.Window.superclass.restoreWindow.call(this,event);
-
- this.minimizeAction.style.display=this.displayMinimizeAction ? "" : "none";
-
- },
-
getIconWidth:function(){
if( !this._iconWidth ){
for(var action in this.windowActions ){
@@ -211,7 +249,6 @@
minimizedWindowWidthPx:function(){
-
return this.getIconWidth()*8 ;
},
@@ -222,64 +259,19 @@
- maximizeWindow:function(evt){
- this.containerNode.style.visibility = "visible" ;
- if (evt && xap.util.Event.getPreventDefault(evt)){
- return;
- }
-
- this.setPrevious() ;
- this.resizeBar.style.visibility="visible" ;
-
- var restoreParent = this.restoreAction.parentNode;
- restoreParent.removeChild(this.restoreAction);
- restoreParent.insertBefore(this.restoreAction,this.minimizeAction);
-
- xap.widgets.dojo.Window.superclass.maximizeWindow.call(this,evt);
-
- },
+
closeWindow:function(evt){
if (xap.util.Event.getPreventDefault(evt)){
return;
}
-
- xap.widgets.dojo.Window.superclass.closeWindow.call(this,evt);
+ //do NOT call superclass close window here, when we close the window
+ //the bridge will remove our element, which will do the cleanup
+ //there instead
},
- // copied from Floating Pane
- // This is called when the user adjusts the size of the floating pane
- resizeTo: function(w, h){
- // About 5 icons' width
- w = Math.max(5*this.getIconWidth(),Math.max(this.minimizedWindowWidthPx(),w)) ;
- h = Math.max(2*this.getIconWidth(),Math.max(this.minimizedWindowHeightPx(),h)) ;
-
-// w = Math.max(100,w) ;
-// h = Math.max(30,h) ;
-
- // call the superclass resizeTo
- xap.widgets.dojo.Window.superclass.resizeTo.call(this,w,h);
-
- // Fix the title text DIV's width:
- this.resetTitleTextBox() ;
-
- // let the child node know that we're resizing
- if (this._childPeer && this._childPeer.onResized) {
- this._childPeer.onResized();
- }
- },
- resizeWindow: function(){
- // logic copied from floating pane
- // called from setWidth and setHeight
- dojo.widget.html.layout(this.domNode,
- [
- {domNode: this.titleBar, layoutAlign: "top"},
- {domNode: this.resizeBar, layoutAlign: "bottom"},
- {domNode: this.containerNode, layoutAlign: "client"}
- ] );
- },
@@ -292,46 +284,27 @@
bottom: this.domNode.style.bottom,
right: this.domNode.style.right
};
-
-
-
},
enableResizeHandle: function(){
- this.resizeBar.style.display="";
- if( !this.resizeBar._resizeHandle ){
- var rh = dojo.widget.createWidget("ResizeHandle", {targetElmId: this.widgetId, id:this.widgetId+"_resize"});
- this.resizeBar._resizeHandle = rh ;
- }
- this.resizeBar.appendChild(this.resizeBar._resizeHandle.domNode);
- this.resizeBar.style.visibility="visible" ;
- this.resizeBar.style.display="";
- },
-
-
- disableResizeHandle: function(){
- if(this.resizeBar.firstChild){
- this.resizeBar.removeChild(this.resizeBar.firstChild);
+ if(this.resizeHandle){
+ this.resizeHandle.domNode.style.display="";
}
- },
+ },
- aquireResizeHandleObject: function(){
- // In order to change resizability, and track size changes better
- // we need to be able to grab the resizehandle object
- // associated with the element---and dojo.byId() can't find it
- // even though we get its name right---maybe it doesn't like the ':'
- // In any event, we'll need this functionality in order to be able
- // to change the "resizable" attribute:
- this.disableResizeHandle() ;
- this.enableResizeHandle() ;
- },
-
- windowActions:
- {minimizeAction:null,
- maximizeAction:null,
- restoreAction:null,
- closeAction:null
- } ,
+ disableResizeHandle: function(){
+ if(this.resizeHandle){
+ this.resizeHandle.domNode.style.display="none";
+ }
+ },
+
+
+ windowActions: {
+ minimizeAction:null,
+ maximizeAction:null,
+ restoreAction:null,
+ closeAction:null
+ } ,
redisplayTitlebarIcons: function(){
@@ -368,42 +341,23 @@
},
endResizing: function(){
- //this.resizeTo(this.domNode.clientWidth,this.domNode.clientHeight) ;
this.showTitleBarIcons() ;
},
- setVisible: function(bVisible){
-
- var sAttr = (bVisible)?"visible":"hidden" ;
- for(var action in this.windowActions ){
- (this[action]).style.visibility = sAttr ;
- }
- this.domNode.style.visibility=sAttr ;
- this.containerNode.style.visibility=sAttr ;
- if( this.windowState != "maximized"
- && this.windowState != "minimized"
- ){
- this.resizeBar.style.visibility=sAttr ;
- } else {
- this.resizeBar.style.visibility="hidden" ;
- }
-
- this._visible = bVisible ;
- },
-
+
setHeight: function(val){
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 = Math.max(val,this.minimizedWindowHeightPx()+"px") ;
+ // state. TODO take into account minimum height
+ this.previous.height = parseInt(val);
} else {
// get value in pixels by resizing dom node first:
this.domNode.style.height = val ;
this.resizeTo(this.domNode.clientWidth,Math.max(this.domNode.clientHeight,this.minimizedWindowHeightPx())) ;
- this.resizeWindow() ;
}
},
@@ -411,70 +365,21 @@
if( this.windowState == "maximized"
|| this.windowState == "minimized"
){
- // Do nothing now, but prepare for next
+ // Do nothing now, but prepare for next
// time this window is in a "normal"
- // state:
- this.previous.width = Math.max(val,this.minimizedWindowWidthPx()+"px") ;
+ // state. TODO take into account minimum width
+ this.previous.width = parseInt(val);
} else {
this.domNode.style.width = val ;
this.resizeTo(this.domNode.clientWidth,this.domNode.clientHeight) ;
- this.resizeWindow() ;
}
},
+
+ //TODO changing on fly needs help resizing the title bar??
setTitle:function(val){
- // We need to be able to set the
- // title to the empty string
- // because that's what we do for
- // "removing" the title attribute:
- if( !val && val != ""){
- this.setTitle(this.title) ;
- return ;
- }
- this.titleBarText.innerHTML=val ;
- this.resetTitleTextBox() ;
+ this.titleBarText.innerHTML=val ;
this.title = val ;
- },
- resetTitleTextBox:function(oneLineBoxHeight){
- this.titleBar.style.overflow="hidden" ;
- this.titleBar.style.verticalAlign="middle" ;
- this.titleBarText.style.verticalAlign="middle" ;
- this.titleBarText.style.overflow="hidden" ;
-//For debugging: this.titleBarText.style.backgroundColor = "black" ;
- var titleWidthPx = this.titleBar.offsetWidth ;
- var maxTextWidthPx = this.titleBar.offsetWidth ;
- var iconWidth = this.getIconWidth()
-
- // look at the css file
- //...but to be sure:
- //var iconWidth = 11 ;
- for(var action in this.windowActions ){
- var w = this[action].offsetWidth ;
- if(w){
- maxTextWidthPx -= w ;
- if( !iconWidth ){
- iconWidth = w ;
- }
- }
- }
-
-
- if(iconWidth){
- // Fudge--if this is too wide, makes title bar multi-line:
- maxTextWidthPx -= Math.round(iconWidth/2) ;
- }
- maxTextWidthPx = Math.max(maxTextWidthPx,0) ;
- this.titleBarText.style.width= maxTextWidthPx+"px";
- // This height-setting is necessitated by
- // a bug[?] under IE that echoes the last ~2.2
- // chars on another line below the titleText div,
- // which expands the titlebar text---only happens
- // under IE6:
- // TODO: avoid the echoing in the first place:
- if(navigator.appVersion.indexOf("MSIE 6")>-1){
- this.titleBar.style.height= (w+4) + "px";
- this.titleBarText.style.height = this.titleBar.offsetHeight + "px" ;
- }
- }
+ }
});
Modified: incubator/xap/trunk/samples/WebContent/examples/widgets/window.xal
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/samples/WebContent/examples/widgets/window.xal?view=diff&rev=526107&r1=526106&r2=526107
==============================================================================
--- incubator/xap/trunk/samples/WebContent/examples/widgets/window.xal (original)
+++ incubator/xap/trunk/samples/WebContent/examples/widgets/window.xal Fri Apr 6 01:54:11 2007
@@ -28,9 +28,8 @@
<xm:modifications xmlns:xm="http://openxal.org/core/xmodify">
<xm:append select="/ui">
- <freePane height="100%" width="100%" backgroundColor="rgb(240,240,255)">
- <label text="100px-by-200px" color="white" backgroundColor="black" width="100px" height="200px" />
- <freePane width="600px" height="500px" x="100px" y="200px"
+ <freePane width="600px" height="400px" x="100px" y="200px"
+ borderWidth="2px" borderColor="green" borderStyle="solid"
backgroundColor="rgb(255,240,240)"
>
<xal:window title="testComponent" id="testComponent">
@@ -44,8 +43,8 @@
<xal:window title="No min,max,close or resize" id="noMinMaxCloseResize"
onCreate="mco:attributeSetter.registerElement(this)" x="200px" resizable="false"
- minimizable="false" maximizable="false" closable="false"/>
- <xal:window title="A window" minimized="true" id="aWindow"
+ minimizable="false" height="300px" maximizable="false" closable="false"/>
+ <xal:window title="A window" maximized="true" id="aWindow"
onCreate="mco:attributeSetter.registerElement(this)">
<xal:borderPane backgroundColor="green">
<xal:menuBar borderPosition="north">
@@ -98,7 +97,6 @@
</xal:window>
- </freePane>
</freePane>
<!--standard test things -->