| 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_combobox.h" | 7 #include "xfa/fwl/core/cfwl_combobox.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 117 } |
| 118 | 118 |
| 119 bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); | 119 bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); |
| 120 bool bRemoveDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); | 120 bool bRemoveDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); |
| 121 if (bAddDropDown && !m_pEdit) { | 121 if (bAddDropDown && !m_pEdit) { |
| 122 m_pEdit = pdfium::MakeUnique<CFWL_ComboEdit>( | 122 m_pEdit = pdfium::MakeUnique<CFWL_ComboEdit>( |
| 123 m_pOwnerApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); | 123 m_pOwnerApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr); |
| 124 m_pEdit->SetOuter(this); | 124 m_pEdit->SetOuter(this); |
| 125 m_pEdit->SetParent(this); | 125 m_pEdit->SetParent(this); |
| 126 } else if (bRemoveDropDown && m_pEdit) { | 126 } else if (bRemoveDropDown && m_pEdit) { |
| 127 m_pEdit->SetStates(FWL_WGTSTATE_Invisible, true); | 127 m_pEdit->SetStates(FWL_WGTSTATE_Invisible); |
| 128 } | 128 } |
| 129 CFWL_Widget::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | 129 CFWL_Widget::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); |
| 130 } | 130 } |
| 131 | 131 |
| 132 void CFWL_ComboBox::Update() { | 132 void CFWL_ComboBox::Update() { |
| 133 if (m_pWidgetMgr->IsFormDisabled()) { | 133 if (m_pWidgetMgr->IsFormDisabled()) { |
| 134 DisForm_Update(); | 134 DisForm_Update(); |
| 135 return; | 135 return; |
| 136 } | 136 } |
| 137 if (IsLocked()) | 137 if (IsLocked()) |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } else { | 269 } else { |
| 270 CFWL_ListItem* hItem = m_pListBox->GetItem(this, iSel); | 270 CFWL_ListItem* hItem = m_pListBox->GetItem(this, iSel); |
| 271 CFX_WideString wsText = m_pListBox->GetDataProviderItemText(hItem); | 271 CFX_WideString wsText = m_pListBox->GetDataProviderItemText(hItem); |
| 272 m_pEdit->SetText(wsText); | 272 m_pEdit->SetText(wsText); |
| 273 } | 273 } |
| 274 m_pEdit->Update(); | 274 m_pEdit->Update(); |
| 275 } | 275 } |
| 276 m_iCurSel = bClearSel ? -1 : iSel; | 276 m_iCurSel = bClearSel ? -1 : iSel; |
| 277 } | 277 } |
| 278 | 278 |
| 279 void CFWL_ComboBox::SetStates(uint32_t dwStates, bool bSet) { | 279 void CFWL_ComboBox::SetStates(uint32_t dwStates) { |
| 280 if (IsDropDownStyle() && m_pEdit) | 280 if (IsDropDownStyle() && m_pEdit) |
| 281 m_pEdit->SetStates(dwStates, bSet); | 281 m_pEdit->SetStates(dwStates); |
| 282 if (m_pListBox) | 282 if (m_pListBox) |
| 283 m_pListBox->SetStates(dwStates, bSet); | 283 m_pListBox->SetStates(dwStates); |
| 284 CFWL_Widget::SetStates(dwStates, bSet); | 284 CFWL_Widget::SetStates(dwStates); |
| 285 } |
| 286 |
| 287 void CFWL_ComboBox::RemoveStates(uint32_t dwStates) { |
| 288 if (IsDropDownStyle() && m_pEdit) |
| 289 m_pEdit->RemoveStates(dwStates); |
| 290 if (m_pListBox) |
| 291 m_pListBox->RemoveStates(dwStates); |
| 292 CFWL_Widget::RemoveStates(dwStates); |
| 285 } | 293 } |
| 286 | 294 |
| 287 void CFWL_ComboBox::SetEditText(const CFX_WideString& wsText) { | 295 void CFWL_ComboBox::SetEditText(const CFX_WideString& wsText) { |
| 288 if (!m_pEdit) | 296 if (!m_pEdit) |
| 289 return; | 297 return; |
| 290 | 298 |
| 291 m_pEdit->SetText(wsText); | 299 m_pEdit->SetText(wsText); |
| 292 m_pEdit->Update(); | 300 m_pEdit->Update(); |
| 293 } | 301 } |
| 294 | 302 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 312 if (m_pWidgetMgr->IsFormDisabled()) { | 320 if (m_pWidgetMgr->IsFormDisabled()) { |
| 313 DisForm_GetBBox(rect); | 321 DisForm_GetBBox(rect); |
| 314 return; | 322 return; |
| 315 } | 323 } |
| 316 | 324 |
| 317 rect = m_pProperties->m_rtWidget; | 325 rect = m_pProperties->m_rtWidget; |
| 318 if (!m_pListBox || !IsDropListVisible()) | 326 if (!m_pListBox || !IsDropListVisible()) |
| 319 return; | 327 return; |
| 320 | 328 |
| 321 CFX_RectF rtList; | 329 CFX_RectF rtList; |
| 322 m_pListBox->GetWidgetRect(rtList); | 330 m_pListBox->GetWidgetRect(rtList, false); |
| 323 rtList.Offset(rect.left, rect.top); | 331 rtList.Offset(rect.left, rect.top); |
| 324 rect.Union(rtList); | 332 rect.Union(rtList); |
| 325 } | 333 } |
| 326 | 334 |
| 327 void CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, | 335 void CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, |
| 328 uint32_t dwStylesExRemoved) { | 336 uint32_t dwStylesExRemoved) { |
| 329 if (m_pEdit) | 337 if (m_pEdit) |
| 330 m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | 338 m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); |
| 331 } | 339 } |
| 332 | 340 |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 rtList.top = 0; | 639 rtList.top = 0; |
| 632 rtList.height = 0; | 640 rtList.height = 0; |
| 633 GetPopupPos(fPopupMin, fPopupMax, m_pProperties->m_rtWidget, rtList); | 641 GetPopupPos(fPopupMin, fPopupMax, m_pProperties->m_rtWidget, rtList); |
| 634 | 642 |
| 635 m_pListBox->SetWidgetRect(rtList); | 643 m_pListBox->SetWidgetRect(rtList); |
| 636 m_pListBox->Update(); | 644 m_pListBox->Update(); |
| 637 } else { | 645 } else { |
| 638 SetFocus(true); | 646 SetFocus(true); |
| 639 } | 647 } |
| 640 | 648 |
| 641 m_pListBox->SetStates(FWL_WGTSTATE_Invisible, !bActivate); | |
| 642 if (bActivate) { | 649 if (bActivate) { |
| 650 m_pListBox->RemoveStates(FWL_WGTSTATE_Invisible); |
| 643 CFWL_Event postEvent(CFWL_EventType::PostDropDown); | 651 CFWL_Event postEvent(CFWL_EventType::PostDropDown); |
| 644 postEvent.m_pSrcTarget = this; | 652 postEvent.m_pSrcTarget = this; |
| 645 DispatchEvent(&postEvent); | 653 DispatchEvent(&postEvent); |
| 654 } else { |
| 655 m_pListBox->SetStates(FWL_WGTSTATE_Invisible); |
| 646 } | 656 } |
| 647 | 657 |
| 648 CFX_RectF rect; | 658 CFX_RectF rect; |
| 649 m_pListBox->GetWidgetRect(rect); | 659 m_pListBox->GetWidgetRect(rect, false); |
| 650 rect.Inflate(2, 2); | 660 rect.Inflate(2, 2); |
| 651 Repaint(&rect); | 661 Repaint(&rect); |
| 652 } | 662 } |
| 653 | 663 |
| 654 void CFWL_ComboBox::DisForm_ModifyStylesEx(uint32_t dwStylesExAdded, | 664 void CFWL_ComboBox::DisForm_ModifyStylesEx(uint32_t dwStylesExAdded, |
| 655 uint32_t dwStylesExRemoved) { | 665 uint32_t dwStylesExRemoved) { |
| 656 if (!m_pEdit) | 666 if (!m_pEdit) |
| 657 DisForm_InitComboEdit(); | 667 DisForm_InitComboEdit(); |
| 658 | 668 |
| 659 bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); | 669 bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 680 | 690 |
| 681 FWL_WidgetHit CFWL_ComboBox::DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy) { | 691 FWL_WidgetHit CFWL_ComboBox::DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy) { |
| 682 CFX_RectF rect; | 692 CFX_RectF rect; |
| 683 rect.Set(0, 0, m_pProperties->m_rtWidget.width - m_rtBtn.width, | 693 rect.Set(0, 0, m_pProperties->m_rtWidget.width - m_rtBtn.width, |
| 684 m_pProperties->m_rtWidget.height); | 694 m_pProperties->m_rtWidget.height); |
| 685 if (rect.Contains(fx, fy)) | 695 if (rect.Contains(fx, fy)) |
| 686 return FWL_WidgetHit::Edit; | 696 return FWL_WidgetHit::Edit; |
| 687 if (m_rtBtn.Contains(fx, fy)) | 697 if (m_rtBtn.Contains(fx, fy)) |
| 688 return FWL_WidgetHit::Client; | 698 return FWL_WidgetHit::Client; |
| 689 if (DisForm_IsDropListVisible()) { | 699 if (DisForm_IsDropListVisible()) { |
| 690 m_pListBox->GetWidgetRect(rect); | 700 m_pListBox->GetWidgetRect(rect, false); |
| 691 if (rect.Contains(fx, fy)) | 701 if (rect.Contains(fx, fy)) |
| 692 return FWL_WidgetHit::Client; | 702 return FWL_WidgetHit::Client; |
| 693 } | 703 } |
| 694 return FWL_WidgetHit::Unknown; | 704 return FWL_WidgetHit::Unknown; |
| 695 } | 705 } |
| 696 | 706 |
| 697 void CFWL_ComboBox::DisForm_DrawWidget(CFX_Graphics* pGraphics, | 707 void CFWL_ComboBox::DisForm_DrawWidget(CFX_Graphics* pGraphics, |
| 698 const CFX_Matrix* pMatrix) { | 708 const CFX_Matrix* pMatrix) { |
| 699 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | 709 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
| 700 CFX_Matrix mtOrg; | 710 CFX_Matrix mtOrg; |
| 701 mtOrg.Set(1, 0, 0, 1, 0, 0); | 711 mtOrg.Set(1, 0, 0, 1, 0, 0); |
| 702 if (pMatrix) | 712 if (pMatrix) |
| 703 mtOrg = *pMatrix; | 713 mtOrg = *pMatrix; |
| 704 | 714 |
| 705 pGraphics->SaveGraphState(); | 715 pGraphics->SaveGraphState(); |
| 706 pGraphics->ConcatMatrix(&mtOrg); | 716 pGraphics->ConcatMatrix(&mtOrg); |
| 707 if (!m_rtBtn.IsEmpty(0.1f)) { | 717 if (!m_rtBtn.IsEmpty(0.1f)) { |
| 708 CFWL_ThemeBackground param; | 718 CFWL_ThemeBackground param; |
| 709 param.m_pWidget = this; | 719 param.m_pWidget = this; |
| 710 param.m_iPart = CFWL_Part::DropDownButton; | 720 param.m_iPart = CFWL_Part::DropDownButton; |
| 711 param.m_dwStates = m_iBtnState; | 721 param.m_dwStates = m_iBtnState; |
| 712 param.m_pGraphics = pGraphics; | 722 param.m_pGraphics = pGraphics; |
| 713 param.m_rtPart = m_rtBtn; | 723 param.m_rtPart = m_rtBtn; |
| 714 pTheme->DrawBackground(¶m); | 724 pTheme->DrawBackground(¶m); |
| 715 } | 725 } |
| 716 pGraphics->RestoreGraphState(); | 726 pGraphics->RestoreGraphState(); |
| 717 | 727 |
| 718 if (m_pEdit) { | 728 if (m_pEdit) { |
| 719 CFX_RectF rtEdit; | 729 CFX_RectF rtEdit; |
| 720 m_pEdit->GetWidgetRect(rtEdit); | 730 m_pEdit->GetWidgetRect(rtEdit, false); |
| 721 CFX_Matrix mt; | 731 CFX_Matrix mt; |
| 722 mt.Set(1, 0, 0, 1, rtEdit.left, rtEdit.top); | 732 mt.Set(1, 0, 0, 1, rtEdit.left, rtEdit.top); |
| 723 mt.Concat(mtOrg); | 733 mt.Concat(mtOrg); |
| 724 m_pEdit->DrawWidget(pGraphics, &mt); | 734 m_pEdit->DrawWidget(pGraphics, &mt); |
| 725 } | 735 } |
| 726 if (m_pListBox && DisForm_IsDropListVisible()) { | 736 if (m_pListBox && DisForm_IsDropListVisible()) { |
| 727 CFX_RectF rtList; | 737 CFX_RectF rtList; |
| 728 m_pListBox->GetWidgetRect(rtList); | 738 m_pListBox->GetWidgetRect(rtList, false); |
| 729 CFX_Matrix mt; | 739 CFX_Matrix mt; |
| 730 mt.Set(1, 0, 0, 1, rtList.left, rtList.top); | 740 mt.Set(1, 0, 0, 1, rtList.left, rtList.top); |
| 731 mt.Concat(mtOrg); | 741 mt.Concat(mtOrg); |
| 732 m_pListBox->DrawWidget(pGraphics, &mt); | 742 m_pListBox->DrawWidget(pGraphics, &mt); |
| 733 } | 743 } |
| 734 } | 744 } |
| 735 | 745 |
| 736 void CFWL_ComboBox::DisForm_GetBBox(CFX_RectF& rect) const { | 746 void CFWL_ComboBox::DisForm_GetBBox(CFX_RectF& rect) const { |
| 737 rect = m_pProperties->m_rtWidget; | 747 rect = m_pProperties->m_rtWidget; |
| 738 if (!m_pListBox || !DisForm_IsDropListVisible()) | 748 if (!m_pListBox || !DisForm_IsDropListVisible()) |
| 739 return; | 749 return; |
| 740 | 750 |
| 741 CFX_RectF rtList; | 751 CFX_RectF rtList; |
| 742 m_pListBox->GetWidgetRect(rtList); | 752 m_pListBox->GetWidgetRect(rtList, false); |
| 743 rtList.Offset(rect.left, rect.top); | 753 rtList.Offset(rect.left, rect.top); |
| 744 rect.Union(rtList); | 754 rect.Union(rtList); |
| 745 } | 755 } |
| 746 | 756 |
| 747 void CFWL_ComboBox::DisForm_Layout() { | 757 void CFWL_ComboBox::DisForm_Layout() { |
| 748 GetClientRect(m_rtClient); | 758 GetClientRect(m_rtClient); |
| 749 m_rtContent = m_rtClient; | 759 m_rtContent = m_rtClient; |
| 750 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( | 760 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( |
| 751 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 761 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
| 752 if (!pFWidth) | 762 if (!pFWidth) |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 else | 1113 else |
| 1104 iCurSel++; | 1114 iCurSel++; |
| 1105 } | 1115 } |
| 1106 m_iCurSel = iCurSel; | 1116 m_iCurSel = iCurSel; |
| 1107 SyncEditText(m_iCurSel); | 1117 SyncEditText(m_iCurSel); |
| 1108 return; | 1118 return; |
| 1109 } | 1119 } |
| 1110 if (m_pEdit) | 1120 if (m_pEdit) |
| 1111 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); | 1121 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); |
| 1112 } | 1122 } |
| OLD | NEW |