Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: fpdfsdk/fxedit/fxet_list.cpp

Issue 2142213002: Remove some IFX_* wrappers. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "fpdfsdk/fxedit/include/fxet_list.h" 7 #include "fpdfsdk/fxedit/include/fxet_list.h"
8 8
9 #include "core/fpdfdoc/include/cpvt_word.h" 9 #include "core/fpdfdoc/include/cpvt_word.h"
10 #include "fpdfsdk/fxedit/include/fxet_edit.h" 10 #include "fpdfsdk/fxedit/include/fxet_edit.h"
11 #include "fpdfsdk/pdfwindow/PWL_ListBox.h"
11 12
12 CFX_ListItem::CFX_ListItem() 13 CFX_ListItem::CFX_ListItem()
13 : m_pEdit(IFX_Edit::NewEdit()), 14 : m_pEdit(new CFX_Edit),
14 m_bSelected(FALSE), 15 m_bSelected(FALSE),
15 m_rcListItem(0.0f, 0.0f, 0.0f, 0.0f) { 16 m_rcListItem(0.0f, 0.0f, 0.0f, 0.0f) {
16 m_pEdit->SetAlignmentV(1); 17 m_pEdit->SetAlignmentV(1);
17 m_pEdit->Initialize(); 18 m_pEdit->Initialize();
18 } 19 }
19 20
20 CFX_ListItem::~CFX_ListItem() { 21 CFX_ListItem::~CFX_ListItem() {
21 IFX_Edit::DelEdit(m_pEdit);
22 } 22 }
23 23
24 void CFX_ListItem::SetFontMap(IPVT_FontMap* pFontMap) { 24 void CFX_ListItem::SetFontMap(IPVT_FontMap* pFontMap) {
25 m_pEdit->SetFontMap(pFontMap); 25 m_pEdit->SetFontMap(pFontMap);
26 } 26 }
27 27
28 IFX_Edit* CFX_ListItem::GetEdit() const { 28 CFX_Edit* CFX_ListItem::GetEdit() const {
29 return m_pEdit; 29 return m_pEdit.get();
30 } 30 }
31 31
32 IFX_Edit_Iterator* CFX_ListItem::GetIterator() const { 32 CFX_Edit_Iterator* CFX_ListItem::GetIterator() const {
33 return m_pEdit->GetIterator(); 33 return m_pEdit->GetIterator();
34 } 34 }
35 35
36 void CFX_ListItem::SetRect(const CLST_Rect& rect) { 36 void CFX_ListItem::SetRect(const CLST_Rect& rect) {
37 m_rcListItem = rect; 37 m_rcListItem = rect;
38 } 38 }
39 39
40 CLST_Rect CFX_ListItem::GetRect() const { 40 CLST_Rect CFX_ListItem::GetRect() const {
41 return m_rcListItem; 41 return m_rcListItem;
42 } 42 }
(...skipping 13 matching lines...) Expand all
56 void CFX_ListItem::SetFontSize(FX_FLOAT fFontSize) { 56 void CFX_ListItem::SetFontSize(FX_FLOAT fFontSize) {
57 m_pEdit->SetFontSize(fFontSize); 57 m_pEdit->SetFontSize(fFontSize);
58 } 58 }
59 59
60 FX_FLOAT CFX_ListItem::GetItemHeight() const { 60 FX_FLOAT CFX_ListItem::GetItemHeight() const {
61 return m_pEdit->GetContentRect().Height(); 61 return m_pEdit->GetContentRect().Height();
62 } 62 }
63 63
64 uint16_t CFX_ListItem::GetFirstChar() const { 64 uint16_t CFX_ListItem::GetFirstChar() const {
65 CPVT_Word word; 65 CPVT_Word word;
66 IFX_Edit_Iterator* pIterator = GetIterator(); 66 CFX_Edit_Iterator* pIterator = GetIterator();
67 pIterator->SetAt(1); 67 pIterator->SetAt(1);
68 pIterator->GetWord(word); 68 pIterator->GetWord(word);
69 return word.Word; 69 return word.Word;
70 } 70 }
71 71
72 CFX_WideString CFX_ListItem::GetText() const { 72 CFX_WideString CFX_ListItem::GetText() const {
73 return m_pEdit->GetText(); 73 return m_pEdit->GetText();
74 } 74 }
75 75
76 CFX_ListContainer::CFX_ListContainer() {} 76 CFX_ListContainer::CFX_ListContainer() {}
77 77
78 CFX_ListContainer::~CFX_ListContainer() {} 78 CFX_ListContainer::~CFX_ListContainer() {}
79 79
80 void CFX_ListContainer::SetPlateRect(const CFX_FloatRect& rect) { 80 void CFX_ListContainer::SetPlateRect(const CFX_FloatRect& rect) {
81 m_rcPlate = rect; 81 m_rcPlate = rect;
82 } 82 }
83 83
84 CFX_List::CFX_List()
85 : m_fFontSize(0.0f), m_pFontMap(nullptr), m_bMultiple(FALSE) {}
86
87 CFX_List::~CFX_List() {
88 Empty();
89 }
90
91 void CFX_List::Empty() {
92 for (int32_t i = 0, sz = m_aListItems.GetSize(); i < sz; i++)
93 delete m_aListItems.GetAt(i);
94
95 m_aListItems.RemoveAll();
96 }
97
98 void CFX_List::SetFontMap(IPVT_FontMap* pFontMap) {
99 m_pFontMap = pFontMap;
100 }
101
102 void CFX_List::SetFontSize(FX_FLOAT fFontSize) {
103 m_fFontSize = fFontSize;
104 }
105
106 void CFX_List::AddItem(const FX_WCHAR* str) {
107 CFX_ListItem* pListItem = new CFX_ListItem();
108 pListItem->SetFontMap(m_pFontMap);
109 pListItem->SetFontSize(m_fFontSize);
110 pListItem->SetText(str);
111 m_aListItems.Add(pListItem);
112 }
113
114 void CFX_List::ReArrange(int32_t nItemIndex) {
115 FX_FLOAT fPosY = 0.0f;
116
117 if (CFX_ListItem* pPrevItem = m_aListItems.GetAt(nItemIndex - 1))
118 fPosY = pPrevItem->GetRect().bottom;
119
120 for (int32_t i = nItemIndex, sz = m_aListItems.GetSize(); i < sz; i++) {
121 if (CFX_ListItem* pListItem = m_aListItems.GetAt(i)) {
122 FX_FLOAT fListItemHeight = pListItem->GetItemHeight();
123 pListItem->SetRect(CLST_Rect(0.0f, fPosY, 0.0f, fPosY + fListItemHeight));
124 fPosY += fListItemHeight;
125 }
126 }
127
128 SetContentRect(CLST_Rect(0.0f, 0.0f, 0.0f, fPosY));
129 }
130
131 IFX_Edit* CFX_List::GetItemEdit(int32_t nIndex) const {
132 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nIndex)) {
133 return pListItem->GetEdit();
134 }
135
136 return nullptr;
137 }
138
139 int32_t CFX_List::GetCount() const {
140 return m_aListItems.GetSize();
141 }
142
143 CFX_FloatRect CFX_List::GetPlateRect() const {
144 return CFX_ListContainer::GetPlateRect();
145 }
146
147 CFX_FloatRect CFX_List::GetContentRect() const {
148 return InnerToOuter(CFX_ListContainer::GetContentRect());
149 }
150
151 FX_FLOAT CFX_List::GetFontSize() const {
152 return m_fFontSize;
153 }
154
155 int32_t CFX_List::GetItemIndex(const CFX_FloatPoint& point) const {
156 CFX_FloatPoint pt = OuterToInner(point);
157
158 FX_BOOL bFirst = TRUE;
159 FX_BOOL bLast = TRUE;
160
161 for (int32_t i = 0, sz = m_aListItems.GetSize(); i < sz; i++) {
162 if (CFX_ListItem* pListItem = m_aListItems.GetAt(i)) {
163 CLST_Rect rcListItem = pListItem->GetRect();
164
165 if (FX_EDIT_IsFloatBigger(pt.y, rcListItem.top)) {
166 bFirst = FALSE;
167 }
168
169 if (FX_EDIT_IsFloatSmaller(pt.y, rcListItem.bottom)) {
170 bLast = FALSE;
171 }
172
173 if (pt.y >= rcListItem.top && pt.y < rcListItem.bottom) {
174 return i;
175 }
176 }
177 }
178
179 if (bFirst)
180 return 0;
181 if (bLast)
182 return m_aListItems.GetSize() - 1;
183
184 return -1;
185 }
186
187 FX_FLOAT CFX_List::GetFirstHeight() const {
188 if (CFX_ListItem* pListItem = m_aListItems.GetAt(0)) {
189 return pListItem->GetItemHeight();
190 }
191
192 return 1.0f;
193 }
194
195 int32_t CFX_List::GetFirstSelected() const {
196 for (int32_t i = 0, sz = m_aListItems.GetSize(); i < sz; i++) {
197 if (CFX_ListItem* pListItem = m_aListItems.GetAt(i)) {
198 if (pListItem->IsSelected())
199 return i;
200 }
201 }
202 return -1;
203 }
204
205 int32_t CFX_List::GetLastSelected() const {
206 for (int32_t i = m_aListItems.GetSize() - 1; i >= 0; i--) {
207 if (CFX_ListItem* pListItem = m_aListItems.GetAt(i)) {
208 if (pListItem->IsSelected())
209 return i;
210 }
211 }
212 return -1;
213 }
214
215 FX_WCHAR CFX_List::Toupper(FX_WCHAR c) const {
216 if ((c >= 'a') && (c <= 'z'))
217 c = c - ('a' - 'A');
218 return c;
219 }
220
221 int32_t CFX_List::FindNext(int32_t nIndex, FX_WCHAR nChar) const {
222 int32_t nCircleIndex = nIndex;
223
224 for (int32_t i = 0, sz = m_aListItems.GetSize(); i < sz; i++) {
225 nCircleIndex++;
226 if (nCircleIndex >= sz)
227 nCircleIndex = 0;
228
229 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nCircleIndex)) {
230 if (Toupper(pListItem->GetFirstChar()) == Toupper(nChar))
231 return nCircleIndex;
232 }
233 }
234
235 return nCircleIndex;
236 }
237
238 CFX_FloatRect CFX_List::GetItemRect(int32_t nIndex) const {
239 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nIndex)) {
240 CFX_FloatRect rcItem = pListItem->GetRect();
241 rcItem.left = 0.0f;
242 rcItem.right = GetPlateRect().Width();
243 return InnerToOuter(CLST_Rect(rcItem));
244 }
245
246 return CFX_FloatRect();
247 }
248
249 FX_BOOL CFX_List::IsItemSelected(int32_t nIndex) const {
250 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nIndex))
251 return pListItem->IsSelected();
252 return FALSE;
253 }
254
255 void CFX_List::SetItemSelect(int32_t nItemIndex, FX_BOOL bSelected) {
256 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nItemIndex)) {
257 pListItem->SetSelect(bSelected);
258 }
259 }
260
261 void CFX_List::SetMultipleSel(FX_BOOL bMultiple) {
262 m_bMultiple = bMultiple;
263 }
264
265 FX_BOOL CFX_List::IsMultipleSel() const {
266 return m_bMultiple;
267 }
268
269 FX_BOOL CFX_List::IsValid(int32_t nItemIndex) const {
270 return nItemIndex >= 0 && nItemIndex < m_aListItems.GetSize();
271 }
272
273 CFX_WideString CFX_List::GetItemText(int32_t nIndex) const {
274 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nIndex)) {
275 return pListItem->GetText();
276 }
277
278 return L"";
279 }
280
281 CPLST_Select::CPLST_Select() {} 84 CPLST_Select::CPLST_Select() {}
282 85
283 CPLST_Select::~CPLST_Select() { 86 CPLST_Select::~CPLST_Select() {
284 for (int32_t i = 0, sz = m_aItems.GetSize(); i < sz; i++) 87 for (int32_t i = 0, sz = m_aItems.GetSize(); i < sz; i++)
285 delete m_aItems.GetAt(i); 88 delete m_aItems.GetAt(i);
286 89
287 m_aItems.RemoveAll(); 90 m_aItems.RemoveAll();
288 } 91 }
289 92
290 void CPLST_Select::Add(int32_t nItemIndex) { 93 void CPLST_Select::Add(int32_t nItemIndex) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 delete pItem; 182 delete pItem;
380 m_aItems.RemoveAt(i); 183 m_aItems.RemoveAt(i);
381 } else { 184 } else {
382 pItem->nState = 0; 185 pItem->nState = 0;
383 } 186 }
384 } 187 }
385 } 188 }
386 } 189 }
387 190
388 CFX_ListCtrl::CFX_ListCtrl() 191 CFX_ListCtrl::CFX_ListCtrl()
389 : m_pNotify(nullptr), 192 : m_bNotifyFlag(FALSE),
390 m_bNotifyFlag(FALSE),
391 m_ptScrollPos(0.0f, 0.0f), 193 m_ptScrollPos(0.0f, 0.0f),
392 m_nSelItem(-1), 194 m_nSelItem(-1),
393 m_nFootIndex(-1), 195 m_nFootIndex(-1),
394 m_bCtrlSel(FALSE), 196 m_bCtrlSel(FALSE),
395 m_nCaretIndex(-1) {} 197 m_nCaretIndex(-1),
198 m_fFontSize(0.0f),
199 m_pFontMap(nullptr),
200 m_bMultiple(FALSE) {}
396 201
397 CFX_ListCtrl::~CFX_ListCtrl() {} 202 CFX_ListCtrl::~CFX_ListCtrl() {
203 Empty();
204 }
398 205
399 void CFX_ListCtrl::SetNotify(IFX_List_Notify* pNotify) { 206 void CFX_ListCtrl::SetNotify(CPWL_List_Notify* pNotify) {
Lei Zhang 2016/07/12 21:36:46 Convert to unique_ptr?
dsinclair 2016/07/13 14:05:45 This is a mistake. The notify should not be owned
400 m_pNotify = pNotify; 207 m_pNotify.reset(pNotify);
401 } 208 }
402 209
403 CFX_FloatPoint CFX_ListCtrl::InToOut(const CFX_FloatPoint& point) const { 210 CFX_FloatPoint CFX_ListCtrl::InToOut(const CFX_FloatPoint& point) const {
404 CFX_FloatRect rcPlate = GetPlateRect(); 211 CFX_FloatRect rcPlate = GetPlateRect();
405 212
406 return CFX_FloatPoint(point.x - (m_ptScrollPos.x - rcPlate.left), 213 return CFX_FloatPoint(point.x - (m_ptScrollPos.x - rcPlate.left),
407 point.y - (m_ptScrollPos.y - rcPlate.top)); 214 point.y - (m_ptScrollPos.y - rcPlate.top));
408 } 215 }
409 216
410 CFX_FloatPoint CFX_ListCtrl::OutToIn(const CFX_FloatPoint& point) const { 217 CFX_FloatPoint CFX_ListCtrl::OutToIn(const CFX_FloatPoint& point) const {
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 366
560 void CFX_ListCtrl::SetPlateRect(const CFX_FloatRect& rect) { 367 void CFX_ListCtrl::SetPlateRect(const CFX_FloatRect& rect) {
561 CFX_ListContainer::SetPlateRect(rect); 368 CFX_ListContainer::SetPlateRect(rect);
562 m_ptScrollPos.x = rect.left; 369 m_ptScrollPos.x = rect.left;
563 SetScrollPos(CFX_FloatPoint(rect.left, rect.top)); 370 SetScrollPos(CFX_FloatPoint(rect.left, rect.top));
564 ReArrange(0); 371 ReArrange(0);
565 InvalidateItem(-1); 372 InvalidateItem(-1);
566 } 373 }
567 374
568 CFX_FloatRect CFX_ListCtrl::GetItemRect(int32_t nIndex) const { 375 CFX_FloatRect CFX_ListCtrl::GetItemRect(int32_t nIndex) const {
569 return InToOut(CFX_List::GetItemRect(nIndex)); 376 return InToOut(GetItemRectInternal(nIndex));
377 }
378
379 CFX_FloatRect CFX_ListCtrl::GetItemRectInternal(int32_t nIndex) const {
380 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nIndex)) {
381 CFX_FloatRect rcItem = pListItem->GetRect();
382 rcItem.left = 0.0f;
383 rcItem.right = GetPlateRect().Width();
384 return InnerToOuter(CLST_Rect(rcItem));
385 }
386
387 return CFX_FloatRect();
570 } 388 }
571 389
572 int32_t CFX_ListCtrl::GetCaret() const { 390 int32_t CFX_ListCtrl::GetCaret() const {
573 return m_nCaretIndex; 391 return m_nCaretIndex;
574 } 392 }
575 393
576 int32_t CFX_ListCtrl::GetSelect() const { 394 int32_t CFX_ListCtrl::GetSelect() const {
577 return m_nSelItem; 395 return m_nSelItem;
578 } 396 }
579 397
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 CFX_FloatRect rcItem = GetItemRect(nItemIndex); 506 CFX_FloatRect rcItem = GetItemRect(nItemIndex);
689 507
690 return rcItem.bottom >= rcPlate.bottom && rcItem.top <= rcPlate.top; 508 return rcItem.bottom >= rcPlate.bottom && rcItem.top <= rcPlate.top;
691 } 509 }
692 510
693 void CFX_ListCtrl::ScrollToListItem(int32_t nItemIndex) { 511 void CFX_ListCtrl::ScrollToListItem(int32_t nItemIndex) {
694 if (!IsValid(nItemIndex)) 512 if (!IsValid(nItemIndex))
695 return; 513 return;
696 514
697 CFX_FloatRect rcPlate = GetPlateRect(); 515 CFX_FloatRect rcPlate = GetPlateRect();
698 CFX_FloatRect rcItem = CFX_List::GetItemRect(nItemIndex); 516 CFX_FloatRect rcItem = GetItemRectInternal(nItemIndex);
699 CFX_FloatRect rcItemCtrl = GetItemRect(nItemIndex); 517 CFX_FloatRect rcItemCtrl = GetItemRect(nItemIndex);
700 518
701 if (FX_EDIT_IsFloatSmaller(rcItemCtrl.bottom, rcPlate.bottom)) { 519 if (FX_EDIT_IsFloatSmaller(rcItemCtrl.bottom, rcPlate.bottom)) {
702 if (FX_EDIT_IsFloatSmaller(rcItemCtrl.top, rcPlate.top)) { 520 if (FX_EDIT_IsFloatSmaller(rcItemCtrl.top, rcPlate.top)) {
703 SetScrollPosY(rcItem.bottom + rcPlate.Height()); 521 SetScrollPosY(rcItem.bottom + rcPlate.Height());
704 } 522 }
705 } else if (FX_EDIT_IsFloatBigger(rcItemCtrl.top, rcPlate.top)) { 523 } else if (FX_EDIT_IsFloatBigger(rcItemCtrl.top, rcPlate.top)) {
706 if (FX_EDIT_IsFloatBigger(rcItemCtrl.bottom, rcPlate.bottom)) { 524 if (FX_EDIT_IsFloatBigger(rcItemCtrl.bottom, rcPlate.bottom)) {
707 SetScrollPosY(rcItem.top); 525 SetScrollPosY(rcItem.top);
708 } 526 }
709 } 527 }
710 } 528 }
711 529
712 void CFX_ListCtrl::SetScrollInfo() { 530 void CFX_ListCtrl::SetScrollInfo() {
713 if (m_pNotify) { 531 if (m_pNotify) {
714 CFX_FloatRect rcPlate = GetPlateRect(); 532 CFX_FloatRect rcPlate = GetPlateRect();
715 CFX_FloatRect rcContent = CFX_List::GetContentRect(); 533 CFX_FloatRect rcContent = GetContentRectInternal();
716 534
717 if (!m_bNotifyFlag) { 535 if (!m_bNotifyFlag) {
718 m_bNotifyFlag = TRUE; 536 m_bNotifyFlag = TRUE;
719 m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top, 537 m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top,
720 rcContent.bottom, rcContent.top, 538 rcContent.bottom, rcContent.top,
721 GetFirstHeight(), rcPlate.Height()); 539 GetFirstHeight(), rcPlate.Height());
722 m_bNotifyFlag = FALSE; 540 m_bNotifyFlag = FALSE;
723 } 541 }
724 } 542 }
725 } 543 }
726 544
727 void CFX_ListCtrl::SetScrollPos(const CFX_FloatPoint& point) { 545 void CFX_ListCtrl::SetScrollPos(const CFX_FloatPoint& point) {
728 SetScrollPosY(point.y); 546 SetScrollPosY(point.y);
729 } 547 }
730 548
731 void CFX_ListCtrl::SetScrollPosY(FX_FLOAT fy) { 549 void CFX_ListCtrl::SetScrollPosY(FX_FLOAT fy) {
732 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y, fy)) { 550 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y, fy)) {
733 CFX_FloatRect rcPlate = GetPlateRect(); 551 CFX_FloatRect rcPlate = GetPlateRect();
734 CFX_FloatRect rcContent = CFX_List::GetContentRect(); 552 CFX_FloatRect rcContent = GetContentRectInternal();
735 553
736 if (rcPlate.Height() > rcContent.Height()) { 554 if (rcPlate.Height() > rcContent.Height()) {
737 fy = rcPlate.top; 555 fy = rcPlate.top;
738 } else { 556 } else {
739 if (FX_EDIT_IsFloatSmaller(fy - rcPlate.Height(), rcContent.bottom)) { 557 if (FX_EDIT_IsFloatSmaller(fy - rcPlate.Height(), rcContent.bottom)) {
740 fy = rcContent.bottom + rcPlate.Height(); 558 fy = rcContent.bottom + rcPlate.Height();
741 } else if (FX_EDIT_IsFloatBigger(fy, rcContent.top)) { 559 } else if (FX_EDIT_IsFloatBigger(fy, rcContent.top)) {
742 fy = rcContent.top; 560 fy = rcContent.top;
743 } 561 }
744 } 562 }
745 563
746 m_ptScrollPos.y = fy; 564 m_ptScrollPos.y = fy;
747 InvalidateItem(-1); 565 InvalidateItem(-1);
748 566
749 if (m_pNotify) { 567 if (m_pNotify) {
750 if (!m_bNotifyFlag) { 568 if (!m_bNotifyFlag) {
751 m_bNotifyFlag = TRUE; 569 m_bNotifyFlag = TRUE;
752 m_pNotify->IOnSetScrollPosY(fy); 570 m_pNotify->IOnSetScrollPosY(fy);
753 m_bNotifyFlag = FALSE; 571 m_bNotifyFlag = FALSE;
754 } 572 }
755 } 573 }
756 } 574 }
757 } 575 }
758 576
577 CFX_FloatRect CFX_ListCtrl::GetContentRectInternal() const {
578 return InnerToOuter(CFX_ListContainer::GetContentRect());
579 }
580
759 CFX_FloatRect CFX_ListCtrl::GetContentRect() const { 581 CFX_FloatRect CFX_ListCtrl::GetContentRect() const {
760 return InToOut(CFX_List::GetContentRect()); 582 return InToOut(GetContentRectInternal());
761 } 583 }
762 584
763 void CFX_ListCtrl::ReArrange(int32_t nItemIndex) { 585 void CFX_ListCtrl::ReArrange(int32_t nItemIndex) {
764 CFX_List::ReArrange(nItemIndex); 586 FX_FLOAT fPosY = 0.0f;
587
588 if (CFX_ListItem* pPrevItem = m_aListItems.GetAt(nItemIndex - 1))
589 fPosY = pPrevItem->GetRect().bottom;
590
591 for (int32_t i = nItemIndex, sz = m_aListItems.GetSize(); i < sz; i++) {
592 if (CFX_ListItem* pListItem = m_aListItems.GetAt(i)) {
593 FX_FLOAT fListItemHeight = pListItem->GetItemHeight();
594 pListItem->SetRect(CLST_Rect(0.0f, fPosY, 0.0f, fPosY + fListItemHeight));
595 fPosY += fListItemHeight;
596 }
597 }
598
599 SetContentRect(CLST_Rect(0.0f, 0.0f, 0.0f, fPosY));
765 SetScrollInfo(); 600 SetScrollInfo();
766 } 601 }
767 602
768 void CFX_ListCtrl::SetTopItem(int32_t nIndex) { 603 void CFX_ListCtrl::SetTopItem(int32_t nIndex) {
769 if (IsValid(nIndex)) { 604 if (IsValid(nIndex)) {
770 GetPlateRect(); 605 GetPlateRect();
771 CFX_FloatRect rcItem = CFX_List::GetItemRect(nIndex); 606 CFX_FloatRect rcItem = GetItemRectInternal(nIndex);
772 SetScrollPosY(rcItem.top); 607 SetScrollPosY(rcItem.top);
773 } 608 }
774 } 609 }
775 610
776 int32_t CFX_ListCtrl::GetTopItem() const { 611 int32_t CFX_ListCtrl::GetTopItem() const {
777 int32_t nItemIndex = GetItemIndex(GetBTPoint()); 612 int32_t nItemIndex = GetItemIndex(GetBTPoint());
778 613
779 if (!IsItemVisible(nItemIndex) && IsItemVisible(nItemIndex + 1)) 614 if (!IsItemVisible(nItemIndex) && IsItemVisible(nItemIndex + 1))
780 nItemIndex += 1; 615 nItemIndex += 1;
781 616
782 return nItemIndex; 617 return nItemIndex;
783 } 618 }
784 619
785 void CFX_ListCtrl::Empty() { 620 void CFX_ListCtrl::Empty() {
Lei Zhang 2016/07/12 21:36:46 Can we rename these to Clear() later?
dsinclair 2016/07/13 14:05:45 Acknowledged.
786 CFX_List::Empty(); 621 for (int32_t i = 0, sz = m_aListItems.GetSize(); i < sz; i++)
622 delete m_aListItems.GetAt(i);
623
624 m_aListItems.RemoveAll();
625
787 InvalidateItem(-1); 626 InvalidateItem(-1);
788 } 627 }
789 628
790 void CFX_ListCtrl::Cancel() { 629 void CFX_ListCtrl::Cancel() {
791 m_aSelItems.DeselectAll(); 630 m_aSelItems.DeselectAll();
792 } 631 }
793 632
794 int32_t CFX_ListCtrl::GetItemIndex(const CFX_FloatPoint& point) const { 633 int32_t CFX_ListCtrl::GetItemIndex(const CFX_FloatPoint& point) const {
795 return CFX_List::GetItemIndex(OutToIn(point)); 634 CFX_FloatPoint pt = OuterToInner(OutToIn(point));
635
636 FX_BOOL bFirst = TRUE;
637 FX_BOOL bLast = TRUE;
638
639 for (int32_t i = 0, sz = m_aListItems.GetSize(); i < sz; i++) {
640 if (CFX_ListItem* pListItem = m_aListItems.GetAt(i)) {
641 CLST_Rect rcListItem = pListItem->GetRect();
642
643 if (FX_EDIT_IsFloatBigger(pt.y, rcListItem.top)) {
644 bFirst = FALSE;
645 }
646
647 if (FX_EDIT_IsFloatSmaller(pt.y, rcListItem.bottom)) {
648 bLast = FALSE;
649 }
650
651 if (pt.y >= rcListItem.top && pt.y < rcListItem.bottom) {
652 return i;
653 }
654 }
655 }
656
657 if (bFirst)
658 return 0;
659 if (bLast)
660 return m_aListItems.GetSize() - 1;
661
662 return -1;
796 } 663 }
797 664
798 CFX_WideString CFX_ListCtrl::GetText() const { 665 CFX_WideString CFX_ListCtrl::GetText() const {
799 if (IsMultipleSel()) 666 if (IsMultipleSel())
800 return GetItemText(m_nCaretIndex); 667 return GetItemText(m_nCaretIndex);
801 return GetItemText(m_nSelItem); 668 return GetItemText(m_nSelItem);
802 } 669 }
670
671 void CFX_ListCtrl::SetFontMap(IPVT_FontMap* pFontMap) {
672 m_pFontMap = pFontMap;
673 }
674
675 void CFX_ListCtrl::SetFontSize(FX_FLOAT fFontSize) {
676 m_fFontSize = fFontSize;
677 }
678
679 void CFX_ListCtrl::AddItem(const FX_WCHAR* str) {
680 CFX_ListItem* pListItem = new CFX_ListItem();
681 pListItem->SetFontMap(m_pFontMap);
682 pListItem->SetFontSize(m_fFontSize);
683 pListItem->SetText(str);
684 m_aListItems.Add(pListItem);
685 }
686
687 CFX_Edit* CFX_ListCtrl::GetItemEdit(int32_t nIndex) const {
688 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nIndex)) {
689 return pListItem->GetEdit();
690 }
691
692 return nullptr;
693 }
694
695 int32_t CFX_ListCtrl::GetCount() const {
696 return m_aListItems.GetSize();
697 }
698
699 CFX_FloatRect CFX_ListCtrl::GetPlateRect() const {
700 return CFX_ListContainer::GetPlateRect();
701 }
702
703 FX_FLOAT CFX_ListCtrl::GetFontSize() const {
704 return m_fFontSize;
705 }
706
707 FX_FLOAT CFX_ListCtrl::GetFirstHeight() const {
708 if (CFX_ListItem* pListItem = m_aListItems.GetAt(0)) {
709 return pListItem->GetItemHeight();
710 }
711
712 return 1.0f;
713 }
714
715 int32_t CFX_ListCtrl::GetFirstSelected() const {
716 for (int32_t i = 0, sz = m_aListItems.GetSize(); i < sz; i++) {
717 if (CFX_ListItem* pListItem = m_aListItems.GetAt(i)) {
718 if (pListItem->IsSelected())
719 return i;
720 }
721 }
722 return -1;
723 }
724
725 int32_t CFX_ListCtrl::GetLastSelected() const {
726 for (int32_t i = m_aListItems.GetSize() - 1; i >= 0; i--) {
727 if (CFX_ListItem* pListItem = m_aListItems.GetAt(i)) {
728 if (pListItem->IsSelected())
729 return i;
730 }
731 }
732 return -1;
733 }
734
735 FX_WCHAR CFX_ListCtrl::Toupper(FX_WCHAR c) const {
736 if ((c >= 'a') && (c <= 'z'))
737 c = c - ('a' - 'A');
738 return c;
739 }
740
741 int32_t CFX_ListCtrl::FindNext(int32_t nIndex, FX_WCHAR nChar) const {
742 int32_t nCircleIndex = nIndex;
743
744 for (int32_t i = 0, sz = m_aListItems.GetSize(); i < sz; i++) {
745 nCircleIndex++;
746 if (nCircleIndex >= sz)
747 nCircleIndex = 0;
748
749 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nCircleIndex)) {
750 if (Toupper(pListItem->GetFirstChar()) == Toupper(nChar))
751 return nCircleIndex;
752 }
753 }
754
755 return nCircleIndex;
756 }
757
758 FX_BOOL CFX_ListCtrl::IsItemSelected(int32_t nIndex) const {
759 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nIndex))
760 return pListItem->IsSelected();
761 return FALSE;
762 }
763
764 void CFX_ListCtrl::SetItemSelect(int32_t nItemIndex, FX_BOOL bSelected) {
765 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nItemIndex)) {
766 pListItem->SetSelect(bSelected);
767 }
768 }
769
770 void CFX_ListCtrl::SetMultipleSel(FX_BOOL bMultiple) {
771 m_bMultiple = bMultiple;
772 }
773
774 FX_BOOL CFX_ListCtrl::IsMultipleSel() const {
775 return m_bMultiple;
776 }
777
778 FX_BOOL CFX_ListCtrl::IsValid(int32_t nItemIndex) const {
779 return nItemIndex >= 0 && nItemIndex < m_aListItems.GetSize();
780 }
781
782 CFX_WideString CFX_ListCtrl::GetItemText(int32_t nIndex) const {
783 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nIndex)) {
784 return pListItem->GetText();
785 }
786
787 return L"";
788 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698