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/ifwl_edit.h" | 7 #include "xfa/fwl/core/ifwl_edit.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 m_iMin(-1), | 69 m_iMin(-1), |
70 m_iMax(0xFFFFFFF), | 70 m_iMax(0xFFFFFFF), |
71 m_backColor(0), | 71 m_backColor(0), |
72 m_updateBackColor(FALSE), | 72 m_updateBackColor(FALSE), |
73 m_iCurRecord(-1), | 73 m_iCurRecord(-1), |
74 m_iMaxRecord(128) { | 74 m_iMaxRecord(128) { |
75 m_rtClient.Reset(); | 75 m_rtClient.Reset(); |
76 m_rtEngine.Reset(); | 76 m_rtEngine.Reset(); |
77 m_rtStatic.Reset(); | 77 m_rtStatic.Reset(); |
78 | 78 |
79 SetDelegate(pdfium::MakeUnique<CFWL_EditImpDelegate>(this)); | |
80 InitCaret(); | 79 InitCaret(); |
81 if (!m_pEdtEngine) | 80 if (!m_pEdtEngine) |
82 InitEngine(); | 81 InitEngine(); |
83 } | 82 } |
84 | 83 |
85 IFWL_Edit::~IFWL_Edit() { | 84 IFWL_Edit::~IFWL_Edit() { |
86 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) | 85 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) |
87 ShowCaret(FALSE); | 86 ShowCaret(FALSE); |
88 | 87 |
89 ClearRecord(); | 88 ClearRecord(); |
(...skipping 1489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1579 case -2: { | 1578 case -2: { |
1580 CFWL_EvtEdtTextFull textFullEvent; | 1579 CFWL_EvtEdtTextFull textFullEvent; |
1581 textFullEvent.m_pSrcTarget = this; | 1580 textFullEvent.m_pSrcTarget = this; |
1582 DispatchEvent(&textFullEvent); | 1581 DispatchEvent(&textFullEvent); |
1583 break; | 1582 break; |
1584 } | 1583 } |
1585 default: {} | 1584 default: {} |
1586 } | 1585 } |
1587 } | 1586 } |
1588 | 1587 |
1589 CFWL_EditImpDelegate::CFWL_EditImpDelegate(IFWL_Edit* pOwner) | 1588 void IFWL_Edit::OnProcessMessage(CFWL_Message* pMessage) { |
1590 : m_pOwner(pOwner) {} | |
1591 | |
1592 void CFWL_EditImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
1593 if (!pMessage) | 1589 if (!pMessage) |
1594 return; | 1590 return; |
1595 | 1591 |
1596 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); | 1592 CFWL_MessageType dwMsgCode = pMessage->GetClassID(); |
1597 switch (dwMsgCode) { | 1593 switch (dwMsgCode) { |
1598 case CFWL_MessageType::Activate: { | 1594 case CFWL_MessageType::Activate: |
1599 DoActivate(static_cast<CFWL_MsgActivate*>(pMessage)); | 1595 DoActivate(static_cast<CFWL_MsgActivate*>(pMessage)); |
1600 break; | 1596 break; |
1601 } | 1597 case CFWL_MessageType::Deactivate: |
1602 case CFWL_MessageType::Deactivate: { | |
1603 DoDeactivate(static_cast<CFWL_MsgDeactivate*>(pMessage)); | 1598 DoDeactivate(static_cast<CFWL_MsgDeactivate*>(pMessage)); |
1604 break; | 1599 break; |
1605 } | |
1606 case CFWL_MessageType::SetFocus: | 1600 case CFWL_MessageType::SetFocus: |
1607 case CFWL_MessageType::KillFocus: { | 1601 case CFWL_MessageType::KillFocus: |
1608 OnFocusChanged(pMessage, dwMsgCode == CFWL_MessageType::SetFocus); | 1602 OnFocusChanged(pMessage, dwMsgCode == CFWL_MessageType::SetFocus); |
1609 break; | 1603 break; |
1610 } | |
1611 case CFWL_MessageType::Mouse: { | 1604 case CFWL_MessageType::Mouse: { |
1612 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | 1605 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); |
1613 switch (pMsg->m_dwCmd) { | 1606 switch (pMsg->m_dwCmd) { |
1614 case FWL_MouseCommand::LeftButtonDown: { | 1607 case FWL_MouseCommand::LeftButtonDown: |
1615 OnLButtonDown(pMsg); | 1608 OnLButtonDown(pMsg); |
1616 break; | 1609 break; |
1617 } | 1610 case FWL_MouseCommand::LeftButtonUp: |
1618 case FWL_MouseCommand::LeftButtonUp: { | |
1619 OnLButtonUp(pMsg); | 1611 OnLButtonUp(pMsg); |
1620 break; | 1612 break; |
1621 } | 1613 case FWL_MouseCommand::LeftButtonDblClk: |
1622 case FWL_MouseCommand::LeftButtonDblClk: { | |
1623 OnButtonDblClk(pMsg); | 1614 OnButtonDblClk(pMsg); |
1624 break; | 1615 break; |
1625 } | 1616 case FWL_MouseCommand::Move: |
1626 case FWL_MouseCommand::Move: { | |
1627 OnMouseMove(pMsg); | 1617 OnMouseMove(pMsg); |
1628 break; | 1618 break; |
1629 } | 1619 case FWL_MouseCommand::RightButtonDown: |
1630 case FWL_MouseCommand::RightButtonDown: { | |
1631 DoButtonDown(pMsg); | 1620 DoButtonDown(pMsg); |
1632 break; | 1621 break; |
1633 } | |
1634 default: | 1622 default: |
1635 break; | 1623 break; |
1636 } | 1624 } |
1637 break; | 1625 break; |
1638 } | 1626 } |
1639 case CFWL_MessageType::Key: { | 1627 case CFWL_MessageType::Key: { |
1640 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); | 1628 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); |
1641 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) | 1629 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) |
1642 OnKeyDown(pKey); | 1630 OnKeyDown(pKey); |
1643 else if (pKey->m_dwCmd == FWL_KeyCommand::Char) | 1631 else if (pKey->m_dwCmd == FWL_KeyCommand::Char) |
1644 OnChar(pKey); | 1632 OnChar(pKey); |
1645 break; | 1633 break; |
1646 } | 1634 } |
1647 default: { break; } | 1635 default: |
| 1636 break; |
1648 } | 1637 } |
1649 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); | 1638 IFWL_Widget::OnProcessMessage(pMessage); |
1650 } | 1639 } |
1651 | 1640 |
1652 void CFWL_EditImpDelegate::OnProcessEvent(CFWL_Event* pEvent) { | 1641 void IFWL_Edit::OnProcessEvent(CFWL_Event* pEvent) { |
1653 if (!pEvent) | 1642 if (!pEvent) |
1654 return; | 1643 return; |
1655 if (pEvent->GetClassID() != CFWL_EventType::Scroll) | 1644 if (pEvent->GetClassID() != CFWL_EventType::Scroll) |
1656 return; | 1645 return; |
1657 | 1646 |
1658 IFWL_Widget* pSrcTarget = pEvent->m_pSrcTarget; | 1647 IFWL_Widget* pSrcTarget = pEvent->m_pSrcTarget; |
1659 if ((pSrcTarget == m_pOwner->m_pVertScrollBar.get() && | 1648 if ((pSrcTarget == m_pVertScrollBar.get() && m_pVertScrollBar) || |
1660 m_pOwner->m_pVertScrollBar) || | 1649 (pSrcTarget == m_pHorzScrollBar.get() && m_pHorzScrollBar)) { |
1661 (pSrcTarget == m_pOwner->m_pHorzScrollBar.get() && | |
1662 m_pOwner->m_pHorzScrollBar)) { | |
1663 CFWL_EvtScroll* pScrollEvent = static_cast<CFWL_EvtScroll*>(pEvent); | 1650 CFWL_EvtScroll* pScrollEvent = static_cast<CFWL_EvtScroll*>(pEvent); |
1664 OnScroll(static_cast<IFWL_ScrollBar*>(pSrcTarget), | 1651 OnScroll(static_cast<IFWL_ScrollBar*>(pSrcTarget), |
1665 pScrollEvent->m_iScrollCode, pScrollEvent->m_fPos); | 1652 pScrollEvent->m_iScrollCode, pScrollEvent->m_fPos); |
1666 } | 1653 } |
1667 } | 1654 } |
1668 | 1655 |
1669 void CFWL_EditImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | 1656 void IFWL_Edit::OnDrawWidget(CFX_Graphics* pGraphics, |
1670 const CFX_Matrix* pMatrix) { | 1657 const CFX_Matrix* pMatrix) { |
1671 m_pOwner->DrawWidget(pGraphics, pMatrix); | 1658 DrawWidget(pGraphics, pMatrix); |
1672 } | 1659 } |
1673 | 1660 |
1674 void CFWL_EditImpDelegate::DoActivate(CFWL_MsgActivate* pMsg) { | 1661 void IFWL_Edit::DoActivate(CFWL_MsgActivate* pMsg) { |
1675 m_pOwner->m_pProperties->m_dwStates |= ~FWL_WGTSTATE_Deactivated; | 1662 m_pProperties->m_dwStates |= ~FWL_WGTSTATE_Deactivated; |
1676 m_pOwner->Repaint(&m_pOwner->m_rtClient); | 1663 Repaint(&m_rtClient); |
1677 } | 1664 } |
1678 void CFWL_EditImpDelegate::DoDeactivate(CFWL_MsgDeactivate* pMsg) { | 1665 |
1679 m_pOwner->m_pProperties->m_dwStates &= FWL_WGTSTATE_Deactivated; | 1666 void IFWL_Edit::DoDeactivate(CFWL_MsgDeactivate* pMsg) { |
1680 m_pOwner->Repaint(&m_pOwner->m_rtClient); | 1667 m_pProperties->m_dwStates &= FWL_WGTSTATE_Deactivated; |
| 1668 Repaint(&m_rtClient); |
1681 } | 1669 } |
1682 void CFWL_EditImpDelegate::DoButtonDown(CFWL_MsgMouse* pMsg) { | 1670 |
1683 if ((m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) { | 1671 void IFWL_Edit::DoButtonDown(CFWL_MsgMouse* pMsg) { |
1684 m_pOwner->SetFocus(TRUE); | 1672 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) |
1685 } | 1673 SetFocus(TRUE); |
1686 if (!m_pOwner->m_pEdtEngine) { | 1674 if (!m_pEdtEngine) |
1687 m_pOwner->UpdateEditEngine(); | 1675 UpdateEditEngine(); |
1688 } | 1676 |
1689 IFDE_TxtEdtPage* pPage = m_pOwner->m_pEdtEngine->GetPage(0); | 1677 IFDE_TxtEdtPage* pPage = m_pEdtEngine->GetPage(0); |
1690 if (!pPage) | 1678 if (!pPage) |
1691 return; | 1679 return; |
1692 CFX_PointF pt(pMsg->m_fx, pMsg->m_fy); | 1680 CFX_PointF pt(pMsg->m_fx, pMsg->m_fy); |
1693 m_pOwner->DeviceToEngine(pt); | 1681 DeviceToEngine(pt); |
1694 FX_BOOL bBefore = TRUE; | 1682 FX_BOOL bBefore = TRUE; |
1695 int32_t nIndex = pPage->GetCharIndex(pt, bBefore); | 1683 int32_t nIndex = pPage->GetCharIndex(pt, bBefore); |
1696 if (nIndex < 0) { | 1684 if (nIndex < 0) |
1697 nIndex = 0; | 1685 nIndex = 0; |
1698 } | 1686 |
1699 m_pOwner->m_pEdtEngine->SetCaretPos(nIndex, bBefore); | 1687 m_pEdtEngine->SetCaretPos(nIndex, bBefore); |
1700 } | 1688 } |
1701 void CFWL_EditImpDelegate::OnFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet) { | 1689 |
1702 uint32_t dwStyleEx = m_pOwner->GetStylesEx(); | 1690 void IFWL_Edit::OnFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet) { |
| 1691 uint32_t dwStyleEx = GetStylesEx(); |
1703 bool bRepaint = !!(dwStyleEx & FWL_STYLEEXT_EDT_InnerCaret); | 1692 bool bRepaint = !!(dwStyleEx & FWL_STYLEEXT_EDT_InnerCaret); |
1704 if (bSet) { | 1693 if (bSet) { |
1705 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | 1694 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; |
1706 if (!m_pOwner->m_pEdtEngine) { | 1695 if (!m_pEdtEngine) |
1707 m_pOwner->UpdateEditEngine(); | 1696 UpdateEditEngine(); |
1708 } | 1697 |
1709 m_pOwner->UpdateVAlignment(); | 1698 UpdateVAlignment(); |
1710 m_pOwner->UpdateOffset(); | 1699 UpdateOffset(); |
1711 m_pOwner->UpdateCaret(); | 1700 UpdateCaret(); |
1712 } else if (m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) { | 1701 } else if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) { |
1713 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | 1702 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; |
1714 m_pOwner->ShowCaret(FALSE); | 1703 ShowCaret(FALSE); |
1715 if (m_pOwner->m_pEdtEngine && | 1704 if (m_pEdtEngine && (dwStyleEx & FWL_STYLEEXT_EDT_NoHideSel) == 0) { |
1716 (dwStyleEx & FWL_STYLEEXT_EDT_NoHideSel) == 0) { | 1705 int32_t nSel = CountSelRanges(); |
1717 int32_t nSel = m_pOwner->CountSelRanges(); | |
1718 if (nSel > 0) { | 1706 if (nSel > 0) { |
1719 m_pOwner->ClearSelections(); | 1707 ClearSelections(); |
1720 bRepaint = TRUE; | 1708 bRepaint = TRUE; |
1721 } | 1709 } |
1722 m_pOwner->SetCaretPos(0); | 1710 SetCaretPos(0); |
1723 m_pOwner->UpdateOffset(); | 1711 UpdateOffset(); |
1724 } | 1712 } |
1725 m_pOwner->ClearRecord(); | 1713 ClearRecord(); |
1726 } | 1714 } |
1727 m_pOwner->LayoutScrollBar(); | 1715 LayoutScrollBar(); |
1728 if (bRepaint) { | 1716 if (bRepaint) { |
1729 CFX_RectF rtInvalidate; | 1717 CFX_RectF rtInvalidate; |
1730 rtInvalidate.Set(0, 0, m_pOwner->m_pProperties->m_rtWidget.width, | 1718 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, |
1731 m_pOwner->m_pProperties->m_rtWidget.height); | 1719 m_pProperties->m_rtWidget.height); |
1732 m_pOwner->Repaint(&rtInvalidate); | 1720 Repaint(&rtInvalidate); |
1733 } | 1721 } |
1734 } | 1722 } |
1735 void CFWL_EditImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { | 1723 |
1736 DoCursor(pMsg); | 1724 void IFWL_Edit::OnLButtonDown(CFWL_MsgMouse* pMsg) { |
1737 if (m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { | 1725 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
1738 return; | 1726 return; |
1739 } | 1727 |
1740 m_pOwner->m_bLButtonDown = TRUE; | 1728 m_bLButtonDown = TRUE; |
1741 m_pOwner->SetGrab(TRUE); | 1729 SetGrab(TRUE); |
1742 DoButtonDown(pMsg); | 1730 DoButtonDown(pMsg); |
1743 int32_t nIndex = m_pOwner->m_pEdtEngine->GetCaretPos(); | 1731 int32_t nIndex = m_pEdtEngine->GetCaretPos(); |
1744 FX_BOOL bRepaint = FALSE; | 1732 FX_BOOL bRepaint = FALSE; |
1745 int32_t iCount = m_pOwner->m_pEdtEngine->CountSelRanges(); | 1733 int32_t iCount = m_pEdtEngine->CountSelRanges(); |
1746 if (iCount > 0) { | 1734 if (iCount > 0) { |
1747 m_pOwner->m_pEdtEngine->ClearSelection(); | 1735 m_pEdtEngine->ClearSelection(); |
1748 bRepaint = TRUE; | 1736 bRepaint = TRUE; |
1749 } | 1737 } |
| 1738 |
1750 bool bShift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift); | 1739 bool bShift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift); |
1751 if (bShift && m_pOwner->m_nSelStart != nIndex) { | 1740 if (bShift && m_nSelStart != nIndex) { |
1752 int32_t iStart = std::min(m_pOwner->m_nSelStart, nIndex); | 1741 int32_t iStart = std::min(m_nSelStart, nIndex); |
1753 int32_t iEnd = std::max(m_pOwner->m_nSelStart, nIndex); | 1742 int32_t iEnd = std::max(m_nSelStart, nIndex); |
1754 m_pOwner->m_pEdtEngine->AddSelRange(iStart, iEnd - iStart); | 1743 m_pEdtEngine->AddSelRange(iStart, iEnd - iStart); |
1755 bRepaint = TRUE; | 1744 bRepaint = TRUE; |
1756 } else { | 1745 } else { |
1757 m_pOwner->m_nSelStart = nIndex; | 1746 m_nSelStart = nIndex; |
1758 } | 1747 } |
1759 if (bRepaint) { | 1748 if (bRepaint) |
1760 m_pOwner->Repaint(&m_pOwner->m_rtEngine); | 1749 Repaint(&m_rtEngine); |
| 1750 } |
| 1751 |
| 1752 void IFWL_Edit::OnLButtonUp(CFWL_MsgMouse* pMsg) { |
| 1753 m_bLButtonDown = FALSE; |
| 1754 SetGrab(FALSE); |
| 1755 } |
| 1756 |
| 1757 void IFWL_Edit::OnButtonDblClk(CFWL_MsgMouse* pMsg) { |
| 1758 if (!m_pEdtEngine) |
| 1759 return; |
| 1760 |
| 1761 IFDE_TxtEdtPage* pPage = m_pEdtEngine->GetPage(0); |
| 1762 if (!pPage) |
| 1763 return; |
| 1764 |
| 1765 CFX_PointF pt(pMsg->m_fx, pMsg->m_fy); |
| 1766 DeviceToEngine(pt); |
| 1767 int32_t nCount = 0; |
| 1768 int32_t nIndex = pPage->SelectWord(pt, nCount); |
| 1769 if (nIndex < 0) |
| 1770 return; |
| 1771 |
| 1772 m_pEdtEngine->AddSelRange(nIndex, nCount); |
| 1773 m_pEdtEngine->SetCaretPos(nIndex + nCount - 1, FALSE); |
| 1774 Repaint(&m_rtEngine); |
| 1775 } |
| 1776 |
| 1777 void IFWL_Edit::OnMouseMove(CFWL_MsgMouse* pMsg) { |
| 1778 if (!m_pEdtEngine) |
| 1779 return; |
| 1780 if (m_nSelStart == -1 || !m_bLButtonDown) |
| 1781 return; |
| 1782 |
| 1783 IFDE_TxtEdtPage* pPage = m_pEdtEngine->GetPage(0); |
| 1784 if (!pPage) |
| 1785 return; |
| 1786 |
| 1787 CFX_PointF pt(pMsg->m_fx, pMsg->m_fy); |
| 1788 DeviceToEngine(pt); |
| 1789 FX_BOOL bBefore = TRUE; |
| 1790 int32_t nIndex = pPage->GetCharIndex(pt, bBefore); |
| 1791 m_pEdtEngine->SetCaretPos(nIndex, bBefore); |
| 1792 nIndex = m_pEdtEngine->GetCaretPos(); |
| 1793 m_pEdtEngine->ClearSelection(); |
| 1794 if (nIndex != m_nSelStart) { |
| 1795 int32_t nLen = m_pEdtEngine->GetTextLength(); |
| 1796 if (m_nSelStart >= nLen) |
| 1797 m_nSelStart = nLen; |
| 1798 |
| 1799 m_pEdtEngine->AddSelRange(std::min(m_nSelStart, nIndex), |
| 1800 FXSYS_abs(nIndex - m_nSelStart)); |
1761 } | 1801 } |
1762 } | 1802 } |
1763 void CFWL_EditImpDelegate::OnLButtonUp(CFWL_MsgMouse* pMsg) { | 1803 |
1764 DoCursor(pMsg); | 1804 void IFWL_Edit::OnKeyDown(CFWL_MsgKey* pMsg) { |
1765 m_pOwner->m_bLButtonDown = FALSE; | 1805 if (!m_pEdtEngine) |
1766 m_pOwner->SetGrab(FALSE); | |
1767 } | |
1768 void CFWL_EditImpDelegate::OnButtonDblClk(CFWL_MsgMouse* pMsg) { | |
1769 if (!m_pOwner->m_pEdtEngine) | |
1770 return; | 1806 return; |
1771 DoCursor(pMsg); | 1807 |
1772 IFDE_TxtEdtPage* pPage = m_pOwner->m_pEdtEngine->GetPage(0); | |
1773 if (!pPage) | |
1774 return; | |
1775 CFX_PointF pt(pMsg->m_fx, pMsg->m_fy); | |
1776 m_pOwner->DeviceToEngine(pt); | |
1777 int32_t nCount = 0; | |
1778 int32_t nIndex = pPage->SelectWord(pt, nCount); | |
1779 if (nIndex < 0) { | |
1780 return; | |
1781 } | |
1782 m_pOwner->m_pEdtEngine->AddSelRange(nIndex, nCount); | |
1783 m_pOwner->m_pEdtEngine->SetCaretPos(nIndex + nCount - 1, FALSE); | |
1784 m_pOwner->Repaint(&m_pOwner->m_rtEngine); | |
1785 } | |
1786 void CFWL_EditImpDelegate::OnMouseMove(CFWL_MsgMouse* pMsg) { | |
1787 if (!m_pOwner->m_pEdtEngine) | |
1788 return; | |
1789 DoCursor(pMsg); | |
1790 if (m_pOwner->m_nSelStart == -1 || !m_pOwner->m_bLButtonDown) { | |
1791 return; | |
1792 } | |
1793 IFDE_TxtEdtPage* pPage = m_pOwner->m_pEdtEngine->GetPage(0); | |
1794 if (!pPage) | |
1795 return; | |
1796 CFX_PointF pt(pMsg->m_fx, pMsg->m_fy); | |
1797 m_pOwner->DeviceToEngine(pt); | |
1798 FX_BOOL bBefore = TRUE; | |
1799 int32_t nIndex = pPage->GetCharIndex(pt, bBefore); | |
1800 m_pOwner->m_pEdtEngine->SetCaretPos(nIndex, bBefore); | |
1801 nIndex = m_pOwner->m_pEdtEngine->GetCaretPos(); | |
1802 m_pOwner->m_pEdtEngine->ClearSelection(); | |
1803 if (nIndex != m_pOwner->m_nSelStart) { | |
1804 int32_t nLen = m_pOwner->m_pEdtEngine->GetTextLength(); | |
1805 if (m_pOwner->m_nSelStart >= nLen) { | |
1806 m_pOwner->m_nSelStart = nLen; | |
1807 } | |
1808 m_pOwner->m_pEdtEngine->AddSelRange( | |
1809 std::min(m_pOwner->m_nSelStart, nIndex), | |
1810 FXSYS_abs(nIndex - m_pOwner->m_nSelStart)); | |
1811 } | |
1812 } | |
1813 void CFWL_EditImpDelegate::OnKeyDown(CFWL_MsgKey* pMsg) { | |
1814 if (!m_pOwner->m_pEdtEngine) | |
1815 return; | |
1816 FDE_TXTEDTMOVECARET MoveCaret = MC_MoveNone; | 1808 FDE_TXTEDTMOVECARET MoveCaret = MC_MoveNone; |
1817 bool bShift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift); | 1809 bool bShift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift); |
1818 bool bCtrl = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl); | 1810 bool bCtrl = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl); |
1819 uint32_t dwKeyCode = pMsg->m_dwKeyCode; | 1811 uint32_t dwKeyCode = pMsg->m_dwKeyCode; |
1820 switch (dwKeyCode) { | 1812 switch (dwKeyCode) { |
1821 case FWL_VKEY_Left: { | 1813 case FWL_VKEY_Left: { |
1822 MoveCaret = MC_Left; | 1814 MoveCaret = MC_Left; |
1823 break; | 1815 break; |
1824 } | 1816 } |
1825 case FWL_VKEY_Right: { | 1817 case FWL_VKEY_Right: { |
1826 MoveCaret = MC_Right; | 1818 MoveCaret = MC_Right; |
1827 break; | 1819 break; |
1828 } | 1820 } |
1829 case FWL_VKEY_Up: { | 1821 case FWL_VKEY_Up: { |
1830 MoveCaret = MC_Up; | 1822 MoveCaret = MC_Up; |
1831 break; | 1823 break; |
1832 } | 1824 } |
1833 case FWL_VKEY_Down: { | 1825 case FWL_VKEY_Down: { |
1834 MoveCaret = MC_Down; | 1826 MoveCaret = MC_Down; |
1835 break; | 1827 break; |
1836 } | 1828 } |
1837 case FWL_VKEY_Home: { | 1829 case FWL_VKEY_Home: { |
1838 if (bCtrl) { | 1830 MoveCaret = bCtrl ? MC_Home : MC_LineStart; |
1839 MoveCaret = MC_Home; | |
1840 } else { | |
1841 MoveCaret = MC_LineStart; | |
1842 } | |
1843 break; | 1831 break; |
1844 } | 1832 } |
1845 case FWL_VKEY_End: { | 1833 case FWL_VKEY_End: { |
1846 if (bCtrl) { | 1834 MoveCaret = bCtrl ? MC_End : MC_LineEnd; |
1847 MoveCaret = MC_End; | |
1848 } else { | |
1849 MoveCaret = MC_LineEnd; | |
1850 } | |
1851 break; | 1835 break; |
1852 } | 1836 } |
1853 case FWL_VKEY_Insert: { | 1837 case FWL_VKEY_Insert: |
1854 break; | 1838 break; |
1855 } | |
1856 case FWL_VKEY_Delete: { | 1839 case FWL_VKEY_Delete: { |
1857 if ((m_pOwner->m_pProperties->m_dwStyleExes & | 1840 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) || |
1858 FWL_STYLEEXT_EDT_ReadOnly) || | 1841 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { |
1859 (m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { | |
1860 break; | 1842 break; |
1861 } | 1843 } |
1862 int32_t nCaret = m_pOwner->m_pEdtEngine->GetCaretPos(); | 1844 int32_t nCaret = m_pEdtEngine->GetCaretPos(); |
1863 #if (_FX_OS_ == _FX_MACOSX_) | 1845 #if (_FX_OS_ == _FX_MACOSX_) |
1864 m_pOwner->m_pEdtEngine->Delete(nCaret, TRUE); | 1846 m_pEdtEngine->Delete(nCaret, TRUE); |
1865 #else | 1847 #else |
1866 m_pOwner->m_pEdtEngine->Delete(nCaret); | 1848 m_pEdtEngine->Delete(nCaret); |
1867 #endif | 1849 #endif |
1868 break; | 1850 break; |
1869 } | 1851 } |
1870 case FWL_VKEY_F2: { | 1852 case FWL_VKEY_F2: |
1871 break; | 1853 break; |
1872 } | |
1873 case FWL_VKEY_Tab: { | 1854 case FWL_VKEY_Tab: { |
1874 m_pOwner->DispatchKeyEvent(pMsg); | 1855 DispatchKeyEvent(pMsg); |
1875 break; | 1856 break; |
1876 } | 1857 } |
1877 default: { | 1858 default: { |
1878 #if (_FX_OS_ == _FX_MACOSX_) | 1859 #if (_FX_OS_ == _FX_MACOSX_) |
1879 if (pMsg->m_dwFlags & FWL_KEYFLAG_Command) { | 1860 if (pMsg->m_dwFlags & FWL_KEYFLAG_Command) { |
1880 #else | 1861 #else |
1881 if (pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl) { | 1862 if (pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl) { |
1882 #endif | 1863 #endif |
1883 if (dwKeyCode == 0x43 || dwKeyCode == 0x63) { | 1864 if (dwKeyCode == 0x43 || dwKeyCode == 0x63) { |
1884 m_pOwner->DoClipboard(1); | 1865 DoClipboard(1); |
1885 return; | 1866 return; |
1886 } | 1867 } |
1887 if (dwKeyCode == 0x58 || dwKeyCode == 0x78) { | 1868 if (dwKeyCode == 0x58 || dwKeyCode == 0x78) { |
1888 m_pOwner->DoClipboard(2); | 1869 DoClipboard(2); |
1889 return; | 1870 return; |
1890 } | 1871 } |
1891 if (dwKeyCode == 0x56 || dwKeyCode == 0x76) { | 1872 if (dwKeyCode == 0x56 || dwKeyCode == 0x76) { |
1892 m_pOwner->DoClipboard(3); | 1873 DoClipboard(3); |
1893 return; | 1874 return; |
1894 } | 1875 } |
1895 } | 1876 } |
1896 } | 1877 } |
1897 } | 1878 } |
1898 if (MoveCaret != MC_MoveNone) { | 1879 if (MoveCaret != MC_MoveNone) |
1899 m_pOwner->m_pEdtEngine->MoveCaretPos(MoveCaret, bShift, bCtrl); | 1880 m_pEdtEngine->MoveCaretPos(MoveCaret, bShift, bCtrl); |
1900 } | |
1901 } | 1881 } |
1902 void CFWL_EditImpDelegate::OnChar(CFWL_MsgKey* pMsg) { | 1882 |
1903 if ((m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) || | 1883 void IFWL_Edit::OnChar(CFWL_MsgKey* pMsg) { |
1904 (m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { | 1884 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) || |
| 1885 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { |
1905 return; | 1886 return; |
1906 } | 1887 } |
1907 if (!m_pOwner->m_pEdtEngine) | 1888 if (!m_pEdtEngine) |
1908 return; | 1889 return; |
| 1890 |
1909 int32_t iError = 0; | 1891 int32_t iError = 0; |
1910 FX_WCHAR c = (FX_WCHAR)pMsg->m_dwKeyCode; | 1892 FX_WCHAR c = (FX_WCHAR)pMsg->m_dwKeyCode; |
1911 int32_t nCaret = m_pOwner->m_pEdtEngine->GetCaretPos(); | 1893 int32_t nCaret = m_pEdtEngine->GetCaretPos(); |
1912 switch (c) { | 1894 switch (c) { |
1913 case FWL_VKEY_Back: { | 1895 case FWL_VKEY_Back: |
1914 m_pOwner->m_pEdtEngine->Delete(nCaret, TRUE); | 1896 m_pEdtEngine->Delete(nCaret, TRUE); |
1915 break; | 1897 break; |
1916 } | 1898 case 0x0A: |
1917 case 0x0A: { | |
1918 break; | 1899 break; |
1919 } | 1900 case FWL_VKEY_Escape: |
1920 case FWL_VKEY_Escape: { | |
1921 break; | 1901 break; |
1922 } | |
1923 case FWL_VKEY_Tab: { | 1902 case FWL_VKEY_Tab: { |
1924 iError = m_pOwner->m_pEdtEngine->Insert(nCaret, L"\t", 1); | 1903 iError = m_pEdtEngine->Insert(nCaret, L"\t", 1); |
1925 break; | 1904 break; |
1926 } | 1905 } |
1927 case FWL_VKEY_Return: { | 1906 case FWL_VKEY_Return: { |
1928 if (m_pOwner->m_pProperties->m_dwStyleExes & | 1907 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_WantReturn) { |
1929 FWL_STYLEEXT_EDT_WantReturn) { | 1908 iError = m_pEdtEngine->Insert(nCaret, L"\n", 1); |
1930 iError = m_pOwner->m_pEdtEngine->Insert(nCaret, L"\n", 1); | |
1931 } | 1909 } |
1932 break; | 1910 break; |
1933 } | 1911 } |
1934 default: { | 1912 default: { |
1935 if (!m_pOwner->m_pWidgetMgr->IsFormDisabled()) { | 1913 if (!m_pWidgetMgr->IsFormDisabled()) { |
1936 if (m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_Number) { | 1914 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_Number) { |
1937 if (((pMsg->m_dwKeyCode < FWL_VKEY_0) && | 1915 if (((pMsg->m_dwKeyCode < FWL_VKEY_0) && |
1938 (pMsg->m_dwKeyCode != 0x2E && pMsg->m_dwKeyCode != 0x2D)) || | 1916 (pMsg->m_dwKeyCode != 0x2E && pMsg->m_dwKeyCode != 0x2D)) || |
1939 pMsg->m_dwKeyCode > FWL_VKEY_9) { | 1917 pMsg->m_dwKeyCode > FWL_VKEY_9) { |
1940 break; | 1918 break; |
1941 } | 1919 } |
1942 if (!m_pOwner->ValidateNumberChar(c)) { | 1920 if (!ValidateNumberChar(c)) |
1943 break; | 1921 break; |
1944 } | |
1945 } | 1922 } |
1946 } | 1923 } |
1947 #if (_FX_OS_ == _FX_MACOSX_) | 1924 #if (_FX_OS_ == _FX_MACOSX_) |
1948 if (pMsg->m_dwFlags & FWL_KEYFLAG_Command) | 1925 if (pMsg->m_dwFlags & FWL_KEYFLAG_Command) |
1949 #else | 1926 #else |
1950 if (pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl) | 1927 if (pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl) |
1951 #endif | 1928 #endif |
1952 { | 1929 { |
1953 break; | 1930 break; |
1954 } | 1931 } |
1955 iError = m_pOwner->m_pEdtEngine->Insert(nCaret, &c, 1); | 1932 iError = m_pEdtEngine->Insert(nCaret, &c, 1); |
1956 break; | 1933 break; |
1957 } | 1934 } |
1958 } | 1935 } |
1959 if (iError < 0) { | 1936 if (iError < 0) |
1960 m_pOwner->ProcessInsertError(iError); | 1937 ProcessInsertError(iError); |
1961 } | |
1962 } | 1938 } |
1963 FX_BOOL CFWL_EditImpDelegate::OnScroll(IFWL_ScrollBar* pScrollBar, | 1939 |
1964 uint32_t dwCode, | 1940 FX_BOOL IFWL_Edit::OnScroll(IFWL_ScrollBar* pScrollBar, |
1965 FX_FLOAT fPos) { | 1941 uint32_t dwCode, |
| 1942 FX_FLOAT fPos) { |
1966 CFX_SizeF fs; | 1943 CFX_SizeF fs; |
1967 pScrollBar->GetRange(fs.x, fs.y); | 1944 pScrollBar->GetRange(fs.x, fs.y); |
1968 FX_FLOAT iCurPos = pScrollBar->GetPos(); | 1945 FX_FLOAT iCurPos = pScrollBar->GetPos(); |
1969 FX_FLOAT fStep = pScrollBar->GetStepSize(); | 1946 FX_FLOAT fStep = pScrollBar->GetStepSize(); |
1970 switch (dwCode) { | 1947 switch (dwCode) { |
1971 case FWL_SCBCODE_Min: { | 1948 case FWL_SCBCODE_Min: { |
1972 fPos = fs.x; | 1949 fPos = fs.x; |
1973 break; | 1950 break; |
1974 } | 1951 } |
1975 case FWL_SCBCODE_Max: { | 1952 case FWL_SCBCODE_Max: { |
(...skipping 22 matching lines...) Expand all Loading... |
1998 break; | 1975 break; |
1999 } | 1976 } |
2000 case FWL_SCBCODE_PageForward: { | 1977 case FWL_SCBCODE_PageForward: { |
2001 fPos += pScrollBar->GetPageSize(); | 1978 fPos += pScrollBar->GetPageSize(); |
2002 if (fPos > fs.y) { | 1979 if (fPos > fs.y) { |
2003 fPos = fs.y; | 1980 fPos = fs.y; |
2004 } | 1981 } |
2005 break; | 1982 break; |
2006 } | 1983 } |
2007 case FWL_SCBCODE_Pos: | 1984 case FWL_SCBCODE_Pos: |
2008 case FWL_SCBCODE_TrackPos: { | 1985 case FWL_SCBCODE_TrackPos: |
2009 break; | 1986 break; |
2010 } | 1987 case FWL_SCBCODE_EndScroll: |
2011 case FWL_SCBCODE_EndScroll: { | |
2012 return FALSE; | 1988 return FALSE; |
2013 } | 1989 default: |
2014 default: {} | 1990 break; |
2015 } | 1991 } |
2016 if (iCurPos != fPos) { | 1992 if (iCurPos != fPos) { |
2017 pScrollBar->SetPos(fPos); | 1993 pScrollBar->SetPos(fPos); |
2018 pScrollBar->SetTrackPos(fPos); | 1994 pScrollBar->SetTrackPos(fPos); |
2019 m_pOwner->UpdateOffset(pScrollBar, fPos - iCurPos); | 1995 UpdateOffset(pScrollBar, fPos - iCurPos); |
2020 if (m_pOwner->m_pEdtEngine) { | 1996 if (m_pEdtEngine) { |
2021 m_pOwner->UpdateCaret(); | 1997 UpdateCaret(); |
2022 } | 1998 } |
2023 CFX_RectF rect; | 1999 CFX_RectF rect; |
2024 m_pOwner->GetWidgetRect(rect); | 2000 GetWidgetRect(rect); |
2025 CFX_RectF rtInvalidate; | 2001 CFX_RectF rtInvalidate; |
2026 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); | 2002 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); |
2027 m_pOwner->Repaint(&rtInvalidate); | 2003 Repaint(&rtInvalidate); |
2028 } | 2004 } |
2029 return TRUE; | 2005 return TRUE; |
2030 } | 2006 } |
2031 void CFWL_EditImpDelegate::DoCursor(CFWL_MsgMouse* pMsg) {} | |
OLD | NEW |