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 "xfa/fwl/core/ifwl_listbox.h" | 7 #include "xfa/fwl/core/ifwl_listbox.h" |
8 | 8 |
9 #include "third_party/base/ptr_util.h" | 9 #include "third_party/base/ptr_util.h" |
10 #include "xfa/fde/tto/fde_textout.h" | 10 #include "xfa/fde/tto/fde_textout.h" |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 if (index == nIndex) { | 199 if (index == nIndex) { |
200 return i; | 200 return i; |
201 } else { | 201 } else { |
202 index++; | 202 index++; |
203 } | 203 } |
204 } | 204 } |
205 } | 205 } |
206 return -1; | 206 return -1; |
207 } | 207 } |
208 | 208 |
209 FWL_Error IFWL_ListBox::SetSelItem(CFWL_ListItem* pItem, bool bSelect) { | 209 void IFWL_ListBox::SetSelItem(CFWL_ListItem* pItem, bool bSelect) { |
210 if (!m_pProperties->m_pDataProvider) | 210 if (!m_pProperties->m_pDataProvider) |
211 return FWL_Error::Indefinite; | 211 return; |
212 if (!pItem) { | 212 if (!pItem) { |
213 if (bSelect) { | 213 if (bSelect) { |
214 SelectAll(); | 214 SelectAll(); |
215 } else { | 215 } else { |
216 ClearSelection(); | 216 ClearSelection(); |
217 SetFocusItem(nullptr); | 217 SetFocusItem(nullptr); |
218 } | 218 } |
219 return FWL_Error::Indefinite; | 219 return; |
220 } | 220 } |
221 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) { | 221 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) { |
222 SetSelectionDirect(pItem, bSelect); | 222 SetSelectionDirect(pItem, bSelect); |
223 } else { | 223 } else { |
224 SetSelection(pItem, pItem, bSelect); | 224 SetSelection(pItem, pItem, bSelect); |
225 } | 225 } |
226 return FWL_Error::Succeeded; | |
227 } | 226 } |
228 | 227 |
229 FWL_Error IFWL_ListBox::GetItemText(CFWL_ListItem* pItem, | 228 void IFWL_ListBox::GetItemText(CFWL_ListItem* pItem, CFX_WideString& wsText) { |
230 CFX_WideString& wsText) { | |
231 if (!m_pProperties->m_pDataProvider) | 229 if (!m_pProperties->m_pDataProvider) |
232 return FWL_Error::Indefinite; | 230 return; |
233 IFWL_ListBoxDP* pData = | 231 IFWL_ListBoxDP* pData = |
234 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 232 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
235 if (!pItem) | 233 if (!pItem) |
236 return FWL_Error::Indefinite; | 234 return; |
237 pData->GetItemText(this, pItem, wsText); | 235 pData->GetItemText(this, pItem, wsText); |
238 return FWL_Error::Succeeded; | |
239 } | 236 } |
240 | 237 |
241 FWL_Error IFWL_ListBox::GetScrollPos(FX_FLOAT& fPos, bool bVert) { | 238 void IFWL_ListBox::GetScrollPos(FX_FLOAT& fPos, bool bVert) { |
242 if ((bVert && IsShowScrollBar(true)) || (!bVert && IsShowScrollBar(false))) { | 239 if ((bVert && IsShowScrollBar(true)) || (!bVert && IsShowScrollBar(false))) { |
243 IFWL_ScrollBar* pScrollBar = | 240 IFWL_ScrollBar* pScrollBar = |
244 bVert ? m_pVertScrollBar.get() : m_pHorzScrollBar.get(); | 241 bVert ? m_pVertScrollBar.get() : m_pHorzScrollBar.get(); |
245 fPos = pScrollBar->GetPos(); | 242 fPos = pScrollBar->GetPos(); |
246 return FWL_Error::Succeeded; | |
247 } | 243 } |
248 return FWL_Error::Indefinite; | |
249 } | 244 } |
250 | 245 |
251 CFWL_ListItem* IFWL_ListBox::GetItem(CFWL_ListItem* pItem, uint32_t dwKeyCode) { | 246 CFWL_ListItem* IFWL_ListBox::GetItem(CFWL_ListItem* pItem, uint32_t dwKeyCode) { |
252 CFWL_ListItem* hRet = nullptr; | 247 CFWL_ListItem* hRet = nullptr; |
253 switch (dwKeyCode) { | 248 switch (dwKeyCode) { |
254 case FWL_VKEY_Up: | 249 case FWL_VKEY_Up: |
255 case FWL_VKEY_Down: | 250 case FWL_VKEY_Down: |
256 case FWL_VKEY_Home: | 251 case FWL_VKEY_Home: |
257 case FWL_VKEY_End: { | 252 case FWL_VKEY_End: { |
258 const bool bUp = dwKeyCode == FWL_VKEY_Up; | 253 const bool bUp = dwKeyCode == FWL_VKEY_Up; |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 fWidth += 2 * kItemTextMargin; | 687 fWidth += 2 * kItemTextMargin; |
693 if (!bAutoSize) { | 688 if (!bAutoSize) { |
694 FX_FLOAT fActualWidth = | 689 FX_FLOAT fActualWidth = |
695 m_rtClient.width - rtUIMargin.left - rtUIMargin.width; | 690 m_rtClient.width - rtUIMargin.left - rtUIMargin.width; |
696 if (fWidth < fActualWidth) { | 691 if (fWidth < fActualWidth) { |
697 fWidth = fActualWidth; | 692 fWidth = fActualWidth; |
698 } | 693 } |
699 } | 694 } |
700 IFWL_ListBoxDP* pData = | 695 IFWL_ListBoxDP* pData = |
701 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 696 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
702 m_fItemHeight = GetItemHeigt(); | 697 m_fItemHeight = CalcItemHeight(); |
703 if ((GetStylesEx() & FWL_STYLEEXT_LTB_Icon)) | 698 if ((GetStylesEx() & FWL_STYLEEXT_LTB_Icon)) |
704 fWidth += m_fItemHeight; | 699 fWidth += m_fItemHeight; |
705 | 700 |
706 int32_t iCount = pData->CountItems(this); | 701 int32_t iCount = pData->CountItems(this); |
707 for (int32_t i = 0; i < iCount; i++) { | 702 for (int32_t i = 0; i < iCount; i++) { |
708 CFWL_ListItem* htem = pData->GetItem(this, i); | 703 CFWL_ListItem* htem = pData->GetItem(this, i); |
709 GetItemSize(fs, htem, fWidth, m_fItemHeight, bAutoSize); | 704 GetItemSize(fs, htem, fWidth, m_fItemHeight, bAutoSize); |
710 } | 705 } |
711 } | 706 } |
712 if (bAutoSize) { | 707 if (bAutoSize) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 } | 844 } |
850 | 845 |
851 FX_FLOAT IFWL_ListBox::GetScrollWidth() { | 846 FX_FLOAT IFWL_ListBox::GetScrollWidth() { |
852 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( | 847 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( |
853 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 848 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
854 if (!pfWidth) | 849 if (!pfWidth) |
855 return 0; | 850 return 0; |
856 return *pfWidth; | 851 return *pfWidth; |
857 } | 852 } |
858 | 853 |
859 FX_FLOAT IFWL_ListBox::GetItemHeigt() { | 854 FX_FLOAT IFWL_ListBox::CalcItemHeight() { |
860 FX_FLOAT* pfFont = | 855 FX_FLOAT* pfFont = |
861 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::FontSize)); | 856 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::FontSize)); |
862 if (!pfFont) | 857 if (!pfFont) |
863 return 20; | 858 return 20; |
864 return *pfFont + 2 * kItemTextMargin; | 859 return *pfFont + 2 * kItemTextMargin; |
865 } | 860 } |
866 | 861 |
867 void IFWL_ListBox::InitScrollBar(bool bVert) { | 862 void IFWL_ListBox::InitScrollBar(bool bVert) { |
868 if ((bVert && m_pVertScrollBar) || (!bVert && m_pHorzScrollBar)) { | 863 if ((bVert && m_pVertScrollBar) || (!bVert && m_pHorzScrollBar)) { |
869 return; | 864 return; |
870 } | 865 } |
871 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); | 866 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); |
872 prop->m_dwStyleExes = bVert ? FWL_STYLEEXT_SCB_Vert : FWL_STYLEEXT_SCB_Horz; | 867 prop->m_dwStyleExes = bVert ? FWL_STYLEEXT_SCB_Vert : FWL_STYLEEXT_SCB_Horz; |
873 prop->m_dwStates = FWL_WGTSTATE_Invisible; | 868 prop->m_dwStates = FWL_WGTSTATE_Invisible; |
874 prop->m_pParent = this; | 869 prop->m_pParent = this; |
875 prop->m_pThemeProvider = m_pScrollBarTP; | 870 prop->m_pThemeProvider = m_pScrollBarTP; |
876 (bVert ? &m_pVertScrollBar : &m_pHorzScrollBar) | 871 IFWL_ScrollBar* sb = new IFWL_ScrollBar(m_pOwnerApp, std::move(prop), this); |
877 ->reset(new IFWL_ScrollBar(m_pOwnerApp, std::move(prop), this)); | 872 if (bVert) |
| 873 m_pVertScrollBar.reset(sb); |
| 874 else |
| 875 m_pHorzScrollBar.reset(sb); |
878 } | 876 } |
879 | 877 |
880 bool IFWL_ListBox::IsShowScrollBar(bool bVert) { | 878 bool IFWL_ListBox::IsShowScrollBar(bool bVert) { |
881 IFWL_ScrollBar* pScrollbar = | 879 IFWL_ScrollBar* pScrollbar = |
882 bVert ? m_pVertScrollBar.get() : m_pHorzScrollBar.get(); | 880 bVert ? m_pVertScrollBar.get() : m_pHorzScrollBar.get(); |
883 if (!pScrollbar || (pScrollbar->GetStates() & FWL_WGTSTATE_Invisible)) { | 881 if (!pScrollbar || (pScrollbar->GetStates() & FWL_WGTSTATE_Invisible)) { |
884 return false; | 882 return false; |
885 } | 883 } |
886 return !(m_pProperties->m_dwStyleExes & | 884 return !(m_pProperties->m_dwStyleExes & |
887 FWL_STYLEEXT_LTB_ShowScrollBarFocus) || | 885 FWL_STYLEEXT_LTB_ShowScrollBarFocus) || |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 Repaint(&m_rtClient); | 1139 Repaint(&m_rtClient); |
1142 } | 1140 } |
1143 return true; | 1141 return true; |
1144 } | 1142 } |
1145 | 1143 |
1146 void IFWL_ListBox::DispatchSelChangedEv() { | 1144 void IFWL_ListBox::DispatchSelChangedEv() { |
1147 CFWL_EvtLtbSelChanged ev; | 1145 CFWL_EvtLtbSelChanged ev; |
1148 ev.m_pSrcTarget = this; | 1146 ev.m_pSrcTarget = this; |
1149 DispatchEvent(&ev); | 1147 DispatchEvent(&ev); |
1150 } | 1148 } |
OLD | NEW |