Changeset 3712

Show
Ignore:
Timestamp:
04/29/06 14:11:04 (3 years ago)
Author:
cal
Message:

added a menu bar widget to simulate window menus

Location:
trunk
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/widget/Menu2.js

    r3699 r3712  
    33dojo.provide("dojo.widget.PopupMenu2"); 
    44dojo.provide("dojo.widget.MenuItem2"); 
     5dojo.provide("dojo.widget.MenuBar2"); 
    56 
    67dojo.require("dojo.html"); 
     
    3435        currentSubmenuTrigger: null, 
    3536        parentMenu: null, 
     37        parentMenuBar: null, 
    3638        isShowingNow: false, 
    3739        menuX: 0, 
     
    318320                this.isShowingNow = false; 
    319321                dojo.widget.html.Menu2Manager.closed(this); 
     322 
     323                if (this.parentMenuBar){ 
     324                        this.parentMenuBar.closedMenu(this); 
     325                } 
    320326        }, 
    321327 
     
    861867}; 
    862868 
     869 
     870dojo.widget.MenuBar2 = function(){ 
     871        dojo.widget.HtmlWidget.call(this); 
     872} 
     873 
     874dojo.inherits(dojo.widget.MenuBar2, dojo.widget.HtmlWidget); 
     875 
     876dojo.lang.extend(dojo.widget.MenuBar2, { 
     877        widgetType: "MenuBar2", 
     878        isContainer: true, 
     879 
     880        snarfChildDomOutput: true, 
     881 
     882        currentItem: null, 
     883        isExpanded: false, 
     884 
     885        currentSubmenu: null, 
     886        currentSubmenuTrigger: null, 
     887 
     888        domNode: null, 
     889        containerNode: null, 
     890 
     891        templateString: '<div class="dojoMenuBar2"><div dojoAttachPoint="containerNode" class="dojoMenuBar2Client"></div></div>', 
     892        templateCssPath: dojo.uri.dojoUri("src/widget/templates/HtmlMenu2.css"), 
     893 
     894        itemHeight: 18, 
     895        openEvent: null, 
     896 
     897 
     898        postCreate: function(){ 
     899 
     900                // do something here 
     901 
     902                this.layoutMenuSoon(); 
     903        }, 
     904 
     905        layoutMenuSoon: function(){ 
     906                dojo.lang.setTimeout(this, "layoutMenu", 0); 
     907        }, 
     908 
     909        layoutMenu: function(){ 
     910 
     911                // menu must be attached to DOM for size calculations to work 
     912 
     913                var parent = this.domNode.parentNode; 
     914                if (! parent || parent == undefined) { 
     915                        document.body.appendChild(this.domNode); 
     916                } 
     917 
     918 
     919                // determine menu height 
     920 
     921                var max_label_h = 0; 
     922 
     923                for(var i=0; i<this.children.length; i++){ 
     924 
     925                        if (this.children[i].getLabelHeight){ 
     926 
     927                                max_label_h = Math.max(max_label_h, this.children[i].getLabelHeight()); 
     928                        } 
     929                } 
     930 
     931                if (isNaN(max_label_h)){ 
     932                        // Browser needs some more time to calculate sizes 
     933                        this.layoutMenuSoon(); 
     934                        return; 
     935                } 
     936 
     937                var clientLeft = dojo.style.getPixelValue(this.domNode, "padding-left", true) 
     938                                + dojo.style.getPixelValue(this.containerNode, "margin-left", true) 
     939                                + dojo.style.getPixelValue(this.containerNode, "padding-left", true); 
     940                var clientTop  = dojo.style.getPixelValue(this.domNode, "padding-top", true) 
     941                                + dojo.style.getPixelValue(this.containerNode, "padding-top", true); 
     942 
     943                if (isNaN(clientLeft) || isNaN(clientTop)){ 
     944                        // Browser needs some more time to calculate sizes 
     945                        this.layoutMenuSoon(); 
     946                        return; 
     947                } 
     948 
     949                var max_item_height = 0; 
     950                var x = clientLeft; 
     951 
     952                for (var i=0; i<this.children.length; i++){ 
     953 
     954                        var ch = this.children[i]; 
     955 
     956                        ch.layoutItem(max_label_h); 
     957 
     958                        ch.leftPosition = x; 
     959                        ch.domNode.style.left = x + 'px'; 
     960 
     961                        x += dojo.style.getOuterWidth(ch.domNode); 
     962                        max_item_height = Math.max(max_item_height, dojo.style.getOuterHeight(ch.domNode)); 
     963                } 
     964 
     965                dojo.style.setContentHeight(this.containerNode, max_item_height); 
     966                dojo.style.setContentHeight(this.domNode, dojo.style.getOuterHeight(this.containerNode)); 
     967        }, 
     968 
     969        openSubmenu: function(submenu, from_item){ 
     970 
     971                var our_pos = dojo.style.getAbsolutePosition(this.domNode, false); 
     972 
     973                var our_h = dojo.style.getOuterHeight(this.domNode); 
     974                var item_x = from_item.leftPosition; 
     975 
     976                var x = our_pos.x + item_x; 
     977                var y = our_pos.y + our_h; 
     978 
     979                this.currentSubmenu = submenu; 
     980                this.currentSubmenu.open(x, y, this, from_item.domNode); 
     981                this.currentSubmenu.parentMenuBar = this; 
     982        }, 
     983 
     984        closeSubmenu: function(){ 
     985 
     986                if (this.currentSubmenu == null){ return; } 
     987 
     988                var menu = this.currentSubmenu; 
     989                this.currentSubmenu = null; 
     990                menu.close(); 
     991        }, 
     992 
     993        itemHover: function(item){ 
     994 
     995                if (item == this.currentItem) return; 
     996 
     997                if (this.currentItem){ 
     998                        this.currentItem.unhighlightItem(); 
     999 
     1000                        if (this.isExpanded){ 
     1001                                this.closeSubmenu(); 
     1002                        } 
     1003                } 
     1004 
     1005                this.currentItem = item; 
     1006                this.currentItem.highlightItem(); 
     1007 
     1008                if (this.isExpanded){ 
     1009                        this.currentItem.expandMenu(); 
     1010                } 
     1011        }, 
     1012 
     1013        itemUnhover: function(item){ 
     1014 
     1015                if (item != this.currentItem) return; 
     1016 
     1017                if (!this.isExpanded){ 
     1018                        this.currentItem.unhighlightItem(); 
     1019                        this.currentItem = null; 
     1020                } 
     1021        }, 
     1022 
     1023        itemClick: function(item){ 
     1024 
     1025                if (item != this.currentItem){ 
     1026 
     1027                        this.itemHover(item); 
     1028                } 
     1029 
     1030                if (this.isExpanded){ 
     1031 
     1032                        this.isExpanded = false; 
     1033                        this.closeSubmenu(); 
     1034 
     1035                }else{ 
     1036 
     1037                        this.isExpanded = true; 
     1038                        this.currentItem.expandMenu(); 
     1039                } 
     1040        }, 
     1041 
     1042        closedMenu: function(menu){ 
     1043 
     1044                if (this.currentSubmenu == menu){ 
     1045 
     1046                        this.isExpanded = false; 
     1047                        this.itemUnhover(this.currentItem); 
     1048                } 
     1049        } 
     1050}); 
     1051 
     1052 
     1053dojo.widget.MenuBarItem2 = function(){ 
     1054        dojo.widget.HtmlWidget.call(this); 
     1055} 
     1056 
     1057dojo.inherits(dojo.widget.MenuBarItem2, dojo.widget.HtmlWidget); 
     1058 
     1059dojo.lang.extend(dojo.widget.MenuBarItem2, { 
     1060 
     1061        widgetType: "MenuBarItem2", 
     1062        templateString: 
     1063                         '<div class="dojoMenuBarItem2">' 
     1064                        +'<span dojoAttachPoint="labelNode" class="dojoMenuBarItem2Label"><span><span></span></span></span>' 
     1065                        +'<div dojoAttachPoint="targetNode" class="dojoMenuBarItem2Target" dojoAttachEvent="onMouseOver: onHover; onMouseOut: onUnhover; onClick: _onClick;">&nbsp;</div>' 
     1066                        +'</div>', 
     1067 
     1068        // 
     1069        // nodes 
     1070        // 
     1071 
     1072        domNode: null, 
     1073        labelNode: null, 
     1074        targetNode: null, 
     1075 
     1076        // 
     1077        // internal settings 
     1078        // 
     1079 
     1080        is_hovering: false, 
     1081        hover_timer: null, 
     1082        is_open: false, 
     1083 
     1084        // 
     1085        // options 
     1086        // 
     1087 
     1088        caption: 'Untitled', 
     1089        accelKey: '', 
     1090        iconSrc: '', 
     1091        submenuId: '', 
     1092        disabled: false, 
     1093        eventNaming: "default", 
     1094 
     1095 
     1096        postCreate: function(){ 
     1097 
     1098                dojo.html.disableSelection(this.domNode); 
     1099 
     1100                if (this.disabled){ 
     1101                        this.setDisabled(true); 
     1102                } 
     1103 
     1104                this.labelNode.childNodes[0].appendChild(document.createTextNode(this.caption)); 
     1105 
     1106                this.labelShadowNode = this.labelNode.childNodes[0].childNodes[0]; 
     1107                this.labelShadowNode.appendChild(document.createTextNode(this.caption)); 
     1108 
     1109                if (this.eventNaming == "default") { 
     1110                        for (eventName in this.eventNames) { 
     1111                                this.eventNames[eventName] = this.widgetId+"/"+eventName; 
     1112                        } 
     1113                } 
     1114        }, 
     1115 
     1116        layoutItem: function(item_h){ 
     1117 
     1118                var label_w = dojo.style.getOuterWidth(this.labelNode); 
     1119 
     1120                var clientLeft = dojo.style.getPixelValue(this.domNode, "padding-left", true); 
     1121                var clientTop  = dojo.style.getPixelValue(this.domNode, "padding-top", true); 
     1122 
     1123                this.labelNode.style.left = clientLeft + 'px'; 
     1124 
     1125                dojo.style.setOuterHeight(this.labelNode, item_h); 
     1126                dojo.style.setContentWidth(this.domNode, label_w); 
     1127                dojo.style.setContentHeight(this.domNode, item_h); 
     1128 
     1129                this.labelNode.style.left = '0px'; 
     1130 
     1131                dojo.style.setOuterWidth(this.targetNode, label_w); 
     1132                dojo.style.setOuterHeight(this.targetNode, item_h); 
     1133        }, 
     1134 
     1135        getLabelHeight: function(){ 
     1136 
     1137                return dojo.style.getOuterHeight(this.labelNode); 
     1138        }, 
     1139 
     1140        onHover: function(){ 
     1141                this.parent.itemHover(this); 
     1142        }, 
     1143 
     1144        onUnhover: function(){ 
     1145                this.parent.itemUnhover(this); 
     1146        }, 
     1147 
     1148        _onClick: function(){ 
     1149                this.parent.itemClick(this); 
     1150        }, 
     1151 
     1152        highlightItem: function(){ 
     1153                dojo.html.addClass(this.domNode, 'dojoMenuBarItem2Hover'); 
     1154        }, 
     1155 
     1156        unhighlightItem: function(){ 
     1157                dojo.html.removeClass(this.domNode, 'dojoMenuBarItem2Hover'); 
     1158        }, 
     1159 
     1160        expandMenu: function(){ 
     1161 
     1162                var submenu = dojo.widget.getWidgetById(this.submenuId); 
     1163                if (submenu){ 
     1164 
     1165                        this.parent.openSubmenu(submenu, this); 
     1166                } 
     1167        }, 
     1168 
     1169        setDisabled: function(value){ 
     1170                this.disabled = value; 
     1171 
     1172                if (this.disabled){ 
     1173                        dojo.html.addClass(this.domNode, 'dojoMenuBarItem2Disabled'); 
     1174                }else{ 
     1175                        dojo.html.removeClass(this.domNode, 'dojoMenuBarItem2Disabled'); 
     1176                } 
     1177        } 
     1178}); 
     1179 
    8631180// make it a tag 
     1181dojo.widget.tags.addParseTreeHandler("dojo:MenuBar2"); 
     1182dojo.widget.tags.addParseTreeHandler("dojo:MenuBarItem2"); 
    8641183dojo.widget.tags.addParseTreeHandler("dojo:PopupMenu2"); 
    8651184dojo.widget.tags.addParseTreeHandler("dojo:MenuItem2"); 
  • trunk/src/widget/templates/HtmlMenu2.css

    r2388 r3712  
    106106        font-size: 1px; 
    107107        background-image: url('images/transparent.gif'); 
    108         cursor: pointer; 
    109         _cursor: hand; 
    110108} 
    111109 
     
    128126        font-size: 1px; 
    129127} 
     128 
     129 
     130 
     131.dojoMenuBar2 { 
     132        position: relative; 
     133        background-color: ThreeDFace; 
     134        border-bottom: 1px solid ThreeDHighlight; 
     135} 
     136 
     137.dojoMenuBar2Client { 
     138        padding: 1px; 
     139        border-top: 1px solid ThreeDHighlight; 
     140        border-bottom: 1px solid ThreeDShadow; 
     141} 
     142 
     143.dojoMenuBarItem2 { 
     144        position: absolute; 
     145        white-space: nowrap; 
     146        font: menu; 
     147        color: WindowText; 
     148        margin: 0; 
     149} 
     150 
     151.dojoMenuBarItem2 span { 
     152        margin: 0; 
     153} 
     154 
     155.dojoMenuBarItem2Target { 
     156        position: absolute; 
     157        z-index: 10; 
     158        font-size: 1px; 
     159        background-image: url('images/transparent.gif'); 
     160} 
     161 
     162.dojoMenuBarItem2Label { 
     163        position: absolute; 
     164        vertical-align: middle; 
     165        z-index: 1; 
     166        padding: 3px 8px; 
     167} 
     168 
     169.dojoMenuBarItem2Label span { 
     170        position: relative; 
     171        z-index: 2; 
     172} 
     173 
     174.dojoMenuBarItem2Label span span { 
     175        position: absolute; 
     176        color: ThreeDHighlight; 
     177        display: none; 
     178        left: 1px; 
     179        top: 1px; 
     180        z-index: -2; 
     181} 
     182 
     183.dojoMenuBarItem2Hover { 
     184        background-color: Highlight; 
     185        color: HighlightText; 
     186} 
     187 
     188.dojoMenuBarItem2Disabled .dojoMenuBarItem2Label span, 
     189.dojoMenuBarItem2Disabled .dojoMenuBarItem2Accel span { 
     190        color: ThreeDShadow; 
     191} 
     192 
     193.dojoMenuBarItem2Disabled .dojoMenuBarItem2Label span span, 
     194.dojoMenuBarItem2Disabled .dojoMenuBarItem2Accel span span { 
     195        color: ThreeDHighlight; 
     196        display: block; 
     197} 
     198 
     199.dojoMenuBarItem2Hover .dojoMenuBarItem2Label span span, 
     200.dojoMenuBarItem2Hover .dojoMenuBarItem2Accel span span { 
     201        display: none; 
     202}