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 2006/11/03 17:39:07 UTC
svn commit: r470921 - in /incubator/xap/trunk/src/xap/bridges/dojo:
MenuBarBridge.js MenuBarItemBridge.js MenuBridge.js MenuItemBridge.js
Author: mturyn
Date: Fri Nov 3 09:39:06 2006
New Revision: 470921
URL: http://svn.apache.org/viewvc?view=rev&rev=470921
Log:
(For Y.Wang)
Menu bar, menu bar item, menuItem changes
https://issues.apache.org/jira/secure/ManageAttachments.jspa?id=12354704
Modified:
incubator/xap/trunk/src/xap/bridges/dojo/MenuBarBridge.js
incubator/xap/trunk/src/xap/bridges/dojo/MenuBarItemBridge.js
incubator/xap/trunk/src/xap/bridges/dojo/MenuBridge.js
incubator/xap/trunk/src/xap/bridges/dojo/MenuItemBridge.js
Modified: incubator/xap/trunk/src/xap/bridges/dojo/MenuBarBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/dojo/MenuBarBridge.js?view=diff&rev=470921&r1=470920&r2=470921
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/dojo/MenuBarBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/dojo/MenuBarBridge.js Fri Nov 3 09:39:06 2006
@@ -25,8 +25,7 @@
Xap.require("dojo.widget.Menu2");
Xap.require("xap.session.ClientEvent");
-Xap.require('xap.bridges.dojo.DojoWidgetBridge');
-
+
/**
* @fileoverview
*
@@ -35,25 +34,48 @@
xap.bridges.dojo.MenuBarBridge= function() {
xap.bridges.dojo.DojoWidgetBridge.call(this);
+ dojo.widget.MenuBar2.prototype.disabled = false;
}
-
Xap.setupClassAsSubclassOf(
"xap.bridges.dojo.MenuBarBridge",
"xap.bridges.dojo.DojoWidgetBridge"
);
-
-
xap.bridges.dojo.MenuBarBridge.prototype.init = function() {
- this.superclass.init.call(this);
+ xap.bridges.dojo.DojoWidgetBridge.prototype.init.call(this);
}
xap.bridges.dojo.MenuBarBridge.prototype.getPeerString = function(){
return "MenuBar2" ;
}
-
+dojo.widget.MenuBar2.prototype.enabled = true;
+dojo.widget.MenuBar2.prototype.height = null;
+
+dojo.widget.MenuBar2.prototype.itemHover = function(item) {
+ if (!this.enabled) {
+ return;
+ }
+
+ if (item == this.currentItem) return;
+
+ if (this.currentItem){
+ this.currentItem.unhighlightItem();
+
+ if (this.isExpanded){
+ this.closeSubmenu();
+ }
+ }
+
+ this.currentItem = item;
+ this.currentItem.highlightItem();
+
+ if (this.isExpanded){
+ this.currentItem.expandMenu();
+ }
+}
+
/**
*
*
@@ -66,7 +88,161 @@
* No new dynamic attributes
*/
xap.bridges.dojo.MenuBarBridge.prototype.getNewAllowedAttributes = function(){
- return [];
-}
+ return ["enabled", "pack"];
+}
+
+xap.bridges.dojo.MenuBarBridge.prototype.setEnabledAttribute = function(value) {
+ var peer = this.getPeer();
+ peer.enabled = value == "true" ? true : false;
+ var children = peer.children;
+
+ for (var i = 0; i < children.length; i++) {
+ var handler = this.getUiContentHandler().getHandlerForPeer(children[i]);
+ handler._enable();
+ }
+}
+
+/** XML attribute set method for "borderWidth" */
+xap.bridges.dojo.MenuBarBridge.prototype.setBorderWidthAttribute = function(value) {
+ this._showBorder(value, null, null);
+}
+
+/** XML attribute set method for "borderStyle" */
+xap.bridges.dojo.MenuBarBridge.prototype.setBorderStyleAttribute = function(value) {
+ this._showBorder(null, value, null);
+}
+
+/** XML attribute set method for "borderColor" */
+xap.bridges.dojo.MenuBarBridge.prototype.setBorderColorAttribute = function(value) {
+ this._showBorder(null, null, value);
+}
+
+xap.bridges.dojo.MenuBarBridge.prototype._showBorder = function(borderWidth, borderStyle, borderColor) {
+ var domNode = this.getRootDomNode();
+
+ domNode.style.borderWidth = borderWidth == null ? domNode.style.borderWidth : borderWidth;
+ domNode.style.borderStyle = borderStyle == null ? domNode.style.borderStyle : borderStyle;
+ domNode.style.borderColor = borderColor == null ? domNode.style.borderColor : borderColor;
+
+ if (domNode.style.borderWidth == null || domNode.style.borderWidth == "") {
+ domNode.style.borderWidth = "1px";
+ }
+ if (domNode.style.borderStyle == null || domNode.style.borderStyle == "") {
+ domNode.style.borderStyle = "solid";
+ }
+ if (domNode.style.borderColor == null || domNode.style.borderColor == "") {
+ domNode.style.borderColor = "black";
+ }
+}
+
+xap.bridges.dojo.MenuBarBridge.prototype.setWidthAttribute = function(value) {
+ var domNode = this.getRootDomNode();
+ domNode.style.width = value;
+ // this is necessary, the parent node is a table cell and the default value for aling is "center".
+ domNode.parentNode.align = "left";
+}
+
+/** XML attribute set method for "borderWidth" */
+xap.bridges.dojo.MenuBarBridge.prototype.setColorAttribute = function(value) {
+ this._setAttributeForMenus("Color", value);
+}
+
+/** XML attribute set method for "fontFamily" */
+xap.bridges.dojo.MenuBarBridge.prototype.setFontFamilyAttribute = function(value) {
+ this._setAttributeForMenus("FontFamily", value);
+}
+
+/** XML attribute set method for "fontSize" */
+xap.bridges.dojo.MenuBarBridge.prototype.setFontSizeAttribute = function(value) {
+ this._setAttributeForMenus("FontSize", value);
+}
+
+/** XML attribute set method for "fontStyle" */
+xap.bridges.dojo.MenuBarBridge.prototype.setFontStyleAttribute = function(value) {
+ this._setAttributeForMenus("FontStyle", value);
+}
+
+/** XML attribute set method for "fontWeight" */
+xap.bridges.dojo.MenuBarBridge.prototype.setFontWeightAttribute = function(value) {
+ this._setAttributeForMenus("FontWeight", value);
+}
+
+xap.bridges.dojo.MenuBarBridge.prototype._setAttributeForMenus = function(name, value) {
+ var peer = this.getPeer();
+ var children = peer.children;
+
+ for (var i = 0; i < children.length; i++) {
+ var handler = this.getUiContentHandler().getHandlerForPeer(children[i]);
+ eval("handler.set" + name + "Attribute(\"" + value +"\")");
+ }
+}
+
+xap.bridges.dojo.MenuBarBridge.prototype.setPackAttribute = function(value) {
+ if (value == "true") {
+ this.getPeer().postCreate();
+ }
+}
+
+xap.bridges.dojo.MenuBarBridge.prototype.setHeightAttribute = function(value) {
+ this.getPeer().height = value;
+ this.getRootDomNode().style.height = value;
+}
+
+/**
+ * Layout menu without changing the height of the menubar.
+ */
+dojo.widget.MenuBar2.prototype.layoutMenu2 = function() {
+ // menu must be attached to DOM for size calculations to work
+
+ var parent = this.domNode.parentNode;
+ if (! parent || parent == undefined) {
+ document.body.appendChild(this.domNode);
+ }
+
+
+ // determine menu height
+
+ var max_label_h = 0;
+
+ for(var i=0; i<this.children.length; i++){
+
+ if (this.children[i].getLabelHeight){
+
+ max_label_h = Math.max(max_label_h, this.children[i].getLabelHeight());
+ }
+ }
+
+ if (isNaN(max_label_h)){
+ // Browser needs some more time to calculate sizes
+ this.layoutMenuSoon();
+ return;
+ }
+
+ var clientLeft = dojo.style.getPixelValue(this.domNode, "padding-left", true)
+ + dojo.style.getPixelValue(this.containerNode, "margin-left", true)
+ + dojo.style.getPixelValue(this.containerNode, "padding-left", true);
+ var clientTop = dojo.style.getPixelValue(this.domNode, "padding-top", true)
+ + dojo.style.getPixelValue(this.containerNode, "padding-top", true);
+
+ if (isNaN(clientLeft) || isNaN(clientTop)){
+ // Browser needs some more time to calculate sizes
+ this.layoutMenuSoon();
+ return;
+ }
+
+ var max_item_height = 0;
+ var x = clientLeft;
+
+ for (var i=0; i<this.children.length; i++){
+
+ var ch = this.children[i];
+
+ ch.layoutItem(max_label_h);
+ ch.leftPosition = x;
+ ch.domNode.style.left = x + 'px';
+ x += dojo.style.getOuterWidth(ch.domNode);
+ max_item_height = Math.max(max_item_height, dojo.style.getOuterHeight(ch.domNode));
+ }
+}
\ No newline at end of file
Modified: incubator/xap/trunk/src/xap/bridges/dojo/MenuBarItemBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/dojo/MenuBarItemBridge.js?view=diff&rev=470921&r1=470920&r2=470921
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/dojo/MenuBarItemBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/dojo/MenuBarItemBridge.js Fri Nov 3 09:39:06 2006
@@ -24,8 +24,9 @@
Xap.provide("xap.bridges.dojo.MenuBarItemBridge");
Xap.require("dojo.widget.Menu2");
+Xap.require("dojo.html.*");
Xap.require("xap.session.ClientEvent");
-Xap.require('xap.bridges.dojo.DojoWidgetBridge');
+dojo.require("dojo.style");
/**
* @fileoverview
@@ -43,6 +44,8 @@
"xap.bridges.dojo.DojoWidgetBridge"
);
+dojo.widget.MenuBarItem2.prototype.enabled = true;
+dojo.widget.MenuBarItem2.prototype.visible = true;
//IMPORTANT DOJO workaround menu item sizing is bad in .31 dojo
dojo.widget.MenuBarItem2.prototype.layoutItem = function(item_h){
@@ -62,11 +65,15 @@
this.labelNode.style.left = '0px';
dojo.style.setOuterWidth(this.targetNode, label_w);
- dojo.style.setOuterHeight(this.targetNode, item_h);
+ dojo.style.setOuterHeight(this.targetNode, item_h);
+
+ if (!this.parent.enabled){
+ this.setDisabled(true);
+ }
}
xap.bridges.dojo.MenuBarItemBridge.prototype.init = function() {
- this.superclass.init.call(this);
+ xap.bridges.dojo.DojoWidgetBridge.prototype.init.call(this);
}
xap.bridges.dojo.MenuBarItemBridge.prototype.getPeerString = function(){
@@ -83,12 +90,11 @@
xap.bridges.dojo.MenuBarItemBridge.prototype.getNewAllowedAttributes = function(){
- return ["text"];
+ return ["text", "enabled", "visible"];
}
-xap.bridges.dojo.MenuBarItemBridge.prototype.setTextAttribute = function( text ){
-
+xap.bridges.dojo.MenuBarItemBridge.prototype.setTextAttribute = function( text ){
var peer = this.getPeer();
if (!peer || !peer.labelShadowNode){
@@ -103,6 +109,27 @@
}
}
+xap.bridges.dojo.MenuBarItemBridge.prototype._getRootSpan = function() {
+ var domNode = this.getRootDomNode();
+ return domNode.childNodes[0];
+}
+
+
+xap.bridges.dojo.MenuBarItemBridge.prototype.setColorAttribute = function(value) {
+ var rootSpan = this._getRootSpan();
+ rootSpan.style.color = value;
+}
+
+
+xap.bridges.dojo.MenuBarItemBridge.prototype._getSubmenuHandler = function() {
+ var submenu = dojo.widget.getWidgetById(this.getPeer().submenuId);
+ var handler = null;
+ if (submenu) {
+ handler = this.getUiContentHandler().getHandlerForPeer(submenu);
+ }
+
+ return handler;
+}
/**
*
@@ -110,7 +137,7 @@
* XAL properties to their Dojo equivalents
*/
xap.bridges.dojo.MenuBarItemBridge.prototype.getXalToToolkitMapper = function(){
- var mapper = this.superclass.getXalToToolkitMapper.call(this);
+ var mapper = xap.bridges.dojo.DojoWidgetBridge.prototype.getXalToToolkitMapper.call(this);
mapper.text = "caption";
return mapper;
}
@@ -123,5 +150,70 @@
}
}
+xap.bridges.dojo.MenuBarItemBridge.prototype.setEnabledAttribute = function(value) {
+ var peer = this.getPeer();
+ peer.enabled = value == "true" ? true : false;
+ this._enable();
+}
+
+xap.bridges.dojo.MenuBarItemBridge.prototype._enable = function() {
+ var peer = this.getPeer();
+
+ if (peer.parent && peer.parent.enabled && peer.enabled) {
+ peer.setDisabled(false);
+ } else {
+ peer.setDisabled(true);
+ }
+}
+
+
+dojo.widget.MenuBarItem2.prototype.expandMenu = function() {
+ if (this.parent.disabled || this.disabled) {
+ return;
+ }
+
+ var submenu = dojo.widget.getWidgetById(this.submenuId);
+ if (submenu){
+ this.parent.openSubmenu(submenu, this);
+ }
+}
+
+/** XML attribute set method for "fontFamily" */
+xap.bridges.dojo.MenuBarItemBridge.prototype.setFontFamilyAttribute = function(value) {
+ this._getRootSpan().style.fontFamily = value;
+}
+/** XML attribute set method for "fontSize" */
+xap.bridges.dojo.MenuBarItemBridge.prototype.setFontSizeAttribute = function(value) {
+ this._getRootSpan().style.fontSize = value;
+}
+
+/** XML attribute set method for "fontStyle" */
+xap.bridges.dojo.MenuBarItemBridge.prototype.setFontStyleAttribute = function(value) {
+ this._getRootSpan().style.fontStyle = value;
+}
+
+/** XML attribute set method for "fontWeight" */
+xap.bridges.dojo.MenuBarItemBridge.prototype.setFontWeightAttribute = function(value) {
+ this._getRootSpan().style.fontWeight = value;
+}
+
+/** XML attribute set method for "fontWeight" */
+xap.bridges.dojo.MenuBarItemBridge.prototype.setVisibleAttribute = function(value) {
+ var booleanValue = value == "true";
+ var peer = this.getPeer();
+
+ if (peer.visible != booleanValue) {
+ peer.visible = booleanValue;
+
+ var domNode = this.getRootDomNode();
+ if (peer.visible) {
+ domNode.style.display = "block";
+ } else {
+ domNode.style.display = "none";
+ }
+
+ this.getPeer().parent.layoutMenu2();
+ }
+}
Modified: incubator/xap/trunk/src/xap/bridges/dojo/MenuBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/dojo/MenuBridge.js?view=diff&rev=470921&r1=470920&r2=470921
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/dojo/MenuBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/dojo/MenuBridge.js Fri Nov 3 09:39:06 2006
@@ -46,7 +46,7 @@
xap.bridges.dojo.MenuBridge.prototype.init = function() {
- this.superclass.init.call(this);
+ xap.bridges.dojo.DojoWidgetBridge.prototype.init.call(this);
}
xap.bridges.dojo.MenuBridge.prototype.getPeerString = function(){
@@ -98,7 +98,3 @@
xap.bridges.dojo.MenuBridge.prototype.getNewAllowedAttributes = function(){
return [];
}
-
-
-
-
Modified: incubator/xap/trunk/src/xap/bridges/dojo/MenuItemBridge.js
URL: http://svn.apache.org/viewvc/incubator/xap/trunk/src/xap/bridges/dojo/MenuItemBridge.js?view=diff&rev=470921&r1=470920&r2=470921
==============================================================================
--- incubator/xap/trunk/src/xap/bridges/dojo/MenuItemBridge.js (original)
+++ incubator/xap/trunk/src/xap/bridges/dojo/MenuItemBridge.js Fri Nov 3 09:39:06 2006
@@ -25,7 +25,6 @@
Xap.require("dojo.widget.Menu2");
Xap.require("xap.session.ClientEvent");
-Xap.require('xap.bridges.dojo.DojoWidgetBridge');
/**
* @fileoverview
@@ -46,7 +45,7 @@
xap.bridges.dojo.MenuItemBridge.prototype.init = function() {
- this.superclass.init.call(this);
+ xap.bridges.dojo.DojoWidgetBridge.prototype.init.call(this);
//add listener last so we don't fire for the initial set
dojo.event.connect(this.getPeer(), "onClick",this,"onClick");
@@ -66,7 +65,7 @@
xap.bridges.dojo.MenuItemBridge.prototype.getNewAllowedAttributes = function(){
- return ["text"];
+ return ["text", "enabled", "visible"];
}
@@ -100,7 +99,7 @@
* XAL properties to their Dojo equivalents
*/
xap.bridges.dojo.MenuItemBridge.prototype.getXalToToolkitMapper = function(){
- var mapper = this.superclass.getXalToToolkitMapper.call(this);
+ var mapper = xap.bridges.dojo.DojoWidgetBridge.prototype.getXalToToolkitMapper.call(this);
mapper.text = "caption";
return mapper;
}
@@ -112,3 +111,31 @@
}
}
+xap.bridges.dojo.MenuItemBridge.prototype.setEnabledAttribute = function(enabled) {
+ var peer = this.getPeer();
+ if (enabled == "true") {
+ peer.setDisabled(false);
+ } else {
+ peer.setDisabled(true);
+ }
+}
+
+dojo.widget.MenuItem2.prototype.visible = true;
+
+/** XML attribute set method for "fontWeight" */
+xap.bridges.dojo.MenuItemBridge.prototype.setVisibleAttribute = function(value) {
+ var booleanValue = value == "true";
+ var peer = this.getPeer();
+
+ if (peer.visible != booleanValue) {
+ peer.visible = booleanValue;
+ var domNode = this.getRootDomNode();
+ if (peer.visible) {
+ domNode.style.display = "block";
+ } else {
+ domNode.style.display = "none";
+ }
+
+ this.getPeer().parent.postCreate();
+ }
+}
\ No newline at end of file