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> |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "xfa/fwl/core/fwl_noteimp.h" | 25 #include "xfa/fwl/core/fwl_noteimp.h" |
26 #include "xfa/fwl/core/fwl_widgetimp.h" | 26 #include "xfa/fwl/core/fwl_widgetimp.h" |
27 #include "xfa/fwl/core/fwl_widgetmgrimp.h" | 27 #include "xfa/fwl/core/fwl_widgetmgrimp.h" |
28 #include "xfa/fwl/core/ifwl_themeprovider.h" | 28 #include "xfa/fwl/core/ifwl_themeprovider.h" |
29 #include "xfa/fxfa/include/xfa_ffdoc.h" | 29 #include "xfa/fxfa/include/xfa_ffdoc.h" |
30 #include "xfa/fxfa/include/xfa_ffwidget.h" | 30 #include "xfa/fxfa/include/xfa_ffwidget.h" |
31 #include "xfa/fxgraphics/cfx_path.h" | 31 #include "xfa/fxgraphics/cfx_path.h" |
32 | 32 |
33 namespace { | 33 namespace { |
34 | 34 |
| 35 const int kEditMargin = 3; |
| 36 |
35 bool FX_EDIT_ISLATINWORD(FX_WCHAR c) { | 37 bool FX_EDIT_ISLATINWORD(FX_WCHAR c) { |
36 return c == 0x2D || (c <= 0x005A && c >= 0x0041) || | 38 return c == 0x2D || (c <= 0x005A && c >= 0x0041) || |
37 (c <= 0x007A && c >= 0x0061) || (c <= 0x02AF && c >= 0x00C0) || | 39 (c <= 0x007A && c >= 0x0061) || (c <= 0x02AF && c >= 0x00C0) || |
38 c == 0x0027; | 40 c == 0x0027; |
39 } | 41 } |
40 | 42 |
41 void AddSquigglyPath(CFX_Path* pPathData, | 43 void AddSquigglyPath(CFX_Path* pPathData, |
42 FX_FLOAT fStartX, | 44 FX_FLOAT fStartX, |
43 FX_FLOAT fEndX, | 45 FX_FLOAT fEndX, |
44 FX_FLOAT fY, | 46 FX_FLOAT fY, |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 FX_BOOL IFWL_Edit::GetSuggestWords(CFX_PointF pointf, | 190 FX_BOOL IFWL_Edit::GetSuggestWords(CFX_PointF pointf, |
189 std::vector<CFX_ByteString>& sSuggest) { | 191 std::vector<CFX_ByteString>& sSuggest) { |
190 return static_cast<CFWL_EditImp*>(GetImpl()) | 192 return static_cast<CFWL_EditImp*>(GetImpl()) |
191 ->GetSuggestWords(pointf, sSuggest); | 193 ->GetSuggestWords(pointf, sSuggest); |
192 } | 194 } |
193 FX_BOOL IFWL_Edit::ReplaceSpellCheckWord(CFX_PointF pointf, | 195 FX_BOOL IFWL_Edit::ReplaceSpellCheckWord(CFX_PointF pointf, |
194 const CFX_ByteStringC& bsReplace) { | 196 const CFX_ByteStringC& bsReplace) { |
195 return static_cast<CFWL_EditImp*>(GetImpl()) | 197 return static_cast<CFWL_EditImp*>(GetImpl()) |
196 ->ReplaceSpellCheckWord(pointf, bsReplace); | 198 ->ReplaceSpellCheckWord(pointf, bsReplace); |
197 } | 199 } |
198 #define FWL_EDIT_Margin 3 | 200 |
199 CFWL_EditImp::CFWL_EditImp(const CFWL_WidgetImpProperties& properties, | 201 CFWL_EditImp::CFWL_EditImp(const CFWL_WidgetImpProperties& properties, |
200 IFWL_Widget* pOuter) | 202 IFWL_Widget* pOuter) |
201 : CFWL_WidgetImp(properties, pOuter), | 203 : CFWL_WidgetImp(properties, pOuter), |
202 m_fVAlignOffset(0.0f), | 204 m_fVAlignOffset(0.0f), |
203 m_fScrollOffsetX(0.0f), | 205 m_fScrollOffsetX(0.0f), |
204 m_fScrollOffsetY(0.0f), | 206 m_fScrollOffsetY(0.0f), |
205 m_pEdtEngine(NULL), | 207 m_pEdtEngine(NULL), |
206 m_bLButtonDown(FALSE), | 208 m_bLButtonDown(FALSE), |
207 m_nSelStart(0), | 209 m_nSelStart(0), |
208 m_nLimit(-1), | 210 m_nLimit(-1), |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 } | 277 } |
276 } | 278 } |
277 CFWL_WidgetImp::GetWidgetRect(rect, TRUE); | 279 CFWL_WidgetImp::GetWidgetRect(rect, TRUE); |
278 } else { | 280 } else { |
279 rect = m_pProperties->m_rtWidget; | 281 rect = m_pProperties->m_rtWidget; |
280 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { | 282 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { |
281 if (IsShowScrollBar(TRUE)) { | 283 if (IsShowScrollBar(TRUE)) { |
282 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( | 284 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( |
283 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 285 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
284 rect.width += *pfWidth; | 286 rect.width += *pfWidth; |
285 rect.width += FWL_EDIT_Margin; | 287 rect.width += kEditMargin; |
286 } | 288 } |
287 if (IsShowScrollBar(FALSE)) { | 289 if (IsShowScrollBar(FALSE)) { |
288 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( | 290 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( |
289 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 291 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
290 rect.height += *pfWidth; | 292 rect.height += *pfWidth; |
291 rect.height += FWL_EDIT_Margin; | 293 rect.height += kEditMargin; |
292 } | 294 } |
293 } | 295 } |
294 } | 296 } |
295 return FWL_ERR_Succeeded; | 297 return FWL_ERR_Succeeded; |
296 } | 298 } |
297 FWL_ERR CFWL_EditImp::SetStates(uint32_t dwStates, FX_BOOL bSet) { | 299 FWL_ERR CFWL_EditImp::SetStates(uint32_t dwStates, FX_BOOL bSet) { |
298 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) || | 300 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) || |
299 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { | 301 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { |
300 ShowCaret(FALSE); | 302 ShowCaret(FALSE); |
301 } | 303 } |
(...skipping 1164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1466 m_rtEngine.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, | 1468 m_rtEngine.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, |
1467 pUIMargin->height); | 1469 pUIMargin->height); |
1468 } | 1470 } |
1469 } | 1471 } |
1470 FX_BOOL bShowVertScrollbar = IsShowScrollBar(TRUE); | 1472 FX_BOOL bShowVertScrollbar = IsShowScrollBar(TRUE); |
1471 FX_BOOL bShowHorzScrollbar = IsShowScrollBar(FALSE); | 1473 FX_BOOL bShowHorzScrollbar = IsShowScrollBar(FALSE); |
1472 if (bShowVertScrollbar) { | 1474 if (bShowVertScrollbar) { |
1473 InitScrollBar(); | 1475 InitScrollBar(); |
1474 CFX_RectF rtVertScr; | 1476 CFX_RectF rtVertScr; |
1475 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { | 1477 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { |
1476 rtVertScr.Set(m_rtClient.right() + FWL_EDIT_Margin, m_rtClient.top, | 1478 rtVertScr.Set(m_rtClient.right() + kEditMargin, m_rtClient.top, fWidth, |
1477 fWidth, m_rtClient.height); | 1479 m_rtClient.height); |
1478 } else { | 1480 } else { |
1479 rtVertScr.Set(m_rtClient.right() - fWidth, m_rtClient.top, fWidth, | 1481 rtVertScr.Set(m_rtClient.right() - fWidth, m_rtClient.top, fWidth, |
1480 m_rtClient.height); | 1482 m_rtClient.height); |
1481 if (bShowHorzScrollbar) { | 1483 if (bShowHorzScrollbar) { |
1482 rtVertScr.height -= fWidth; | 1484 rtVertScr.height -= fWidth; |
1483 } | 1485 } |
1484 m_rtEngine.width -= fWidth; | 1486 m_rtEngine.width -= fWidth; |
1485 } | 1487 } |
1486 m_pVertScrollBar->SetWidgetRect(rtVertScr); | 1488 m_pVertScrollBar->SetWidgetRect(rtVertScr); |
1487 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, FALSE); | 1489 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, FALSE); |
1488 m_pVertScrollBar->Update(); | 1490 m_pVertScrollBar->Update(); |
1489 } else if (m_pVertScrollBar) { | 1491 } else if (m_pVertScrollBar) { |
1490 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, TRUE); | 1492 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, TRUE); |
1491 } | 1493 } |
1492 if (bShowHorzScrollbar) { | 1494 if (bShowHorzScrollbar) { |
1493 InitScrollBar(FALSE); | 1495 InitScrollBar(FALSE); |
1494 CFX_RectF rtHoriScr; | 1496 CFX_RectF rtHoriScr; |
1495 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { | 1497 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { |
1496 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() + FWL_EDIT_Margin, | 1498 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() + kEditMargin, |
1497 m_rtClient.width, fWidth); | 1499 m_rtClient.width, fWidth); |
1498 } else { | 1500 } else { |
1499 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() - fWidth, | 1501 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() - fWidth, |
1500 m_rtClient.width, fWidth); | 1502 m_rtClient.width, fWidth); |
1501 if (bShowVertScrollbar) { | 1503 if (bShowVertScrollbar) { |
1502 rtHoriScr.width -= fWidth; | 1504 rtHoriScr.width -= fWidth; |
1503 } | 1505 } |
1504 m_rtEngine.height -= fWidth; | 1506 m_rtEngine.height -= fWidth; |
1505 } | 1507 } |
1506 m_pHorzScrollBar->SetWidgetRect(rtHoriScr); | 1508 m_pHorzScrollBar->SetWidgetRect(rtHoriScr); |
(...skipping 12 matching lines...) Expand all Loading... |
1519 FX_BOOL bShowVertScrollbar = IsShowScrollBar(TRUE); | 1521 FX_BOOL bShowVertScrollbar = IsShowScrollBar(TRUE); |
1520 FX_BOOL bShowHorzScrollbar = IsShowScrollBar(FALSE); | 1522 FX_BOOL bShowHorzScrollbar = IsShowScrollBar(FALSE); |
1521 if (bShowVertScrollbar) { | 1523 if (bShowVertScrollbar) { |
1522 if (!m_pVertScrollBar) { | 1524 if (!m_pVertScrollBar) { |
1523 pfWidth = static_cast<FX_FLOAT*>( | 1525 pfWidth = static_cast<FX_FLOAT*>( |
1524 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 1526 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
1525 FX_FLOAT fWidth = pfWidth ? *pfWidth : 0; | 1527 FX_FLOAT fWidth = pfWidth ? *pfWidth : 0; |
1526 InitScrollBar(); | 1528 InitScrollBar(); |
1527 CFX_RectF rtVertScr; | 1529 CFX_RectF rtVertScr; |
1528 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { | 1530 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { |
1529 rtVertScr.Set(m_rtClient.right() + FWL_EDIT_Margin, m_rtClient.top, | 1531 rtVertScr.Set(m_rtClient.right() + kEditMargin, m_rtClient.top, fWidth, |
1530 fWidth, m_rtClient.height); | 1532 m_rtClient.height); |
1531 } else { | 1533 } else { |
1532 rtVertScr.Set(m_rtClient.right() - fWidth, m_rtClient.top, fWidth, | 1534 rtVertScr.Set(m_rtClient.right() - fWidth, m_rtClient.top, fWidth, |
1533 m_rtClient.height); | 1535 m_rtClient.height); |
1534 if (bShowHorzScrollbar) { | 1536 if (bShowHorzScrollbar) { |
1535 rtVertScr.height -= fWidth; | 1537 rtVertScr.height -= fWidth; |
1536 } | 1538 } |
1537 } | 1539 } |
1538 m_pVertScrollBar->SetWidgetRect(rtVertScr); | 1540 m_pVertScrollBar->SetWidgetRect(rtVertScr); |
1539 m_pVertScrollBar->Update(); | 1541 m_pVertScrollBar->Update(); |
1540 } | 1542 } |
1541 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, FALSE); | 1543 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, FALSE); |
1542 } else if (m_pVertScrollBar) { | 1544 } else if (m_pVertScrollBar) { |
1543 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, TRUE); | 1545 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, TRUE); |
1544 } | 1546 } |
1545 if (bShowHorzScrollbar) { | 1547 if (bShowHorzScrollbar) { |
1546 if (!m_pHorzScrollBar) { | 1548 if (!m_pHorzScrollBar) { |
1547 if (!pfWidth) { | 1549 if (!pfWidth) { |
1548 pfWidth = static_cast<FX_FLOAT*>( | 1550 pfWidth = static_cast<FX_FLOAT*>( |
1549 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 1551 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
1550 } | 1552 } |
1551 FX_FLOAT fWidth = pfWidth ? *pfWidth : 0; | 1553 FX_FLOAT fWidth = pfWidth ? *pfWidth : 0; |
1552 InitScrollBar(FALSE); | 1554 InitScrollBar(FALSE); |
1553 CFX_RectF rtHoriScr; | 1555 CFX_RectF rtHoriScr; |
1554 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { | 1556 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { |
1555 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() + FWL_EDIT_Margin, | 1557 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() + kEditMargin, |
1556 m_rtClient.width, fWidth); | 1558 m_rtClient.width, fWidth); |
1557 } else { | 1559 } else { |
1558 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() - fWidth, | 1560 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() - fWidth, |
1559 m_rtClient.width, fWidth); | 1561 m_rtClient.width, fWidth); |
1560 if (bShowVertScrollbar) { | 1562 if (bShowVertScrollbar) { |
1561 rtHoriScr.width -= (fWidth); | 1563 rtHoriScr.width -= (fWidth); |
1562 } | 1564 } |
1563 } | 1565 } |
1564 m_pHorzScrollBar->SetWidgetRect(rtHoriScr); | 1566 m_pHorzScrollBar->SetWidgetRect(rtHoriScr); |
1565 m_pHorzScrollBar->Update(); | 1567 m_pHorzScrollBar->Update(); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1728 DoDeactivate(static_cast<CFWL_MsgDeactivate*>(pMessage)); | 1730 DoDeactivate(static_cast<CFWL_MsgDeactivate*>(pMessage)); |
1729 break; | 1731 break; |
1730 } | 1732 } |
1731 case CFWL_MessageType::SetFocus: | 1733 case CFWL_MessageType::SetFocus: |
1732 case CFWL_MessageType::KillFocus: { | 1734 case CFWL_MessageType::KillFocus: { |
1733 OnFocusChanged(pMessage, dwMsgCode == CFWL_MessageType::SetFocus); | 1735 OnFocusChanged(pMessage, dwMsgCode == CFWL_MessageType::SetFocus); |
1734 break; | 1736 break; |
1735 } | 1737 } |
1736 case CFWL_MessageType::Mouse: { | 1738 case CFWL_MessageType::Mouse: { |
1737 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | 1739 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); |
1738 uint32_t dwCmd = pMsg->m_dwCmd; | 1740 switch (pMsg->m_dwCmd) { |
1739 switch (dwCmd) { | 1741 case FWL_MouseCommand::LeftButtonDown: { |
1740 case FWL_MSGMOUSECMD_LButtonDown: { | |
1741 OnLButtonDown(pMsg); | 1742 OnLButtonDown(pMsg); |
1742 break; | 1743 break; |
1743 } | 1744 } |
1744 case FWL_MSGMOUSECMD_LButtonUp: { | 1745 case FWL_MouseCommand::LeftButtonUp: { |
1745 OnLButtonUp(pMsg); | 1746 OnLButtonUp(pMsg); |
1746 break; | 1747 break; |
1747 } | 1748 } |
1748 case FWL_MSGMOUSECMD_LButtonDblClk: { | 1749 case FWL_MouseCommand::LeftButtonDblClk: { |
1749 OnButtonDblClk(pMsg); | 1750 OnButtonDblClk(pMsg); |
1750 break; | 1751 break; |
1751 } | 1752 } |
1752 case FWL_MSGMOUSECMD_MouseMove: { | 1753 case FWL_MouseCommand::Move: { |
1753 OnMouseMove(pMsg); | 1754 OnMouseMove(pMsg); |
1754 break; | 1755 break; |
1755 } | 1756 } |
1756 case FWL_MSGMOUSECMD_RButtonDown: { | 1757 case FWL_MouseCommand::RightButtonDown: { |
1757 DoButtonDown(pMsg); | 1758 DoButtonDown(pMsg); |
1758 break; | 1759 break; |
1759 } | 1760 } |
1760 default: | 1761 default: |
1761 break; | 1762 break; |
1762 } | 1763 } |
1763 break; | 1764 break; |
1764 } | 1765 } |
1765 case CFWL_MessageType::Key: { | 1766 case CFWL_MessageType::Key: { |
1766 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); | 1767 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); |
1767 uint32_t dwCmd = pKey->m_dwCmd; | 1768 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) |
1768 if (dwCmd == FWL_MSGKEYCMD_KeyDown) | |
1769 OnKeyDown(pKey); | 1769 OnKeyDown(pKey); |
1770 else if (dwCmd == FWL_MSGKEYCMD_Char) | 1770 else if (pKey->m_dwCmd == FWL_KeyCommand::Char) |
1771 OnChar(pKey); | 1771 OnChar(pKey); |
1772 break; | 1772 break; |
1773 } | 1773 } |
1774 default: { | 1774 default: { |
1775 iRet = 0; | 1775 iRet = 0; |
1776 break; | 1776 break; |
1777 } | 1777 } |
1778 } | 1778 } |
1779 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); | 1779 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); |
1780 return iRet; | 1780 return iRet; |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2153 } | 2153 } |
2154 CFX_RectF rect; | 2154 CFX_RectF rect; |
2155 m_pOwner->GetWidgetRect(rect); | 2155 m_pOwner->GetWidgetRect(rect); |
2156 CFX_RectF rtInvalidate; | 2156 CFX_RectF rtInvalidate; |
2157 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); | 2157 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); |
2158 m_pOwner->Repaint(&rtInvalidate); | 2158 m_pOwner->Repaint(&rtInvalidate); |
2159 } | 2159 } |
2160 return TRUE; | 2160 return TRUE; |
2161 } | 2161 } |
2162 void CFWL_EditImpDelegate::DoCursor(CFWL_MsgMouse* pMsg) {} | 2162 void CFWL_EditImpDelegate::DoCursor(CFWL_MsgMouse* pMsg) {} |
OLD | NEW |