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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 rtList.top = 0; | 636 rtList.top = 0; |
629 rtList.height = 0; | 637 rtList.height = 0; |
630 GetPopupPos(fPopupMin, fPopupMax, m_pProperties->m_rtWidget, rtList); | 638 GetPopupPos(fPopupMin, fPopupMax, m_pProperties->m_rtWidget, rtList); |
631 | 639 |
632 m_pListBox->SetWidgetRect(rtList); | 640 m_pListBox->SetWidgetRect(rtList); |
633 m_pListBox->Update(); | 641 m_pListBox->Update(); |
634 } else { | 642 } else { |
635 SetFocus(true); | 643 SetFocus(true); |
636 } | 644 } |
637 | 645 |
638 m_pListBox->SetStates(FWL_WGTSTATE_Invisible, !bActivate); | |
639 if (bActivate) { | 646 if (bActivate) { |
| 647 m_pListBox->RemoveStates(FWL_WGTSTATE_Invisible); |
640 CFWL_Event postEvent(CFWL_Event::Type::PostDropDown, this); | 648 CFWL_Event postEvent(CFWL_Event::Type::PostDropDown, this); |
641 DispatchEvent(&postEvent); | 649 DispatchEvent(&postEvent); |
| 650 } else { |
| 651 m_pListBox->SetStates(FWL_WGTSTATE_Invisible); |
642 } | 652 } |
643 | 653 |
644 CFX_RectF rect; | 654 CFX_RectF rect; |
645 m_pListBox->GetWidgetRect(rect); | 655 m_pListBox->GetWidgetRect(rect, false); |
646 rect.Inflate(2, 2); | 656 rect.Inflate(2, 2); |
647 Repaint(&rect); | 657 Repaint(&rect); |
648 } | 658 } |
649 | 659 |
650 void CFWL_ComboBox::DisForm_ModifyStylesEx(uint32_t dwStylesExAdded, | 660 void CFWL_ComboBox::DisForm_ModifyStylesEx(uint32_t dwStylesExAdded, |
651 uint32_t dwStylesExRemoved) { | 661 uint32_t dwStylesExRemoved) { |
652 if (!m_pEdit) | 662 if (!m_pEdit) |
653 DisForm_InitComboEdit(); | 663 DisForm_InitComboEdit(); |
654 | 664 |
655 bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); | 665 bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); |
(...skipping 20 matching lines...) Expand all Loading... |
676 | 686 |
677 FWL_WidgetHit CFWL_ComboBox::DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy) { | 687 FWL_WidgetHit CFWL_ComboBox::DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy) { |
678 CFX_RectF rect; | 688 CFX_RectF rect; |
679 rect.Set(0, 0, m_pProperties->m_rtWidget.width - m_rtBtn.width, | 689 rect.Set(0, 0, m_pProperties->m_rtWidget.width - m_rtBtn.width, |
680 m_pProperties->m_rtWidget.height); | 690 m_pProperties->m_rtWidget.height); |
681 if (rect.Contains(fx, fy)) | 691 if (rect.Contains(fx, fy)) |
682 return FWL_WidgetHit::Edit; | 692 return FWL_WidgetHit::Edit; |
683 if (m_rtBtn.Contains(fx, fy)) | 693 if (m_rtBtn.Contains(fx, fy)) |
684 return FWL_WidgetHit::Client; | 694 return FWL_WidgetHit::Client; |
685 if (DisForm_IsDropListVisible()) { | 695 if (DisForm_IsDropListVisible()) { |
686 m_pListBox->GetWidgetRect(rect); | 696 m_pListBox->GetWidgetRect(rect, false); |
687 if (rect.Contains(fx, fy)) | 697 if (rect.Contains(fx, fy)) |
688 return FWL_WidgetHit::Client; | 698 return FWL_WidgetHit::Client; |
689 } | 699 } |
690 return FWL_WidgetHit::Unknown; | 700 return FWL_WidgetHit::Unknown; |
691 } | 701 } |
692 | 702 |
693 void CFWL_ComboBox::DisForm_DrawWidget(CFX_Graphics* pGraphics, | 703 void CFWL_ComboBox::DisForm_DrawWidget(CFX_Graphics* pGraphics, |
694 const CFX_Matrix* pMatrix) { | 704 const CFX_Matrix* pMatrix) { |
695 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | 705 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
696 CFX_Matrix mtOrg; | 706 CFX_Matrix mtOrg; |
697 mtOrg.Set(1, 0, 0, 1, 0, 0); | 707 mtOrg.Set(1, 0, 0, 1, 0, 0); |
698 if (pMatrix) | 708 if (pMatrix) |
699 mtOrg = *pMatrix; | 709 mtOrg = *pMatrix; |
700 | 710 |
701 pGraphics->SaveGraphState(); | 711 pGraphics->SaveGraphState(); |
702 pGraphics->ConcatMatrix(&mtOrg); | 712 pGraphics->ConcatMatrix(&mtOrg); |
703 if (!m_rtBtn.IsEmpty(0.1f)) { | 713 if (!m_rtBtn.IsEmpty(0.1f)) { |
704 CFWL_ThemeBackground param; | 714 CFWL_ThemeBackground param; |
705 param.m_pWidget = this; | 715 param.m_pWidget = this; |
706 param.m_iPart = CFWL_Part::DropDownButton; | 716 param.m_iPart = CFWL_Part::DropDownButton; |
707 param.m_dwStates = m_iBtnState; | 717 param.m_dwStates = m_iBtnState; |
708 param.m_pGraphics = pGraphics; | 718 param.m_pGraphics = pGraphics; |
709 param.m_rtPart = m_rtBtn; | 719 param.m_rtPart = m_rtBtn; |
710 pTheme->DrawBackground(¶m); | 720 pTheme->DrawBackground(¶m); |
711 } | 721 } |
712 pGraphics->RestoreGraphState(); | 722 pGraphics->RestoreGraphState(); |
713 | 723 |
714 if (m_pEdit) { | 724 if (m_pEdit) { |
715 CFX_RectF rtEdit; | 725 CFX_RectF rtEdit; |
716 m_pEdit->GetWidgetRect(rtEdit); | 726 m_pEdit->GetWidgetRect(rtEdit, false); |
717 CFX_Matrix mt; | 727 CFX_Matrix mt; |
718 mt.Set(1, 0, 0, 1, rtEdit.left, rtEdit.top); | 728 mt.Set(1, 0, 0, 1, rtEdit.left, rtEdit.top); |
719 mt.Concat(mtOrg); | 729 mt.Concat(mtOrg); |
720 m_pEdit->DrawWidget(pGraphics, &mt); | 730 m_pEdit->DrawWidget(pGraphics, &mt); |
721 } | 731 } |
722 if (m_pListBox && DisForm_IsDropListVisible()) { | 732 if (m_pListBox && DisForm_IsDropListVisible()) { |
723 CFX_RectF rtList; | 733 CFX_RectF rtList; |
724 m_pListBox->GetWidgetRect(rtList); | 734 m_pListBox->GetWidgetRect(rtList, false); |
725 CFX_Matrix mt; | 735 CFX_Matrix mt; |
726 mt.Set(1, 0, 0, 1, rtList.left, rtList.top); | 736 mt.Set(1, 0, 0, 1, rtList.left, rtList.top); |
727 mt.Concat(mtOrg); | 737 mt.Concat(mtOrg); |
728 m_pListBox->DrawWidget(pGraphics, &mt); | 738 m_pListBox->DrawWidget(pGraphics, &mt); |
729 } | 739 } |
730 } | 740 } |
731 | 741 |
732 void CFWL_ComboBox::DisForm_GetBBox(CFX_RectF& rect) const { | 742 void CFWL_ComboBox::DisForm_GetBBox(CFX_RectF& rect) const { |
733 rect = m_pProperties->m_rtWidget; | 743 rect = m_pProperties->m_rtWidget; |
734 if (!m_pListBox || !DisForm_IsDropListVisible()) | 744 if (!m_pListBox || !DisForm_IsDropListVisible()) |
735 return; | 745 return; |
736 | 746 |
737 CFX_RectF rtList; | 747 CFX_RectF rtList; |
738 m_pListBox->GetWidgetRect(rtList); | 748 m_pListBox->GetWidgetRect(rtList, false); |
739 rtList.Offset(rect.left, rect.top); | 749 rtList.Offset(rect.left, rect.top); |
740 rect.Union(rtList); | 750 rect.Union(rtList); |
741 } | 751 } |
742 | 752 |
743 void CFWL_ComboBox::DisForm_Layout() { | 753 void CFWL_ComboBox::DisForm_Layout() { |
744 GetClientRect(m_rtClient); | 754 GetClientRect(m_rtClient); |
745 m_rtContent = m_rtClient; | 755 m_rtContent = m_rtClient; |
746 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( | 756 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( |
747 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 757 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
748 if (!pFWidth) | 758 if (!pFWidth) |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 else | 1103 else |
1094 iCurSel++; | 1104 iCurSel++; |
1095 } | 1105 } |
1096 m_iCurSel = iCurSel; | 1106 m_iCurSel = iCurSel; |
1097 SyncEditText(m_iCurSel); | 1107 SyncEditText(m_iCurSel); |
1098 return; | 1108 return; |
1099 } | 1109 } |
1100 if (m_pEdit) | 1110 if (m_pEdit) |
1101 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); | 1111 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); |
1102 } | 1112 } |
OLD | NEW |