| 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/basewidget/fwl_editimp.h" | 7 #include "xfa/fwl/basewidget/fwl_editimp.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "xfa/fde/fde_gedevice.h" | 12 #include "xfa/fde/fde_gedevice.h" |
| 13 #include "xfa/fde/fde_render.h" | 13 #include "xfa/fde/fde_render.h" |
| 14 #include "xfa/fee/fde_txtedtengine.h" |
| 14 #include "xfa/fee/ifde_txtedtpage.h" | 15 #include "xfa/fee/ifde_txtedtpage.h" |
| 15 #include "xfa/fwl/basewidget/fwl_caretimp.h" | 16 #include "xfa/fwl/basewidget/fwl_caretimp.h" |
| 16 #include "xfa/fwl/basewidget/fwl_comboboximp.h" | 17 #include "xfa/fwl/basewidget/fwl_comboboximp.h" |
| 17 #include "xfa/fwl/basewidget/fwl_scrollbarimp.h" | 18 #include "xfa/fwl/basewidget/fwl_scrollbarimp.h" |
| 18 #include "xfa/fwl/basewidget/ifwl_caret.h" | 19 #include "xfa/fwl/basewidget/ifwl_caret.h" |
| 19 #include "xfa/fwl/basewidget/ifwl_datetimepicker.h" | 20 #include "xfa/fwl/basewidget/ifwl_datetimepicker.h" |
| 20 #include "xfa/fwl/core/cfwl_message.h" | 21 #include "xfa/fwl/core/cfwl_message.h" |
| 21 #include "xfa/fwl/core/cfwl_themebackground.h" | 22 #include "xfa/fwl/core/cfwl_themebackground.h" |
| 22 #include "xfa/fwl/core/cfwl_themepart.h" | 23 #include "xfa/fwl/core/cfwl_themepart.h" |
| 23 #include "xfa/fwl/core/fwl_appimp.h" | 24 #include "xfa/fwl/core/fwl_appimp.h" |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 } | 749 } |
| 749 FX_BOOL CFWL_EditImp::CanUndo() { | 750 FX_BOOL CFWL_EditImp::CanUndo() { |
| 750 return m_iCurRecord >= 0; | 751 return m_iCurRecord >= 0; |
| 751 } | 752 } |
| 752 FX_BOOL CFWL_EditImp::CanRedo() { | 753 FX_BOOL CFWL_EditImp::CanRedo() { |
| 753 return m_iCurRecord < m_RecordArr.GetSize() - 1; | 754 return m_iCurRecord < m_RecordArr.GetSize() - 1; |
| 754 } | 755 } |
| 755 FWL_ERR CFWL_EditImp::SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant) { | 756 FWL_ERR CFWL_EditImp::SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant) { |
| 756 if (!m_pEdtEngine) | 757 if (!m_pEdtEngine) |
| 757 return FWL_ERR_Succeeded; | 758 return FWL_ERR_Succeeded; |
| 758 FDE_LPTXTEDTPARAMS pParams = | 759 FDE_TXTEDTPARAMS* pParams = m_pEdtEngine->GetEditParams(); |
| 759 (FDE_LPTXTEDTPARAMS)m_pEdtEngine->GetEditParams(); | |
| 760 pParams->fTabWidth = fTabWidth; | 760 pParams->fTabWidth = fTabWidth; |
| 761 pParams->bTabEquidistant = bEquidistant; | 761 pParams->bTabEquidistant = bEquidistant; |
| 762 return FWL_ERR_Succeeded; | 762 return FWL_ERR_Succeeded; |
| 763 } | 763 } |
| 764 FWL_ERR CFWL_EditImp::SetOuter(IFWL_Widget* pOuter) { | 764 FWL_ERR CFWL_EditImp::SetOuter(IFWL_Widget* pOuter) { |
| 765 m_pOuter = pOuter; | 765 m_pOuter = pOuter; |
| 766 return FWL_ERR_Succeeded; | 766 return FWL_ERR_Succeeded; |
| 767 } | 767 } |
| 768 FWL_ERR CFWL_EditImp::SetNumberRange(int32_t iMin, int32_t iMax) { | 768 FWL_ERR CFWL_EditImp::SetNumberRange(int32_t iMin, int32_t iMax) { |
| 769 m_iMin = iMin; | 769 m_iMin = iMin; |
| 770 m_iMax = iMax; | 770 m_iMax = iMax; |
| 771 m_bSetRange = TRUE; | 771 m_bSetRange = TRUE; |
| 772 return FWL_ERR_Succeeded; | 772 return FWL_ERR_Succeeded; |
| 773 } | 773 } |
| 774 void CFWL_EditImp::On_CaretChanged(IFDE_TxtEdtEngine* pEdit, | 774 void CFWL_EditImp::On_CaretChanged(CFDE_TxtEdtEngine* pEdit, |
| 775 int32_t nPage, | 775 int32_t nPage, |
| 776 FX_BOOL bVisible) { | 776 FX_BOOL bVisible) { |
| 777 if (m_rtEngine.IsEmpty()) { | 777 if (m_rtEngine.IsEmpty()) { |
| 778 return; | 778 return; |
| 779 } | 779 } |
| 780 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) { | 780 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) { |
| 781 return; | 781 return; |
| 782 } | 782 } |
| 783 FX_BOOL bRepaintContent = UpdateOffset(); | 783 FX_BOOL bRepaintContent = UpdateOffset(); |
| 784 UpdateCaret(); | 784 UpdateCaret(); |
| 785 CFX_RectF rtInvalid; | 785 CFX_RectF rtInvalid; |
| 786 rtInvalid.Set(0, 0, 0, 0); | 786 rtInvalid.Set(0, 0, 0, 0); |
| 787 FX_BOOL bRepaintScroll = FALSE; | 787 FX_BOOL bRepaintScroll = FALSE; |
| 788 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) { | 788 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) { |
| 789 IFWL_ScrollBar* pScroll = UpdateScroll(); | 789 IFWL_ScrollBar* pScroll = UpdateScroll(); |
| 790 if (pScroll) { | 790 if (pScroll) { |
| 791 pScroll->GetWidgetRect(rtInvalid); | 791 pScroll->GetWidgetRect(rtInvalid); |
| 792 bRepaintScroll = TRUE; | 792 bRepaintScroll = TRUE; |
| 793 } | 793 } |
| 794 } | 794 } |
| 795 if (bRepaintContent || bRepaintScroll) { | 795 if (bRepaintContent || bRepaintScroll) { |
| 796 if (bRepaintContent) { | 796 if (bRepaintContent) { |
| 797 rtInvalid.Union(m_rtEngine); | 797 rtInvalid.Union(m_rtEngine); |
| 798 } | 798 } |
| 799 Repaint(&rtInvalid); | 799 Repaint(&rtInvalid); |
| 800 } | 800 } |
| 801 } | 801 } |
| 802 void CFWL_EditImp::On_TextChanged(IFDE_TxtEdtEngine* pEdit, | 802 void CFWL_EditImp::On_TextChanged(CFDE_TxtEdtEngine* pEdit, |
| 803 FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo) { | 803 FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo) { |
| 804 uint32_t dwStyleEx = m_pProperties->m_dwStyleExes; | 804 uint32_t dwStyleEx = m_pProperties->m_dwStyleExes; |
| 805 if (dwStyleEx & FWL_STYLEEXT_EDT_VAlignMask) { | 805 if (dwStyleEx & FWL_STYLEEXT_EDT_VAlignMask) { |
| 806 UpdateVAlignment(); | 806 UpdateVAlignment(); |
| 807 } | 807 } |
| 808 IFDE_TxtEdtPage* page = m_pEdtEngine->GetPage(0); | 808 IFDE_TxtEdtPage* page = m_pEdtEngine->GetPage(0); |
| 809 FX_FLOAT fContentWidth = page->GetContentsBox().width; | 809 FX_FLOAT fContentWidth = page->GetContentsBox().width; |
| 810 FX_FLOAT fContentHeight = page->GetContentsBox().height; | 810 FX_FLOAT fContentHeight = page->GetContentsBox().height; |
| 811 CFX_RectF rtTemp; | 811 CFX_RectF rtTemp; |
| 812 GetClientRect(rtTemp); | 812 GetClientRect(rtTemp); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 CFWL_EvtEdtTextChanged event; | 857 CFWL_EvtEdtTextChanged event; |
| 858 event.m_pSrcTarget = m_pInterface; | 858 event.m_pSrcTarget = m_pInterface; |
| 859 event.nChangeType = ChangeInfo.nChangeType; | 859 event.nChangeType = ChangeInfo.nChangeType; |
| 860 event.wsInsert = ChangeInfo.wsInsert; | 860 event.wsInsert = ChangeInfo.wsInsert; |
| 861 event.wsDelete = ChangeInfo.wsDelete; | 861 event.wsDelete = ChangeInfo.wsDelete; |
| 862 event.wsPrevText = ChangeInfo.wsPrevText; | 862 event.wsPrevText = ChangeInfo.wsPrevText; |
| 863 DispatchEvent(&event); | 863 DispatchEvent(&event); |
| 864 LayoutScrollBar(); | 864 LayoutScrollBar(); |
| 865 Repaint(&rtTemp); | 865 Repaint(&rtTemp); |
| 866 } | 866 } |
| 867 void CFWL_EditImp::On_SelChanged(IFDE_TxtEdtEngine* pEdit) { | 867 void CFWL_EditImp::On_SelChanged(CFDE_TxtEdtEngine* pEdit) { |
| 868 CFX_RectF rtTemp; | 868 CFX_RectF rtTemp; |
| 869 GetClientRect(rtTemp); | 869 GetClientRect(rtTemp); |
| 870 Repaint(&rtTemp); | 870 Repaint(&rtTemp); |
| 871 } | 871 } |
| 872 FX_BOOL CFWL_EditImp::On_PageLoad(IFDE_TxtEdtEngine* pEdit, | 872 FX_BOOL CFWL_EditImp::On_PageLoad(CFDE_TxtEdtEngine* pEdit, |
| 873 int32_t nPageIndex, | 873 int32_t nPageIndex, |
| 874 int32_t nPurpose) { | 874 int32_t nPurpose) { |
| 875 IFDE_TxtEdtEngine* pEdtEngine = m_pEdtEngine; | 875 CFDE_TxtEdtEngine* pEdtEngine = m_pEdtEngine; |
| 876 IFDE_TxtEdtPage* pPage = pEdtEngine->GetPage(nPageIndex); | 876 IFDE_TxtEdtPage* pPage = pEdtEngine->GetPage(nPageIndex); |
| 877 if (!pPage) | 877 if (!pPage) |
| 878 return FALSE; | 878 return FALSE; |
| 879 pPage->LoadPage(nullptr, nullptr); | 879 pPage->LoadPage(nullptr, nullptr); |
| 880 return TRUE; | 880 return TRUE; |
| 881 } | 881 } |
| 882 FX_BOOL CFWL_EditImp::On_PageUnload(IFDE_TxtEdtEngine* pEdit, | 882 FX_BOOL CFWL_EditImp::On_PageUnload(CFDE_TxtEdtEngine* pEdit, |
| 883 int32_t nPageIndex, | 883 int32_t nPageIndex, |
| 884 int32_t nPurpose) { | 884 int32_t nPurpose) { |
| 885 IFDE_TxtEdtEngine* pEdtEngine = m_pEdtEngine; | 885 CFDE_TxtEdtEngine* pEdtEngine = m_pEdtEngine; |
| 886 IFDE_TxtEdtPage* pPage = pEdtEngine->GetPage(nPageIndex); | 886 IFDE_TxtEdtPage* pPage = pEdtEngine->GetPage(nPageIndex); |
| 887 if (!pPage) | 887 if (!pPage) |
| 888 return FALSE; | 888 return FALSE; |
| 889 pPage->UnloadPage(nullptr); | 889 pPage->UnloadPage(nullptr); |
| 890 return TRUE; | 890 return TRUE; |
| 891 } | 891 } |
| 892 | 892 |
| 893 void CFWL_EditImp::On_AddDoRecord(IFDE_TxtEdtEngine* pEdit, | 893 void CFWL_EditImp::On_AddDoRecord(CFDE_TxtEdtEngine* pEdit, |
| 894 const CFX_ByteStringC& bsDoRecord) { | 894 const CFX_ByteStringC& bsDoRecord) { |
| 895 AddDoRecord(bsDoRecord); | 895 AddDoRecord(bsDoRecord); |
| 896 } | 896 } |
| 897 | 897 |
| 898 FX_BOOL CFWL_EditImp::On_ValidateField(IFDE_TxtEdtEngine* pEdit, | 898 FX_BOOL CFWL_EditImp::On_Validate(CFDE_TxtEdtEngine* pEdit, |
| 899 int32_t nBlockIndex, | |
| 900 int32_t nFieldIndex, | |
| 901 const CFX_WideString& wsFieldText, | |
| 902 int32_t nCharIndex) { | |
| 903 return TRUE; | |
| 904 } | |
| 905 FX_BOOL CFWL_EditImp::On_ValidateBlock(IFDE_TxtEdtEngine* pEdit, | |
| 906 int32_t nBlockIndex) { | |
| 907 return TRUE; | |
| 908 } | |
| 909 FX_BOOL CFWL_EditImp::On_GetBlockFormatText(IFDE_TxtEdtEngine* pEdit, | |
| 910 int32_t nBlockIndex, | |
| 911 CFX_WideString& wsBlockText) { | |
| 912 return FALSE; | |
| 913 } | |
| 914 FX_BOOL CFWL_EditImp::On_Validate(IFDE_TxtEdtEngine* pEdit, | |
| 915 CFX_WideString& wsText) { | 899 CFX_WideString& wsText) { |
| 916 IFWL_Widget* pDst = GetOuter(); | 900 IFWL_Widget* pDst = GetOuter(); |
| 917 if (!pDst) { | 901 if (!pDst) { |
| 918 pDst = m_pInterface; | 902 pDst = m_pInterface; |
| 919 } | 903 } |
| 920 CFWL_EvtEdtValidate event; | 904 CFWL_EvtEdtValidate event; |
| 921 event.pDstWidget = pDst; | 905 event.pDstWidget = pDst; |
| 922 event.m_pSrcTarget = m_pInterface; | 906 event.m_pSrcTarget = m_pInterface; |
| 923 event.wsInsert = wsText; | 907 event.wsInsert = wsText; |
| 924 event.bValidate = TRUE; | 908 event.bValidate = TRUE; |
| (...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1600 } | 1584 } |
| 1601 CFWL_WidgetImpProperties prop; | 1585 CFWL_WidgetImpProperties prop; |
| 1602 prop.m_dwStyleExes = bVert ? FWL_STYLEEXT_SCB_Vert : FWL_STYLEEXT_SCB_Horz; | 1586 prop.m_dwStyleExes = bVert ? FWL_STYLEEXT_SCB_Vert : FWL_STYLEEXT_SCB_Horz; |
| 1603 prop.m_dwStates = FWL_WGTSTATE_Disabled | FWL_WGTSTATE_Invisible; | 1587 prop.m_dwStates = FWL_WGTSTATE_Disabled | FWL_WGTSTATE_Invisible; |
| 1604 prop.m_pParent = m_pInterface; | 1588 prop.m_pParent = m_pInterface; |
| 1605 prop.m_pThemeProvider = m_pProperties->m_pThemeProvider; | 1589 prop.m_pThemeProvider = m_pProperties->m_pThemeProvider; |
| 1606 IFWL_ScrollBar* pScrollBar = IFWL_ScrollBar::Create(prop, m_pInterface); | 1590 IFWL_ScrollBar* pScrollBar = IFWL_ScrollBar::Create(prop, m_pInterface); |
| 1607 pScrollBar->Initialize(); | 1591 pScrollBar->Initialize(); |
| 1608 (bVert ? &m_pVertScrollBar : &m_pHorzScrollBar)->reset(pScrollBar); | 1592 (bVert ? &m_pVertScrollBar : &m_pHorzScrollBar)->reset(pScrollBar); |
| 1609 } | 1593 } |
| 1594 |
| 1610 void CFWL_EditImp::InitEngine() { | 1595 void CFWL_EditImp::InitEngine() { |
| 1611 if (m_pEdtEngine) { | 1596 if (!m_pEdtEngine) |
| 1612 return; | 1597 m_pEdtEngine = new CFDE_TxtEdtEngine; |
| 1613 } | |
| 1614 m_pEdtEngine = IFDE_TxtEdtEngine::Create(); | |
| 1615 } | 1598 } |
| 1616 | 1599 |
| 1617 FX_BOOL FWL_ShowCaret(IFWL_Widget* pWidget, | 1600 FX_BOOL FWL_ShowCaret(IFWL_Widget* pWidget, |
| 1618 FX_BOOL bVisible, | 1601 FX_BOOL bVisible, |
| 1619 const CFX_RectF* pRtAnchor) { | 1602 const CFX_RectF* pRtAnchor) { |
| 1620 CXFA_FFWidget* pXFAWidget = | 1603 CXFA_FFWidget* pXFAWidget = |
| 1621 static_cast<CXFA_FFWidget*>(pWidget->GetPrivateData(pWidget)); | 1604 static_cast<CXFA_FFWidget*>(pWidget->GetPrivateData(pWidget)); |
| 1622 if (!pXFAWidget) | 1605 if (!pXFAWidget) |
| 1623 return FALSE; | 1606 return FALSE; |
| 1624 | 1607 |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2170 } | 2153 } |
| 2171 CFX_RectF rect; | 2154 CFX_RectF rect; |
| 2172 m_pOwner->GetWidgetRect(rect); | 2155 m_pOwner->GetWidgetRect(rect); |
| 2173 CFX_RectF rtInvalidate; | 2156 CFX_RectF rtInvalidate; |
| 2174 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); | 2157 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); |
| 2175 m_pOwner->Repaint(&rtInvalidate); | 2158 m_pOwner->Repaint(&rtInvalidate); |
| 2176 } | 2159 } |
| 2177 return TRUE; | 2160 return TRUE; |
| 2178 } | 2161 } |
| 2179 void CFWL_EditImpDelegate::DoCursor(CFWL_MsgMouse* pMsg) {} | 2162 void CFWL_EditImpDelegate::DoCursor(CFWL_MsgMouse* pMsg) {} |
| OLD | NEW |