Example #1
0
void TextRange::setRange (const KTextEditor::Range &range)
{
  // avoid work if nothing changed!
  if (range == toRange())
    return;

  // remember old line range
  int oldStartLine = m_start.line();
  int oldEndLine = m_end.line();

  // change start and end cursor
  m_start.setPosition (range.start ());
  m_end.setPosition (range.end ());

  // check if range now invalid, don't emit feedback here, will be handled below
  // otherwise you can't delete ranges in feedback!
  checkValidity (oldStartLine, oldEndLine, false);

  // no attribute or feedback set, be done
  if (!m_attribute && !m_feedback)
    return;

  // get full range
  int startLineMin = oldStartLine;
  if (oldStartLine == -1 || (m_start.line() != -1 && m_start.line() < oldStartLine))
    startLineMin = m_start.line();

  int endLineMax = oldEndLine;
  if (oldEndLine == -1 || m_end.line() > oldEndLine)
    endLineMax = m_end.line();

  /**
   * notify buffer about attribute change, it will propagate the changes
   * notify right view
   */
  m_buffer.notifyAboutRangeChange (m_view, startLineMin, endLineMax, m_attribute);

  // perhaps need to notify stuff!
  if (m_feedback) {
    // do this last: may delete this range
    if (!toRange().isValid())
      m_feedback->rangeInvalid (this);
    else if (toRange().isEmpty())
      m_feedback->rangeEmpty (this);
  }
}
Example #2
0
JSValue* jsRangePrototypeFunctionCompareBoundaryPoints(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)
{
    if (!thisValue->isObject(&JSRange::s_info))
        return throwError(exec, TypeError);
    JSRange* castedThisObj = static_cast<JSRange*>(thisValue);
    Range* imp = static_cast<Range*>(castedThisObj->impl());
    ExceptionCode ec = 0;
    Range::CompareHow how = static_cast<Range::CompareHow>(args[0]->toInt32(exec));
    Range* sourceRange = toRange(args[1]);


    KJS::JSValue* result = jsNumber(exec, imp->compareBoundaryPoints(how, sourceRange, ec));
    setDOMException(exec, ec);
    return result;
}
EncodedJSValue JSC_HOST_CALL jsDOMSelectionPrototypeFunctionAddRange(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSDOMSelection::s_info))
        return throwVMTypeError(exec);
    JSDOMSelection* castedThis = static_cast<JSDOMSelection*>(asObject(thisValue));
    ASSERT_GC_OBJECT_INHERITS(castedThis, &JSDOMSelection::s_info);
    DOMSelection* imp = static_cast<DOMSelection*>(castedThis->impl());
    Range* range(toRange(exec->argument(0)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    imp->addRange(range);
    return JSValue::encode(jsUndefined());
}
Example #4
0
bool KCSheetModel::setData(const QItemSelectionRange &range, const QVariant &value, int role)
{
    const KCRegion region(toRange(range), d->sheet);
    KCCellStorage *const storage = d->sheet->cellStorage();
    switch (role) {
    case CommentRole:
        storage->setComment(region, value.toString());
        break;
    case ConditionRole:
        storage->setConditions(region, value.value<KCConditions>());
        break;
    case FusionedRangeRole:
        // TODO
//         storage->setFusion(region, value.value<bool>());
        break;
    case LockedRangeRole:
        // TODO
//         storage->setMatrix(region, value.value<bool>());
        break;
    case NamedAreaRole:
        storage->emitInsertNamedArea(region, value.toString());
            break;
    case SourceRangeRole:
        storage->setBinding(region, value.value<KCBinding>());
        break;
    case StyleRole:
        // TODO
//         storage->setStyle(region, value.value<KCStyle>());
        break;
    case TargetRangeRole:
        storage->setDatabase(region, value.value<Database>());
        break;
    case ValidityRole:
        storage->setValidity(region, value.value<KCValidity>());
        break;
    default:
        return false;
    }
    emit dataChanged(range.topLeft(), range.bottomRight());
    return true;
}
Example #5
0
JSValue* JSRangePrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
{
    if (!thisObj->inherits(&JSRange::info))
      return throwError(exec, TypeError);

    Range* imp = static_cast<Range*>(static_cast<JSRange*>(thisObj)->impl());

    switch (id) {
    case JSRange::SetStartFuncNum: {
        ExceptionCode ec = 0;
        Node* refNode = toNode(args[0]);
        bool offsetOk;
        int offset = args[1]->toInt32(exec, offsetOk);
        if (!offsetOk) {
            setDOMException(exec, TYPE_MISMATCH_ERR);
            return jsUndefined();
        }

        imp->setStart(refNode, offset, ec);
        setDOMException(exec, ec);
        return jsUndefined();
    }
    case JSRange::SetEndFuncNum: {
        ExceptionCode ec = 0;
        Node* refNode = toNode(args[0]);
        bool offsetOk;
        int offset = args[1]->toInt32(exec, offsetOk);
        if (!offsetOk) {
            setDOMException(exec, TYPE_MISMATCH_ERR);
            return jsUndefined();
        }

        imp->setEnd(refNode, offset, ec);
        setDOMException(exec, ec);
        return jsUndefined();
    }
    case JSRange::SetStartBeforeFuncNum: {
        ExceptionCode ec = 0;
        Node* refNode = toNode(args[0]);

        imp->setStartBefore(refNode, ec);
        setDOMException(exec, ec);
        return jsUndefined();
    }
    case JSRange::SetStartAfterFuncNum: {
        ExceptionCode ec = 0;
        Node* refNode = toNode(args[0]);

        imp->setStartAfter(refNode, ec);
        setDOMException(exec, ec);
        return jsUndefined();
    }
    case JSRange::SetEndBeforeFuncNum: {
        ExceptionCode ec = 0;
        Node* refNode = toNode(args[0]);

        imp->setEndBefore(refNode, ec);
        setDOMException(exec, ec);
        return jsUndefined();
    }
    case JSRange::SetEndAfterFuncNum: {
        ExceptionCode ec = 0;
        Node* refNode = toNode(args[0]);

        imp->setEndAfter(refNode, ec);
        setDOMException(exec, ec);
        return jsUndefined();
    }
    case JSRange::CollapseFuncNum: {
        ExceptionCode ec = 0;
        bool toStart = args[0]->toBoolean(exec);

        imp->collapse(toStart, ec);
        setDOMException(exec, ec);
        return jsUndefined();
    }
    case JSRange::SelectNodeFuncNum: {
        ExceptionCode ec = 0;
        Node* refNode = toNode(args[0]);

        imp->selectNode(refNode, ec);
        setDOMException(exec, ec);
        return jsUndefined();
    }
    case JSRange::SelectNodeContentsFuncNum: {
        ExceptionCode ec = 0;
        Node* refNode = toNode(args[0]);

        imp->selectNodeContents(refNode, ec);
        setDOMException(exec, ec);
        return jsUndefined();
    }
    case JSRange::CompareBoundaryPointsFuncNum: {
        ExceptionCode ec = 0;
        Range::CompareHow how = static_cast<Range::CompareHow>(args[0]->toInt32(exec));
        Range* sourceRange = toRange(args[1]);


        KJS::JSValue* result = jsNumber(imp->compareBoundaryPoints(how, sourceRange, ec));
        setDOMException(exec, ec);
        return result;
    }
    case JSRange::DeleteContentsFuncNum: {
        ExceptionCode ec = 0;

        imp->deleteContents(ec);
        setDOMException(exec, ec);
        return jsUndefined();
    }
    case JSRange::ExtractContentsFuncNum: {
        ExceptionCode ec = 0;


        KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->extractContents(ec)));
        setDOMException(exec, ec);
        return result;
    }
    case JSRange::CloneContentsFuncNum: {
        ExceptionCode ec = 0;


        KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->cloneContents(ec)));
        setDOMException(exec, ec);
        return result;
    }
    case JSRange::InsertNodeFuncNum: {
        ExceptionCode ec = 0;
        Node* newNode = toNode(args[0]);

        imp->insertNode(newNode, ec);
        setDOMException(exec, ec);
        return jsUndefined();
    }
    case JSRange::SurroundContentsFuncNum: {
        ExceptionCode ec = 0;
        Node* newParent = toNode(args[0]);

        imp->surroundContents(newParent, ec);
        setDOMException(exec, ec);
        return jsUndefined();
    }
    case JSRange::CloneRangeFuncNum: {
        ExceptionCode ec = 0;


        KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->cloneRange(ec)));
        setDOMException(exec, ec);
        return result;
    }
    case JSRange::ToStringFuncNum: {
        ExceptionCode ec = 0;


        KJS::JSValue* result = jsString(imp->toString(ec));
        setDOMException(exec, ec);
        return result;
    }
    case JSRange::DetachFuncNum: {
        ExceptionCode ec = 0;

        imp->detach(ec);
        setDOMException(exec, ec);
        return jsUndefined();
    }
    case JSRange::CreateContextualFragmentFuncNum: {
        ExceptionCode ec = 0;
        String html = args[0]->toString(exec);


        KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->createContextualFragment(html, ec)));
        setDOMException(exec, ec);
        return result;
    }
    case JSRange::IntersectsNodeFuncNum: {
        ExceptionCode ec = 0;
        Node* refNode = toNode(args[0]);


        KJS::JSValue* result = jsBoolean(imp->intersectsNode(refNode, ec));
        setDOMException(exec, ec);
        return result;
    }
    case JSRange::CompareNodeFuncNum: {
        ExceptionCode ec = 0;
        Node* refNode = toNode(args[0]);


        KJS::JSValue* result = jsNumber(imp->compareNode(refNode, ec));
        setDOMException(exec, ec);
        return result;
    }
    case JSRange::ComparePointFuncNum: {
        ExceptionCode ec = 0;
        Node* refNode = toNode(args[0]);
        bool offsetOk;
        int offset = args[1]->toInt32(exec, offsetOk);
        if (!offsetOk) {
            setDOMException(exec, TYPE_MISMATCH_ERR);
            return jsUndefined();
        }


        KJS::JSValue* result = jsNumber(imp->comparePoint(refNode, offset, ec));
        setDOMException(exec, ec);
        return result;
    }
    case JSRange::IsPointInRangeFuncNum: {
        ExceptionCode ec = 0;
        Node* refNode = toNode(args[0]);
        bool offsetOk;
        int offset = args[1]->toInt32(exec, offsetOk);
        if (!offsetOk) {
            setDOMException(exec, TYPE_MISMATCH_ERR);
            return jsUndefined();
        }


        KJS::JSValue* result = jsBoolean(imp->isPointInRange(refNode, offset, ec));
        setDOMException(exec, ec);
        return result;
    }
    }
    return 0;
}