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 | |
dan sinclair | 61b2fc7 | 2016-03-23 19:21:44 -0400 | [diff] [blame] | 11 | #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
Dan Sinclair | a8a28e0 | 2016-03-23 15:41:39 -0400 | [diff] [blame] | 12 | #include "core/fxcrt/include/fx_safe_types.h" |
| 13 | #include "core/fxcrt/include/fx_xml.h" |
Dan Sinclair | aa403d3 | 2016-03-15 14:57:22 -0400 | [diff] [blame] | 14 | #include "core/include/fxge/fx_ge.h" |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 15 | #include "fpdfsdk/pdfwindow/PWL_Caret.h" |
| 16 | #include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" |
| 17 | #include "fpdfsdk/pdfwindow/PWL_FontMap.h" |
| 18 | #include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" |
| 19 | #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
| 20 | #include "fpdfsdk/pdfwindow/PWL_Wnd.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 21 | #include "public/fpdf_fwlevent.h" |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 22 | #include "third_party/base/stl_util.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 23 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 24 | CPWL_Edit::CPWL_Edit() |
| 25 | : m_pFillerNotify(NULL), m_pSpellCheck(NULL), m_bFocus(FALSE) { |
| 26 | m_pFormFiller = NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 27 | } |
| 28 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 29 | CPWL_Edit::~CPWL_Edit() { |
| 30 | ASSERT(m_bFocus == FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 33 | CFX_ByteString CPWL_Edit::GetClassName() const { |
| 34 | return PWL_CLASSNAME_EDIT; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 35 | } |
| 36 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 37 | void CPWL_Edit::OnDestroy() {} |
| 38 | |
| 39 | void CPWL_Edit::SetText(const FX_WCHAR* csText) { |
| 40 | CFX_WideString swText = csText; |
| 41 | |
| 42 | if (HasFlag(PES_RICH)) { |
| 43 | CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText); |
| 44 | |
| 45 | if (CXML_Element* pXML = |
| 46 | CXML_Element::Parse(sValue.c_str(), sValue.GetLength())) { |
| 47 | int32_t nCount = pXML->CountChildren(); |
| 48 | FX_BOOL bFirst = TRUE; |
| 49 | |
| 50 | swText.Empty(); |
| 51 | |
| 52 | for (int32_t i = 0; i < nCount; i++) { |
| 53 | if (CXML_Element* pSubElement = pXML->GetElement(i)) { |
| 54 | CFX_ByteString tag = pSubElement->GetTagName(); |
| 55 | if (tag.EqualNoCase("p")) { |
| 56 | int nChild = pSubElement->CountChildren(); |
| 57 | CFX_WideString swSection; |
| 58 | for (int32_t j = 0; j < nChild; j++) { |
| 59 | swSection += pSubElement->GetContent(j); |
| 60 | } |
| 61 | |
| 62 | if (bFirst) |
| 63 | bFirst = FALSE; |
| 64 | else |
| 65 | swText += FWL_VKEY_Return; |
| 66 | swText += swSection; |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | delete pXML; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | m_pEdit->SetText(swText.c_str()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 78 | void CPWL_Edit::RePosChildWnd() { |
| 79 | if (CPWL_ScrollBar* pVSB = GetVScrollBar()) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 80 | CFX_FloatRect rcWindow = m_rcOldWindow; |
| 81 | CFX_FloatRect rcVScroll = |
| 82 | CFX_FloatRect(rcWindow.right, rcWindow.bottom, |
| 83 | rcWindow.right + PWL_SCROLLBAR_WIDTH, rcWindow.top); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 84 | pVSB->Move(rcVScroll, TRUE, FALSE); |
| 85 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 86 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 87 | if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW)) |
| 88 | m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( |
Dan Sinclair | 50cce60 | 2016-02-24 09:51:16 -0500 | [diff] [blame] | 89 | GetClientRect(), 1.0f)); // +1 for caret beside border |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 90 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 91 | CPWL_EditCtrl::RePosChildWnd(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 94 | CFX_FloatRect CPWL_Edit::GetClientRect() const { |
| 95 | CFX_FloatRect rcClient = CPWL_Utils::DeflateRect( |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 96 | GetWindowRect(), (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth())); |
| 97 | |
| 98 | if (CPWL_ScrollBar* pVSB = GetVScrollBar()) { |
| 99 | if (pVSB->IsVisible()) { |
| 100 | rcClient.right -= PWL_SCROLLBAR_WIDTH; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | return rcClient; |
| 105 | } |
| 106 | |
| 107 | void CPWL_Edit::SetAlignFormatH(PWL_EDIT_ALIGNFORMAT_H nFormat, |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 108 | FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 109 | m_pEdit->SetAlignmentH((int32_t)nFormat, bPaint); |
| 110 | } |
| 111 | |
| 112 | void CPWL_Edit::SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat, |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 113 | FX_BOOL bPaint) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 114 | m_pEdit->SetAlignmentV((int32_t)nFormat, bPaint); |
| 115 | } |
| 116 | |
| 117 | FX_BOOL CPWL_Edit::CanSelectAll() const { |
| 118 | return GetSelectWordRange() != m_pEdit->GetWholeWordRange(); |
| 119 | } |
| 120 | |
| 121 | FX_BOOL CPWL_Edit::CanClear() const { |
| 122 | return !IsReadOnly() && m_pEdit->IsSelected(); |
| 123 | } |
| 124 | |
| 125 | FX_BOOL CPWL_Edit::CanCopy() const { |
| 126 | return !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) && |
| 127 | m_pEdit->IsSelected(); |
| 128 | } |
| 129 | |
| 130 | FX_BOOL CPWL_Edit::CanCut() const { |
| 131 | return CanCopy() && !IsReadOnly(); |
| 132 | } |
| 133 | |
| 134 | FX_BOOL CPWL_Edit::CanPaste() const { |
| 135 | if (IsReadOnly()) |
| 136 | return FALSE; |
| 137 | |
| 138 | CFX_WideString swClipboard; |
| 139 | if (IFX_SystemHandler* pSH = GetSystemHandler()) |
| 140 | swClipboard = pSH->GetClipboardText(GetAttachedHWnd()); |
| 141 | |
| 142 | return !swClipboard.IsEmpty(); |
| 143 | } |
| 144 | |
| 145 | void CPWL_Edit::CopyText() { |
| 146 | if (!CanCopy()) |
| 147 | return; |
| 148 | |
| 149 | CFX_WideString str = m_pEdit->GetSelText(); |
| 150 | |
| 151 | if (IFX_SystemHandler* pSH = GetSystemHandler()) |
| 152 | pSH->SetClipboardText(GetAttachedHWnd(), str); |
| 153 | } |
| 154 | |
| 155 | void CPWL_Edit::PasteText() { |
| 156 | if (!CanPaste()) |
| 157 | return; |
| 158 | |
| 159 | CFX_WideString swClipboard; |
| 160 | if (IFX_SystemHandler* pSH = GetSystemHandler()) |
| 161 | swClipboard = pSH->GetClipboardText(GetAttachedHWnd()); |
| 162 | |
| 163 | if (m_pFillerNotify) { |
| 164 | FX_BOOL bRC = TRUE; |
| 165 | FX_BOOL bExit = FALSE; |
| 166 | CFX_WideString strChangeEx; |
| 167 | int nSelStart = 0; |
| 168 | int nSelEnd = 0; |
| 169 | GetSel(nSelStart, nSelEnd); |
Lei Zhang | a5b4704 | 2015-10-19 14:32:16 -0700 | [diff] [blame] | 170 | m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swClipboard, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 171 | strChangeEx, nSelStart, nSelEnd, TRUE, |
| 172 | bRC, bExit, 0); |
| 173 | if (!bRC) |
| 174 | return; |
| 175 | if (bExit) |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | if (swClipboard.GetLength() > 0) { |
| 180 | Clear(); |
| 181 | InsertText(swClipboard.c_str()); |
| 182 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | void CPWL_Edit::CutText() { |
| 186 | if (!CanCut()) |
| 187 | return; |
| 188 | |
| 189 | CFX_WideString str = m_pEdit->GetSelText(); |
| 190 | |
| 191 | if (IFX_SystemHandler* pSH = GetSystemHandler()) |
| 192 | pSH->SetClipboardText(GetAttachedHWnd(), str); |
| 193 | |
| 194 | m_pEdit->Clear(); |
| 195 | } |
| 196 | |
| 197 | void CPWL_Edit::OnCreated() { |
| 198 | CPWL_EditCtrl::OnCreated(); |
| 199 | |
| 200 | if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { |
| 201 | pScroll->RemoveFlag(PWS_AUTOTRANSPARENT); |
| 202 | pScroll->SetTransparency(255); |
| 203 | } |
| 204 | |
| 205 | SetParamByFlag(); |
| 206 | |
| 207 | m_rcOldWindow = GetWindowRect(); |
| 208 | |
| 209 | m_pEdit->SetOprNotify(this); |
| 210 | m_pEdit->EnableOprNotify(TRUE); |
| 211 | } |
| 212 | |
| 213 | void CPWL_Edit::SetParamByFlag() { |
| 214 | if (HasFlag(PES_RIGHT)) { |
| 215 | m_pEdit->SetAlignmentH(2, FALSE); |
| 216 | } else if (HasFlag(PES_MIDDLE)) { |
| 217 | m_pEdit->SetAlignmentH(1, FALSE); |
| 218 | } else { |
| 219 | m_pEdit->SetAlignmentH(0, FALSE); |
| 220 | } |
| 221 | |
| 222 | if (HasFlag(PES_BOTTOM)) { |
| 223 | m_pEdit->SetAlignmentV(2, FALSE); |
| 224 | } else if (HasFlag(PES_CENTER)) { |
| 225 | m_pEdit->SetAlignmentV(1, FALSE); |
| 226 | } else { |
| 227 | m_pEdit->SetAlignmentV(0, FALSE); |
| 228 | } |
| 229 | |
| 230 | if (HasFlag(PES_PASSWORD)) { |
| 231 | m_pEdit->SetPasswordChar('*', FALSE); |
| 232 | } |
| 233 | |
| 234 | m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE), FALSE); |
| 235 | m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN), FALSE); |
| 236 | m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE), FALSE); |
| 237 | m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL), FALSE); |
| 238 | m_pEdit->EnableUndo(HasFlag(PES_UNDO)); |
| 239 | |
| 240 | if (HasFlag(PES_TEXTOVERFLOW)) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 241 | SetClipRect(CFX_FloatRect(0.0f, 0.0f, 0.0f, 0.0f)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 242 | m_pEdit->SetTextOverflow(TRUE, FALSE); |
| 243 | } else { |
| 244 | if (m_pEditCaret) { |
| 245 | m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( |
Dan Sinclair | 50cce60 | 2016-02-24 09:51:16 -0500 | [diff] [blame] | 246 | GetClientRect(), 1.0f)); // +1 for caret beside border |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
| 250 | if (HasFlag(PES_SPELLCHECK)) { |
| 251 | m_pSpellCheck = GetCreationParam().pSpellCheck; |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
| 256 | CPWL_Wnd::GetThisAppearanceStream(sAppStream); |
| 257 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 258 | CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 259 | CFX_ByteTextBuf sLine; |
| 260 | |
| 261 | int32_t nCharArray = m_pEdit->GetCharArray(); |
| 262 | |
| 263 | if (nCharArray > 0) { |
| 264 | switch (GetBorderStyle()) { |
| 265 | case PBS_SOLID: { |
| 266 | sLine << "q\n" << GetBorderWidth() << " w\n" |
| 267 | << CPWL_Utils::GetColorAppStream(GetBorderColor(), FALSE) |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 268 | .AsByteStringC() |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 269 | << " 2 J 0 j\n"; |
| 270 | |
| 271 | for (int32_t i = 1; i < nCharArray; i++) { |
| 272 | sLine << rcClient.left + |
| 273 | ((rcClient.right - rcClient.left) / nCharArray) * i |
| 274 | << " " << rcClient.bottom << " m\n" |
| 275 | << rcClient.left + |
| 276 | ((rcClient.right - rcClient.left) / nCharArray) * i |
| 277 | << " " << rcClient.top << " l S\n"; |
| 278 | } |
| 279 | |
| 280 | sLine << "Q\n"; |
| 281 | } break; |
| 282 | case PBS_DASH: { |
| 283 | sLine << "q\n" << GetBorderWidth() << " w\n" |
| 284 | << CPWL_Utils::GetColorAppStream(GetBorderColor(), FALSE) |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 285 | .AsByteStringC() |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 286 | << " 2 J 0 j\n" |
| 287 | << "[" << GetBorderDash().nDash << " " << GetBorderDash().nGap |
| 288 | << "] " << GetBorderDash().nPhase << " d\n"; |
| 289 | |
| 290 | for (int32_t i = 1; i < nCharArray; i++) { |
| 291 | sLine << rcClient.left + |
| 292 | ((rcClient.right - rcClient.left) / nCharArray) * i |
| 293 | << " " << rcClient.bottom << " m\n" |
| 294 | << rcClient.left + |
| 295 | ((rcClient.right - rcClient.left) / nCharArray) * i |
| 296 | << " " << rcClient.top << " l S\n"; |
| 297 | } |
| 298 | |
| 299 | sLine << "Q\n"; |
| 300 | } break; |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | sAppStream << sLine; |
| 305 | |
| 306 | CFX_ByteTextBuf sText; |
| 307 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 308 | CFX_FloatPoint ptOffset = CFX_FloatPoint(0.0f, 0.0f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 309 | |
| 310 | CPVT_WordRange wrWhole = m_pEdit->GetWholeWordRange(); |
| 311 | CPVT_WordRange wrSelect = GetSelectWordRange(); |
| 312 | CPVT_WordRange wrVisible = |
| 313 | (HasFlag(PES_TEXTOVERFLOW) ? wrWhole : m_pEdit->GetVisibleWordRange()); |
| 314 | CPVT_WordRange wrSelBefore(wrWhole.BeginPos, wrSelect.BeginPos); |
| 315 | CPVT_WordRange wrSelAfter(wrSelect.EndPos, wrWhole.EndPos); |
| 316 | |
| 317 | CPVT_WordRange wrTemp = |
| 318 | CPWL_Utils::OverlapWordRange(GetSelectWordRange(), wrVisible); |
| 319 | CFX_ByteString sEditSel = |
| 320 | CPWL_Utils::GetEditSelAppStream(m_pEdit, ptOffset, &wrTemp); |
| 321 | |
| 322 | if (sEditSel.GetLength() > 0) |
| 323 | sText << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELBACKCOLOR) |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 324 | .AsByteStringC() |
| 325 | << sEditSel.AsByteStringC(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 326 | |
| 327 | wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelBefore); |
| 328 | CFX_ByteString sEditBefore = CPWL_Utils::GetEditAppStream( |
| 329 | m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), |
| 330 | m_pEdit->GetPasswordChar()); |
| 331 | |
| 332 | if (sEditBefore.GetLength() > 0) |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 333 | sText << "BT\n" |
| 334 | << CPWL_Utils::GetColorAppStream(GetTextColor()).AsByteStringC() |
| 335 | << sEditBefore.AsByteStringC() << "ET\n"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 336 | |
| 337 | wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelect); |
| 338 | CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream( |
| 339 | m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), |
| 340 | m_pEdit->GetPasswordChar()); |
| 341 | |
| 342 | if (sEditMid.GetLength() > 0) |
| 343 | sText << "BT\n" |
| 344 | << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1)) |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 345 | .AsByteStringC() |
| 346 | << sEditMid.AsByteStringC() << "ET\n"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 347 | |
| 348 | wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelAfter); |
| 349 | CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream( |
| 350 | m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), |
| 351 | m_pEdit->GetPasswordChar()); |
| 352 | |
| 353 | if (sEditAfter.GetLength() > 0) |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 354 | sText << "BT\n" |
| 355 | << CPWL_Utils::GetColorAppStream(GetTextColor()).AsByteStringC() |
| 356 | << sEditAfter.AsByteStringC() << "ET\n"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 357 | |
| 358 | if (HasFlag(PES_SPELLCHECK)) { |
| 359 | CFX_ByteString sSpellCheck = CPWL_Utils::GetSpellCheckAppStream( |
| 360 | m_pEdit, m_pSpellCheck, ptOffset, &wrVisible); |
| 361 | if (sSpellCheck.GetLength() > 0) |
| 362 | sText << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_RGB, 1, 0, 0), |
| 363 | FALSE) |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 364 | .AsByteStringC() |
| 365 | << sSpellCheck.AsByteStringC(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | if (sText.GetLength() > 0) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 369 | CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 370 | sAppStream << "q\n/Tx BMC\n"; |
| 371 | |
| 372 | if (!HasFlag(PES_TEXTOVERFLOW)) |
| 373 | sAppStream << rcClient.left << " " << rcClient.bottom << " " |
| 374 | << rcClient.right - rcClient.left << " " |
| 375 | << rcClient.top - rcClient.bottom << " re W n\n"; |
| 376 | |
| 377 | sAppStream << sText; |
| 378 | |
| 379 | sAppStream << "EMC\nQ\n"; |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice, |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 384 | CFX_Matrix* pUser2Device) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 385 | CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); |
| 386 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 387 | CFX_FloatRect rcClient = GetClientRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 388 | CFX_ByteTextBuf sLine; |
| 389 | |
| 390 | int32_t nCharArray = m_pEdit->GetCharArray(); |
| 391 | FX_SAFE_INT32 nCharArraySafe = nCharArray; |
| 392 | nCharArraySafe -= 1; |
| 393 | nCharArraySafe *= 2; |
| 394 | |
| 395 | if (nCharArray > 0 && nCharArraySafe.IsValid()) { |
| 396 | switch (GetBorderStyle()) { |
| 397 | case PBS_SOLID: { |
| 398 | CFX_GraphStateData gsd; |
| 399 | gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth(); |
| 400 | |
| 401 | CFX_PathData path; |
| 402 | path.SetPointCount(nCharArraySafe.ValueOrDie()); |
| 403 | |
| 404 | for (int32_t i = 0; i < nCharArray - 1; i++) { |
| 405 | path.SetPoint( |
| 406 | i * 2, |
| 407 | rcClient.left + |
| 408 | ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), |
| 409 | rcClient.bottom, FXPT_MOVETO); |
| 410 | path.SetPoint( |
| 411 | i * 2 + 1, |
| 412 | rcClient.left + |
| 413 | ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), |
| 414 | rcClient.top, FXPT_LINETO); |
| 415 | } |
| 416 | if (path.GetPointCount() > 0) |
| 417 | pDevice->DrawPath( |
| 418 | &path, pUser2Device, &gsd, 0, |
| 419 | CPWL_Utils::PWLColorToFXColor(GetBorderColor(), 255), |
| 420 | FXFILL_ALTERNATE); |
| 421 | } break; |
| 422 | case PBS_DASH: { |
| 423 | CFX_GraphStateData gsd; |
| 424 | gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth(); |
| 425 | |
| 426 | gsd.SetDashCount(2); |
| 427 | gsd.m_DashArray[0] = (FX_FLOAT)GetBorderDash().nDash; |
| 428 | gsd.m_DashArray[1] = (FX_FLOAT)GetBorderDash().nGap; |
| 429 | gsd.m_DashPhase = (FX_FLOAT)GetBorderDash().nPhase; |
| 430 | |
| 431 | CFX_PathData path; |
| 432 | path.SetPointCount(nCharArraySafe.ValueOrDie()); |
| 433 | |
| 434 | for (int32_t i = 0; i < nCharArray - 1; i++) { |
| 435 | path.SetPoint( |
| 436 | i * 2, |
| 437 | rcClient.left + |
| 438 | ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), |
| 439 | rcClient.bottom, FXPT_MOVETO); |
| 440 | path.SetPoint( |
| 441 | i * 2 + 1, |
| 442 | rcClient.left + |
| 443 | ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), |
| 444 | rcClient.top, FXPT_LINETO); |
| 445 | } |
| 446 | if (path.GetPointCount() > 0) |
| 447 | pDevice->DrawPath( |
| 448 | &path, pUser2Device, &gsd, 0, |
| 449 | CPWL_Utils::PWLColorToFXColor(GetBorderColor(), 255), |
| 450 | FXFILL_ALTERNATE); |
| 451 | } break; |
| 452 | } |
| 453 | } |
| 454 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 455 | CFX_FloatRect rcClip; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 456 | CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange(); |
| 457 | CPVT_WordRange* pRange = NULL; |
| 458 | |
| 459 | if (!HasFlag(PES_TEXTOVERFLOW)) { |
| 460 | rcClip = GetClientRect(); |
| 461 | pRange = &wrRange; |
| 462 | } |
| 463 | IFX_SystemHandler* pSysHandler = GetSystemHandler(); |
| 464 | IFX_Edit::DrawEdit( |
| 465 | pDevice, pUser2Device, m_pEdit, |
| 466 | CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), |
| 467 | CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), GetTransparency()), |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 468 | rcClip, CFX_FloatPoint(0.0f, 0.0f), pRange, pSysHandler, m_pFormFiller); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 469 | |
| 470 | if (HasFlag(PES_SPELLCHECK)) { |
| 471 | CPWL_Utils::DrawEditSpellCheck(pDevice, pUser2Device, m_pEdit, rcClip, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 472 | CFX_FloatPoint(0.0f, 0.0f), pRange, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 473 | GetCreationParam().pSpellCheck); |
| 474 | } |
| 475 | } |
| 476 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 477 | FX_BOOL CPWL_Edit::OnLButtonDown(const CFX_FloatPoint& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 478 | CPWL_Wnd::OnLButtonDown(point, nFlag); |
| 479 | |
| 480 | if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) { |
| 481 | if (m_bMouseDown) |
| 482 | InvalidateRect(); |
| 483 | |
| 484 | m_bMouseDown = TRUE; |
| 485 | SetCapture(); |
| 486 | |
| 487 | m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 488 | } |
| 489 | |
| 490 | return TRUE; |
| 491 | } |
| 492 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 493 | FX_BOOL CPWL_Edit::OnLButtonDblClk(const CFX_FloatPoint& point, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 494 | uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 495 | CPWL_Wnd::OnLButtonDblClk(point, nFlag); |
| 496 | |
| 497 | if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) { |
| 498 | m_pEdit->SelectAll(); |
| 499 | } |
| 500 | |
| 501 | return TRUE; |
| 502 | } |
| 503 | |
| 504 | #define WM_PWLEDIT_UNDO 0x01 |
| 505 | #define WM_PWLEDIT_REDO 0x02 |
| 506 | #define WM_PWLEDIT_CUT 0x03 |
| 507 | #define WM_PWLEDIT_COPY 0x04 |
| 508 | #define WM_PWLEDIT_PASTE 0x05 |
| 509 | #define WM_PWLEDIT_DELETE 0x06 |
| 510 | #define WM_PWLEDIT_SELECTALL 0x07 |
| 511 | #define WM_PWLEDIT_SUGGEST 0x08 |
| 512 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 513 | FX_BOOL CPWL_Edit::OnRButtonUp(const CFX_FloatPoint& point, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 514 | if (m_bMouseDown) |
| 515 | return FALSE; |
| 516 | |
| 517 | CPWL_Wnd::OnRButtonUp(point, nFlag); |
| 518 | |
| 519 | if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point)) |
| 520 | return TRUE; |
| 521 | |
| 522 | IFX_SystemHandler* pSH = GetSystemHandler(); |
| 523 | if (!pSH) |
| 524 | return FALSE; |
| 525 | |
| 526 | SetFocus(); |
| 527 | |
| 528 | CPVT_WordRange wrLatin = GetLatinWordsRange(point); |
| 529 | CFX_WideString swLatin = m_pEdit->GetRangeText(wrLatin); |
| 530 | |
| 531 | FX_HMENU hPopup = pSH->CreatePopupMenu(); |
| 532 | if (!hPopup) |
| 533 | return FALSE; |
| 534 | |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 535 | std::vector<CFX_ByteString> sSuggestWords; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 536 | CFX_FloatPoint ptPopup = point; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 537 | |
| 538 | if (!IsReadOnly()) { |
| 539 | if (HasFlag(PES_SPELLCHECK) && !swLatin.IsEmpty()) { |
| 540 | if (m_pSpellCheck) { |
| 541 | CFX_ByteString sLatin = CFX_ByteString::FromUnicode(swLatin); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 542 | if (!m_pSpellCheck->CheckWord(sLatin)) { |
| 543 | m_pSpellCheck->SuggestWords(sLatin, sSuggestWords); |
| 544 | |
Tom Sepez | ab27768 | 2016-02-17 10:07:21 -0800 | [diff] [blame] | 545 | int32_t nSuggest = pdfium::CollectionSize<int32_t>(sSuggestWords); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 546 | for (int32_t nWord = 0; nWord < nSuggest; nWord++) { |
| 547 | pSH->AppendMenuItem(hPopup, WM_PWLEDIT_SUGGEST + nWord, |
| 548 | sSuggestWords[nWord].UTF8Decode()); |
| 549 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 550 | if (nSuggest > 0) |
| 551 | pSH->AppendMenuItem(hPopup, 0, L""); |
| 552 | |
| 553 | ptPopup = GetWordRightBottomPoint(wrLatin.EndPos); |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | IPWL_Provider* pProvider = GetProvider(); |
| 560 | |
| 561 | if (HasFlag(PES_UNDO)) { |
| 562 | pSH->AppendMenuItem( |
| 563 | hPopup, WM_PWLEDIT_UNDO, |
| 564 | pProvider ? pProvider->LoadPopupMenuString(0) : L"&Undo"); |
| 565 | pSH->AppendMenuItem( |
| 566 | hPopup, WM_PWLEDIT_REDO, |
| 567 | pProvider ? pProvider->LoadPopupMenuString(1) : L"&Redo"); |
| 568 | pSH->AppendMenuItem(hPopup, 0, L""); |
| 569 | |
| 570 | if (!m_pEdit->CanUndo()) |
| 571 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_UNDO, FALSE); |
| 572 | if (!m_pEdit->CanRedo()) |
| 573 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_REDO, FALSE); |
| 574 | } |
| 575 | |
| 576 | pSH->AppendMenuItem(hPopup, WM_PWLEDIT_CUT, |
| 577 | pProvider ? pProvider->LoadPopupMenuString(2) : L"Cu&t"); |
| 578 | pSH->AppendMenuItem(hPopup, WM_PWLEDIT_COPY, |
| 579 | pProvider ? pProvider->LoadPopupMenuString(3) : L"&Copy"); |
| 580 | pSH->AppendMenuItem( |
| 581 | hPopup, WM_PWLEDIT_PASTE, |
| 582 | pProvider ? pProvider->LoadPopupMenuString(4) : L"&Paste"); |
| 583 | pSH->AppendMenuItem( |
| 584 | hPopup, WM_PWLEDIT_DELETE, |
| 585 | pProvider ? pProvider->LoadPopupMenuString(5) : L"&Delete"); |
| 586 | |
| 587 | CFX_WideString swText = pSH->GetClipboardText(GetAttachedHWnd()); |
| 588 | if (swText.IsEmpty()) |
| 589 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE); |
| 590 | |
| 591 | if (!m_pEdit->IsSelected()) { |
| 592 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); |
| 593 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE); |
| 594 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE); |
| 595 | } |
| 596 | |
| 597 | if (IsReadOnly()) { |
| 598 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); |
| 599 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE); |
| 600 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE); |
| 601 | } |
| 602 | |
| 603 | if (HasFlag(PES_PASSWORD)) { |
| 604 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); |
| 605 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE); |
| 606 | } |
| 607 | |
| 608 | if (HasFlag(PES_NOREAD)) { |
| 609 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); |
| 610 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE); |
| 611 | } |
| 612 | |
| 613 | pSH->AppendMenuItem(hPopup, 0, L""); |
| 614 | pSH->AppendMenuItem( |
| 615 | hPopup, WM_PWLEDIT_SELECTALL, |
| 616 | pProvider ? pProvider->LoadPopupMenuString(6) : L"&Select All"); |
| 617 | |
| 618 | if (m_pEdit->GetTotalWords() == 0) { |
| 619 | pSH->EnableMenuItem(hPopup, WM_PWLEDIT_SELECTALL, FALSE); |
| 620 | } |
| 621 | |
| 622 | int32_t x, y; |
| 623 | PWLtoWnd(ptPopup, x, y); |
| 624 | pSH->ClientToScreen(GetAttachedHWnd(), x, y); |
| 625 | pSH->SetCursor(FXCT_ARROW); |
| 626 | int32_t nCmd = pSH->TrackPopupMenu(hPopup, x, y, GetAttachedHWnd()); |
| 627 | |
| 628 | switch (nCmd) { |
| 629 | case WM_PWLEDIT_UNDO: |
| 630 | Undo(); |
| 631 | break; |
| 632 | case WM_PWLEDIT_REDO: |
| 633 | Redo(); |
| 634 | break; |
| 635 | case WM_PWLEDIT_CUT: |
| 636 | CutText(); |
| 637 | break; |
| 638 | case WM_PWLEDIT_COPY: |
| 639 | CopyText(); |
| 640 | break; |
| 641 | case WM_PWLEDIT_PASTE: |
| 642 | PasteText(); |
| 643 | break; |
| 644 | case WM_PWLEDIT_DELETE: |
| 645 | Clear(); |
| 646 | break; |
| 647 | case WM_PWLEDIT_SELECTALL: |
| 648 | SelectAll(); |
| 649 | break; |
| 650 | case WM_PWLEDIT_SUGGEST + 0: |
| 651 | SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), |
| 652 | m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); |
| 653 | ReplaceSel(sSuggestWords[0].UTF8Decode().c_str()); |
| 654 | break; |
| 655 | case WM_PWLEDIT_SUGGEST + 1: |
| 656 | SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), |
| 657 | m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); |
| 658 | ReplaceSel(sSuggestWords[1].UTF8Decode().c_str()); |
| 659 | break; |
| 660 | case WM_PWLEDIT_SUGGEST + 2: |
| 661 | SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), |
| 662 | m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); |
| 663 | ReplaceSel(sSuggestWords[2].UTF8Decode().c_str()); |
| 664 | break; |
| 665 | case WM_PWLEDIT_SUGGEST + 3: |
| 666 | SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), |
| 667 | m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); |
| 668 | ReplaceSel(sSuggestWords[3].UTF8Decode().c_str()); |
| 669 | break; |
| 670 | case WM_PWLEDIT_SUGGEST + 4: |
| 671 | SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), |
| 672 | m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); |
| 673 | ReplaceSel(sSuggestWords[4].UTF8Decode().c_str()); |
| 674 | break; |
| 675 | default: |
| 676 | break; |
| 677 | } |
| 678 | |
| 679 | pSH->DestroyMenu(hPopup); |
| 680 | |
| 681 | return TRUE; |
| 682 | } |
| 683 | |
| 684 | void CPWL_Edit::OnSetFocus() { |
| 685 | SetEditCaret(TRUE); |
| 686 | |
| 687 | if (!IsReadOnly()) { |
| 688 | if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler()) |
| 689 | pFocusHandler->OnSetFocus(this); |
| 690 | } |
| 691 | |
| 692 | m_bFocus = TRUE; |
| 693 | } |
| 694 | |
| 695 | void CPWL_Edit::OnKillFocus() { |
| 696 | ShowVScrollBar(FALSE); |
| 697 | |
| 698 | m_pEdit->SelectNone(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 699 | SetCaret(FALSE, CFX_FloatPoint(0.0f, 0.0f), CFX_FloatPoint(0.0f, 0.0f)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 700 | |
| 701 | SetCharSet(0); |
| 702 | |
| 703 | if (!IsReadOnly()) { |
| 704 | if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler()) |
| 705 | pFocusHandler->OnKillFocus(this); |
| 706 | } |
| 707 | |
| 708 | m_bFocus = FALSE; |
| 709 | } |
| 710 | |
| 711 | void CPWL_Edit::SetHorzScale(int32_t nHorzScale, FX_BOOL bPaint /* = TRUE*/) { |
| 712 | m_pEdit->SetHorzScale(nHorzScale, bPaint); |
| 713 | } |
| 714 | |
| 715 | void CPWL_Edit::SetCharSpace(FX_FLOAT fCharSpace, FX_BOOL bPaint /* = TRUE*/) { |
| 716 | m_pEdit->SetCharSpace(fCharSpace, bPaint); |
| 717 | } |
| 718 | |
| 719 | void CPWL_Edit::SetLineLeading(FX_FLOAT fLineLeading, |
| 720 | FX_BOOL bPaint /* = TRUE*/) { |
| 721 | m_pEdit->SetLineLeading(fLineLeading, bPaint); |
| 722 | } |
| 723 | |
| 724 | CFX_ByteString CPWL_Edit::GetSelectAppearanceStream( |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 725 | const CFX_FloatPoint& ptOffset) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 726 | CPVT_WordRange wr = GetSelectWordRange(); |
| 727 | return CPWL_Utils::GetEditSelAppStream(m_pEdit, ptOffset, &wr); |
| 728 | } |
| 729 | |
| 730 | CPVT_WordRange CPWL_Edit::GetSelectWordRange() const { |
| 731 | if (m_pEdit->IsSelected()) { |
| 732 | int32_t nStart = -1; |
| 733 | int32_t nEnd = -1; |
| 734 | |
| 735 | m_pEdit->GetSel(nStart, nEnd); |
| 736 | |
| 737 | CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart); |
| 738 | CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd); |
| 739 | |
| 740 | return CPVT_WordRange(wpStart, wpEnd); |
| 741 | } |
| 742 | |
| 743 | return CPVT_WordRange(); |
| 744 | } |
| 745 | |
| 746 | CFX_ByteString CPWL_Edit::GetTextAppearanceStream( |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 747 | const CFX_FloatPoint& ptOffset) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 748 | CFX_ByteTextBuf sRet; |
| 749 | CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit, ptOffset); |
| 750 | |
| 751 | if (sEdit.GetLength() > 0) { |
tsepez | 28f97ff | 2016-04-04 16:41:35 -0700 | [diff] [blame] | 752 | sRet << "BT\n" |
| 753 | << CPWL_Utils::GetColorAppStream(GetTextColor()).AsByteStringC() |
| 754 | << sEdit.AsByteStringC() << "ET\n"; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | return sRet.GetByteString(); |
| 758 | } |
| 759 | |
| 760 | CFX_ByteString CPWL_Edit::GetCaretAppearanceStream( |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 761 | const CFX_FloatPoint& ptOffset) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 762 | if (m_pEditCaret) |
| 763 | return m_pEditCaret->GetCaretAppearanceStream(ptOffset); |
| 764 | |
| 765 | return CFX_ByteString(); |
| 766 | } |
| 767 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 768 | CFX_FloatPoint CPWL_Edit::GetWordRightBottomPoint( |
| 769 | const CPVT_WordPlace& wpWord) { |
| 770 | CFX_FloatPoint pt(0.0f, 0.0f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 771 | |
| 772 | if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) { |
| 773 | CPVT_WordPlace wpOld = pIterator->GetAt(); |
| 774 | pIterator->SetAt(wpWord); |
| 775 | CPVT_Word word; |
| 776 | if (pIterator->GetWord(word)) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 777 | pt = CFX_FloatPoint(word.ptWord.x + word.fWidth, |
| 778 | word.ptWord.y + word.fDescent); |
Lei Zhang | 60f507b | 2015-06-13 00:41:00 -0700 | [diff] [blame] | 779 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 780 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 781 | pIterator->SetAt(wpOld); |
| 782 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 783 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 784 | return pt; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 787 | FX_BOOL CPWL_Edit::IsTextFull() const { |
| 788 | return m_pEdit->IsTextFull(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 789 | } |
| 790 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 791 | FX_FLOAT CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 792 | const CFX_FloatRect& rcPlate, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 793 | int32_t nCharArray) { |
| 794 | if (pFont && !pFont->IsStandardFont()) { |
| 795 | FX_RECT rcBBox; |
| 796 | pFont->GetFontBBox(rcBBox); |
| 797 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 798 | CFX_FloatRect rcCell = rcPlate; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 799 | FX_FLOAT xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width(); |
| 800 | FX_FLOAT ydiv = -rcCell.Height() * 1000.0f / rcBBox.Height(); |
| 801 | |
| 802 | return xdiv < ydiv ? xdiv : ydiv; |
| 803 | } |
| 804 | |
| 805 | return 0.0f; |
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 | void CPWL_Edit::SetCharArray(int32_t nCharArray) { |
| 809 | if (HasFlag(PES_CHARARRAY) && nCharArray > 0) { |
| 810 | m_pEdit->SetCharArray(nCharArray); |
| 811 | m_pEdit->SetTextOverflow(TRUE); |
| 812 | |
| 813 | if (HasFlag(PWS_AUTOFONTSIZE)) { |
| 814 | if (IFX_Edit_FontMap* pFontMap = GetFontMap()) { |
| 815 | FX_FLOAT fFontSize = GetCharArrayAutoFontSize( |
| 816 | pFontMap->GetPDFFont(0), GetClientRect(), nCharArray); |
| 817 | if (fFontSize > 0.0f) { |
| 818 | m_pEdit->SetAutoFontSize(FALSE); |
| 819 | m_pEdit->SetFontSize(fFontSize); |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 824 | } |
| 825 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 826 | void CPWL_Edit::SetLimitChar(int32_t nLimitChar) { |
| 827 | m_pEdit->SetLimitChar(nLimitChar); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 828 | } |
| 829 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 830 | void CPWL_Edit::ReplaceSel(const FX_WCHAR* csText) { |
| 831 | m_pEdit->Clear(); |
| 832 | m_pEdit->InsertText(csText); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 833 | } |
| 834 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 835 | CFX_FloatRect CPWL_Edit::GetFocusRect() const { |
| 836 | return CFX_FloatRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 837 | } |
| 838 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 839 | void CPWL_Edit::ShowVScrollBar(FX_BOOL bShow) { |
| 840 | if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { |
| 841 | if (bShow) { |
| 842 | if (!pScroll->IsVisible()) { |
| 843 | pScroll->SetVisible(TRUE); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 844 | CFX_FloatRect rcWindow = GetWindowRect(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 845 | m_rcOldWindow = rcWindow; |
| 846 | rcWindow.right += PWL_SCROLLBAR_WIDTH; |
| 847 | Move(rcWindow, TRUE, TRUE); |
| 848 | } |
| 849 | } else { |
| 850 | if (pScroll->IsVisible()) { |
| 851 | pScroll->SetVisible(FALSE); |
| 852 | Move(m_rcOldWindow, TRUE, TRUE); |
| 853 | } |
| 854 | } |
| 855 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 856 | } |
| 857 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 858 | FX_BOOL CPWL_Edit::IsVScrollBarVisible() const { |
| 859 | if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { |
| 860 | return pScroll->IsVisible(); |
| 861 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 862 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 863 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 864 | } |
| 865 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 866 | void CPWL_Edit::EnableSpellCheck(FX_BOOL bEnabled) { |
| 867 | if (bEnabled) |
| 868 | AddFlag(PES_SPELLCHECK); |
| 869 | else |
| 870 | RemoveFlag(PES_SPELLCHECK); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 871 | } |
| 872 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 873 | FX_BOOL CPWL_Edit::OnKeyDown(uint16_t nChar, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 874 | if (m_bMouseDown) |
| 875 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 876 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 877 | if (nChar == FWL_VKEY_Delete) { |
| 878 | if (m_pFillerNotify) { |
| 879 | FX_BOOL bRC = TRUE; |
| 880 | FX_BOOL bExit = FALSE; |
| 881 | CFX_WideString strChange; |
| 882 | CFX_WideString strChangeEx; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 883 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 884 | int nSelStart = 0; |
| 885 | int nSelEnd = 0; |
| 886 | GetSel(nSelStart, nSelEnd); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 887 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 888 | if (nSelStart == nSelEnd) |
| 889 | nSelEnd = nSelStart + 1; |
Lei Zhang | a5b4704 | 2015-10-19 14:32:16 -0700 | [diff] [blame] | 890 | m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), strChange, |
| 891 | strChangeEx, nSelStart, nSelEnd, TRUE, |
| 892 | bRC, bExit, nFlag); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 893 | if (!bRC) |
| 894 | return FALSE; |
| 895 | if (bExit) |
| 896 | return FALSE; |
| 897 | } |
| 898 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 899 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 900 | FX_BOOL bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 901 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 902 | // In case of implementation swallow the OnKeyDown event. |
| 903 | if (IsProceedtoOnChar(nChar, nFlag)) |
| 904 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 905 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 906 | return bRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | /** |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 910 | *In case of implementation swallow the OnKeyDown event. |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 911 | *If the event is swallowed, implementation may do other unexpected things, which |
| 912 | *is not the control means to do. |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 913 | */ |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 914 | FX_BOOL CPWL_Edit::IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 915 | FX_BOOL bCtrl = IsCTRLpressed(nFlag); |
| 916 | FX_BOOL bAlt = IsALTpressed(nFlag); |
| 917 | if (bCtrl && !bAlt) { |
| 918 | // hot keys for edit control. |
| 919 | switch (nKeyCode) { |
| 920 | case 'C': |
| 921 | case 'V': |
| 922 | case 'X': |
| 923 | case 'A': |
| 924 | case 'Z': |
| 925 | return TRUE; |
| 926 | default: |
| 927 | break; |
| 928 | } |
| 929 | } |
| 930 | // control characters. |
| 931 | switch (nKeyCode) { |
| 932 | case FWL_VKEY_Escape: |
| 933 | case FWL_VKEY_Back: |
| 934 | case FWL_VKEY_Return: |
| 935 | case FWL_VKEY_Space: |
| 936 | return TRUE; |
| 937 | default: |
Lei Zhang | a5b4704 | 2015-10-19 14:32:16 -0700 | [diff] [blame] | 938 | return FALSE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 939 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 940 | } |
| 941 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 942 | FX_BOOL CPWL_Edit::OnChar(uint16_t nChar, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 943 | if (m_bMouseDown) |
| 944 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 945 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 946 | FX_BOOL bRC = TRUE; |
| 947 | FX_BOOL bExit = FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 948 | |
Lei Zhang | a5b4704 | 2015-10-19 14:32:16 -0700 | [diff] [blame] | 949 | if (!IsCTRLpressed(nFlag)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 950 | if (m_pFillerNotify) { |
| 951 | CFX_WideString swChange; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 952 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 953 | int nSelStart = 0; |
| 954 | int nSelEnd = 0; |
| 955 | GetSel(nSelStart, nSelEnd); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 956 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 957 | switch (nChar) { |
| 958 | case FWL_VKEY_Back: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 959 | if (nSelStart == nSelEnd) |
| 960 | nSelStart = nSelEnd - 1; |
| 961 | break; |
| 962 | case FWL_VKEY_Return: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 963 | break; |
| 964 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 965 | swChange += nChar; |
| 966 | break; |
| 967 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 968 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 969 | CFX_WideString strChangeEx; |
Lei Zhang | a5b4704 | 2015-10-19 14:32:16 -0700 | [diff] [blame] | 970 | m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swChange, |
| 971 | strChangeEx, nSelStart, nSelEnd, TRUE, |
| 972 | bRC, bExit, nFlag); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 973 | } |
| 974 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 975 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 976 | if (!bRC) |
| 977 | return TRUE; |
| 978 | if (bExit) |
| 979 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 980 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 981 | if (IFX_Edit_FontMap* pFontMap = GetFontMap()) { |
| 982 | int32_t nOldCharSet = GetCharSet(); |
| 983 | int32_t nNewCharSet = pFontMap->CharSetFromUnicode(nChar, DEFAULT_CHARSET); |
| 984 | if (nOldCharSet != nNewCharSet) { |
| 985 | SetCharSet(nNewCharSet); |
| 986 | } |
| 987 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 988 | |
Lei Zhang | a5b4704 | 2015-10-19 14:32:16 -0700 | [diff] [blame] | 989 | return CPWL_EditCtrl::OnChar(nChar, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 990 | } |
| 991 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 992 | FX_BOOL CPWL_Edit::OnMouseWheel(short zDelta, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 993 | const CFX_FloatPoint& point, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 994 | uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 995 | if (HasFlag(PES_MULTILINE)) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 996 | CFX_FloatPoint ptScroll = GetScrollPos(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 997 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 998 | if (zDelta > 0) { |
| 999 | ptScroll.y += GetFontSize(); |
| 1000 | } else { |
| 1001 | ptScroll.y -= GetFontSize(); |
| 1002 | } |
| 1003 | SetScrollPos(ptScroll); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1004 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1005 | return TRUE; |
| 1006 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1007 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1008 | return FALSE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1009 | } |
| 1010 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1011 | void CPWL_Edit::OnInsertReturn(const CPVT_WordPlace& place, |
| 1012 | const CPVT_WordPlace& oldplace) { |
| 1013 | if (HasFlag(PES_SPELLCHECK)) { |
| 1014 | m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
| 1015 | GetLatinWordsRange(place))); |
| 1016 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1017 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1018 | if (m_pEditNotify) { |
| 1019 | m_pEditNotify->OnInsertReturn(place, oldplace); |
| 1020 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1023 | void CPWL_Edit::OnBackSpace(const CPVT_WordPlace& place, |
| 1024 | const CPVT_WordPlace& oldplace) { |
| 1025 | if (HasFlag(PES_SPELLCHECK)) { |
| 1026 | m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
| 1027 | GetLatinWordsRange(place))); |
| 1028 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1029 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1030 | if (m_pEditNotify) { |
| 1031 | m_pEditNotify->OnBackSpace(place, oldplace); |
| 1032 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1033 | } |
| 1034 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1035 | void CPWL_Edit::OnDelete(const CPVT_WordPlace& place, |
| 1036 | const CPVT_WordPlace& oldplace) { |
| 1037 | if (HasFlag(PES_SPELLCHECK)) { |
| 1038 | m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
| 1039 | GetLatinWordsRange(place))); |
| 1040 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1041 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1042 | if (m_pEditNotify) { |
| 1043 | m_pEditNotify->OnDelete(place, oldplace); |
| 1044 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1047 | void CPWL_Edit::OnClear(const CPVT_WordPlace& place, |
| 1048 | const CPVT_WordPlace& oldplace) { |
| 1049 | if (HasFlag(PES_SPELLCHECK)) { |
| 1050 | m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
| 1051 | GetLatinWordsRange(place))); |
| 1052 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1053 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1054 | if (m_pEditNotify) { |
| 1055 | m_pEditNotify->OnClear(place, oldplace); |
| 1056 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1059 | void CPWL_Edit::OnInsertWord(const CPVT_WordPlace& place, |
| 1060 | const CPVT_WordPlace& oldplace) { |
| 1061 | if (HasFlag(PES_SPELLCHECK)) { |
| 1062 | m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
| 1063 | GetLatinWordsRange(place))); |
| 1064 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1065 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1066 | if (m_pEditNotify) { |
| 1067 | m_pEditNotify->OnInsertWord(place, oldplace); |
| 1068 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1069 | } |
| 1070 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1071 | void CPWL_Edit::OnSetText(const CPVT_WordPlace& place, |
| 1072 | const CPVT_WordPlace& oldplace) {} |
| 1073 | |
| 1074 | void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place, |
| 1075 | const CPVT_WordPlace& oldplace) { |
| 1076 | if (HasFlag(PES_SPELLCHECK)) { |
| 1077 | m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
| 1078 | GetLatinWordsRange(place))); |
| 1079 | } |
| 1080 | |
| 1081 | if (m_pEditNotify) { |
| 1082 | m_pEditNotify->OnInsertText(place, oldplace); |
| 1083 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1086 | void CPWL_Edit::OnAddUndo(IFX_Edit_UndoItem* pUndoItem) { |
| 1087 | if (m_pEditNotify) { |
| 1088 | m_pEditNotify->OnAddUndo(this); |
| 1089 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1090 | } |
| 1091 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1092 | CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1, |
| 1093 | const CPVT_WordRange& wr2) { |
| 1094 | CPVT_WordRange wrRet; |
| 1095 | |
| 1096 | if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0) { |
| 1097 | wrRet.BeginPos = wr1.BeginPos; |
| 1098 | } else { |
| 1099 | wrRet.BeginPos = wr2.BeginPos; |
| 1100 | } |
| 1101 | |
| 1102 | if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) { |
| 1103 | wrRet.EndPos = wr2.EndPos; |
| 1104 | } else { |
| 1105 | wrRet.EndPos = wr1.EndPos; |
| 1106 | } |
| 1107 | |
| 1108 | return wrRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1111 | CPVT_WordRange CPWL_Edit::GetLatinWordsRange( |
| 1112 | const CFX_FloatPoint& point) const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1113 | return GetSameWordsRange(m_pEdit->SearchWordPlace(point), TRUE, FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1114 | } |
| 1115 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1116 | CPVT_WordRange CPWL_Edit::GetLatinWordsRange( |
| 1117 | const CPVT_WordPlace& place) const { |
| 1118 | return GetSameWordsRange(place, TRUE, FALSE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1119 | } |
| 1120 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1121 | CPVT_WordRange CPWL_Edit::GetArabicWordsRange( |
| 1122 | const CPVT_WordPlace& place) const { |
| 1123 | return GetSameWordsRange(place, FALSE, TRUE); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1126 | #define PWL_ISARABICWORD(word) \ |
| 1127 | ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC)) |
| 1128 | |
| 1129 | CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace& place, |
| 1130 | FX_BOOL bLatin, |
| 1131 | FX_BOOL bArabic) const { |
| 1132 | CPVT_WordRange range; |
| 1133 | |
| 1134 | if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) { |
| 1135 | CPVT_Word wordinfo; |
| 1136 | CPVT_WordPlace wpStart(place), wpEnd(place); |
| 1137 | pIterator->SetAt(place); |
| 1138 | |
| 1139 | if (bLatin) { |
| 1140 | while (pIterator->NextWord()) { |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1141 | if (!pIterator->GetWord(wordinfo) || |
| 1142 | !FX_EDIT_ISLATINWORD(wordinfo.Word)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1143 | break; |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | wpEnd = pIterator->GetAt(); |
| 1147 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1148 | } else if (bArabic) { |
| 1149 | while (pIterator->NextWord()) { |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1150 | if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1151 | break; |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1152 | |
| 1153 | wpEnd = pIterator->GetAt(); |
| 1154 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | pIterator->SetAt(place); |
| 1158 | |
| 1159 | if (bLatin) { |
| 1160 | do { |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1161 | if (!pIterator->GetWord(wordinfo) || |
| 1162 | !FX_EDIT_ISLATINWORD(wordinfo.Word)) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1163 | break; |
| 1164 | } |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1165 | |
| 1166 | wpStart = pIterator->GetAt(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1167 | } while (pIterator->PrevWord()); |
| 1168 | } else if (bArabic) { |
| 1169 | do { |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1170 | if (!pIterator->GetWord(wordinfo) || !PWL_ISARABICWORD(wordinfo.Word)) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1171 | break; |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 1172 | |
| 1173 | wpStart = pIterator->GetAt(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1174 | } while (pIterator->PrevWord()); |
| 1175 | } |
| 1176 | |
| 1177 | range.Set(wpStart, wpEnd); |
| 1178 | } |
| 1179 | |
| 1180 | return range; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1183 | void CPWL_Edit::GeneratePageObjects( |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1184 | CPDF_PageObjectHolder* pObjectHolder, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1185 | const CFX_FloatPoint& ptOffset, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1186 | CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { |
| 1187 | IFX_Edit::GeneratePageObjects( |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1188 | pObjectHolder, m_pEdit, ptOffset, NULL, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1189 | CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), |
| 1190 | ObjArray); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1191 | } |
| 1192 | |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1193 | void CPWL_Edit::GeneratePageObjects(CPDF_PageObjectHolder* pObjectHolder, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 1194 | const CFX_FloatPoint& ptOffset) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1195 | CFX_ArrayTemplate<CPDF_TextObject*> ObjArray; |
| 1196 | IFX_Edit::GeneratePageObjects( |
Tom Sepez | 2398d89 | 2016-02-17 16:46:26 -0800 | [diff] [blame] | 1197 | pObjectHolder, m_pEdit, ptOffset, NULL, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 1198 | CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), |
| 1199 | ObjArray); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1200 | } |