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 "../../include/pdfwindow/PDFWindow.h" | 7 #include "../../include/pdfwindow/PDFWindow.h" |
8 #include "../../include/pdfwindow/PWL_Wnd.h" | 8 #include "../../include/pdfwindow/PWL_Wnd.h" |
9 #include "../../include/pdfwindow/PWL_ListCtrl.h" | 9 #include "../../include/pdfwindow/PWL_ListCtrl.h" |
10 | 10 |
11 /* ---------------------------- CPWL_ListCtrl ---------------------------- */ | 11 /* ---------------------------- CPWL_ListCtrl ---------------------------- */ |
12 | 12 |
13 CPWL_ListCtrl::CPWL_ListCtrl() : | 13 CPWL_ListCtrl::CPWL_ListCtrl() |
14 m_rcContent(0,0,0,0), | 14 : m_rcContent(0, 0, 0, 0), |
15 m_ptScroll(0,0), | 15 m_ptScroll(0, 0), |
16 m_fItemSpace(0.0f), | 16 m_fItemSpace(0.0f), |
17 m_fTopSpace(0.0f), | 17 m_fTopSpace(0.0f), |
18 m_fBottomSpace(0.0f) | 18 m_fBottomSpace(0.0f) { |
19 { | 19 } |
20 } | 20 |
21 | 21 CPWL_ListCtrl::~CPWL_ListCtrl() { |
22 CPWL_ListCtrl::~CPWL_ListCtrl() | 22 } |
23 { | 23 |
24 } | 24 void CPWL_ListCtrl::SetScrollPos(const CPDF_Point& point) { |
25 | 25 m_ptScroll = point; |
26 void CPWL_ListCtrl::SetScrollPos(const CPDF_Point& point) | 26 |
27 { | 27 if (m_ptScroll.x < m_rcContent.left) |
28 m_ptScroll = point; | 28 m_ptScroll.x = m_rcContent.left; |
29 | 29 |
30 if (m_ptScroll.x < m_rcContent.left) | 30 if (m_ptScroll.x > m_rcContent.right) |
31 m_ptScroll.x = m_rcContent.left; | 31 m_ptScroll.x = m_rcContent.right; |
32 | 32 |
33 if (m_ptScroll.x > m_rcContent.right) | 33 if (m_ptScroll.y > m_rcContent.top) |
34 m_ptScroll.x = m_rcContent.right; | 34 m_ptScroll.y = m_rcContent.top; |
35 | 35 |
36 if (m_ptScroll.y > m_rcContent.top) | 36 if (m_ptScroll.y < m_rcContent.bottom) |
37 m_ptScroll.y = m_rcContent.top; | 37 m_ptScroll.y = m_rcContent.bottom; |
38 | 38 } |
39 if (m_ptScroll.y < m_rcContent.bottom) | 39 |
40 m_ptScroll.y = m_rcContent.bottom; | 40 CPDF_Point CPWL_ListCtrl::GetScrollPos() const { |
41 } | 41 return m_ptScroll; |
42 | 42 } |
43 CPDF_Point CPWL_ListCtrl::GetScrollPos() const | 43 |
44 { | 44 CPDF_Rect CPWL_ListCtrl::GetScrollArea() const { |
45 return m_ptScroll; | 45 return m_rcContent; |
46 } | 46 } |
47 | 47 |
48 CPDF_Rect CPWL_ListCtrl::GetScrollArea() const | 48 void CPWL_ListCtrl::ResetFace() { |
49 { | 49 ResetAll(FALSE, 0); |
50 return m_rcContent; | 50 } |
51 } | 51 |
52 | 52 void CPWL_ListCtrl::ResetContent(FX_INT32 nStart) { |
53 void CPWL_ListCtrl::ResetFace() | 53 if (nStart < 0) |
54 { | 54 nStart = 0; |
55 ResetAll(FALSE, 0); | 55 if (nStart >= 0 && nStart < m_aChildren.GetSize()) |
56 } | 56 ResetAll(TRUE, nStart); |
57 | 57 } |
58 void CPWL_ListCtrl::ResetContent(FX_INT32 nStart) | 58 |
59 { | 59 FX_FLOAT CPWL_ListCtrl::GetContentsHeight(FX_FLOAT fLimitWidth) { |
60 if (nStart < 0) | 60 FX_FLOAT fRet = m_fTopSpace; |
61 nStart = 0; | 61 |
62 if (nStart >= 0 && nStart < m_aChildren.GetSize()) | 62 FX_FLOAT fBorderWidth = (FX_FLOAT) this->GetBorderWidth(); |
63 ResetAll(TRUE, nStart); | 63 |
64 } | 64 if (fLimitWidth > fBorderWidth * 2) { |
65 | 65 for (FX_INT32 i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { |
66 FX_FLOAT CPWL_ListCtrl::GetContentsHeight(FX_FLOAT fLimitWidth) | 66 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { |
67 { | 67 FX_FLOAT fLeft = pChild->GetItemLeftMargin(); |
68 FX_FLOAT fRet = m_fTopSpace; | 68 FX_FLOAT fRight = pChild->GetItemRightMargin(); |
69 | 69 |
70 FX_FLOAT fBorderWidth = (FX_FLOAT)this->GetBorderWidth(); | 70 fRet += pChild->GetItemHeight(fLimitWidth - fBorderWidth * 2 - fLeft - |
71 | 71 fRight); |
72 if (fLimitWidth > fBorderWidth* 2) | 72 fRet += m_fItemSpace; |
73 { | 73 } |
74 for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++) | 74 } |
75 { | 75 |
76 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) | 76 fRet -= m_fItemSpace; |
77 { | 77 } |
78 FX_FLOAT fLeft = pChild->GetItemLeftMargin(); | 78 |
79 FX_FLOAT fRight = pChild->GetItemRightMargin(); | 79 fRet += m_fBottomSpace; |
80 | 80 |
81 fRet += pChild->GetItemHeight(fLimitWidth - fBor
derWidth* 2 - fLeft - fRight); | 81 return fRet; |
82 fRet += m_fItemSpace; | 82 } |
83 } | 83 |
84 } | 84 void CPWL_ListCtrl::ResetAll(FX_BOOL bMove, FX_INT32 nStart) { |
85 | 85 CPDF_Rect rcClient = GetClientRect(); |
86 fRet -= m_fItemSpace; | 86 |
87 } | 87 FX_FLOAT fWidth = rcClient.Width(); |
88 | 88 |
89 fRet += m_fBottomSpace; | 89 FX_FLOAT fy = 0.0f - m_fTopSpace; |
90 | 90 |
91 return fRet; | 91 if (nStart - 1 >= 0 && nStart - 1 < m_aChildren.GetSize()) |
92 } | 92 if (CPWL_Wnd* pChild = m_aChildren.GetAt(nStart - 1)) |
93 | 93 fy = pChild->GetWindowRect().bottom - m_fItemSpace; |
94 void CPWL_ListCtrl::ResetAll(FX_BOOL bMove, FX_INT32 nStart) | 94 |
95 { | 95 for (FX_INT32 i = nStart, sz = m_aChildren.GetSize(); i < sz; i++) { |
96 CPDF_Rect rcClient = GetClientRect(); | 96 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { |
97 | 97 FX_FLOAT fLeft = pChild->GetItemLeftMargin(); |
98 FX_FLOAT fWidth = rcClient.Width(); | 98 FX_FLOAT fRight = pChild->GetItemRightMargin(); |
99 | 99 |
100 FX_FLOAT fy = 0.0f - m_fTopSpace; | 100 pChild->SetChildMatrix(CPDF_Matrix(1, |
101 | 101 0, |
102 if (nStart-1 >= 0 && nStart-1 < m_aChildren.GetSize()) | 102 0, |
103 if (CPWL_Wnd* pChild = m_aChildren.GetAt(nStart-1)) | 103 1, |
104 fy = pChild->GetWindowRect().bottom - m_fItemSpace; | 104 rcClient.left - m_ptScroll.x, |
105 | 105 rcClient.top - m_ptScroll.y)); |
106 for (FX_INT32 i=nStart,sz=m_aChildren.GetSize(); i<sz; i++) | 106 |
107 { | 107 if (bMove) { |
108 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) | 108 FX_FLOAT fItemHeight = pChild->GetItemHeight(fWidth - fLeft - fRight); |
109 { | 109 pChild->Move(CPDF_Rect(fLeft, fy - fItemHeight, fWidth - fRight, fy), |
110 FX_FLOAT fLeft = pChild->GetItemLeftMargin(); | 110 TRUE, |
111 FX_FLOAT fRight = pChild->GetItemRightMargin(); | 111 FALSE); |
112 | 112 fy -= fItemHeight; |
113 pChild->SetChildMatrix( | 113 fy -= m_fItemSpace; |
114 CPDF_Matrix(1,0,0,1, | 114 } |
115 rcClient.left - m_ptScroll.x, | 115 } |
116 rcClient.top - m_ptScroll.y) | 116 } |
117 ); | 117 |
118 | 118 fy += m_fItemSpace; |
119 if (bMove) | 119 |
120 { | 120 fy -= m_fBottomSpace; |
121 FX_FLOAT fItemHeight = pChild->GetItemHeight(fWi
dth - fLeft - fRight); | 121 |
122 pChild->Move(CPDF_Rect(fLeft, fy-fItemHeight, fW
idth - fRight, fy), TRUE, FALSE); | 122 if (bMove) { |
123 fy -= fItemHeight; | 123 m_rcContent.left = 0; |
124 fy -= m_fItemSpace; | 124 m_rcContent.top = 0; |
125 } | 125 m_rcContent.right = fWidth; |
126 } | 126 m_rcContent.bottom = fy; |
127 } | 127 } |
128 | 128 } |
129 fy += m_fItemSpace; | 129 |
130 | 130 void CPWL_ListCtrl::SetItemSpace(FX_FLOAT fSpace) { |
131 fy -= m_fBottomSpace; | 131 m_fItemSpace = fSpace; |
132 | 132 } |
133 if (bMove) | 133 |
134 { | 134 void CPWL_ListCtrl::SetTopSpace(FX_FLOAT fSpace) { |
135 m_rcContent.left = 0; | 135 m_fTopSpace = fSpace; |
136 m_rcContent.top = 0; | 136 } |
137 m_rcContent.right = fWidth; | 137 |
138 m_rcContent.bottom = fy; | 138 void CPWL_ListCtrl::SetBottomSpace(FX_FLOAT fSpace) { |
139 } | 139 m_fBottomSpace = fSpace; |
140 } | 140 } |
141 | 141 |
142 void CPWL_ListCtrl::SetItemSpace(FX_FLOAT fSpace) | 142 void CPWL_ListCtrl::RePosChildWnd() { |
143 { | 143 ResetFace(); |
144 m_fItemSpace = fSpace; | 144 } |
145 } | 145 |
146 | 146 void CPWL_ListCtrl::DrawChildAppearance(CFX_RenderDevice* pDevice, |
147 void CPWL_ListCtrl::SetTopSpace(FX_FLOAT fSpace) | 147 CPDF_Matrix* pUser2Device) { |
148 { | 148 pDevice->SaveState(); |
149 m_fTopSpace = fSpace; | 149 CPDF_Rect rcClient = GetClientRect(); |
150 } | 150 CPDF_Rect rcTemp = rcClient; |
151 | 151 pUser2Device->TransformRect(rcTemp); |
152 void CPWL_ListCtrl::SetBottomSpace(FX_FLOAT fSpace) | 152 FX_RECT rcClip((FX_INT32)rcTemp.left, |
153 { | 153 (FX_INT32)rcTemp.bottom, |
154 m_fBottomSpace = fSpace; | 154 (FX_INT32)rcTemp.right, |
155 } | 155 (FX_INT32)rcTemp.top); |
156 | 156 |
157 void CPWL_ListCtrl::RePosChildWnd() | 157 pDevice->SetClip_Rect(&rcClip); |
158 { | 158 |
159 ResetFace(); | 159 for (FX_INT32 i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { |
160 } | 160 if (CPWL_Wnd* pChild = m_aChildren.GetAt(i)) { |
161 | 161 CPDF_Rect rcChild = pChild->ChildToParent(pChild->GetWindowRect()); |
162 void CPWL_ListCtrl::DrawChildAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix*
pUser2Device) | 162 if (!(rcChild.top < rcClient.bottom || rcChild.bottom > rcClient.top)) { |
163 { | 163 CPDF_Matrix mt = pChild->GetChildMatrix(); |
164 pDevice->SaveState(); | 164 if (mt.IsIdentity()) { |
165 CPDF_Rect rcClient = GetClientRect(); | 165 pChild->DrawAppearance(pDevice, pUser2Device); |
166 CPDF_Rect rcTemp = rcClient; | 166 } else { |
167 pUser2Device->TransformRect(rcTemp); | 167 mt.Concat(*pUser2Device); |
168 FX_RECT rcClip((FX_INT32)rcTemp.left, | 168 pChild->DrawAppearance(pDevice, &mt); |
169 (FX_INT32)rcTemp.bottom, | 169 } |
170 (FX_INT32)rcTemp.right, | 170 } |
171 (FX_INT32)rcTemp.top); | 171 } |
172 | 172 } |
173 pDevice->SetClip_Rect(&rcClip); | 173 |
174 | 174 pDevice->RestoreState(); |
175 for (FX_INT32 i=0,sz=m_aChildren.GetSize(); i<sz; i++) | 175 } |
176 { | 176 |
177 if (CPWL_Wnd * pChild = m_aChildren.GetAt(i)) | 177 FX_INT32 CPWL_ListCtrl::GetItemIndex(CPWL_Wnd* pItem) { |
178 { | 178 for (FX_INT32 i = 0, sz = m_aChildren.GetSize(); i < sz; i++) { |
179 CPDF_Rect rcChild = pChild->ChildToParent(pChild->GetWin
dowRect()); | 179 if (pItem == m_aChildren.GetAt(i)) |
180 if (!(rcChild.top < rcClient.bottom || rcChild.bottom >
rcClient.top)) | 180 return i; |
181 { | 181 } |
182 CPDF_Matrix mt = pChild->GetChildMatrix(); | 182 |
183 if (mt.IsIdentity()) | 183 return -1; |
184 { | 184 } |
185 pChild->DrawAppearance(pDevice,pUser2Dev
ice); | 185 |
186 } | 186 CPDF_Point CPWL_ListCtrl::InToOut(const CPDF_Point& point) const { |
187 else | 187 CPDF_Rect rcClient = GetClientRect(); |
188 { | 188 |
189 mt.Concat(*pUser2Device); | 189 return CPDF_Point(point.x + rcClient.left - m_ptScroll.x, |
190 pChild->DrawAppearance(pDevice,&mt); | 190 point.y + rcClient.top - m_ptScroll.y); |
191 } | 191 } |
192 } | 192 |
193 } | 193 CPDF_Point CPWL_ListCtrl::OutToIn(const CPDF_Point& point) const { |
194 } | 194 CPDF_Rect rcClient = GetClientRect(); |
195 | 195 |
196 pDevice->RestoreState(); | 196 return CPDF_Point(point.x - rcClient.left + m_ptScroll.x, |
197 } | 197 point.y - rcClient.top + m_ptScroll.y); |
198 | 198 } |
199 FX_INT32 CPWL_ListCtrl::GetItemIndex(CPWL_Wnd* pItem) | 199 |
200 { | 200 CPDF_Rect CPWL_ListCtrl::InToOut(const CPDF_Rect& rect) const { |
201 for (FX_INT32 i=0, sz=m_aChildren.GetSize(); i<sz; i++) | 201 CPDF_Rect rcClient = GetClientRect(); |
202 { | 202 |
203 if (pItem == m_aChildren.GetAt(i)) | 203 return CPDF_Rect(rect.left + rcClient.left - m_ptScroll.x, |
204 return i; | 204 rect.bottom + rcClient.top - m_ptScroll.y, |
205 } | 205 rect.right + rcClient.left - m_ptScroll.x, |
206 | 206 rect.top + rcClient.top - m_ptScroll.y); |
207 return -1; | 207 } |
208 } | 208 |
209 | 209 CPDF_Rect CPWL_ListCtrl::OutToIn(const CPDF_Rect& rect) const { |
210 CPDF_Point CPWL_ListCtrl::InToOut(const CPDF_Point& point) const | 210 CPDF_Rect rcClient = GetClientRect(); |
211 { | 211 |
212 CPDF_Rect rcClient = GetClientRect(); | 212 return CPDF_Rect(rect.left - rcClient.left + m_ptScroll.x, |
213 | 213 rect.bottom - rcClient.top + m_ptScroll.y, |
214 return CPDF_Point(point.x + rcClient.left - m_ptScroll.x, | 214 rect.right - rcClient.left + m_ptScroll.x, |
215 point.y + rcClient.top - m_ptScroll.y); | 215 rect.top - rcClient.top + m_ptScroll.y); |
216 } | 216 } |
217 | |
218 CPDF_Point CPWL_ListCtrl::OutToIn(const CPDF_Point& point) const | |
219 { | |
220 CPDF_Rect rcClient = GetClientRect(); | |
221 | |
222 return CPDF_Point(point.x - rcClient.left + m_ptScroll.x, | |
223 point.y - rcClient.top + m_ptScroll.y); | |
224 } | |
225 | |
226 CPDF_Rect CPWL_ListCtrl::InToOut(const CPDF_Rect& rect) const | |
227 { | |
228 CPDF_Rect rcClient = GetClientRect(); | |
229 | |
230 return CPDF_Rect(rect.left + rcClient.left - m_ptScroll.x, | |
231 rect.bottom + rcClient.top - m_ptScroll.y, | |
232 rect.right + rcClient.left - m_ptScroll.x, | |
233 rect.top + rcClient.top - m_ptScroll.y); | |
234 } | |
235 | |
236 CPDF_Rect CPWL_ListCtrl::OutToIn(const CPDF_Rect& rect) const | |
237 { | |
238 CPDF_Rect rcClient = GetClientRect(); | |
239 | |
240 return CPDF_Rect(rect.left - rcClient.left + m_ptScroll.x, | |
241 rect.bottom - rcClient.top + m_ptScroll.y, | |
242 rect.right - rcClient.left + m_ptScroll.x, | |
243 rect.top - rcClient.top + m_ptScroll.y); | |
244 } | |
245 | |
OLD | NEW |