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 | 60f507b | 2015-06-13 00:41:00 -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_EditCtrl.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 8 | |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 9 | #include "core/fpdfdoc/include/cpvt_section.h" |
| 10 | #include "core/fpdfdoc/include/cpvt_word.h" |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 11 | #include "fpdfsdk/pdfwindow/PWL_Caret.h" |
| 12 | #include "fpdfsdk/pdfwindow/PWL_FontMap.h" |
| 13 | #include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" |
| 14 | #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
| 15 | #include "fpdfsdk/pdfwindow/PWL_Wnd.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 16 | #include "public/fpdf_fwlevent.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 17 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 18 | #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001) |
| 19 | #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) |
| 20 | #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) |
| 21 | #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb)) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 22 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 23 | CPWL_EditCtrl::CPWL_EditCtrl() |
| 24 | : m_pEdit(NULL), |
| 25 | m_pEditCaret(NULL), |
| 26 | m_bMouseDown(FALSE), |
| 27 | m_pEditNotify(NULL), |
| 28 | m_nCharSet(DEFAULT_CHARSET), |
| 29 | m_nCodePage(0) { |
| 30 | m_pEdit = IFX_Edit::NewEdit(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 31 | ASSERT(m_pEdit); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 32 | } |
| 33 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 34 | CPWL_EditCtrl::~CPWL_EditCtrl() { |
| 35 | IFX_Edit::DelEdit(m_pEdit); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 36 | } |
| 37 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 38 | void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM& cp) { |
| 39 | cp.eCursorType = FXCT_VBEAM; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 42 | void CPWL_EditCtrl::OnCreated() { |
| 43 | SetFontSize(GetCreationParam().fFontSize); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 44 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 45 | m_pEdit->SetFontMap(GetFontMap()); |
| 46 | m_pEdit->SetNotify(this); |
| 47 | m_pEdit->Initialize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 50 | FX_BOOL CPWL_EditCtrl::IsWndHorV() { |
Tom Sepez | 60d909e | 2015-12-10 15:34:55 -0800 | [diff] [blame] | 51 | CFX_Matrix mt = GetWindowMatrix(); |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 52 | CFX_FloatPoint point1(0, 1); |
| 53 | CFX_FloatPoint point2(1, 1); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 54 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 55 | mt.Transform(point1.x, point1.y); |
| 56 | mt.Transform(point2.x, point2.y); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 57 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 58 | return point2.y == point1.y; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 61 | void CPWL_EditCtrl::SetCursor() { |
| 62 | if (IsValid()) { |
dsinclair | b959010 | 2016-04-27 06:38:59 -0700 | [diff] [blame] | 63 | if (CFX_SystemHandler* pSH = GetSystemHandler()) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 64 | if (IsWndHorV()) |
| 65 | pSH->SetCursor(FXCT_VBEAM); |
| 66 | else |
| 67 | pSH->SetCursor(FXCT_HBEAM); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 68 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 69 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 72 | void CPWL_EditCtrl::RePosChildWnd() { |
| 73 | m_pEdit->SetPlateRect(GetClientRect()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 76 | void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 77 | uint32_t msg, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 78 | intptr_t wParam, |
| 79 | intptr_t lParam) { |
| 80 | CPWL_Wnd::OnNotify(pWnd, msg, wParam, lParam); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 81 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 82 | switch (msg) { |
| 83 | case PNM_SETSCROLLINFO: |
| 84 | switch (wParam) { |
| 85 | case SBT_VSCROLL: |
| 86 | if (CPWL_Wnd* pChild = GetVScrollBar()) { |
| 87 | pChild->OnNotify(pWnd, PNM_SETSCROLLINFO, wParam, lParam); |
| 88 | } |
| 89 | break; |
| 90 | } |
| 91 | break; |
| 92 | case PNM_SETSCROLLPOS: |
| 93 | switch (wParam) { |
| 94 | case SBT_VSCROLL: |
| 95 | if (CPWL_Wnd* pChild = GetVScrollBar()) { |
| 96 | pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam); |
| 97 | } |
| 98 | break; |
| 99 | } |
| 100 | break; |
| 101 | case PNM_SCROLLWINDOW: { |
| 102 | FX_FLOAT fPos = *(FX_FLOAT*)lParam; |
| 103 | switch (wParam) { |
| 104 | case SBT_VSCROLL: |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 105 | m_pEdit->SetScrollPos( |
| 106 | CFX_FloatPoint(m_pEdit->GetScrollPos().x, fPos)); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 107 | break; |
| 108 | } |
| 109 | } break; |
| 110 | case PNM_SETCARETINFO: { |
| 111 | if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) { |
| 112 | SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot); |
| 113 | } |
| 114 | } break; |
| 115 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 118 | void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) { |
| 119 | if (!IsReadOnly()) |
| 120 | CreateEditCaret(cp); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 123 | void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) { |
| 124 | if (!m_pEditCaret) { |
| 125 | m_pEditCaret = new CPWL_Caret; |
| 126 | m_pEditCaret->SetInvalidRect(GetClientRect()); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 127 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 128 | PWL_CREATEPARAM ecp = cp; |
| 129 | ecp.pParentWnd = this; |
| 130 | ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP; |
| 131 | ecp.dwBorderWidth = 0; |
| 132 | ecp.nBorderStyle = PBS_SOLID; |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 133 | ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 134 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 135 | m_pEditCaret->Create(ecp); |
| 136 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 137 | } |
| 138 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 139 | void CPWL_EditCtrl::SetFontSize(FX_FLOAT fFontSize) { |
| 140 | m_pEdit->SetFontSize(fFontSize); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 143 | FX_FLOAT CPWL_EditCtrl::GetFontSize() const { |
| 144 | return m_pEdit->GetFontSize(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 145 | } |
| 146 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 147 | FX_BOOL CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 148 | if (m_bMouseDown) |
| 149 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 150 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 151 | FX_BOOL bRet = CPWL_Wnd::OnKeyDown(nChar, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 152 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 153 | // FILTER |
| 154 | switch (nChar) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 155 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 156 | return FALSE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 157 | case FWL_VKEY_Delete: |
| 158 | case FWL_VKEY_Up: |
| 159 | case FWL_VKEY_Down: |
| 160 | case FWL_VKEY_Left: |
| 161 | case FWL_VKEY_Right: |
| 162 | case FWL_VKEY_Home: |
| 163 | case FWL_VKEY_End: |
| 164 | case FWL_VKEY_Insert: |
| 165 | case 'C': |
| 166 | case 'V': |
| 167 | case 'X': |
| 168 | case 'A': |
| 169 | case 'Z': |
| 170 | case 'c': |
| 171 | case 'v': |
| 172 | case 'x': |
| 173 | case 'a': |
| 174 | case 'z': |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 175 | break; |
| 176 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 177 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 178 | if (nChar == FWL_VKEY_Delete) { |
| 179 | if (m_pEdit->IsSelected()) |
| 180 | nChar = FWL_VKEY_Unknown; |
| 181 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 182 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 183 | switch (nChar) { |
| 184 | case FWL_VKEY_Delete: |
| 185 | Delete(); |
| 186 | return TRUE; |
| 187 | case FWL_VKEY_Insert: |
| 188 | if (IsSHIFTpressed(nFlag)) |
| 189 | PasteText(); |
| 190 | return TRUE; |
| 191 | case FWL_VKEY_Up: |
| 192 | m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag), FALSE); |
| 193 | return TRUE; |
| 194 | case FWL_VKEY_Down: |
| 195 | m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag), FALSE); |
| 196 | return TRUE; |
| 197 | case FWL_VKEY_Left: |
| 198 | m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag), FALSE); |
| 199 | return TRUE; |
| 200 | case FWL_VKEY_Right: |
| 201 | m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag), FALSE); |
| 202 | return TRUE; |
| 203 | case FWL_VKEY_Home: |
| 204 | m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 205 | return TRUE; |
| 206 | case FWL_VKEY_End: |
| 207 | m_pEdit->OnVK_END(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 208 | return TRUE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 209 | case FWL_VKEY_Unknown: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 210 | if (!IsSHIFTpressed(nFlag)) |
| 211 | Clear(); |
| 212 | else |
| 213 | CutText(); |
| 214 | return TRUE; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 215 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 216 | break; |
| 217 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 218 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 219 | return bRet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 220 | } |
| 221 | |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 222 | FX_BOOL CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 223 | if (m_bMouseDown) |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 224 | return TRUE; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 225 | |
| 226 | CPWL_Wnd::OnChar(nChar, nFlag); |
| 227 | |
| 228 | // FILTER |
| 229 | switch (nChar) { |
| 230 | case 0x0A: |
| 231 | case 0x1B: |
| 232 | return FALSE; |
| 233 | default: |
| 234 | break; |
| 235 | } |
| 236 | |
| 237 | FX_BOOL bCtrl = IsCTRLpressed(nFlag); |
| 238 | FX_BOOL bAlt = IsALTpressed(nFlag); |
| 239 | FX_BOOL bShift = IsSHIFTpressed(nFlag); |
| 240 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 241 | uint16_t word = nChar; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 242 | |
| 243 | if (bCtrl && !bAlt) { |
| 244 | switch (nChar) { |
| 245 | case 'C' - 'A' + 1: |
| 246 | CopyText(); |
| 247 | return TRUE; |
| 248 | case 'V' - 'A' + 1: |
| 249 | PasteText(); |
| 250 | return TRUE; |
| 251 | case 'X' - 'A' + 1: |
| 252 | CutText(); |
| 253 | return TRUE; |
| 254 | case 'A' - 'A' + 1: |
| 255 | SelectAll(); |
| 256 | return TRUE; |
| 257 | case 'Z' - 'A' + 1: |
| 258 | if (bShift) |
| 259 | Redo(); |
| 260 | else |
| 261 | Undo(); |
| 262 | return TRUE; |
| 263 | default: |
| 264 | if (nChar < 32) |
| 265 | return FALSE; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | if (IsReadOnly()) |
| 270 | return TRUE; |
| 271 | |
| 272 | if (m_pEdit->IsSelected() && word == FWL_VKEY_Back) |
| 273 | word = FWL_VKEY_Unknown; |
| 274 | |
| 275 | Clear(); |
| 276 | |
| 277 | switch (word) { |
| 278 | case FWL_VKEY_Back: |
| 279 | Backspace(); |
| 280 | break; |
| 281 | case FWL_VKEY_Return: |
| 282 | InsertReturn(); |
| 283 | break; |
| 284 | case FWL_VKEY_Unknown: |
| 285 | break; |
| 286 | default: |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 287 | InsertWord(word, GetCharSet()); |
| 288 | break; |
| 289 | } |
| 290 | |
| 291 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 294 | FX_BOOL CPWL_EditCtrl::OnLButtonDown(const CFX_FloatPoint& point, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 295 | uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 296 | CPWL_Wnd::OnLButtonDown(point, nFlag); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 297 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 298 | if (ClientHitTest(point)) { |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 299 | if (m_bMouseDown) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 300 | InvalidateRect(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 301 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 302 | m_bMouseDown = TRUE; |
| 303 | SetCapture(); |
| 304 | |
| 305 | m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
| 306 | } |
| 307 | |
| 308 | return TRUE; |
| 309 | } |
| 310 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 311 | FX_BOOL CPWL_EditCtrl::OnLButtonUp(const CFX_FloatPoint& point, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 312 | uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 313 | CPWL_Wnd::OnLButtonUp(point, nFlag); |
| 314 | |
| 315 | if (m_bMouseDown) { |
| 316 | // can receive keybord message |
| 317 | if (ClientHitTest(point) && !IsFocused()) |
| 318 | SetFocus(); |
| 319 | |
| 320 | ReleaseCapture(); |
| 321 | m_bMouseDown = FALSE; |
| 322 | } |
| 323 | |
| 324 | return TRUE; |
| 325 | } |
| 326 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 327 | FX_BOOL CPWL_EditCtrl::OnMouseMove(const CFX_FloatPoint& point, |
tsepez | c3255f5 | 2016-03-25 14:52:27 -0700 | [diff] [blame] | 328 | uint32_t nFlag) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 329 | CPWL_Wnd::OnMouseMove(point, nFlag); |
| 330 | |
| 331 | if (m_bMouseDown) |
| 332 | m_pEdit->OnMouseMove(point, FALSE, FALSE); |
| 333 | |
| 334 | return TRUE; |
| 335 | } |
| 336 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 337 | CFX_FloatRect CPWL_EditCtrl::GetContentRect() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 338 | return m_pEdit->GetContentRect(); |
| 339 | } |
| 340 | |
| 341 | void CPWL_EditCtrl::SetEditCaret(FX_BOOL bVisible) { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 342 | CFX_FloatPoint ptHead(0, 0), ptFoot(0, 0); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 343 | |
| 344 | if (bVisible) { |
| 345 | GetCaretInfo(ptHead, ptFoot); |
| 346 | } |
| 347 | |
| 348 | CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace(); |
| 349 | IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp); |
| 350 | } |
| 351 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 352 | void CPWL_EditCtrl::GetCaretInfo(CFX_FloatPoint& ptHead, |
| 353 | CFX_FloatPoint& ptFoot) const { |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame^] | 354 | IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator(); |
| 355 | pIterator->SetAt(m_pEdit->GetCaret()); |
| 356 | CPVT_Word word; |
| 357 | CPVT_Line line; |
| 358 | if (pIterator->GetWord(word)) { |
| 359 | ptHead.x = word.ptWord.x + word.fWidth; |
| 360 | ptHead.y = word.ptWord.y + word.fAscent; |
| 361 | ptFoot.x = word.ptWord.x + word.fWidth; |
| 362 | ptFoot.y = word.ptWord.y + word.fDescent; |
| 363 | } else if (pIterator->GetLine(line)) { |
| 364 | ptHead.x = line.ptLine.x; |
| 365 | ptHead.y = line.ptLine.y + line.fLineAscent; |
| 366 | ptFoot.x = line.ptLine.x; |
| 367 | ptFoot.y = line.ptLine.y + line.fLineDescent; |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 368 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 371 | void CPWL_EditCtrl::GetCaretPos(int32_t& x, int32_t& y) const { |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 372 | CFX_FloatPoint ptHead(0, 0), ptFoot(0, 0); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 373 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 374 | GetCaretInfo(ptHead, ptFoot); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 375 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 376 | PWLtoWnd(ptHead, x, y); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 379 | void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 380 | const CFX_FloatPoint& ptHead, |
| 381 | const CFX_FloatPoint& ptFoot) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 382 | if (m_pEditCaret) { |
| 383 | if (!IsFocused() || m_pEdit->IsSelected()) |
| 384 | bVisible = FALSE; |
| 385 | |
| 386 | m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot); |
| 387 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 390 | CFX_WideString CPWL_EditCtrl::GetText() const { |
| 391 | return m_pEdit->GetText(); |
| 392 | } |
| 393 | |
| 394 | void CPWL_EditCtrl::SetSel(int32_t nStartChar, int32_t nEndChar) { |
| 395 | m_pEdit->SetSel(nStartChar, nEndChar); |
| 396 | } |
| 397 | |
| 398 | void CPWL_EditCtrl::GetSel(int32_t& nStartChar, int32_t& nEndChar) const { |
| 399 | m_pEdit->GetSel(nStartChar, nEndChar); |
| 400 | } |
| 401 | |
| 402 | void CPWL_EditCtrl::Clear() { |
| 403 | if (!IsReadOnly()) |
| 404 | m_pEdit->Clear(); |
| 405 | } |
| 406 | |
| 407 | void CPWL_EditCtrl::SelectAll() { |
| 408 | m_pEdit->SelectAll(); |
| 409 | } |
| 410 | |
| 411 | void CPWL_EditCtrl::Paint() { |
| 412 | if (m_pEdit) |
| 413 | m_pEdit->Paint(); |
| 414 | } |
| 415 | |
| 416 | void CPWL_EditCtrl::EnableRefresh(FX_BOOL bRefresh) { |
| 417 | if (m_pEdit) |
| 418 | m_pEdit->EnableRefresh(bRefresh); |
| 419 | } |
| 420 | |
| 421 | int32_t CPWL_EditCtrl::GetCaret() const { |
| 422 | if (m_pEdit) |
| 423 | return m_pEdit->GetCaret(); |
| 424 | |
| 425 | return -1; |
| 426 | } |
| 427 | |
| 428 | void CPWL_EditCtrl::SetCaret(int32_t nPos) { |
| 429 | if (m_pEdit) |
| 430 | m_pEdit->SetCaret(nPos); |
| 431 | } |
| 432 | |
| 433 | int32_t CPWL_EditCtrl::GetTotalWords() const { |
| 434 | if (m_pEdit) |
| 435 | return m_pEdit->GetTotalWords(); |
| 436 | |
| 437 | return 0; |
| 438 | } |
| 439 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 440 | void CPWL_EditCtrl::SetScrollPos(const CFX_FloatPoint& point) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 441 | if (m_pEdit) |
| 442 | m_pEdit->SetScrollPos(point); |
| 443 | } |
| 444 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 445 | CFX_FloatPoint CPWL_EditCtrl::GetScrollPos() const { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 446 | if (m_pEdit) |
| 447 | return m_pEdit->GetScrollPos(); |
| 448 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 449 | return CFX_FloatPoint(0.0f, 0.0f); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | CPDF_Font* CPWL_EditCtrl::GetCaretFont() const { |
| 453 | int32_t nFontIndex = 0; |
| 454 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame^] | 455 | IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator(); |
| 456 | pIterator->SetAt(m_pEdit->GetCaret()); |
| 457 | CPVT_Word word; |
| 458 | CPVT_Section section; |
| 459 | if (pIterator->GetWord(word)) { |
| 460 | nFontIndex = word.nFontIndex; |
| 461 | } else if (HasFlag(PES_RICH)) { |
| 462 | if (pIterator->GetSection(section)) { |
| 463 | nFontIndex = section.WordProps.nFontIndex; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 464 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 465 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 466 | |
dsinclair | c7a7349 | 2016-04-05 12:01:42 -0700 | [diff] [blame] | 467 | if (IPVT_FontMap* pFontMap = GetFontMap()) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 468 | return pFontMap->GetPDFFont(nFontIndex); |
| 469 | |
| 470 | return NULL; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 471 | } |
| 472 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 473 | FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const { |
| 474 | FX_FLOAT fFontSize = GetFontSize(); |
| 475 | |
thestig | 821d59e | 2016-05-11 12:59:22 -0700 | [diff] [blame^] | 476 | IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator(); |
| 477 | pIterator->SetAt(m_pEdit->GetCaret()); |
| 478 | CPVT_Word word; |
| 479 | CPVT_Section section; |
| 480 | if (pIterator->GetWord(word)) { |
| 481 | fFontSize = word.fFontSize; |
| 482 | } else if (HasFlag(PES_RICH)) { |
| 483 | if (pIterator->GetSection(section)) { |
| 484 | fFontSize = section.WordProps.fFontSize; |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 485 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | return fFontSize; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 491 | void CPWL_EditCtrl::SetText(const FX_WCHAR* csText) { |
| 492 | m_pEdit->SetText(csText); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 493 | } |
| 494 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 495 | void CPWL_EditCtrl::CopyText() {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 496 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 497 | void CPWL_EditCtrl::PasteText() {} |
| 498 | |
| 499 | void CPWL_EditCtrl::CutText() {} |
| 500 | |
| 501 | void CPWL_EditCtrl::ShowVScrollBar(FX_BOOL bShow) {} |
| 502 | |
| 503 | void CPWL_EditCtrl::InsertText(const FX_WCHAR* csText) { |
| 504 | if (!IsReadOnly()) |
| 505 | m_pEdit->InsertText(csText); |
| 506 | } |
| 507 | |
Tom Sepez | 62a70f9 | 2016-03-21 15:00:20 -0700 | [diff] [blame] | 508 | void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t nCharset) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 509 | if (!IsReadOnly()) |
| 510 | m_pEdit->InsertWord(word, nCharset); |
| 511 | } |
| 512 | |
| 513 | void CPWL_EditCtrl::InsertReturn() { |
| 514 | if (!IsReadOnly()) |
| 515 | m_pEdit->InsertReturn(); |
| 516 | } |
| 517 | |
| 518 | void CPWL_EditCtrl::Delete() { |
| 519 | if (!IsReadOnly()) |
| 520 | m_pEdit->Delete(); |
| 521 | } |
| 522 | |
| 523 | void CPWL_EditCtrl::Backspace() { |
| 524 | if (!IsReadOnly()) |
| 525 | m_pEdit->Backspace(); |
| 526 | } |
| 527 | |
| 528 | FX_BOOL CPWL_EditCtrl::CanUndo() const { |
| 529 | return !IsReadOnly() && m_pEdit->CanUndo(); |
| 530 | } |
| 531 | |
| 532 | FX_BOOL CPWL_EditCtrl::CanRedo() const { |
| 533 | return !IsReadOnly() && m_pEdit->CanRedo(); |
| 534 | } |
| 535 | |
| 536 | void CPWL_EditCtrl::Redo() { |
| 537 | if (CanRedo()) |
| 538 | m_pEdit->Redo(); |
| 539 | } |
| 540 | |
| 541 | void CPWL_EditCtrl::Undo() { |
| 542 | if (CanUndo()) |
| 543 | m_pEdit->Undo(); |
| 544 | } |
| 545 | |
| 546 | void CPWL_EditCtrl::IOnSetScrollInfoY(FX_FLOAT fPlateMin, |
| 547 | FX_FLOAT fPlateMax, |
| 548 | FX_FLOAT fContentMin, |
| 549 | FX_FLOAT fContentMax, |
| 550 | FX_FLOAT fSmallStep, |
| 551 | FX_FLOAT fBigStep) { |
| 552 | PWL_SCROLL_INFO Info; |
| 553 | |
| 554 | Info.fPlateWidth = fPlateMax - fPlateMin; |
| 555 | Info.fContentMin = fContentMin; |
| 556 | Info.fContentMax = fContentMax; |
| 557 | Info.fSmallStep = fSmallStep; |
| 558 | Info.fBigStep = fBigStep; |
| 559 | |
| 560 | OnNotify(this, PNM_SETSCROLLINFO, SBT_VSCROLL, (intptr_t)&Info); |
| 561 | |
| 562 | if (IsFloatBigger(Info.fPlateWidth, Info.fContentMax - Info.fContentMin) || |
| 563 | IsFloatEqual(Info.fPlateWidth, Info.fContentMax - Info.fContentMin)) { |
| 564 | ShowVScrollBar(FALSE); |
| 565 | } else { |
| 566 | ShowVScrollBar(TRUE); |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy) { |
| 571 | OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy); |
| 572 | } |
| 573 | |
| 574 | void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 575 | const CFX_FloatPoint& ptHead, |
| 576 | const CFX_FloatPoint& ptFoot, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 577 | const CPVT_WordPlace& place) { |
| 578 | PWL_CARET_INFO cInfo; |
| 579 | cInfo.bVisible = bVisible; |
| 580 | cInfo.ptHead = ptHead; |
| 581 | cInfo.ptFoot = ptFoot; |
| 582 | |
| 583 | OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t)NULL); |
| 584 | } |
| 585 | |
| 586 | void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps& secProps, |
| 587 | const CPVT_WordProps& wordProps) {} |
| 588 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 589 | void CPWL_EditCtrl::IOnContentChange(const CFX_FloatRect& rcContent) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 590 | if (IsValid()) { |
| 591 | if (m_pEditNotify) { |
| 592 | m_pEditNotify->OnContentChange(rcContent); |
Tom Sepez | 2f2ffec | 2015-07-23 14:42:09 -0700 | [diff] [blame] | 593 | } |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 594 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 595 | } |
| 596 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 597 | void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 598 | InvalidateRect(pRect); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 599 | } |
| 600 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 601 | int32_t CPWL_EditCtrl::GetCharSet() const { |
| 602 | return m_nCharSet < 0 ? DEFAULT_CHARSET : m_nCharSet; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 605 | void CPWL_EditCtrl::GetTextRange(const CFX_FloatRect& rect, |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 606 | int32_t& nStartChar, |
| 607 | int32_t& nEndChar) const { |
| 608 | nStartChar = m_pEdit->WordPlaceToWordIndex( |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 609 | m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.left, rect.top))); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 610 | nEndChar = m_pEdit->WordPlaceToWordIndex( |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 611 | m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.right, rect.bottom))); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 612 | } |
| 613 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 614 | CFX_WideString CPWL_EditCtrl::GetText(int32_t& nStartChar, |
| 615 | int32_t& nEndChar) const { |
| 616 | CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar); |
| 617 | CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar); |
| 618 | return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd)); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 621 | void CPWL_EditCtrl::SetReadyToInput() { |
| 622 | if (m_bMouseDown) { |
| 623 | ReleaseCapture(); |
| 624 | m_bMouseDown = FALSE; |
| 625 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 626 | } |