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

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: Rebase to master 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
« no previous file with comments | « fpdfsdk/fxedit/fxet_edit.cpp ('k') | fpdfsdk/fxedit/fxet_module.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 188 }
386 } 189 }
387 190
388 CFX_ListCtrl::CFX_ListCtrl() 191 CFX_ListCtrl::CFX_ListCtrl()
389 : m_pNotify(nullptr), 192 : m_pNotify(nullptr),
390 m_bNotifyFlag(FALSE), 193 m_bNotifyFlag(FALSE),
391 m_ptScrollPos(0.0f, 0.0f), 194 m_ptScrollPos(0.0f, 0.0f),
392 m_nSelItem(-1), 195 m_nSelItem(-1),
393 m_nFootIndex(-1), 196 m_nFootIndex(-1),
394 m_bCtrlSel(FALSE), 197 m_bCtrlSel(FALSE),
395 m_nCaretIndex(-1) {} 198 m_nCaretIndex(-1),
199 m_fFontSize(0.0f),
200 m_pFontMap(nullptr),
201 m_bMultiple(FALSE) {}
396 202
397 CFX_ListCtrl::~CFX_ListCtrl() {} 203 CFX_ListCtrl::~CFX_ListCtrl() {
204 Empty();
205 }
398 206
399 void CFX_ListCtrl::SetNotify(IFX_List_Notify* pNotify) { 207 void CFX_ListCtrl::SetNotify(CPWL_List_Notify* pNotify) {
400 m_pNotify = pNotify; 208 m_pNotify = pNotify;
401 } 209 }
402 210
403 CFX_FloatPoint CFX_ListCtrl::InToOut(const CFX_FloatPoint& point) const { 211 CFX_FloatPoint CFX_ListCtrl::InToOut(const CFX_FloatPoint& point) const {
404 CFX_FloatRect rcPlate = GetPlateRect(); 212 CFX_FloatRect rcPlate = GetPlateRect();
405 213
406 return CFX_FloatPoint(point.x - (m_ptScrollPos.x - rcPlate.left), 214 return CFX_FloatPoint(point.x - (m_ptScrollPos.x - rcPlate.left),
407 point.y - (m_ptScrollPos.y - rcPlate.top)); 215 point.y - (m_ptScrollPos.y - rcPlate.top));
408 } 216 }
409 217
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 367
560 void CFX_ListCtrl::SetPlateRect(const CFX_FloatRect& rect) { 368 void CFX_ListCtrl::SetPlateRect(const CFX_FloatRect& rect) {
561 CFX_ListContainer::SetPlateRect(rect); 369 CFX_ListContainer::SetPlateRect(rect);
562 m_ptScrollPos.x = rect.left; 370 m_ptScrollPos.x = rect.left;
563 SetScrollPos(CFX_FloatPoint(rect.left, rect.top)); 371 SetScrollPos(CFX_FloatPoint(rect.left, rect.top));
564 ReArrange(0); 372 ReArrange(0);
565 InvalidateItem(-1); 373 InvalidateItem(-1);
566 } 374 }
567 375
568 CFX_FloatRect CFX_ListCtrl::GetItemRect(int32_t nIndex) const { 376 CFX_FloatRect CFX_ListCtrl::GetItemRect(int32_t nIndex) const {
569 return InToOut(CFX_List::GetItemRect(nIndex)); 377 return InToOut(GetItemRectInternal(nIndex));
378 }
379
380 CFX_FloatRect CFX_ListCtrl::GetItemRectInternal(int32_t nIndex) const {
381 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nIndex)) {
382 CFX_FloatRect rcItem = pListItem->GetRect();
383 rcItem.left = 0.0f;
384 rcItem.right = GetPlateRect().Width();
385 return InnerToOuter(CLST_Rect(rcItem));
386 }
387
388 return CFX_FloatRect();
570 } 389 }
571 390
572 int32_t CFX_ListCtrl::GetCaret() const { 391 int32_t CFX_ListCtrl::GetCaret() const {
573 return m_nCaretIndex; 392 return m_nCaretIndex;
574 } 393 }
575 394
576 int32_t CFX_ListCtrl::GetSelect() const { 395 int32_t CFX_ListCtrl::GetSelect() const {
577 return m_nSelItem; 396 return m_nSelItem;
578 } 397 }
579 398
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 CFX_FloatRect rcItem = GetItemRect(nItemIndex); 507 CFX_FloatRect rcItem = GetItemRect(nItemIndex);
689 508
690 return rcItem.bottom >= rcPlate.bottom && rcItem.top <= rcPlate.top; 509 return rcItem.bottom >= rcPlate.bottom && rcItem.top <= rcPlate.top;
691 } 510 }
692 511
693 void CFX_ListCtrl::ScrollToListItem(int32_t nItemIndex) { 512 void CFX_ListCtrl::ScrollToListItem(int32_t nItemIndex) {
694 if (!IsValid(nItemIndex)) 513 if (!IsValid(nItemIndex))
695 return; 514 return;
696 515
697 CFX_FloatRect rcPlate = GetPlateRect(); 516 CFX_FloatRect rcPlate = GetPlateRect();
698 CFX_FloatRect rcItem = CFX_List::GetItemRect(nItemIndex); 517 CFX_FloatRect rcItem = GetItemRectInternal(nItemIndex);
699 CFX_FloatRect rcItemCtrl = GetItemRect(nItemIndex); 518 CFX_FloatRect rcItemCtrl = GetItemRect(nItemIndex);
700 519
701 if (FX_EDIT_IsFloatSmaller(rcItemCtrl.bottom, rcPlate.bottom)) { 520 if (FX_EDIT_IsFloatSmaller(rcItemCtrl.bottom, rcPlate.bottom)) {
702 if (FX_EDIT_IsFloatSmaller(rcItemCtrl.top, rcPlate.top)) { 521 if (FX_EDIT_IsFloatSmaller(rcItemCtrl.top, rcPlate.top)) {
703 SetScrollPosY(rcItem.bottom + rcPlate.Height()); 522 SetScrollPosY(rcItem.bottom + rcPlate.Height());
704 } 523 }
705 } else if (FX_EDIT_IsFloatBigger(rcItemCtrl.top, rcPlate.top)) { 524 } else if (FX_EDIT_IsFloatBigger(rcItemCtrl.top, rcPlate.top)) {
706 if (FX_EDIT_IsFloatBigger(rcItemCtrl.bottom, rcPlate.bottom)) { 525 if (FX_EDIT_IsFloatBigger(rcItemCtrl.bottom, rcPlate.bottom)) {
707 SetScrollPosY(rcItem.top); 526 SetScrollPosY(rcItem.top);
708 } 527 }
709 } 528 }
710 } 529 }
711 530
712 void CFX_ListCtrl::SetScrollInfo() { 531 void CFX_ListCtrl::SetScrollInfo() {
713 if (m_pNotify) { 532 if (m_pNotify) {
714 CFX_FloatRect rcPlate = GetPlateRect(); 533 CFX_FloatRect rcPlate = GetPlateRect();
715 CFX_FloatRect rcContent = CFX_List::GetContentRect(); 534 CFX_FloatRect rcContent = GetContentRectInternal();
716 535
717 if (!m_bNotifyFlag) { 536 if (!m_bNotifyFlag) {
718 m_bNotifyFlag = TRUE; 537 m_bNotifyFlag = TRUE;
719 m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top, 538 m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top,
720 rcContent.bottom, rcContent.top, 539 rcContent.bottom, rcContent.top,
721 GetFirstHeight(), rcPlate.Height()); 540 GetFirstHeight(), rcPlate.Height());
722 m_bNotifyFlag = FALSE; 541 m_bNotifyFlag = FALSE;
723 } 542 }
724 } 543 }
725 } 544 }
726 545
727 void CFX_ListCtrl::SetScrollPos(const CFX_FloatPoint& point) { 546 void CFX_ListCtrl::SetScrollPos(const CFX_FloatPoint& point) {
728 SetScrollPosY(point.y); 547 SetScrollPosY(point.y);
729 } 548 }
730 549
731 void CFX_ListCtrl::SetScrollPosY(FX_FLOAT fy) { 550 void CFX_ListCtrl::SetScrollPosY(FX_FLOAT fy) {
732 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y, fy)) { 551 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y, fy)) {
733 CFX_FloatRect rcPlate = GetPlateRect(); 552 CFX_FloatRect rcPlate = GetPlateRect();
734 CFX_FloatRect rcContent = CFX_List::GetContentRect(); 553 CFX_FloatRect rcContent = GetContentRectInternal();
735 554
736 if (rcPlate.Height() > rcContent.Height()) { 555 if (rcPlate.Height() > rcContent.Height()) {
737 fy = rcPlate.top; 556 fy = rcPlate.top;
738 } else { 557 } else {
739 if (FX_EDIT_IsFloatSmaller(fy - rcPlate.Height(), rcContent.bottom)) { 558 if (FX_EDIT_IsFloatSmaller(fy - rcPlate.Height(), rcContent.bottom)) {
740 fy = rcContent.bottom + rcPlate.Height(); 559 fy = rcContent.bottom + rcPlate.Height();
741 } else if (FX_EDIT_IsFloatBigger(fy, rcContent.top)) { 560 } else if (FX_EDIT_IsFloatBigger(fy, rcContent.top)) {
742 fy = rcContent.top; 561 fy = rcContent.top;
743 } 562 }
744 } 563 }
745 564
746 m_ptScrollPos.y = fy; 565 m_ptScrollPos.y = fy;
747 InvalidateItem(-1); 566 InvalidateItem(-1);
748 567
749 if (m_pNotify) { 568 if (m_pNotify) {
750 if (!m_bNotifyFlag) { 569 if (!m_bNotifyFlag) {
751 m_bNotifyFlag = TRUE; 570 m_bNotifyFlag = TRUE;
752 m_pNotify->IOnSetScrollPosY(fy); 571 m_pNotify->IOnSetScrollPosY(fy);
753 m_bNotifyFlag = FALSE; 572 m_bNotifyFlag = FALSE;
754 } 573 }
755 } 574 }
756 } 575 }
757 } 576 }
758 577
578 CFX_FloatRect CFX_ListCtrl::GetContentRectInternal() const {
579 return InnerToOuter(CFX_ListContainer::GetContentRect());
580 }
581
759 CFX_FloatRect CFX_ListCtrl::GetContentRect() const { 582 CFX_FloatRect CFX_ListCtrl::GetContentRect() const {
760 return InToOut(CFX_List::GetContentRect()); 583 return InToOut(GetContentRectInternal());
761 } 584 }
762 585
763 void CFX_ListCtrl::ReArrange(int32_t nItemIndex) { 586 void CFX_ListCtrl::ReArrange(int32_t nItemIndex) {
764 CFX_List::ReArrange(nItemIndex); 587 FX_FLOAT fPosY = 0.0f;
588
589 if (CFX_ListItem* pPrevItem = m_aListItems.GetAt(nItemIndex - 1))
590 fPosY = pPrevItem->GetRect().bottom;
591
592 for (int32_t i = nItemIndex, sz = m_aListItems.GetSize(); i < sz; i++) {
593 if (CFX_ListItem* pListItem = m_aListItems.GetAt(i)) {
594 FX_FLOAT fListItemHeight = pListItem->GetItemHeight();
595 pListItem->SetRect(CLST_Rect(0.0f, fPosY, 0.0f, fPosY + fListItemHeight));
596 fPosY += fListItemHeight;
597 }
598 }
599
600 SetContentRect(CLST_Rect(0.0f, 0.0f, 0.0f, fPosY));
765 SetScrollInfo(); 601 SetScrollInfo();
766 } 602 }
767 603
768 void CFX_ListCtrl::SetTopItem(int32_t nIndex) { 604 void CFX_ListCtrl::SetTopItem(int32_t nIndex) {
769 if (IsValid(nIndex)) { 605 if (IsValid(nIndex)) {
770 GetPlateRect(); 606 GetPlateRect();
771 CFX_FloatRect rcItem = CFX_List::GetItemRect(nIndex); 607 CFX_FloatRect rcItem = GetItemRectInternal(nIndex);
772 SetScrollPosY(rcItem.top); 608 SetScrollPosY(rcItem.top);
773 } 609 }
774 } 610 }
775 611
776 int32_t CFX_ListCtrl::GetTopItem() const { 612 int32_t CFX_ListCtrl::GetTopItem() const {
777 int32_t nItemIndex = GetItemIndex(GetBTPoint()); 613 int32_t nItemIndex = GetItemIndex(GetBTPoint());
778 614
779 if (!IsItemVisible(nItemIndex) && IsItemVisible(nItemIndex + 1)) 615 if (!IsItemVisible(nItemIndex) && IsItemVisible(nItemIndex + 1))
780 nItemIndex += 1; 616 nItemIndex += 1;
781 617
782 return nItemIndex; 618 return nItemIndex;
783 } 619 }
784 620
785 void CFX_ListCtrl::Empty() { 621 void CFX_ListCtrl::Empty() {
786 CFX_List::Empty(); 622 for (int32_t i = 0, sz = m_aListItems.GetSize(); i < sz; i++)
623 delete m_aListItems.GetAt(i);
624
625 m_aListItems.RemoveAll();
626
787 InvalidateItem(-1); 627 InvalidateItem(-1);
788 } 628 }
789 629
790 void CFX_ListCtrl::Cancel() { 630 void CFX_ListCtrl::Cancel() {
791 m_aSelItems.DeselectAll(); 631 m_aSelItems.DeselectAll();
792 } 632 }
793 633
794 int32_t CFX_ListCtrl::GetItemIndex(const CFX_FloatPoint& point) const { 634 int32_t CFX_ListCtrl::GetItemIndex(const CFX_FloatPoint& point) const {
795 return CFX_List::GetItemIndex(OutToIn(point)); 635 CFX_FloatPoint pt = OuterToInner(OutToIn(point));
636
637 FX_BOOL bFirst = TRUE;
638 FX_BOOL bLast = TRUE;
639
640 for (int32_t i = 0, sz = m_aListItems.GetSize(); i < sz; i++) {
641 if (CFX_ListItem* pListItem = m_aListItems.GetAt(i)) {
642 CLST_Rect rcListItem = pListItem->GetRect();
643
644 if (FX_EDIT_IsFloatBigger(pt.y, rcListItem.top)) {
645 bFirst = FALSE;
646 }
647
648 if (FX_EDIT_IsFloatSmaller(pt.y, rcListItem.bottom)) {
649 bLast = FALSE;
650 }
651
652 if (pt.y >= rcListItem.top && pt.y < rcListItem.bottom) {
653 return i;
654 }
655 }
656 }
657
658 if (bFirst)
659 return 0;
660 if (bLast)
661 return m_aListItems.GetSize() - 1;
662
663 return -1;
796 } 664 }
797 665
798 CFX_WideString CFX_ListCtrl::GetText() const { 666 CFX_WideString CFX_ListCtrl::GetText() const {
799 if (IsMultipleSel()) 667 if (IsMultipleSel())
800 return GetItemText(m_nCaretIndex); 668 return GetItemText(m_nCaretIndex);
801 return GetItemText(m_nSelItem); 669 return GetItemText(m_nSelItem);
802 } 670 }
671
672 void CFX_ListCtrl::SetFontMap(IPVT_FontMap* pFontMap) {
673 m_pFontMap = pFontMap;
674 }
675
676 void CFX_ListCtrl::SetFontSize(FX_FLOAT fFontSize) {
677 m_fFontSize = fFontSize;
678 }
679
680 void CFX_ListCtrl::AddItem(const FX_WCHAR* str) {
681 CFX_ListItem* pListItem = new CFX_ListItem();
682 pListItem->SetFontMap(m_pFontMap);
683 pListItem->SetFontSize(m_fFontSize);
684 pListItem->SetText(str);
685 m_aListItems.Add(pListItem);
686 }
687
688 CFX_Edit* CFX_ListCtrl::GetItemEdit(int32_t nIndex) const {
689 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nIndex)) {
690 return pListItem->GetEdit();
691 }
692
693 return nullptr;
694 }
695
696 int32_t CFX_ListCtrl::GetCount() const {
697 return m_aListItems.GetSize();
698 }
699
700 CFX_FloatRect CFX_ListCtrl::GetPlateRect() const {
701 return CFX_ListContainer::GetPlateRect();
702 }
703
704 FX_FLOAT CFX_ListCtrl::GetFontSize() const {
705 return m_fFontSize;
706 }
707
708 FX_FLOAT CFX_ListCtrl::GetFirstHeight() const {
709 if (CFX_ListItem* pListItem = m_aListItems.GetAt(0)) {
710 return pListItem->GetItemHeight();
711 }
712
713 return 1.0f;
714 }
715
716 int32_t CFX_ListCtrl::GetFirstSelected() const {
717 for (int32_t i = 0, sz = m_aListItems.GetSize(); i < sz; i++) {
718 if (CFX_ListItem* pListItem = m_aListItems.GetAt(i)) {
719 if (pListItem->IsSelected())
720 return i;
721 }
722 }
723 return -1;
724 }
725
726 int32_t CFX_ListCtrl::GetLastSelected() const {
727 for (int32_t i = m_aListItems.GetSize() - 1; i >= 0; i--) {
728 if (CFX_ListItem* pListItem = m_aListItems.GetAt(i)) {
729 if (pListItem->IsSelected())
730 return i;
731 }
732 }
733 return -1;
734 }
735
736 FX_WCHAR CFX_ListCtrl::Toupper(FX_WCHAR c) const {
737 if ((c >= 'a') && (c <= 'z'))
738 c = c - ('a' - 'A');
739 return c;
740 }
741
742 int32_t CFX_ListCtrl::FindNext(int32_t nIndex, FX_WCHAR nChar) const {
743 int32_t nCircleIndex = nIndex;
744
745 for (int32_t i = 0, sz = m_aListItems.GetSize(); i < sz; i++) {
746 nCircleIndex++;
747 if (nCircleIndex >= sz)
748 nCircleIndex = 0;
749
750 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nCircleIndex)) {
751 if (Toupper(pListItem->GetFirstChar()) == Toupper(nChar))
752 return nCircleIndex;
753 }
754 }
755
756 return nCircleIndex;
757 }
758
759 FX_BOOL CFX_ListCtrl::IsItemSelected(int32_t nIndex) const {
760 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nIndex))
761 return pListItem->IsSelected();
762 return FALSE;
763 }
764
765 void CFX_ListCtrl::SetItemSelect(int32_t nItemIndex, FX_BOOL bSelected) {
766 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nItemIndex)) {
767 pListItem->SetSelect(bSelected);
768 }
769 }
770
771 void CFX_ListCtrl::SetMultipleSel(FX_BOOL bMultiple) {
772 m_bMultiple = bMultiple;
773 }
774
775 FX_BOOL CFX_ListCtrl::IsMultipleSel() const {
776 return m_bMultiple;
777 }
778
779 FX_BOOL CFX_ListCtrl::IsValid(int32_t nItemIndex) const {
780 return nItemIndex >= 0 && nItemIndex < m_aListItems.GetSize();
781 }
782
783 CFX_WideString CFX_ListCtrl::GetItemText(int32_t nIndex) const {
784 if (CFX_ListItem* pListItem = m_aListItems.GetAt(nIndex)) {
785 return pListItem->GetText();
786 }
787
788 return L"";
789 }
OLDNEW
« no previous file with comments | « fpdfsdk/fxedit/fxet_edit.cpp ('k') | fpdfsdk/fxedit/fxet_module.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698