Exemplo n.º 1
0
    def getEventTargetCell(self, event):
        td = DOM.eventGetTarget(event)
        while td is not None:
            if DOM.getAttribute(td, "tagName").lower() == "td":
                tr = DOM.getParent(td)
                body = DOM.getParent(tr)
                if DOM.compare(body, self.bodyElem):
                    return td
            if DOM.compare(td, self.bodyElem):
                return None
            td = DOM.getParent(td)

        return None
Exemplo n.º 2
0
    def getEventTargetCell(self, event):
        td = DOM.eventGetTarget(event)
        while td is not None:
            if DOM.getAttribute(td, "tagName").lower() == "td":
                tr = DOM.getParent(td)
                body = DOM.getParent(tr)
                if DOM.compare(body, self.bodyElem):
                    return td
            if DOM.compare(td, self.bodyElem):
                return None
            td = DOM.getParent(td)

        return None
Exemplo n.º 3
0
    def getSelectedTextElements(self, startNode=None, endNode=None):
        """
        Returns all text nodes between (and including) two arbitrary text nodes.
        Caller must ensure startNode comes before endNode.

        @param startNode start node to traverse
        @param endNode end node to finish traversal
        @return A list of all text nodes between these two text nodes
        """
        if startNode is None and endNode is None:
            startNode = self.m_startPoint.getTextNode()
            endNode = self.m_endPoint.getTextNode()

        res = []

        # print "getSelectedTextElements", startNode, endNode

        current = startNode
        while (current is not None) and (not DOM.compare(current, endNode)):
            res.append(current)

            current = RangeUtil.getAdjacentTextElement(current, None, True, False)

        if current is None:
            # With the old way this could have been backwards, but should not
            # happen now, so this is an error
            res = None
        else:
            res.append(current)

        return res
Exemplo n.º 4
0
    def getSelectedTextElements(self, startNode=None, endNode=None):
        """
        Returns all text nodes between (and including) two arbitrary text nodes.
        Caller must ensure startNode comes before endNode.

        @param startNode start node to traverse
        @param endNode end node to finish traversal
        @return A list of all text nodes between these two text nodes
        """
        if startNode is None and endNode is None:
            startNode = self.m_startPoint.getTextNode()
            endNode = self.m_endPoint.getTextNode()

        res = []

        #print "getSelectedTextElements", startNode, endNode

        current = startNode
        while (current is not None) and (not DOM.compare(current, endNode)):
            res.append(current)

            current = RangeUtil.getAdjacentTextElement(current, None, True,
                                                       False)

        if current is None:
            # With the old way this could have been backwards, but should not
            # happen now, so this is an error
            res = None
        else:
            res.append(current)

        return res
Exemplo n.º 5
0
    def getDividerIndex(self, elem):
        while (elem is not None) and not DOM.compare(elem, self.getElement()):
            expando = self._getIndex(elem)
            if expando is not None:
                return int(expando)

            elem = DOM.getParent(elem)

        return -1
Exemplo n.º 6
0
    def getDividerIndex(self, elem):
        while (elem is not None) and not DOM.compare(elem, self.getElement()):
            expando = self._getIndex(elem)
            if expando is not None:
                return int(expando)

            elem = DOM.getParent(elem)

        return -1
Exemplo n.º 7
0
    def setCurrentTargetElement(self, element):
        if self._currentTargetElement is not None:
            if not DOM.compare(self._currentTargetElement, element):
#                leave_event = self.makeDragEvent(self.mouseEvent, 'dragleave',
#                                                self.currentTargetElement)
                self.fireDNDEvent('dragleave', self.currentTargetElement,
                                  self.currentDropWidget)
#                self.currentDropWidget.onDragLeave(leave_event)
#                self.finalize(leave_event)
        self._currentTargetElement = element
