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