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 "fpdfsdk/formfiller/cffl_textfield.h" | 7 #include "fpdfsdk/formfiller/cffl_textfield.h" |
8 | 8 |
9 #include "fpdfsdk/formfiller/cba_fontmap.h" | 9 #include "fpdfsdk/formfiller/cba_fontmap.h" |
10 #include "fpdfsdk/include/cpdfsdk_environment.h" | 10 #include "fpdfsdk/include/cpdfsdk_environment.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 break; | 64 break; |
65 case BF_ALIGN_MIDDLE: | 65 case BF_ALIGN_MIDDLE: |
66 cp.dwFlags |= PES_MIDDLE; | 66 cp.dwFlags |= PES_MIDDLE; |
67 break; | 67 break; |
68 case BF_ALIGN_RIGHT: | 68 case BF_ALIGN_RIGHT: |
69 cp.dwFlags |= PES_RIGHT; | 69 cp.dwFlags |= PES_RIGHT; |
70 break; | 70 break; |
71 } | 71 } |
72 | 72 |
73 if (!m_pFontMap) | 73 if (!m_pFontMap) |
74 m_pFontMap.reset(new CBA_FontMap(m_pWidget, m_pApp->GetSysHandler())); | 74 m_pFontMap.reset(new CBA_FontMap(m_pWidget, m_pEnv->GetSysHandler())); |
75 cp.pFontMap = m_pFontMap.get(); | 75 cp.pFontMap = m_pFontMap.get(); |
76 cp.pFocusHandler = this; | 76 cp.pFocusHandler = this; |
77 | 77 |
78 return cp; | 78 return cp; |
79 } | 79 } |
80 | 80 |
81 CPWL_Wnd* CFFL_TextField::NewPDFWindow(const PWL_CREATEPARAM& cp, | 81 CPWL_Wnd* CFFL_TextField::NewPDFWindow(const PWL_CREATEPARAM& cp, |
82 CPDFSDK_PageView* pPageView) { | 82 CPDFSDK_PageView* pPageView) { |
83 CPWL_Edit* pWnd = new CPWL_Edit(); | 83 CPWL_Edit* pWnd = new CPWL_Edit(); |
84 pWnd->AttachFFLData(this); | 84 pWnd->AttachFFLData(this); |
85 pWnd->Create(cp); | 85 pWnd->Create(cp); |
86 | 86 |
87 CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller(); | 87 CFFL_IFormFiller* pIFormFiller = m_pEnv->GetIFormFiller(); |
88 pWnd->SetFillerNotify(pIFormFiller); | 88 pWnd->SetFillerNotify(pIFormFiller); |
89 | 89 |
90 int32_t nMaxLen = m_pWidget->GetMaxLen(); | 90 int32_t nMaxLen = m_pWidget->GetMaxLen(); |
91 CFX_WideString swValue = m_pWidget->GetValue(); | 91 CFX_WideString swValue = m_pWidget->GetValue(); |
92 | 92 |
93 if (nMaxLen > 0) { | 93 if (nMaxLen > 0) { |
94 if (pWnd->HasFlag(PES_CHARARRAY)) { | 94 if (pWnd->HasFlag(PES_CHARARRAY)) { |
95 pWnd->SetCharArray(nMaxLen); | 95 pWnd->SetCharArray(nMaxLen); |
96 pWnd->SetAlignFormatV(PEAV_CENTER); | 96 pWnd->SetAlignFormatV(PEAV_CENTER); |
97 } else { | 97 } else { |
98 pWnd->SetLimitChar(nMaxLen); | 98 pWnd->SetLimitChar(nMaxLen); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 pWnd->SetText(swValue); | 102 pWnd->SetText(swValue); |
103 return pWnd; | 103 return pWnd; |
104 } | 104 } |
105 | 105 |
106 FX_BOOL CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, | 106 FX_BOOL CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, |
107 uint32_t nChar, | 107 uint32_t nChar, |
108 uint32_t nFlags) { | 108 uint32_t nFlags) { |
109 switch (nChar) { | 109 switch (nChar) { |
110 case FWL_VKEY_Return: | 110 case FWL_VKEY_Return: |
111 if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE)) { | 111 if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE)) { |
112 CPDFSDK_PageView* pPageView = GetCurPageView(true); | 112 CPDFSDK_PageView* pPageView = GetCurPageView(true); |
113 ASSERT(pPageView); | 113 ASSERT(pPageView); |
114 m_bValid = !m_bValid; | 114 m_bValid = !m_bValid; |
115 CFX_FloatRect rcAnnot = pAnnot->GetRect(); | 115 CFX_FloatRect rcAnnot = pAnnot->GetRect(); |
116 m_pApp->Invalidate(pAnnot->GetUnderlyingPage(), rcAnnot.left, | 116 m_pEnv->Invalidate(pAnnot->GetUnderlyingPage(), rcAnnot.left, |
117 rcAnnot.top, rcAnnot.right, rcAnnot.bottom); | 117 rcAnnot.top, rcAnnot.right, rcAnnot.bottom); |
118 | 118 |
119 if (m_bValid) { | 119 if (m_bValid) { |
120 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) | 120 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) |
121 pWnd->SetFocus(); | 121 pWnd->SetFocus(); |
122 } else { | 122 } else { |
123 if (CommitData(pPageView, nFlags)) { | 123 if (CommitData(pPageView, nFlags)) { |
124 DestroyPDFWindow(pPageView); | 124 DestroyPDFWindow(pPageView); |
125 return TRUE; | 125 return TRUE; |
126 } | 126 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 FX_BOOL CFFL_TextField::IsFieldFull(CPDFSDK_PageView* pPageView) { | 262 FX_BOOL CFFL_TextField::IsFieldFull(CPDFSDK_PageView* pPageView) { |
263 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { | 263 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { |
264 return pWnd->IsTextFull(); | 264 return pWnd->IsTextFull(); |
265 } | 265 } |
266 | 266 |
267 return FALSE; | 267 return FALSE; |
268 } | 268 } |
269 #endif // PDF_ENABLE_XFA | 269 #endif // PDF_ENABLE_XFA |
270 | 270 |
271 void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) { | 271 void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) { |
272 ASSERT(m_pApp); | 272 ASSERT(m_pEnv); |
273 if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) { | 273 if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) { |
274 CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; | 274 CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; |
275 pEdit->SetCharSet(FXFONT_GB2312_CHARSET); | 275 pEdit->SetCharSet(FXFONT_GB2312_CHARSET); |
276 pEdit->SetCodePage(936); | 276 pEdit->SetCodePage(936); |
277 | 277 |
278 pEdit->SetReadyToInput(); | 278 pEdit->SetReadyToInput(); |
279 CFX_WideString wsText = pEdit->GetText(); | 279 CFX_WideString wsText = pEdit->GetText(); |
280 int nCharacters = wsText.GetLength(); | 280 int nCharacters = wsText.GetLength(); |
281 CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); | 281 CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); |
282 unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str(); | 282 unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str(); |
283 m_pApp->OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, | 283 m_pEnv->OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, |
284 nCharacters, TRUE); | 284 nCharacters, TRUE); |
285 } | 285 } |
286 } | 286 } |
OLD | NEW |