Exemplo n.º 8
0
    def setCurrentTargetElement(self, element):
        if self._currentTargetElement is not None:
            if not DOM.compare(self._currentTargetElement, element):
                #                leave_event = self.makeDragEvent(self.mouseEvent, 'dragleave',
                #                                                self.currentTargetElement)
                self.fireDNDEvent('dragleave', self.currentTargetElement,
                                  self.currentDropWidget)
#                self.currentDropWidget.onDragLeave(leave_event)
#                self.finalize(leave_event)
        self._currentTargetElement = element
Exemplo n.º 9
0
    def equals(self, obj):
        res = False

        try:
            comp = obj

            res = (comp == self)  or  \
            (DOM.compare(comp.getNode(), self.getNode())  and  \
            (comp.getOffset() == self.getOffset()))
        except ex:
            pass

        return res
Exemplo n.º 10
0
    def equals(self, obj):
        res = False

        try:
            comp = obj

            res = (comp == self)  or  \
            (DOM.compare(comp.getNode(), self.getNode())  and  \
            (comp.getOffset() == self.getOffset()))
        except ex:
            pass

        return res
Exemplo n.º 11
0
 def compareTo(self, arg0):
     Candidate other = (Candidate) arg0
     
     Element myElement = getDropTarget().getElement()
     Element otherElement = other.getDropTarget().getElement()
     if DOM.compare(myElement, otherElement):
         return 0
      elif DOM.isOrHasChild(myElement, otherElement):
         return -1
      elif DOM.isOrHasChild(otherElement, myElement):
         return 1
      else:
         return 0
Exemplo n.º 12
0
    def findItemByChain(self, chain, idx, root):
        if idx == len(chain):
            return root

        hCurElem = chain[idx]
        for i in range(root.getChildCount()):
            child = root.getChild(i)
            if DOM.compare(child.getElement(), hCurElem):
                retItem = self.findItemByChain(chain, idx + 1, root.getChild(i))
                if retItem is None:
                    return child
                return retItem

        return self.findItemByChain(chain, idx + 1, root)
Exemplo n.º 13
0
def getAdjacentTextElement(current,
                           topMostNode,
                           forward=None,
                           traversingUp=False):
    if forward is None:
        forward = topMostNode
        topMostNode = None

    res = None

    #print "getAdjacentTextElement", current, topMostNode, forward, traversingUp

    # If traversingUp, then the children have already been processed
    if not traversingUp:
        if DOM.getChildCount(current) > 0:
            if forward:
                node = DOM.getFirstChild(current)
            else:
                node = DOM.getLastChild(current)

            if DOM.getNodeType(node) == DOM.TEXT_NODE:
                res = node
            else:
                # Depth first traversal, the recursive call deals with
                # siblings
                res = getAdjacentTextElement(node, topMostNode, forward, False)

    if res is None:
        if forward:
            node = current.nextSibling
        else:
            node = current.previousSibling
        # Traverse siblings
        if node is not None:
            if DOM.getNodeType(node) == DOM.TEXT_NODE:
                res = node
            else:
                #print node, DOM.getNodeType(node), node.innerHTML
                # Depth first traversal, the recursive call deals with
                # siblings
                res = getAdjacentTextElement(node, topMostNode, forward, False)

    # Go up and over if still not found
    if (res is None) and (not DOM.compare(current, topMostNode)):
        node = current.parentNode
        # Stop at document (technically could stop at "html" tag)
        if (node is not None)  and  \
                (DOM.getNodeType(node) != DOM.DOCUMENT_NODE):
            res = getAdjacentTextElement(node, topMostNode, forward, True)
    return res
