| 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 "../../include/formfiller/FFL_TextField.h" | 7 #include "../../include/formfiller/FFL_TextField.h" |
| 8 #include "../../include/formfiller/FFL_CBA_Fontmap.h" | 8 #include "../../include/formfiller/FFL_CBA_Fontmap.h" |
| 9 | 9 |
| 10 /* ------------------------------- CFFL_TextField ------------------------------
- */ | 10 /* ------------------------------- CFFL_TextField ------------------------------
- */ |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 { | 122 { |
| 123 pWnd->SetLimitChar(nMaxLen); | 123 pWnd->SetLimitChar(nMaxLen); |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 pWnd->SetText(swValue.c_str()); | 127 pWnd->SetText(swValue.c_str()); |
| 128 return pWnd; | 128 return pWnd; |
| 129 } | 129 } |
| 130 | 130 |
| 131 | 131 |
| 132 FX_BOOL CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFl
ags) | 132 bool CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFlags
) |
| 133 { | 133 { |
| 134 switch (nChar) | 134 switch (nChar) |
| 135 { | 135 { |
| 136 case FWL_VKEY_Return: | 136 case FWL_VKEY_Return: |
| 137 if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE)) | 137 if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE)) |
| 138 { | 138 { |
| 139 CPDFSDK_PageView* pPageView = GetCurPageView(); | 139 CPDFSDK_PageView* pPageView = GetCurPageView(); |
| 140 ASSERT(pPageView != NULL); | 140 ASSERT(pPageView != NULL); |
| 141 m_bValid = !m_bValid; | 141 m_bValid = !m_bValid; |
| 142 CPDF_Rect rcAnnot = pAnnot->GetRect(); | 142 CPDF_Rect rcAnnot = pAnnot->GetRect(); |
| 143 m_pApp->FFI_Invalidate(pAnnot->GetPDFPage(), rcAnnot.left, rcAnnot.t
op, rcAnnot.right, rcAnnot.bottom); | 143 m_pApp->FFI_Invalidate(pAnnot->GetPDFPage(), rcAnnot.left, rcAnnot.t
op, rcAnnot.right, rcAnnot.bottom); |
| 144 | 144 |
| 145 if (m_bValid) | 145 if (m_bValid) |
| 146 { | 146 { |
| 147 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) | 147 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, true)) |
| 148 pWnd->SetFocus(); | 148 pWnd->SetFocus(); |
| 149 } | 149 } |
| 150 else | 150 else |
| 151 { | 151 { |
| 152 if (CommitData(pPageView, nFlags)) | 152 if (CommitData(pPageView, nFlags)) |
| 153 { | 153 { |
| 154 DestroyPDFWindow(pPageView); | 154 DestroyPDFWindow(pPageView); |
| 155 return TRUE; | 155 return true; |
| 156 } | 156 } |
| 157 return FALSE; | 157 return false; |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 break; | 160 break; |
| 161 case FWL_VKEY_Escape: | 161 case FWL_VKEY_Escape: |
| 162 { | 162 { |
| 163 CPDFSDK_PageView* pPageView = GetCurPageView(); | 163 CPDFSDK_PageView* pPageView = GetCurPageView(); |
| 164 ASSERT(pPageView != NULL); | 164 ASSERT(pPageView != NULL); |
| 165 EscapeFiller(pPageView,TRUE); | 165 EscapeFiller(pPageView,true); |
| 166 return TRUE; | 166 return true; |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 | 169 |
| 170 return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); | 170 return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); |
| 171 } | 171 } |
| 172 | 172 |
| 173 FX_BOOL CFFL_TextField::IsDataChanged(CPDFSDK_PageView* pPageView) | 173 bool CFFL_TextField::IsDataChanged(CPDFSDK_PageView* pPageView) |
| 174 { | 174 { |
| 175 ASSERT(m_pWidget != NULL); | 175 ASSERT(m_pWidget != NULL); |
| 176 | 176 |
| 177 if (CPWL_Edit * pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) | 177 if (CPWL_Edit * pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, false)) |
| 178 return pEdit->GetText() != m_pWidget->GetValue(); | 178 return pEdit->GetText() != m_pWidget->GetValue(); |
| 179 | 179 |
| 180 return FALSE; | 180 return false; |
| 181 } | 181 } |
| 182 | 182 |
| 183 void CFFL_TextField::SaveData(CPDFSDK_PageView* pPageView) | 183 void CFFL_TextField::SaveData(CPDFSDK_PageView* pPageView) |
| 184 { | 184 { |
| 185 ASSERT(m_pWidget != NULL); | 185 ASSERT(m_pWidget != NULL); |
| 186 | 186 |
| 187 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) | 187 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) |
| 188 { | 188 { |
| 189 CFX_WideString sOldValue = m_pWidget->GetValue(); | 189 CFX_WideString sOldValue = m_pWidget->GetValue(); |
| 190 CFX_WideString sNewValue = pWnd->GetText(); | 190 CFX_WideString sNewValue = pWnd->GetText(); |
| 191 | 191 |
| 192 m_pWidget->SetValue(sNewValue, FALSE); | 192 m_pWidget->SetValue(sNewValue, false); |
| 193 m_pWidget->ResetFieldAppearance(TRUE); | 193 m_pWidget->ResetFieldAppearance(true); |
| 194 m_pWidget->UpdateField(); | 194 m_pWidget->UpdateField(); |
| 195 SetChangeMark(); | 195 SetChangeMark(); |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 | 198 |
| 199 void CFFL_TextField::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AA
ctionType type, | 199 void CFFL_TextField::GetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AA
ctionType type, |
| 200 PDFSDK_FieldAction& fa) | 200 PDFSDK_FieldAction& fa) |
| 201 { | 201 { |
| 202 switch (type) | 202 switch (type) |
| 203 { | 203 { |
| 204 case CPDF_AAction::KeyStroke: | 204 case CPDF_AAction::KeyStroke: |
| 205 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) | 205 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) |
| 206 { | 206 { |
| 207 fa.bFieldFull = pWnd->IsTextFull(); | 207 fa.bFieldFull = pWnd->IsTextFull(); |
| 208 | 208 |
| 209 fa.sValue = pWnd->GetText(); | 209 fa.sValue = pWnd->GetText(); |
| 210 | 210 |
| 211 if (fa.bFieldFull) | 211 if (fa.bFieldFull) |
| 212 { | 212 { |
| 213 fa.sChange = L""; | 213 fa.sChange = L""; |
| 214 fa.sChangeEx = L""; | 214 fa.sChangeEx = L""; |
| 215 } | 215 } |
| 216 } | 216 } |
| 217 break; | 217 break; |
| 218 case CPDF_AAction::Validate: | 218 case CPDF_AAction::Validate: |
| 219 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) | 219 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) |
| 220 { | 220 { |
| 221 fa.sValue = pWnd->GetText(); | 221 fa.sValue = pWnd->GetText(); |
| 222 } | 222 } |
| 223 break; | 223 break; |
| 224 case CPDF_AAction::LoseFocus: | 224 case CPDF_AAction::LoseFocus: |
| 225 case CPDF_AAction::GetFocus: | 225 case CPDF_AAction::GetFocus: |
| 226 ASSERT(m_pWidget != NULL); | 226 ASSERT(m_pWidget != NULL); |
| 227 fa.sValue = m_pWidget->GetValue(); | 227 fa.sValue = m_pWidget->GetValue(); |
| 228 break; | 228 break; |
| 229 default: | 229 default: |
| 230 break; | 230 break; |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 | 233 |
| 234 void CFFL_TextField::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AA
ctionType type, | 234 void CFFL_TextField::SetActionData(CPDFSDK_PageView* pPageView, CPDF_AAction::AA
ctionType type, |
| 235 const PDFSDK_FieldAction& fa) | 235 const PDFSDK_FieldAction& fa) |
| 236 { | 236 { |
| 237 switch (type) | 237 switch (type) |
| 238 { | 238 { |
| 239 case CPDF_AAction::KeyStroke: | 239 case CPDF_AAction::KeyStroke: |
| 240 if (CPWL_Edit * pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) | 240 if (CPWL_Edit * pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, false)) |
| 241 { | 241 { |
| 242 pEdit->SetFocus(); | 242 pEdit->SetFocus(); |
| 243 pEdit->SetSel(fa.nSelStart, fa.nSelEnd); | 243 pEdit->SetSel(fa.nSelStart, fa.nSelEnd); |
| 244 pEdit->ReplaceSel(fa.sChange.c_str()); | 244 pEdit->ReplaceSel(fa.sChange.c_str()); |
| 245 } | 245 } |
| 246 break; | 246 break; |
| 247 default: | 247 default: |
| 248 break; | 248 break; |
| 249 } | 249 } |
| 250 } | 250 } |
| 251 | 251 |
| 252 | 252 |
| 253 FX_BOOL CFFL_TextField::IsActionDataChanged(CPDF_AAction::AActionType type, cons
t PDFSDK_FieldAction& faOld, | 253 bool CFFL_TextField::IsActionDataChanged(CPDF_AAction::AActionType type, const P
DFSDK_FieldAction& faOld, |
| 254 const PDFSDK_FieldAction& faNew) | 254 const PDFSDK_FieldAction& faNew) |
| 255 { | 255 { |
| 256 switch (type) | 256 switch (type) |
| 257 { | 257 { |
| 258 case CPDF_AAction::KeyStroke: | 258 case CPDF_AAction::KeyStroke: |
| 259 return (!faOld.bFieldFull && faOld.nSelEnd != faNew.nSelEnd) || faOld.nS
elStart != faNew.nSelStart || | 259 return (!faOld.bFieldFull && faOld.nSelEnd != faNew.nSelEnd) || faOld.nS
elStart != faNew.nSelStart || |
| 260 faOld.sChange != faNew.sChange; | 260 faOld.sChange != faNew.sChange; |
| 261 default: | 261 default: |
| 262 break; | 262 break; |
| 263 } | 263 } |
| 264 | 264 |
| 265 return FALSE; | 265 return false; |
| 266 } | 266 } |
| 267 | 267 |
| 268 void CFFL_TextField::SaveState(CPDFSDK_PageView* pPageView) | 268 void CFFL_TextField::SaveState(CPDFSDK_PageView* pPageView) |
| 269 { | 269 { |
| 270 ASSERT(pPageView != NULL); | 270 ASSERT(pPageView != NULL); |
| 271 | 271 |
| 272 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) | 272 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, false)) |
| 273 { | 273 { |
| 274 pWnd->GetSel(m_State.nStart, m_State.nEnd); | 274 pWnd->GetSel(m_State.nStart, m_State.nEnd); |
| 275 m_State.sValue = pWnd->GetText(); | 275 m_State.sValue = pWnd->GetText(); |
| 276 } | 276 } |
| 277 } | 277 } |
| 278 | 278 |
| 279 void CFFL_TextField::RestoreState(CPDFSDK_PageView* pPageView) | 279 void CFFL_TextField::RestoreState(CPDFSDK_PageView* pPageView) |
| 280 { | 280 { |
| 281 ASSERT(pPageView != NULL); | 281 ASSERT(pPageView != NULL); |
| 282 | 282 |
| 283 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, TRUE)) | 283 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, true)) |
| 284 { | 284 { |
| 285 pWnd->SetText(m_State.sValue.c_str()); | 285 pWnd->SetText(m_State.sValue.c_str()); |
| 286 pWnd->SetSel(m_State.nStart, m_State.nEnd); | 286 pWnd->SetSel(m_State.nStart, m_State.nEnd); |
| 287 } | 287 } |
| 288 } | 288 } |
| 289 | 289 |
| 290 CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView, FX_BOOL bR
estoreValue) | 290 CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView, bool bRest
oreValue) |
| 291 { | 291 { |
| 292 if (bRestoreValue) | 292 if (bRestoreValue) |
| 293 SaveState(pPageView); | 293 SaveState(pPageView); |
| 294 | 294 |
| 295 DestroyPDFWindow(pPageView); | 295 DestroyPDFWindow(pPageView); |
| 296 | 296 |
| 297 CPWL_Wnd* pRet = NULL; | 297 CPWL_Wnd* pRet = NULL; |
| 298 | 298 |
| 299 if (bRestoreValue) | 299 if (bRestoreValue) |
| 300 { | 300 { |
| 301 RestoreState(pPageView); | 301 RestoreState(pPageView); |
| 302 pRet = GetPDFWindow(pPageView, FALSE); | 302 pRet = GetPDFWindow(pPageView, false); |
| 303 } | 303 } |
| 304 else | 304 else |
| 305 pRet = GetPDFWindow(pPageView, TRUE); | 305 pRet = GetPDFWindow(pPageView, true); |
| 306 | 306 |
| 307 m_pWidget->UpdateField(); | 307 m_pWidget->UpdateField(); |
| 308 | 308 |
| 309 return pRet; | 309 return pRet; |
| 310 } | 310 } |
| 311 | 311 |
| 312 void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) | 312 void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) |
| 313 { | 313 { |
| 314 ASSERT(m_pApp != NULL); | 314 ASSERT(m_pApp != NULL); |
| 315 | 315 |
| 316 ASSERT(pWnd != NULL); | 316 ASSERT(pWnd != NULL); |
| 317 | 317 |
| 318 if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) | 318 if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) |
| 319 { | 319 { |
| 320 CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; | 320 CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; |
| 321 pEdit->SetCharSet(134); | 321 pEdit->SetCharSet(134); |
| 322 pEdit->SetCodePage(936); | 322 pEdit->SetCodePage(936); |
| 323 | 323 |
| 324 pEdit->SetReadyToInput(); | 324 pEdit->SetReadyToInput(); |
| 325 CFX_WideString wsText = pEdit->GetText(); | 325 CFX_WideString wsText = pEdit->GetText(); |
| 326 int nCharacters = wsText.GetLength(); | 326 int nCharacters = wsText.GetLength(); |
| 327 CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); | 327 CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); |
| 328 unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str(); | 328 unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str(); |
| 329 m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, nCh
aracters, TRUE); | 329 m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, nCh
aracters, true); |
| 330 | 330 |
| 331 pEdit->SetEditNotify(this); | 331 pEdit->SetEditNotify(this); |
| 332 //pUndo->BeginEdit(pDocument); | 332 //pUndo->BeginEdit(pDocument); |
| 333 } | 333 } |
| 334 } | 334 } |
| 335 | 335 |
| 336 void CFFL_TextField::OnKillFocus(CPWL_Wnd* pWnd) | 336 void CFFL_TextField::OnKillFocus(CPWL_Wnd* pWnd) |
| 337 { | 337 { |
| 338 | 338 |
| 339 } | 339 } |
| 340 | 340 |
| 341 FX_BOOL CFFL_TextField::CanCopy(CPDFSDK_Document* pDocument) | 341 bool CFFL_TextField::CanCopy(CPDFSDK_Document* pDocument) |
| 342 { | 342 { |
| 343 return FALSE; | 343 return false; |
| 344 } | 344 } |
| 345 | 345 |
| 346 FX_BOOL CFFL_TextField::CanCut(CPDFSDK_Document* pDocument) | 346 bool CFFL_TextField::CanCut(CPDFSDK_Document* pDocument) |
| 347 { | 347 { |
| 348 return FALSE; | 348 return false; |
| 349 } | 349 } |
| 350 | 350 |
| 351 FX_BOOL CFFL_TextField::CanPaste(CPDFSDK_Document* pDocument) | 351 bool CFFL_TextField::CanPaste(CPDFSDK_Document* pDocument) |
| 352 { | 352 { |
| 353 return FALSE; | 353 return false; |
| 354 } | 354 } |
| 355 | 355 |
| 356 void CFFL_TextField::OnAddUndo(CPWL_Edit* pEdit) | 356 void CFFL_TextField::OnAddUndo(CPWL_Edit* pEdit) |
| 357 { | 357 { |
| 358 } | 358 } |
| 359 | 359 |
| OLD | NEW |