| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 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_combolist.h" | 7 #include "xfa/fwl/core/ifwl_combolist.h" |
| 8 | 8 |
| 9 #include "third_party/base/ptr_util.h" | 9 #include "third_party/base/ptr_util.h" |
| 10 #include "xfa/fwl/core/ifwl_combobox.h" | 10 #include "xfa/fwl/core/ifwl_combobox.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 int32_t IFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) { | 21 int32_t IFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) { |
| 22 if (wsMatch.IsEmpty()) { | 22 if (wsMatch.IsEmpty()) { |
| 23 return -1; | 23 return -1; |
| 24 } | 24 } |
| 25 if (!m_pProperties->m_pDataProvider) | 25 if (!m_pProperties->m_pDataProvider) |
| 26 return -1; | 26 return -1; |
| 27 IFWL_ListBoxDP* pData = | 27 IFWL_ListBoxDP* pData = |
| 28 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 28 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 29 int32_t iCount = pData->CountItems(this); | 29 int32_t iCount = pData->CountItems(this); |
| 30 for (int32_t i = 0; i < iCount; i++) { | 30 for (int32_t i = 0; i < iCount; i++) { |
| 31 IFWL_ListItem* hItem = pData->GetItem(this, i); | 31 CFWL_ListItem* hItem = pData->GetItem(this, i); |
| 32 CFX_WideString wsText; | 32 CFX_WideString wsText; |
| 33 pData->GetItemText(this, hItem, wsText); | 33 pData->GetItemText(this, hItem, wsText); |
| 34 FX_STRSIZE pos = wsText.Find(wsMatch.c_str()); | 34 FX_STRSIZE pos = wsText.Find(wsMatch.c_str()); |
| 35 if (!pos) { | 35 if (!pos) { |
| 36 return i; | 36 return i; |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 return -1; | 39 return -1; |
| 40 } | 40 } |
| 41 | 41 |
| 42 void IFWL_ComboList::ChangeSelected(int32_t iSel) { | 42 void IFWL_ComboList::ChangeSelected(int32_t iSel) { |
| 43 if (!m_pProperties->m_pDataProvider) | 43 if (!m_pProperties->m_pDataProvider) |
| 44 return; | 44 return; |
| 45 IFWL_ListBoxDP* pData = | 45 IFWL_ListBoxDP* pData = |
| 46 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 46 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 47 IFWL_ListItem* hItem = pData->GetItem(this, iSel); | 47 CFWL_ListItem* hItem = pData->GetItem(this, iSel); |
| 48 CFX_RectF rtInvalidate; | 48 CFX_RectF rtInvalidate; |
| 49 rtInvalidate.Reset(); | 49 rtInvalidate.Reset(); |
| 50 IFWL_ListItem* hOld = GetSelItem(0); | 50 CFWL_ListItem* hOld = GetSelItem(0); |
| 51 int32_t iOld = pData->GetItemIndex(this, hOld); | 51 int32_t iOld = pData->GetItemIndex(this, hOld); |
| 52 if (iOld == iSel) { | 52 if (iOld == iSel) { |
| 53 return; | 53 return; |
| 54 } else if (iOld > -1) { | 54 } else if (iOld > -1) { |
| 55 GetItemRect(iOld, rtInvalidate); | 55 GetItemRect(iOld, rtInvalidate); |
| 56 SetSelItem(hOld, false); | 56 SetSelItem(hOld, false); |
| 57 } | 57 } |
| 58 if (hItem) { | 58 if (hItem) { |
| 59 CFX_RectF rect; | 59 CFX_RectF rect; |
| 60 GetItemRect(iSel, rect); | 60 GetItemRect(iSel, rect); |
| 61 rtInvalidate.Union(rect); | 61 rtInvalidate.Union(rect); |
| 62 IFWL_ListItem* hSel = pData->GetItem(this, iSel); | 62 CFWL_ListItem* hSel = pData->GetItem(this, iSel); |
| 63 SetSelItem(hSel, true); | 63 SetSelItem(hSel, true); |
| 64 } | 64 } |
| 65 if (!rtInvalidate.IsEmpty()) { | 65 if (!rtInvalidate.IsEmpty()) { |
| 66 Repaint(&rtInvalidate); | 66 Repaint(&rtInvalidate); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 int32_t IFWL_ComboList::CountItems() { | 70 int32_t IFWL_ComboList::CountItems() { |
| 71 IFWL_ListBoxDP* pData = | 71 IFWL_ListBoxDP* pData = |
| 72 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 72 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 73 return pData ? pData->CountItems(this) : 0; | 73 return pData ? pData->CountItems(this) : 0; |
| 74 } | 74 } |
| 75 | 75 |
| 76 void IFWL_ComboList::GetItemRect(int32_t nIndex, CFX_RectF& rtItem) { | 76 void IFWL_ComboList::GetItemRect(int32_t nIndex, CFX_RectF& rtItem) { |
| 77 IFWL_ListBoxDP* pData = | 77 IFWL_ListBoxDP* pData = |
| 78 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 78 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 79 IFWL_ListItem* hItem = pData->GetItem(this, nIndex); | 79 CFWL_ListItem* hItem = pData->GetItem(this, nIndex); |
| 80 pData->GetItemRect(this, hItem, rtItem); | 80 pData->GetItemRect(this, hItem, rtItem); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void IFWL_ComboList::ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy) { | 83 void IFWL_ComboList::ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy) { |
| 84 fx += m_pProperties->m_rtWidget.left, fy += m_pProperties->m_rtWidget.top; | 84 fx += m_pProperties->m_rtWidget.left, fy += m_pProperties->m_rtWidget.top; |
| 85 IFWL_Widget* pOwner = GetOwner(); | 85 IFWL_Widget* pOwner = GetOwner(); |
| 86 if (!pOwner) | 86 if (!pOwner) |
| 87 return; | 87 return; |
| 88 pOwner->TransformTo(m_pOuter, fx, fy); | 88 pOwner->TransformTo(m_pOuter, fx, fy); |
| 89 } | 89 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 if (m_bNotifyOwner) { | 156 if (m_bNotifyOwner) { |
| 157 m_bNotifyOwner = false; | 157 m_bNotifyOwner = false; |
| 158 } | 158 } |
| 159 if (IsShowScrollBar(true) && m_pVertScrollBar) { | 159 if (IsShowScrollBar(true) && m_pVertScrollBar) { |
| 160 CFX_RectF rect; | 160 CFX_RectF rect; |
| 161 m_pVertScrollBar->GetWidgetRect(rect); | 161 m_pVertScrollBar->GetWidgetRect(rect); |
| 162 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { | 162 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 163 return 1; | 163 return 1; |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 IFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | 166 CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); |
| 167 if (hItem) { | 167 if (hItem) { |
| 168 if (!m_pProperties->m_pDataProvider) | 168 if (!m_pProperties->m_pDataProvider) |
| 169 return 0; | 169 return 0; |
| 170 IFWL_ListBoxDP* pData = | 170 IFWL_ListBoxDP* pData = |
| 171 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 171 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 172 int32_t iSel = pData->GetItemIndex(this, hItem); | 172 int32_t iSel = pData->GetItemIndex(this, hItem); |
| 173 CFWL_EvtCmbHoverChanged event; | 173 CFWL_EvtCmbHoverChanged event; |
| 174 event.m_pSrcTarget = m_pOuter; | 174 event.m_pSrcTarget = m_pOuter; |
| 175 event.m_iCurHover = iSel; | 175 event.m_iCurHover = iSel; |
| 176 DispatchEvent(&event); | 176 DispatchEvent(&event); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 200 pOuter->GetDelegate()->OnProcessMessage(pMsg); | 200 pOuter->GetDelegate()->OnProcessMessage(pMsg); |
| 201 } else { | 201 } else { |
| 202 if (IsShowScrollBar(true) && m_pVertScrollBar) { | 202 if (IsShowScrollBar(true) && m_pVertScrollBar) { |
| 203 CFX_RectF rect; | 203 CFX_RectF rect; |
| 204 m_pVertScrollBar->GetWidgetRect(rect); | 204 m_pVertScrollBar->GetWidgetRect(rect); |
| 205 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { | 205 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 206 return 1; | 206 return 1; |
| 207 } | 207 } |
| 208 } | 208 } |
| 209 pOuter->ShowDropList(false); | 209 pOuter->ShowDropList(false); |
| 210 IFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | 210 CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); |
| 211 if (hItem) | 211 if (hItem) |
| 212 pOuter->ProcessSelChanged(true); | 212 pOuter->ProcessSelChanged(true); |
| 213 } | 213 } |
| 214 return 1; | 214 return 1; |
| 215 } | 215 } |
| 216 | 216 |
| 217 int32_t IFWL_ComboList::OnDropListKey(CFWL_MsgKey* pKey) { | 217 int32_t IFWL_ComboList::OnDropListKey(CFWL_MsgKey* pKey) { |
| 218 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 218 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
| 219 bool bPropagate = false; | 219 bool bPropagate = false; |
| 220 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { | 220 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 247 void IFWL_ComboList::OnDropListKeyDown(CFWL_MsgKey* pKey) { | 247 void IFWL_ComboList::OnDropListKeyDown(CFWL_MsgKey* pKey) { |
| 248 uint32_t dwKeyCode = pKey->m_dwKeyCode; | 248 uint32_t dwKeyCode = pKey->m_dwKeyCode; |
| 249 switch (dwKeyCode) { | 249 switch (dwKeyCode) { |
| 250 case FWL_VKEY_Up: | 250 case FWL_VKEY_Up: |
| 251 case FWL_VKEY_Down: | 251 case FWL_VKEY_Down: |
| 252 case FWL_VKEY_Home: | 252 case FWL_VKEY_Home: |
| 253 case FWL_VKEY_End: { | 253 case FWL_VKEY_End: { |
| 254 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 254 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
| 255 IFWL_ListBoxDP* pData = | 255 IFWL_ListBoxDP* pData = |
| 256 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 256 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); |
| 257 IFWL_ListItem* hItem = | 257 CFWL_ListItem* hItem = |
| 258 pData->GetItem(this, pOuter->GetCurrentSelection()); | 258 pData->GetItem(this, pOuter->GetCurrentSelection()); |
| 259 hItem = GetItem(hItem, dwKeyCode); | 259 hItem = GetItem(hItem, dwKeyCode); |
| 260 if (!hItem) { | 260 if (!hItem) { |
| 261 break; | 261 break; |
| 262 } | 262 } |
| 263 SetSelection(hItem, hItem, true); | 263 SetSelection(hItem, hItem, true); |
| 264 ScrollToVisible(hItem); | 264 ScrollToVisible(hItem); |
| 265 CFX_RectF rtInvalidate; | 265 CFX_RectF rtInvalidate; |
| 266 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, | 266 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, |
| 267 m_pProperties->m_rtWidget.height); | 267 m_pProperties->m_rtWidget.height); |
| 268 Repaint(&rtInvalidate); | 268 Repaint(&rtInvalidate); |
| 269 break; | 269 break; |
| 270 } | 270 } |
| 271 default: | 271 default: |
| 272 break; | 272 break; |
| 273 } | 273 } |
| 274 } | 274 } |
| OLD | NEW |