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 "fpdfsdk/pdfwindow/PWL_ListBox.h" | 7 #include "fpdfsdk/pdfwindow/PWL_ListBox.h" |
8 | 8 |
| 9 #include "fpdfsdk/fxedit/include/fxet_edit.h" |
| 10 #include "fpdfsdk/fxedit/include/fxet_list.h" |
9 #include "fpdfsdk/pdfwindow/PWL_Edit.h" | 11 #include "fpdfsdk/pdfwindow/PWL_Edit.h" |
10 #include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" | 12 #include "fpdfsdk/pdfwindow/PWL_EditCtrl.h" |
11 #include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" | 13 #include "fpdfsdk/pdfwindow/PWL_ScrollBar.h" |
12 #include "fpdfsdk/pdfwindow/PWL_Utils.h" | 14 #include "fpdfsdk/pdfwindow/PWL_Utils.h" |
13 #include "fpdfsdk/pdfwindow/PWL_Wnd.h" | 15 #include "fpdfsdk/pdfwindow/PWL_Wnd.h" |
14 #include "public/fpdf_fwlevent.h" | 16 #include "public/fpdf_fwlevent.h" |
15 | 17 |
16 #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001) | 18 #define IsFloatZero(f) ((f) < 0.0001 && (f) > -0.0001) |
17 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) | 19 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) |
18 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) | 20 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 60 |
59 void CPWL_List_Notify::IOnSetScrollPosY(FX_FLOAT fy) { | 61 void CPWL_List_Notify::IOnSetScrollPosY(FX_FLOAT fy) { |
60 m_pList->OnNotify(m_pList, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy); | 62 m_pList->OnNotify(m_pList, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy); |
61 } | 63 } |
62 | 64 |
63 void CPWL_List_Notify::IOnInvalidateRect(CFX_FloatRect* pRect) { | 65 void CPWL_List_Notify::IOnInvalidateRect(CFX_FloatRect* pRect) { |
64 m_pList->InvalidateRect(pRect); | 66 m_pList->InvalidateRect(pRect); |
65 } | 67 } |
66 | 68 |
67 CPWL_ListBox::CPWL_ListBox() | 69 CPWL_ListBox::CPWL_ListBox() |
68 : m_pList(nullptr), | 70 : m_pList(new CFX_ListCtrl), |
69 m_pListNotify(nullptr), | |
70 m_bMouseDown(FALSE), | 71 m_bMouseDown(FALSE), |
71 m_bHoverSel(FALSE), | 72 m_bHoverSel(FALSE), |
72 m_pFillerNotify(nullptr) { | 73 m_pFillerNotify(nullptr) {} |
73 m_pList = IFX_List::NewList(); | |
74 } | |
75 | 74 |
76 CPWL_ListBox::~CPWL_ListBox() { | 75 CPWL_ListBox::~CPWL_ListBox() { |
77 IFX_List::DelList(m_pList); | |
78 delete m_pListNotify; | |
79 m_pListNotify = nullptr; | |
80 } | 76 } |
81 | 77 |
82 CFX_ByteString CPWL_ListBox::GetClassName() const { | 78 CFX_ByteString CPWL_ListBox::GetClassName() const { |
83 return "CPWL_ListBox"; | 79 return "CPWL_ListBox"; |
84 } | 80 } |
85 | 81 |
86 void CPWL_ListBox::OnCreated() { | 82 void CPWL_ListBox::OnCreated() { |
87 if (m_pList) { | 83 if (m_pList) { |
88 delete m_pListNotify; | |
89 | |
90 m_pList->SetFontMap(GetFontMap()); | 84 m_pList->SetFontMap(GetFontMap()); |
91 m_pList->SetNotify(m_pListNotify = new CPWL_List_Notify(this)); | 85 m_pListNotify.reset(new CPWL_List_Notify(this)); |
| 86 m_pList->SetNotify(m_pListNotify.get()); |
92 | 87 |
93 SetHoverSel(HasFlag(PLBS_HOVERSEL)); | 88 SetHoverSel(HasFlag(PLBS_HOVERSEL)); |
94 m_pList->SetMultipleSel(HasFlag(PLBS_MULTIPLESEL)); | 89 m_pList->SetMultipleSel(HasFlag(PLBS_MULTIPLESEL)); |
95 m_pList->SetFontSize(GetCreationParam().fFontSize); | 90 m_pList->SetFontSize(GetCreationParam().fFontSize); |
96 | 91 |
97 m_bHoverSel = HasFlag(PLBS_HOVERSEL); | 92 m_bHoverSel = HasFlag(PLBS_HOVERSEL); |
98 } | 93 } |
99 } | 94 } |
100 | 95 |
101 void CPWL_ListBox::OnDestroy() { | 96 void CPWL_ListBox::OnDestroy() { |
102 delete m_pListNotify; | 97 m_pListNotify.reset(); |
103 m_pListNotify = nullptr; | |
104 } | 98 } |
105 | 99 |
106 void CPWL_ListBox::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { | 100 void CPWL_ListBox::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
107 CPWL_Wnd::GetThisAppearanceStream(sAppStream); | 101 CPWL_Wnd::GetThisAppearanceStream(sAppStream); |
108 | 102 |
109 CFX_ByteTextBuf sListItems; | 103 CFX_ByteTextBuf sListItems; |
110 | 104 |
111 if (m_pList) { | 105 if (m_pList) { |
112 CFX_FloatRect rcPlate = m_pList->GetPlateRect(); | 106 CFX_FloatRect rcPlate = m_pList->GetPlateRect(); |
113 for (int32_t i = 0, sz = m_pList->GetCount(); i < sz; i++) { | 107 for (int32_t i = 0, sz = m_pList->GetCount(); i < sz; i++) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 CFX_FloatRect rcPlate = m_pList->GetPlateRect(); | 159 CFX_FloatRect rcPlate = m_pList->GetPlateRect(); |
166 CFX_FloatRect rcList = GetListRect(); | 160 CFX_FloatRect rcList = GetListRect(); |
167 CFX_FloatRect rcClient = GetClientRect(); | 161 CFX_FloatRect rcClient = GetClientRect(); |
168 | 162 |
169 for (int32_t i = 0, sz = m_pList->GetCount(); i < sz; i++) { | 163 for (int32_t i = 0, sz = m_pList->GetCount(); i < sz; i++) { |
170 CFX_FloatRect rcItem = m_pList->GetItemRect(i); | 164 CFX_FloatRect rcItem = m_pList->GetItemRect(i); |
171 if (rcItem.bottom > rcPlate.top || rcItem.top < rcPlate.bottom) | 165 if (rcItem.bottom > rcPlate.top || rcItem.top < rcPlate.bottom) |
172 continue; | 166 continue; |
173 | 167 |
174 CFX_FloatPoint ptOffset(rcItem.left, (rcItem.top + rcItem.bottom) * 0.5f); | 168 CFX_FloatPoint ptOffset(rcItem.left, (rcItem.top + rcItem.bottom) * 0.5f); |
175 if (IFX_Edit* pEdit = m_pList->GetItemEdit(i)) { | 169 if (CFX_Edit* pEdit = m_pList->GetItemEdit(i)) { |
176 CFX_FloatRect rcContent = pEdit->GetContentRect(); | 170 CFX_FloatRect rcContent = pEdit->GetContentRect(); |
177 if (rcContent.Width() > rcClient.Width()) | 171 if (rcContent.Width() > rcClient.Width()) |
178 rcItem.Intersect(rcList); | 172 rcItem.Intersect(rcList); |
179 else | 173 else |
180 rcItem.Intersect(rcClient); | 174 rcItem.Intersect(rcClient); |
181 } | 175 } |
182 | 176 |
183 if (m_pList->IsItemSelected(i)) { | 177 if (m_pList->IsItemSelected(i)) { |
184 CFX_SystemHandler* pSysHandler = GetSystemHandler(); | 178 CFX_SystemHandler* pSysHandler = GetSystemHandler(); |
185 if (pSysHandler && pSysHandler->IsSelectionImplemented()) { | 179 if (pSysHandler && pSysHandler->IsSelectionImplemented()) { |
186 IFX_Edit::DrawEdit( | 180 CFX_Edit::DrawEdit( |
187 pDevice, pUser2Device, m_pList->GetItemEdit(i), | 181 pDevice, pUser2Device, m_pList->GetItemEdit(i), |
188 CPWL_Utils::PWLColorToFXColor(GetTextColor()), | 182 CPWL_Utils::PWLColorToFXColor(GetTextColor()), |
189 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor()), rcList, | 183 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor()), rcList, |
190 ptOffset, nullptr, pSysHandler, m_pFormFiller); | 184 ptOffset, nullptr, pSysHandler, m_pFormFiller); |
191 pSysHandler->OutputSelectedRect(m_pFormFiller, rcItem); | 185 pSysHandler->OutputSelectedRect(m_pFormFiller, rcItem); |
192 } else { | 186 } else { |
193 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcItem, | 187 CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcItem, |
194 ArgbEncode(255, 0, 51, 113)); | 188 ArgbEncode(255, 0, 51, 113)); |
195 IFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i), | 189 CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i), |
196 ArgbEncode(255, 255, 255, 255), 0, rcList, | 190 ArgbEncode(255, 255, 255, 255), 0, rcList, |
197 ptOffset, nullptr, pSysHandler, m_pFormFiller); | 191 ptOffset, nullptr, pSysHandler, m_pFormFiller); |
198 } | 192 } |
199 } else { | 193 } else { |
200 CFX_SystemHandler* pSysHandler = GetSystemHandler(); | 194 CFX_SystemHandler* pSysHandler = GetSystemHandler(); |
201 IFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i), | 195 CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i), |
202 CPWL_Utils::PWLColorToFXColor(GetTextColor()), | 196 CPWL_Utils::PWLColorToFXColor(GetTextColor()), |
203 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor()), | 197 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor()), |
204 rcList, ptOffset, nullptr, pSysHandler, nullptr); | 198 rcList, ptOffset, nullptr, pSysHandler, nullptr); |
205 } | 199 } |
206 } | 200 } |
207 } | 201 } |
208 } | 202 } |
209 | 203 |
210 FX_BOOL CPWL_ListBox::OnKeyDown(uint16_t nChar, uint32_t nFlag) { | 204 FX_BOOL CPWL_ListBox::OnKeyDown(uint16_t nChar, uint32_t nFlag) { |
211 CPWL_Wnd::OnKeyDown(nChar, nFlag); | 205 CPWL_Wnd::OnKeyDown(nChar, nFlag); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 if (zDelta < 0) { | 522 if (zDelta < 0) { |
529 m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); | 523 m_pList->OnVK_DOWN(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
530 } else { | 524 } else { |
531 m_pList->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); | 525 m_pList->OnVK_UP(IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
532 } | 526 } |
533 | 527 |
534 FX_BOOL bExit = FALSE; | 528 FX_BOOL bExit = FALSE; |
535 OnNotifySelChanged(FALSE, bExit, nFlag); | 529 OnNotifySelChanged(FALSE, bExit, nFlag); |
536 return TRUE; | 530 return TRUE; |
537 } | 531 } |
OLD | NEW |