NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

edit_components.py (27459B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\carbonui\control\edit_components.py
      2 import sys
      3 import _weakref
      4 import blue
      5 import uthread
      6 from carbonui import uiconst
      7 from carbonui.control.editutils import parser
      8 from carbonui.control.editutils.parserbase import ParserBaseCoreOverride as ParserBase
      9 from carbonui.control.image import ImageCoreOverride as Image
     10 from carbonui.control.scrollentries import SE_BaseClassCore
     11 from carbonui.primitives.container import Container
     12 from carbonui.primitives.fill import Fill
     13 from carbonui.primitives.line import Line
     14 from carbonui.primitives.sprite import Sprite
     15 from carbonui.uicore import uicore
     16 from carbonui.util.various_unsorted import GetBrowser, ParseHTMLColor
     17 
     18 class hr(SE_BaseClassCore):
     19     __guid__ = 'uicls.SE_hr'
     20     __params__ = []
     21     default_showHilite = False
     22 
     23     def Startup(self, *args):
     24         self.sr.leftmargin = Container(name='leftmargin', parent=self, align=uiconst.TOLEFT)
     25         self.sr.rightmargin = Container(name='rightmargin', parent=self, align=uiconst.TORIGHT)
     26         self.sr.line = Container(name='lineparent', parent=self)
     27 
     28     def Load(self, node):
     29         self.sr.leftmargin.width = node.Get('leftmargin', 0)
     30         self.sr.rightmargin.width = node.Get('rightmargin', 0)
     31         self.sr.line.Flush()
     32         Fill(parent=self.sr.line, color=ParseHTMLColor(node.attrs.color or '#88ffffff', 1))
     33         align = uiconst.RELATIVE
     34         if node.attrs.width:
     35             if unicode(node.attrs.width).endswith('%'):
     36                 node.attrs.width = self.sr.node.scroll.GetContentWidth() * int(node.attrs.width[:-1]) / 100
     37             self.sr.line.width = int(node.attrs.width)
     38             if node.attrs.align and node.attrs.align.lower() in ('left', 'right'):
     39                 if node.attrs.align.lower() == 'right':
     40                     align = uiconst.TORIGHT
     41                 else:
     42                     align = uiconst.TOLEFT
     43             elif node.attrs.align is None:
     44                 align = uiconst.RELATIVE
     45             else:
     46                 align = uiconst.CENTER
     47         else:
     48             self.sr.line.left = self.sr.line.width = 0
     49             align = uiconst.TOALL
     50         self.sr.line.SetAlign(align)
     51 
     52     def GetHeight(self, *args):
     53         node, width = args
     54         if node.attrs.size:
     55             node.height = int(node.attrs.size)
     56         else:
     57             node.height = 1
     58         return node.height
     59 
     60 
     61 class VirtualTable(SE_BaseClassCore):
     62     __guid__ = 'uicls.SE_table'
     63     default_showHilite = False
     64 
     65     def Startup(self, browser, *args):
     66         self.browser = _weakref.proxy(browser)
     67         self.taken = []
     68         self.tableloaded = 0
     69         self.name = 'table'
     70         self.sr.cells = None
     71         attrs = self.data.attrs
     72         self.charset = attrs.Get('charset', 'cp1252')
     73         self.stack = self.browser.attrStack[-1].copy()
     74         if not self.tableloaded:
     75             self.RefreshSizes()
     76             if self.destroyed:
     77                 return
     78             s = self.stack
     79             self.AddBackground(self, s)
     80             self.tableloaded = 1
     81 
     82     def Load(self):
     83         if not self.loaded:
     84             self.loaded = 1
     85             uthread.new(self.Load_thread).context = 'uicls.SE_table.Load'
     86 
     87     def Load_thread(self):
     88         while not getattr(self, 'tableloaded', None):
     89             blue.pyos.synchro.SleepWallclock(50)
     90 
     91         if self.destroyed:
     92             return
     93         self.state = uiconst.UI_PICKCHILDREN
     94         if self.sr.cells:
     95             for cell in self.sr.cells:
     96                 cell.LoadContent(cell.sr.lines)
     97 
     98     def GetValue(self):
     99         selectionString = ''
    100         row = 0
    101         col = 0
    102         for cell in self.children:
    103             if not isinstance(cell, Cell):
    104                 continue
    105             if cell.rowIdx != row:
    106                 selectionString += '\r\n'
    107             for cellentry in cell.sr.content.children:
    108                 if hasattr(cellentry, 'GetCopyData'):
    109                     try:
    110                         selectionString += cellentry.GetCopyData(0, -1) or ''
    111                     except TypeError:
    112                         pass
    113 
    114             selectionString += '\t'
    115             row = cell.rowIdx
    116 
    117         return selectionString
    118 
    119     def AddBackground(self, where, s):
    120         for i, side in enumerate(['top',
    121          'left',
    122          'right',
    123          'bottom']):
    124             if s['border-%s-width' % side]:
    125                 align = [uiconst.TOTOP,
    126                  uiconst.TOLEFT,
    127                  uiconst.TORIGHT,
    128                  uiconst.TOBOTTOM][i]
    129                 Line(parent=where, align=align, weight=s['border-%s-width' % side], color=s['border-%s-color' % side], idx=0)
    130 
    131         if s['background-image'] and where.sr.background:
    132             browser = GetBrowser(self)
    133             currentURL = None
    134             if browser:
    135                 currentURL = browser.sr.currentURL
    136             texture, tWidth, tHeight = sm.GetService('browserImage').GetTextureFromURL(s['background-image'], currentURL, fromWhere='VirtualTable::AddBackground')
    137             pic = Sprite()
    138             pic.left = pic.top = 0
    139             pic.width = tWidth
    140             pic.height = tHeight
    141             pic.texture = texture
    142             row = Container(name='row', align=uiconst.TOTOP, pos=(0,
    143              0,
    144              0,
    145              tHeight), clipChildren=1)
    146             if s['background-repeat'] in ('repeat', 'repeat-x'):
    147                 for x in xrange(max(where.width / tWidth, 2) + 1):
    148                     row.children.append(pic.CopyTo())
    149                     pic.left += pic.width
    150 
    151             else:
    152                 row.children.append(pic.CopyTo())
    153             if s['background-repeat'] in ('repeat', 'repeat-y'):
    154                 for y in xrange(max(where.height / tHeight, 2) + 1):
    155                     row.height = min(where.height - tHeight * y, row.height)
    156                     where.sr.background.children.append(row.CopyTo())
    157 
    158             else:
    159                 where.sr.background.children.append(row.CopyTo())
    160         if s['background-color']:
    161             Fill(parent=where, color=s['background-color'])
    162 
    163     def GetInt(self, string):
    164         value = filter(lambda x: x in '0123456789', unicode(string))
    165         try:
    166             value = int(value)
    167         except:
    168             sys.exc_clear()
    169 
    170         return value
    171 
    172     def RefreshSizes(self):
    173         self.drows = []
    174         self.dcols = []
    175         self.fcols = []
    176         if not self or self.destroyed:
    177             return
    178         w = self.data.attrs.Get('width', None)
    179         contentWidth = self.browser.GetContentWidth()
    180         singleWordMax = contentWidth - self.browser.xmargin * 2
    181         if w:
    182             if isinstance(w, basestring) and (w.endswith('%') or w.endswith('\xef\xbf\xbd')):
    183                 w = self.GetInt(w)
    184                 w = int(float(w) / 100.0 * singleWordMax)
    185             else:
    186                 w = self.GetInt(w)
    187         h = self.data.attrs.Get('height', None)
    188         if h and isinstance(h, basestring) and (h.endswith('%') or h.endswith('\xef\xbf\xbd')):
    189             h = self.GetInt(h)
    190             if self.browser.sr.clipper:
    191                 h = float(h) / 100.0 * self.browser.sr.clipperHeight
    192             else:
    193                 h = float(h) / 100.0 * self.browser.height
    194         else:
    195             h = self.GetInt(h)
    196         for col in self.data.attrs.Get('colgroups', []):
    197             if unicode(col).isdigit():
    198                 self.dcols.append(int(col))
    199                 self.fcols.append(int(col))
    200             elif col and isinstance(col, basestring) and (col.endswith('%') or col.endswith('\xef\xbf\xbd')):
    201                 col = self.GetInt(col)
    202                 col = float(col) / 100.0 * ((w or contentWidth - self.browser.xmargin * 2) - int(self.browser.attrStack[-1]['border-left-width']) - int(self.browser.attrStack[-1]['border-right-width']))
    203                 self.dcols.append(int(col))
    204                 self.fcols.append(int(col))
    205             else:
    206                 self.dcols.append(0)
    207                 self.fcols.append(0)
    208 
    209         cells = []
    210         needMore = []
    211         rowIdx = 0
    212         bCollapse = self.browser.attrStack[-1]['border-collapse']
    213         for rowdata in self.data.attrs.Get('rows', []):
    214             for celldata in rowdata.cols:
    215                 colIdx = self.GetColIdx(rowIdx)
    216                 while len(self.dcols) < colIdx + int(celldata.colspan or 1):
    217                     self.dcols.append(0)
    218                     self.fcols.append(0)
    219 
    220                 cell = Cell(parent=self, name='tablecell', align=uiconst.RELATIVE)
    221                 wd = celldata.width
    222                 if wd and isinstance(wd, basestring) and (wd.endswith('%') or wd.endswith('\xef\xbf\xbd')):
    223                     wd = self.GetInt(wd)
    224                     if wd == 100:
    225                         wd = 0
    226                     else:
    227                         wd = float(wd) / 100.0 * contentWidth - self.browser.xmargin * 2
    228                     celldata.width = int(wd)
    229                 elif wd:
    230                     celldata.width = self.GetInt(wd)
    231                 else:
    232                     celldata.width = None
    233                 cell.name = 'tablecell %s-%s' % (rowIdx, colIdx)
    234                 cell.Startup(self)
    235                 cell.charset = getattr(self, 'charset', 'cp1252')
    236                 cell.celldata = celldata
    237                 cell.rowdata = rowdata
    238                 cell.rowspan = int(celldata.rowspan or 1)
    239                 cell.colspan = int(celldata.colspan or 1)
    240                 cell.rowIdx = rowIdx
    241                 cell.colIdx = colIdx
    242                 styles = celldata.styles
    243                 styles['border-left-width'] = styles['border-left-width'] or [self.stack['border-left-width'], 0][colIdx == 0 and bCollapse]
    244                 styles['border-top-width'] = styles['border-top-width'] or [self.stack['border-top-width'], 0][rowIdx == 0 and bCollapse]
    245                 styles['border-right-width'] = styles['border-right-width'] or [self.stack['border-right-width'], 0][bCollapse]
    246                 styles['border-bottom-width'] = styles['border-bottom-width'] or [self.stack['border-bottom-width'], 0][bCollapse]
    247                 cell.celldata.content.insert(0, ('AddStyles', (styles, celldata.css)))
    248                 if not self or self.destroyed:
    249                     return
    250                 mw, sw = cell.GetMinWidth(singleWordMax)
    251                 mw += self.stack.get('spacing-left', 0) + self.stack.get('spacing-right', 0)
    252                 if not self or getattr(self, 'sr', None) is None:
    253                     return
    254                 colsdone = 0
    255                 for y in xrange(rowIdx, rowIdx + cell.rowspan):
    256                     if cell.colspan == 1:
    257                         self.fcols[colIdx] = int(max(self.fcols[colIdx], sw))
    258                         self.dcols[colIdx] = int(max(self.dcols[colIdx], mw))
    259                     for x in xrange(colIdx, colIdx + cell.colspan):
    260                         self.MarkCellTaken(x, y)
    261 
    262                     colsdone = 1
    263 
    264                 cells.append(cell)
    265 
    266             self.drows.append(2)
    267             rowIdx += 1
    268 
    269         maxTableWidth = int(w or contentWidth - self.browser.xmargin * 2)
    270         currentWidth = sum(self.dcols)
    271         toDivide = max(0, maxTableWidth - currentWidth)
    272         getMore = []
    273         for cell in cells:
    274             cell.width = sum(self.dcols[cell.colIdx:cell.colIdx + cell.colspan])
    275             if cell.totalWidth > cell.width and sum(self.fcols[cell.colIdx:cell.colIdx + cell.colspan]) == 0:
    276                 getMore.append(cell)
    277 
    278         for cell in getMore:
    279             cols = [ col for col in xrange(cell.colIdx, cell.colIdx + cell.colspan) if self.fcols[col] == 0 ]
    280             if len(cols) == 0:
    281                 continue
    282             add = int(min((cell.totalWidth - cell.width) / len(cols), toDivide / len(getMore) / len(cols)))
    283             for x in cols:
    284                 self.dcols[x] += add
    285 
    286         if w:
    287             borders = int(self.stack['border-left-width']) + int(self.stack['border-right-width']) + int(self.stack.get('spacing-left', 0)) + int(self.stack.get('spacing-right', 0))
    288             totalWidth = sum(self.dcols[:]) + borders
    289             setWidth = int(w)
    290             if totalWidth:
    291                 setWidth -= borders
    292                 totalWidth -= borders
    293                 oind = sind = 0
    294                 for i in xrange(len(self.dcols)):
    295                     osave = self.dcols[i]
    296                     if self.fcols[i] == 0:
    297                         self.dcols[i] = int((oind + self.dcols[i]) * setWidth / totalWidth - sind)
    298                     oind += osave
    299                     sind += self.dcols[i]
    300 
    301         if not self or self.destroyed:
    302             return
    303         for cell in cells:
    304             cell.width = int(sum(self.dcols[cell.colIdx:cell.colIdx + cell.colspan])) - self.stack.get('spacing-left', 0) - self.stack.get('spacing-right', 0)
    305             mh = cell.GetMinHeight()
    306             mh += self.stack.get('spacing-top', 0) + self.stack.get('spacing-bottom', 0)
    307             for i in xrange(cell.rowIdx, cell.rowIdx + cell.rowspan):
    308                 self.drows[i] = max(self.drows[i], mh / cell.rowspan)
    309 
    310         if h:
    311             borders = int(self.stack['border-top-width']) + int(self.stack['border-bottom-width'])
    312             totalHeight = sum(self.drows[:]) + borders
    313             setHeight = int(h)
    314             if setHeight > totalHeight:
    315                 setHeight -= borders
    316                 totalHeight -= borders
    317                 oind = sind = 0
    318                 for i in xrange(len(self.drows)):
    319                     osave = self.drows[i]
    320                     self.drows[i] = (oind + self.drows[i]) * setHeight / totalHeight - sind
    321                     oind += osave
    322                     sind += self.drows[i]
    323 
    324         w, h = (0, 0)
    325         for cell in cells:
    326             cell.width = sum(self.dcols[cell.colIdx:cell.colIdx + cell.colspan]) - self.stack.get('spacing-left', 0) - self.stack.get('spacing-right', 0)
    327             cell.height = sum(self.drows[cell.rowIdx:cell.rowIdx + cell.rowspan]) - self.stack.get('spacing-top', 0) - self.stack.get('spacing-bottom', 0)
    328             cell.left = sum(self.dcols[:cell.colIdx]) + self.stack['border-left-width'] + self.stack.get('spacing-right', 0) + self.stack.get('spacing-left', 0)
    329             cell.top = sum(self.drows[:cell.rowIdx]) + self.stack['border-top-width'] + self.stack.get('spacing-bottom', 0) + self.stack.get('spacing-top', 0)
    330             w = max(w, cell.left + cell.width)
    331             h = max(h, cell.top + cell.height)
    332             cell.VAlignContent()
    333             self.AddBackground(cell, cell.celldata.styles)
    334 
    335         if not self or not self.sr:
    336             return
    337         self.sr.cells = cells
    338         self.width = w + self.stack['border-right-width'] + self.stack.get('spacing-right', 0) + self.stack.get('spacing-left', 0)
    339         self.height = h + self.stack['border-bottom-width'] + self.stack.get('spacing-bottom', 0) + self.stack.get('spacing-top', 0)
    340 
    341     def GetColIdx(self, rowIdx):
    342         if len(self.taken) <= rowIdx:
    343             return 0
    344         row = self.taken[rowIdx]
    345         if 0 in row:
    346             return row.index(0)
    347         return len(row)
    348 
    349     def MarkCellTaken(self, xIdx, yIdx):
    350         while len(self.taken) < yIdx + 1:
    351             self.taken.append([])
    352 
    353         row = self.taken[yIdx]
    354         while len(row) < xIdx + 1:
    355             row.append(0)
    356 
    357         row[xIdx] = 1
    358 
    359     def GetHeight(self, *args):
    360         node, width = args
    361         node.height = self.height
    362         return node.height
    363 
    364 
    365 class Cell(ParserBase, SE_BaseClassCore):
    366     default_showHilite = False
    367 
    368     def _OnClose(self):
    369         SE_BaseClassCore._OnClose(self)
    370         self.Load = None
    371         self.celldata = None
    372         self.sr.lines = None
    373         self.sr.overlays = None
    374         self.sr.entries = None
    375 
    376     def ApplyAttributes(self, attributes):
    377         SE_BaseClassCore.ApplyAttributes(self, attributes)
    378         ParserBase.Prepare(self)
    379         self.sr.selfProxy = _weakref.proxy(self)
    380         self.htmldebug = 0
    381         self.xmargin = 0
    382         self.sr.entries = []
    383         self.sr.overlays = []
    384         self.sr.overlays_content = Container(name='overlays', parent=self, padding=(1, 1, 1, 1))
    385         self.sr.content = Container(name='content', parent=self)
    386         self.sr.underlays_content = Container(name='underlays_content', parent=self, padding=(1, 1, 1, 1))
    387         self.sr.background = Container(name='background', parent=self)
    388         self.sr.backgroundColorContainer = Container(name='backgroundColorContainer', parent=self)
    389         browser = GetBrowser(self)
    390         self.sr.browser = browser
    391 
    392     def GetContentWidth(self, *args):
    393         return self.sr.width or 200
    394 
    395     def Load(self, contentList = [], scrolltotop = 0, scrollTo = 0.0, *args):
    396         browser = GetBrowser(self)
    397         if browser:
    398             self.attrStack = browser.attrStack
    399             self.css = browser.css
    400             self.LoadFont()
    401         self.LoadContent(contentList)
    402 
    403     def Startup(self, *args):
    404         pass
    405 
    406     def GetNodes(self):
    407         return self.sr.entries
    408 
    409     def LoadContent(self, contentList = [], *args):
    410         for data in contentList:
    411             if not data.panel:
    412                 entry = self.AddEntry(data)
    413 
    414         self.sr.overlays_content.left = self.attrStack[-1]['border-left-width']
    415         self.sr.overlays_content.top = self.attrStack[-1]['border-top-width']
    416         self.CheckOverlaysAndUnderlays()
    417 
    418     def GetMinWidth(self, singleWordMax):
    419         s = self.celldata.styles
    420         sideAddon = s['border-left-width'] + s['border-right-width'] + s['padding-left'] + s['padding-right'] + s['margin-left'] + s['margin-right']
    421         self.LoadBuffer(self.celldata.content[:], getWidths=1, singleWordMax=singleWordMax)
    422         if not self or getattr(self, 'sr', None) is None:
    423             return (0, 0)
    424         setWidth = int(self.celldata.Get('width', None) or 0)
    425         minOverlay = 0
    426         for overlay, attrs, x, y in self.sr.overlays:
    427             minOverlay = max(minOverlay, x + int(attrs.width) + int((attrs.Get('border', 0) or 0) * 2))
    428 
    429         return (max(self.minWidth + sideAddon + minOverlay, setWidth), setWidth)
    430 
    431     def GetMinHeight(self):
    432         if not self.celldata or self.destroyed:
    433             return 0
    434         h = int(self.celldata.Get('height', None) or self.rowdata.Get('height', None) or 1)
    435         s = self.celldata.styles
    436         topAddon = s['border-top-width'] + s['border-bottom-width'] + s['padding-top'] + s['padding-bottom'] + s['margin-top'] + s['margin-bottom']
    437         self.attrStack.append(s)
    438         self.LoadBuffer(self.celldata.content[:], setWidth=self.width)
    439         if self.destroyed:
    440             return 0
    441         minOverlay = 0
    442         for overlay, attrs, x, y in self.sr.overlays:
    443             minOverlay = max(minOverlay, y + int(attrs.height) + int((attrs.Get('border', 0) or 0) * 2))
    444 
    445         return max(h, self.contentHeight + topAddon, minOverlay)
    446 
    447     def VAlignContent(self):
    448         if not self or self.destroyed:
    449             return
    450         s = self.celldata.styles
    451         if s['vertical-align'] == parser.ALIGNMIDDLE:
    452             self.sr.content.top = s['padding-top'] + s['margin-top'] - s['border-top-width'] + (self.height - s['padding-top'] - s['margin-top'] - s['padding-bottom'] - s['margin-bottom'] - self.contentHeight) / 2
    453         elif s['vertical-align'] == parser.ALIGNBOTTOM:
    454             self.sr.content.top = self.height - self.contentHeight - s['border-top-width'] - s['border-bottom-width'] - s['padding-bottom'] - s['margin-bottom']
    455         elif s['vertical-align'] == parser.ALIGNTOP:
    456             self.sr.content.top = s['padding-top'] + s['margin-top']
    457         self.sr.content.left = -s['border-left-width']
    458 
    459     def AddEntry(self, entry):
    460         entry.panel = None
    461         entry.open = 0
    462         entry.idx = len(self.sr.entries)
    463         entry.isSub = 0
    464         entry.selected = entry.Get('isSelected', 0)
    465         if entry.Get('PreLoadFunction', None):
    466             entry.PreLoadFunction(entry)
    467         self.sr.entries.append(entry)
    468         self.AddPanel(entry)
    469 
    470     def AddPanel(self, entry):
    471         w = entry.decoClass(parent=self.sr.content, align=uiconst.TOTOP)
    472         entry.panel = w
    473         entry.scroll = self.sr.selfProxy
    474         if hasattr(w, 'Startup'):
    475             w.Startup()
    476         entry.panel.height = entry.Get('maxBaseHeight', 1)
    477         w.sr.node = entry
    478         entry.SelectionHandler = None
    479         w.name = 'cellContent'
    480         w.Load(entry)
    481         w.state = uiconst.UI_PICKCHILDREN
    482 
    483     def CheckOverlaysAndUnderlays(self):
    484         for overlay, attrs, x, y in self.sr.overlays:
    485             if not overlay.loaded:
    486                 overlay.Load()
    487             overlay.top = attrs.top
    488             overlay.left = attrs.left
    489             self.contentHeight = max(self.contentHeight, overlay.top + overlay.height)
    490 
    491     def GetInt(self, string):
    492         value = filter(lambda x: x in '0123456789', unicode(string))
    493         try:
    494             value = int(value)
    495         except:
    496             sys.exc_clear()
    497 
    498         return value
    499 
    500 
    501 class DivOverlay(Cell):
    502     __guid__ = 'uicls.SE_div'
    503     __params__ = []
    504 
    505     def Startup(self, *args):
    506         attrs = self.data.attrs
    507         self.name = 'div'
    508         browser = GetBrowser(self)
    509         contentWidth = browser.GetContentWidth()
    510         self.width = width = self.GetPercent(attrs.stack['width'] or contentWidth - attrs.stack.get('left', 0), contentWidth - attrs.stack.get('left', 0))
    511         self.height = attrs.stack['height'] or 32
    512         self.SetAlign(uiconst.RELATIVE)
    513         self.AddBackground(self, attrs.stack)
    514         self.LoadBuffer(self.data.attrs.content, setWidth=self.width)
    515         self.CheckOverlaysAndUnderlays()
    516         self.width = attrs.width = width or self.contentWidth
    517         self.height = attrs.height = attrs.stack.get('height', None) or self.contentHeight
    518         if attrs.stack['position'] == 'absolute':
    519             self.left = attrs.left = attrs.stack.get('left', 0)
    520             self.top = attrs.top = attrs.stack.get('top', 0)
    521         elif attrs.stack['position'] == 'relative' and attrs.stack['align']:
    522             if attrs.stack['align'] == 'center':
    523                 aL, aT, aW, aH = self.parent.GetAbsolute()
    524                 self.left = attrs.left = (aW - self.width) / 2
    525             elif attrs.stack['align'] == 'right':
    526                 aL, aT, aW, aH = self.parent.GetAbsolute()
    527                 self.left = attrs.left = aW - self.width
    528             else:
    529                 self.left = attrs.left
    530             self.top = attrs.top
    531         elif attrs.stack['float'] in ('left', 'right'):
    532             self.left = attrs.left
    533             self.top = attrs.top
    534 
    535     def FindCellAbove(self, wnd):
    536         if wnd is uicore.desktop:
    537             return None
    538         if isinstance(wnd, DivOverlay):
    539             return wnd
    540         return self.FindCellAbove(wnd.parent)
    541 
    542     def Load(self):
    543         if not self.loaded:
    544             self.loaded = 1
    545             Cell.Load(self, contentList=self.sr.lines)
    546             self.state = uiconst.UI_NORMAL
    547 
    548     def AddBackground(self, where, s):
    549         contentWidth = GetBrowser(self).GetContentWidth()
    550         for i, side in enumerate(['top',
    551          'left',
    552          'right',
    553          'bottom']):
    554             align = [uiconst.TOTOP,
    555              uiconst.TOLEFT,
    556              uiconst.TORIGHT,
    557              uiconst.TOBOTTOM][i]
    558             if s['margin-%s' % side]:
    559                 s['margin-%s' % side] = self.GetPercent(s['margin-%s' % side], contentWidth)
    560                 Container(name='margin-%s' % side, parent=where, align=align, padding=(0,
    561                  0,
    562                  int(s['margin-%s' % side]),
    563                  int(s['margin-%s' % side])), idx=0)
    564             if s['border-%s-width' % side]:
    565                 Line(parent=where, align=align, weight=s['border-%s-width' % side], color=s['border-%s-color' % side])
    566 
    567         if s['background-color']:
    568             Fill(parent=where, color=s['background-color'])
    569 
    570 
    571 class BorderUnderlay(SE_BaseClassCore):
    572     __guid__ = 'uicls.SE_border'
    573     __params__ = []
    574     default_showHilite = False
    575 
    576     def Startup(self, *args):
    577         self.width = self.data.attrs.width or 1
    578         self.height = self.data.attrs.height or 1
    579         self.left = self.data.attrs.left
    580 
    581     def Load(self):
    582         if not self.loaded:
    583             i = 0
    584             for each in ('tb', 'bb', 'lb', 'rb'):
    585                 if self.data.attrs.Get(each + 'style', None) in (None, 1, 2):
    586                     style = self.data.attrs.Get(each + 'style', 1)
    587                     color = self.data.attrs.Get(each + 'color', None)
    588                     weight = self.data.attrs.Get(each + 'width', None)
    589                     align = [uiconst.TOTOP,
    590                      uiconst.TOBOTTOM,
    591                      uiconst.TOLEFT,
    592                      uiconst.TORIGHT][i]
    593                     Line(parent=self, align=align, weight=weight, color=color)
    594                 i += 1
    595 
    596             color = self.data.attrs.Get('bgcolor', None)
    597             if color:
    598                 Fill(parent=self, state=uiconst.UI_DISABLED, color=color)
    599             self.state = uiconst.UI_NORMAL
    600             self.width = (self.data.attrs.width or 1) + (int(self.data.attrs.border or 0) + 0)
    601             self.height = (self.data.attrs.height or 1) + (int(self.data.attrs.border or 0) + 0)
    602             self.loaded = 1
    603 
    604 
    605 class ImgListentry(SE_BaseClassCore):
    606     __guid__ = 'uicls.SE_img'
    607     default_showHilite = False
    608     default_align = uiconst.RELATIVE
    609 
    610     def Startup(self, parser, *args):
    611         attrs = self.data.attrs
    612         self.width = (attrs.width or 1) + (attrs.leftmargin + attrs.rightmargin + attrs.leftborder + attrs.rightborder)
    613         self.height = (attrs.height or 1) + (attrs.topmargin + attrs.bottommargin + attrs.topborder + attrs.bottomborder)
    614         contentWidth = parser.GetContentWidth()
    615         if attrs.Get('align', None) == 'right':
    616             self.left = contentWidth - self.width - attrs.left
    617             self.name = 'rightdude'
    618         elif attrs.Get('align', None) == 'left':
    619             self.left = self.data.attrs.left
    620         self.AddBorders(self, attrs)
    621         attrs.pictureLeft = attrs.leftmargin + attrs.leftborder
    622         attrs.pictureTop = attrs.topmargin + attrs.topborder
    623         self.picloaded = 0
    624         self.pic = None
    625 
    626     def AddBorders(self, where, attrs):
    627         for i, side in enumerate(['top',
    628          'left',
    629          'right',
    630          'bottom']):
    631             align = [uiconst.TOTOP,
    632              uiconst.TOLEFT,
    633              uiconst.TORIGHT,
    634              uiconst.TOBOTTOM][i]
    635             if attrs.Get('%smargin' % side, 0):
    636                 Container(name='margin-%s' % side, parent=where, align=align, padding=(0,
    637                  0,
    638                  attrs.Get('%smargin-' % side, 0),
    639                  attrs.Get('%smargin-' % side, 0)), idx=0)
    640             if attrs.Get('%sborder' % side, 0):
    641                 Line(parent=where, align=align, weight=attrs.Get('%sborder' % side, 0), color=attrs.Get('%scolor' % side, None))
    642 
    643     def Load(self):
    644         if not self.loaded:
    645             self.loaded = 1
    646             if not self.picloaded:
    647                 self.LoadPicture()
    648             self.state = uiconst.UI_PICKCHILDREN
    649 
    650     def GetValue(self):
    651         return '<img:%s>' % self.data.attrs.src
    652 
    653     def LoadPicture(self):
    654         if self.pic is None:
    655             self.pic = Image(name='img', align=uiconst.RELATIVE)
    656         self.children.append(self.pic)
    657         self.pic.Load(self.data.attrs)
    658         self.pic.attrs.texture = None
    659         self.picloaded = 1