| 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/include/formfiller/FFL_CBA_Fontmap.h" | 7 #include "fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h" |
| 8 #include "fpdfsdk/include/formfiller/FFL_ComboBox.h" | 8 #include "fpdfsdk/include/formfiller/FFL_ComboBox.h" |
| 9 #include "fpdfsdk/include/formfiller/FFL_FormFiller.h" | 9 #include "fpdfsdk/include/formfiller/FFL_FormFiller.h" |
| 10 #include "fpdfsdk/include/formfiller/FFL_IFormFiller.h" | 10 #include "fpdfsdk/include/formfiller/FFL_IFormFiller.h" |
| 11 #include "fpdfsdk/include/formfiller/FormFiller.h" | 11 #include "fpdfsdk/include/formfiller/FormFiller.h" |
| 12 | 12 |
| 13 /* ------------------------------- CFFL_ComboBox ------------------------------- | 13 /* ------------------------------- CFFL_ComboBox ------------------------------- |
| 14 */ | 14 */ |
| 15 | 15 |
| 16 CFFL_ComboBox::CFFL_ComboBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) | 16 CFFL_ComboBox::CFFL_ComboBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) |
| 17 : CFFL_FormFiller(pApp, pAnnot), m_pFontMap(NULL) { | 17 : CFFL_FormFiller(pApp, pAnnot), m_pFontMap(NULL) { |
| 18 m_State.nIndex = 0; | 18 m_State.nIndex = 0; |
| 19 m_State.nStart = 0; | 19 m_State.nStart = 0; |
| 20 m_State.nEnd = 0; | 20 m_State.nEnd = 0; |
| 21 } | 21 } |
| 22 | 22 |
| 23 CFFL_ComboBox::~CFFL_ComboBox() { | 23 CFFL_ComboBox::~CFFL_ComboBox() { |
| 24 delete m_pFontMap; | 24 delete m_pFontMap; |
| 25 } | 25 } |
| 26 | 26 |
| 27 PWL_CREATEPARAM CFFL_ComboBox::GetCreateParam() { | 27 PWL_CREATEPARAM CFFL_ComboBox::GetCreateParam() { |
| 28 PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam(); | 28 PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam(); |
| 29 | 29 |
| 30 ASSERT(m_pWidget != NULL); | |
| 31 | |
| 32 int nFlags = m_pWidget->GetFieldFlags(); | 30 int nFlags = m_pWidget->GetFieldFlags(); |
| 33 | |
| 34 if (nFlags & FIELDFLAG_EDIT) { | 31 if (nFlags & FIELDFLAG_EDIT) { |
| 35 cp.dwFlags |= PCBS_ALLOWCUSTOMTEXT; | 32 cp.dwFlags |= PCBS_ALLOWCUSTOMTEXT; |
| 36 } | 33 } |
| 37 | 34 |
| 38 if (!m_pFontMap) { | 35 if (!m_pFontMap) { |
| 39 m_pFontMap = new CBA_FontMap(m_pWidget, GetSystemHandler()); | 36 m_pFontMap = new CBA_FontMap(m_pWidget, GetSystemHandler()); |
| 40 m_pFontMap->Initial(); | 37 m_pFontMap->Initial(); |
| 41 } | 38 } |
| 42 | 39 |
| 43 cp.pFontMap = m_pFontMap; | 40 cp.pFontMap = m_pFontMap; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT)) | 83 if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT)) |
| 87 return nCurSel != m_pWidget->GetSelectedIndex(0); | 84 return nCurSel != m_pWidget->GetSelectedIndex(0); |
| 88 | 85 |
| 89 if (nCurSel >= 0) | 86 if (nCurSel >= 0) |
| 90 return nCurSel != m_pWidget->GetSelectedIndex(0); | 87 return nCurSel != m_pWidget->GetSelectedIndex(0); |
| 91 | 88 |
| 92 return pWnd->GetText() != m_pWidget->GetValue(); | 89 return pWnd->GetText() != m_pWidget->GetValue(); |
| 93 } | 90 } |
| 94 | 91 |
| 95 void CFFL_ComboBox::SaveData(CPDFSDK_PageView* pPageView) { | 92 void CFFL_ComboBox::SaveData(CPDFSDK_PageView* pPageView) { |
| 96 ASSERT(m_pWidget != NULL); | |
| 97 | |
| 98 if (CPWL_ComboBox* pWnd = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE)) { | 93 if (CPWL_ComboBox* pWnd = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE)) { |
| 99 CFX_WideString swText = pWnd->GetText(); | 94 CFX_WideString swText = pWnd->GetText(); |
| 100 int32_t nCurSel = pWnd->GetSelect(); | 95 int32_t nCurSel = pWnd->GetSelect(); |
| 101 | 96 |
| 102 // mantis:0004157 | 97 // mantis:0004157 |
| 103 FX_BOOL bSetValue = TRUE; | 98 FX_BOOL bSetValue = TRUE; |
| 104 | 99 |
| 105 if (m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT) { | 100 if (m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT) { |
| 106 if (nCurSel >= 0) { | 101 if (nCurSel >= 0) { |
| 107 if (swText != m_pWidget->GetOptionLabel(nCurSel)) | 102 if (swText != m_pWidget->GetOptionLabel(nCurSel)) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 case CPDF_AAction::Validate: | 153 case CPDF_AAction::Validate: |
| 159 if (CPWL_ComboBox* pComboBox = | 154 if (CPWL_ComboBox* pComboBox = |
| 160 static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, FALSE))) { | 155 static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, FALSE))) { |
| 161 if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { | 156 if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { |
| 162 fa.sValue = pEdit->GetText(); | 157 fa.sValue = pEdit->GetText(); |
| 163 } | 158 } |
| 164 } | 159 } |
| 165 break; | 160 break; |
| 166 case CPDF_AAction::LoseFocus: | 161 case CPDF_AAction::LoseFocus: |
| 167 case CPDF_AAction::GetFocus: | 162 case CPDF_AAction::GetFocus: |
| 168 ASSERT(m_pWidget != NULL); | |
| 169 fa.sValue = m_pWidget->GetValue(); | 163 fa.sValue = m_pWidget->GetValue(); |
| 170 break; | 164 break; |
| 171 default: | 165 default: |
| 172 break; | 166 break; |
| 173 } | 167 } |
| 174 } | 168 } |
| 175 | 169 |
| 176 void CFFL_ComboBox::SetActionData(CPDFSDK_PageView* pPageView, | 170 void CFFL_ComboBox::SetActionData(CPDFSDK_PageView* pPageView, |
| 177 CPDF_AAction::AActionType type, | 171 CPDF_AAction::AActionType type, |
| 178 const PDFSDK_FieldAction& fa) { | 172 const PDFSDK_FieldAction& fa) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 200 faOld.nSelStart != faNew.nSelStart || | 194 faOld.nSelStart != faNew.nSelStart || |
| 201 faOld.sChange != faNew.sChange; | 195 faOld.sChange != faNew.sChange; |
| 202 default: | 196 default: |
| 203 break; | 197 break; |
| 204 } | 198 } |
| 205 | 199 |
| 206 return FALSE; | 200 return FALSE; |
| 207 } | 201 } |
| 208 | 202 |
| 209 void CFFL_ComboBox::SaveState(CPDFSDK_PageView* pPageView) { | 203 void CFFL_ComboBox::SaveState(CPDFSDK_PageView* pPageView) { |
| 210 ASSERT(pPageView != NULL); | 204 ASSERT(pPageView); |
| 211 | 205 |
| 212 if (CPWL_ComboBox* pComboBox = | 206 if (CPWL_ComboBox* pComboBox = |
| 213 static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, FALSE))) { | 207 static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, FALSE))) { |
| 214 m_State.nIndex = pComboBox->GetSelect(); | 208 m_State.nIndex = pComboBox->GetSelect(); |
| 215 | 209 |
| 216 if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { | 210 if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { |
| 217 pEdit->GetSel(m_State.nStart, m_State.nEnd); | 211 pEdit->GetSel(m_State.nStart, m_State.nEnd); |
| 218 m_State.sValue = pEdit->GetText(); | 212 m_State.sValue = pEdit->GetText(); |
| 219 } | 213 } |
| 220 } | 214 } |
| 221 } | 215 } |
| 222 | 216 |
| 223 void CFFL_ComboBox::RestoreState(CPDFSDK_PageView* pPageView) { | 217 void CFFL_ComboBox::RestoreState(CPDFSDK_PageView* pPageView) { |
| 224 ASSERT(pPageView != NULL); | 218 ASSERT(pPageView); |
| 225 | 219 |
| 226 if (CPWL_ComboBox* pComboBox = | 220 if (CPWL_ComboBox* pComboBox = |
| 227 static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, TRUE))) { | 221 static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, TRUE))) { |
| 228 if (m_State.nIndex >= 0) | 222 if (m_State.nIndex >= 0) |
| 229 pComboBox->SetSelect(m_State.nIndex); | 223 pComboBox->SetSelect(m_State.nIndex); |
| 230 else { | 224 else { |
| 231 if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { | 225 if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { |
| 232 pEdit->SetText(m_State.sValue.c_str()); | 226 pEdit->SetText(m_State.sValue.c_str()); |
| 233 pEdit->SetSel(m_State.nStart, m_State.nEnd); | 227 pEdit->SetSel(m_State.nStart, m_State.nEnd); |
| 234 } | 228 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 261 if (CPWL_ComboBox* pComboBox = | 255 if (CPWL_ComboBox* pComboBox = |
| 262 static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, FALSE))) { | 256 static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, FALSE))) { |
| 263 if (CPWL_Edit* pEdit = pComboBox->GetEdit()) | 257 if (CPWL_Edit* pEdit = pComboBox->GetEdit()) |
| 264 return pEdit->IsTextFull(); | 258 return pEdit->IsTextFull(); |
| 265 } | 259 } |
| 266 return FALSE; | 260 return FALSE; |
| 267 } | 261 } |
| 268 #endif // PDF_ENABLE_XFA | 262 #endif // PDF_ENABLE_XFA |
| 269 | 263 |
| 270 void CFFL_ComboBox::OnSetFocus(CPWL_Wnd* pWnd) { | 264 void CFFL_ComboBox::OnSetFocus(CPWL_Wnd* pWnd) { |
| 271 ASSERT(m_pApp != NULL); | 265 ASSERT(m_pApp); |
| 272 | |
| 273 ASSERT(pWnd != NULL); | |
| 274 | 266 |
| 275 if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) { | 267 if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) { |
| 276 CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; | 268 CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; |
| 277 pEdit->SetCharSet(134); | 269 pEdit->SetCharSet(134); |
| 278 pEdit->SetCodePage(936); | 270 pEdit->SetCodePage(936); |
| 279 | 271 |
| 280 pEdit->SetReadyToInput(); | 272 pEdit->SetReadyToInput(); |
| 281 CFX_WideString wsText = pEdit->GetText(); | 273 CFX_WideString wsText = pEdit->GetText(); |
| 282 int nCharacters = wsText.GetLength(); | 274 int nCharacters = wsText.GetLength(); |
| 283 CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); | 275 CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); |
| 284 unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str(); | 276 unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str(); |
| 285 m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, | 277 m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, |
| 286 nCharacters, TRUE); | 278 nCharacters, TRUE); |
| 287 | 279 |
| 288 pEdit->SetEditNotify(this); | 280 pEdit->SetEditNotify(this); |
| 289 } | 281 } |
| 290 } | 282 } |
| 291 | 283 |
| 292 void CFFL_ComboBox::OnKillFocus(CPWL_Wnd* pWnd) { | 284 void CFFL_ComboBox::OnKillFocus(CPWL_Wnd* pWnd) { |
| 293 ASSERT(m_pApp != NULL); | 285 ASSERT(m_pApp); |
| 294 } | 286 } |
| 295 | 287 |
| 296 void CFFL_ComboBox::OnAddUndo(CPWL_Edit* pEdit) { | 288 void CFFL_ComboBox::OnAddUndo(CPWL_Edit* pEdit) { |
| 297 ASSERT(pEdit != NULL); | 289 ASSERT(pEdit); |
| 298 } | 290 } |
| 299 | 291 |
| 300 CFX_WideString CFFL_ComboBox::GetSelectExportText() { | 292 CFX_WideString CFFL_ComboBox::GetSelectExportText() { |
| 301 CFX_WideString swRet; | 293 CFX_WideString swRet; |
| 302 | 294 |
| 303 int nExport = -1; | 295 int nExport = -1; |
| 304 CPDFSDK_PageView* pPageView = GetCurPageView(); | 296 CPDFSDK_PageView* pPageView = GetCurPageView(); |
| 305 if (CPWL_ComboBox* pComboBox = | 297 if (CPWL_ComboBox* pComboBox = |
| 306 (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE)) { | 298 (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE)) { |
| 307 nExport = pComboBox->GetSelect(); | 299 nExport = pComboBox->GetSelect(); |
| 308 } | 300 } |
| 309 | 301 |
| 310 if (nExport >= 0) { | 302 if (nExport >= 0) { |
| 311 if (CPDF_FormField* pFormField = m_pWidget->GetFormField()) { | 303 if (CPDF_FormField* pFormField = m_pWidget->GetFormField()) { |
| 312 swRet = pFormField->GetOptionValue(nExport); | 304 swRet = pFormField->GetOptionValue(nExport); |
| 313 if (swRet.IsEmpty()) | 305 if (swRet.IsEmpty()) |
| 314 swRet = pFormField->GetOptionLabel(nExport); | 306 swRet = pFormField->GetOptionLabel(nExport); |
| 315 } | 307 } |
| 316 } | 308 } |
| 317 | 309 |
| 318 return swRet; | 310 return swRet; |
| 319 } | 311 } |
| OLD | NEW |