| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 | |
| 7 #include "core/fxge/include/fx_ge.h" | |
| 8 #include "fpdfsdk/pdfwindow/PWL_ListCtrl.h" | |
| 9 #include "fpdfsdk/pdfwindow/PWL_Wnd.h" | |
| 10 | |
| 11 CPWL_ListCtrl::CPWL_ListCtrl() | |
| 12 : m_rcContent(0, 0, 0, 0), | |
| 13 m_ptScroll(0, 0), | |
| 14 m_fItemSpace(0.0f), | |
| 15 m_fTopSpace(0.0f), | |
| 16 m_fBottomSpace(0.0f) {} | |
| 17 | |
| 18 CPWL_ListCtrl::~CPWL_ListCtrl() {} | |
| 19 | |
| 20 void CPWL_ListCtrl::SetScrollPos(const CFX_FloatPoint& point) { | |
| 21 m_ptScroll = point; | |
| 22 | |
| 23 if (m_ptScroll.x < m_rcContent.left) | |
| 24 m_ptScroll.x = m_rcContent.left; | |
| 25 | |
| 26 if (m_ptScroll.x > m_rcContent.right) | |
| 27 m_ptScroll.x = m_rcContent.right; | |
| 28 | |
| 29 if (m_ptScroll.y > m_rcContent.top) | |
| 30 m_ptScroll.y = m_rcContent.top; | |
| 31 | |
| 32 if (m_ptScroll.y < m_rcContent.bottom) | |
| 33 m_ptScroll.y = m_rcContent.bottom; | |
| 34 } | |
| 35 | |
| 36 CFX_FloatPoint CPWL_ListCtrl::GetScrollPos() const { | |
| 37 return m_ptScroll; | |
| 38 } | |
| 39 | |
| 40 CFX_FloatRect CPWL_ListCtrl::GetScrollArea() const { | |
| 41 return m_rcContent; | |
| 42 } | |
| 43 | |
| 44 void CPWL_ListCtrl::ResetFace() { | |
| 45 ResetAll(FALSE, 0); | |
| 46 } | |
| 47 | |
| 48 void CPWL_ListCtrl::ResetContent(int32_t nStart) { | |
| 49 if (nStart < 0) | |
| 50 nStart = 0; | |
| 51 if (nStart >= 0 && nStart < m_aChildren.GetSize()) | |
| 52 ResetAll(TRUE, nStart); | |
| 53 } | |
| 54 | |
| 55 FX_FLOAT CPWL_ListCtrl::GetContentsHeight(FX_FLOAT fLimitWidth) { | |
| 56 FX_FLOAT fRet = m_fTopSpace; | |
| 57 | |
| 58 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); | |
| 59 | |
| 60 if (fLimitWidth > fBorderWidth * 2) { | |
| 61 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { | |
| 62 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { | |
| 63 FX_FLOAT fLeft = pChild->GetItemLeftMargin(); | |
| 64 FX_FLOAT fRight = pChild->GetItemRightMargin(); | |
| 65 | |
| 66 fRet += pChild->GetItemHeight(fLimitWidth - fBorderWidth * 2 - fLeft - | |
| 67 fRight); | |
| 68 fRet += m_fItemSpace; | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 fRet -= m_fItemSpace; | |
| 73 } | |
| 74 | |
| 75 fRet += m_fBottomSpace; | |
| 76 | |
| 77 return fRet; | |
| 78 } | |
| 79 | |
| 80 void CPWL_ListCtrl::ResetAll(FX_BOOL bMove, int32_t nStart) { | |
| 81 CFX_FloatRect rcClient = GetClientRect(); | |
| 82 | |
| 83 FX_FLOAT fWidth = rcClient.Width(); | |
| 84 | |
| 85 FX_FLOAT fy = 0.0f - m_fTopSpace; | |
| 86 | |
| 87 if (nStart - 1 >= 0 && nStart - 1 < m_aChildren.GetSize()) | |
| 88 if (CPWL_Wnd* pChild = m_aChildren.GetAt(nStart - 1)) | |
| 89 fy = pChild->GetWindowRect().bottom - m_fItemSpace; | |
| 90 | |
| 91 for (int32_t i = nStart, sz = m_aChildren.GetSize(); i < sz; i++) { | |
| 92 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { | |
| 93 FX_FLOAT fLeft = pChild->GetItemLeftMargin(); | |
| 94 FX_FLOAT fRight = pChild->GetItemRightMargin(); | |
| 95 | |
| 96 pChild->SetChildMatrix(CFX_Matrix(1, 0, 0, 1, | |
| 97 rcClient.left - m_ptScroll.x, | |
| 98 rcClient.top - m_ptScroll.y)); | |
| 99 | |
| 100 if (bMove) { | |
| 101 FX_FLOAT fItemHeight = pChild->GetItemHeight(fWidth - fLeft - fRight); | |
| 102 pChild->Move( | |
| 103 CFX_FloatRect(fLeft, fy - fItemHeight, fWidth - fRight, fy), TRUE, | |
| 104 FALSE); | |
| 105 fy -= fItemHeight; | |
| 106 fy -= m_fItemSpace; | |
| 107 } | |
| 108 } | |
| 109 } | |
| 110 | |
| 111 fy += m_fItemSpace; | |
| 112 | |
| 113 fy -= m_fBottomSpace; | |
| 114 | |
| 115 if (bMove) { | |
| 116 m_rcContent.left = 0; | |
| 117 m_rcContent.top = 0; | |
| 118 m_rcContent.right = fWidth; | |
| 119 m_rcContent.bottom = fy; | |
| 120 } | |
| 121 } | |
| 122 | |
| 123 void CPWL_ListCtrl::SetItemSpace(FX_FLOAT fSpace) { | |
| 124 m_fItemSpace = fSpace; | |
| 125 } | |
| 126 | |
| 127 void CPWL_ListCtrl::SetTopSpace(FX_FLOAT fSpace) { | |
| 128 m_fTopSpace = fSpace; | |
| 129 } | |
| 130 | |
| 131 void CPWL_ListCtrl::SetBottomSpace(FX_FLOAT fSpace) { | |
| 132 m_fBottomSpace = fSpace; | |
| 133 } | |
| 134 | |
| 135 void CPWL_ListCtrl::RePosChildWnd() { | |
| 136 ResetFace(); | |
| 137 } | |
| 138 | |
| 139 void CPWL_ListCtrl::DrawChildAppearance(CFX_RenderDevice* pDevice, | |
| 140 CFX_Matrix* pUser2Device) { | |
| 141 pDevice->SaveState(); | |
| 142 CFX_FloatRect rcClient = GetClientRect(); | |
| 143 CFX_FloatRect rcTemp = rcClient; | |
| 144 pUser2Device->TransformRect(rcTemp); | |
| 145 pDevice->SetClip_Rect(FX_RECT((int32_t)rcTemp.left, (int32_t)rcTemp.bottom, | |
| 146 (int32_t)rcTemp.right, (int32_t)rcTemp.top)); | |
| 147 | |
| 148 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { | |
| 149 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { | |
| 150 CFX_FloatRect rcChild = pChild->ChildToParent(pChild->GetWindowRect()); | |
| 151 if (!(rcChild.top < rcClient.bottom || rcChild.bottom > rcClient.top)) { | |
| 152 CFX_Matrix mt = pChild->GetChildMatrix(); | |
| 153 if (mt.IsIdentity()) { | |
| 154 pChild->DrawAppearance(pDevice, pUser2Device); | |
| 155 } else { | |
| 156 mt.Concat(*pUser2Device); | |
| 157 pChild->DrawAppearance(pDevice, &mt); | |
| 158 } | |
| 159 } | |
| 160 } | |
| 161 } | |
| 162 | |
| 163 pDevice->RestoreState(false); | |
| 164 } | |
| 165 | |
| 166 int32_t CPWL_ListCtrl::GetItemIndex(CPWL_Wnd* pItem) { | |
| 167 for (int32_t i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { | |
| 168 if (pItem == m_aChildren.GetAt(i)) | |
| 169 return i; | |
| 170 } | |
| 171 | |
| 172 return -1; | |
| 173 } | |
| 174 | |
| 175 CFX_FloatPoint CPWL_ListCtrl::InToOut(const CFX_FloatPoint& point) const { | |
| 176 CFX_FloatRect rcClient = GetClientRect(); | |
| 177 | |
| 178 return CFX_FloatPoint(point.x + rcClient.left - m_ptScroll.x, | |
| 179 point.y + rcClient.top - m_ptScroll.y); | |
| 180 } | |
| 181 | |
| 182 CFX_FloatPoint CPWL_ListCtrl::OutToIn(const CFX_FloatPoint& point) const { | |
| 183 CFX_FloatRect rcClient = GetClientRect(); | |
| 184 | |
| 185 return CFX_FloatPoint(point.x - rcClient.left + m_ptScroll.x, | |
| 186 point.y - rcClient.top + m_ptScroll.y); | |
| 187 } | |
| 188 | |
| 189 CFX_FloatRect CPWL_ListCtrl::InToOut(const CFX_FloatRect& rect) const { | |
| 190 CFX_FloatRect rcClient = GetClientRect(); | |
| 191 | |
| 192 return CFX_FloatRect(rect.left + rcClient.left - m_ptScroll.x, | |
| 193 rect.bottom + rcClient.top - m_ptScroll.y, | |
| 194 rect.right + rcClient.left - m_ptScroll.x, | |
| 195 rect.top + rcClient.top - m_ptScroll.y); | |
| 196 } | |
| 197 | |
| 198 CFX_FloatRect CPWL_ListCtrl::OutToIn(const CFX_FloatRect& rect) const { | |
| 199 CFX_FloatRect rcClient = GetClientRect(); | |
| 200 | |
| 201 return CFX_FloatRect(rect.left - rcClient.left + m_ptScroll.x, | |
| 202 rect.bottom - rcClient.top + m_ptScroll.y, | |
| 203 rect.right - rcClient.left + m_ptScroll.x, | |
| 204 rect.top - rcClient.top + m_ptScroll.y); | |
| 205 } | |
| OLD | NEW |