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