| 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/cfwl_msgkey.h" | 10 #include "xfa/fwl/core/cfwl_msgkey.h" |
| 11 #include "xfa/fwl/core/cfwl_msgkillfocus.h" | 11 #include "xfa/fwl/core/cfwl_msgkillfocus.h" |
| 12 #include "xfa/fwl/core/cfwl_msgmouse.h" | 12 #include "xfa/fwl/core/cfwl_msgmouse.h" |
| 13 #include "xfa/fwl/core/ifwl_combobox.h" | 13 #include "xfa/fwl/core/ifwl_combobox.h" |
| 14 #include "xfa/fwl/core/ifwl_comboedit.h" | 14 #include "xfa/fwl/core/ifwl_comboedit.h" |
| 15 #include "xfa/fwl/core/ifwl_listbox.h" |
| 15 | 16 |
| 16 IFWL_ComboList::IFWL_ComboList( | 17 IFWL_ComboList::IFWL_ComboList( |
| 17 const IFWL_App* app, | 18 const IFWL_App* app, |
| 18 std::unique_ptr<CFWL_WidgetProperties> properties, | 19 std::unique_ptr<CFWL_WidgetProperties> properties, |
| 19 IFWL_Widget* pOuter) | 20 IFWL_Widget* pOuter) |
| 20 : IFWL_ListBox(app, std::move(properties), pOuter), m_bNotifyOwner(true) { | 21 : IFWL_ListBox(app, std::move(properties), pOuter), m_bNotifyOwner(true) { |
| 21 ASSERT(pOuter); | 22 ASSERT(pOuter); |
| 22 } | 23 } |
| 23 | 24 |
| 24 int32_t IFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) { | 25 int32_t IFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) { |
| 25 if (wsMatch.IsEmpty()) | 26 if (wsMatch.IsEmpty()) |
| 26 return -1; | 27 return -1; |
| 27 if (!m_pProperties->m_pDataProvider) | 28 if (!m_pProperties->m_pDataProvider) |
| 28 return -1; | 29 return -1; |
| 29 | 30 |
| 30 IFWL_ListBoxDP* pData = | 31 IFWL_ListBox::DataProvider* pData = |
| 31 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 32 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 32 int32_t iCount = pData->CountItems(this); | 33 int32_t iCount = pData->CountItems(this); |
| 33 for (int32_t i = 0; i < iCount; i++) { | 34 for (int32_t i = 0; i < iCount; i++) { |
| 34 CFWL_ListItem* hItem = pData->GetItem(this, i); | 35 CFWL_ListItem* hItem = pData->GetItem(this, i); |
| 35 CFX_WideString wsText; | 36 CFX_WideString wsText; |
| 36 pData->GetItemText(this, hItem, wsText); | 37 pData->GetItemText(this, hItem, wsText); |
| 37 FX_STRSIZE pos = wsText.Find(wsMatch.c_str()); | 38 FX_STRSIZE pos = wsText.Find(wsMatch.c_str()); |
| 38 if (!pos) | 39 if (!pos) |
| 39 return i; | 40 return i; |
| 40 } | 41 } |
| 41 return -1; | 42 return -1; |
| 42 } | 43 } |
| 43 | 44 |
| 44 void IFWL_ComboList::ChangeSelected(int32_t iSel) { | 45 void IFWL_ComboList::ChangeSelected(int32_t iSel) { |
| 45 if (!m_pProperties->m_pDataProvider) | 46 if (!m_pProperties->m_pDataProvider) |
| 46 return; | 47 return; |
| 47 | 48 |
| 48 IFWL_ListBoxDP* pData = | 49 IFWL_ListBox::DataProvider* pData = |
| 49 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 50 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 50 CFWL_ListItem* hItem = pData->GetItem(this, iSel); | 51 CFWL_ListItem* hItem = pData->GetItem(this, iSel); |
| 51 CFX_RectF rtInvalidate; | 52 CFX_RectF rtInvalidate; |
| 52 rtInvalidate.Reset(); | 53 rtInvalidate.Reset(); |
| 53 CFWL_ListItem* hOld = GetSelItem(0); | 54 CFWL_ListItem* hOld = GetSelItem(0); |
| 54 int32_t iOld = pData->GetItemIndex(this, hOld); | 55 int32_t iOld = pData->GetItemIndex(this, hOld); |
| 55 if (iOld == iSel) | 56 if (iOld == iSel) |
| 56 return; | 57 return; |
| 57 if (iOld > -1) { | 58 if (iOld > -1) { |
| 58 GetItemRect(iOld, rtInvalidate); | 59 GetItemRect(iOld, rtInvalidate); |
| 59 SetSelItem(hOld, false); | 60 SetSelItem(hOld, false); |
| 60 } | 61 } |
| 61 if (hItem) { | 62 if (hItem) { |
| 62 CFX_RectF rect; | 63 CFX_RectF rect; |
| 63 GetItemRect(iSel, rect); | 64 GetItemRect(iSel, rect); |
| 64 rtInvalidate.Union(rect); | 65 rtInvalidate.Union(rect); |
| 65 CFWL_ListItem* hSel = pData->GetItem(this, iSel); | 66 CFWL_ListItem* hSel = pData->GetItem(this, iSel); |
| 66 SetSelItem(hSel, true); | 67 SetSelItem(hSel, true); |
| 67 } | 68 } |
| 68 if (!rtInvalidate.IsEmpty()) | 69 if (!rtInvalidate.IsEmpty()) |
| 69 Repaint(&rtInvalidate); | 70 Repaint(&rtInvalidate); |
| 70 } | 71 } |
| 71 | 72 |
| 72 int32_t IFWL_ComboList::CountItems() { | 73 int32_t IFWL_ComboList::CountItems() { |
| 73 IFWL_ListBoxDP* pData = | 74 IFWL_ListBox::DataProvider* pData = |
| 74 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 75 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 75 return pData ? pData->CountItems(this) : 0; | 76 return pData ? pData->CountItems(this) : 0; |
| 76 } | 77 } |
| 77 | 78 |
| 78 void IFWL_ComboList::GetItemRect(int32_t nIndex, CFX_RectF& rtItem) { | 79 void IFWL_ComboList::GetItemRect(int32_t nIndex, CFX_RectF& rtItem) { |
| 79 IFWL_ListBoxDP* pData = | 80 IFWL_ListBox::DataProvider* pData = |
| 80 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 81 static_cast<IFWL_ListBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 81 CFWL_ListItem* hItem = pData->GetItem(this, nIndex); | 82 CFWL_ListItem* hItem = pData->GetItem(this, nIndex); |
| 82 pData->GetItemRect(this, hItem, rtItem); | 83 pData->GetItemRect(this, hItem, rtItem); |
| 83 } | 84 } |
| 84 | 85 |
| 85 void IFWL_ComboList::ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy) { | 86 void IFWL_ComboList::ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy) { |
| 86 fx += m_pProperties->m_rtWidget.left, fy += m_pProperties->m_rtWidget.top; | 87 fx += m_pProperties->m_rtWidget.left, fy += m_pProperties->m_rtWidget.top; |
| 87 IFWL_Widget* pOwner = GetOwner(); | 88 IFWL_Widget* pOwner = GetOwner(); |
| 88 if (!pOwner) | 89 if (!pOwner) |
| 89 return; | 90 return; |
| 90 pOwner->TransformTo(m_pOuter, fx, fy); | 91 pOwner->TransformTo(m_pOuter, fx, fy); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) | 163 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) |
| 163 return; | 164 return; |
| 164 } | 165 } |
| 165 | 166 |
| 166 CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | 167 CFWL_ListItem* hItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); |
| 167 if (!hItem) | 168 if (!hItem) |
| 168 return; | 169 return; |
| 169 if (!m_pProperties->m_pDataProvider) | 170 if (!m_pProperties->m_pDataProvider) |
| 170 return; | 171 return; |
| 171 | 172 |
| 172 IFWL_ListBoxDP* pData = | 173 IFWL_ListBox::DataProvider* pData = |
| 173 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 174 static_cast<IFWL_ListBox::DataProvider*>( |
| 175 m_pProperties->m_pDataProvider); |
| 174 ChangeSelected(pData->GetItemIndex(this, hItem)); | 176 ChangeSelected(pData->GetItemIndex(this, hItem)); |
| 175 } else if (m_bNotifyOwner) { | 177 } else if (m_bNotifyOwner) { |
| 176 ClientToOuter(pMsg->m_fx, pMsg->m_fy); | 178 ClientToOuter(pMsg->m_fx, pMsg->m_fy); |
| 177 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 179 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
| 178 pOuter->GetDelegate()->OnProcessMessage(pMsg); | 180 pOuter->GetDelegate()->OnProcessMessage(pMsg); |
| 179 } | 181 } |
| 180 } | 182 } |
| 181 | 183 |
| 182 void IFWL_ComboList::OnDropListLButtonDown(CFWL_MsgMouse* pMsg) { | 184 void IFWL_ComboList::OnDropListLButtonDown(CFWL_MsgMouse* pMsg) { |
| 183 if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) | 185 if (GetRTClient().Contains(pMsg->m_fx, pMsg->m_fy)) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 } | 245 } |
| 244 | 246 |
| 245 void IFWL_ComboList::OnDropListKeyDown(CFWL_MsgKey* pKey) { | 247 void IFWL_ComboList::OnDropListKeyDown(CFWL_MsgKey* pKey) { |
| 246 uint32_t dwKeyCode = pKey->m_dwKeyCode; | 248 uint32_t dwKeyCode = pKey->m_dwKeyCode; |
| 247 switch (dwKeyCode) { | 249 switch (dwKeyCode) { |
| 248 case FWL_VKEY_Up: | 250 case FWL_VKEY_Up: |
| 249 case FWL_VKEY_Down: | 251 case FWL_VKEY_Down: |
| 250 case FWL_VKEY_Home: | 252 case FWL_VKEY_Home: |
| 251 case FWL_VKEY_End: { | 253 case FWL_VKEY_End: { |
| 252 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); | 254 IFWL_ComboBox* pOuter = static_cast<IFWL_ComboBox*>(m_pOuter); |
| 253 IFWL_ListBoxDP* pData = | 255 IFWL_ListBox::DataProvider* pData = |
| 254 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | 256 static_cast<IFWL_ListBox::DataProvider*>( |
| 257 m_pProperties->m_pDataProvider); |
| 255 CFWL_ListItem* hItem = | 258 CFWL_ListItem* hItem = |
| 256 pData->GetItem(this, pOuter->GetCurrentSelection()); | 259 pData->GetItem(this, pOuter->GetCurrentSelection()); |
| 257 hItem = GetItem(hItem, dwKeyCode); | 260 hItem = GetItem(hItem, dwKeyCode); |
| 258 if (!hItem) | 261 if (!hItem) |
| 259 break; | 262 break; |
| 260 | 263 |
| 261 SetSelection(hItem, hItem, true); | 264 SetSelection(hItem, hItem, true); |
| 262 ScrollToVisible(hItem); | 265 ScrollToVisible(hItem); |
| 263 CFX_RectF rtInvalidate; | 266 CFX_RectF rtInvalidate; |
| 264 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, | 267 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, |
| 265 m_pProperties->m_rtWidget.height); | 268 m_pProperties->m_rtWidget.height); |
| 266 Repaint(&rtInvalidate); | 269 Repaint(&rtInvalidate); |
| 267 break; | 270 break; |
| 268 } | 271 } |
| 269 default: | 272 default: |
| 270 break; | 273 break; |
| 271 } | 274 } |
| 272 } | 275 } |
| OLD | NEW |