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