diff options
Diffstat (limited to 'xfa/fwl/cfwl_combobox.cpp')
-rw-r--r-- | xfa/fwl/cfwl_combobox.cpp | 274 |
1 files changed, 12 insertions, 262 deletions
diff --git a/xfa/fwl/cfwl_combobox.cpp b/xfa/fwl/cfwl_combobox.cpp index 20134a830b..c60c27497f 100644 --- a/xfa/fwl/cfwl_combobox.cpp +++ b/xfa/fwl/cfwl_combobox.cpp @@ -40,27 +40,8 @@ CFWL_ComboBox::CFWL_ComboBox(const CFWL_App* app) m_rtBtn.Reset(); m_rtHandler.Reset(); - if (m_pWidgetMgr->IsFormDisabled()) { - DisForm_InitComboList(); - DisForm_InitComboEdit(); - return; - } - - auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); - prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; - prop->m_dwStyles |= FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; - m_pListBox = pdfium::MakeUnique<CFWL_ComboList>(m_pOwnerApp.Get(), - std::move(prop), this); - - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_DropDown) && !m_pEdit) { - m_pEdit = pdfium::MakeUnique<CFWL_ComboEdit>( - m_pOwnerApp.Get(), pdfium::MakeUnique<CFWL_WidgetProperties>(), this); - m_pEdit->SetOuter(this); - } - if (m_pEdit) - m_pEdit->SetParent(this); - - SetStates(m_pProperties->m_dwStates); + DisForm_InitComboList(); + DisForm_InitComboEdit(); } CFWL_ComboBox::~CFWL_ComboBox() {} @@ -83,118 +64,20 @@ void CFWL_ComboBox::RemoveAll() { void CFWL_ComboBox::ModifyStylesEx(uint32_t dwStylesExAdded, uint32_t dwStylesExRemoved) { - if (m_pWidgetMgr->IsFormDisabled()) { - DisForm_ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); - return; - } - - bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); - bool bRemoveDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); - if (bAddDropDown && !m_pEdit) { - m_pEdit = pdfium::MakeUnique<CFWL_ComboEdit>( - m_pOwnerApp.Get(), pdfium::MakeUnique<CFWL_WidgetProperties>(), - nullptr); - m_pEdit->SetOuter(this); - m_pEdit->SetParent(this); - } else if (bRemoveDropDown && m_pEdit) { - m_pEdit->SetStates(FWL_WGTSTATE_Invisible); - } - CFWL_Widget::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); + DisForm_ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); } void CFWL_ComboBox::Update() { - if (m_pWidgetMgr->IsFormDisabled()) { - DisForm_Update(); - return; - } - if (IsLocked()) - return; - - ResetTheme(); - if (IsDropDownStyle() && m_pEdit) - ResetEditAlignment(); - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - - Layout(); + DisForm_Update(); } FWL_WidgetHit CFWL_ComboBox::HitTest(const CFX_PointF& point) { - if (m_pWidgetMgr->IsFormDisabled()) - return DisForm_HitTest(point); - return CFWL_Widget::HitTest(point); + return DisForm_HitTest(point); } void CFWL_ComboBox::DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) { - if (m_pWidgetMgr->IsFormDisabled()) { - DisForm_DrawWidget(pGraphics, &matrix); - return; - } - - if (!pGraphics) - return; - if (!m_pProperties->m_pThemeProvider) - return; - - IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; - if (HasBorder()) - DrawBorder(pGraphics, CFWL_Part::Border, pTheme, matrix); - - if (!IsDropDownStyle()) { - CFX_RectF rtTextBk(m_rtClient); - rtTextBk.width -= m_rtBtn.width; - - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::Background; - param.m_pGraphics = pGraphics; - param.m_matrix.Concat(matrix); - param.m_rtPart = rtTextBk; - - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { - param.m_dwStates = CFWL_PartState_Disabled; - } else if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) && - (m_iCurSel >= 0)) { - param.m_dwStates = CFWL_PartState_Selected; - } else { - param.m_dwStates = CFWL_PartState_Normal; - } - pTheme->DrawBackground(¶m); - - if (m_iCurSel >= 0) { - if (!m_pListBox) - return; - - CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); - - CFWL_ThemeText theme_text; - theme_text.m_pWidget = this; - theme_text.m_iPart = CFWL_Part::Caption; - theme_text.m_dwStates = m_iBtnState; - theme_text.m_pGraphics = pGraphics; - theme_text.m_matrix.Concat(matrix); - theme_text.m_rtPart = rtTextBk; - theme_text.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) - ? CFWL_PartState_Selected - : CFWL_PartState_Normal; - theme_text.m_wsText = hItem ? hItem->GetText() : L""; - theme_text.m_dwTTOStyles.single_line_ = true; - theme_text.m_iTTOAlign = FDE_TextAlignment::kCenterLeft; - pTheme->DrawText(&theme_text); - } - } - - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::DropDownButton; - param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) - ? CFWL_PartState_Disabled - : m_iBtnState; - param.m_pGraphics = pGraphics; - param.m_matrix.Concat(matrix); - param.m_rtPart = m_rtBtn; - pTheme->DrawBackground(¶m); + DisForm_DrawWidget(pGraphics, &matrix); } void CFWL_ComboBox::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { @@ -268,17 +151,7 @@ void CFWL_ComboBox::OpenDropDownList(bool bActivate) { } CFX_RectF CFWL_ComboBox::GetBBox() const { - if (m_pWidgetMgr->IsFormDisabled()) - return DisForm_GetBBox(); - - CFX_RectF rect = m_pProperties->m_rtWidget; - if (!m_pListBox || !IsDropListVisible()) - return rect; - - CFX_RectF rtList = m_pListBox->GetWidgetRect(); - rtList.Offset(rect.left, rect.top); - rect.Union(rtList); - return rect; + return DisForm_GetBBox(); } void CFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, @@ -301,50 +174,7 @@ void CFWL_ComboBox::DrawStretchHandler(CXFA_Graphics* pGraphics, } void CFWL_ComboBox::ShowDropList(bool bActivate) { - if (m_pWidgetMgr->IsFormDisabled()) - return DisForm_ShowDropList(bActivate); - if (IsDropListVisible() == bActivate) - return; - if (!m_pComboBoxProxy) - InitProxyForm(); - - m_pComboBoxProxy->Reset(); - if (!bActivate) { - m_pComboBoxProxy->EndDoModal(); - - m_bLButtonDown = false; - m_pListBox->SetNotifyOwner(true); - SetFocus(true); - return; - } - - m_pListBox->ChangeSelected(m_iCurSel); - ResetListItemAlignment(); - - uint32_t dwStyleAdd = m_pProperties->m_dwStyleExes & - (FWL_STYLEEXT_CMB_Sort | FWL_STYLEEXT_CMB_OwnerDraw); - m_pListBox->ModifyStylesEx(dwStyleAdd, 0); - m_rtList = m_pListBox->GetAutosizedWidgetRect(); - - CFX_RectF rtAnchor(0, 0, m_pProperties->m_rtWidget.width, - m_pProperties->m_rtWidget.height); - - m_rtList.width = std::max(m_rtList.width, m_rtClient.width); - m_rtProxy = m_rtList; - - GetPopupPos(0, m_rtProxy.height, rtAnchor, &m_rtProxy); - - m_pComboBoxProxy->SetWidgetRect(m_rtProxy); - m_pComboBoxProxy->Update(); - m_pListBox->SetWidgetRect(m_rtList); - m_pListBox->Update(); - - CFWL_Event ev(CFWL_Event::Type::PreDropDown, this); - DispatchEvent(&ev); - - m_pListBox->SetFocus(true); - m_pComboBoxProxy->DoModal(); - m_pListBox->SetFocus(false); + return DisForm_ShowDropList(bActivate); } void CFWL_ComboBox::MatchEditText() { @@ -368,31 +198,7 @@ void CFWL_ComboBox::SyncEditText(int32_t iListItem) { } void CFWL_ComboBox::Layout() { - if (m_pWidgetMgr->IsFormDisabled()) - return DisForm_Layout(); - - m_rtClient = GetClientRect(); - IFWL_ThemeProvider* theme = GetAvailableTheme(); - if (!theme) - return; - - float fBtn = theme->GetScrollBarWidth(); - m_rtBtn = CFX_RectF(m_rtClient.right() - fBtn, m_rtClient.top, fBtn, - m_rtClient.height); - if (!IsDropDownStyle() || !m_pEdit) - return; - - CFX_RectF rtEdit(m_rtClient.left, m_rtClient.top, m_rtClient.width - fBtn, - m_rtClient.height); - m_pEdit->SetWidgetRect(rtEdit); - - if (m_iCurSel >= 0) { - CFWL_ListItem* hItem = m_pListBox->GetItem(this, m_iCurSel); - m_pEdit->LockUpdate(); - m_pEdit->SetText(hItem ? hItem->GetText() : L""); - m_pEdit->UnlockUpdate(); - } - m_pEdit->Update(); + return DisForm_Layout(); } void CFWL_ComboBox::ResetTheme() { @@ -697,48 +503,7 @@ void CFWL_ComboBox::DisForm_Layout() { } void CFWL_ComboBox::OnProcessMessage(CFWL_Message* pMessage) { - if (m_pWidgetMgr->IsFormDisabled()) { - DisForm_OnProcessMessage(pMessage); - return; - } - if (!pMessage) - return; - - switch (pMessage->GetType()) { - case CFWL_Message::Type::SetFocus: - OnFocusChanged(pMessage, true); - break; - case CFWL_Message::Type::KillFocus: - OnFocusChanged(pMessage, false); - break; - case CFWL_Message::Type::Mouse: { - CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage); - switch (pMsg->m_dwCmd) { - case FWL_MouseCommand::LeftButtonDown: - OnLButtonDown(pMsg); - break; - case FWL_MouseCommand::LeftButtonUp: - OnLButtonUp(pMsg); - break; - case FWL_MouseCommand::Move: - OnMouseMove(pMsg); - break; - case FWL_MouseCommand::Leave: - OnMouseLeave(pMsg); - break; - default: - break; - } - break; - } - case CFWL_Message::Type::Key: - OnKey(static_cast<CFWL_MessageKey*>(pMessage)); - break; - default: - break; - } - - CFWL_Widget::OnProcessMessage(pMessage); + DisForm_OnProcessMessage(pMessage); } void CFWL_ComboBox::OnProcessEvent(CFWL_Event* pEvent) { @@ -1019,21 +784,6 @@ void CFWL_ComboBox::GetPopupPos(float fMinHeight, float fMaxHeight, const CFX_RectF& rtAnchor, CFX_RectF* pPopupRect) { - if (m_pWidgetMgr->IsFormDisabled()) { - m_pWidgetMgr->GetAdapterPopupPos(this, fMinHeight, fMaxHeight, rtAnchor, - pPopupRect); - return; - } - - CFX_PointF point = TransformTo(nullptr, CFX_PointF()); - float fPopupHeight = - pdfium::clamp(pPopupRect->height, fMinHeight, fMaxHeight); - float fPopupWidth = std::max(rtAnchor.width, pPopupRect->width); - float fPopupBottom = rtAnchor.bottom() + fPopupHeight; - float fPopupTop = (fPopupBottom + point.y > 0.0f) - ? rtAnchor.top - fPopupHeight - : rtAnchor.bottom(); - - *pPopupRect = CFX_RectF(rtAnchor.left, fPopupTop, fPopupWidth, fPopupHeight); - pPopupRect->Offset(point.x, point.y); + m_pWidgetMgr->GetAdapterPopupPos(this, fMinHeight, fMaxHeight, rtAnchor, + pPopupRect); } |