diff options
-rw-r--r-- | xfa/fwl/cfwl_combobox.cpp | 10 | ||||
-rw-r--r-- | xfa/fwl/cfwl_combobox.h | 2 | ||||
-rw-r--r-- | xfa/fwl/cfwl_combolist.cpp | 16 | ||||
-rw-r--r-- | xfa/fwl/cfwl_datetimepicker.cpp | 30 | ||||
-rw-r--r-- | xfa/fwl/cfwl_datetimepicker.h | 4 | ||||
-rw-r--r-- | xfa/fwl/cfwl_form.cpp | 9 | ||||
-rw-r--r-- | xfa/fwl/cfwl_form.h | 2 | ||||
-rw-r--r-- | xfa/fwl/cfwl_listbox.cpp | 197 | ||||
-rw-r--r-- | xfa/fwl/cfwl_listbox.h | 39 | ||||
-rw-r--r-- | xfa/fwl/cfwl_listitem.cpp | 7 | ||||
-rw-r--r-- | xfa/fwl/cfwl_listitem.h | 22 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_ffchoicelist.cpp | 6 | ||||
-rw-r--r-- | xfa/fxfa/app/xfa_fftextedit.cpp | 14 |
13 files changed, 131 insertions, 227 deletions
diff --git a/xfa/fwl/cfwl_combobox.cpp b/xfa/fwl/cfwl_combobox.cpp index 7e5d1b8d74..8567e68dff 100644 --- a/xfa/fwl/cfwl_combobox.cpp +++ b/xfa/fwl/cfwl_combobox.cpp @@ -76,8 +76,8 @@ void CFWL_ComboBox::AddString(const CFX_WideStringC& wsText) { m_pListBox->AddString(wsText); } -bool CFWL_ComboBox::RemoveAt(int32_t iIndex) { - return m_pListBox->RemoveAt(iIndex); +void CFWL_ComboBox::RemoveAt(int32_t iIndex) { + m_pListBox->RemoveAt(iIndex); } void CFWL_ComboBox::RemoveAll() { @@ -222,7 +222,7 @@ void CFWL_ComboBox::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { CFX_WideString CFWL_ComboBox::GetTextByIndex(int32_t iIndex) const { CFWL_ListItem* pItem = static_cast<CFWL_ListItem*>( m_pListBox->GetItem(m_pListBox.get(), iIndex)); - return pItem ? pItem->m_wsText : L""; + return pItem ? pItem->GetText() : L""; } void CFWL_ComboBox::SetCurSel(int32_t iSel) { @@ -511,10 +511,8 @@ void CFWL_ComboBox::ProcessSelChanged(bool bLButtonUp) { CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); if (!hItem) return; - - CFX_WideString wsText = m_pListBox->GetItemText(this, hItem); if (m_pEdit) { - m_pEdit->SetText(wsText); + m_pEdit->SetText(hItem->GetText()); m_pEdit->Update(); m_pEdit->SetSelected(); } diff --git a/xfa/fwl/cfwl_combobox.h b/xfa/fwl/cfwl_combobox.h index 9927b65c04..3faa1cc8d6 100644 --- a/xfa/fwl/cfwl_combobox.h +++ b/xfa/fwl/cfwl_combobox.h @@ -72,7 +72,7 @@ class CFWL_ComboBox : public CFWL_Widget { void SetCurSel(int32_t iSel); void AddString(const CFX_WideStringC& wsText); - bool RemoveAt(int32_t iIndex); // Returns false iff |iIndex| out of range. + void RemoveAt(int32_t iIndex); void RemoveAll(); void SetEditText(const CFX_WideString& wsText); diff --git a/xfa/fwl/cfwl_combolist.cpp b/xfa/fwl/cfwl_combolist.cpp index 1fa9acb68e..e78372cb26 100644 --- a/xfa/fwl/cfwl_combolist.cpp +++ b/xfa/fwl/cfwl_combolist.cpp @@ -32,7 +32,7 @@ int32_t CFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) { int32_t iCount = CountItems(this); for (int32_t i = 0; i < iCount; i++) { CFWL_ListItem* hItem = GetItem(this, i); - CFX_WideString wsText = GetItemText(this, hItem); + CFX_WideString wsText = hItem ? hItem->GetText() : L""; FX_STRSIZE pos = wsText.Find(wsMatch.c_str()); if (!pos) return i; @@ -42,22 +42,20 @@ int32_t CFWL_ComboList::MatchItem(const CFX_WideString& wsMatch) { void CFWL_ComboList::ChangeSelected(int32_t iSel) { CFWL_ListItem* hItem = GetItem(this, iSel); - CFX_RectF rtInvalidate; - rtInvalidate.Reset(); CFWL_ListItem* hOld = GetSelItem(0); int32_t iOld = GetItemIndex(this, hOld); if (iOld == iSel) return; + + CFX_RectF rtInvalidate; if (iOld > -1) { - CFWL_ListItem* hItem = GetItem(this, iOld); - GetItemRect(this, hItem, rtInvalidate); + if (CFWL_ListItem* hOldItem = GetItem(this, iOld)) + rtInvalidate = hOldItem->GetRect(); SetSelItem(hOld, false); } if (hItem) { - CFX_RectF rect; - CFWL_ListItem* hItem = GetItem(this, iSel); - GetItemRect(this, hItem, rect); - rtInvalidate.Union(rect); + if (CFWL_ListItem* hOldItem = GetItem(this, iSel)) + rtInvalidate.Union(hOldItem->GetRect()); CFWL_ListItem* hSel = GetItem(this, iSel); SetSelItem(hSel, true); } diff --git a/xfa/fwl/cfwl_datetimepicker.cpp b/xfa/fwl/cfwl_datetimepicker.cpp index 10e26b4891..5819a27cfc 100644 --- a/xfa/fwl/cfwl_datetimepicker.cpp +++ b/xfa/fwl/cfwl_datetimepicker.cpp @@ -183,19 +183,18 @@ CFX_WideString CFWL_DateTimePicker::GetEditText() const { return m_pEdit ? m_pEdit->GetText() : L""; } -void CFWL_DateTimePicker::GetBBox(CFX_RectF& rect) const { - if (m_pWidgetMgr->IsFormDisabled()) { - DisForm_GetBBox(rect); - return; - } +CFX_RectF CFWL_DateTimePicker::GetBBox() const { + if (m_pWidgetMgr->IsFormDisabled()) + return DisForm_GetBBox(); - rect = m_pProperties->m_rtWidget; - if (IsMonthCalendarVisible()) { - CFX_RectF rtMonth = m_pMonthCal->GetWidgetRect(); - rtMonth.Offset(m_pProperties->m_rtWidget.left, - m_pProperties->m_rtWidget.top); - rect.Union(rtMonth); - } + CFX_RectF rect = m_pProperties->m_rtWidget; + if (!IsMonthCalendarVisible()) + return rect; + + CFX_RectF rtMonth = m_pMonthCal->GetWidgetRect(); + rtMonth.Offset(m_pProperties->m_rtWidget.left, m_pProperties->m_rtWidget.top); + rect.Union(rtMonth); + return rect; } void CFWL_DateTimePicker::ModifyEditStylesEx(uint32_t dwStylesExAdded, @@ -450,16 +449,17 @@ void CFWL_DateTimePicker::DisForm_Update() { m_pMonthCal->Update(); } -void CFWL_DateTimePicker::DisForm_GetBBox(CFX_RectF& rect) const { - rect = m_pProperties->m_rtWidget; +CFX_RectF CFWL_DateTimePicker::DisForm_GetBBox() const { + CFX_RectF rect = m_pProperties->m_rtWidget; if (DisForm_IsNeedShowButton()) rect.width += m_fBtn; if (!IsMonthCalendarVisible()) - return; + return rect; CFX_RectF rtMonth = m_pMonthCal->GetWidgetRect(); rtMonth.Offset(m_pProperties->m_rtWidget.left, m_pProperties->m_rtWidget.top); rect.Union(rtMonth); + return rect; } void CFWL_DateTimePicker::DisForm_DrawWidget(CFX_Graphics* pGraphics, diff --git a/xfa/fwl/cfwl_datetimepicker.h b/xfa/fwl/cfwl_datetimepicker.h index 7ddb4c248d..8c9d70ce75 100644 --- a/xfa/fwl/cfwl_datetimepicker.h +++ b/xfa/fwl/cfwl_datetimepicker.h @@ -61,7 +61,7 @@ class CFWL_DateTimePicker : public CFWL_Widget { return m_pEdit->GetSelRange(nIndex, nStart); } - void GetBBox(CFX_RectF& rect) const; + CFX_RectF GetBBox() const; void SetEditLimit(int32_t nLimit) { m_pEdit->SetLimit(nLimit); } void ModifyEditStylesEx(uint32_t dwStylesExAdded, uint32_t dwStylesExRemoved); @@ -92,7 +92,7 @@ class CFWL_DateTimePicker : public CFWL_Widget { FWL_WidgetHit DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy) const; bool DisForm_IsNeedShowButton() const; void DisForm_Update(); - void DisForm_GetBBox(CFX_RectF& rect) const; + CFX_RectF DisForm_GetBBox() const; void DisForm_DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix); void DisForm_OnFocusChanged(CFWL_Message* pMsg, bool bSet); diff --git a/xfa/fwl/cfwl_form.cpp b/xfa/fwl/cfwl_form.cpp index 4d978a503a..58d9e18989 100644 --- a/xfa/fwl/cfwl_form.cpp +++ b/xfa/fwl/cfwl_form.cpp @@ -186,10 +186,8 @@ void CFWL_Form::DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) { } if ((m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_EdgeMask) != FWL_WGTSTYLE_EdgeNone) { - CFX_RectF rtEdge; - GetEdgeRect(rtEdge); param.m_iPart = CFWL_Part::Edge; - param.m_rtPart = rtEdge; + param.m_rtPart = GetEdgeRect(); param.m_dwStates = iState; pTheme->DrawBackground(¶m); } @@ -369,13 +367,14 @@ int32_t CFWL_Form::GetSysBtnIndex(CFWL_SysBtn* pBtn) { return arrBtn.Find(pBtn); } -void CFWL_Form::GetEdgeRect(CFX_RectF& rtEdge) { - rtEdge = m_rtRelative; +CFX_RectF CFWL_Form::GetEdgeRect() { + CFX_RectF rtEdge = m_rtRelative; if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_Border) { FX_FLOAT fCX = GetBorderSize(true); FX_FLOAT fCY = GetBorderSize(false); rtEdge.Deflate(fCX, fCY, fCX, fCY); } + return rtEdge; } void CFWL_Form::SetWorkAreaRect() { diff --git a/xfa/fwl/cfwl_form.h b/xfa/fwl/cfwl_form.h index e894784b09..8755874fab 100644 --- a/xfa/fwl/cfwl_form.h +++ b/xfa/fwl/cfwl_form.h @@ -64,7 +64,7 @@ class CFWL_Form : public CFWL_Widget { CFWL_SysBtn* GetSysBtnByState(uint32_t dwState); CFWL_SysBtn* GetSysBtnByIndex(int32_t nIndex); int32_t GetSysBtnIndex(CFWL_SysBtn* pBtn); - void GetEdgeRect(CFX_RectF& rtEdge); + CFX_RectF GetEdgeRect(); void SetWorkAreaRect(); void Layout(); void ResetSysBtn(); diff --git a/xfa/fwl/cfwl_listbox.cpp b/xfa/fwl/cfwl_listbox.cpp index fafb61f4d2..e3aebcc2f2 100644 --- a/xfa/fwl/cfwl_listbox.cpp +++ b/xfa/fwl/cfwl_listbox.cpp @@ -136,9 +136,7 @@ int32_t CFWL_ListBox::CountSelItems() { CFWL_ListItem* pItem = GetItem(this, i); if (!pItem) continue; - - uint32_t dwStyle = GetItemStyles(this, pItem); - if (dwStyle & FWL_ITEMSTATE_LTB_Selected) + if (pItem->GetStyles() & FWL_ITEMSTATE_LTB_Selected) iRet++; } return iRet; @@ -158,9 +156,7 @@ int32_t CFWL_ListBox::GetSelIndex(int32_t nIndex) { CFWL_ListItem* pItem = GetItem(this, i); if (!pItem) return -1; - - uint32_t dwStyle = GetItemStyles(this, pItem); - if (dwStyle & FWL_ITEMSTATE_LTB_Selected) { + if (pItem->GetStyles() & FWL_ITEMSTATE_LTB_Selected) { if (index == nIndex) return i; index++; @@ -186,9 +182,7 @@ void CFWL_ListBox::SetSelItem(CFWL_ListItem* pItem, bool bSelect) { } CFX_WideString CFWL_ListBox::GetDataProviderItemText(CFWL_ListItem* pItem) { - if (!pItem) - return L""; - return GetItemText(this, pItem); + return pItem ? pItem->GetText() : L""; } CFWL_ListItem* CFWL_ListBox::GetListItem(CFWL_ListItem* pItem, @@ -245,10 +239,13 @@ void CFWL_ListBox::SetSelection(CFWL_ListItem* hStart, } void CFWL_ListBox::SetSelectionDirect(CFWL_ListItem* pItem, bool bSelect) { - uint32_t dwOldStyle = GetItemStyles(this, pItem); + if (!pItem) + return; + + uint32_t dwOldStyle = pItem->GetStyles(); bSelect ? dwOldStyle |= FWL_ITEMSTATE_LTB_Selected : dwOldStyle &= ~FWL_ITEMSTATE_LTB_Selected; - SetItemStyles(this, pItem, dwOldStyle); + pItem->SetStyles(dwOldStyle); } bool CFWL_ListBox::IsMultiSelection() const { @@ -256,8 +253,7 @@ bool CFWL_ListBox::IsMultiSelection() const { } bool CFWL_ListBox::IsItemSelected(CFWL_ListItem* pItem) { - uint32_t dwState = GetItemStyles(this, pItem); - return (dwState & FWL_ITEMSTATE_LTB_Selected) != 0; + return pItem && (pItem->GetStyles() & FWL_ITEMSTATE_LTB_Selected) != 0; } void CFWL_ListBox::ClearSelection() { @@ -265,8 +261,9 @@ void CFWL_ListBox::ClearSelection() { int32_t iCount = CountItems(this); for (int32_t i = 0; i < iCount; i++) { CFWL_ListItem* pItem = GetItem(this, i); - uint32_t dwState = GetItemStyles(this, pItem); - if (!(dwState & FWL_ITEMSTATE_LTB_Selected)) + if (!pItem) + continue; + if (!(pItem->GetStyles() & FWL_ITEMSTATE_LTB_Selected)) continue; SetSelectionDirect(pItem, false); if (!bMulti) @@ -293,7 +290,7 @@ CFWL_ListItem* CFWL_ListBox::GetFocusedItem() { CFWL_ListItem* pItem = GetItem(this, i); if (!pItem) return nullptr; - if (GetItemStyles(this, pItem) & FWL_ITEMSTATE_LTB_Focused) + if (pItem->GetStyles() & FWL_ITEMSTATE_LTB_Focused) return pItem; } return nullptr; @@ -305,14 +302,14 @@ void CFWL_ListBox::SetFocusItem(CFWL_ListItem* pItem) { return; if (hFocus) { - uint32_t dwStyle = GetItemStyles(this, hFocus); + uint32_t dwStyle = hFocus->GetStyles(); dwStyle &= ~FWL_ITEMSTATE_LTB_Focused; - SetItemStyles(this, hFocus, dwStyle); + hFocus->SetStyles(dwStyle); } if (pItem) { - uint32_t dwStyle = GetItemStyles(this, pItem); + uint32_t dwStyle = pItem->GetStyles(); dwStyle |= FWL_ITEMSTATE_LTB_Focused; - SetItemStyles(this, pItem, dwStyle); + pItem->SetStyles(dwStyle); } } @@ -332,8 +329,7 @@ CFWL_ListItem* CFWL_ListBox::GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy) { if (!pItem) continue; - CFX_RectF rtItem; - GetItemRect(this, pItem, rtItem); + CFX_RectF rtItem = pItem->GetRect(); rtItem.Offset(-fPosX, -fPosY); if (rtItem.Contains(fx, fy)) return pItem; @@ -341,25 +337,17 @@ CFWL_ListItem* CFWL_ListBox::GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy) { return nullptr; } -bool CFWL_ListBox::GetItemCheckRectInternal(CFWL_ListItem* pItem, - CFX_RectF& rtCheck) { - if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) - return false; - GetItemCheckRect(this, pItem, rtCheck); - return true; -} - bool CFWL_ListBox::GetItemChecked(CFWL_ListItem* pItem) { if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) return false; - return !!(GetItemCheckState(this, pItem) & FWL_ITEMSTATE_LTB_Checked); + return !!(pItem->GetCheckState() & FWL_ITEMSTATE_LTB_Checked); } bool CFWL_ListBox::SetItemChecked(CFWL_ListItem* pItem, bool bChecked) { if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check)) return false; - SetItemCheckState(this, pItem, bChecked ? FWL_ITEMSTATE_LTB_Checked : 0); + pItem->SetCheckState(bChecked ? FWL_ITEMSTATE_LTB_Checked : 0); return true; } @@ -367,9 +355,7 @@ bool CFWL_ListBox::ScrollToVisible(CFWL_ListItem* pItem) { if (!m_pVertScrollBar) return false; - CFX_RectF rtItem; - GetItemRect(this, pItem, rtItem); - + CFX_RectF rtItem = pItem ? pItem->GetRect() : CFX_RectF(); bool bScroll = false; FX_FLOAT fPosY = m_pVertScrollBar->GetPos(); rtItem.Offset(0, -fPosY + m_rtConent.top); @@ -437,8 +423,7 @@ void CFWL_ListBox::DrawItems(CFX_Graphics* pGraphics, if (!pItem) continue; - CFX_RectF rtItem; - GetItemRect(this, pItem, rtItem); + CFX_RectF rtItem = pItem->GetRect(); rtItem.Offset(m_rtConent.left - fPosX, m_rtConent.top - fPosY); if (rtItem.bottom() < m_rtConent.top) continue; @@ -458,7 +443,7 @@ void CFWL_ListBox::DrawItem(CFX_Graphics* pGraphics, int32_t Index, const CFX_RectF& rtItem, const CFX_Matrix* pMatrix) { - uint32_t dwItemStyles = GetItemStyles(this, pItem); + uint32_t dwItemStyles = pItem ? pItem->GetStyles() : 0; uint32_t dwPartStates = CFWL_PartState_Normal; if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) dwPartStates = CFWL_PartState_Disabled; @@ -491,7 +476,7 @@ void CFWL_ListBox::DrawItem(CFX_Graphics* pGraphics, bool bHasIcon = !!(GetStylesEx() & FWL_STYLEEXT_LTB_Icon); if (bHasIcon) { CFX_RectF rtDIB; - CFX_DIBitmap* pDib = GetItemIcon(this, pItem); + CFX_DIBitmap* pDib = pItem->GetIcon(); rtDIB.Set(rtItem.left, rtItem.top, rtItem.height, rtItem.height); if (pDib) { CFWL_ThemeBackground param; @@ -511,7 +496,8 @@ void CFWL_ListBox::DrawItem(CFX_Graphics* pGraphics, CFX_RectF rtCheck; rtCheck.Set(rtItem.left, rtItem.top, rtItem.height, rtItem.height); rtCheck.Deflate(2, 2, 2, 2); - SetItemCheckRect(this, pItem, rtCheck); + pItem->SetCheckRect(rtCheck); + CFWL_ThemeBackground param; param.m_pWidget = this; param.m_iPart = CFWL_Part::Check; @@ -526,7 +512,10 @@ void CFWL_ListBox::DrawItem(CFX_Graphics* pGraphics, pTheme->DrawBackground(¶m); } - CFX_WideString wsText = GetItemText(this, pItem); + if (!pItem) + return; + + CFX_WideString wsText = pItem->GetText(); if (wsText.GetLength() <= 0) return; @@ -550,9 +539,8 @@ void CFWL_ListBox::DrawItem(CFX_Graphics* pGraphics, } CFX_SizeF CFWL_ListBox::CalcSize(bool bAutoSize) { - CFX_SizeF fs; if (!m_pProperties->m_pThemeProvider) - return fs; + return CFX_SizeF(); m_rtClient = GetClientRect(); m_rtConent = m_rtClient; @@ -580,9 +568,10 @@ CFX_SizeF CFWL_ListBox::CalcSize(bool bAutoSize) { fWidth += m_fItemHeight; int32_t iCount = CountItems(this); + CFX_SizeF fs; for (int32_t i = 0; i < iCount; i++) { CFWL_ListItem* htem = GetItem(this, i); - GetItemSize(fs, htem, fWidth, m_fItemHeight, bAutoSize); + UpdateItemSize(htem, fs, fWidth, m_fItemHeight, bAutoSize); } if (bAutoSize) return fs; @@ -675,18 +664,18 @@ CFX_SizeF CFWL_ListBox::CalcSize(bool bAutoSize) { return fs; } -void CFWL_ListBox::GetItemSize(CFX_SizeF& size, - CFWL_ListItem* pItem, - FX_FLOAT fWidth, - FX_FLOAT fItemHeight, - bool bAutoSize) { +void CFWL_ListBox::UpdateItemSize(CFWL_ListItem* pItem, + CFX_SizeF& size, + FX_FLOAT fWidth, + FX_FLOAT fItemHeight, + bool bAutoSize) const { if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_MultiColumn) return; - if (!bAutoSize) { + if (!bAutoSize && pItem) { CFX_RectF rtItem; rtItem.Set(0, size.y, fWidth, fItemHeight); - SetItemRect(this, pItem, rtItem); + pItem->SetRect(rtItem); } size.x = fWidth; size.y += fItemHeight; @@ -700,8 +689,8 @@ FX_FLOAT CFWL_ListBox::GetMaxTextWidth() { if (!pItem) continue; - CFX_WideString wsText = GetItemText(this, pItem); - CFX_SizeF sz = CalcTextSize(wsText, m_pProperties->m_pThemeProvider, false); + CFX_SizeF sz = + CalcTextSize(pItem->GetText(), m_pProperties->m_pThemeProvider, false); fRet = std::max(fRet, sz.x); } return fRet; @@ -873,7 +862,9 @@ void CFWL_ListBox::OnLButtonDown(CFWL_MessageMouse* pMsg) { if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check) { CFWL_ListItem* hSelectedItem = GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); CFX_RectF rtCheck; - GetItemCheckRectInternal(hSelectedItem, rtCheck); + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_LTB_Check) + rtCheck = hSelectedItem->GetCheckRect(); + bool bChecked = GetItemChecked(pItem); if (rtCheck.Contains(pMsg->m_fx, pMsg->m_fy)) { SetItemChecked(pItem, !bChecked); @@ -1003,11 +994,6 @@ bool CFWL_ListBox::OnScroll(CFWL_ScrollBar* pScrollBar, return true; } -CFX_WideString CFWL_ListBox::GetItemText(CFWL_Widget* pWidget, - CFWL_ListItem* pItem) { - return pItem ? static_cast<CFWL_ListItem*>(pItem)->m_wsText : L""; -} - int32_t CFWL_ListBox::CountItems(const CFWL_Widget* pWidget) const { return pdfium::CollectionSize<int32_t>(m_ItemArray); } @@ -1020,107 +1006,42 @@ CFWL_ListItem* CFWL_ListBox::GetItem(const CFWL_Widget* pWidget, } int32_t CFWL_ListBox::GetItemIndex(CFWL_Widget* pWidget, CFWL_ListItem* pItem) { - auto it = std::find_if( - m_ItemArray.begin(), m_ItemArray.end(), - [pItem](const std::unique_ptr<CFWL_ListItem>& candidate) { - return candidate.get() == static_cast<CFWL_ListItem*>(pItem); - }); + auto it = + std::find_if(m_ItemArray.begin(), m_ItemArray.end(), + [pItem](const std::unique_ptr<CFWL_ListItem>& candidate) { + return candidate.get() == pItem; + }); return it != m_ItemArray.end() ? it - m_ItemArray.begin() : -1; } -uint32_t CFWL_ListBox::GetItemStyles(CFWL_Widget* pWidget, - CFWL_ListItem* pItem) { - return pItem ? static_cast<CFWL_ListItem*>(pItem)->m_dwStates : 0; -} - -void CFWL_ListBox::GetItemRect(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - CFX_RectF& rtItem) { - if (pItem) - rtItem = static_cast<CFWL_ListItem*>(pItem)->m_rtItem; -} - -void CFWL_ListBox::SetItemStyles(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - uint32_t dwStyle) { - if (pItem) - static_cast<CFWL_ListItem*>(pItem)->m_dwStates = dwStyle; -} - -void CFWL_ListBox::SetItemRect(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - const CFX_RectF& rtItem) { - if (pItem) - static_cast<CFWL_ListItem*>(pItem)->m_rtItem = rtItem; -} - -CFX_DIBitmap* CFWL_ListBox::GetItemIcon(CFWL_Widget* pWidget, - CFWL_ListItem* pItem) { - return static_cast<CFWL_ListItem*>(pItem)->m_pDIB; -} - -void CFWL_ListBox::GetItemCheckRect(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - CFX_RectF& rtCheck) { - rtCheck = static_cast<CFWL_ListItem*>(pItem)->m_rtCheckBox; -} - -void CFWL_ListBox::SetItemCheckRect(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - const CFX_RectF& rtCheck) { - static_cast<CFWL_ListItem*>(pItem)->m_rtCheckBox = rtCheck; -} - -uint32_t CFWL_ListBox::GetItemCheckState(CFWL_Widget* pWidget, - CFWL_ListItem* pItem) { - return static_cast<CFWL_ListItem*>(pItem)->m_dwCheckState; -} - -void CFWL_ListBox::SetItemCheckState(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - uint32_t dwCheckState) { - static_cast<CFWL_ListItem*>(pItem)->m_dwCheckState = dwCheckState; -} - CFWL_ListItem* CFWL_ListBox::AddString(const CFX_WideStringC& wsAdd) { - auto pItem = pdfium::MakeUnique<CFWL_ListItem>(); - pItem->m_dwStates = 0; - pItem->m_wsText = wsAdd; - pItem->m_dwStates = 0; - m_ItemArray.push_back(std::move(pItem)); + m_ItemArray.emplace_back( + pdfium::MakeUnique<CFWL_ListItem>(CFX_WideString(wsAdd))); return m_ItemArray.back().get(); } -bool CFWL_ListBox::RemoveAt(int32_t iIndex) { +void CFWL_ListBox::RemoveAt(int32_t iIndex) { if (iIndex < 0 || static_cast<size_t>(iIndex) >= m_ItemArray.size()) - return false; - + return; m_ItemArray.erase(m_ItemArray.begin() + iIndex); - return true; } -bool CFWL_ListBox::DeleteString(CFWL_ListItem* pItem) { +void CFWL_ListBox::DeleteString(CFWL_ListItem* pItem) { int32_t nIndex = GetItemIndex(this, pItem); if (nIndex < 0 || static_cast<size_t>(nIndex) >= m_ItemArray.size()) - return false; + return; int32_t iSel = nIndex + 1; if (iSel >= CountItems(this)) iSel = nIndex - 1; if (iSel >= 0) { - CFWL_ListItem* pSel = static_cast<CFWL_ListItem*>(GetItem(this, iSel)); - pSel->m_dwStates |= FWL_ITEMSTATE_LTB_Selected; + if (CFWL_ListItem* item = GetItem(this, iSel)) + item->SetStyles(item->GetStyles() | FWL_ITEMSTATE_LTB_Selected); } + m_ItemArray.erase(m_ItemArray.begin() + nIndex); - return true; } void CFWL_ListBox::DeleteAll() { m_ItemArray.clear(); } - -uint32_t CFWL_ListBox::GetItemStates(CFWL_ListItem* pItem) { - if (!pItem) - return 0; - return pItem->m_dwStates | pItem->m_dwCheckState; -} diff --git a/xfa/fwl/cfwl_listbox.h b/xfa/fwl/cfwl_listbox.h index 13aab48277..8ef1579859 100644 --- a/xfa/fwl/cfwl_listbox.h +++ b/xfa/fwl/cfwl_listbox.h @@ -59,32 +59,10 @@ class CFWL_ListBox : public CFWL_Widget { int32_t CountItems(const CFWL_Widget* pWidget) const; CFWL_ListItem* GetItem(const CFWL_Widget* pWidget, int32_t nIndex) const; int32_t GetItemIndex(CFWL_Widget* pWidget, CFWL_ListItem* pItem); - uint32_t GetItemStyles(CFWL_Widget* pWidget, CFWL_ListItem* pItem); - uint32_t GetItemStates(CFWL_ListItem* pItem); - CFX_WideString GetItemText(CFWL_Widget* pWidget, CFWL_ListItem* pItem); - void GetItemRect(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - CFX_RectF& rtItem); - void SetItemStyles(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - uint32_t dwStyle); - void SetItemRect(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - const CFX_RectF& rtItem); - CFX_DIBitmap* GetItemIcon(CFWL_Widget* pWidget, CFWL_ListItem* pItem); - void GetItemCheckRect(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - CFX_RectF& rtCheck); - void SetItemCheckRect(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - const CFX_RectF& rtCheck); - uint32_t GetItemCheckState(CFWL_Widget* pWidget, CFWL_ListItem* pItem); - void SetItemCheckState(CFWL_Widget* pWidget, - CFWL_ListItem* pItem, - uint32_t dwCheckState); + CFWL_ListItem* AddString(const CFX_WideStringC& wsAdd); - bool RemoveAt(int32_t iIndex); - bool DeleteString(CFWL_ListItem* pItem); + void RemoveAt(int32_t iIndex); + void DeleteString(CFWL_ListItem* pItem); void DeleteAll(); int32_t CountSelItems(); @@ -115,7 +93,6 @@ class CFWL_ListBox : public CFWL_Widget { void SelectAll(); CFWL_ListItem* GetFocusedItem(); void SetFocusItem(CFWL_ListItem* hItem); - bool GetItemCheckRectInternal(CFWL_ListItem* hItem, CFX_RectF& rtCheck); bool SetItemChecked(CFWL_ListItem* hItem, bool bChecked); bool GetItemChecked(CFWL_ListItem* hItem); void DrawBkground(CFX_Graphics* pGraphics, @@ -132,11 +109,11 @@ class CFWL_ListBox : public CFWL_Widget { const CFX_Matrix* pMatrix); void DrawStatic(CFX_Graphics* pGraphics, IFWL_ThemeProvider* pTheme); CFX_SizeF CalcSize(bool bAutoSize); - void GetItemSize(CFX_SizeF& size, - CFWL_ListItem* hItem, - FX_FLOAT fWidth, - FX_FLOAT fHeight, - bool bAutoSize); + void UpdateItemSize(CFWL_ListItem* hItem, + CFX_SizeF& size, + FX_FLOAT fWidth, + FX_FLOAT fHeight, + bool bAutoSize) const; FX_FLOAT GetMaxTextWidth(); FX_FLOAT GetScrollWidth(); diff --git a/xfa/fwl/cfwl_listitem.cpp b/xfa/fwl/cfwl_listitem.cpp index 3e23b17d91..049548a1f5 100644 --- a/xfa/fwl/cfwl_listitem.cpp +++ b/xfa/fwl/cfwl_listitem.cpp @@ -6,11 +6,8 @@ #include "xfa/fwl/cfwl_listitem.h" -CFWL_ListItem::CFWL_ListItem() - : m_dwStates(0), - m_wsText(L""), - m_pDIB(nullptr), - m_dwCheckState(0) { +CFWL_ListItem::CFWL_ListItem(const CFX_WideString& text) + : m_dwStates(0), m_wsText(text), m_pDIB(nullptr), m_dwCheckState(0) { m_rtCheckBox.Reset(); m_rtItem.Reset(); } diff --git a/xfa/fwl/cfwl_listitem.h b/xfa/fwl/cfwl_listitem.h index 0e608f8d92..c4af1d89b5 100644 --- a/xfa/fwl/cfwl_listitem.h +++ b/xfa/fwl/cfwl_listitem.h @@ -14,12 +14,30 @@ class CFX_DIBitmap; class CFWL_ListItem { public: - CFWL_ListItem(); + explicit CFWL_ListItem(const CFX_WideString& text); ~CFWL_ListItem(); + CFX_RectF GetRect() const { return m_rtItem; } + void SetRect(const CFX_RectF& rect) { m_rtItem = rect; } + + uint32_t GetStyles() const { return m_dwStates; } + void SetStyles(uint32_t dwStyle) { m_dwStates = dwStyle; } + + CFX_RectF GetCheckRect() const { return m_rtCheckBox; } + void SetCheckRect(const CFX_RectF& rtCheck) { m_rtCheckBox = rtCheck; } + + uint32_t GetStates() const { return GetStyles() | GetCheckState(); } + + uint32_t GetCheckState() const { return m_dwCheckState; } + void SetCheckState(uint32_t dwCheckState) { m_dwCheckState = dwCheckState; } + + CFX_DIBitmap* GetIcon() const { return m_pDIB; } + + CFX_WideString GetText() const { return m_wsText; } + + private: CFX_RectF m_rtItem; uint32_t m_dwStates; - uint32_t m_dwStyles; CFX_WideString m_wsText; CFX_DIBitmap* m_pDIB; uint32_t m_dwCheckState; diff --git a/xfa/fxfa/app/xfa_ffchoicelist.cpp b/xfa/fxfa/app/xfa_ffchoicelist.cpp index d19fd6876b..2764d725af 100644 --- a/xfa/fxfa/app/xfa_ffchoicelist.cpp +++ b/xfa/fxfa/app/xfa_ffchoicelist.cpp @@ -104,7 +104,7 @@ bool CXFA_FFListBox::IsDataChanged() { for (int32_t i = 0; i < iSels; ++i) { CFWL_ListItem* hlistItem = pListBox->GetItem(nullptr, iSelArray[i]); - if (!(pListBox->GetItemStates(hlistItem) & FWL_ITEMSTATE_LTB_Selected)) + if (!(hlistItem->GetStates() & FWL_ITEMSTATE_LTB_Selected)) return true; } return false; @@ -163,8 +163,8 @@ void CXFA_FFListBox::OnSelectChanged(CFWL_Widget* pWidget, CFWL_ListBox* pListBox = (CFWL_ListBox*)m_pNormalWidget; int32_t iSels = pListBox->CountSelItems(); if (iSels > 0) { - eParam.m_wsNewText = - pListBox->GetItemText(nullptr, pListBox->GetSelItem(0)); + CFWL_ListItem* item = pListBox->GetSelItem(0); + eParam.m_wsNewText = item ? item->GetText() : L""; } m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam); diff --git a/xfa/fxfa/app/xfa_fftextedit.cpp b/xfa/fxfa/app/xfa_fftextedit.cpp index 50b087315d..74bd99a55d 100644 --- a/xfa/fxfa/app/xfa_fftextedit.cpp +++ b/xfa/fxfa/app/xfa_fftextedit.cpp @@ -505,16 +505,12 @@ bool CXFA_FFDateTimeEdit::GetBBox(CFX_RectF& rtBox, } bool CXFA_FFDateTimeEdit::PtInActiveRect(FX_FLOAT fx, FX_FLOAT fy) { - if (!m_pNormalWidget) { - return false; - } - CFX_RectF rtWidget; - ((CFWL_DateTimePicker*)m_pNormalWidget)->GetBBox(rtWidget); - if (rtWidget.Contains(fx, fy)) { - return true; - } - return false; + return m_pNormalWidget && + static_cast<CFWL_DateTimePicker*>(m_pNormalWidget) + ->GetBBox() + .Contains(fx, fy); } + bool CXFA_FFDateTimeEdit::LoadWidget() { CFWL_DateTimePicker* pWidget = new CFWL_DateTimePicker(GetFWLApp()); m_pNormalWidget = pWidget; |