OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fwl/core/cfwl_edit.h" | 7 #include "xfa/fwl/core/cfwl_edit.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "third_party/base/ptr_util.h" | 14 #include "third_party/base/ptr_util.h" |
15 #include "third_party/base/stl_util.h" | 15 #include "third_party/base/stl_util.h" |
16 #include "xfa/fde/cfde_txtedtengine.h" | 16 #include "xfa/fde/cfde_txtedtengine.h" |
17 #include "xfa/fde/fde_gedevice.h" | 17 #include "xfa/fde/fde_gedevice.h" |
18 #include "xfa/fde/fde_render.h" | 18 #include "xfa/fde/fde_render.h" |
19 #include "xfa/fde/ifde_txtedtpage.h" | 19 #include "xfa/fde/ifde_txtedtpage.h" |
20 #include "xfa/fgas/font/cfgas_gefont.h" | 20 #include "xfa/fgas/font/cfgas_gefont.h" |
21 #include "xfa/fwl/core/cfwl_app.h" | 21 #include "xfa/fwl/core/cfwl_app.h" |
22 #include "xfa/fwl/core/cfwl_caret.h" | 22 #include "xfa/fwl/core/cfwl_caret.h" |
| 23 #include "xfa/fwl/core/cfwl_event.h" |
23 #include "xfa/fwl/core/cfwl_evtcheckword.h" | 24 #include "xfa/fwl/core/cfwl_evtcheckword.h" |
24 #include "xfa/fwl/core/cfwl_evttextchanged.h" | 25 #include "xfa/fwl/core/cfwl_evttextchanged.h" |
25 #include "xfa/fwl/core/cfwl_evttextfull.h" | |
26 #include "xfa/fwl/core/cfwl_evtvalidate.h" | 26 #include "xfa/fwl/core/cfwl_evtvalidate.h" |
27 #include "xfa/fwl/core/cfwl_msgkey.h" | 27 #include "xfa/fwl/core/cfwl_msgkey.h" |
28 #include "xfa/fwl/core/cfwl_msgmouse.h" | 28 #include "xfa/fwl/core/cfwl_msgmouse.h" |
29 #include "xfa/fwl/core/cfwl_themebackground.h" | 29 #include "xfa/fwl/core/cfwl_themebackground.h" |
30 #include "xfa/fwl/core/cfwl_themepart.h" | 30 #include "xfa/fwl/core/cfwl_themepart.h" |
31 #include "xfa/fwl/core/cfwl_widgetmgr.h" | 31 #include "xfa/fwl/core/cfwl_widgetmgr.h" |
32 #include "xfa/fwl/core/ifwl_themeprovider.h" | 32 #include "xfa/fwl/core/ifwl_themeprovider.h" |
33 #include "xfa/fxfa/xfa_ffdoc.h" | 33 #include "xfa/fxfa/xfa_ffdoc.h" |
34 #include "xfa/fxfa/xfa_ffwidget.h" | 34 #include "xfa/fxfa/xfa_ffwidget.h" |
35 #include "xfa/fxgraphics/cfx_path.h" | 35 #include "xfa/fxgraphics/cfx_path.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 } | 193 } |
194 } | 194 } |
195 | 195 |
196 void CFWL_Edit::DrawSpellCheck(CFX_Graphics* pGraphics, | 196 void CFWL_Edit::DrawSpellCheck(CFX_Graphics* pGraphics, |
197 const CFX_Matrix* pMatrix) { | 197 const CFX_Matrix* pMatrix) { |
198 pGraphics->SaveGraphState(); | 198 pGraphics->SaveGraphState(); |
199 if (pMatrix) | 199 if (pMatrix) |
200 pGraphics->ConcatMatrix(const_cast<CFX_Matrix*>(pMatrix)); | 200 pGraphics->ConcatMatrix(const_cast<CFX_Matrix*>(pMatrix)); |
201 | 201 |
202 CFX_Color crLine(0xFFFF0000); | 202 CFX_Color crLine(0xFFFF0000); |
203 CFWL_EvtCheckWord checkWordEvent; | 203 CFWL_EvtCheckWord checkWordEvent(this); |
204 checkWordEvent.m_pSrcTarget = this; | |
205 | 204 |
206 CFX_ByteString sLatinWord; | 205 CFX_ByteString sLatinWord; |
207 CFX_Path pathSpell; | 206 CFX_Path pathSpell; |
208 pathSpell.Create(); | 207 pathSpell.Create(); |
209 | 208 |
210 int32_t nStart = 0; | 209 int32_t nStart = 0; |
211 FX_FLOAT fOffSetX = m_rtEngine.left - m_fScrollOffsetX; | 210 FX_FLOAT fOffSetX = m_rtEngine.left - m_fScrollOffsetX; |
212 FX_FLOAT fOffSetY = m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset; | 211 FX_FLOAT fOffSetY = m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset; |
213 | 212 |
214 CFX_WideString wsSpell = GetText(); | 213 CFX_WideString wsSpell = GetText(); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 } | 444 } |
446 | 445 |
447 void CFWL_Edit::On_TextChanged(CFDE_TxtEdtEngine* pEdit, | 446 void CFWL_Edit::On_TextChanged(CFDE_TxtEdtEngine* pEdit, |
448 FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo) { | 447 FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo) { |
449 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VAlignMask) | 448 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VAlignMask) |
450 UpdateVAlignment(); | 449 UpdateVAlignment(); |
451 | 450 |
452 CFX_RectF rtTemp; | 451 CFX_RectF rtTemp; |
453 GetClientRect(rtTemp); | 452 GetClientRect(rtTemp); |
454 | 453 |
455 CFWL_EvtTextChanged event; | 454 CFWL_EvtTextChanged event(this); |
456 event.m_pSrcTarget = this; | |
457 event.nChangeType = ChangeInfo.nChangeType; | |
458 event.wsInsert = ChangeInfo.wsInsert; | |
459 event.wsDelete = ChangeInfo.wsDelete; | |
460 event.wsPrevText = ChangeInfo.wsPrevText; | 455 event.wsPrevText = ChangeInfo.wsPrevText; |
461 DispatchEvent(&event); | 456 DispatchEvent(&event); |
462 | 457 |
463 LayoutScrollBar(); | 458 LayoutScrollBar(); |
464 Repaint(&rtTemp); | 459 Repaint(&rtTemp); |
465 } | 460 } |
466 | 461 |
467 void CFWL_Edit::On_SelChanged(CFDE_TxtEdtEngine* pEdit) { | 462 void CFWL_Edit::On_SelChanged(CFDE_TxtEdtEngine* pEdit) { |
468 CFX_RectF rtTemp; | 463 CFX_RectF rtTemp; |
469 GetClientRect(rtTemp); | 464 GetClientRect(rtTemp); |
(...skipping 25 matching lines...) Expand all Loading... |
495 void CFWL_Edit::On_AddDoRecord(CFDE_TxtEdtEngine* pEdit, | 490 void CFWL_Edit::On_AddDoRecord(CFDE_TxtEdtEngine* pEdit, |
496 IFDE_TxtEdtDoRecord* pRecord) { | 491 IFDE_TxtEdtDoRecord* pRecord) { |
497 AddDoRecord(pRecord); | 492 AddDoRecord(pRecord); |
498 } | 493 } |
499 | 494 |
500 bool CFWL_Edit::On_Validate(CFDE_TxtEdtEngine* pEdit, CFX_WideString& wsText) { | 495 bool CFWL_Edit::On_Validate(CFDE_TxtEdtEngine* pEdit, CFX_WideString& wsText) { |
501 CFWL_Widget* pDst = GetOuter(); | 496 CFWL_Widget* pDst = GetOuter(); |
502 if (!pDst) | 497 if (!pDst) |
503 pDst = this; | 498 pDst = this; |
504 | 499 |
505 CFWL_EvtValidate event; | 500 CFWL_EvtValidate event(this); |
506 event.pDstWidget = pDst; | |
507 event.m_pSrcTarget = this; | |
508 event.wsInsert = wsText; | 501 event.wsInsert = wsText; |
509 event.bValidate = true; | 502 event.bValidate = true; |
510 DispatchEvent(&event); | 503 DispatchEvent(&event); |
511 return event.bValidate; | 504 return event.bValidate; |
512 } | 505 } |
513 | 506 |
514 void CFWL_Edit::SetScrollOffset(FX_FLOAT fScrollOffset) { | 507 void CFWL_Edit::SetScrollOffset(FX_FLOAT fScrollOffset) { |
515 m_fScrollOffsetY = fScrollOffset; | 508 m_fScrollOffsetY = fScrollOffset; |
516 } | 509 } |
517 | 510 |
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1270 | 1263 |
1271 void CFWL_Edit::ClearRecord() { | 1264 void CFWL_Edit::ClearRecord() { |
1272 m_iCurRecord = -1; | 1265 m_iCurRecord = -1; |
1273 m_DoRecords.clear(); | 1266 m_DoRecords.clear(); |
1274 } | 1267 } |
1275 | 1268 |
1276 void CFWL_Edit::ProcessInsertError(int32_t iError) { | 1269 void CFWL_Edit::ProcessInsertError(int32_t iError) { |
1277 if (iError != -2) | 1270 if (iError != -2) |
1278 return; | 1271 return; |
1279 | 1272 |
1280 CFWL_EvtTextFull textFullEvent; | 1273 CFWL_Event textFullEvent(CFWL_Event::Type::TextFull, this); |
1281 textFullEvent.m_pSrcTarget = this; | |
1282 DispatchEvent(&textFullEvent); | 1274 DispatchEvent(&textFullEvent); |
1283 } | 1275 } |
1284 | 1276 |
1285 void CFWL_Edit::OnProcessMessage(CFWL_Message* pMessage) { | 1277 void CFWL_Edit::OnProcessMessage(CFWL_Message* pMessage) { |
1286 if (!pMessage) | 1278 if (!pMessage) |
1287 return; | 1279 return; |
1288 | 1280 |
1289 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); | 1281 switch (pMessage->GetType()) { |
1290 switch (dwMsgCode) { | 1282 case CFWL_Message::Type::SetFocus: |
1291 case CFWL_MessageType::SetFocus: | 1283 OnFocusChanged(pMessage, true); |
1292 case CFWL_MessageType::KillFocus: | |
1293 OnFocusChanged(pMessage, dwMsgCode == CFWL_MessageType::SetFocus); | |
1294 break; | 1284 break; |
1295 case CFWL_MessageType::Mouse: { | 1285 case CFWL_Message::Type::KillFocus: |
| 1286 OnFocusChanged(pMessage, false); |
| 1287 break; |
| 1288 case CFWL_Message::Type::Mouse: { |
1296 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | 1289 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); |
1297 switch (pMsg->m_dwCmd) { | 1290 switch (pMsg->m_dwCmd) { |
1298 case FWL_MouseCommand::LeftButtonDown: | 1291 case FWL_MouseCommand::LeftButtonDown: |
1299 OnLButtonDown(pMsg); | 1292 OnLButtonDown(pMsg); |
1300 break; | 1293 break; |
1301 case FWL_MouseCommand::LeftButtonUp: | 1294 case FWL_MouseCommand::LeftButtonUp: |
1302 OnLButtonUp(pMsg); | 1295 OnLButtonUp(pMsg); |
1303 break; | 1296 break; |
1304 case FWL_MouseCommand::LeftButtonDblClk: | 1297 case FWL_MouseCommand::LeftButtonDblClk: |
1305 OnButtonDblClk(pMsg); | 1298 OnButtonDblClk(pMsg); |
1306 break; | 1299 break; |
1307 case FWL_MouseCommand::Move: | 1300 case FWL_MouseCommand::Move: |
1308 OnMouseMove(pMsg); | 1301 OnMouseMove(pMsg); |
1309 break; | 1302 break; |
1310 case FWL_MouseCommand::RightButtonDown: | 1303 case FWL_MouseCommand::RightButtonDown: |
1311 DoButtonDown(pMsg); | 1304 DoButtonDown(pMsg); |
1312 break; | 1305 break; |
1313 default: | 1306 default: |
1314 break; | 1307 break; |
1315 } | 1308 } |
1316 break; | 1309 break; |
1317 } | 1310 } |
1318 case CFWL_MessageType::Key: { | 1311 case CFWL_Message::Type::Key: { |
1319 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); | 1312 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); |
1320 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) | 1313 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) |
1321 OnKeyDown(pKey); | 1314 OnKeyDown(pKey); |
1322 else if (pKey->m_dwCmd == FWL_KeyCommand::Char) | 1315 else if (pKey->m_dwCmd == FWL_KeyCommand::Char) |
1323 OnChar(pKey); | 1316 OnChar(pKey); |
1324 break; | 1317 break; |
1325 } | 1318 } |
1326 default: | 1319 default: |
1327 break; | 1320 break; |
1328 } | 1321 } |
1329 CFWL_Widget::OnProcessMessage(pMessage); | 1322 CFWL_Widget::OnProcessMessage(pMessage); |
1330 } | 1323 } |
1331 | 1324 |
1332 void CFWL_Edit::OnProcessEvent(CFWL_Event* pEvent) { | 1325 void CFWL_Edit::OnProcessEvent(CFWL_Event* pEvent) { |
1333 if (!pEvent) | 1326 if (!pEvent) |
1334 return; | 1327 return; |
1335 if (pEvent->GetClassID() != CFWL_EventType::Scroll) | 1328 if (pEvent->GetType() != CFWL_Event::Type::Scroll) |
1336 return; | 1329 return; |
1337 | 1330 |
1338 CFWL_Widget* pSrcTarget = pEvent->m_pSrcTarget; | 1331 CFWL_Widget* pSrcTarget = pEvent->m_pSrcTarget; |
1339 if ((pSrcTarget == m_pVertScrollBar.get() && m_pVertScrollBar) || | 1332 if ((pSrcTarget == m_pVertScrollBar.get() && m_pVertScrollBar) || |
1340 (pSrcTarget == m_pHorzScrollBar.get() && m_pHorzScrollBar)) { | 1333 (pSrcTarget == m_pHorzScrollBar.get() && m_pHorzScrollBar)) { |
1341 CFWL_EvtScroll* pScrollEvent = static_cast<CFWL_EvtScroll*>(pEvent); | 1334 CFWL_EvtScroll* pScrollEvent = static_cast<CFWL_EvtScroll*>(pEvent); |
1342 OnScroll(static_cast<CFWL_ScrollBar*>(pSrcTarget), | 1335 OnScroll(static_cast<CFWL_ScrollBar*>(pSrcTarget), |
1343 pScrollEvent->m_iScrollCode, pScrollEvent->m_fPos); | 1336 pScrollEvent->m_iScrollCode, pScrollEvent->m_fPos); |
1344 } | 1337 } |
1345 } | 1338 } |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1515 } | 1508 } |
1516 int32_t nCaret = m_EdtEngine.GetCaretPos(); | 1509 int32_t nCaret = m_EdtEngine.GetCaretPos(); |
1517 #if (_FX_OS_ == _FX_MACOSX_) | 1510 #if (_FX_OS_ == _FX_MACOSX_) |
1518 m_EdtEngine.Delete(nCaret, true); | 1511 m_EdtEngine.Delete(nCaret, true); |
1519 #else | 1512 #else |
1520 m_EdtEngine.Delete(nCaret); | 1513 m_EdtEngine.Delete(nCaret); |
1521 #endif | 1514 #endif |
1522 break; | 1515 break; |
1523 } | 1516 } |
1524 case FWL_VKEY_F2: | 1517 case FWL_VKEY_F2: |
1525 break; | 1518 case FWL_VKEY_Tab: |
1526 case FWL_VKEY_Tab: { | |
1527 DispatchKeyEvent(pMsg); | |
1528 break; | |
1529 } | |
1530 default: | 1519 default: |
1531 break; | 1520 break; |
1532 } | 1521 } |
1533 if (MoveCaret != MC_MoveNone) | 1522 if (MoveCaret != MC_MoveNone) |
1534 m_EdtEngine.MoveCaretPos(MoveCaret, bShift, bCtrl); | 1523 m_EdtEngine.MoveCaretPos(MoveCaret, bShift, bCtrl); |
1535 } | 1524 } |
1536 | 1525 |
1537 void CFWL_Edit::OnChar(CFWL_MsgKey* pMsg) { | 1526 void CFWL_Edit::OnChar(CFWL_MsgKey* pMsg) { |
1538 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) || | 1527 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) || |
1539 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { | 1528 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1582 } | 1571 } |
1583 iError = m_EdtEngine.Insert(nCaret, &c, 1); | 1572 iError = m_EdtEngine.Insert(nCaret, &c, 1); |
1584 break; | 1573 break; |
1585 } | 1574 } |
1586 } | 1575 } |
1587 if (iError < 0) | 1576 if (iError < 0) |
1588 ProcessInsertError(iError); | 1577 ProcessInsertError(iError); |
1589 } | 1578 } |
1590 | 1579 |
1591 bool CFWL_Edit::OnScroll(CFWL_ScrollBar* pScrollBar, | 1580 bool CFWL_Edit::OnScroll(CFWL_ScrollBar* pScrollBar, |
1592 FWL_SCBCODE dwCode, | 1581 CFWL_EvtScroll::Code dwCode, |
1593 FX_FLOAT fPos) { | 1582 FX_FLOAT fPos) { |
1594 CFX_SizeF fs; | 1583 CFX_SizeF fs; |
1595 pScrollBar->GetRange(&fs.x, &fs.y); | 1584 pScrollBar->GetRange(&fs.x, &fs.y); |
1596 FX_FLOAT iCurPos = pScrollBar->GetPos(); | 1585 FX_FLOAT iCurPos = pScrollBar->GetPos(); |
1597 FX_FLOAT fStep = pScrollBar->GetStepSize(); | 1586 FX_FLOAT fStep = pScrollBar->GetStepSize(); |
1598 switch (dwCode) { | 1587 switch (dwCode) { |
1599 case FWL_SCBCODE::Min: { | 1588 case CFWL_EvtScroll::Code::Min: { |
1600 fPos = fs.x; | 1589 fPos = fs.x; |
1601 break; | 1590 break; |
1602 } | 1591 } |
1603 case FWL_SCBCODE::Max: { | 1592 case CFWL_EvtScroll::Code::Max: { |
1604 fPos = fs.y; | 1593 fPos = fs.y; |
1605 break; | 1594 break; |
1606 } | 1595 } |
1607 case FWL_SCBCODE::StepBackward: { | 1596 case CFWL_EvtScroll::Code::StepBackward: { |
1608 fPos -= fStep; | 1597 fPos -= fStep; |
1609 if (fPos < fs.x + fStep / 2) { | 1598 if (fPos < fs.x + fStep / 2) { |
1610 fPos = fs.x; | 1599 fPos = fs.x; |
1611 } | 1600 } |
1612 break; | 1601 break; |
1613 } | 1602 } |
1614 case FWL_SCBCODE::StepForward: { | 1603 case CFWL_EvtScroll::Code::StepForward: { |
1615 fPos += fStep; | 1604 fPos += fStep; |
1616 if (fPos > fs.y - fStep / 2) { | 1605 if (fPos > fs.y - fStep / 2) { |
1617 fPos = fs.y; | 1606 fPos = fs.y; |
1618 } | 1607 } |
1619 break; | 1608 break; |
1620 } | 1609 } |
1621 case FWL_SCBCODE::PageBackward: { | 1610 case CFWL_EvtScroll::Code::PageBackward: { |
1622 fPos -= pScrollBar->GetPageSize(); | 1611 fPos -= pScrollBar->GetPageSize(); |
1623 if (fPos < fs.x) { | 1612 if (fPos < fs.x) { |
1624 fPos = fs.x; | 1613 fPos = fs.x; |
1625 } | 1614 } |
1626 break; | 1615 break; |
1627 } | 1616 } |
1628 case FWL_SCBCODE::PageForward: { | 1617 case CFWL_EvtScroll::Code::PageForward: { |
1629 fPos += pScrollBar->GetPageSize(); | 1618 fPos += pScrollBar->GetPageSize(); |
1630 if (fPos > fs.y) { | 1619 if (fPos > fs.y) { |
1631 fPos = fs.y; | 1620 fPos = fs.y; |
1632 } | 1621 } |
1633 break; | 1622 break; |
1634 } | 1623 } |
1635 case FWL_SCBCODE::Pos: | 1624 case CFWL_EvtScroll::Code::Pos: |
1636 case FWL_SCBCODE::TrackPos: | 1625 case CFWL_EvtScroll::Code::TrackPos: |
1637 case FWL_SCBCODE::None: | 1626 case CFWL_EvtScroll::Code::None: |
1638 break; | 1627 break; |
1639 case FWL_SCBCODE::EndScroll: | 1628 case CFWL_EvtScroll::Code::EndScroll: |
1640 return false; | 1629 return false; |
1641 } | 1630 } |
1642 if (iCurPos == fPos) | 1631 if (iCurPos == fPos) |
1643 return true; | 1632 return true; |
1644 | 1633 |
1645 pScrollBar->SetPos(fPos); | 1634 pScrollBar->SetPos(fPos); |
1646 pScrollBar->SetTrackPos(fPos); | 1635 pScrollBar->SetTrackPos(fPos); |
1647 UpdateOffset(pScrollBar, fPos - iCurPos); | 1636 UpdateOffset(pScrollBar, fPos - iCurPos); |
1648 UpdateCaret(); | 1637 UpdateCaret(); |
1649 | 1638 |
1650 CFX_RectF rect; | 1639 CFX_RectF rect; |
1651 GetWidgetRect(rect); | 1640 GetWidgetRect(rect); |
1652 CFX_RectF rtInvalidate; | 1641 CFX_RectF rtInvalidate; |
1653 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); | 1642 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); |
1654 Repaint(&rtInvalidate); | 1643 Repaint(&rtInvalidate); |
1655 return true; | 1644 return true; |
1656 } | 1645 } |
OLD | NEW |