void EnhancedTagAttributeTree::deleteSubTree() { QuantaView *view = ViewManager::ref()->activeView(); if(!curNode || !view->document()) return; Node *oldCurNode; NodeModifsSet *modifs; int curLine, curCol; long offset; DOM::Node domNode; QValueList<int> loc; //Save the cursor position in kafka/quanta if(view->hadLastFocus() == QuantaView::SourceFocus) curNode->tag->beginPos(curLine, curCol); else { KafkaDocument::ref()->getKafkaWidget()->getCurrentNode(domNode, offset); if(!domNode.previousSibling().isNull()) domNode = domNode.previousSibling(); else if(!domNode.parentNode().isNull()) domNode = domNode.parentNode(); else domNode = KafkaDocument::ref()->getKafkaWidget()->document(); if(domNode.nodeType() == DOM::Node::TEXT_NODE) offset = domNode.nodeValue().length(); else offset = 0; loc = kafkaCommon::getLocation(domNode); } //Remove the Nodes oldCurNode = curNode; curNode = 0L; attrTree->setCurrentNode(curNode); modifs = new NodeModifsSet(); kafkaCommon::extractAndDeleteNode(oldCurNode, modifs); view->document()->docUndoRedo->addNewModifsSet(modifs, undoRedo::NodeTreeModif); //set the cursor position in kafka/quanta if(view->hadLastFocus() == QuantaView::SourceFocus) view->document()->viewCursorIf->setCursorPositionReal((uint)curLine, (uint)curCol); else { domNode = kafkaCommon::getNodeFromLocation(loc, KafkaDocument::ref()->getKafkaWidget()->document()); KafkaDocument::ref()->getKafkaWidget()->setCurrentNode(domNode, offset); } }
void DOMTreeView::slotAddTextDlg() { DOMListViewItem *item = static_cast<DOMListViewItem *>(m_listView->currentItem()); if (!item) return; QString text; SignalReceiver addBefore; { TextEditDialog dlg(this, "TextEditDialog", true); connect(dlg.insBeforeBtn, SIGNAL(clicked()), &addBefore, SLOT(slot())); if (dlg.exec() != QDialog::Accepted) return; text = dlg.textPane->text(); } DOM::Node curNode = item->node(); try { DOM::Node parent = addBefore() ? curNode.parentNode() : curNode; DOM::Node after = addBefore() ? curNode : 0; DOM::Node newNode = curNode.ownerDocument().createTextNode(text); ManipulationCommand *cmd = new InsertNodeCommand(newNode, parent, after); mainWindow()->executeAndAddCommand(cmd); if (cmd->isValid()) activateNode(newNode); } catch (DOM::DOMException &ex) { mainWindow()->addMessage(ex.code, domErrorMessage(ex.code)); } }
static void clear_from(DOM::Node n) { DOM::Node p = n.parentNode(); while(1) { DOM::Node next = n.nextSibling(); p.removeChild(n); if(next.isNull()) break; n = next; } }
long khtml::MouseEvent::offset() const { Position pos; if (innerNode().handle()) { // FIXME: Shouldn't be necessary to skip text nodes. DOM::Node inner = innerNode(); if (inner.nodeType() == Node::TEXT_NODE) { inner = inner.parentNode(); } pos = inner.handle()->positionForCoordinates(m_x, m_y).position(); } return pos.offset(); }
void DOMTreeView::moveToParent() { // This is a hypersmart algorithm. // If infoNode is defined, go to the parent of infoNode, otherwise, go // to the parent of the tree view's current item. // Hope this isn't too smart. DOM::Node cur = infoNode; if (cur.isNull()) cur = static_cast<DOMListViewItem *>(m_listView->currentItem())->node(); if (cur.isNull()) return; cur = cur.parentNode(); activateNode(cur); }
void DOMTreeView::slotAddElementDlg() { DOMListViewItem *item = static_cast<DOMListViewItem *>(m_listView->currentItem()); if (!item) return; QString qname; QString namespc; SignalReceiver addBefore; { ElementEditDialog dlg(this); dlg.setModal(true); connect(dlg.button(KDialog::User2), SIGNAL(clicked()), &addBefore, SLOT(slot())); // ### activate when namespaces are supported dlg.elemNamespace->setEnabled(false); if (dlg.exec() != QDialog::Accepted) return; qname = dlg.elemName->text(); namespc = dlg.elemNamespace->currentText(); } DOM::Node curNode = item->node(); try { DOM::Node parent = addBefore() ? curNode.parentNode() : curNode; DOM::Node after = addBefore() ? curNode : 0; // ### take namespace into account DOM::Node newNode = curNode.ownerDocument().createElement(qname); ManipulationCommand *cmd = new InsertNodeCommand(newNode, parent, after); mainWindow()->executeAndAddCommand(cmd); if (cmd->isValid()) activateNode(newNode); } catch (DOM::DOMException &ex) { mainWindow()->addMessage(ex.code, domErrorMessage(ex.code)); } }
void EnhancedTagAttributeTree::deleteNode() { QuantaView *view = ViewManager::ref()->activeView(); if(!curNode || !view->document()) return; Node *oldCurNode, *oldCurNodeParent, *child; QTag *oldCurNodeParentQTag; int curLine, curCol; long offset; DOM::Node domNode; QValueList<int> loc; NodeModifsSet *modifs; //Save the cursor position in kafka/quanta if(view->hadLastFocus() == QuantaView::SourceFocus) curNode->tag->beginPos(curLine, curCol); else { KafkaDocument::ref()->getKafkaWidget()->getCurrentNode(domNode, offset); if(!domNode.previousSibling().isNull()) domNode = domNode.previousSibling(); else if(!domNode.parentNode().isNull()) domNode = domNode.parentNode(); else domNode = KafkaDocument::ref()->getKafkaWidget()->document(); if(domNode.nodeType() == DOM::Node::TEXT_NODE) offset = domNode.nodeValue().length(); else offset = 0; loc = kafkaCommon::getLocation(domNode); } //remove the Nodes oldCurNode = curNode; oldCurNodeParent = curNode->parent; curNode = 0L; attrTree->setCurrentNode(curNode); modifs = new NodeModifsSet(); kafkaCommon::extractAndDeleteNode(oldCurNode, modifs, false); //Then we see if the new parent - child relationships are valid, and if not, delete the child and restart if(oldCurNodeParent) { oldCurNodeParentQTag = QuantaCommon::tagFromDTD(oldCurNodeParent); if(oldCurNodeParentQTag) { child = oldCurNodeParent->child; while(child) { if(!oldCurNodeParentQTag->isChild(child)) { kafkaCommon::extractAndDeleteNode(child, modifs, false); //too lazy to get the real next node ;-) child = oldCurNodeParent->child; } else child = child->next; } } } view->document()->docUndoRedo->addNewModifsSet(modifs, undoRedo::NodeTreeModif); //set the cursor position in kafka/quanta if(view->hadLastFocus() == QuantaView::SourceFocus) view->document()->viewCursorIf->setCursorPositionReal((uint)curLine, (uint)curCol); else { domNode = kafkaCommon::getNodeFromLocation(loc, KafkaDocument::ref()->getKafkaWidget()->document()); KafkaDocument::ref()->getKafkaWidget()->setCurrentNode(domNode, offset); } }
void HTMLEnhancer::postEnhanceNode(DOM::Node domNode) { DOM::Node textNode; kNodeAttrs *props; QTag *qTag; bool isInline; if(domNode.isNull()) return; //If domNode is a Block and there is no text around, and if domNode's parent can handle //text or a P tag, add an empty text DOM::Node // so that the user can access this area. qTag = QuantaCommon::tagFromDTD(m_wkafkapart->getCurrentDoc()->defaultDTD(), domNode.nodeName().string()); isInline = kafkaCommon::isInline(domNode.nodeName().string()); if(domNode.nodeType() == DOM::Node::ELEMENT_NODE && (!isInline || (isInline && qTag && qTag->isSingle()))) { qTag = QuantaCommon::tagFromDTD(m_wkafkapart->getNode(domNode.parentNode())); if((domNode.nextSibling().isNull() || (!domNode.nextSibling().isNull() && domNode.nextSibling().nodeType() == DOM::Node::ELEMENT_NODE && !kafkaCommon::isInline(domNode.nextSibling().nodeName().string()))) && qTag && (qTag->isChild("#text", false) || qTag->isChild("p", false)) && domNode.nodeName().string().lower() != "p") { textNode = kafkaCommon::createTextDomNode("", m_wkafkapart->getKafkaWidget()->document()); props = m_wkafkapart->connectDomNodeToQuantaNode(textNode, 0L); props->setIsLinkedToNode(false); props->setSpecialBehavior(kNodeAttrs::emptyTextSurroundingBlockElementAtTheRight); kafkaCommon::insertDomNode(textNode, domNode.parentNode(), domNode.nextSibling()); } if((domNode.previousSibling().isNull() || (!domNode.previousSibling().isNull() && domNode.previousSibling().nodeType() == DOM::Node::ELEMENT_NODE && !kafkaCommon::isInline(domNode.previousSibling().nodeName().string()))) && qTag && (qTag->isChild("#text", false) || qTag->isChild("p", false)) && domNode.nodeName().string().lower() != "p") { textNode = kafkaCommon::createTextDomNode("", m_wkafkapart->getKafkaWidget()->document()); props = m_wkafkapart->connectDomNodeToQuantaNode(textNode, 0L); props->setIsLinkedToNode(false); props->setSpecialBehavior(kNodeAttrs::emptyTextSurroundingBlockElementAtTheLeft); kafkaCommon::insertDomNode(textNode, domNode.parentNode(), domNode); } } //If domNode is an childless element, and if it can handle Text or a P tag, //add an empty text DOM::Node so that the //user can access this area. qTag = QuantaCommon::tagFromDTD(m_wkafkapart->getNode(domNode)); if(domNode.nodeType() == DOM::Node::ELEMENT_NODE && !domNode.hasChildNodes() && qTag && (qTag->isChild("#text", false) || qTag->isChild("p", false))) { textNode = kafkaCommon::createTextDomNode("", m_wkafkapart->getKafkaWidget()->document()); props = m_wkafkapart->connectDomNodeToQuantaNode(textNode, 0L); props->setIsLinkedToNode(false); props->setSpecialBehavior(kNodeAttrs::emptyTextAsChildOfAChildlessElement); kafkaCommon::insertDomNode(textNode, domNode); } }
MoveNodeCommand::MoveNodeCommand(const DOM::Node &node, const DOM::Node &parent, const DOM::Node &after) : _node(node), new_parent(parent), new_after(after) { old_parent = node.parentNode(); old_after = node.nextSibling(); }