Home | Trees | Indices | Help |
|
---|
|
1 # Copyright 2006 James Tauber and contributors 2 # Copyright (C) 2009 Luke Kenneth Casson Leighton <lkcl@lkcl.net> 3 # Copyright (C) 2009 Pavel Mironchyk <p.mironchyk@gmail.com> 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 from pyjamas import DOM 17 from pyjamas import Factory 18 19 from pyjamas import DeferredCommand 20 from Widget import Widget 21 from MenuItem import MenuItem 22 from MenuBarPopupPanel import MenuBarPopupPanel 23 from pyjamas.ui import Event 24237 238 Factory.registerClass('pyjamas.ui.MenuBar', MenuBar) 23927 if not kwargs.has_key('StyleName'): kwargs['StyleName']="gwt-MenuBar" 28 29 self.body = None 30 self.items = [] 31 self.parentMenu = None 32 self.popup = None 33 self.selectedItem = None 34 self.shownChildMenu = None 35 self.vertical = False 36 self.autoOpen = False 37 38 if kwargs.has_key('Element'): 39 table = kwargs.pop('Element') 40 fc = DOM.getFirstChild(table) 41 if fc: 42 self.body = fc 43 else: 44 self.body = DOM.createTBody() 45 DOM.appendChild(table, self.body) 46 else: 47 table = DOM.createTable() 48 self.body = DOM.createTBody() 49 DOM.appendChild(table, self.body) 50 51 if not vertical: 52 tr = DOM.createTR() 53 DOM.appendChild(self.body, tr) 54 55 self.vertical = vertical 56 57 outer = DOM.createDiv() 58 DOM.appendChild(outer, table) 59 self.setElement(outer) 60 Widget.__init__(self, **kwargs)61 62 # also callable as: 63 # addItem(item) 64 # addItem(text, cmd) 65 # addItem(text, popup) 66 # addItem(text, asHTML, cmd)68 if not hasattr(item, "setSubMenu"): 69 item = MenuItem(item, asHTML, popup) 70 71 if self.vertical: 72 tr = DOM.createTR() 73 DOM.appendChild(self.body, tr) 74 else: 75 tr = DOM.getChild(self.body, 0) 76 77 DOM.appendChild(tr, item.getElement()) 78 79 item.setParentMenu(self) 80 item.setSelectionStyle(False) 81 self.items.append(item) 82 return item8385 container = self.getItemContainerElement() 86 while DOM.getChildCount(container) > 0: 87 DOM.removeChild(container, DOM.getChild(container, 0)) 88 self.items = []89 9294 Widget.onBrowserEvent(self, event) 95 96 item = self.findItem(DOM.eventGetTarget(event)) 97 if item is None: 98 return False 99 100 type = DOM.eventGetType(event) 101 if type == "click": 102 self.doItemAction(item, True) 103 return True 104 elif type == "mouseover": 105 self.itemOver(item) 106 elif type == "mouseout": 107 self.itemOver(None) 108 109 return False110112 if autoClosed: 113 self.closeAllParents() 114 115 self.onHide() 116 self.shownChildMenu = None 117 self.popup = None118120 try: 121 idx = self.items.index(item) 122 except ValueError: 123 return 124 container = self.getItemContainerElement() 125 DOM.removeChild(container, DOM.getChild(container, idx)) 126 del self.items[idx]127 130132 curMenu = self 133 while curMenu is not None: 134 curMenu.close() 135 136 if curMenu.parentMenu is None and curMenu.selectedItem is not None: 137 curMenu.selectedItem.setSelectionStyle(False) 138 curMenu.selectedItem = None 139 140 curMenu = curMenu.parentMenu141143 if (self.shownChildMenu is not None) and (item.getSubMenu() == self.shownChildMenu): 144 return 145 146 if (self.shownChildMenu is not None): 147 self.shownChildMenu.onHide() 148 self.popup.hide() 149 150 if item.getSubMenu() is None: 151 if fireCommand: 152 self.closeAllParents() 153 154 cmd = item.getCommand() 155 if cmd is not None: 156 DeferredCommand.add(cmd) 157 return 158 159 self.selectItem(item) 160 self.popup = MenuBarPopupPanel(item) 161 self.popup.addPopupListener(self) 162 163 if self.vertical: 164 self.popup.setPopupPosition(self.getAbsoluteLeft() + 165 self.getOffsetWidth() - 1, 166 item.getAbsoluteTop()) 167 else: 168 self.popup.setPopupPosition(item.getAbsoluteLeft(), 169 self.getAbsoluteTop() + 170 self.getOffsetHeight() - 1) 171 172 self.shownChildMenu = item.getSubMenu() 173 sub_menu = item.getSubMenu() 174 sub_menu.parentMenu = self 175 176 self.popup.show()177 183185 if item is None: 186 if (self.selectedItem is not None): 187 if self.selectedItem.getSubMenu() != None: 188 if (self.shownChildMenu == self.selectedItem.getSubMenu()): 189 return 190 else: 191 self.selectItem(item) 192 return 193 194 self.selectItem(item) 195 196 if item is not None: 197 if (self.shownChildMenu is not None) or (self.parentMenu is not None) or self.autoOpen: 198 self.doItemAction(item, False)199 203205 for item in self.items: 206 if DOM.isOrHasChild(item.getElement(), hItem): 207 return item 208 209 return None210 216 221 225227 if item == self.selectedItem: 228 return 229 230 if self.selectedItem is not None: 231 self.selectedItem.setSelectionStyle(False) 232 233 if item is not None: 234 item.setSelectionStyle(True) 235 236 self.selectedItem = item
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Jun 16 12:42:33 2010 | http://epydoc.sourceforge.net |