// Set the cursor offset.
void QsciAccessibleScintillaBase::setCursorPosition(int position)
{
    QsciScintillaBase *sb = sciWidget();

    sb->SendScintilla(QsciScintillaBase::SCI_GOTOPOS,
            offsetAsPosition(sb, position));
}
// Return the number of characters in the text.
int QsciAccessibleScintillaBase::characterCount() const
{
    QsciScintillaBase *sb = sciWidget();

    return sb->SendScintilla(QsciScintillaBase::SCI_COUNTCHARACTERS, 0,
            sb->SendScintilla(QsciScintillaBase::SCI_GETTEXTLENGTH));
}
// Return the fragment of text after an offset.
QString QsciAccessibleScintillaBase::textAfterOffset(int offset,
        QAccessible::TextBoundaryType boundaryType, int *startOffset,
        int *endOffset) const
{
    QsciScintillaBase *sb = sciWidget();

    // Initialise in case of errors.
    *startOffset = *endOffset = -1;

    int position = validPosition(offset);

    if (position < 0)
        return QString();

    int start_position, end_position;

    if (!boundaries(sb, position, boundaryType, &start_position, &end_position))
        return QString();

    if (end_position >= sb->SendScintilla(QsciScintillaBase::SCI_GETTEXTLENGTH))
        return QString();

    if (!boundaries(sb, end_position, boundaryType, &start_position, &end_position))
        return QString();

    positionRangeAsOffsetRange(sb, start_position, end_position, startOffset,
            endOffset);

    return textRange(sb, start_position, end_position);
}
// Insert some text.
void QsciAccessibleScintillaBase::insertText(int offset, const QString &text)
{
    QsciScintillaBase *sb = sciWidget();

    sb->SendScintilla(QsciScintillaBase::SCI_INSERTTEXT,
            offsetAsPosition(sb, offset), textAsBytes(sb, text).constData());
}
// Scroll to make sure an area of text is visible.
void QsciAccessibleScintillaBase::scrollToSubstring(int startIndex,
        int endIndex)
{
    QsciScintillaBase *sb = sciWidget();
    int start = offsetAsPosition(sb, startIndex);
    int end = offsetAsPosition(sb, endIndex);

    sb->SendScintilla(QsciScintillaBase::SCI_SCROLLRANGE, end, start);
}
// Replace some text.
void QsciAccessibleScintillaBase::replaceText(int startOffset, int endOffset,
        const QString &text)
{
    QsciScintillaBase *sb = sciWidget();

    addSelection(startOffset, endOffset);
    sb->SendScintilla(QsciScintillaBase::SCI_REPLACESEL,
            textAsBytes(sb, text).constData());
}
// Return the offset of the character at the given screen coordinates.
int QsciAccessibleScintillaBase::offsetAtPoint(const QPoint &point) const
{
    QsciScintillaBase *sb = sciWidget();
    QPoint p = sb->viewport()->mapFromGlobal(point);
    int position = sb->SendScintilla(QsciScintillaBase::SCI_POSITIONFROMPOINT,
            p.x(), p.y());

    return (position >= 0) ? positionAsOffset(sb, position) : -1;
}
// Set the selection.
void QsciAccessibleScintillaBase::setSelection(int selectionIndex,
        int startOffset, int endOffset)
{
    if (selectionIndex == 0)
    {
        QsciScintillaBase *sb = sciWidget();
        sb->SendScintilla(QsciScintillaBase::SCI_SETSELECTIONSTART,
                offsetAsPosition(sb, startOffset));
        sb->SendScintilla(QsciScintillaBase::SCI_SETSELECTIONEND,
                offsetAsPosition(sb, endOffset));
    }
}
示例#9
0
// Set the color attribute.
void QsciStyle::setColor(const QColor &color)
{
    style_color = color;

    if (style_nr >= 0)
    {
        QsciScintillaBase *sci = QsciScintillaBase::pool();

        if (sci)
            sci->SendScintilla(QsciScintillaBase::SCI_STYLESETFORE, style_nr,
                    style_color);
    }
}
示例#10
0
// Set the hotspot attribute.
void QsciStyle::setHotspot(bool hotspot)
{
    style_hotspot = hotspot;

    if (style_nr >= 0)
    {
        QsciScintillaBase *sci = QsciScintillaBase::pool();

        if (sci)
            sci->SendScintilla(QsciScintillaBase::SCI_STYLESETHOTSPOT,
                    style_nr, style_hotspot);
    }
}
示例#11
0
// Set the changeable attribute.
void QsciStyle::setChangeable(bool changeable)
{
    style_changeable = changeable;

    if (style_nr >= 0)
    {
        QsciScintillaBase *sci = QsciScintillaBase::pool();

        if (sci)
            sci->SendScintilla(QsciScintillaBase::SCI_STYLESETCHANGEABLE,
                    style_nr, style_changeable);
    }
}
示例#12
0
// Set the visible attribute.
void QsciStyle::setVisible(bool visible)
{
    style_visible = visible;

    if (style_nr >= 0)
    {
        QsciScintillaBase *sci = QsciScintillaBase::pool();

        if (sci)
            sci->SendScintilla(QsciScintillaBase::SCI_STYLESETVISIBLE,
                    style_nr, style_visible);
    }
}
示例#13
0
// Set the text case attribute.
void QsciStyle::setTextCase(QsciStyle::TextCase text_case)
{
    style_case = text_case;

    if (style_nr >= 0)
    {
        QsciScintillaBase *sci = QsciScintillaBase::pool();

        if (sci)
            sci->SendScintilla(QsciScintillaBase::SCI_STYLESETCASE, style_nr,
                    (long)style_case);
    }
}
示例#14
0
// Set the eol fill attribute.
void QsciStyle::setEolFill(bool eolFill)
{
    style_eol_fill = eolFill;

    if (style_nr >= 0)
    {
        QsciScintillaBase *sci = QsciScintillaBase::pool();

        if (sci)
            sci->SendScintilla(QsciScintillaBase::SCI_STYLESETEOLFILLED,
                    style_nr, style_eol_fill);
    }
}
示例#15
0
// Set the paper attribute.
void QsciStyle::setPaper(const QColor &paper)
{
    style_paper = paper;

    if (style_nr >= 0)
    {
        QsciScintillaBase *sci = QsciScintillaBase::pool();

        if (sci)
            sci->SendScintilla(QsciScintillaBase::SCI_STYLESETBACK, style_nr,
                    style_paper);
    }
}
// Convert a integer colour to an RGB string.
QFont QsciAccessibleScintillaBase::fontForStyle(int style) const
{
    QsciScintillaBase *sb = sciWidget();
    char fontName[64];
    int len = sb->SendScintilla(QsciScintillaBase::SCI_STYLEGETFONT, style,
            fontName);
    int size = sb->SendScintilla(QsciScintillaBase::SCI_STYLEGETSIZE, style);
    bool italic = sb->SendScintilla(QsciScintillaBase::SCI_STYLEGETITALIC,
            style);
    int weight = sb->SendScintilla(QsciScintillaBase::SCI_STYLEGETWEIGHT,
            style);

    return QFont(QString::fromUtf8(fontName, len), size, weight, italic);
}
QRect QsciAccessibleScintillaBase::characterRect(int offset) const
{
    QsciScintillaBase *sb = sciWidget();
    int position = offsetAsPosition(sb, offset);
    int x_vport = sb->SendScintilla(QsciScintillaBase::SCI_POINTXFROMPOSITION,
            position);
    int y_vport = sb->SendScintilla(QsciScintillaBase::SCI_POINTYFROMPOSITION,
            position);
    const QString ch = text(offset, offset + 1);

    // Get the character's font metrics.
    int style = sb->SendScintilla(QsciScintillaBase::SCI_GETSTYLEAT, position);
    QFontMetrics metrics(fontForStyle(style));

    QRect rect(x_vport, y_vport, metrics.width(ch), metrics.height());
    rect.moveTo(sb->viewport()->mapToGlobal(rect.topLeft()));

    return rect;
}
示例#18
0
// Detach the underlying document.
void QsciDocument::detach()
{
    if (!pdoc)
        return;

    if (--pdoc->nr_attaches == 0)
    {
        if (pdoc->doc && pdoc->nr_displays == 0)
        {
            QsciScintillaBase *qsb = QsciScintillaBase::pool();

            // Release the explicit reference to the document.  If the pool is
            // empty then we just accept the memory leak.
            if (qsb)
                qsb->SendScintilla(QsciScintillaBase::SCI_RELEASEDOCUMENT, 0,
                                   pdoc->doc);
        }

        delete pdoc;
    }

    pdoc = 0;
}
// Get the current selection if any.
void QsciAccessibleScintillaBase::selection(int selectionIndex,
        int *startOffset, int *endOffset) const
{
    int start, end;

    if (selectionIndex == 0 && is_selection)
    {
        QsciScintillaBase *sb = sciWidget();
        int start_position = sb->SendScintilla(
                QsciScintillaBase::SCI_GETSELECTIONSTART);
        int end_position = sb->SendScintilla(
                QsciScintillaBase::SCI_GETSELECTIONEND);

        start = positionAsOffset(sb, start_position);
        end = positionAsOffset(sb, end_position);
    }
    else
    {
        start = end = 0;
    }

    *startOffset = start;
    *endOffset = end;
}
示例#20
0
// Set the font attribute.
void QsciStyle::setFont(const QFont &font)
{
    style_font = font;

    if (style_nr >= 0)
    {
        QsciScintillaBase *sci = QsciScintillaBase::pool();

        if (sci)
        {
            sci->SendScintilla(QsciScintillaBase::SCI_STYLESETFONT, style_nr,
                    style_font.family().toAscii().data());
            sci->SendScintilla(QsciScintillaBase::SCI_STYLESETSIZE, style_nr,
                    style_font.pointSize());
            sci->SendScintilla(QsciScintillaBase::SCI_STYLESETBOLD, style_nr,
                    style_font.bold());
            sci->SendScintilla(QsciScintillaBase::SCI_STYLESETITALIC, style_nr,
                    style_font.italic());
            sci->SendScintilla(QsciScintillaBase::SCI_STYLESETUNDERLINE,
                    style_nr, style_font.underline());
        }
    }
}
// Return the attributes of a character and surrounding text.
QString QsciAccessibleScintillaBase::attributes(int offset, int *startOffset,
        int *endOffset) const
{
    QsciScintillaBase *sb = sciWidget();
    int position = offsetAsPosition(sb, offset);
    int style = sb->SendScintilla(QsciScintillaBase::SCI_GETSTYLEAT, position);

    // Find the start of the text with this style.
    int start_position = position;
    int start_text_position = offset;

    while (start_position > 0)
    {
        int before = sb->SendScintilla(QsciScintillaBase::SCI_POSITIONBEFORE,
                start_position);
        int s = sb->SendScintilla(QsciScintillaBase::SCI_GETSTYLEAT, before);

        if (s != style)
            break;

        start_position = before;
        --start_text_position;
    }

    *startOffset = start_text_position;

    // Find the end of the text with this style.
    int end_position = sb->SendScintilla(QsciScintillaBase::SCI_POSITIONAFTER,
            position);
    int end_text_position = offset + 1;
    int last_position = sb->SendScintilla(
            QsciScintillaBase::SCI_GETTEXTLENGTH);

    while (end_position < last_position)
    {
        int s = sb->SendScintilla(QsciScintillaBase::SCI_GETSTYLEAT,
                end_position);

        if (s != style)
            break;

        end_position = sb->SendScintilla(QsciScintillaBase::SCI_POSITIONAFTER,
                end_position);
        ++end_text_position;
    }

    *endOffset = end_text_position;

    // Convert the style to attributes.
    QString attrs;

    int back = sb->SendScintilla(QsciScintillaBase::SCI_STYLEGETBACK, style);
    addAttribute(attrs, "background-color", colourAsRGB(back));

    int fore = sb->SendScintilla(QsciScintillaBase::SCI_STYLEGETFORE, style);
    addAttribute(attrs, "color", colourAsRGB(fore));

    QFont font = fontForStyle(style);

    QString family = font.family();
    family = family.replace('\\', QLatin1String("\\\\"));
    family = family.replace(':', QLatin1String("\\:"));
    family = family.replace(',', QLatin1String("\\,"));
    family = family.replace('=', QLatin1String("\\="));
    family = family.replace(';', QLatin1String("\\;"));
    family = family.replace('\"', QLatin1String("\\\""));
    addAttribute(attrs, "font-familly",
            QLatin1Char('"') + family + QLatin1Char('"'));

    int font_size = int(font.pointSize());
    addAttribute(attrs, "font-size",
            QString::fromLatin1("%1pt").arg(font_size));

    QFont::Style font_style = font.style();
    addAttribute(attrs, "font-style",
            QString::fromLatin1((font_style == QFont::StyleItalic) ? "italic" : ((font_style == QFont::StyleOblique) ? "oblique": "normal")));

    int font_weight = font.weight();
    addAttribute(attrs, "font-weight",
            QString::fromLatin1(
                    (font_weight > QFont::Normal) ? "bold" : "normal"));

    int underline = sb->SendScintilla(QsciScintillaBase::SCI_STYLEGETUNDERLINE,
            style);
    if (underline)
        addAttribute(attrs, "text-underline-type",
                QString::fromLatin1("single"));

    return attrs;
}