コード例 #1
0
ファイル: TextRange.cpp プロジェクト: RazvanB/sumatrapdf
HRESULT STDMETHODCALLTYPE SumatraUIAutomationTextRange::GetText(int maxLength, BSTR *text)
{
    if (text == NULL)
        return E_POINTER;
    if (!document->IsDocumentLoaded())
        return E_FAIL;

    if (IsNullRange() || IsEmptyRange()) {
        *text = SysAllocString(L""); // 0-sized not-null string
        return S_OK;
    }

    TextSelection selection(document->GetDM()->engine(), document->GetDM()->textCache);
    selection.StartAt(startPage, startGlyph);
    selection.SelectUpTo(endPage, endGlyph);

    ScopedMem<WCHAR> selected_text(selection.ExtractText(L"\r\n"));
    size_t selected_text_length = str::Len(selected_text);

    // -1 and [0, inf) are allowed
    if (maxLength > -2) {
        if (maxLength != -1 && selected_text_length > (size_t)maxLength)
            selected_text[maxLength] = '\0'; // truncate

        *text = SysAllocString(selected_text);
        if (*text)
            return S_OK;
        else
            return E_OUTOFMEMORY;
    } else {
        return E_INVALIDARG;
    }
}
コード例 #2
0
ファイル: TextRange.cpp プロジェクト: sambhare/sumatrapdf
HRESULT STDMETHODCALLTYPE SumatraUIAutomationTextRange::Select(void) {
    if (!document->IsDocumentLoaded())
        return E_FAIL;

    if (IsNullRange() || IsEmptyRange()) {
        document->GetDM()->textSelection->Reset();
    } else {
        document->GetDM()->textSelection->Reset();
        document->GetDM()->textSelection->StartAt(startPage, startGlyph);
        document->GetDM()->textSelection->SelectUpTo(endPage, endGlyph);
    }

    return S_OK;
}