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_combobox.h" | 7 #include "xfa/fwl/core/ifwl_combobox.h" |
8 | 8 |
9 #include "third_party/base/ptr_util.h" | 9 #include "third_party/base/ptr_util.h" |
10 #include "xfa/fde/cfde_txtedtengine.h" | 10 #include "xfa/fde/cfde_txtedtengine.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 } else { | 185 } else { |
186 param.m_dwStates = CFWL_PartState_Normal; | 186 param.m_dwStates = CFWL_PartState_Normal; |
187 } | 187 } |
188 pTheme->DrawBackground(¶m); | 188 pTheme->DrawBackground(¶m); |
189 if (m_iCurSel >= 0) { | 189 if (m_iCurSel >= 0) { |
190 if (!m_pListBox) | 190 if (!m_pListBox) |
191 return FWL_Error::Indefinite; | 191 return FWL_Error::Indefinite; |
192 CFX_WideString wsText; | 192 CFX_WideString wsText; |
193 IFWL_ComboBoxDP* pData = | 193 IFWL_ComboBoxDP* pData = |
194 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | 194 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); |
195 IFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); | 195 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); |
196 m_pListBox->GetItemText(hItem, wsText); | 196 m_pListBox->GetItemText(hItem, wsText); |
197 CFWL_ThemeText theme_text; | 197 CFWL_ThemeText theme_text; |
198 theme_text.m_pWidget = this; | 198 theme_text.m_pWidget = this; |
199 theme_text.m_iPart = CFWL_Part::Caption; | 199 theme_text.m_iPart = CFWL_Part::Caption; |
200 theme_text.m_dwStates = m_iBtnState; | 200 theme_text.m_dwStates = m_iBtnState; |
201 theme_text.m_pGraphics = pGraphics; | 201 theme_text.m_pGraphics = pGraphics; |
202 theme_text.m_matrix.Concat(*pMatrix); | 202 theme_text.m_matrix.Concat(*pMatrix); |
203 theme_text.m_rtPart = rtTextBk; | 203 theme_text.m_rtPart = rtTextBk; |
204 theme_text.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) | 204 theme_text.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) |
205 ? CFWL_PartState_Selected | 205 ? CFWL_PartState_Selected |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 int32_t iCount = m_pListBox->CountItems(); | 244 int32_t iCount = m_pListBox->CountItems(); |
245 bool bClearSel = iSel < 0 || iSel >= iCount; | 245 bool bClearSel = iSel < 0 || iSel >= iCount; |
246 bool bDropDown = IsDropDownStyle(); | 246 bool bDropDown = IsDropDownStyle(); |
247 if (bDropDown && m_pEdit) { | 247 if (bDropDown && m_pEdit) { |
248 if (bClearSel) { | 248 if (bClearSel) { |
249 m_pEdit->SetText(CFX_WideString()); | 249 m_pEdit->SetText(CFX_WideString()); |
250 } else { | 250 } else { |
251 CFX_WideString wsText; | 251 CFX_WideString wsText; |
252 IFWL_ComboBoxDP* pData = | 252 IFWL_ComboBoxDP* pData = |
253 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | 253 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); |
254 IFWL_ListItem* hItem = pData->GetItem(this, iSel); | 254 CFWL_ListItem* hItem = pData->GetItem(this, iSel); |
255 m_pListBox->GetItemText(hItem, wsText); | 255 m_pListBox->GetItemText(hItem, wsText); |
256 m_pEdit->SetText(wsText); | 256 m_pEdit->SetText(wsText); |
257 } | 257 } |
258 m_pEdit->Update(); | 258 m_pEdit->Update(); |
259 } | 259 } |
260 m_iCurSel = bClearSel ? -1 : iSel; | 260 m_iCurSel = bClearSel ? -1 : iSel; |
261 return FWL_Error::Succeeded; | 261 return FWL_Error::Succeeded; |
262 } | 262 } |
263 | 263 |
264 void IFWL_ComboBox::SetStates(uint32_t dwStates, bool bSet) { | 264 void IFWL_ComboBox::SetStates(uint32_t dwStates, bool bSet) { |
(...skipping 19 matching lines...) Expand all Loading... |
284 } | 284 } |
285 | 285 |
286 FWL_Error IFWL_ComboBox::GetEditText(CFX_WideString& wsText, | 286 FWL_Error IFWL_ComboBox::GetEditText(CFX_WideString& wsText, |
287 int32_t nStart, | 287 int32_t nStart, |
288 int32_t nCount) const { | 288 int32_t nCount) const { |
289 if (m_pEdit) { | 289 if (m_pEdit) { |
290 return m_pEdit->GetText(wsText, nStart, nCount); | 290 return m_pEdit->GetText(wsText, nStart, nCount); |
291 } else if (m_pListBox) { | 291 } else if (m_pListBox) { |
292 IFWL_ComboBoxDP* pData = | 292 IFWL_ComboBoxDP* pData = |
293 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | 293 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); |
294 IFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); | 294 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); |
295 return m_pListBox->GetItemText(hItem, wsText); | 295 return m_pListBox->GetItemText(hItem, wsText); |
296 } | 296 } |
297 return FWL_Error::Indefinite; | 297 return FWL_Error::Indefinite; |
298 } | 298 } |
299 | 299 |
300 FWL_Error IFWL_ComboBox::SetEditSelRange(int32_t nStart, int32_t nCount) { | 300 FWL_Error IFWL_ComboBox::SetEditSelRange(int32_t nStart, int32_t nCount) { |
301 if (!m_pEdit) | 301 if (!m_pEdit) |
302 return FWL_Error::Indefinite; | 302 return FWL_Error::Indefinite; |
303 m_pEdit->ClearSelected(); | 303 m_pEdit->ClearSelected(); |
304 m_pEdit->AddSelRange(nStart, nCount); | 304 m_pEdit->AddSelRange(nStart, nCount); |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 } else if (iMatch >= 0) { | 546 } else if (iMatch >= 0) { |
547 m_pEdit->SetSelected(); | 547 m_pEdit->SetSelected(); |
548 } | 548 } |
549 m_iCurSel = iMatch; | 549 m_iCurSel = iMatch; |
550 } | 550 } |
551 | 551 |
552 void IFWL_ComboBox::SynchrEditText(int32_t iListItem) { | 552 void IFWL_ComboBox::SynchrEditText(int32_t iListItem) { |
553 CFX_WideString wsText; | 553 CFX_WideString wsText; |
554 IFWL_ComboBoxDP* pData = | 554 IFWL_ComboBoxDP* pData = |
555 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | 555 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); |
556 IFWL_ListItem* hItem = pData->GetItem(this, iListItem); | 556 CFWL_ListItem* hItem = pData->GetItem(this, iListItem); |
557 m_pListBox->GetItemText(hItem, wsText); | 557 m_pListBox->GetItemText(hItem, wsText); |
558 m_pEdit->SetText(wsText); | 558 m_pEdit->SetText(wsText); |
559 m_pEdit->Update(); | 559 m_pEdit->Update(); |
560 m_pEdit->SetSelected(); | 560 m_pEdit->SetSelected(); |
561 } | 561 } |
562 | 562 |
563 void IFWL_ComboBox::Layout() { | 563 void IFWL_ComboBox::Layout() { |
564 if (m_pWidgetMgr->IsFormDisabled()) { | 564 if (m_pWidgetMgr->IsFormDisabled()) { |
565 return DisForm_Layout(); | 565 return DisForm_Layout(); |
566 } | 566 } |
567 GetClientRect(m_rtClient); | 567 GetClientRect(m_rtClient); |
568 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( | 568 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( |
569 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 569 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
570 if (!pFWidth) | 570 if (!pFWidth) |
571 return; | 571 return; |
572 FX_FLOAT fBtn = *pFWidth; | 572 FX_FLOAT fBtn = *pFWidth; |
573 m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top, fBtn, | 573 m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top, fBtn, |
574 m_rtClient.height); | 574 m_rtClient.height); |
575 bool bIsDropDown = IsDropDownStyle(); | 575 bool bIsDropDown = IsDropDownStyle(); |
576 if (bIsDropDown && m_pEdit) { | 576 if (bIsDropDown && m_pEdit) { |
577 CFX_RectF rtEdit; | 577 CFX_RectF rtEdit; |
578 rtEdit.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width - fBtn, | 578 rtEdit.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width - fBtn, |
579 m_rtClient.height); | 579 m_rtClient.height); |
580 m_pEdit->SetWidgetRect(rtEdit); | 580 m_pEdit->SetWidgetRect(rtEdit); |
581 if (m_iCurSel >= 0) { | 581 if (m_iCurSel >= 0) { |
582 CFX_WideString wsText; | 582 CFX_WideString wsText; |
583 IFWL_ComboBoxDP* pData = | 583 IFWL_ComboBoxDP* pData = |
584 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | 584 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); |
585 IFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); | 585 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); |
586 m_pListBox->GetItemText(hItem, wsText); | 586 m_pListBox->GetItemText(hItem, wsText); |
587 m_pEdit->LockUpdate(); | 587 m_pEdit->LockUpdate(); |
588 m_pEdit->SetText(wsText); | 588 m_pEdit->SetText(wsText); |
589 m_pEdit->UnlockUpdate(); | 589 m_pEdit->UnlockUpdate(); |
590 } | 590 } |
591 m_pEdit->Update(); | 591 m_pEdit->Update(); |
592 } | 592 } |
593 } | 593 } |
594 | 594 |
595 void IFWL_ComboBox::ReSetTheme() { | 595 void IFWL_ComboBox::ReSetTheme() { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 } | 660 } |
661 | 661 |
662 void IFWL_ComboBox::ProcessSelChanged(bool bLButtonUp) { | 662 void IFWL_ComboBox::ProcessSelChanged(bool bLButtonUp) { |
663 IFWL_ComboBoxDP* pDatas = | 663 IFWL_ComboBoxDP* pDatas = |
664 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | 664 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); |
665 m_iCurSel = pDatas->GetItemIndex(this, m_pListBox->GetSelItem(0)); | 665 m_iCurSel = pDatas->GetItemIndex(this, m_pListBox->GetSelItem(0)); |
666 bool bDropDown = IsDropDownStyle(); | 666 bool bDropDown = IsDropDownStyle(); |
667 if (bDropDown) { | 667 if (bDropDown) { |
668 IFWL_ComboBoxDP* pData = | 668 IFWL_ComboBoxDP* pData = |
669 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | 669 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); |
670 IFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); | 670 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); |
671 if (hItem) { | 671 if (hItem) { |
672 CFX_WideString wsText; | 672 CFX_WideString wsText; |
673 pData->GetItemText(this, hItem, wsText); | 673 pData->GetItemText(this, hItem, wsText); |
674 if (m_pEdit) { | 674 if (m_pEdit) { |
675 m_pEdit->SetText(wsText); | 675 m_pEdit->SetText(wsText); |
676 m_pEdit->Update(); | 676 m_pEdit->Update(); |
677 m_pEdit->SetSelected(); | 677 m_pEdit->SetSelected(); |
678 } | 678 } |
679 CFWL_EvtCmbSelChanged ev; | 679 CFWL_EvtCmbSelChanged ev; |
680 ev.bLButtonUp = bLButtonUp; | 680 ev.bLButtonUp = bLButtonUp; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 bool bIsDropDown = IsDropDownStyle(); | 895 bool bIsDropDown = IsDropDownStyle(); |
896 if (bIsDropDown && m_pEdit) { | 896 if (bIsDropDown && m_pEdit) { |
897 CFX_RectF rtEdit; | 897 CFX_RectF rtEdit; |
898 rtEdit.Set(m_rtContent.left, m_rtContent.top, m_rtContent.width - fBtn, | 898 rtEdit.Set(m_rtContent.left, m_rtContent.top, m_rtContent.width - fBtn, |
899 m_rtContent.height); | 899 m_rtContent.height); |
900 m_pEdit->SetWidgetRect(rtEdit); | 900 m_pEdit->SetWidgetRect(rtEdit); |
901 if (m_iCurSel >= 0) { | 901 if (m_iCurSel >= 0) { |
902 CFX_WideString wsText; | 902 CFX_WideString wsText; |
903 IFWL_ComboBoxDP* pData = | 903 IFWL_ComboBoxDP* pData = |
904 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | 904 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); |
905 IFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); | 905 CFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); |
906 m_pListBox->GetItemText(hItem, wsText); | 906 m_pListBox->GetItemText(hItem, wsText); |
907 m_pEdit->LockUpdate(); | 907 m_pEdit->LockUpdate(); |
908 m_pEdit->SetText(wsText); | 908 m_pEdit->SetText(wsText); |
909 m_pEdit->UnlockUpdate(); | 909 m_pEdit->UnlockUpdate(); |
910 } | 910 } |
911 m_pEdit->Update(); | 911 m_pEdit->Update(); |
912 } | 912 } |
913 } | 913 } |
914 | 914 |
915 void IFWL_ComboBox::OnProcessMessage(CFWL_Message* pMessage) { | 915 void IFWL_ComboBox::OnProcessMessage(CFWL_Message* pMessage) { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 int32_t iCurSel = m_iCurSel; | 1096 int32_t iCurSel = m_iCurSel; |
1097 bool bDropDown = IsDropDownStyle(); | 1097 bool bDropDown = IsDropDownStyle(); |
1098 if (bDropDown && m_pEdit) { | 1098 if (bDropDown && m_pEdit) { |
1099 CFX_WideString wsText; | 1099 CFX_WideString wsText; |
1100 m_pEdit->GetText(wsText); | 1100 m_pEdit->GetText(wsText); |
1101 iCurSel = m_pListBox->MatchItem(wsText); | 1101 iCurSel = m_pListBox->MatchItem(wsText); |
1102 if (iCurSel >= 0) { | 1102 if (iCurSel >= 0) { |
1103 CFX_WideString wsTemp; | 1103 CFX_WideString wsTemp; |
1104 IFWL_ComboBoxDP* pData = | 1104 IFWL_ComboBoxDP* pData = |
1105 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | 1105 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); |
1106 IFWL_ListItem* hItem = pData->GetItem(this, iCurSel); | 1106 CFWL_ListItem* hItem = pData->GetItem(this, iCurSel); |
1107 m_pListBox->GetItemText(hItem, wsTemp); | 1107 m_pListBox->GetItemText(hItem, wsTemp); |
1108 bMatchEqual = wsText == wsTemp; | 1108 bMatchEqual = wsText == wsTemp; |
1109 } | 1109 } |
1110 } | 1110 } |
1111 if (iCurSel < 0) { | 1111 if (iCurSel < 0) { |
1112 iCurSel = 0; | 1112 iCurSel = 0; |
1113 } else if (!bDropDown || bMatchEqual) { | 1113 } else if (!bDropDown || bMatchEqual) { |
1114 if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) | 1114 if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) |
1115 return; | 1115 return; |
1116 if (bUp) | 1116 if (bUp) |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1233 return; | 1233 return; |
1234 | 1234 |
1235 bool bMatchEqual = false; | 1235 bool bMatchEqual = false; |
1236 int32_t iCurSel = m_iCurSel; | 1236 int32_t iCurSel = m_iCurSel; |
1237 if (m_pEdit) { | 1237 if (m_pEdit) { |
1238 CFX_WideString wsText; | 1238 CFX_WideString wsText; |
1239 m_pEdit->GetText(wsText); | 1239 m_pEdit->GetText(wsText); |
1240 iCurSel = pComboList->MatchItem(wsText); | 1240 iCurSel = pComboList->MatchItem(wsText); |
1241 if (iCurSel >= 0) { | 1241 if (iCurSel >= 0) { |
1242 CFX_WideString wsTemp; | 1242 CFX_WideString wsTemp; |
1243 IFWL_ListItem* item = m_pListBox->GetSelItem(iCurSel); | 1243 CFWL_ListItem* item = m_pListBox->GetSelItem(iCurSel); |
1244 m_pListBox->GetItemText(item, wsTemp); | 1244 m_pListBox->GetItemText(item, wsTemp); |
1245 bMatchEqual = wsText == wsTemp; | 1245 bMatchEqual = wsText == wsTemp; |
1246 } | 1246 } |
1247 } | 1247 } |
1248 if (iCurSel < 0) { | 1248 if (iCurSel < 0) { |
1249 iCurSel = 0; | 1249 iCurSel = 0; |
1250 } else if (bMatchEqual) { | 1250 } else if (bMatchEqual) { |
1251 if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) | 1251 if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) |
1252 return; | 1252 return; |
1253 if (bUp) | 1253 if (bUp) |
1254 iCurSel--; | 1254 iCurSel--; |
1255 else | 1255 else |
1256 iCurSel++; | 1256 iCurSel++; |
1257 } | 1257 } |
1258 m_iCurSel = iCurSel; | 1258 m_iCurSel = iCurSel; |
1259 SynchrEditText(m_iCurSel); | 1259 SynchrEditText(m_iCurSel); |
1260 return; | 1260 return; |
1261 } | 1261 } |
1262 if (m_pEdit) | 1262 if (m_pEdit) |
1263 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); | 1263 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); |
1264 } | 1264 } |
OLD | NEW |