diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-04-24 16:26:11 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-24 20:50:12 +0000 |
commit | ed991c7d9d5bede7e3bb93ff6571512d875716dd (patch) | |
tree | f59ba63435f5c83db25c12c49ce798c274ee2608 /xfa/fxfa/app/xfa_fftextedit.cpp | |
parent | 302cd78d00c280cb212a5934a7a8293851e9650c (diff) | |
download | pdfium-ed991c7d9d5bede7e3bb93ff6571512d875716dd.tar.xz |
Nit cleanup in XFA widget code
This Cl cleans up nits in the remaining XFA widget code.
Change-Id: I10f33ee2ab0ebdb06aeee582a04188fbd7a8bf9e
Reviewed-on: https://pdfium-review.googlesource.com/4472
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/app/xfa_fftextedit.cpp')
-rw-r--r-- | xfa/fxfa/app/xfa_fftextedit.cpp | 239 |
1 files changed, 129 insertions, 110 deletions
diff --git a/xfa/fxfa/app/xfa_fftextedit.cpp b/xfa/fxfa/app/xfa_fftextedit.cpp index 03f09cc11a..a1030f538a 100644 --- a/xfa/fxfa/app/xfa_fftextedit.cpp +++ b/xfa/fxfa/app/xfa_fftextedit.cpp @@ -88,11 +88,12 @@ void CXFA_FFTextEdit::UpdateWidgetProperty() { dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; dwExtendedStyle |= FWL_STYLEEXT_EDT_MultiLine; } + XFA_Element eType = XFA_Element::Unknown; int32_t iMaxChars = m_pDataAcc->GetMaxChars(eType); - if (eType == XFA_Element::ExData) { + if (eType == XFA_Element::ExData) iMaxChars = 0; - } + int32_t iNumCells = m_pDataAcc->GetNumberOfCells(); if (iNumCells == 0) { dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText; @@ -166,18 +167,22 @@ bool CXFA_FFTextEdit::OnSetFocus(CXFA_FFWidget* pOldWidget) { TranslateFWLMessage(&ms); return true; } + bool CXFA_FFTextEdit::OnKillFocus(CXFA_FFWidget* pNewWidget) { CFWL_MessageKillFocus ms(nullptr, m_pNormalWidget.get()); TranslateFWLMessage(&ms); m_dwStatus &= ~XFA_WidgetStatus_Focused; + SetEditScrollOffset(); ProcessCommittedData(); UpdateFWLData(); AddInvalidateRect(); CXFA_FFWidget::OnKillFocus(pNewWidget); + m_dwStatus &= ~XFA_WidgetStatus_TextEditValueChanged; return true; } + bool CXFA_FFTextEdit::CommitData() { CFX_WideString wsText = static_cast<CFWL_Edit*>(m_pNormalWidget.get())->GetText(); @@ -188,84 +193,90 @@ bool CXFA_FFTextEdit::CommitData() { ValidateNumberField(wsText); return false; } + void CXFA_FFTextEdit::ValidateNumberField(const CFX_WideString& wsText) { CXFA_WidgetAcc* pAcc = GetDataAcc(); - if (pAcc && pAcc->GetUIType() == XFA_Element::NumericEdit) { - IXFA_AppProvider* pAppProvider = GetApp()->GetAppProvider(); - if (pAppProvider) { - CFX_WideString wsSomField; - pAcc->GetNode()->GetSOMExpression(wsSomField); - - CFX_WideString wsMessage; - wsMessage.Format(L"%s can not contain %s", wsText.c_str(), - wsSomField.c_str()); - pAppProvider->MsgBox(wsMessage, pAppProvider->GetAppTitle(), - XFA_MBICON_Error, XFA_MB_OK); - } - } + if (!pAcc || pAcc->GetUIType() != XFA_Element::NumericEdit) + return; + + IXFA_AppProvider* pAppProvider = GetApp()->GetAppProvider(); + if (!pAppProvider) + return; + + CFX_WideString wsSomField; + pAcc->GetNode()->GetSOMExpression(wsSomField); + + CFX_WideString wsMessage; + wsMessage.Format(L"%s can not contain %s", wsText.c_str(), + wsSomField.c_str()); + pAppProvider->MsgBox(wsMessage, pAppProvider->GetAppTitle(), XFA_MBICON_Error, + XFA_MB_OK); } + bool CXFA_FFTextEdit::IsDataChanged() { return (m_dwStatus & XFA_WidgetStatus_TextEditValueChanged) != 0; } + uint32_t CXFA_FFTextEdit::GetAlignment() { + CXFA_Para para = m_pDataAcc->GetPara(); + if (!para) + return 0; + uint32_t dwExtendedStyle = 0; - if (CXFA_Para para = m_pDataAcc->GetPara()) { - int32_t iHorz = para.GetHorizontalAlign(); - switch (iHorz) { - case XFA_ATTRIBUTEENUM_Center: - dwExtendedStyle |= FWL_STYLEEXT_EDT_HCenter; - break; - case XFA_ATTRIBUTEENUM_Justify: - dwExtendedStyle |= FWL_STYLEEXT_EDT_Justified; - break; - case XFA_ATTRIBUTEENUM_JustifyAll: - break; - case XFA_ATTRIBUTEENUM_Radix: - break; - case XFA_ATTRIBUTEENUM_Right: - dwExtendedStyle |= FWL_STYLEEXT_EDT_HFar; - break; - default: - dwExtendedStyle |= FWL_STYLEEXT_EDT_HNear; - break; - } - int32_t iVert = para.GetVerticalAlign(); - switch (iVert) { - case XFA_ATTRIBUTEENUM_Middle: - dwExtendedStyle |= FWL_STYLEEXT_EDT_VCenter; - break; - case XFA_ATTRIBUTEENUM_Bottom: - dwExtendedStyle |= FWL_STYLEEXT_EDT_VFar; - break; - default: - dwExtendedStyle |= FWL_STYLEEXT_EDT_VNear; - break; - } + switch (para.GetHorizontalAlign()) { + case XFA_ATTRIBUTEENUM_Center: + dwExtendedStyle |= FWL_STYLEEXT_EDT_HCenter; + break; + case XFA_ATTRIBUTEENUM_Justify: + dwExtendedStyle |= FWL_STYLEEXT_EDT_Justified; + break; + case XFA_ATTRIBUTEENUM_JustifyAll: + case XFA_ATTRIBUTEENUM_Radix: + break; + case XFA_ATTRIBUTEENUM_Right: + dwExtendedStyle |= FWL_STYLEEXT_EDT_HFar; + break; + default: + dwExtendedStyle |= FWL_STYLEEXT_EDT_HNear; + break; + } + + switch (para.GetVerticalAlign()) { + case XFA_ATTRIBUTEENUM_Middle: + dwExtendedStyle |= FWL_STYLEEXT_EDT_VCenter; + break; + case XFA_ATTRIBUTEENUM_Bottom: + dwExtendedStyle |= FWL_STYLEEXT_EDT_VFar; + break; + default: + dwExtendedStyle |= FWL_STYLEEXT_EDT_VNear; + break; } return dwExtendedStyle; } + bool CXFA_FFTextEdit::UpdateFWLData() { - if (!m_pNormalWidget) { + if (!m_pNormalWidget) return false; - } + XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display; - if (IsFocused()) { + if (IsFocused()) eType = XFA_VALUEPICTURE_Edit; - } + bool bUpdate = false; if (m_pDataAcc->GetUIType() == XFA_Element::TextEdit && m_pDataAcc->GetNumberOfCells() < 0) { XFA_Element elementType = XFA_Element::Unknown; int32_t iMaxChars = m_pDataAcc->GetMaxChars(elementType); - if (elementType == XFA_Element::ExData) { + if (elementType == XFA_Element::ExData) iMaxChars = eType == XFA_VALUEPICTURE_Edit ? iMaxChars : 0; - } if (static_cast<CFWL_Edit*>(m_pNormalWidget.get())->GetLimit() != iMaxChars) { static_cast<CFWL_Edit*>(m_pNormalWidget.get())->SetLimit(iMaxChars); bUpdate = true; } } + if (m_pDataAcc->GetUIType() == XFA_Element::Barcode) { int32_t nDataLen = 0; if (eType == XFA_VALUEPICTURE_Edit) @@ -273,19 +284,22 @@ bool CXFA_FFTextEdit::UpdateFWLData() { static_cast<CFWL_Edit*>(m_pNormalWidget.get())->SetLimit(nDataLen); bUpdate = true; } + CFX_WideString wsText; m_pDataAcc->GetValue(wsText, eType); + CFX_WideString wsOldText = static_cast<CFWL_Edit*>(m_pNormalWidget.get())->GetText(); if (wsText != wsOldText || (eType == XFA_VALUEPICTURE_Edit && bUpdate)) { static_cast<CFWL_Edit*>(m_pNormalWidget.get())->SetText(wsText); bUpdate = true; } - if (bUpdate) { + if (bUpdate) m_pNormalWidget->Update(); - } + return true; } + void CXFA_FFTextEdit::OnTextChanged(CFWL_Widget* pWidget, const CFX_WideString& wsChanged, const CFX_WideString& wsPrevText) { @@ -300,18 +314,17 @@ void CXFA_FFTextEdit::OnTextChanged(CFWL_Widget* pWidget, CFWL_DateTimePicker* pDateTime = (CFWL_DateTimePicker*)pEdit; eParam.m_wsNewText = pDateTime->GetEditText(); int32_t iSels = pDateTime->CountSelRanges(); - if (iSels) { + if (iSels) eParam.m_iSelEnd = pDateTime->GetSelRange(0, &eParam.m_iSelStart); - } } else { eParam.m_wsNewText = pEdit->GetText(); int32_t iSels = pEdit->CountSelRanges(); - if (iSels) { + if (iSels) eParam.m_iSelEnd = pEdit->GetSelRange(0, &eParam.m_iSelStart); - } } m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); } + void CXFA_FFTextEdit::OnTextFull(CFWL_Widget* pWidget) { CXFA_EventParam eParam; eParam.m_eType = XFA_EVENT_Full; @@ -387,6 +400,7 @@ bool CXFA_FFNumericEdit::LoadWidget() { m_pNormalWidget->UnlockUpdate(); return CXFA_FFField::LoadWidget(); } + void CXFA_FFNumericEdit::UpdateWidgetProperty() { CFWL_Edit* pWidget = static_cast<CFWL_Edit*>(m_pNormalWidget.get()); if (!pWidget) @@ -426,13 +440,15 @@ bool CXFA_FFNumericEdit::OnValidate(CFWL_Widget* pWidget, CFX_WideString& wsText) { CFX_WideString wsPattern; m_pDataAcc->GetPictureContent(wsPattern, XFA_VALUEPICTURE_Edit); - if (!wsPattern.IsEmpty()) { + if (!wsPattern.IsEmpty()) return true; - } + int32_t iLeads = 0; m_pDataAcc->GetLeadDigits(iLeads); + int32_t iFracs = 0; m_pDataAcc->GetFracDigits(iFracs); + CFX_WideString wsFormat; CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(m_pDataAcc); widgetValue.GetNumbericFormat(wsFormat, iLeads, iFracs); @@ -477,14 +493,13 @@ void CXFA_FFPasswordEdit::UpdateWidgetProperty() { FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar | FWL_STYLEEXT_EDT_Password | FWL_STYLEEXT_EDT_LastLineHeight; dwExtendedStyle |= UpdateUIProperty(); + CFX_WideString wsPassWord; m_pDataAcc->GetPasswordChar(wsPassWord); - if (!wsPassWord.IsEmpty()) { + if (!wsPassWord.IsEmpty()) pWidget->SetAliasChar(wsPassWord.GetAt(0)); - } - if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { + if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll; - } if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly; @@ -492,6 +507,7 @@ void CXFA_FFPasswordEdit::UpdateWidgetProperty() { dwExtendedStyle |= GetAlignment(); m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); } + CXFA_FFDateTimeEdit::CXFA_FFDateTimeEdit(CXFA_WidgetAcc* pDataAcc) : CXFA_FFTextEdit(pDataAcc) {} @@ -543,6 +559,7 @@ bool CXFA_FFDateTimeEdit::LoadWidget() { m_pNormalWidget->UnlockUpdate(); return CXFA_FFField::LoadWidget(); } + void CXFA_FFDateTimeEdit::UpdateWidgetProperty() { CFWL_DateTimePicker* pWidget = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); @@ -563,45 +580,46 @@ void CXFA_FFDateTimeEdit::UpdateWidgetProperty() { !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) { dwEditStyles |= FWL_STYLEEXT_EDT_ReadOnly; } - if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { + if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) dwEditStyles |= FWL_STYLEEXT_EDT_AutoHScroll; - } + pWidget->ModifyEditStylesEx(dwEditStyles, 0xFFFFFFFF); } + uint32_t CXFA_FFDateTimeEdit::GetAlignment() { + CXFA_Para para = m_pDataAcc->GetPara(); + if (!para) + return 0; + uint32_t dwExtendedStyle = 0; - if (CXFA_Para para = m_pDataAcc->GetPara()) { - int32_t iHorz = para.GetHorizontalAlign(); - switch (iHorz) { - case XFA_ATTRIBUTEENUM_Center: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHCenter; - break; - case XFA_ATTRIBUTEENUM_Justify: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditJustified; - break; - case XFA_ATTRIBUTEENUM_JustifyAll: - break; - case XFA_ATTRIBUTEENUM_Radix: - break; - case XFA_ATTRIBUTEENUM_Right: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHFar; - break; - default: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHNear; - break; - } - int32_t iVert = para.GetVerticalAlign(); - switch (iVert) { - case XFA_ATTRIBUTEENUM_Middle: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVCenter; - break; - case XFA_ATTRIBUTEENUM_Bottom: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVFar; - break; - default: - dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVNear; - break; - } + switch (para.GetHorizontalAlign()) { + case XFA_ATTRIBUTEENUM_Center: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHCenter; + break; + case XFA_ATTRIBUTEENUM_Justify: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditJustified; + break; + case XFA_ATTRIBUTEENUM_JustifyAll: + case XFA_ATTRIBUTEENUM_Radix: + break; + case XFA_ATTRIBUTEENUM_Right: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHFar; + break; + default: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHNear; + break; + } + + switch (para.GetVerticalAlign()) { + case XFA_ATTRIBUTEENUM_Middle: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVCenter; + break; + case XFA_ATTRIBUTEENUM_Bottom: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVFar; + break; + default: + dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVNear; + break; } return dwExtendedStyle; } @@ -616,33 +634,34 @@ bool CXFA_FFDateTimeEdit::CommitData() { } bool CXFA_FFDateTimeEdit::UpdateFWLData() { - if (!m_pNormalWidget) { + if (!m_pNormalWidget) return false; - } + XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display; - if (IsFocused()) { + if (IsFocused()) eType = XFA_VALUEPICTURE_Edit; - } + CFX_WideString wsText; m_pDataAcc->GetValue(wsText, eType); - static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get())->SetEditText(wsText); + + auto* normalWidget = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()); + normalWidget->SetEditText(wsText); if (IsFocused() && !wsText.IsEmpty()) { CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc); CFX_DateTime date = lcValue.GetDate(); if (lcValue.IsValid()) { - if (date.IsSet()) { - static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get()) - ->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay()); - } + if (date.IsSet()) + normalWidget->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay()); } } m_pNormalWidget->Update(); return true; } + bool CXFA_FFDateTimeEdit::IsDataChanged() { - if (m_dwStatus & XFA_WidgetStatus_TextEditValueChanged) { + if (m_dwStatus & XFA_WidgetStatus_TextEditValueChanged) return true; - } + CFX_WideString wsText = static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get())->GetEditText(); CFX_WideString wsOldValue; |