Exemplo n.º 14
0
def getAdjacentTextElement(current, topMostNode, forward=None, traversingUp=False):
    if forward is None:
        forward = topMostNode
        topMostNode = None

    res = None

    #print "getAdjacentTextElement", current, topMostNode, forward, traversingUp

    # If traversingUp, then the children have already been processed
    if not traversingUp:
        if DOM.getChildCount(current) > 0:
            if forward:
                node = DOM.getFirstChild(current)
            else:
                node = DOM.getLastChild(current)

            if DOM.getNodeType(node) == DOM.TEXT_NODE:
                res = node
            else:
                # Depth first traversal, the recursive call deals with
                # siblings
                res = getAdjacentTextElement(node, topMostNode,
                                        forward, False)

    if res is None:
        if forward:
            node = current.nextSibling
        else:
            node = current.previousSibling
        # Traverse siblings
        if node is not None:
            if DOM.getNodeType(node) == DOM.TEXT_NODE:
                res = node
            else:
                #print node, DOM.getNodeType(node), node.innerHTML
                # Depth first traversal, the recursive call deals with
                # siblings
                res = getAdjacentTextElement(node, topMostNode,
                                        forward, False)

    # Go up and over if still not found
    if (res is None)  and  (not DOM.compare(current, topMostNode)):
        node = current.parentNode
        # Stop at document (technically could stop at "html" tag)
        if (node is not None)  and  \
                (DOM.getNodeType(node) != DOM.DOCUMENT_NODE):
            res = getAdjacentTextElement(node, topMostNode,
                                        forward, True)
    return res
Exemplo n.º 15
0
    def elementClicked(self, root, hElem):
        chain = []
        self.collectElementChain(chain, self.getElement(), hElem)

        item = self.findItemByChain(chain, 0, root)
        if item is not None:
            if DOM.compare(item.getImageElement(), hElem):
                item.setState(not item.getState(), True)
                return True
            elif DOM.isOrHasChild(item.getElement(), hElem):
                self.onSelection(item, True)
                return True

        return False
Exemplo n.º 16
0
    def elementClicked(self, root, hElem):
        chain = []
        self.collectElementChain(chain, self.getElement(), hElem)

        item = self.findItemByChain(chain, 0, root)
        if item is not None:
            if DOM.compare(item.getImageElement(), hElem):
                item.setState(not item.getState(), True)
                return True
            elif DOM.isOrHasChild(item.getElement(), hElem):
                self.onSelection(item, True)
                return True

        return False
Exemplo n.º 17
0
    def findItemByChain(self, chain, idx, root):
        if idx == len(chain):
            return root

        hCurElem = chain[idx]
        for i in range(root.getChildCount()):
            child = root.getChild(i)
            if DOM.compare(child.getElement(), hCurElem):
                retItem = self.findItemByChain(chain, idx + 1,
                                               root.getChild(i))
                if retItem is None:
                    return child
                return retItem

        return self.findItemByChain(chain, idx + 1, root)
Exemplo n.º 18
0
    def doDrag(self, event, x, y):
        self.dragBusy = True
        #self.dragDataStore.dropEffect = 'none'
        drag_event = self.fireDNDEvent('drag', None, self.dragWidget)
        # drag event was not canceled
        if not isCanceled(drag_event):
            target = None
            widget = None
            # Find the most specific element under the cursor and the widget
            # with the drop listener for it.
            for widget in self.dropTargets:
                target = getElementUnderMouse(widget, x, y)
                if target is not None:
                    break
            if target:
                drop_widget = widget
                drop_element = target
                if (not self.currentTargetElement or
                    not DOM.compare(drop_element, self.currentTargetElement)):
#                    enter_event = self.makeDragEvent(event,'dragenter',
#                                                     drop_element)
                    enter_event = self.fireDNDEvent('dragenter', drop_element,
                                                    drop_widget)
#                    drop_widget.onDragEnter(enter_event)
#                    self.finalize(enter_event)
                    if isCanceled(enter_event):
                        self.currentTargetElement = drop_element
                        self.currentDropWidget = drop_widget

                if self.currentTargetElement is not None:
                    # disable dropping if over event is not canceled
#                    over_event = self.makeDragEvent(event, 'dragover',
#                                                    drop_element)
                    over_event = self.fireDNDEvent('dragover', drop_element,
                                self.currentDropWidget)
