| 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/cfwl_listbox.h" | 7 #include "xfa/fwl/core/cfwl_listbox.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 void CFWL_ListBox::SetSelItem(CFWL_ListItem* pItem, bool bSelect) { | 189 void CFWL_ListBox::SetSelItem(CFWL_ListItem* pItem, bool bSelect) { |
| 190 if (!pItem) { | 190 if (!pItem) { |
| 191 if (bSelect) { | 191 if (bSelect) { |
| 192 SelectAll(); | 192 SelectAll(); |
| 193 } else { | 193 } else { |
| 194 ClearSelection(); | 194 ClearSelection(); |
| 195 SetFocusItem(nullptr); | 195 SetFocusItem(nullptr); |
| 196 } | 196 } |
| 197 return; | 197 return; |
| 198 } | 198 } |
| 199 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) | 199 if (IsMultiSelection()) |
| 200 SetSelectionDirect(pItem, bSelect); | 200 SetSelectionDirect(pItem, bSelect); |
| 201 else | 201 else |
| 202 SetSelection(pItem, pItem, bSelect); | 202 SetSelection(pItem, pItem, bSelect); |
| 203 } | 203 } |
| 204 | 204 |
| 205 void CFWL_ListBox::GetDataProviderItemText(CFWL_ListItem* pItem, | 205 void CFWL_ListBox::GetDataProviderItemText(CFWL_ListItem* pItem, |
| 206 CFX_WideString& wsText) { | 206 CFX_WideString& wsText) { |
| 207 if (!pItem) | 207 if (!pItem) |
| 208 return; | 208 return; |
| 209 GetItemText(this, pItem, wsText); | 209 GetItemText(this, pItem, wsText); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 262 } |
| 263 } | 263 } |
| 264 | 264 |
| 265 void CFWL_ListBox::SetSelectionDirect(CFWL_ListItem* pItem, bool bSelect) { | 265 void CFWL_ListBox::SetSelectionDirect(CFWL_ListItem* pItem, bool bSelect) { |
| 266 uint32_t dwOldStyle = GetItemStyles(this, pItem); | 266 uint32_t dwOldStyle = GetItemStyles(this, pItem); |
| 267 bSelect ? dwOldStyle |= FWL_ITEMSTATE_LTB_Selected | 267 bSelect ? dwOldStyle |= FWL_ITEMSTATE_LTB_Selected |
| 268 : dwOldStyle &= ~FWL_ITEMSTATE_LTB_Selected; | 268 : dwOldStyle &= ~FWL_ITEMSTATE_LTB_Selected; |
| 269 SetItemStyles(this, pItem, dwOldStyle); | 269 SetItemStyles(this, pItem, dwOldStyle); |
| 270 } | 270 } |
| 271 | 271 |
| 272 bool CFWL_ListBox::IsMultiSelection() const { |
| 273 return m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection; |
| 274 } |
| 275 |
| 272 bool CFWL_ListBox::IsItemSelected(CFWL_ListItem* pItem) { | 276 bool CFWL_ListBox::IsItemSelected(CFWL_ListItem* pItem) { |
| 273 uint32_t dwState = GetItemStyles(this, pItem); | 277 uint32_t dwState = GetItemStyles(this, pItem); |
| 274 return (dwState & FWL_ITEMSTATE_LTB_Selected) != 0; | 278 return (dwState & FWL_ITEMSTATE_LTB_Selected) != 0; |
| 275 } | 279 } |
| 276 | 280 |
| 277 void CFWL_ListBox::ClearSelection() { | 281 void CFWL_ListBox::ClearSelection() { |
| 278 bool bMulti = m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection; | 282 bool bMulti = IsMultiSelection(); |
| 279 int32_t iCount = CountItems(this); | 283 int32_t iCount = CountItems(this); |
| 280 for (int32_t i = 0; i < iCount; i++) { | 284 for (int32_t i = 0; i < iCount; i++) { |
| 281 CFWL_ListItem* pItem = GetItem(this, i); | 285 CFWL_ListItem* pItem = GetItem(this, i); |
| 282 uint32_t dwState = GetItemStyles(this, pItem); | 286 uint32_t dwState = GetItemStyles(this, pItem); |
| 283 if (!(dwState & FWL_ITEMSTATE_LTB_Selected)) | 287 if (!(dwState & FWL_ITEMSTATE_LTB_Selected)) |
| 284 continue; | 288 continue; |
| 285 SetSelectionDirect(pItem, false); | 289 SetSelectionDirect(pItem, false); |
| 286 if (!bMulti) | 290 if (!bMulti) |
| 287 return; | 291 return; |
| 288 } | 292 } |
| 289 } | 293 } |
| 290 | 294 |
| 291 void CFWL_ListBox::SelectAll() { | 295 void CFWL_ListBox::SelectAll() { |
| 292 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection)) | 296 if (!IsMultiSelection()) |
| 293 return; | 297 return; |
| 294 | 298 |
| 295 int32_t iCount = CountItems(this); | 299 int32_t iCount = CountItems(this); |
| 296 if (iCount <= 0) | 300 if (iCount <= 0) |
| 297 return; | 301 return; |
| 298 | 302 |
| 299 CFWL_ListItem* pItemStart = GetItem(this, 0); | 303 CFWL_ListItem* pItemStart = GetItem(this, 0); |
| 300 CFWL_ListItem* pItemEnd = GetItem(this, iCount - 1); | 304 CFWL_ListItem* pItemEnd = GetItem(this, iCount - 1); |
| 301 SetSelection(pItemStart, pItemEnd, false); | 305 SetSelection(pItemStart, pItemEnd, false); |
| 302 } | 306 } |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 | 849 |
| 846 void CFWL_ListBox::OnLButtonDown(CFWL_MsgMouse* pMsg) { | 850 void CFWL_ListBox::OnLButtonDown(CFWL_MsgMouse* pMsg) { |
| 847 m_bLButtonDown = true; | 851 m_bLButtonDown = true; |
| 848 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) | 852 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) |
| 849 SetFocus(true); | 853 SetFocus(true); |
| 850 | 854 |
| 851 CFWL_ListItem* pItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | 855 CFWL_ListItem* pItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); |
| 852 if (!pItem) | 856 if (!pItem) |
| 853 return; | 857 return; |
| 854 | 858 |
| 855 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) { | 859 if (IsMultiSelection()) { |
| 856 if (pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl) { | 860 if (pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl) { |
| 857 bool bSelected = IsItemSelected(pItem); | 861 bool bSelected = IsItemSelected(pItem); |
| 858 SetSelectionDirect(pItem, !bSelected); | 862 SetSelectionDirect(pItem, !bSelected); |
| 859 m_hAnchor = pItem; | 863 m_hAnchor = pItem; |
| 860 } else if (pMsg->m_dwFlags & FWL_KEYFLAG_Shift) { | 864 } else if (pMsg->m_dwFlags & FWL_KEYFLAG_Shift) { |
| 861 if (m_hAnchor) | 865 if (m_hAnchor) |
| 862 SetSelection(m_hAnchor, pItem, true); | 866 SetSelection(m_hAnchor, pItem, true); |
| 863 else | 867 else |
| 864 SetSelectionDirect(pItem, true); | 868 SetSelectionDirect(pItem, true); |
| 865 } else { | 869 } else { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 } | 919 } |
| 916 default: | 920 default: |
| 917 break; | 921 break; |
| 918 } | 922 } |
| 919 } | 923 } |
| 920 | 924 |
| 921 void CFWL_ListBox::OnVK(CFWL_ListItem* pItem, bool bShift, bool bCtrl) { | 925 void CFWL_ListBox::OnVK(CFWL_ListItem* pItem, bool bShift, bool bCtrl) { |
| 922 if (!pItem) | 926 if (!pItem) |
| 923 return; | 927 return; |
| 924 | 928 |
| 925 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiSelection) { | 929 if (IsMultiSelection()) { |
| 926 if (bCtrl) { | 930 if (bCtrl) { |
| 927 // Do nothing. | 931 // Do nothing. |
| 928 } else if (bShift) { | 932 } else if (bShift) { |
| 929 if (m_hAnchor) | 933 if (m_hAnchor) |
| 930 SetSelection(m_hAnchor, pItem, true); | 934 SetSelection(m_hAnchor, pItem, true); |
| 931 else | 935 else |
| 932 SetSelectionDirect(pItem, true); | 936 SetSelectionDirect(pItem, true); |
| 933 } else { | 937 } else { |
| 934 SetSelection(pItem, pItem, true); | 938 SetSelection(pItem, pItem, true); |
| 935 m_hAnchor = pItem; | 939 m_hAnchor = pItem; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1124 void CFWL_ListBox::DeleteAll() { | 1128 void CFWL_ListBox::DeleteAll() { |
| 1125 m_ItemArray.clear(); | 1129 m_ItemArray.clear(); |
| 1126 } | 1130 } |
| 1127 | 1131 |
| 1128 uint32_t CFWL_ListBox::GetItemStates(CFWL_ListItem* pItem) { | 1132 uint32_t CFWL_ListBox::GetItemStates(CFWL_ListItem* pItem) { |
| 1129 if (!pItem) | 1133 if (!pItem) |
| 1130 return 0; | 1134 return 0; |
| 1131 return pItem->m_dwStates | pItem->m_dwCheckState; | 1135 return pItem->m_dwStates | pItem->m_dwCheckState; |
| 1132 } | 1136 } |
| 1133 | 1137 |
| OLD | NEW |