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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 | 65 |
66 SetStates(m_pProperties->m_dwStates); | 66 SetStates(m_pProperties->m_dwStates); |
67 } | 67 } |
68 | 68 |
69 CFWL_ComboBox::~CFWL_ComboBox() {} | 69 CFWL_ComboBox::~CFWL_ComboBox() {} |
70 | 70 |
71 FWL_Type CFWL_ComboBox::GetClassID() const { | 71 FWL_Type CFWL_ComboBox::GetClassID() const { |
72 return FWL_Type::ComboBox; | 72 return FWL_Type::ComboBox; |
73 } | 73 } |
74 | 74 |
75 void CFWL_ComboBox::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { | |
76 if (!bAutoSize) { | |
77 rect = m_pProperties->m_rtWidget; | |
78 return; | |
79 } | |
80 | |
81 rect.Reset(); | |
82 if (IsDropDownStyle() && m_pEdit) { | |
83 m_pEdit->GetWidgetRect(rect, true); | |
84 } else { | |
85 rect.width = 100; | |
86 rect.height = 16; | |
87 } | |
88 if (!m_pProperties->m_pThemeProvider) | |
89 ResetTheme(); | |
90 | |
91 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( | |
92 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | |
93 if (!pFWidth) | |
94 return; | |
95 | |
96 rect.Inflate(0, 0, *pFWidth, 0); | |
97 InflateWidgetRect(rect); | |
98 } | |
99 | |
100 void CFWL_ComboBox::AddString(const CFX_WideStringC& wsText) { | 75 void CFWL_ComboBox::AddString(const CFX_WideStringC& wsText) { |
101 m_pListBox->AddString(wsText); | 76 m_pListBox->AddString(wsText); |
102 } | 77 } |
103 | 78 |
104 bool CFWL_ComboBox::RemoveAt(int32_t iIndex) { | 79 bool CFWL_ComboBox::RemoveAt(int32_t iIndex) { |
105 return m_pListBox->RemoveAt(iIndex); | 80 return m_pListBox->RemoveAt(iIndex); |
106 } | 81 } |
107 | 82 |
108 void CFWL_ComboBox::RemoveAll() { | 83 void CFWL_ComboBox::RemoveAll() { |
109 m_pListBox->DeleteAll(); | 84 m_pListBox->DeleteAll(); |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 } | 288 } |
314 | 289 |
315 CFX_RectF CFWL_ComboBox::GetBBox() const { | 290 CFX_RectF CFWL_ComboBox::GetBBox() const { |
316 if (m_pWidgetMgr->IsFormDisabled()) | 291 if (m_pWidgetMgr->IsFormDisabled()) |
317 return DisForm_GetBBox(); | 292 return DisForm_GetBBox(); |
318 | 293 |
319 CFX_RectF rect = m_pProperties->m_rtWidget; | 294 CFX_RectF rect = m_pProperties->m_rtWidget; |
320 if (!m_pListBox || !IsDropListVisible()) | 295 if (!m_pListBox || !IsDropListVisible()) |
321 return rect; | 296 return rect; |
322 | 297 |
323 CFX_RectF rtList; | 298 CFX_RectF rtList = m_pListBox->GetWidgetRect(); |
324 m_pListBox->GetWidgetRect(rtList, false); | |
325 rtList.Offset(rect.left, rect.top); | 299 rtList.Offset(rect.left, rect.top); |
326 rect.Union(rtList); | 300 rect.Union(rtList); |
327 return rect; | 301 return rect; |
328 } | 302 } |
329 | 303 |
330 void CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, | 304 void CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, |
331 uint32_t dwStylesExRemoved) { | 305 uint32_t dwStylesExRemoved) { |
332 if (m_pEdit) | 306 if (m_pEdit) |
333 m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | 307 m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); |
334 } | 308 } |
(...skipping 28 matching lines...) Expand all Loading... |
363 SetFocus(true); | 337 SetFocus(true); |
364 return; | 338 return; |
365 } | 339 } |
366 | 340 |
367 m_pListBox->ChangeSelected(m_iCurSel); | 341 m_pListBox->ChangeSelected(m_iCurSel); |
368 ResetListItemAlignment(); | 342 ResetListItemAlignment(); |
369 | 343 |
370 uint32_t dwStyleAdd = m_pProperties->m_dwStyleExes & | 344 uint32_t dwStyleAdd = m_pProperties->m_dwStyleExes & |
371 (FWL_STYLEEXT_CMB_Sort | FWL_STYLEEXT_CMB_OwnerDraw); | 345 (FWL_STYLEEXT_CMB_Sort | FWL_STYLEEXT_CMB_OwnerDraw); |
372 m_pListBox->ModifyStylesEx(dwStyleAdd, 0); | 346 m_pListBox->ModifyStylesEx(dwStyleAdd, 0); |
373 m_pListBox->GetWidgetRect(m_rtList, true); | 347 m_rtList = m_pListBox->GetAutosizedWidgetRect(); |
374 | 348 |
375 CFX_RectF rtAnchor; | 349 CFX_RectF rtAnchor; |
376 rtAnchor.Set(0, 0, m_pProperties->m_rtWidget.width, | 350 rtAnchor.Set(0, 0, m_pProperties->m_rtWidget.width, |
377 m_pProperties->m_rtWidget.height); | 351 m_pProperties->m_rtWidget.height); |
378 | 352 |
379 m_rtList.width = std::max(m_rtList.width, m_rtClient.width); | 353 m_rtList.width = std::max(m_rtList.width, m_rtClient.width); |
380 m_rtProxy = m_rtList; | 354 m_rtProxy = m_rtList; |
381 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListDrag) | 355 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListDrag) |
382 m_rtProxy.height += m_fComboFormHandler; | 356 m_rtProxy.height += m_fComboFormHandler; |
383 | 357 |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 } | 613 } |
640 | 614 |
641 if (bActivate) { | 615 if (bActivate) { |
642 m_pListBox->RemoveStates(FWL_WGTSTATE_Invisible); | 616 m_pListBox->RemoveStates(FWL_WGTSTATE_Invisible); |
643 CFWL_Event postEvent(CFWL_Event::Type::PostDropDown, this); | 617 CFWL_Event postEvent(CFWL_Event::Type::PostDropDown, this); |
644 DispatchEvent(&postEvent); | 618 DispatchEvent(&postEvent); |
645 } else { | 619 } else { |
646 m_pListBox->SetStates(FWL_WGTSTATE_Invisible); | 620 m_pListBox->SetStates(FWL_WGTSTATE_Invisible); |
647 } | 621 } |
648 | 622 |
649 CFX_RectF rect; | 623 CFX_RectF rect = m_pListBox->GetWidgetRect(); |
650 m_pListBox->GetWidgetRect(rect, false); | |
651 rect.Inflate(2, 2); | 624 rect.Inflate(2, 2); |
652 Repaint(&rect); | 625 Repaint(&rect); |
653 } | 626 } |
654 | 627 |
655 void CFWL_ComboBox::DisForm_ModifyStylesEx(uint32_t dwStylesExAdded, | 628 void CFWL_ComboBox::DisForm_ModifyStylesEx(uint32_t dwStylesExAdded, |
656 uint32_t dwStylesExRemoved) { | 629 uint32_t dwStylesExRemoved) { |
657 if (!m_pEdit) | 630 if (!m_pEdit) |
658 DisForm_InitComboEdit(); | 631 DisForm_InitComboEdit(); |
659 | 632 |
660 bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); | 633 bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); |
(...skipping 20 matching lines...) Expand all Loading... |
681 | 654 |
682 FWL_WidgetHit CFWL_ComboBox::DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy) { | 655 FWL_WidgetHit CFWL_ComboBox::DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy) { |
683 CFX_RectF rect; | 656 CFX_RectF rect; |
684 rect.Set(0, 0, m_pProperties->m_rtWidget.width - m_rtBtn.width, | 657 rect.Set(0, 0, m_pProperties->m_rtWidget.width - m_rtBtn.width, |
685 m_pProperties->m_rtWidget.height); | 658 m_pProperties->m_rtWidget.height); |
686 if (rect.Contains(fx, fy)) | 659 if (rect.Contains(fx, fy)) |
687 return FWL_WidgetHit::Edit; | 660 return FWL_WidgetHit::Edit; |
688 if (m_rtBtn.Contains(fx, fy)) | 661 if (m_rtBtn.Contains(fx, fy)) |
689 return FWL_WidgetHit::Client; | 662 return FWL_WidgetHit::Client; |
690 if (DisForm_IsDropListVisible()) { | 663 if (DisForm_IsDropListVisible()) { |
691 m_pListBox->GetWidgetRect(rect, false); | 664 rect = m_pListBox->GetWidgetRect(); |
692 if (rect.Contains(fx, fy)) | 665 if (rect.Contains(fx, fy)) |
693 return FWL_WidgetHit::Client; | 666 return FWL_WidgetHit::Client; |
694 } | 667 } |
695 return FWL_WidgetHit::Unknown; | 668 return FWL_WidgetHit::Unknown; |
696 } | 669 } |
697 | 670 |
698 void CFWL_ComboBox::DisForm_DrawWidget(CFX_Graphics* pGraphics, | 671 void CFWL_ComboBox::DisForm_DrawWidget(CFX_Graphics* pGraphics, |
699 const CFX_Matrix* pMatrix) { | 672 const CFX_Matrix* pMatrix) { |
700 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | 673 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
701 CFX_Matrix mtOrg; | 674 CFX_Matrix mtOrg; |
702 mtOrg.Set(1, 0, 0, 1, 0, 0); | 675 mtOrg.Set(1, 0, 0, 1, 0, 0); |
703 if (pMatrix) | 676 if (pMatrix) |
704 mtOrg = *pMatrix; | 677 mtOrg = *pMatrix; |
705 | 678 |
706 pGraphics->SaveGraphState(); | 679 pGraphics->SaveGraphState(); |
707 pGraphics->ConcatMatrix(&mtOrg); | 680 pGraphics->ConcatMatrix(&mtOrg); |
708 if (!m_rtBtn.IsEmpty(0.1f)) { | 681 if (!m_rtBtn.IsEmpty(0.1f)) { |
709 CFWL_ThemeBackground param; | 682 CFWL_ThemeBackground param; |
710 param.m_pWidget = this; | 683 param.m_pWidget = this; |
711 param.m_iPart = CFWL_Part::DropDownButton; | 684 param.m_iPart = CFWL_Part::DropDownButton; |
712 param.m_dwStates = m_iBtnState; | 685 param.m_dwStates = m_iBtnState; |
713 param.m_pGraphics = pGraphics; | 686 param.m_pGraphics = pGraphics; |
714 param.m_rtPart = m_rtBtn; | 687 param.m_rtPart = m_rtBtn; |
715 pTheme->DrawBackground(¶m); | 688 pTheme->DrawBackground(¶m); |
716 } | 689 } |
717 pGraphics->RestoreGraphState(); | 690 pGraphics->RestoreGraphState(); |
718 | 691 |
719 if (m_pEdit) { | 692 if (m_pEdit) { |
720 CFX_RectF rtEdit; | 693 CFX_RectF rtEdit = m_pEdit->GetWidgetRect(); |
721 m_pEdit->GetWidgetRect(rtEdit, false); | |
722 CFX_Matrix mt; | 694 CFX_Matrix mt; |
723 mt.Set(1, 0, 0, 1, rtEdit.left, rtEdit.top); | 695 mt.Set(1, 0, 0, 1, rtEdit.left, rtEdit.top); |
724 mt.Concat(mtOrg); | 696 mt.Concat(mtOrg); |
725 m_pEdit->DrawWidget(pGraphics, &mt); | 697 m_pEdit->DrawWidget(pGraphics, &mt); |
726 } | 698 } |
727 if (m_pListBox && DisForm_IsDropListVisible()) { | 699 if (m_pListBox && DisForm_IsDropListVisible()) { |
728 CFX_RectF rtList; | 700 CFX_RectF rtList = m_pListBox->GetWidgetRect(); |
729 m_pListBox->GetWidgetRect(rtList, false); | |
730 CFX_Matrix mt; | 701 CFX_Matrix mt; |
731 mt.Set(1, 0, 0, 1, rtList.left, rtList.top); | 702 mt.Set(1, 0, 0, 1, rtList.left, rtList.top); |
732 mt.Concat(mtOrg); | 703 mt.Concat(mtOrg); |
733 m_pListBox->DrawWidget(pGraphics, &mt); | 704 m_pListBox->DrawWidget(pGraphics, &mt); |
734 } | 705 } |
735 } | 706 } |
736 | 707 |
737 CFX_RectF CFWL_ComboBox::DisForm_GetBBox() const { | 708 CFX_RectF CFWL_ComboBox::DisForm_GetBBox() const { |
738 CFX_RectF rect = m_pProperties->m_rtWidget; | 709 CFX_RectF rect = m_pProperties->m_rtWidget; |
739 if (!m_pListBox || !DisForm_IsDropListVisible()) | 710 if (!m_pListBox || !DisForm_IsDropListVisible()) |
740 return rect; | 711 return rect; |
741 | 712 |
742 CFX_RectF rtList; | 713 CFX_RectF rtList = m_pListBox->GetWidgetRect(); |
743 m_pListBox->GetWidgetRect(rtList, false); | |
744 rtList.Offset(rect.left, rect.top); | 714 rtList.Offset(rect.left, rect.top); |
745 rect.Union(rtList); | 715 rect.Union(rtList); |
746 return rect; | 716 return rect; |
747 } | 717 } |
748 | 718 |
749 void CFWL_ComboBox::DisForm_Layout() { | 719 void CFWL_ComboBox::DisForm_Layout() { |
750 GetClientRect(m_rtClient); | 720 GetClientRect(m_rtClient); |
751 m_rtContent = m_rtClient; | 721 m_rtContent = m_rtClient; |
752 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( | 722 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( |
753 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 723 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1099 else | 1069 else |
1100 iCurSel++; | 1070 iCurSel++; |
1101 } | 1071 } |
1102 m_iCurSel = iCurSel; | 1072 m_iCurSel = iCurSel; |
1103 SyncEditText(m_iCurSel); | 1073 SyncEditText(m_iCurSel); |
1104 return; | 1074 return; |
1105 } | 1075 } |
1106 if (m_pEdit) | 1076 if (m_pEdit) |
1107 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); | 1077 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); |
1108 } | 1078 } |
OLD | NEW |