| 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_listbox.h" | 7 #include "xfa/fwl/cfwl_listbox.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "third_party/base/ptr_util.h" | 13 #include "third_party/base/ptr_util.h" |
| 14 #include "third_party/base/stl_util.h" | 14 #include "third_party/base/stl_util.h" |
| 15 #include "xfa/fde/tto/fde_textout.h" | 15 #include "xfa/fde/tto/fde_textout.h" |
| 16 #include "xfa/fwl/core/cfwl_app.h" | 16 #include "xfa/fwl/cfwl_app.h" |
| 17 #include "xfa/fwl/core/cfwl_msgkey.h" | 17 #include "xfa/fwl/cfwl_messagekey.h" |
| 18 #include "xfa/fwl/core/cfwl_msgmouse.h" | 18 #include "xfa/fwl/cfwl_messagemouse.h" |
| 19 #include "xfa/fwl/core/cfwl_msgmousewheel.h" | 19 #include "xfa/fwl/cfwl_messagemousewheel.h" |
| 20 #include "xfa/fwl/core/cfwl_themebackground.h" | 20 #include "xfa/fwl/cfwl_themebackground.h" |
| 21 #include "xfa/fwl/core/cfwl_themepart.h" | 21 #include "xfa/fwl/cfwl_themepart.h" |
| 22 #include "xfa/fwl/core/cfwl_themetext.h" | 22 #include "xfa/fwl/cfwl_themetext.h" |
| 23 #include "xfa/fwl/core/ifwl_themeprovider.h" | 23 #include "xfa/fwl/ifwl_themeprovider.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 const int kItemTextMargin = 2; | 27 const int kItemTextMargin = 2; |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 CFWL_ListBox::CFWL_ListBox(const CFWL_App* app, | 31 CFWL_ListBox::CFWL_ListBox(const CFWL_App* app, |
| 32 std::unique_ptr<CFWL_WidgetProperties> properties, | 32 std::unique_ptr<CFWL_WidgetProperties> properties, |
| 33 CFWL_Widget* pOuter) | 33 CFWL_Widget* pOuter) |
| (...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 return; | 766 return; |
| 767 | 767 |
| 768 switch (pMessage->GetType()) { | 768 switch (pMessage->GetType()) { |
| 769 case CFWL_Message::Type::SetFocus: | 769 case CFWL_Message::Type::SetFocus: |
| 770 OnFocusChanged(pMessage, true); | 770 OnFocusChanged(pMessage, true); |
| 771 break; | 771 break; |
| 772 case CFWL_Message::Type::KillFocus: | 772 case CFWL_Message::Type::KillFocus: |
| 773 OnFocusChanged(pMessage, false); | 773 OnFocusChanged(pMessage, false); |
| 774 break; | 774 break; |
| 775 case CFWL_Message::Type::Mouse: { | 775 case CFWL_Message::Type::Mouse: { |
| 776 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | 776 CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage); |
| 777 switch (pMsg->m_dwCmd) { | 777 switch (pMsg->m_dwCmd) { |
| 778 case FWL_MouseCommand::LeftButtonDown: | 778 case FWL_MouseCommand::LeftButtonDown: |
| 779 OnLButtonDown(pMsg); | 779 OnLButtonDown(pMsg); |
| 780 break; | 780 break; |
| 781 case FWL_MouseCommand::LeftButtonUp: | 781 case FWL_MouseCommand::LeftButtonUp: |
| 782 OnLButtonUp(pMsg); | 782 OnLButtonUp(pMsg); |
| 783 break; | 783 break; |
| 784 default: | 784 default: |
| 785 break; | 785 break; |
| 786 } | 786 } |
| 787 break; | 787 break; |
| 788 } | 788 } |
| 789 case CFWL_Message::Type::MouseWheel: | 789 case CFWL_Message::Type::MouseWheel: |
| 790 OnMouseWheel(static_cast<CFWL_MsgMouseWheel*>(pMessage)); | 790 OnMouseWheel(static_cast<CFWL_MessageMouseWheel*>(pMessage)); |
| 791 break; | 791 break; |
| 792 case CFWL_Message::Type::Key: { | 792 case CFWL_Message::Type::Key: { |
| 793 CFWL_MsgKey* pMsg = static_cast<CFWL_MsgKey*>(pMessage); | 793 CFWL_MessageKey* pMsg = static_cast<CFWL_MessageKey*>(pMessage); |
| 794 if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown) | 794 if (pMsg->m_dwCmd == FWL_KeyCommand::KeyDown) |
| 795 OnKeyDown(pMsg); | 795 OnKeyDown(pMsg); |
| 796 break; | 796 break; |
| 797 } | 797 } |
| 798 default: | 798 default: |
| 799 break; | 799 break; |
| 800 } | 800 } |
| 801 CFWL_Widget::OnProcessMessage(pMessage); | 801 CFWL_Widget::OnProcessMessage(pMessage); |
| 802 } | 802 } |
| 803 | 803 |
| 804 void CFWL_ListBox::OnProcessEvent(CFWL_Event* pEvent) { | 804 void CFWL_ListBox::OnProcessEvent(CFWL_Event* pEvent) { |
| 805 if (!pEvent) | 805 if (!pEvent) |
| 806 return; | 806 return; |
| 807 if (pEvent->GetType() != CFWL_Event::Type::Scroll) | 807 if (pEvent->GetType() != CFWL_Event::Type::Scroll) |
| 808 return; | 808 return; |
| 809 | 809 |
| 810 CFWL_Widget* pSrcTarget = pEvent->m_pSrcTarget; | 810 CFWL_Widget* pSrcTarget = pEvent->m_pSrcTarget; |
| 811 if ((pSrcTarget == m_pVertScrollBar.get() && m_pVertScrollBar) || | 811 if ((pSrcTarget == m_pVertScrollBar.get() && m_pVertScrollBar) || |
| 812 (pSrcTarget == m_pHorzScrollBar.get() && m_pHorzScrollBar)) { | 812 (pSrcTarget == m_pHorzScrollBar.get() && m_pHorzScrollBar)) { |
| 813 CFWL_EvtScroll* pScrollEvent = static_cast<CFWL_EvtScroll*>(pEvent); | 813 CFWL_EventScroll* pScrollEvent = static_cast<CFWL_EventScroll*>(pEvent); |
| 814 OnScroll(static_cast<CFWL_ScrollBar*>(pSrcTarget), | 814 OnScroll(static_cast<CFWL_ScrollBar*>(pSrcTarget), |
| 815 pScrollEvent->m_iScrollCode, pScrollEvent->m_fPos); | 815 pScrollEvent->m_iScrollCode, pScrollEvent->m_fPos); |
| 816 } | 816 } |
| 817 } | 817 } |
| 818 | 818 |
| 819 void CFWL_ListBox::OnDrawWidget(CFX_Graphics* pGraphics, | 819 void CFWL_ListBox::OnDrawWidget(CFX_Graphics* pGraphics, |
| 820 const CFX_Matrix* pMatrix) { | 820 const CFX_Matrix* pMatrix) { |
| 821 DrawWidget(pGraphics, pMatrix); | 821 DrawWidget(pGraphics, pMatrix); |
| 822 } | 822 } |
| 823 | 823 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 837 } | 837 } |
| 838 } | 838 } |
| 839 if (bSet) | 839 if (bSet) |
| 840 m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); | 840 m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); |
| 841 else | 841 else |
| 842 m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); | 842 m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); |
| 843 | 843 |
| 844 Repaint(&m_rtClient); | 844 Repaint(&m_rtClient); |
| 845 } | 845 } |
| 846 | 846 |
| 847 void CFWL_ListBox::OnLButtonDown(CFWL_MsgMouse* pMsg) { | 847 void CFWL_ListBox::OnLButtonDown(CFWL_MessageMouse* pMsg) { |
| 848 m_bLButtonDown = true; | 848 m_bLButtonDown = true; |
| 849 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) | 849 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) |
| 850 SetFocus(true); | 850 SetFocus(true); |
| 851 | 851 |
| 852 CFWL_ListItem* pItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | 852 CFWL_ListItem* pItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); |
| 853 if (!pItem) | 853 if (!pItem) |
| 854 return; | 854 return; |
| 855 | 855 |
| 856 if (IsMultiSelection()) { | 856 if (IsMultiSelection()) { |
| 857 if (pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl) { | 857 if (pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 879 SetItemChecked(pItem, !bChecked); | 879 SetItemChecked(pItem, !bChecked); |
| 880 Update(); | 880 Update(); |
| 881 } | 881 } |
| 882 } | 882 } |
| 883 SetFocusItem(pItem); | 883 SetFocusItem(pItem); |
| 884 ScrollToVisible(pItem); | 884 ScrollToVisible(pItem); |
| 885 SetGrab(true); | 885 SetGrab(true); |
| 886 Repaint(&m_rtClient); | 886 Repaint(&m_rtClient); |
| 887 } | 887 } |
| 888 | 888 |
| 889 void CFWL_ListBox::OnLButtonUp(CFWL_MsgMouse* pMsg) { | 889 void CFWL_ListBox::OnLButtonUp(CFWL_MessageMouse* pMsg) { |
| 890 if (!m_bLButtonDown) | 890 if (!m_bLButtonDown) |
| 891 return; | 891 return; |
| 892 | 892 |
| 893 m_bLButtonDown = false; | 893 m_bLButtonDown = false; |
| 894 SetGrab(false); | 894 SetGrab(false); |
| 895 } | 895 } |
| 896 | 896 |
| 897 void CFWL_ListBox::OnMouseWheel(CFWL_MsgMouseWheel* pMsg) { | 897 void CFWL_ListBox::OnMouseWheel(CFWL_MessageMouseWheel* pMsg) { |
| 898 if (IsShowScrollBar(true)) | 898 if (IsShowScrollBar(true)) |
| 899 m_pVertScrollBar->GetDelegate()->OnProcessMessage(pMsg); | 899 m_pVertScrollBar->GetDelegate()->OnProcessMessage(pMsg); |
| 900 } | 900 } |
| 901 | 901 |
| 902 void CFWL_ListBox::OnKeyDown(CFWL_MsgKey* pMsg) { | 902 void CFWL_ListBox::OnKeyDown(CFWL_MessageKey* pMsg) { |
| 903 uint32_t dwKeyCode = pMsg->m_dwKeyCode; | 903 uint32_t dwKeyCode = pMsg->m_dwKeyCode; |
| 904 switch (dwKeyCode) { | 904 switch (dwKeyCode) { |
| 905 case FWL_VKEY_Tab: | 905 case FWL_VKEY_Tab: |
| 906 case FWL_VKEY_Up: | 906 case FWL_VKEY_Up: |
| 907 case FWL_VKEY_Down: | 907 case FWL_VKEY_Down: |
| 908 case FWL_VKEY_Home: | 908 case FWL_VKEY_Home: |
| 909 case FWL_VKEY_End: { | 909 case FWL_VKEY_End: { |
| 910 CFWL_ListItem* pItem = GetFocusedItem(); | 910 CFWL_ListItem* pItem = GetFocusedItem(); |
| 911 pItem = GetListItem(pItem, dwKeyCode); | 911 pItem = GetListItem(pItem, dwKeyCode); |
| 912 bool bShift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift); | 912 bool bShift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 942 SetFocusItem(pItem); | 942 SetFocusItem(pItem); |
| 943 ScrollToVisible(pItem); | 943 ScrollToVisible(pItem); |
| 944 | 944 |
| 945 CFX_RectF rtInvalidate; | 945 CFX_RectF rtInvalidate; |
| 946 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, | 946 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, |
| 947 m_pProperties->m_rtWidget.height); | 947 m_pProperties->m_rtWidget.height); |
| 948 Repaint(&rtInvalidate); | 948 Repaint(&rtInvalidate); |
| 949 } | 949 } |
| 950 | 950 |
| 951 bool CFWL_ListBox::OnScroll(CFWL_ScrollBar* pScrollBar, | 951 bool CFWL_ListBox::OnScroll(CFWL_ScrollBar* pScrollBar, |
| 952 CFWL_EvtScroll::Code dwCode, | 952 CFWL_EventScroll::Code dwCode, |
| 953 FX_FLOAT fPos) { | 953 FX_FLOAT fPos) { |
| 954 CFX_SizeF fs; | 954 CFX_SizeF fs; |
| 955 pScrollBar->GetRange(&fs.x, &fs.y); | 955 pScrollBar->GetRange(&fs.x, &fs.y); |
| 956 FX_FLOAT iCurPos = pScrollBar->GetPos(); | 956 FX_FLOAT iCurPos = pScrollBar->GetPos(); |
| 957 FX_FLOAT fStep = pScrollBar->GetStepSize(); | 957 FX_FLOAT fStep = pScrollBar->GetStepSize(); |
| 958 switch (dwCode) { | 958 switch (dwCode) { |
| 959 case CFWL_EvtScroll::Code::Min: { | 959 case CFWL_EventScroll::Code::Min: { |
| 960 fPos = fs.x; | 960 fPos = fs.x; |
| 961 break; | 961 break; |
| 962 } | 962 } |
| 963 case CFWL_EvtScroll::Code::Max: { | 963 case CFWL_EventScroll::Code::Max: { |
| 964 fPos = fs.y; | 964 fPos = fs.y; |
| 965 break; | 965 break; |
| 966 } | 966 } |
| 967 case CFWL_EvtScroll::Code::StepBackward: { | 967 case CFWL_EventScroll::Code::StepBackward: { |
| 968 fPos -= fStep; | 968 fPos -= fStep; |
| 969 if (fPos < fs.x + fStep / 2) | 969 if (fPos < fs.x + fStep / 2) |
| 970 fPos = fs.x; | 970 fPos = fs.x; |
| 971 break; | 971 break; |
| 972 } | 972 } |
| 973 case CFWL_EvtScroll::Code::StepForward: { | 973 case CFWL_EventScroll::Code::StepForward: { |
| 974 fPos += fStep; | 974 fPos += fStep; |
| 975 if (fPos > fs.y - fStep / 2) | 975 if (fPos > fs.y - fStep / 2) |
| 976 fPos = fs.y; | 976 fPos = fs.y; |
| 977 break; | 977 break; |
| 978 } | 978 } |
| 979 case CFWL_EvtScroll::Code::PageBackward: { | 979 case CFWL_EventScroll::Code::PageBackward: { |
| 980 fPos -= pScrollBar->GetPageSize(); | 980 fPos -= pScrollBar->GetPageSize(); |
| 981 if (fPos < fs.x) | 981 if (fPos < fs.x) |
| 982 fPos = fs.x; | 982 fPos = fs.x; |
| 983 break; | 983 break; |
| 984 } | 984 } |
| 985 case CFWL_EvtScroll::Code::PageForward: { | 985 case CFWL_EventScroll::Code::PageForward: { |
| 986 fPos += pScrollBar->GetPageSize(); | 986 fPos += pScrollBar->GetPageSize(); |
| 987 if (fPos > fs.y) | 987 if (fPos > fs.y) |
| 988 fPos = fs.y; | 988 fPos = fs.y; |
| 989 break; | 989 break; |
| 990 } | 990 } |
| 991 case CFWL_EvtScroll::Code::Pos: | 991 case CFWL_EventScroll::Code::Pos: |
| 992 case CFWL_EvtScroll::Code::TrackPos: | 992 case CFWL_EventScroll::Code::TrackPos: |
| 993 case CFWL_EvtScroll::Code::None: | 993 case CFWL_EventScroll::Code::None: |
| 994 break; | 994 break; |
| 995 case CFWL_EvtScroll::Code::EndScroll: | 995 case CFWL_EventScroll::Code::EndScroll: |
| 996 return false; | 996 return false; |
| 997 } | 997 } |
| 998 if (iCurPos != fPos) { | 998 if (iCurPos != fPos) { |
| 999 pScrollBar->SetPos(fPos); | 999 pScrollBar->SetPos(fPos); |
| 1000 pScrollBar->SetTrackPos(fPos); | 1000 pScrollBar->SetTrackPos(fPos); |
| 1001 Repaint(&m_rtClient); | 1001 Repaint(&m_rtClient); |
| 1002 } | 1002 } |
| 1003 return true; | 1003 return true; |
| 1004 } | 1004 } |
| 1005 | 1005 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 | 1121 |
| 1122 void CFWL_ListBox::DeleteAll() { | 1122 void CFWL_ListBox::DeleteAll() { |
| 1123 m_ItemArray.clear(); | 1123 m_ItemArray.clear(); |
| 1124 } | 1124 } |
| 1125 | 1125 |
| 1126 uint32_t CFWL_ListBox::GetItemStates(CFWL_ListItem* pItem) { | 1126 uint32_t CFWL_ListBox::GetItemStates(CFWL_ListItem* pItem) { |
| 1127 if (!pItem) | 1127 if (!pItem) |
| 1128 return 0; | 1128 return 0; |
| 1129 return pItem->m_dwStates | pItem->m_dwCheckState; | 1129 return pItem->m_dwStates | pItem->m_dwCheckState; |
| 1130 } | 1130 } |
| 1131 | |
| OLD | NEW |