| 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> |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 CFWL_Edit::~CFWL_Edit() { | 82 CFWL_Edit::~CFWL_Edit() { |
| 83 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) | 83 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) |
| 84 HideCaret(nullptr); | 84 HideCaret(nullptr); |
| 85 ClearRecord(); | 85 ClearRecord(); |
| 86 } | 86 } |
| 87 | 87 |
| 88 FWL_Type CFWL_Edit::GetClassID() const { | 88 FWL_Type CFWL_Edit::GetClassID() const { |
| 89 return FWL_Type::Edit; | 89 return FWL_Type::Edit; |
| 90 } | 90 } |
| 91 | 91 |
| 92 void CFWL_Edit::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { | 92 CFX_RectF CFWL_Edit::GetWidgetRect(bool bAutoSize) { |
| 93 if (!bAutoSize) { | 93 if (!bAutoSize) { |
| 94 rect = m_pProperties->m_rtWidget; | 94 CFX_RectF rect = m_pProperties->m_rtWidget; |
| 95 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { | 95 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { |
| 96 if (IsShowScrollBar(true)) { | 96 if (IsShowScrollBar(true)) { |
| 97 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( | 97 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( |
| 98 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 98 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
| 99 rect.width += *pfWidth; | 99 rect.width += *pfWidth; |
| 100 rect.width += kEditMargin; | 100 rect.width += kEditMargin; |
| 101 } | 101 } |
| 102 if (IsShowScrollBar(false)) { | 102 if (IsShowScrollBar(false)) { |
| 103 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( | 103 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( |
| 104 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 104 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
| 105 rect.height += *pfWidth; | 105 rect.height += *pfWidth; |
| 106 rect.height += kEditMargin; | 106 rect.height += kEditMargin; |
| 107 } | 107 } |
| 108 } | 108 } |
| 109 return; | 109 return rect; |
| 110 } | 110 } |
| 111 | 111 |
| 112 rect.Set(0, 0, 0, 0); | 112 CFX_RectF rect; |
| 113 | |
| 114 int32_t iTextLen = m_EdtEngine.GetTextLength(); | 113 int32_t iTextLen = m_EdtEngine.GetTextLength(); |
| 115 if (iTextLen > 0) { | 114 if (iTextLen > 0) { |
| 116 CFX_WideString wsText = m_EdtEngine.GetText(0, -1); | 115 CFX_WideString wsText = m_EdtEngine.GetText(0, -1); |
| 117 CFX_SizeF sz = CalcTextSize( | 116 CFX_SizeF sz = CalcTextSize( |
| 118 wsText, m_pProperties->m_pThemeProvider, | 117 wsText, m_pProperties->m_pThemeProvider, |
| 119 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine)); | 118 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine)); |
| 120 rect.Set(0, 0, sz.x, sz.y); | 119 rect.Set(0, 0, sz.x, sz.y); |
| 121 } | 120 } |
| 122 InflateWidgetRect(rect); | 121 InflateWidgetRect(rect); |
| 122 return rect; |
| 123 } | 123 } |
| 124 | 124 |
| 125 void CFWL_Edit::SetStates(uint32_t dwStates) { | 125 void CFWL_Edit::SetStates(uint32_t dwStates) { |
| 126 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) || | 126 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) || |
| 127 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { | 127 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { |
| 128 HideCaret(nullptr); | 128 HideCaret(nullptr); |
| 129 } | 129 } |
| 130 CFWL_Widget::SetStates(dwStates); | 130 CFWL_Widget::SetStates(dwStates); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void CFWL_Edit::Update() { | 133 void CFWL_Edit::Update() { |
| 134 if (IsLocked()) | 134 if (IsLocked()) |
| 135 return; | 135 return; |
| 136 if (!m_pProperties->m_pThemeProvider) | 136 if (!m_pProperties->m_pThemeProvider) |
| 137 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | 137 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
| 138 | 138 |
| 139 Layout(); | 139 Layout(); |
| 140 if (m_rtClient.IsEmpty()) | 140 if (m_rtClient.IsEmpty()) |
| 141 return; | 141 return; |
| 142 | 142 |
| 143 UpdateEditEngine(); | 143 UpdateEditEngine(); |
| 144 UpdateVAlignment(); | 144 UpdateVAlignment(); |
| 145 UpdateScroll(); | 145 UpdateScroll(); |
| 146 InitCaret(); | 146 InitCaret(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 FWL_WidgetHit CFWL_Edit::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | 149 FWL_WidgetHit CFWL_Edit::HitTest(FX_FLOAT fx, FX_FLOAT fy) { |
| 150 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { | 150 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { |
| 151 if (IsShowScrollBar(true)) { | 151 if (IsShowScrollBar(true)) { |
| 152 CFX_RectF rect; | 152 if (m_pVertScrollBar->GetWidgetRect(false).Contains(fx, fy)) |
| 153 m_pVertScrollBar->GetWidgetRect(rect, false); | |
| 154 if (rect.Contains(fx, fy)) | |
| 155 return FWL_WidgetHit::VScrollBar; | 153 return FWL_WidgetHit::VScrollBar; |
| 156 } | 154 } |
| 157 if (IsShowScrollBar(false)) { | 155 if (IsShowScrollBar(false)) { |
| 158 CFX_RectF rect; | 156 if (m_pHorzScrollBar->GetWidgetRect(false).Contains(fx, fy)) |
| 159 m_pHorzScrollBar->GetWidgetRect(rect, false); | |
| 160 if (rect.Contains(fx, fy)) | |
| 161 return FWL_WidgetHit::HScrollBar; | 157 return FWL_WidgetHit::HScrollBar; |
| 162 } | 158 } |
| 163 } | 159 } |
| 164 if (m_rtClient.Contains(fx, fy)) | 160 if (m_rtClient.Contains(fx, fy)) |
| 165 return FWL_WidgetHit::Edit; | 161 return FWL_WidgetHit::Edit; |
| 166 return FWL_WidgetHit::Unknown; | 162 return FWL_WidgetHit::Unknown; |
| 167 } | 163 } |
| 168 | 164 |
| 169 void CFWL_Edit::AddSpellCheckObj(CFX_Path& PathData, | 165 void CFWL_Edit::AddSpellCheckObj(CFX_Path& PathData, |
| 170 int32_t nStart, | 166 int32_t nStart, |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 return; | 417 return; |
| 422 | 418 |
| 423 bool bRepaintContent = UpdateOffset(); | 419 bool bRepaintContent = UpdateOffset(); |
| 424 UpdateCaret(); | 420 UpdateCaret(); |
| 425 CFX_RectF rtInvalid; | 421 CFX_RectF rtInvalid; |
| 426 rtInvalid.Set(0, 0, 0, 0); | 422 rtInvalid.Set(0, 0, 0, 0); |
| 427 bool bRepaintScroll = false; | 423 bool bRepaintScroll = false; |
| 428 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) { | 424 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) { |
| 429 CFWL_ScrollBar* pScroll = UpdateScroll(); | 425 CFWL_ScrollBar* pScroll = UpdateScroll(); |
| 430 if (pScroll) { | 426 if (pScroll) { |
| 431 pScroll->GetWidgetRect(rtInvalid, false); | 427 rtInvalid = pScroll->GetWidgetRect(false); |
| 432 bRepaintScroll = true; | 428 bRepaintScroll = true; |
| 433 } | 429 } |
| 434 } | 430 } |
| 435 if (bRepaintContent || bRepaintScroll) { | 431 if (bRepaintContent || bRepaintScroll) { |
| 436 if (bRepaintContent) | 432 if (bRepaintContent) |
| 437 rtInvalid.Union(m_rtEngine); | 433 rtInvalid.Union(m_rtEngine); |
| 438 Repaint(&rtInvalid); | 434 Repaint(&rtInvalid); |
| 439 } | 435 } |
| 440 } | 436 } |
| 441 | 437 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 if (dwStates) | 508 if (dwStates) |
| 513 param.m_dwStates = CFWL_PartState_Disabled; | 509 param.m_dwStates = CFWL_PartState_Disabled; |
| 514 param.m_pGraphics = pGraphics; | 510 param.m_pGraphics = pGraphics; |
| 515 param.m_matrix = *pMatrix; | 511 param.m_matrix = *pMatrix; |
| 516 param.m_rtPart = m_rtClient; | 512 param.m_rtPart = m_rtClient; |
| 517 pTheme->DrawBackground(¶m); | 513 pTheme->DrawBackground(¶m); |
| 518 | 514 |
| 519 if (!IsShowScrollBar(true) || !IsShowScrollBar(false)) | 515 if (!IsShowScrollBar(true) || !IsShowScrollBar(false)) |
| 520 return; | 516 return; |
| 521 | 517 |
| 522 CFX_RectF rtScroll; | 518 CFX_RectF rtScroll = m_pHorzScrollBar->GetWidgetRect(false); |
| 523 m_pHorzScrollBar->GetWidgetRect(rtScroll, false); | |
| 524 | 519 |
| 525 CFX_RectF rtStatic; | 520 CFX_RectF rtStatic; |
| 526 rtStatic.Set(m_rtClient.right() - rtScroll.height, | 521 rtStatic.Set(m_rtClient.right() - rtScroll.height, |
| 527 m_rtClient.bottom() - rtScroll.height, rtScroll.height, | 522 m_rtClient.bottom() - rtScroll.height, rtScroll.height, |
| 528 rtScroll.height); | 523 rtScroll.height); |
| 529 param.m_bStaticBackground = true; | 524 param.m_bStaticBackground = true; |
| 530 param.m_bMaximize = true; | 525 param.m_bMaximize = true; |
| 531 param.m_rtPart = rtStatic; | 526 param.m_rtPart = rtStatic; |
| 532 pTheme->DrawBackground(¶m); | 527 pTheme->DrawBackground(¶m); |
| 533 } | 528 } |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 if (!bShowHorz && !bShowVert) | 891 if (!bShowHorz && !bShowVert) |
| 897 return nullptr; | 892 return nullptr; |
| 898 | 893 |
| 899 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); | 894 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); |
| 900 if (!pPage) | 895 if (!pPage) |
| 901 return nullptr; | 896 return nullptr; |
| 902 | 897 |
| 903 const CFX_RectF& rtFDE = pPage->GetContentsBox(); | 898 const CFX_RectF& rtFDE = pPage->GetContentsBox(); |
| 904 CFWL_ScrollBar* pRepaint = nullptr; | 899 CFWL_ScrollBar* pRepaint = nullptr; |
| 905 if (bShowHorz) { | 900 if (bShowHorz) { |
| 906 CFX_RectF rtScroll; | 901 CFX_RectF rtScroll = m_pHorzScrollBar->GetWidgetRect(false); |
| 907 m_pHorzScrollBar->GetWidgetRect(rtScroll, false); | |
| 908 if (rtScroll.width < rtFDE.width) { | 902 if (rtScroll.width < rtFDE.width) { |
| 909 m_pHorzScrollBar->LockUpdate(); | 903 m_pHorzScrollBar->LockUpdate(); |
| 910 FX_FLOAT fRange = rtFDE.width - rtScroll.width; | 904 FX_FLOAT fRange = rtFDE.width - rtScroll.width; |
| 911 m_pHorzScrollBar->SetRange(0.0f, fRange); | 905 m_pHorzScrollBar->SetRange(0.0f, fRange); |
| 912 | 906 |
| 913 FX_FLOAT fPos = std::min(std::max(m_fScrollOffsetX, 0.0f), fRange); | 907 FX_FLOAT fPos = std::min(std::max(m_fScrollOffsetX, 0.0f), fRange); |
| 914 m_pHorzScrollBar->SetPos(fPos); | 908 m_pHorzScrollBar->SetPos(fPos); |
| 915 m_pHorzScrollBar->SetTrackPos(fPos); | 909 m_pHorzScrollBar->SetTrackPos(fPos); |
| 916 m_pHorzScrollBar->SetPageSize(rtScroll.width); | 910 m_pHorzScrollBar->SetPageSize(rtScroll.width); |
| 917 m_pHorzScrollBar->SetStepSize(rtScroll.width / 10); | 911 m_pHorzScrollBar->SetStepSize(rtScroll.width / 10); |
| 918 m_pHorzScrollBar->RemoveStates(FWL_WGTSTATE_Disabled); | 912 m_pHorzScrollBar->RemoveStates(FWL_WGTSTATE_Disabled); |
| 919 m_pHorzScrollBar->UnlockUpdate(); | 913 m_pHorzScrollBar->UnlockUpdate(); |
| 920 m_pHorzScrollBar->Update(); | 914 m_pHorzScrollBar->Update(); |
| 921 pRepaint = m_pHorzScrollBar.get(); | 915 pRepaint = m_pHorzScrollBar.get(); |
| 922 } else if ((m_pHorzScrollBar->GetStates() & FWL_WGTSTATE_Disabled) == 0) { | 916 } else if ((m_pHorzScrollBar->GetStates() & FWL_WGTSTATE_Disabled) == 0) { |
| 923 m_pHorzScrollBar->LockUpdate(); | 917 m_pHorzScrollBar->LockUpdate(); |
| 924 m_pHorzScrollBar->SetRange(0, -1); | 918 m_pHorzScrollBar->SetRange(0, -1); |
| 925 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Disabled); | 919 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Disabled); |
| 926 m_pHorzScrollBar->UnlockUpdate(); | 920 m_pHorzScrollBar->UnlockUpdate(); |
| 927 m_pHorzScrollBar->Update(); | 921 m_pHorzScrollBar->Update(); |
| 928 pRepaint = m_pHorzScrollBar.get(); | 922 pRepaint = m_pHorzScrollBar.get(); |
| 929 } | 923 } |
| 930 } | 924 } |
| 931 | 925 |
| 932 if (bShowVert) { | 926 if (bShowVert) { |
| 933 CFX_RectF rtScroll; | 927 CFX_RectF rtScroll = m_pVertScrollBar->GetWidgetRect(false); |
| 934 m_pVertScrollBar->GetWidgetRect(rtScroll, false); | |
| 935 if (rtScroll.height < rtFDE.height) { | 928 if (rtScroll.height < rtFDE.height) { |
| 936 m_pVertScrollBar->LockUpdate(); | 929 m_pVertScrollBar->LockUpdate(); |
| 937 FX_FLOAT fStep = m_EdtEngine.GetEditParams()->fLineSpace; | 930 FX_FLOAT fStep = m_EdtEngine.GetEditParams()->fLineSpace; |
| 938 FX_FLOAT fRange = std::max(rtFDE.height - m_rtEngine.height, fStep); | 931 FX_FLOAT fRange = std::max(rtFDE.height - m_rtEngine.height, fStep); |
| 939 | 932 |
| 940 m_pVertScrollBar->SetRange(0.0f, fRange); | 933 m_pVertScrollBar->SetRange(0.0f, fRange); |
| 941 FX_FLOAT fPos = std::min(std::max(m_fScrollOffsetY, 0.0f), fRange); | 934 FX_FLOAT fPos = std::min(std::max(m_fScrollOffsetY, 0.0f), fRange); |
| 942 m_pVertScrollBar->SetPos(fPos); | 935 m_pVertScrollBar->SetPos(fPos); |
| 943 m_pVertScrollBar->SetTrackPos(fPos); | 936 m_pVertScrollBar->SetTrackPos(fPos); |
| 944 m_pVertScrollBar->SetPageSize(rtScroll.height); | 937 m_pVertScrollBar->SetPageSize(rtScroll.height); |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1173 m_pCaret->SetWidgetRect(*pRect); | 1166 m_pCaret->SetWidgetRect(*pRect); |
| 1174 Repaint(&m_rtEngine); | 1167 Repaint(&m_rtEngine); |
| 1175 return; | 1168 return; |
| 1176 } | 1169 } |
| 1177 | 1170 |
| 1178 CFWL_Widget* pOuter = this; | 1171 CFWL_Widget* pOuter = this; |
| 1179 pRect->Offset(m_pProperties->m_rtWidget.left, m_pProperties->m_rtWidget.top); | 1172 pRect->Offset(m_pProperties->m_rtWidget.left, m_pProperties->m_rtWidget.top); |
| 1180 while (pOuter->GetOuter()) { | 1173 while (pOuter->GetOuter()) { |
| 1181 pOuter = pOuter->GetOuter(); | 1174 pOuter = pOuter->GetOuter(); |
| 1182 | 1175 |
| 1183 CFX_RectF rtOuter; | 1176 CFX_RectF rtOuter = pOuter->GetWidgetRect(false); |
| 1184 pOuter->GetWidgetRect(rtOuter, false); | |
| 1185 pRect->Offset(rtOuter.left, rtOuter.top); | 1177 pRect->Offset(rtOuter.left, rtOuter.top); |
| 1186 } | 1178 } |
| 1187 | 1179 |
| 1188 CXFA_FFWidget* pXFAWidget = | 1180 CXFA_FFWidget* pXFAWidget = |
| 1189 static_cast<CXFA_FFWidget*>(pOuter->GetLayoutItem()); | 1181 static_cast<CXFA_FFWidget*>(pOuter->GetLayoutItem()); |
| 1190 if (!pXFAWidget) | 1182 if (!pXFAWidget) |
| 1191 return; | 1183 return; |
| 1192 | 1184 |
| 1193 IXFA_DocEnvironment* pDocEnvironment = | 1185 IXFA_DocEnvironment* pDocEnvironment = |
| 1194 pXFAWidget->GetDoc()->GetDocEnvironment(); | 1186 pXFAWidget->GetDoc()->GetDocEnvironment(); |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1639 return false; | 1631 return false; |
| 1640 } | 1632 } |
| 1641 if (iCurPos == fPos) | 1633 if (iCurPos == fPos) |
| 1642 return true; | 1634 return true; |
| 1643 | 1635 |
| 1644 pScrollBar->SetPos(fPos); | 1636 pScrollBar->SetPos(fPos); |
| 1645 pScrollBar->SetTrackPos(fPos); | 1637 pScrollBar->SetTrackPos(fPos); |
| 1646 UpdateOffset(pScrollBar, fPos - iCurPos); | 1638 UpdateOffset(pScrollBar, fPos - iCurPos); |
| 1647 UpdateCaret(); | 1639 UpdateCaret(); |
| 1648 | 1640 |
| 1649 CFX_RectF rect; | 1641 CFX_RectF rect = GetWidgetRect(false); |
| 1650 GetWidgetRect(rect, false); | |
| 1651 CFX_RectF rtInvalidate; | 1642 CFX_RectF rtInvalidate; |
| 1652 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); | 1643 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); |
| 1653 Repaint(&rtInvalidate); | 1644 Repaint(&rtInvalidate); |
| 1654 return true; | 1645 return true; |
| 1655 } | 1646 } |
| OLD | NEW |