summaryrefslogtreecommitdiff
path: root/xfa/fwl/core/cfwl_edit.cpp
blob: e404b1de6a811f2867703f346c300537c891e5cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2014 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#include "xfa/fwl/core/cfwl_edit.h"

#include <memory>
#include <vector>

#include "third_party/base/ptr_util.h"

namespace {

IFWL_Edit* ToEdit(IFWL_Widget* widget) {
  return static_cast<IFWL_Edit*>(widget);
}

}  // namespace

CFWL_Edit::CFWL_Edit(const CFWL_App* app) : CFWL_Widget(app) {}

CFWL_Edit::~CFWL_Edit() {}

void CFWL_Edit::Initialize() {
  ASSERT(!m_pIface);

  m_pIface = pdfium::MakeUnique<IFWL_Edit>(
      m_pApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr);

  CFWL_Widget::Initialize();
}

void CFWL_Edit::SetText(const CFX_WideString& wsText) {
  if (GetWidget())
    ToEdit(GetWidget())->SetText(wsText);
}

void CFWL_Edit::GetText(CFX_WideString& wsText,
                        int32_t nStart,
                        int32_t nCount) const {
  if (GetWidget())
    ToEdit(GetWidget())->GetText(wsText, nStart, nCount);
}

int32_t CFWL_Edit::CountSelRanges() const {
  return GetWidget() ? ToEdit(GetWidget())->CountSelRanges() : 0;
}

int32_t CFWL_Edit::GetSelRange(int32_t nIndex, int32_t& nStart) const {
  return GetWidget() ? ToEdit(GetWidget())->GetSelRange(nIndex, nStart) : 0;
}

int32_t CFWL_Edit::GetLimit() const {
  return GetWidget() ? ToEdit(GetWidget())->GetLimit() : -1;
}

void CFWL_Edit::SetLimit(int32_t nLimit) {
  if (GetWidget())
    ToEdit(GetWidget())->SetLimit(nLimit);
}

void CFWL_Edit::SetAliasChar(FX_WCHAR wAlias) {
  if (GetWidget())
    ToEdit(GetWidget())->SetAliasChar(wAlias);
}

void CFWL_Edit::SetScrollOffset(FX_FLOAT fScrollOffset) {
  if (GetWidget())
    ToEdit(GetWidget())->SetScrollOffset(fScrollOffset);
}