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/cfwl_edit.h" | 7 #include "xfa/fwl/cfwl_edit.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) { | 422 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) { |
423 CFWL_ScrollBar* pScroll = UpdateScroll(); | 423 CFWL_ScrollBar* pScroll = UpdateScroll(); |
424 if (pScroll) { | 424 if (pScroll) { |
425 rtInvalid = pScroll->GetWidgetRect(); | 425 rtInvalid = pScroll->GetWidgetRect(); |
426 bRepaintScroll = true; | 426 bRepaintScroll = true; |
427 } | 427 } |
428 } | 428 } |
429 if (bRepaintContent || bRepaintScroll) { | 429 if (bRepaintContent || bRepaintScroll) { |
430 if (bRepaintContent) | 430 if (bRepaintContent) |
431 rtInvalid.Union(m_rtEngine); | 431 rtInvalid.Union(m_rtEngine); |
432 Repaint(&rtInvalid); | 432 RepaintRect(rtInvalid); |
433 } | 433 } |
434 } | 434 } |
435 | 435 |
436 void CFWL_Edit::OnTextChanged(const FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo) { | 436 void CFWL_Edit::OnTextChanged(const FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo) { |
437 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VAlignMask) | 437 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VAlignMask) |
438 UpdateVAlignment(); | 438 UpdateVAlignment(); |
439 | 439 |
440 CFX_RectF rtTemp; | |
441 GetClientRect(rtTemp); | |
442 | |
443 CFWL_EventTextChanged event(this); | 440 CFWL_EventTextChanged event(this); |
444 event.wsPrevText = ChangeInfo.wsPrevText; | 441 event.wsPrevText = ChangeInfo.wsPrevText; |
445 DispatchEvent(&event); | 442 DispatchEvent(&event); |
446 | 443 |
447 LayoutScrollBar(); | 444 LayoutScrollBar(); |
448 Repaint(&rtTemp); | 445 RepaintRect(GetClientRect()); |
449 } | 446 } |
450 | 447 |
451 void CFWL_Edit::OnSelChanged() { | 448 void CFWL_Edit::OnSelChanged() { |
452 CFX_RectF rtTemp; | 449 RepaintRect(GetClientRect()); |
453 GetClientRect(rtTemp); | |
454 Repaint(&rtTemp); | |
455 } | 450 } |
456 | 451 |
457 bool CFWL_Edit::OnPageLoad(int32_t nPageIndex) { | 452 bool CFWL_Edit::OnPageLoad(int32_t nPageIndex) { |
458 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(nPageIndex); | 453 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(nPageIndex); |
459 if (!pPage) | 454 if (!pPage) |
460 return false; | 455 return false; |
461 | 456 |
462 pPage->LoadPage(nullptr, nullptr); | 457 pPage->LoadPage(nullptr, nullptr); |
463 return true; | 458 return true; |
464 } | 459 } |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 | 851 |
857 void CFWL_Edit::UpdateCaret() { | 852 void CFWL_Edit::UpdateCaret() { |
858 CFX_RectF rtFDE; | 853 CFX_RectF rtFDE; |
859 m_EdtEngine.GetCaretRect(rtFDE); | 854 m_EdtEngine.GetCaretRect(rtFDE); |
860 | 855 |
861 rtFDE.Offset(m_rtEngine.left - m_fScrollOffsetX, | 856 rtFDE.Offset(m_rtEngine.left - m_fScrollOffsetX, |
862 m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset); | 857 m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset); |
863 CFX_RectF rtCaret; | 858 CFX_RectF rtCaret; |
864 rtCaret.Set(rtFDE.left, rtFDE.top, rtFDE.width, rtFDE.height); | 859 rtCaret.Set(rtFDE.left, rtFDE.top, rtFDE.width, rtFDE.height); |
865 | 860 |
866 CFX_RectF rtClient; | 861 CFX_RectF rtClient = GetClientRect(); |
867 GetClientRect(rtClient); | |
868 rtCaret.Intersect(rtClient); | 862 rtCaret.Intersect(rtClient); |
869 | |
870 if (rtCaret.left > rtClient.right()) { | 863 if (rtCaret.left > rtClient.right()) { |
871 FX_FLOAT right = rtCaret.right(); | 864 FX_FLOAT right = rtCaret.right(); |
872 rtCaret.left = rtClient.right() - 1; | 865 rtCaret.left = rtClient.right() - 1; |
873 rtCaret.width = right - rtCaret.left; | 866 rtCaret.width = right - rtCaret.left; |
874 } | 867 } |
875 | 868 |
876 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && !rtCaret.IsEmpty()) | 869 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && !rtCaret.IsEmpty()) |
877 ShowCaret(&rtCaret); | 870 ShowCaret(&rtCaret); |
878 else | 871 else |
879 HideCaret(&rtCaret); | 872 HideCaret(&rtCaret); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
983 m_DoRecords.erase(m_DoRecords.begin() + m_iCurRecord + 1, | 976 m_DoRecords.erase(m_DoRecords.begin() + m_iCurRecord + 1, |
984 m_DoRecords.end()); | 977 m_DoRecords.end()); |
985 } | 978 } |
986 | 979 |
987 m_DoRecords.push_back(std::move(pRecord)); | 980 m_DoRecords.push_back(std::move(pRecord)); |
988 m_iCurRecord = pdfium::CollectionSize<int32_t>(m_DoRecords) - 1; | 981 m_iCurRecord = pdfium::CollectionSize<int32_t>(m_DoRecords) - 1; |
989 return m_iCurRecord; | 982 return m_iCurRecord; |
990 } | 983 } |
991 | 984 |
992 void CFWL_Edit::Layout() { | 985 void CFWL_Edit::Layout() { |
993 GetClientRect(m_rtClient); | 986 m_rtClient = GetClientRect(); |
994 m_rtEngine = m_rtClient; | 987 m_rtEngine = m_rtClient; |
995 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( | 988 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( |
996 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 989 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
997 if (!pfWidth) | 990 if (!pfWidth) |
998 return; | 991 return; |
999 | 992 |
1000 FX_FLOAT fWidth = *pfWidth; | 993 FX_FLOAT fWidth = *pfWidth; |
1001 if (!m_pOuter) { | 994 if (!m_pOuter) { |
1002 CFX_RectF* pUIMargin = static_cast<CFX_RectF*>( | 995 CFX_RectF* pUIMargin = static_cast<CFX_RectF*>( |
1003 GetThemeCapacity(CFWL_WidgetCapacity::UIMargin)); | 996 GetThemeCapacity(CFWL_WidgetCapacity::UIMargin)); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; | 1148 prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; |
1156 m_pHorzScrollBar = | 1149 m_pHorzScrollBar = |
1157 pdfium::MakeUnique<CFWL_ScrollBar>(m_pOwnerApp, std::move(prop), this); | 1150 pdfium::MakeUnique<CFWL_ScrollBar>(m_pOwnerApp, std::move(prop), this); |
1158 } | 1151 } |
1159 | 1152 |
1160 void CFWL_Edit::ShowCaret(CFX_RectF* pRect) { | 1153 void CFWL_Edit::ShowCaret(CFX_RectF* pRect) { |
1161 if (m_pCaret) { | 1154 if (m_pCaret) { |
1162 m_pCaret->ShowCaret(); | 1155 m_pCaret->ShowCaret(); |
1163 if (!pRect->IsEmpty()) | 1156 if (!pRect->IsEmpty()) |
1164 m_pCaret->SetWidgetRect(*pRect); | 1157 m_pCaret->SetWidgetRect(*pRect); |
1165 Repaint(&m_rtEngine); | 1158 RepaintRect(m_rtEngine); |
1166 return; | 1159 return; |
1167 } | 1160 } |
1168 | 1161 |
1169 CFWL_Widget* pOuter = this; | 1162 CFWL_Widget* pOuter = this; |
1170 pRect->Offset(m_pProperties->m_rtWidget.left, m_pProperties->m_rtWidget.top); | 1163 pRect->Offset(m_pProperties->m_rtWidget.left, m_pProperties->m_rtWidget.top); |
1171 while (pOuter->GetOuter()) { | 1164 while (pOuter->GetOuter()) { |
1172 pOuter = pOuter->GetOuter(); | 1165 pOuter = pOuter->GetOuter(); |
1173 | 1166 |
1174 CFX_RectF rtOuter = pOuter->GetWidgetRect(); | 1167 CFX_RectF rtOuter = pOuter->GetWidgetRect(); |
1175 pRect->Offset(rtOuter.left, rtOuter.top); | 1168 pRect->Offset(rtOuter.left, rtOuter.top); |
(...skipping 13 matching lines...) Expand all Loading... |
1189 pXFAWidget->GetRotateMatrix(mt); | 1182 pXFAWidget->GetRotateMatrix(mt); |
1190 | 1183 |
1191 CFX_RectF rt(*pRect); | 1184 CFX_RectF rt(*pRect); |
1192 mt.TransformRect(rt); | 1185 mt.TransformRect(rt); |
1193 pDocEnvironment->DisplayCaret(pXFAWidget, true, &rt); | 1186 pDocEnvironment->DisplayCaret(pXFAWidget, true, &rt); |
1194 } | 1187 } |
1195 | 1188 |
1196 void CFWL_Edit::HideCaret(CFX_RectF* pRect) { | 1189 void CFWL_Edit::HideCaret(CFX_RectF* pRect) { |
1197 if (m_pCaret) { | 1190 if (m_pCaret) { |
1198 m_pCaret->HideCaret(); | 1191 m_pCaret->HideCaret(); |
1199 Repaint(&m_rtEngine); | 1192 RepaintRect(m_rtEngine); |
1200 return; | 1193 return; |
1201 } | 1194 } |
1202 | 1195 |
1203 CFWL_Widget* pOuter = this; | 1196 CFWL_Widget* pOuter = this; |
1204 while (pOuter->GetOuter()) | 1197 while (pOuter->GetOuter()) |
1205 pOuter = pOuter->GetOuter(); | 1198 pOuter = pOuter->GetOuter(); |
1206 | 1199 |
1207 CXFA_FFWidget* pXFAWidget = | 1200 CXFA_FFWidget* pXFAWidget = |
1208 static_cast<CXFA_FFWidget*>(pOuter->GetLayoutItem()); | 1201 static_cast<CXFA_FFWidget*>(pOuter->GetLayoutItem()); |
1209 if (!pXFAWidget) | 1202 if (!pXFAWidget) |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1384 ClearRecord(); | 1377 ClearRecord(); |
1385 } | 1378 } |
1386 | 1379 |
1387 LayoutScrollBar(); | 1380 LayoutScrollBar(); |
1388 if (!bRepaint) | 1381 if (!bRepaint) |
1389 return; | 1382 return; |
1390 | 1383 |
1391 CFX_RectF rtInvalidate; | 1384 CFX_RectF rtInvalidate; |
1392 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, | 1385 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, |
1393 m_pProperties->m_rtWidget.height); | 1386 m_pProperties->m_rtWidget.height); |
1394 Repaint(&rtInvalidate); | 1387 RepaintRect(rtInvalidate); |
1395 } | 1388 } |
1396 | 1389 |
1397 void CFWL_Edit::OnLButtonDown(CFWL_MessageMouse* pMsg) { | 1390 void CFWL_Edit::OnLButtonDown(CFWL_MessageMouse* pMsg) { |
1398 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) | 1391 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
1399 return; | 1392 return; |
1400 | 1393 |
1401 m_bLButtonDown = true; | 1394 m_bLButtonDown = true; |
1402 SetGrab(true); | 1395 SetGrab(true); |
1403 DoButtonDown(pMsg); | 1396 DoButtonDown(pMsg); |
1404 int32_t nIndex = m_EdtEngine.GetCaretPos(); | 1397 int32_t nIndex = m_EdtEngine.GetCaretPos(); |
1405 bool bRepaint = false; | 1398 bool bRepaint = false; |
1406 if (m_EdtEngine.CountSelRanges() > 0) { | 1399 if (m_EdtEngine.CountSelRanges() > 0) { |
1407 m_EdtEngine.ClearSelection(); | 1400 m_EdtEngine.ClearSelection(); |
1408 bRepaint = true; | 1401 bRepaint = true; |
1409 } | 1402 } |
1410 | 1403 |
1411 if ((pMsg->m_dwFlags & FWL_KEYFLAG_Shift) && m_nSelStart != nIndex) { | 1404 if ((pMsg->m_dwFlags & FWL_KEYFLAG_Shift) && m_nSelStart != nIndex) { |
1412 int32_t iStart = std::min(m_nSelStart, nIndex); | 1405 int32_t iStart = std::min(m_nSelStart, nIndex); |
1413 int32_t iEnd = std::max(m_nSelStart, nIndex); | 1406 int32_t iEnd = std::max(m_nSelStart, nIndex); |
1414 m_EdtEngine.AddSelRange(iStart, iEnd - iStart); | 1407 m_EdtEngine.AddSelRange(iStart, iEnd - iStart); |
1415 bRepaint = true; | 1408 bRepaint = true; |
1416 } else { | 1409 } else { |
1417 m_nSelStart = nIndex; | 1410 m_nSelStart = nIndex; |
1418 } | 1411 } |
1419 if (bRepaint) | 1412 if (bRepaint) |
1420 Repaint(&m_rtEngine); | 1413 RepaintRect(m_rtEngine); |
1421 } | 1414 } |
1422 | 1415 |
1423 void CFWL_Edit::OnLButtonUp(CFWL_MessageMouse* pMsg) { | 1416 void CFWL_Edit::OnLButtonUp(CFWL_MessageMouse* pMsg) { |
1424 m_bLButtonDown = false; | 1417 m_bLButtonDown = false; |
1425 SetGrab(false); | 1418 SetGrab(false); |
1426 } | 1419 } |
1427 | 1420 |
1428 void CFWL_Edit::OnButtonDblClk(CFWL_MessageMouse* pMsg) { | 1421 void CFWL_Edit::OnButtonDblClk(CFWL_MessageMouse* pMsg) { |
1429 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); | 1422 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); |
1430 if (!pPage) | 1423 if (!pPage) |
1431 return; | 1424 return; |
1432 | 1425 |
1433 CFX_PointF pt(pMsg->m_fx, pMsg->m_fy); | 1426 CFX_PointF pt(pMsg->m_fx, pMsg->m_fy); |
1434 DeviceToEngine(pt); | 1427 DeviceToEngine(pt); |
1435 int32_t nCount = 0; | 1428 int32_t nCount = 0; |
1436 int32_t nIndex = pPage->SelectWord(pt, nCount); | 1429 int32_t nIndex = pPage->SelectWord(pt, nCount); |
1437 if (nIndex < 0) | 1430 if (nIndex < 0) |
1438 return; | 1431 return; |
1439 | 1432 |
1440 m_EdtEngine.AddSelRange(nIndex, nCount); | 1433 m_EdtEngine.AddSelRange(nIndex, nCount); |
1441 m_EdtEngine.SetCaretPos(nIndex + nCount - 1, false); | 1434 m_EdtEngine.SetCaretPos(nIndex + nCount - 1, false); |
1442 Repaint(&m_rtEngine); | 1435 RepaintRect(m_rtEngine); |
1443 } | 1436 } |
1444 | 1437 |
1445 void CFWL_Edit::OnMouseMove(CFWL_MessageMouse* pMsg) { | 1438 void CFWL_Edit::OnMouseMove(CFWL_MessageMouse* pMsg) { |
1446 if (m_nSelStart == -1 || !m_bLButtonDown) | 1439 if (m_nSelStart == -1 || !m_bLButtonDown) |
1447 return; | 1440 return; |
1448 | 1441 |
1449 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); | 1442 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); |
1450 if (!pPage) | 1443 if (!pPage) |
1451 return; | 1444 return; |
1452 | 1445 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1632 return true; | 1625 return true; |
1633 | 1626 |
1634 pScrollBar->SetPos(fPos); | 1627 pScrollBar->SetPos(fPos); |
1635 pScrollBar->SetTrackPos(fPos); | 1628 pScrollBar->SetTrackPos(fPos); |
1636 UpdateOffset(pScrollBar, fPos - iCurPos); | 1629 UpdateOffset(pScrollBar, fPos - iCurPos); |
1637 UpdateCaret(); | 1630 UpdateCaret(); |
1638 | 1631 |
1639 CFX_RectF rect = GetWidgetRect(); | 1632 CFX_RectF rect = GetWidgetRect(); |
1640 CFX_RectF rtInvalidate; | 1633 CFX_RectF rtInvalidate; |
1641 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); | 1634 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); |
1642 Repaint(&rtInvalidate); | 1635 RepaintRect(rtInvalidate); |
1643 return true; | 1636 return true; |
1644 } | 1637 } |
OLD | NEW |