diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-04-20 16:11:14 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-20 20:29:07 +0000 |
commit | 88008a2be11ccbb5001dc540e96024a9641e4915 (patch) | |
tree | 41805821999d0d1dfba41e180967699865aa28e1 /xfa/fxfa/app/xfa_ffchoicelist.cpp | |
parent | 138cc10361b7dca0fa13efb59f24394797e41219 (diff) | |
download | pdfium-88008a2be11ccbb5001dc540e96024a9641e4915.tar.xz |
Cleanup some XFA widget code
This CL cleans up the nits in some of the XFA widget files.
Change-Id: If72e7855a09a22b2ec8ad3ce297b142ce35f71c9
Reviewed-on: https://pdfium-review.googlesource.com/4395
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'xfa/fxfa/app/xfa_ffchoicelist.cpp')
-rw-r--r-- | xfa/fxfa/app/xfa_ffchoicelist.cpp | 227 |
1 files changed, 123 insertions, 104 deletions
diff --git a/xfa/fxfa/app/xfa_ffchoicelist.cpp b/xfa/fxfa/app/xfa_ffchoicelist.cpp index 061e9aa842..b191f838ce 100644 --- a/xfa/fxfa/app/xfa_ffchoicelist.cpp +++ b/xfa/fxfa/app/xfa_ffchoicelist.cpp @@ -27,15 +27,28 @@ #include "xfa/fxfa/cxfa_ffpageview.h" #include "xfa/fxfa/cxfa_ffwidget.h" +namespace { + +CFWL_ListBox* ToListBox(CFWL_Widget* widget) { + return static_cast<CFWL_ListBox*>(widget); +} + +CFWL_ComboBox* ToComboBox(CFWL_Widget* widget) { + return static_cast<CFWL_ComboBox*>(widget); +} + +} // namespace + CXFA_FFListBox::CXFA_FFListBox(CXFA_WidgetAcc* pDataAcc) : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {} CXFA_FFListBox::~CXFA_FFListBox() { - if (m_pNormalWidget) { - CFWL_NoteDriver* pNoteDriver = - m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); - pNoteDriver->UnregisterEventTarget(m_pNormalWidget.get()); - } + if (!m_pNormalWidget) + return; + + CFWL_NoteDriver* pNoteDriver = + m_pNormalWidget->GetOwnerApp()->GetNoteDriver(); + pNoteDriver->UnregisterEventTarget(m_pNormalWidget.get()); } bool CXFA_FFListBox::LoadWidget() { @@ -74,16 +87,18 @@ bool CXFA_FFListBox::LoadWidget() { bool CXFA_FFListBox::OnKillFocus(CXFA_FFWidget* pNewFocus) { if (!ProcessCommittedData()) UpdateFWLData(); + CXFA_FFField::OnKillFocus(pNewFocus); return true; } bool CXFA_FFListBox::CommitData() { - auto* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget.get()); + auto* pListBox = ToListBox(m_pNormalWidget.get()); std::vector<int32_t> iSelArray; int32_t iSels = pListBox->CountSelItems(); for (int32_t i = 0; i < iSels; ++i) iSelArray.push_back(pListBox->GetSelIndex(i)); + m_pDataAcc->SetSelectedItems(iSelArray, true, false, true); return true; } @@ -91,7 +106,7 @@ bool CXFA_FFListBox::CommitData() { bool CXFA_FFListBox::IsDataChanged() { std::vector<int32_t> iSelArray = m_pDataAcc->GetSelectedItems(); int32_t iOldSels = pdfium::CollectionSize<int32_t>(iSelArray); - auto* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget.get()); + auto* pListBox = ToListBox(m_pNormalWidget.get()); int32_t iSels = pListBox->CountSelItems(); if (iOldSels != iSels) return true; @@ -105,34 +120,36 @@ bool CXFA_FFListBox::IsDataChanged() { } uint32_t CXFA_FFListBox::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_LTB_CenterAlign; - break; - case XFA_ATTRIBUTEENUM_Justify: - break; - case XFA_ATTRIBUTEENUM_JustifyAll: - break; - case XFA_ATTRIBUTEENUM_Radix: - break; - case XFA_ATTRIBUTEENUM_Right: - dwExtendedStyle |= FWL_STYLEEXT_LTB_RightAlign; - break; - default: - dwExtendedStyle |= FWL_STYLEEXT_LTB_LeftAlign; - break; - } + switch (para.GetHorizontalAlign()) { + case XFA_ATTRIBUTEENUM_Center: + dwExtendedStyle |= FWL_STYLEEXT_LTB_CenterAlign; + break; + case XFA_ATTRIBUTEENUM_Justify: + break; + case XFA_ATTRIBUTEENUM_JustifyAll: + break; + case XFA_ATTRIBUTEENUM_Radix: + break; + case XFA_ATTRIBUTEENUM_Right: + dwExtendedStyle |= FWL_STYLEEXT_LTB_RightAlign; + break; + default: + dwExtendedStyle |= FWL_STYLEEXT_LTB_LeftAlign; + break; } return dwExtendedStyle; } + bool CXFA_FFListBox::UpdateFWLData() { if (!m_pNormalWidget) return false; - auto* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget.get()); + auto* pListBox = ToListBox(m_pNormalWidget.get()); std::vector<int32_t> iSelArray = m_pDataAcc->GetSelectedItems(); std::vector<CFWL_ListItem*> selItemArray(iSelArray.size()); std::transform(iSelArray.begin(), iSelArray.end(), selItemArray.begin(), @@ -146,13 +163,13 @@ bool CXFA_FFListBox::UpdateFWLData() { return true; } -void CXFA_FFListBox::OnSelectChanged(CFWL_Widget* pWidget, - const std::vector<int32_t>& arrSels) { +void CXFA_FFListBox::OnSelectChanged(CFWL_Widget* pWidget) { CXFA_EventParam eParam; eParam.m_eType = XFA_EVENT_Change; eParam.m_pTarget = m_pDataAcc; m_pDataAcc->GetValue(eParam.m_wsPrevText, XFA_VALUEPICTURE_Raw); - auto* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget.get()); + + auto* pListBox = ToListBox(m_pNormalWidget.get()); int32_t iSels = pListBox->CountSelItems(); if (iSels > 0) { CFWL_ListItem* item = pListBox->GetSelItem(0); @@ -162,7 +179,7 @@ void CXFA_FFListBox::OnSelectChanged(CFWL_Widget* pWidget, } void CXFA_FFListBox::SetItemState(int32_t nIndex, bool bSelected) { - auto* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget.get()); + auto* pListBox = ToListBox(m_pNormalWidget.get()); pListBox->SetSelItem(pListBox->GetSelItem(nIndex), bSelected); m_pNormalWidget->Update(); AddInvalidateRect(); @@ -171,14 +188,13 @@ void CXFA_FFListBox::SetItemState(int32_t nIndex, bool bSelected) { void CXFA_FFListBox::InsertItem(const CFX_WideStringC& wsLabel, int32_t nIndex) { CFX_WideString wsTemp(wsLabel); - static_cast<CFWL_ListBox*>(m_pNormalWidget.get()) - ->AddString(wsTemp.AsStringC()); + ToListBox(m_pNormalWidget.get())->AddString(wsTemp.AsStringC()); m_pNormalWidget->Update(); AddInvalidateRect(); } void CXFA_FFListBox::DeleteItem(int32_t nIndex) { - auto* pListBox = static_cast<CFWL_ListBox*>(m_pNormalWidget.get()); + auto* pListBox = ToListBox(m_pNormalWidget.get()); if (nIndex < 0) pListBox->DeleteAll(); else @@ -195,16 +211,15 @@ void CXFA_FFListBox::OnProcessMessage(CFWL_Message* pMessage) { void CXFA_FFListBox::OnProcessEvent(CFWL_Event* pEvent) { CXFA_FFField::OnProcessEvent(pEvent); switch (pEvent->GetType()) { - case CFWL_Event::Type::SelectChanged: { - std::vector<int32_t> arrSels; - OnSelectChanged(m_pNormalWidget.get(), arrSels); + case CFWL_Event::Type::SelectChanged: + OnSelectChanged(m_pNormalWidget.get()); break; - } default: break; } m_pOldDelegate->OnProcessEvent(pEvent); } + void CXFA_FFListBox::OnDrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) { m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix); @@ -216,13 +231,11 @@ CXFA_FFComboBox::CXFA_FFComboBox(CXFA_WidgetAcc* pDataAcc) CXFA_FFComboBox::~CXFA_FFComboBox() {} CFX_RectF CXFA_FFComboBox::GetBBox(uint32_t dwStatus, bool bDrawFocus) { - if (bDrawFocus) - return CFX_RectF(); - return CXFA_FFWidget::GetBBox(dwStatus); + return bDrawFocus ? CFX_RectF() : CXFA_FFWidget::GetBBox(dwStatus); } bool CXFA_FFComboBox::PtInActiveRect(const CFX_PointF& point) { - auto* pComboBox = static_cast<CFWL_ComboBox*>(m_pNormalWidget.get()); + auto* pComboBox = ToComboBox(m_pNormalWidget.get()); return pComboBox && pComboBox->GetBBox().Contains(point); } @@ -251,13 +264,14 @@ bool CXFA_FFComboBox::LoadWidget() { m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Raw); pComboBox->SetEditText(wsText); } + UpdateWidgetProperty(); m_pNormalWidget->UnlockUpdate(); return CXFA_FFField::LoadWidget(); } void CXFA_FFComboBox::UpdateWidgetProperty() { - auto* pComboBox = static_cast<CFWL_ComboBox*>(m_pNormalWidget.get()); + auto* pComboBox = ToComboBox(m_pNormalWidget.get()); if (!pComboBox) return; @@ -276,9 +290,10 @@ void CXFA_FFComboBox::UpdateWidgetProperty() { } dwExtendedStyle |= GetAlignment(); m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF); - if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) { + + if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) dwEditStyles |= FWL_STYLEEXT_EDT_AutoHScroll; - } + pComboBox->EditModifyStylesEx(dwEditStyles, 0xFFFFFFFF); } @@ -299,7 +314,7 @@ bool CXFA_FFComboBox::OnKillFocus(CXFA_FFWidget* pNewWidget) { } void CXFA_FFComboBox::OpenDropDownList() { - static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->OpenDropDownList(true); + ToComboBox(m_pNormalWidget.get())->OpenDropDownList(true); } bool CXFA_FFComboBox::CommitData() { @@ -307,7 +322,7 @@ bool CXFA_FFComboBox::CommitData() { } bool CXFA_FFComboBox::IsDataChanged() { - auto* pFWLcombobox = static_cast<CFWL_ComboBox*>(m_pNormalWidget.get()); + auto* pFWLcombobox = ToComboBox(m_pNormalWidget.get()); CFX_WideString wsText = pFWLcombobox->GetEditText(); int32_t iCursel = pFWLcombobox->GetCurSel(); if (iCursel >= 0) { @@ -315,6 +330,7 @@ bool CXFA_FFComboBox::IsDataChanged() { if (wsSel == wsText) m_pDataAcc->GetChoiceListItem(wsText, iCursel, true); } + CFX_WideString wsOldValue; m_pDataAcc->GetValue(wsOldValue, XFA_VALUEPICTURE_Raw); if (wsOldValue == wsText) @@ -327,51 +343,52 @@ bool CXFA_FFComboBox::IsDataChanged() { void CXFA_FFComboBox::FWLEventSelChange(CXFA_EventParam* pParam) { pParam->m_eType = XFA_EVENT_Change; pParam->m_pTarget = m_pDataAcc; - auto* pFWLcombobox = static_cast<CFWL_ComboBox*>(m_pNormalWidget.get()); - pParam->m_wsNewText = pFWLcombobox->GetEditText(); + pParam->m_wsNewText = ToComboBox(m_pNormalWidget.get())->GetEditText(); m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, pParam); } + uint32_t CXFA_FFComboBox::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_CMB_EditHCenter | FWL_STYLEEXT_CMB_ListItemCenterAlign; - break; - case XFA_ATTRIBUTEENUM_Justify: - dwExtendedStyle |= FWL_STYLEEXT_CMB_EditJustified; - break; - case XFA_ATTRIBUTEENUM_JustifyAll: - break; - case XFA_ATTRIBUTEENUM_Radix: - break; - case XFA_ATTRIBUTEENUM_Right: - break; - default: - dwExtendedStyle |= - FWL_STYLEEXT_CMB_EditHNear | FWL_STYLEEXT_CMB_ListItemLeftAlign; - break; - } - int32_t iVert = para.GetVerticalAlign(); - switch (iVert) { - case XFA_ATTRIBUTEENUM_Middle: - dwExtendedStyle |= FWL_STYLEEXT_CMB_EditVCenter; - break; - case XFA_ATTRIBUTEENUM_Bottom: - dwExtendedStyle |= FWL_STYLEEXT_CMB_EditVFar; - break; - default: - dwExtendedStyle |= FWL_STYLEEXT_CMB_EditVNear; - break; - } + switch (para.GetHorizontalAlign()) { + case XFA_ATTRIBUTEENUM_Center: + dwExtendedStyle |= + FWL_STYLEEXT_CMB_EditHCenter | FWL_STYLEEXT_CMB_ListItemCenterAlign; + break; + case XFA_ATTRIBUTEENUM_Justify: + dwExtendedStyle |= FWL_STYLEEXT_CMB_EditJustified; + break; + case XFA_ATTRIBUTEENUM_JustifyAll: + break; + case XFA_ATTRIBUTEENUM_Radix: + break; + case XFA_ATTRIBUTEENUM_Right: + break; + default: + dwExtendedStyle |= + FWL_STYLEEXT_CMB_EditHNear | FWL_STYLEEXT_CMB_ListItemLeftAlign; + break; + } + + switch (para.GetVerticalAlign()) { + case XFA_ATTRIBUTEENUM_Middle: + dwExtendedStyle |= FWL_STYLEEXT_CMB_EditVCenter; + break; + case XFA_ATTRIBUTEENUM_Bottom: + dwExtendedStyle |= FWL_STYLEEXT_CMB_EditVFar; + break; + default: + dwExtendedStyle |= FWL_STYLEEXT_CMB_EditVNear; + break; } return dwExtendedStyle; } bool CXFA_FFComboBox::UpdateFWLData() { - auto* pComboBox = static_cast<CFWL_ComboBox*>(m_pNormalWidget.get()); + auto* pComboBox = ToComboBox(m_pNormalWidget.get()); if (!pComboBox) return false; @@ -390,32 +407,32 @@ bool CXFA_FFComboBox::UpdateFWLData() { bool CXFA_FFComboBox::CanUndo() { return m_pDataAcc->IsChoiceListAllowTextEntry() && - static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditCanUndo(); + ToComboBox(m_pNormalWidget.get())->EditCanUndo(); } bool CXFA_FFComboBox::CanRedo() { return m_pDataAcc->IsChoiceListAllowTextEntry() && - static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditCanRedo(); + ToComboBox(m_pNormalWidget.get())->EditCanRedo(); } bool CXFA_FFComboBox::Undo() { return m_pDataAcc->IsChoiceListAllowTextEntry() && - static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditUndo(); + ToComboBox(m_pNormalWidget.get())->EditUndo(); } bool CXFA_FFComboBox::Redo() { return m_pDataAcc->IsChoiceListAllowTextEntry() && - static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditRedo(); + ToComboBox(m_pNormalWidget.get())->EditRedo(); } bool CXFA_FFComboBox::CanCopy() { - return static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditCanCopy(); + return ToComboBox(m_pNormalWidget.get())->EditCanCopy(); } bool CXFA_FFComboBox::CanCut() { return m_pDataAcc->GetAccess() == XFA_ATTRIBUTEENUM_Open && m_pDataAcc->IsChoiceListAllowTextEntry() && - static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditCanCut(); + ToComboBox(m_pNormalWidget.get())->EditCanCut(); } bool CXFA_FFComboBox::CanPaste() { @@ -424,55 +441,54 @@ bool CXFA_FFComboBox::CanPaste() { } bool CXFA_FFComboBox::CanSelectAll() { - return static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditCanSelectAll(); + return ToComboBox(m_pNormalWidget.get())->EditCanSelectAll(); } bool CXFA_FFComboBox::Copy(CFX_WideString& wsCopy) { - return static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditCopy(wsCopy); + return ToComboBox(m_pNormalWidget.get())->EditCopy(wsCopy); } bool CXFA_FFComboBox::Cut(CFX_WideString& wsCut) { return m_pDataAcc->IsChoiceListAllowTextEntry() && - static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditCut(wsCut); + ToComboBox(m_pNormalWidget.get())->EditCut(wsCut); } bool CXFA_FFComboBox::Paste(const CFX_WideString& wsPaste) { return m_pDataAcc->IsChoiceListAllowTextEntry() && - static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditPaste(wsPaste); + ToComboBox(m_pNormalWidget.get())->EditPaste(wsPaste); } void CXFA_FFComboBox::SelectAll() { - static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditSelectAll(); + ToComboBox(m_pNormalWidget.get())->EditSelectAll(); } void CXFA_FFComboBox::Delete() { - static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditDelete(); + ToComboBox(m_pNormalWidget.get())->EditDelete(); } void CXFA_FFComboBox::DeSelect() { - static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->EditDeSelect(); + ToComboBox(m_pNormalWidget.get())->EditDeSelect(); } void CXFA_FFComboBox::SetItemState(int32_t nIndex, bool bSelected) { - static_cast<CFWL_ComboBox*>(m_pNormalWidget.get()) - ->SetCurSel(bSelected ? nIndex : -1); + ToComboBox(m_pNormalWidget.get())->SetCurSel(bSelected ? nIndex : -1); m_pNormalWidget->Update(); AddInvalidateRect(); } void CXFA_FFComboBox::InsertItem(const CFX_WideStringC& wsLabel, int32_t nIndex) { - static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->AddString(wsLabel); + ToComboBox(m_pNormalWidget.get())->AddString(wsLabel); m_pNormalWidget->Update(); AddInvalidateRect(); } void CXFA_FFComboBox::DeleteItem(int32_t nIndex) { - if (nIndex < 0) { - static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->RemoveAll(); - } else { - static_cast<CFWL_ComboBox*>(m_pNormalWidget.get())->RemoveAt(nIndex); - } + if (nIndex < 0) + ToComboBox(m_pNormalWidget.get())->RemoveAll(); + else + ToComboBox(m_pNormalWidget.get())->RemoveAt(nIndex); + m_pNormalWidget->Update(); AddInvalidateRect(); } @@ -484,6 +500,7 @@ void CXFA_FFComboBox::OnTextChanged(CFWL_Widget* pWidget, eParam.m_wsChange = wsChanged; FWLEventSelChange(&eParam); } + void CXFA_FFComboBox::OnSelectChanged(CFWL_Widget* pWidget, bool bLButtonUp) { CXFA_EventParam eParam; m_pDataAcc->GetValue(eParam.m_wsPrevText, XFA_VALUEPICTURE_Raw); @@ -493,12 +510,14 @@ void CXFA_FFComboBox::OnSelectChanged(CFWL_Widget* pWidget, bool bLButtonUp) { m_pDocView->SetFocusWidgetAcc(nullptr); } } + void CXFA_FFComboBox::OnPreOpen(CFWL_Widget* pWidget) { CXFA_EventParam eParam; eParam.m_eType = XFA_EVENT_PreOpen; eParam.m_pTarget = m_pDataAcc; m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_PreOpen, &eParam); } + void CXFA_FFComboBox::OnPostOpen(CFWL_Widget* pWidget) { CXFA_EventParam eParam; eParam.m_eType = XFA_EVENT_PostOpen; |