#                    self.currentDropWidget.onDragOver(over_event)
#                    self.finalize(over_event)
                    if isCanceled(over_event):
                        self.updateDragOperation(over_event)
                    else:
                        self.currentDragOperation = 'none'
                    self.draggingImage.updateCursor(self.currentDragOperation)
            else:
                self.currentTargetElement = None

        else:
            self.currentDragOperation = 'none'
        self.dragBusy = False
Exemplo n.º 19
0
    def doDrag(self, event, x, y):
        self.dragBusy = True
        #self.dragDataStore.dropEffect = 'none'
        drag_event = self.fireDNDEvent('drag', None, self.dragWidget)
        # drag event was not canceled
        if not isCanceled(drag_event):
            target = None
            widget = None
            # Find the most specific element under the cursor and the widget
            # with the drop listener for it.
            for widget in self.dropTargets:
                target = getElementUnderMouse(widget, x, y)
                if target is not None:
                    break
            if target:
                drop_widget = widget
                drop_element = target
                if (not self.currentTargetElement or not DOM.compare(
                        drop_element, self.currentTargetElement)):
                    #                    enter_event = self.makeDragEvent(event,'dragenter',
                    #                                                     drop_element)
                    enter_event = self.fireDNDEvent('dragenter', drop_element,
                                                    drop_widget)
                    #                    drop_widget.onDragEnter(enter_event)
                    #                    self.finalize(enter_event)
                    if isCanceled(enter_event):
                        self.currentTargetElement = drop_element
                        self.currentDropWidget = drop_widget

                if self.currentTargetElement is not None:
                    # disable dropping if over event is not canceled
                    #                    over_event = self.makeDragEvent(event, 'dragover',
                    #                                                    drop_element)
                    over_event = self.fireDNDEvent('dragover', drop_element,
                                                   self.currentDropWidget)
                    #                    self.currentDropWidget.onDragOver(over_event)
                    #                    self.finalize(over_event)
                    if isCanceled(over_event):
                        self.updateDragOperation(over_event)
                    else:
                        self.currentDragOperation = 'none'
                    self.draggingImage.updateCursor(self.currentDragOperation)
            else:
                self.currentTargetElement = None

        else:
            self.currentDragOperation = 'none'
        self.dragBusy = False
Exemplo n.º 20
0
    def getSelectedTextElements(self, startNode=None, endNode=None):
        if startNode is None and endNode is None:
            startNode = self.m_startPoint.getTextNode()
            endNode = self.m_endPoint.getTextNode()

        res = []

        #print "getSelectedTextElements", startNode, endNode

        current = startNode
        while (current is not None) and (not DOM.compare(current, endNode)):
            res.append(current)

            current = RangeUtil.getAdjacentTextElement(current, None, True, False)

        if current is None:
            # With the old way this could have been backwards, but should not
            # happen now, so this is an error
            res = None
        else:
            res.append(current)

        return res
Exemplo n.º 21
0
 def appendAndMaybeAdopt(self, parent, child, beingAdded):
     if beingAdded is not None:
         if DOM.compare(child, beingAdded.getElement()):
             CellPanel.add(self, beingAdded, parent)
             return
     DOM.appendChild(parent, child)
Exemplo n.º 22
0
    def collectElementChain(self, chain, hRoot, hElem):
        if (hElem is None) or DOM.compare(hElem, hRoot):
            return

        self.collectElementChain(chain, hRoot, DOM.getParent(hElem))
        chain.append(hElem)
Exemplo n.º 23
0
    def collectElementChain(self, chain, hRoot, hElem):
        if (hElem is None) or DOM.compare(hElem, hRoot):
            return

        self.collectElementChain(chain, hRoot, DOM.getParent(hElem))
        chain.append(hElem)
Exemplo n.º 24
0
 def appendAndMaybeAdopt(self, parent, child, beingAdded):
     if beingAdded is not None:
         if DOM.compare(child, beingAdded.getElement()):
             CellPanel.add(self, beingAdded, parent)
             return
     DOM.appendChild(parent, child)