OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fwl/core/cfwl_edit.h" | 7 #include "xfa/fwl/core/cfwl_edit.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "third_party/base/ptr_util.h" | 12 #include "third_party/base/ptr_util.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 IFWL_Edit* ToEdit(IFWL_Widget* widget) { | 16 IFWL_Edit* ToEdit(IFWL_Widget* widget) { |
17 return static_cast<IFWL_Edit*>(widget); | 17 return static_cast<IFWL_Edit*>(widget); |
18 } | 18 } |
19 | 19 |
| 20 const IFWL_Edit* ToEdit(const IFWL_Widget* widget) { |
| 21 return static_cast<const IFWL_Edit*>(widget); |
| 22 } |
| 23 |
20 } // namespace | 24 } // namespace |
21 | 25 |
22 CFWL_Edit::CFWL_Edit(const IFWL_App* app) : CFWL_Widget(app) {} | 26 CFWL_Edit::CFWL_Edit(const IFWL_App* app) : CFWL_Widget(app) {} |
23 | 27 |
24 CFWL_Edit::~CFWL_Edit() {} | 28 CFWL_Edit::~CFWL_Edit() {} |
25 | 29 |
26 void CFWL_Edit::Initialize() { | 30 void CFWL_Edit::Initialize() { |
27 ASSERT(!m_pIface); | 31 ASSERT(!m_pIface); |
28 | 32 |
29 m_pIface = pdfium::MakeUnique<IFWL_Edit>( | 33 m_pIface = pdfium::MakeUnique<IFWL_Edit>( |
30 m_pApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); | 34 m_pApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); |
31 | 35 |
32 CFWL_Widget::Initialize(); | 36 CFWL_Widget::Initialize(); |
33 } | 37 } |
34 | 38 |
35 void CFWL_Edit::SetText(const CFX_WideString& wsText) { | 39 void CFWL_Edit::SetText(const CFX_WideString& wsText) { |
36 if (GetWidget()) | 40 if (GetWidget()) |
37 ToEdit(GetWidget())->SetText(wsText); | 41 ToEdit(GetWidget())->SetText(wsText); |
38 } | 42 } |
39 | 43 |
40 void CFWL_Edit::GetText(CFX_WideString& wsText, | 44 void CFWL_Edit::GetText(CFX_WideString& wsText, |
41 int32_t nStart, | 45 int32_t nStart, |
42 int32_t nCount) { | 46 int32_t nCount) const { |
43 if (GetWidget()) | 47 if (GetWidget()) |
44 ToEdit(GetWidget())->GetText(wsText, nStart, nCount); | 48 ToEdit(GetWidget())->GetText(wsText, nStart, nCount); |
45 } | 49 } |
46 | 50 |
47 int32_t CFWL_Edit::CountSelRanges() { | 51 int32_t CFWL_Edit::CountSelRanges() const { |
48 return GetWidget() ? ToEdit(GetWidget())->CountSelRanges() : 0; | 52 return GetWidget() ? ToEdit(GetWidget())->CountSelRanges() : 0; |
49 } | 53 } |
50 | 54 |
51 int32_t CFWL_Edit::GetSelRange(int32_t nIndex, int32_t& nStart) { | 55 int32_t CFWL_Edit::GetSelRange(int32_t nIndex, int32_t& nStart) const { |
52 return GetWidget() ? ToEdit(GetWidget())->GetSelRange(nIndex, nStart) : 0; | 56 return GetWidget() ? ToEdit(GetWidget())->GetSelRange(nIndex, nStart) : 0; |
53 } | 57 } |
54 | 58 |
55 int32_t CFWL_Edit::GetLimit() { | 59 int32_t CFWL_Edit::GetLimit() const { |
56 return GetWidget() ? ToEdit(GetWidget())->GetLimit() : -1; | 60 return GetWidget() ? ToEdit(GetWidget())->GetLimit() : -1; |
57 } | 61 } |
58 | 62 |
59 void CFWL_Edit::SetLimit(int32_t nLimit) { | 63 void CFWL_Edit::SetLimit(int32_t nLimit) { |
60 if (GetWidget()) | 64 if (GetWidget()) |
61 ToEdit(GetWidget())->SetLimit(nLimit); | 65 ToEdit(GetWidget())->SetLimit(nLimit); |
62 } | 66 } |
63 | 67 |
64 void CFWL_Edit::SetAliasChar(FX_WCHAR wAlias) { | 68 void CFWL_Edit::SetAliasChar(FX_WCHAR wAlias) { |
65 if (GetWidget()) | 69 if (GetWidget()) |
66 ToEdit(GetWidget())->SetAliasChar(wAlias); | 70 ToEdit(GetWidget())->SetAliasChar(wAlias); |
67 } | 71 } |
68 | 72 |
69 void CFWL_Edit::SetScrollOffset(FX_FLOAT fScrollOffset) { | 73 void CFWL_Edit::SetScrollOffset(FX_FLOAT fScrollOffset) { |
70 if (GetWidget()) | 74 if (GetWidget()) |
71 ToEdit(GetWidget())->SetScrollOffset(fScrollOffset); | 75 ToEdit(GetWidget())->SetScrollOffset(fScrollOffset); |
72 } | 76 } |
OLD | NEW |