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