John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 7 | #include "fpdfsdk/pdfwindow/PWL_Edit.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 8 | |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 9 | #include <algorithm> |
Lei Zhang | a99de0e | 2017-02-27 14:45:56 -0800 | [diff] [blame] | 10 | #include <memory> |
Dan Sinclair | 3ebd121 | 2016-03-09 09:59:23 -0500 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
dsinclair | bc5e6d2 | 2016-10-04 11:08:49 -0700 | [diff] [blame] | 13 | #include "core/fpdfapi/font/cpdf_font.h" |
dsinclair | 1727aee | 2016-09-29 13:12:56 -0700 | [diff] [blame] | 14 | #include "core/fpdfdoc/cpvt_word.h" |
dsinclair | a52ab74 | 2016-09-29 13:59:29 -0700 | [diff] [blame] | 15 | #include "core/fxcrt/fx_safe_types.h" |
Dan Sinclair | 908c848 | 2017-03-30 14:33:28 -0400 | [diff] [blame] | 16 | #include "core/fxcrt/xml/cxml_element.h" |
dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 17 | #include "core/fxge/cfx_graphstatedata.h" |
| 18 | #include "core/fxge/cfx_pathdata.h" |
| 19 | #include "core/fxge/cfx_renderdevice.h" |
| 20 | #include "core/fxge/fx_font.h" |
dsinclair | 0bb385b | 2016-09-29 17:03:59 -0700 | [diff] [blame] | 21 | #include "fpdfsdk/fxedit/fxet_edit.h" |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 22 | #include "fpdfsdk/pdfwindow/PWL_Caret.h" |
| 23 | #include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" |
| 24 | #include "fpdfsdk/pdfwindow/PWL_FontMap.h" |
| 25 | #include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" |
| 26 | #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
| 27 | #include "fpdfsdk/pdfwindow/PWL_Wnd.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 28 | #include "public/fpdf_fwlevent.h" |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 29 | #include "third_party/base/stl_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 30 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 31 | CPWL_Edit::CPWL_Edit() |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 32 | : m_pFillerNotify(nullptr), m_bFocus(false), m_pFormFiller(nullptr) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 33 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 34 | CPWL_Edit::~CPWL_Edit() { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 35 | ASSERT(m_bFocus == false); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 38 | CFX_ByteString CPWL_Edit::GetClassName() const { |
| 39 | return PWL_CLASSNAME_EDIT; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 42 | void CPWL_Edit::OnDestroy() {} |
| 43 | |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 44 | void CPWL_Edit::SetText(const CFX_WideString& csText) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 45 | CFX_WideString swText = csText; |
Lei Zhang | a99de0e | 2017-02-27 14:45:56 -0800 | [diff] [blame] | 46 | if (!HasFlag(PES_RICH)) { |
| 47 | m_pEdit->SetText(swText); |
| 48 | return; |
| 49 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 50 | |
Lei Zhang | a99de0e | 2017-02-27 14:45:56 -0800 | [diff] [blame] | 51 | CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText); |
| 52 | std::unique_ptr<CXML_Element> pXML( |
| 53 | CXML_Element::Parse(sValue.c_str(), sValue.GetLength())); |
| 54 | if (!pXML) { |
| 55 | m_pEdit->SetText(swText); |
| 56 | return; |
| 57 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 58 | |
Lei Zhang | a99de0e | 2017-02-27 14:45:56 -0800 | [diff] [blame] | 59 | int32_t nCount = pXML->CountChildren(); |
| 60 | bool bFirst = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 61 | |
Lei Zhang | a99de0e | 2017-02-27 14:45:56 -0800 | [diff] [blame] | 62 | swText.clear(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 63 | |
Lei Zhang | a99de0e | 2017-02-27 14:45:56 -0800 | [diff] [blame] | 64 | for (int32_t i = 0; i < nCount; i++) { |
| 65 | CXML_Element* pSubElement = pXML->GetElement(i); |
| 66 | if (!pSubElement) |
| 67 | continue; |
| 68 | |
| 69 | CFX_ByteString tag = pSubElement->GetTagName(); |
| 70 | if (tag.EqualNoCase("p")) { |
| 71 | int nChild = pSubElement->CountChildren(); |
| 72 | CFX_WideString swSection; |
| 73 | for (int32_t j = 0; j < nChild; j++) |
| 74 | swSection += pSubElement->GetContent(j); |
| 75 | |
| 76 | if (bFirst) |
| 77 | bFirst = false; |
| 78 | else |
| 79 | swText += FWL_VKEY_Return; |
| 80 | swText += swSection; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 84 | m_pEdit->SetText(swText); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 87 | void CPWL_Edit::RePosChildWnd() { |
| 88 | if (CPWL_ScrollBar* pVSB = GetVScrollBar()) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 89 | CFX_FloatRect rcWindow = m_rcOldWindow; |
| 90 | CFX_FloatRect rcVScroll = |
| 91 | CFX_FloatRect(rcWindow.right, rcWindow.bottom, |
| 92 | rcWindow.right + PWL_SCROLLBAR_WIDTH, rcWindow.top); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 93 | pVSB->Move(rcVScroll, true, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 94 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 95 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 96 | if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW)) |
| 97 | m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( |
Dan Sinclair | 50cce60 | 2016-02-24 09:51:16 -0500 | [diff] [blame] | 98 | GetClientRect(), 1.0f)); // +1 for caret beside border |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 99 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 100 | CPWL_EditCtrl::RePosChildWnd(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 103 | CFX_FloatRect CPWL_Edit::GetClientRect() const { |
| 104 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect( |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 105 | GetWindowRect(), (float)(GetBorderWidth() + GetInnerBorderWidth())); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 106 | |
| 107 | if (CPWL_ScrollBar* pVSB = GetVScrollBar()) { |
| 108 | if (pVSB->IsVisible()) { |
| 109 | rcClient.right -= PWL_SCROLLBAR_WIDTH; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | return rcClient; |
| 114 | } |
| 115 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 116 | void CPWL_Edit::SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat, bool bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 117 | m_pEdit->SetAlignmentV((int32_t)nFormat, bPaint); |
| 118 | } |
| 119 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 120 | bool CPWL_Edit::CanSelectAll() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 121 | return GetSelectWordRange() != m_pEdit->GetWholeWordRange(); |
| 122 | } |
| 123 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 124 | bool CPWL_Edit::CanClear() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 125 | return !IsReadOnly() && m_pEdit->IsSelected(); |
| 126 | } |
| 127 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 128 | bool CPWL_Edit::CanCopy() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 129 | return !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) && |
| 130 | m_pEdit->IsSelected(); |
| 131 | } |
| 132 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 133 | bool CPWL_Edit::CanCut() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 134 | return CanCopy() && !IsReadOnly(); |
| 135 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 136 | void CPWL_Edit::CutText() { |
| 137 | if (!CanCut()) |
| 138 | return; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 139 | m_pEdit->Clear(); |
| 140 | } |
| 141 | |
| 142 | void CPWL_Edit::OnCreated() { |
| 143 | CPWL_EditCtrl::OnCreated(); |
| 144 | |
| 145 | if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { |
| 146 | pScroll->RemoveFlag(PWS_AUTOTRANSPARENT); |
| 147 | pScroll->SetTransparency(255); |
| 148 | } |
| 149 | |
| 150 | SetParamByFlag(); |
| 151 | |
| 152 | m_rcOldWindow = GetWindowRect(); |
| 153 | |
| 154 | m_pEdit->SetOprNotify(this); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 155 | m_pEdit->EnableOprNotify(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | void CPWL_Edit::SetParamByFlag() { |
| 159 | if (HasFlag(PES_RIGHT)) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 160 | m_pEdit->SetAlignmentH(2, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 161 | } else if (HasFlag(PES_MIDDLE)) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 162 | m_pEdit->SetAlignmentH(1, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 163 | } else { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 164 | m_pEdit->SetAlignmentH(0, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | if (HasFlag(PES_BOTTOM)) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 168 | m_pEdit->SetAlignmentV(2, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 169 | } else if (HasFlag(PES_CENTER)) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 170 | m_pEdit->SetAlignmentV(1, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 171 | } else { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 172 | m_pEdit->SetAlignmentV(0, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | if (HasFlag(PES_PASSWORD)) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 176 | m_pEdit->SetPasswordChar('*', false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 177 | } |
| 178 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 179 | m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE), false); |
| 180 | m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN), false); |
| 181 | m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE), false); |
| 182 | m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL), false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 183 | m_pEdit->EnableUndo(HasFlag(PES_UNDO)); |
| 184 | |
| 185 | if (HasFlag(PES_TEXTOVERFLOW)) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 186 | SetClipRect(CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f)); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 187 | m_pEdit->SetTextOverflow(true, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 188 | } else { |
| 189 | if (m_pEditCaret) { |
| 190 | m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( |
Dan Sinclair | 50cce60 | 2016-02-24 09:51:16 -0500 | [diff] [blame] | 191 | GetClientRect(), 1.0f)); // +1 for caret beside border |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 192 | } |
| 193 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
| 197 | CPWL_Wnd::GetThisAppearanceStream(sAppStream); |
| 198 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 199 | CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 200 | CFX_ByteTextBuf sLine; |
| 201 | |
| 202 | int32_t nCharArray = m_pEdit->GetCharArray(); |
| 203 | |
| 204 | if (nCharArray > 0) { |
| 205 | switch (GetBorderStyle()) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 206 | case BorderStyle::SOLID: { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 207 | sLine << "q\n" |
| 208 | << GetBorderWidth() << " w\n" |
| 209 | << CPWL_Utils::GetColorAppStream(GetBorderColor(), false) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 210 | .AsStringC() |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 211 | << " 2 J 0 j\n"; |
| 212 | |
| 213 | for (int32_t i = 1; i < nCharArray; i++) { |
| 214 | sLine << rcClient.left + |
| 215 | ((rcClient.right - rcClient.left) / nCharArray) * i |
| 216 | << " " << rcClient.bottom << " m\n" |
| 217 | << rcClient.left + |
| 218 | ((rcClient.right - rcClient.left) / nCharArray) * i |
| 219 | << " " << rcClient.top << " l S\n"; |
| 220 | } |
| 221 | |
| 222 | sLine << "Q\n"; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 223 | break; |
| 224 | } |
| 225 | case BorderStyle::DASH: { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 226 | sLine << "q\n" |
| 227 | << GetBorderWidth() << " w\n" |
| 228 | << CPWL_Utils::GetColorAppStream(GetBorderColor(), false) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 229 | .AsStringC() |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 230 | << " 2 J 0 j\n" |
| 231 | << "[" << GetBorderDash().nDash << " " << GetBorderDash().nGap |
| 232 | << "] " << GetBorderDash().nPhase << " d\n"; |
| 233 | |
| 234 | for (int32_t i = 1; i < nCharArray; i++) { |
| 235 | sLine << rcClient.left + |
| 236 | ((rcClient.right - rcClient.left) / nCharArray) * i |
| 237 | << " " << rcClient.bottom << " m\n" |
| 238 | << rcClient.left + |
| 239 | ((rcClient.right - rcClient.left) / nCharArray) * i |
| 240 | << " " << rcClient.top << " l S\n"; |
| 241 | } |
| 242 | |
| 243 | sLine << "Q\n"; |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 244 | break; |
| 245 | } |
| 246 | default: |
| 247 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
| 251 | sAppStream << sLine; |
| 252 | |
| 253 | CFX_ByteTextBuf sText; |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 254 | CFX_PointF ptOffset; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 255 | CPVT_WordRange wrWhole = m_pEdit->GetWholeWordRange(); |
| 256 | CPVT_WordRange wrSelect = GetSelectWordRange(); |
| 257 | CPVT_WordRange wrVisible = |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 258 | HasFlag(PES_TEXTOVERFLOW) ? wrWhole : m_pEdit->GetVisibleWordRange(); |
| 259 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 260 | CPVT_WordRange wrSelBefore(wrWhole.BeginPos, wrSelect.BeginPos); |
| 261 | CPVT_WordRange wrSelAfter(wrSelect.EndPos, wrWhole.EndPos); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 262 | CPVT_WordRange wrTemp = |
| 263 | CPWL_Utils::OverlapWordRange(GetSelectWordRange(), wrVisible); |
| 264 | CFX_ByteString sEditSel = |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 265 | CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wrTemp); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 266 | |
| 267 | if (sEditSel.GetLength() > 0) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 268 | sText << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELBACKCOLOR).AsStringC() |
| 269 | << sEditSel.AsStringC(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 270 | |
| 271 | wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelBefore); |
| 272 | CFX_ByteString sEditBefore = CPWL_Utils::GetEditAppStream( |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 273 | m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 274 | m_pEdit->GetPasswordChar()); |
| 275 | |
| 276 | if (sEditBefore.GetLength() > 0) |
Dan Sinclair | a0061af | 2017-02-23 09:25:17 -0500 | [diff] [blame] | 277 | sText << "BT\n" |
| 278 | << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC() |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 279 | << sEditBefore.AsStringC() << "ET\n"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 280 | |
| 281 | wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelect); |
| 282 | CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream( |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 283 | m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 284 | m_pEdit->GetPasswordChar()); |
| 285 | |
| 286 | if (sEditMid.GetLength() > 0) |
| 287 | sText << "BT\n" |
| 288 | << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1)) |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 289 | .AsStringC() |
| 290 | << sEditMid.AsStringC() << "ET\n"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 291 | |
| 292 | wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelAfter); |
| 293 | CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream( |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 294 | m_pEdit.get(), ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 295 | m_pEdit->GetPasswordChar()); |
| 296 | |
| 297 | if (sEditAfter.GetLength() > 0) |
Dan Sinclair | a0061af | 2017-02-23 09:25:17 -0500 | [diff] [blame] | 298 | sText << "BT\n" |
| 299 | << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC() |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 300 | << sEditAfter.AsStringC() << "ET\n"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 301 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 302 | if (sText.GetLength() > 0) { |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 303 | CFX_FloatRect rect = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 304 | sAppStream << "q\n/Tx BMC\n"; |
| 305 | |
| 306 | if (!HasFlag(PES_TEXTOVERFLOW)) |
weili | db444d2 | 2016-06-02 15:48:15 -0700 | [diff] [blame] | 307 | sAppStream << rect.left << " " << rect.bottom << " " |
| 308 | << rect.right - rect.left << " " << rect.top - rect.bottom |
| 309 | << " re W n\n"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 310 | |
| 311 | sAppStream << sText; |
| 312 | |
| 313 | sAppStream << "EMC\nQ\n"; |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 318 | CFX_Matrix* pUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 319 | CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); |
| 320 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 321 | CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 322 | CFX_ByteTextBuf sLine; |
| 323 | |
| 324 | int32_t nCharArray = m_pEdit->GetCharArray(); |
| 325 | FX_SAFE_INT32 nCharArraySafe = nCharArray; |
| 326 | nCharArraySafe -= 1; |
| 327 | nCharArraySafe *= 2; |
| 328 | |
| 329 | if (nCharArray > 0 && nCharArraySafe.IsValid()) { |
| 330 | switch (GetBorderStyle()) { |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 331 | case BorderStyle::SOLID: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 332 | CFX_GraphStateData gsd; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 333 | gsd.m_LineWidth = (float)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 334 | |
| 335 | CFX_PathData path; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 336 | |
| 337 | for (int32_t i = 0; i < nCharArray - 1; i++) { |
Dan Sinclair | e460232 | 2017-02-15 11:07:32 -0500 | [diff] [blame] | 338 | path.AppendPoint( |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 339 | CFX_PointF( |
| 340 | rcClient.left + |
| 341 | ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), |
| 342 | rcClient.bottom), |
| 343 | FXPT_TYPE::MoveTo, false); |
Dan Sinclair | e460232 | 2017-02-15 11:07:32 -0500 | [diff] [blame] | 344 | path.AppendPoint( |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 345 | CFX_PointF( |
| 346 | rcClient.left + |
| 347 | ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), |
| 348 | rcClient.top), |
| 349 | FXPT_TYPE::LineTo, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 350 | } |
Dan Sinclair | e460232 | 2017-02-15 11:07:32 -0500 | [diff] [blame] | 351 | if (!path.GetPoints().empty()) { |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 352 | pDevice->DrawPath(&path, pUser2Device, &gsd, 0, |
| 353 | GetBorderColor().ToFXColor(255), FXFILL_ALTERNATE); |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 354 | } |
| 355 | break; |
| 356 | } |
| 357 | case BorderStyle::DASH: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 358 | CFX_GraphStateData gsd; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 359 | gsd.m_LineWidth = (float)GetBorderWidth(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 360 | |
| 361 | gsd.SetDashCount(2); |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 362 | gsd.m_DashArray[0] = (float)GetBorderDash().nDash; |
| 363 | gsd.m_DashArray[1] = (float)GetBorderDash().nGap; |
| 364 | gsd.m_DashPhase = (float)GetBorderDash().nPhase; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 365 | |
| 366 | CFX_PathData path; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 367 | for (int32_t i = 0; i < nCharArray - 1; i++) { |
Dan Sinclair | e460232 | 2017-02-15 11:07:32 -0500 | [diff] [blame] | 368 | path.AppendPoint( |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 369 | CFX_PointF( |
| 370 | rcClient.left + |
| 371 | ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), |
| 372 | rcClient.bottom), |
| 373 | FXPT_TYPE::MoveTo, false); |
Dan Sinclair | e460232 | 2017-02-15 11:07:32 -0500 | [diff] [blame] | 374 | path.AppendPoint( |
dan sinclair | b147e07 | 2017-02-22 19:56:15 -0500 | [diff] [blame] | 375 | CFX_PointF( |
| 376 | rcClient.left + |
| 377 | ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), |
| 378 | rcClient.top), |
| 379 | FXPT_TYPE::LineTo, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 380 | } |
Dan Sinclair | e460232 | 2017-02-15 11:07:32 -0500 | [diff] [blame] | 381 | if (!path.GetPoints().empty()) { |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 382 | pDevice->DrawPath(&path, pUser2Device, &gsd, 0, |
| 383 | GetBorderColor().ToFXColor(255), FXFILL_ALTERNATE); |
dsinclair | 92cb5e5 | 2016-05-16 11:38:28 -0700 | [diff] [blame] | 384 | } |
| 385 | break; |
| 386 | } |
| 387 | default: |
| 388 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 392 | CFX_FloatRect rcClip; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 393 | CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange(); |
thestig | 1cd352e | 2016-06-07 17:53:06 -0700 | [diff] [blame] | 394 | CPVT_WordRange* pRange = nullptr; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 395 | if (!HasFlag(PES_TEXTOVERFLOW)) { |
| 396 | rcClip = GetClientRect(); |
| 397 | pRange = &wrRange; |
| 398 | } |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 399 | |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 400 | CFX_SystemHandler* pSysHandler = GetSystemHandler(); |
Dan Sinclair | fc54e05 | 2017-02-23 09:59:05 -0500 | [diff] [blame] | 401 | CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pEdit.get(), |
| 402 | GetTextColor().ToFXColor(GetTransparency()), rcClip, |
| 403 | CFX_PointF(), pRange, pSysHandler, m_pFormFiller); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 406 | bool CPWL_Edit::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 407 | CPWL_Wnd::OnLButtonDown(point, nFlag); |
| 408 | |
| 409 | if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) { |
| 410 | if (m_bMouseDown) |
| 411 | InvalidateRect(); |
| 412 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 413 | m_bMouseDown = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 414 | SetCapture(); |
| 415 | |
| 416 | m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 417 | } |
| 418 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 419 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 422 | bool CPWL_Edit::OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 423 | CPWL_Wnd::OnLButtonDblClk(point, nFlag); |
| 424 | |
| 425 | if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) { |
| 426 | m_pEdit->SelectAll(); |
| 427 | } |
| 428 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 429 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 432 | bool CPWL_Edit::OnRButtonUp(const CFX_PointF& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 433 | if (m_bMouseDown) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 434 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 435 | |
| 436 | CPWL_Wnd::OnRButtonUp(point, nFlag); |
| 437 | |
| 438 | if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 439 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 440 | |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 441 | CFX_SystemHandler* pSH = GetSystemHandler(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 442 | if (!pSH) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 443 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 444 | |
| 445 | SetFocus(); |
| 446 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 447 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | void CPWL_Edit::OnSetFocus() { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 451 | SetEditCaret(true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 452 | if (!IsReadOnly()) { |
| 453 | if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler()) |
| 454 | pFocusHandler->OnSetFocus(this); |
| 455 | } |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 456 | m_bFocus = true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | void CPWL_Edit::OnKillFocus() { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 460 | ShowVScrollBar(false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 461 | m_pEdit->SelectNone(); |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 462 | SetCaret(false, CFX_PointF(), CFX_PointF()); |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame^] | 463 | SetCharSet(FX_CHARSET_ANSI); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 464 | m_bFocus = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 467 | void CPWL_Edit::SetCharSpace(float fCharSpace) { |
dsinclair | efd5a99 | 2016-07-18 10:04:07 -0700 | [diff] [blame] | 468 | m_pEdit->SetCharSpace(fCharSpace); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | CFX_ByteString CPWL_Edit::GetSelectAppearanceStream( |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 472 | const CFX_PointF& ptOffset) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 473 | CPVT_WordRange wr = GetSelectWordRange(); |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 474 | return CPWL_Utils::GetEditSelAppStream(m_pEdit.get(), ptOffset, &wr); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | CPVT_WordRange CPWL_Edit::GetSelectWordRange() const { |
| 478 | if (m_pEdit->IsSelected()) { |
| 479 | int32_t nStart = -1; |
| 480 | int32_t nEnd = -1; |
| 481 | |
| 482 | m_pEdit->GetSel(nStart, nEnd); |
| 483 | |
| 484 | CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart); |
| 485 | CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd); |
| 486 | |
| 487 | return CPVT_WordRange(wpStart, wpEnd); |
| 488 | } |
| 489 | |
| 490 | return CPVT_WordRange(); |
| 491 | } |
| 492 | |
| 493 | CFX_ByteString CPWL_Edit::GetTextAppearanceStream( |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 494 | const CFX_PointF& ptOffset) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 495 | CFX_ByteTextBuf sRet; |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 496 | CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit.get(), ptOffset); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 497 | if (sEdit.GetLength() > 0) { |
Dan Sinclair | a0061af | 2017-02-23 09:25:17 -0500 | [diff] [blame] | 498 | sRet << "BT\n" |
| 499 | << CPWL_Utils::GetColorAppStream(GetTextColor()).AsStringC() |
tsepez | 4c3debb | 2016-04-08 12:20:38 -0700 | [diff] [blame] | 500 | << sEdit.AsStringC() << "ET\n"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 501 | } |
tsepez | 71a452f | 2016-05-13 17:51:27 -0700 | [diff] [blame] | 502 | return sRet.MakeString(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | CFX_ByteString CPWL_Edit::GetCaretAppearanceStream( |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 506 | const CFX_PointF& ptOffset) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 507 | if (m_pEditCaret) |
| 508 | return m_pEditCaret->GetCaretAppearanceStream(ptOffset); |
| 509 | |
| 510 | return CFX_ByteString(); |
| 511 | } |
| 512 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 513 | CFX_PointF CPWL_Edit::GetWordRightBottomPoint(const CPVT_WordPlace& wpWord) { |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 514 | CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator(); |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 515 | CPVT_WordPlace wpOld = pIterator->GetAt(); |
| 516 | pIterator->SetAt(wpWord); |
tsepez | 63f545c | 2016-09-13 16:08:49 -0700 | [diff] [blame] | 517 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 518 | CFX_PointF pt; |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 519 | CPVT_Word word; |
| 520 | if (pIterator->GetWord(word)) { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 521 | pt = CFX_PointF(word.ptWord.x + word.fWidth, word.ptWord.y + word.fDescent); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 522 | } |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 523 | pIterator->SetAt(wpOld); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 524 | return pt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 525 | } |
| 526 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 527 | bool CPWL_Edit::IsTextFull() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 528 | return m_pEdit->IsTextFull(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 529 | } |
| 530 | |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 531 | float CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont, |
| 532 | const CFX_FloatRect& rcPlate, |
| 533 | int32_t nCharArray) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 534 | if (pFont && !pFont->IsStandardFont()) { |
| 535 | FX_RECT rcBBox; |
| 536 | pFont->GetFontBBox(rcBBox); |
| 537 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 538 | CFX_FloatRect rcCell = rcPlate; |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 539 | float xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width(); |
| 540 | float ydiv = -rcCell.Height() * 1000.0f / rcBBox.Height(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 541 | |
| 542 | return xdiv < ydiv ? xdiv : ydiv; |
| 543 | } |
| 544 | |
| 545 | return 0.0f; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 546 | } |
| 547 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 548 | void CPWL_Edit::SetCharArray(int32_t nCharArray) { |
| 549 | if (HasFlag(PES_CHARARRAY) && nCharArray > 0) { |
| 550 | m_pEdit->SetCharArray(nCharArray); |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 551 | m_pEdit->SetTextOverflow(true, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 552 | |
| 553 | if (HasFlag(PWS_AUTOFONTSIZE)) { |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 554 | if (IPVT_FontMap* pFontMap = GetFontMap()) { |
Dan Sinclair | 05df075 | 2017-03-14 14:43:42 -0400 | [diff] [blame] | 555 | float fFontSize = GetCharArrayAutoFontSize(pFontMap->GetPDFFont(0), |
| 556 | GetClientRect(), nCharArray); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 557 | if (fFontSize > 0.0f) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 558 | m_pEdit->SetAutoFontSize(false, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 559 | m_pEdit->SetFontSize(fFontSize); |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 564 | } |
| 565 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 566 | void CPWL_Edit::SetLimitChar(int32_t nLimitChar) { |
| 567 | m_pEdit->SetLimitChar(nLimitChar); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 568 | } |
| 569 | |
tsepez | 067990c | 2016-09-13 06:46:40 -0700 | [diff] [blame] | 570 | void CPWL_Edit::ReplaceSel(const CFX_WideString& wsText) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 571 | m_pEdit->Clear(); |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame^] | 572 | m_pEdit->InsertText(wsText, FX_CHARSET_Default); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 573 | } |
| 574 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 575 | CFX_FloatRect CPWL_Edit::GetFocusRect() const { |
| 576 | return CFX_FloatRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 577 | } |
| 578 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 579 | void CPWL_Edit::ShowVScrollBar(bool bShow) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 580 | if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { |
| 581 | if (bShow) { |
| 582 | if (!pScroll->IsVisible()) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 583 | pScroll->SetVisible(true); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 584 | CFX_FloatRect rcWindow = GetWindowRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 585 | m_rcOldWindow = rcWindow; |
| 586 | rcWindow.right += PWL_SCROLLBAR_WIDTH; |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 587 | Move(rcWindow, true, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 588 | } |
| 589 | } else { |
| 590 | if (pScroll->IsVisible()) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 591 | pScroll->SetVisible(false); |
| 592 | Move(m_rcOldWindow, true, true); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 593 | } |
| 594 | } |
| 595 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 596 | } |
| 597 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 598 | bool CPWL_Edit::IsVScrollBarVisible() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 599 | if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { |
| 600 | return pScroll->IsVisible(); |
| 601 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 602 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 603 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 604 | } |
| 605 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 606 | bool CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 607 | if (m_bMouseDown) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 608 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 609 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 610 | if (nChar == FWL_VKEY_Delete) { |
| 611 | if (m_pFillerNotify) { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 612 | bool bRC = true; |
| 613 | bool bExit = false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 614 | CFX_WideString strChange; |
| 615 | CFX_WideString strChangeEx; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 616 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 617 | int nSelStart = 0; |
| 618 | int nSelEnd = 0; |
| 619 | GetSel(nSelStart, nSelEnd); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 620 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 621 | if (nSelStart == nSelEnd) |
| 622 | nSelEnd = nSelStart + 1; |
Lei Zhang | a5b4704 | 2015-10-19 14:32:16 -0700 | [diff] [blame] | 623 | m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), strChange, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 624 | strChangeEx, nSelStart, nSelEnd, true, |
Lei Zhang | a5b4704 | 2015-10-19 14:32:16 -0700 | [diff] [blame] | 625 | bRC, bExit, nFlag); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 626 | if (!bRC) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 627 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 628 | if (bExit) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 629 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 630 | } |
| 631 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 632 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 633 | bool bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 634 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 635 | // In case of implementation swallow the OnKeyDown event. |
| 636 | if (IsProceedtoOnChar(nChar, nFlag)) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 637 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 638 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 639 | return bRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | /** |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 643 | *In case of implementation swallow the OnKeyDown event. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 644 | *If the event is swallowed, implementation may do other unexpected things, which |
| 645 | *is not the control means to do. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 646 | */ |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 647 | bool CPWL_Edit::IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag) { |
| 648 | bool bCtrl = IsCTRLpressed(nFlag); |
| 649 | bool bAlt = IsALTpressed(nFlag); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 650 | if (bCtrl && !bAlt) { |
| 651 | // hot keys for edit control. |
| 652 | switch (nKeyCode) { |
| 653 | case 'C': |
| 654 | case 'V': |
| 655 | case 'X': |
| 656 | case 'A': |
| 657 | case 'Z': |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 658 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 659 | default: |
| 660 | break; |
| 661 | } |
| 662 | } |
| 663 | // control characters. |
| 664 | switch (nKeyCode) { |
| 665 | case FWL_VKEY_Escape: |
| 666 | case FWL_VKEY_Back: |
| 667 | case FWL_VKEY_Return: |
| 668 | case FWL_VKEY_Space: |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 669 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 670 | default: |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 671 | return false; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 672 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 673 | } |
| 674 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 675 | bool CPWL_Edit::OnChar(uint16_t nChar, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 676 | if (m_bMouseDown) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 677 | return true; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 678 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 679 | bool bRC = true; |
| 680 | bool bExit = false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 681 | |
Lei Zhang | a5b4704 | 2015-10-19 14:32:16 -0700 | [diff] [blame] | 682 | if (!IsCTRLpressed(nFlag)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 683 | if (m_pFillerNotify) { |
| 684 | CFX_WideString swChange; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 685 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 686 | int nSelStart = 0; |
| 687 | int nSelEnd = 0; |
| 688 | GetSel(nSelStart, nSelEnd); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 689 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 690 | switch (nChar) { |
| 691 | case FWL_VKEY_Back: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 692 | if (nSelStart == nSelEnd) |
| 693 | nSelStart = nSelEnd - 1; |
| 694 | break; |
| 695 | case FWL_VKEY_Return: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 696 | break; |
| 697 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 698 | swChange += nChar; |
| 699 | break; |
| 700 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 701 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 702 | CFX_WideString strChangeEx; |
Lei Zhang | a5b4704 | 2015-10-19 14:32:16 -0700 | [diff] [blame] | 703 | m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 704 | strChangeEx, nSelStart, nSelEnd, true, |
Lei Zhang | a5b4704 | 2015-10-19 14:32:16 -0700 | [diff] [blame] | 705 | bRC, bExit, nFlag); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 706 | } |
| 707 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 708 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 709 | if (!bRC) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 710 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 711 | if (bExit) |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 712 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 713 | |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 714 | if (IPVT_FontMap* pFontMap = GetFontMap()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 715 | int32_t nOldCharSet = GetCharSet(); |
npm | ea3c3be | 2016-09-19 07:24:33 -0700 | [diff] [blame] | 716 | int32_t nNewCharSet = |
Dan Sinclair | f51a02a | 2017-04-19 12:46:53 -0400 | [diff] [blame^] | 717 | pFontMap->CharSetFromUnicode(nChar, FX_CHARSET_Default); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 718 | if (nOldCharSet != nNewCharSet) { |
| 719 | SetCharSet(nNewCharSet); |
| 720 | } |
| 721 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 722 | |
Lei Zhang | a5b4704 | 2015-10-19 14:32:16 -0700 | [diff] [blame] | 723 | return CPWL_EditCtrl::OnChar(nChar, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 724 | } |
| 725 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 726 | bool CPWL_Edit::OnMouseWheel(short zDelta, |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 727 | const CFX_PointF& point, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 728 | uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 729 | if (HasFlag(PES_MULTILINE)) { |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 730 | CFX_PointF ptScroll = GetScrollPos(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 731 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 732 | if (zDelta > 0) { |
| 733 | ptScroll.y += GetFontSize(); |
| 734 | } else { |
| 735 | ptScroll.y -= GetFontSize(); |
| 736 | } |
| 737 | SetScrollPos(ptScroll); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 738 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 739 | return true; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 740 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 741 | |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 742 | return false; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 743 | } |
| 744 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 745 | void CPWL_Edit::OnInsertReturn(const CPVT_WordPlace& place, |
| 746 | const CPVT_WordPlace& oldplace) { |
| 747 | if (HasFlag(PES_SPELLCHECK)) { |
| 748 | m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
| 749 | GetLatinWordsRange(place))); |
| 750 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 753 | void CPWL_Edit::OnBackSpace(const CPVT_WordPlace& place, |
| 754 | const CPVT_WordPlace& oldplace) { |
| 755 | if (HasFlag(PES_SPELLCHECK)) { |
| 756 | m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
| 757 | GetLatinWordsRange(place))); |
| 758 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 761 | void CPWL_Edit::OnDelete(const CPVT_WordPlace& place, |
| 762 | const CPVT_WordPlace& oldplace) { |
| 763 | if (HasFlag(PES_SPELLCHECK)) { |
| 764 | m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
| 765 | GetLatinWordsRange(place))); |
| 766 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 767 | } |
| 768 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 769 | void CPWL_Edit::OnClear(const CPVT_WordPlace& place, |
| 770 | const CPVT_WordPlace& oldplace) { |
| 771 | if (HasFlag(PES_SPELLCHECK)) { |
| 772 | m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
| 773 | GetLatinWordsRange(place))); |
| 774 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 775 | } |
| 776 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 777 | void CPWL_Edit::OnInsertWord(const CPVT_WordPlace& place, |
| 778 | const CPVT_WordPlace& oldplace) { |
| 779 | if (HasFlag(PES_SPELLCHECK)) { |
| 780 | m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
| 781 | GetLatinWordsRange(place))); |
| 782 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 785 | void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place, |
| 786 | const CPVT_WordPlace& oldplace) { |
| 787 | if (HasFlag(PES_SPELLCHECK)) { |
| 788 | m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
| 789 | GetLatinWordsRange(place))); |
| 790 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 791 | } |
| 792 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 793 | CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1, |
| 794 | const CPVT_WordRange& wr2) { |
Tom Sepez | 52f69b3 | 2017-03-21 13:42:38 -0700 | [diff] [blame] | 795 | return CPVT_WordRange(std::min(wr1.BeginPos, wr2.BeginPos), |
| 796 | std::max(wr1.EndPos, wr2.EndPos)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Dan Sinclair | f528eee | 2017-02-14 11:52:07 -0500 | [diff] [blame] | 799 | CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CFX_PointF& point) const { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 800 | return GetSameWordsRange(m_pEdit->SearchWordPlace(point), true, false); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 801 | } |
| 802 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 803 | CPVT_WordRange CPWL_Edit::GetLatinWordsRange( |
| 804 | const CPVT_WordPlace& place) const { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 805 | return GetSameWordsRange(place, true, false); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 808 | CPVT_WordRange CPWL_Edit::GetArabicWordsRange( |
| 809 | const CPVT_WordPlace& place) const { |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 810 | return GetSameWordsRange(place, false, true); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 811 | } |
| 812 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 813 | #define PWL_ISARABICWORD(word) \ |
| 814 | ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC)) |
| 815 | |
| 816 | CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace& place, |
tsepez | 4cf5515 | 2016-11-02 14:37:54 -0700 | [diff] [blame] | 817 | bool bLatin, |
| 818 | bool bArabic) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 819 | CPVT_WordRange range; |
| 820 | |
dsinclair | e35af1e | 2016-07-13 11:26:20 -0700 | [diff] [blame] | 821 | CFX_Edit_Iterator* pIterator = m_pEdit->GetIterator(); |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 822 | CPVT_Word wordinfo; |
| 823 | CPVT_WordPlace wpStart(place), wpEnd(place); |
| 824 | pIterator->SetAt(place); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 825 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 826 | if (bLatin) { |
| 827 | while (pIterator->NextWord()) { |
| 828 | if (!pIterator->GetWord(wordinfo) || |
| 829 | !FX_EDIT_ISLATINWORD(wordinfo.Word)) { |
| 830 | break; |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 831 | } |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 832 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 833 | wpEnd = pIterator->GetAt(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 834 | } |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 835 | } else if (bArabic) { |
| 836 | while (pIterator->NextWord()) { |
| 837 | if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word)) |
| 838 | break; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 839 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 840 | wpEnd = pIterator->GetAt(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 841 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 842 | } |
| 843 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame] | 844 | pIterator->SetAt(place); |
| 845 | |
| 846 | if (bLatin) { |
| 847 | do { |
| 848 | if (!pIterator->GetWord(wordinfo) || |
| 849 | !FX_EDIT_ISLATINWORD(wordinfo.Word)) { |
| 850 | break; |
| 851 | } |
| 852 | |
| 853 | wpStart = pIterator->GetAt(); |
| 854 | } while (pIterator->PrevWord()); |
| 855 | } else if (bArabic) { |
| 856 | do { |
| 857 | if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word)) |
| 858 | break; |
| 859 | |
| 860 | wpStart = pIterator->GetAt(); |
| 861 | } while (pIterator->PrevWord()); |
| 862 | } |
| 863 | |
| 864 | range.Set(wpStart, wpEnd); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 865 | return range; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 866 | } |