From d4f24c79c8b67401bdb1326c03083853326f7554 Mon Sep 17 00:00:00 2001 From: dsinclair Date: Wed, 16 Nov 2016 08:44:31 -0800 Subject: Continue fwl/core nit cleanup. Review-Url: https://codereview.chromium.org/2501033005 --- xfa/fwl/core/ifwl_barcode.cpp | 76 +++++------ xfa/fwl/core/ifwl_barcode.h | 2 +- xfa/fwl/core/ifwl_caret.cpp | 12 +- xfa/fwl/core/ifwl_checkbox.cpp | 290 ++++++++++++++++++++--------------------- xfa/fwl/core/ifwl_checkbox.h | 8 +- 5 files changed, 189 insertions(+), 199 deletions(-) diff --git a/xfa/fwl/core/ifwl_barcode.cpp b/xfa/fwl/core/ifwl_barcode.cpp index c918b3bc8c..d055a4bcd1 100644 --- a/xfa/fwl/core/ifwl_barcode.cpp +++ b/xfa/fwl/core/ifwl_barcode.cpp @@ -26,9 +26,9 @@ FWL_Type IFWL_Barcode::GetClassID() const { } void IFWL_Barcode::Update() { - if (IsLocked()) { + if (IsLocked()) return; - } + IFWL_Edit::Update(); GenerateBarcodeImageCache(); } @@ -41,15 +41,15 @@ void IFWL_Barcode::DrawWidget(CFX_Graphics* pGraphics, return; if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) { GenerateBarcodeImageCache(); - if (!m_pBarcodeEngine || (m_dwStatus & XFA_BCS_EncodeSuccess) == 0) { + if (!m_pBarcodeEngine || (m_dwStatus & XFA_BCS_EncodeSuccess) == 0) return; - } + CFX_Matrix mt; mt.e = GetRTClient().left; mt.f = GetRTClient().top; - if (pMatrix) { + if (pMatrix) mt.Concat(*pMatrix); - } + int32_t errorCode = 0; m_pBarcodeEngine->RenderDevice(pGraphics->GetRenderDevice(), pMatrix, errorCode); @@ -57,9 +57,11 @@ void IFWL_Barcode::DrawWidget(CFX_Graphics* pGraphics, } IFWL_Edit::DrawWidget(pGraphics, pMatrix); } + void IFWL_Barcode::GenerateBarcodeImageCache() { if ((m_dwStatus & XFA_BCS_NeedUpdate) == 0) return; + m_dwStatus = 0; CreateBarcodeEngine(); IFWL_BarcodeDP* pData = @@ -68,70 +70,60 @@ void IFWL_Barcode::GenerateBarcodeImageCache() { return; if (!m_pBarcodeEngine) return; + CFX_WideString wsText; GetText(wsText); CFWL_ThemePart part; part.m_pWidget = this; + IFWL_ThemeProvider* pTheme = GetAvailableTheme(); CFGAS_GEFont* pFont = static_cast( pTheme->GetCapacity(&part, CFWL_WidgetCapacity::Font)); CFX_Font* pCXFont = pFont ? pFont->GetDevFont() : nullptr; - if (pCXFont) { + if (pCXFont) m_pBarcodeEngine->SetFont(pCXFont); - } + FX_FLOAT* pFontSize = static_cast( pTheme->GetCapacity(&part, CFWL_WidgetCapacity::FontSize)); - if (pFontSize) { + if (pFontSize) m_pBarcodeEngine->SetFontSize(*pFontSize); - } + FX_ARGB* pFontColor = static_cast( pTheme->GetCapacity(&part, CFWL_WidgetCapacity::TextColor)); - if (pFontColor) { + if (pFontColor) m_pBarcodeEngine->SetFontColor(*pFontColor); - } + m_pBarcodeEngine->SetHeight(int32_t(GetRTClient().height)); m_pBarcodeEngine->SetWidth(int32_t(GetRTClient().width)); uint32_t dwAttributeMask = pData->GetBarcodeAttributeMask(); - if (dwAttributeMask & FWL_BCDATTRIBUTE_CHARENCODING) { + if (dwAttributeMask & FWL_BCDATTRIBUTE_CHARENCODING) m_pBarcodeEngine->SetCharEncoding(pData->GetCharEncoding()); - } - if (dwAttributeMask & FWL_BCDATTRIBUTE_MODULEHEIGHT) { + if (dwAttributeMask & FWL_BCDATTRIBUTE_MODULEHEIGHT) m_pBarcodeEngine->SetModuleHeight(pData->GetModuleHeight()); - } - if (dwAttributeMask & FWL_BCDATTRIBUTE_MODULEWIDTH) { + if (dwAttributeMask & FWL_BCDATTRIBUTE_MODULEWIDTH) m_pBarcodeEngine->SetModuleWidth(pData->GetModuleWidth()); - } - if (dwAttributeMask & FWL_BCDATTRIBUTE_DATALENGTH) { + if (dwAttributeMask & FWL_BCDATTRIBUTE_DATALENGTH) m_pBarcodeEngine->SetDataLength(pData->GetDataLength()); - } - if (dwAttributeMask & FWL_BCDATTRIBUTE_CALCHECKSUM) { + if (dwAttributeMask & FWL_BCDATTRIBUTE_CALCHECKSUM) m_pBarcodeEngine->SetCalChecksum(pData->GetCalChecksum()); - } - if (dwAttributeMask & FWL_BCDATTRIBUTE_PRINTCHECKSUM) { + if (dwAttributeMask & FWL_BCDATTRIBUTE_PRINTCHECKSUM) m_pBarcodeEngine->SetPrintChecksum(pData->GetPrintChecksum()); - } - if (dwAttributeMask & FWL_BCDATTRIBUTE_TEXTLOCATION) { + if (dwAttributeMask & FWL_BCDATTRIBUTE_TEXTLOCATION) m_pBarcodeEngine->SetTextLocation(pData->GetTextLocation()); - } - if (dwAttributeMask & FWL_BCDATTRIBUTE_WIDENARROWRATIO) { + if (dwAttributeMask & FWL_BCDATTRIBUTE_WIDENARROWRATIO) m_pBarcodeEngine->SetWideNarrowRatio(pData->GetWideNarrowRatio()); - } - if (dwAttributeMask & FWL_BCDATTRIBUTE_STARTCHAR) { + if (dwAttributeMask & FWL_BCDATTRIBUTE_STARTCHAR) m_pBarcodeEngine->SetStartChar(pData->GetStartChar()); - } - if (dwAttributeMask & FWL_BCDATTRIBUTE_ENDCHAR) { + if (dwAttributeMask & FWL_BCDATTRIBUTE_ENDCHAR) m_pBarcodeEngine->SetEndChar(pData->GetEndChar()); - } - if (dwAttributeMask & FWL_BCDATTRIBUTE_VERSION) { + if (dwAttributeMask & FWL_BCDATTRIBUTE_VERSION) m_pBarcodeEngine->SetVersion(pData->GetVersion()); - } - if (dwAttributeMask & FWL_BCDATTRIBUTE_ECLEVEL) { + if (dwAttributeMask & FWL_BCDATTRIBUTE_ECLEVEL) m_pBarcodeEngine->SetErrorCorrectionLevel(pData->GetErrorCorrectionLevel()); - } - if (dwAttributeMask & FWL_BCDATTRIBUTE_TRUNCATED) { + if (dwAttributeMask & FWL_BCDATTRIBUTE_TRUNCATED) m_pBarcodeEngine->SetTruncated(pData->GetTruncated()); - } + int32_t errorCode = 0; m_dwStatus = m_pBarcodeEngine->Encode(wsText.AsStringC(), true, errorCode) ? XFA_BCS_EncodeSuccess @@ -155,15 +147,17 @@ void IFWL_Barcode::SetType(BC_TYPE type) { m_type = type; m_dwStatus = XFA_BCS_NeedUpdate; } + void IFWL_Barcode::SetText(const CFX_WideString& wsText) { m_pBarcodeEngine.reset(); m_dwStatus = XFA_BCS_NeedUpdate; IFWL_Edit::SetText(wsText); } -bool IFWL_Barcode::IsProtectedType() { - if (!m_pBarcodeEngine) { + +bool IFWL_Barcode::IsProtectedType() const { + if (!m_pBarcodeEngine) return true; - } + BC_TYPE tEngineType = m_pBarcodeEngine->GetType(); if (tEngineType == BC_QR_CODE || tEngineType == BC_PDF417 || tEngineType == BC_DATAMATRIX) { diff --git a/xfa/fwl/core/ifwl_barcode.h b/xfa/fwl/core/ifwl_barcode.h index d69cd23fcb..09ec1f3e7d 100644 --- a/xfa/fwl/core/ifwl_barcode.h +++ b/xfa/fwl/core/ifwl_barcode.h @@ -73,7 +73,7 @@ class IFWL_Barcode : public IFWL_Edit { void SetText(const CFX_WideString& wsText) override; void SetType(BC_TYPE type); - bool IsProtectedType(); + bool IsProtectedType() const; private: void GenerateBarcodeImageCache(); diff --git a/xfa/fwl/core/ifwl_caret.cpp b/xfa/fwl/core/ifwl_caret.cpp index f333fdd94c..0b84cdf53b 100644 --- a/xfa/fwl/core/ifwl_caret.cpp +++ b/xfa/fwl/core/ifwl_caret.cpp @@ -65,21 +65,21 @@ void IFWL_Caret::ShowCaret(bool bFlag) { void IFWL_Caret::DrawCaretBK(CFX_Graphics* pGraphics, IFWL_ThemeProvider* pTheme, const CFX_Matrix* pMatrix) { + if (!(m_pProperties->m_dwStates & FWL_STATE_CAT_HightLight)) + return; + CFX_RectF rect; GetWidgetRect(rect); rect.Set(0, 0, rect.width, rect.height); + CFWL_ThemeBackground param; param.m_pWidget = this; param.m_pGraphics = pGraphics; param.m_rtPart = rect; - if (!(m_pProperties->m_dwStates & FWL_STATE_CAT_HightLight)) - return; - param.m_iPart = CFWL_Part::Background; param.m_dwStates = CFWL_PartState_HightLight; if (pMatrix) param.m_matrix.Concat(*pMatrix); - pTheme->DrawBackground(¶m); } @@ -94,8 +94,8 @@ IFWL_Caret::Timer::Timer(IFWL_Caret* pCaret) : IFWL_Timer(pCaret) {} void IFWL_Caret::Timer::Run(IFWL_TimerInfo* pTimerInfo) { IFWL_Caret* pCaret = static_cast(m_pWidget); - bool toggle = !(pCaret->GetStates() & FWL_STATE_CAT_HightLight); - pCaret->SetStates(FWL_STATE_CAT_HightLight, toggle); + pCaret->SetStates(FWL_STATE_CAT_HightLight, + !(pCaret->GetStates() & FWL_STATE_CAT_HightLight)); CFX_RectF rt; pCaret->GetWidgetRect(rt); diff --git a/xfa/fwl/core/ifwl_checkbox.cpp b/xfa/fwl/core/ifwl_checkbox.cpp index e309a35cd0..6c548014f5 100644 --- a/xfa/fwl/core/ifwl_checkbox.cpp +++ b/xfa/fwl/core/ifwl_checkbox.cpp @@ -44,43 +44,43 @@ FWL_Type IFWL_CheckBox::GetClassID() const { } void IFWL_CheckBox::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { - if (bAutoSize) { - rect.Set(0, 0, 0, 0); - if (!m_pProperties->m_pThemeProvider) - m_pProperties->m_pThemeProvider = GetAvailableTheme(); - if (!m_pProperties->m_pThemeProvider) - return; - if (!m_pProperties->m_pDataProvider) - return; - CFX_WideString wsCaption; - m_pProperties->m_pDataProvider->GetCaption(this, wsCaption); - if (wsCaption.GetLength() > 0) { - CFX_SizeF sz = CalcTextSize( - wsCaption, m_pProperties->m_pThemeProvider, - !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine)); - rect.Set(0, 0, sz.x, sz.y); - } - rect.Inflate(kCaptionMargin, kCaptionMargin); - IFWL_CheckBoxDP* pData = - static_cast(m_pProperties->m_pDataProvider); - FX_FLOAT fCheckBox = pData->GetBoxSize(this); - rect.width += fCheckBox; - if (rect.height < fCheckBox) { - rect.height = fCheckBox; - } - IFWL_Widget::GetWidgetRect(rect, true); - } else { + if (!bAutoSize) { rect = m_pProperties->m_rtWidget; + return; + } + + rect.Set(0, 0, 0, 0); + if (!m_pProperties->m_pThemeProvider) + m_pProperties->m_pThemeProvider = GetAvailableTheme(); + if (!m_pProperties->m_pThemeProvider) + return; + if (!m_pProperties->m_pDataProvider) + return; + + CFX_WideString wsCaption; + m_pProperties->m_pDataProvider->GetCaption(this, wsCaption); + if (wsCaption.GetLength() > 0) { + CFX_SizeF sz = CalcTextSize( + wsCaption, m_pProperties->m_pThemeProvider, + !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine)); + rect.Set(0, 0, sz.x, sz.y); } + rect.Inflate(kCaptionMargin, kCaptionMargin); + + IFWL_CheckBoxDP* pData = + static_cast(m_pProperties->m_pDataProvider); + FX_FLOAT fCheckBox = pData->GetBoxSize(this); + rect.width += fCheckBox; + rect.height = std::max(rect.height, fCheckBox); + IFWL_Widget::GetWidgetRect(rect, true); } void IFWL_CheckBox::Update() { - if (IsLocked()) { + if (IsLocked()) return; - } - if (!m_pProperties->m_pThemeProvider) { + if (!m_pProperties->m_pThemeProvider) m_pProperties->m_pThemeProvider = GetAvailableTheme(); - } + UpdateTextOutStyles(); Layout(); } @@ -91,56 +91,53 @@ void IFWL_CheckBox::DrawWidget(CFX_Graphics* pGraphics, return; if (!m_pProperties->m_pThemeProvider) return; + IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; if (HasBorder()) { DrawBorder(pGraphics, CFWL_Part::Border, m_pProperties->m_pThemeProvider, pMatrix); } - if (HasEdge()) { + if (HasEdge()) DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); - } + int32_t dwStates = GetPartStates(); - { - CFWL_ThemeBackground param; - param.m_pWidget = this; - param.m_iPart = CFWL_Part::Background; - param.m_dwStates = dwStates; - param.m_pGraphics = pGraphics; - if (pMatrix) { - param.m_matrix.Concat(*pMatrix); - } - param.m_rtPart = m_rtClient; - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) { - param.m_pData = &m_rtFocus; - } - pTheme->DrawBackground(¶m); - param.m_iPart = CFWL_Part::CheckBox; - param.m_rtPart = m_rtBox; - pTheme->DrawBackground(¶m); - } + + CFWL_ThemeBackground param; + param.m_pWidget = this; + param.m_iPart = CFWL_Part::Background; + param.m_dwStates = dwStates; + param.m_pGraphics = pGraphics; + if (pMatrix) + param.m_matrix.Concat(*pMatrix); + param.m_rtPart = m_rtClient; + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) + param.m_pData = &m_rtFocus; + pTheme->DrawBackground(¶m); + + param.m_iPart = CFWL_Part::CheckBox; + param.m_rtPart = m_rtBox; + pTheme->DrawBackground(¶m); + if (!m_pProperties->m_pDataProvider) return; - { - CFX_WideString wsCaption; - m_pProperties->m_pDataProvider->GetCaption(this, wsCaption); - int32_t iLen = wsCaption.GetLength(); - if (iLen <= 0) - return; - CFWL_ThemeText textParam; - textParam.m_pWidget = this; - textParam.m_iPart = CFWL_Part::Caption; - textParam.m_dwStates = dwStates; - textParam.m_pGraphics = pGraphics; - if (pMatrix) { - textParam.m_matrix.Concat(*pMatrix); - } - textParam.m_rtPart = m_rtCaption; - textParam.m_wsText = wsCaption; - textParam.m_dwTTOStyles = m_dwTTOStyles; - textParam.m_iTTOAlign = m_iTTOAlign; - pTheme->DrawText(&textParam); - } + CFX_WideString wsCaption; + m_pProperties->m_pDataProvider->GetCaption(this, wsCaption); + if (wsCaption.GetLength() <= 0) + return; + + CFWL_ThemeText textParam; + textParam.m_pWidget = this; + textParam.m_iPart = CFWL_Part::Caption; + textParam.m_dwStates = dwStates; + textParam.m_pGraphics = pGraphics; + if (pMatrix) + textParam.m_matrix.Concat(*pMatrix); + textParam.m_rtPart = m_rtCaption; + textParam.m_wsText = wsCaption; + textParam.m_dwTTOStyles = m_dwTTOStyles; + textParam.m_iTTOAlign = m_iTTOAlign; + pTheme->DrawText(&textParam); } void IFWL_CheckBox::SetCheckState(int32_t iCheck) { @@ -160,26 +157,24 @@ void IFWL_CheckBox::SetCheckState(int32_t iCheck) { } void IFWL_CheckBox::Layout() { - int32_t width = int32_t(m_pProperties->m_rtWidget.width + 0.5f); - int32_t height = int32_t(m_pProperties->m_rtWidget.height + 0.5f); - m_pProperties->m_rtWidget.width = (FX_FLOAT)width; - m_pProperties->m_rtWidget.height = (FX_FLOAT)height; + m_pProperties->m_rtWidget.width = + FXSYS_round(m_pProperties->m_rtWidget.width); + m_pProperties->m_rtWidget.height = + FXSYS_round(m_pProperties->m_rtWidget.height); GetClientRect(m_rtClient); - FX_FLOAT fBoxTop = m_rtClient.top; - FX_FLOAT fBoxLeft = m_rtClient.left; - FX_FLOAT fTextLeft = 0.0, fTextRight = 0.0; - FX_FLOAT fClientRight = m_rtClient.right(); - FX_FLOAT fClientBottom = m_rtClient.bottom(); + if (!m_pProperties->m_pDataProvider) return; + + FX_FLOAT fBoxTop = m_rtClient.top; + FX_FLOAT fClientBottom = m_rtClient.bottom(); + IFWL_CheckBoxDP* pData = static_cast(m_pProperties->m_pDataProvider); FX_FLOAT fCheckBox = pData->GetBoxSize(this); switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) { - case FWL_STYLEEXT_CKB_Top: { - fBoxTop = m_rtClient.top; + case FWL_STYLEEXT_CKB_Top: break; - } case FWL_STYLEEXT_CKB_Bottom: { fBoxTop = fClientBottom - fCheckBox; break; @@ -188,8 +183,14 @@ void IFWL_CheckBox::Layout() { default: { fBoxTop = m_rtClient.top + (m_rtClient.height - fCheckBox) / 2; fBoxTop = FXSYS_floor(fBoxTop); + break; } } + + FX_FLOAT fBoxLeft = m_rtClient.left; + FX_FLOAT fTextLeft = 0.0; + FX_FLOAT fTextRight = 0.0; + FX_FLOAT fClientRight = m_rtClient.right(); if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_LeftText) { fBoxLeft = fClientRight - fCheckBox; fTextLeft = m_rtClient.left; @@ -202,44 +203,47 @@ void IFWL_CheckBox::Layout() { m_rtCaption.Set(fTextLeft, m_rtClient.top, fTextRight - fTextLeft, m_rtClient.height); m_rtCaption.Inflate(-kCaptionMargin, -kCaptionMargin); + CFX_RectF rtFocus; rtFocus.Set(m_rtCaption.left, m_rtCaption.top, m_rtCaption.width, m_rtCaption.height); + CFX_WideString wsCaption; m_pProperties->m_pDataProvider->GetCaption(this, wsCaption); if (wsCaption.IsEmpty()) { m_rtFocus.Set(0, 0, 0, 0); - } else { - CalcTextRect(wsCaption, m_pProperties->m_pThemeProvider, m_dwTTOStyles, - m_iTTOAlign, rtFocus); - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) == 0) { - FX_FLOAT fWidth = std::max(m_rtCaption.width, rtFocus.width); - FX_FLOAT fHeight = std::min(m_rtCaption.height, rtFocus.height); - FX_FLOAT fLeft = m_rtCaption.left; - FX_FLOAT fTop = m_rtCaption.top; - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) == - FWL_STYLEEXT_CKB_Center) { - fLeft = m_rtCaption.left + (m_rtCaption.width - fWidth) / 2; - } else if ((m_pProperties->m_dwStyleExes & - FWL_STYLEEXT_CKB_HLayoutMask) == FWL_STYLEEXT_CKB_Right) { - fLeft = m_rtCaption.right() - fWidth; - } - if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) == - FWL_STYLEEXT_CKB_VCenter) { - fTop = m_rtCaption.top + (m_rtCaption.height - fHeight) / 2; - } else if ((m_pProperties->m_dwStyleExes & - FWL_STYLEEXT_CKB_VLayoutMask) == FWL_STYLEEXT_CKB_Bottom) { - fTop = m_rtCaption.bottom() - fHeight; - } - m_rtFocus.Set(fLeft, fTop, fWidth, fHeight); - } else { - m_rtFocus.Set(rtFocus.left, rtFocus.top, rtFocus.width, rtFocus.height); + return; + } + + CalcTextRect(wsCaption, m_pProperties->m_pThemeProvider, m_dwTTOStyles, + m_iTTOAlign, rtFocus); + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) == 0) { + FX_FLOAT fWidth = std::max(m_rtCaption.width, rtFocus.width); + FX_FLOAT fHeight = std::min(m_rtCaption.height, rtFocus.height); + FX_FLOAT fLeft = m_rtCaption.left; + FX_FLOAT fTop = m_rtCaption.top; + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) == + FWL_STYLEEXT_CKB_Center) { + fLeft = m_rtCaption.left + (m_rtCaption.width - fWidth) / 2; + } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) == + FWL_STYLEEXT_CKB_Right) { + fLeft = m_rtCaption.right() - fWidth; } - m_rtFocus.Inflate(1, 1); + if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) == + FWL_STYLEEXT_CKB_VCenter) { + fTop = m_rtCaption.top + (m_rtCaption.height - fHeight) / 2; + } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) == + FWL_STYLEEXT_CKB_Bottom) { + fTop = m_rtCaption.bottom() - fHeight; + } + m_rtFocus.Set(fLeft, fTop, fWidth, fHeight); + } else { + m_rtFocus.Set(rtFocus.left, rtFocus.top, rtFocus.width, rtFocus.height); } + m_rtFocus.Inflate(1, 1); } -uint32_t IFWL_CheckBox::GetPartStates() { +uint32_t IFWL_CheckBox::GetPartStates() const { int32_t dwStates = CFWL_PartState_Normal; if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == FWL_STATE_CKB_Neutral) { @@ -248,23 +252,20 @@ uint32_t IFWL_CheckBox::GetPartStates() { FWL_STATE_CKB_Checked) { dwStates = CFWL_PartState_Checked; } - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) dwStates |= CFWL_PartState_Disabled; - } else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) { + else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) dwStates |= CFWL_PartState_Hovered; - } else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) { + else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) dwStates |= CFWL_PartState_Pressed; - } else { + else dwStates |= CFWL_PartState_Normal; - } - if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) { + if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) dwStates |= CFWL_PartState_Focused; - } return dwStates; } void IFWL_CheckBox::UpdateTextOutStyles() { - m_iTTOAlign = FDE_TTOALIGNMENT_Center; switch (m_pProperties->m_dwStyleExes & (FWL_STYLEEXT_CKB_HLayoutMask | FWL_STYLEEXT_CKB_VLayoutMask)) { case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_Top: { @@ -283,10 +284,6 @@ void IFWL_CheckBox::UpdateTextOutStyles() { m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; break; } - case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_VCenter: { - m_iTTOAlign = FDE_TTOALIGNMENT_Center; - break; - } case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_VCenter: { m_iTTOAlign = FDE_TTOALIGNMENT_CenterRight; break; @@ -303,17 +300,19 @@ void IFWL_CheckBox::UpdateTextOutStyles() { m_iTTOAlign = FDE_TTOALIGNMENT_BottomRight; break; } - default: {} + case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_VCenter: + default: { + m_iTTOAlign = FDE_TTOALIGNMENT_Center; + break; + } } m_dwTTOStyles = 0; - if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) { + if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) m_dwTTOStyles |= FDE_TTOSTYLE_RTL; - } - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) { + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) m_dwTTOStyles |= FDE_TTOSTYLE_LineWrap; - } else { + else m_dwTTOStyles |= FDE_TTOSTYLE_SingleLine; - } } void IFWL_CheckBox::NextStates() { @@ -346,23 +345,21 @@ void IFWL_CheckBox::NextStates() { if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == FWL_STATE_CKB_Neutral) { m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask; - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) { + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; - } } else if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == FWL_STATE_CKB_Checked) { m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask; } else { - if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) { + if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) m_pProperties->m_dwStates |= FWL_STATE_CKB_Neutral; - } else { + else m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; - } } } + Repaint(&m_rtClient); - uint32_t dwLaststate = m_pProperties->m_dwStates; - if (dwFirststate != dwLaststate) { + if (dwFirststate != m_pProperties->m_dwStates) { CFWL_EvtCkbCheckStateChanged wmCheckBoxState; wmCheckBoxState.m_pSrcTarget = this; DispatchEvent(&wmCheckBoxState); @@ -375,16 +372,16 @@ void IFWL_CheckBox::OnProcessMessage(CFWL_Message* pMessage) { switch (pMessage->GetClassID()) { case CFWL_MessageType::SetFocus: - OnFocusChanged(pMessage, true); + OnFocusChanged(true); break; case CFWL_MessageType::KillFocus: - OnFocusChanged(pMessage, false); + OnFocusChanged(false); break; case CFWL_MessageType::Mouse: { CFWL_MsgMouse* pMsg = static_cast(pMessage); switch (pMsg->m_dwCmd) { case FWL_MouseCommand::LeftButtonDown: - OnLButtonDown(pMsg); + OnLButtonDown(); break; case FWL_MouseCommand::LeftButtonUp: OnLButtonUp(pMsg); @@ -393,7 +390,7 @@ void IFWL_CheckBox::OnProcessMessage(CFWL_Message* pMessage) { OnMouseMove(pMsg); break; case FWL_MouseCommand::Leave: - OnMouseLeave(pMsg); + OnMouseLeave(); break; default: break; @@ -418,16 +415,16 @@ void IFWL_CheckBox::OnDrawWidget(CFX_Graphics* pGraphics, DrawWidget(pGraphics, pMatrix); } -void IFWL_CheckBox::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { +void IFWL_CheckBox::OnFocusChanged(bool bSet) { if (bSet) m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; else m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; - Repaint(&(m_rtClient)); + Repaint(&m_rtClient); } -void IFWL_CheckBox::OnLButtonDown(CFWL_MsgMouse* pMsg) { +void IFWL_CheckBox::OnLButtonDown() { if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) return; if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) @@ -436,7 +433,7 @@ void IFWL_CheckBox::OnLButtonDown(CFWL_MsgMouse* pMsg) { m_bBtnDown = true; m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; - Repaint(&(m_rtClient)); + Repaint(&m_rtClient); } void IFWL_CheckBox::OnLButtonUp(CFWL_MsgMouse* pMsg) { @@ -485,18 +482,17 @@ void IFWL_CheckBox::OnMouseMove(CFWL_MsgMouse* pMsg) { } } } - if (bRepaint) { - Repaint(&(m_rtBox)); - } + if (bRepaint) + Repaint(&m_rtBox); } -void IFWL_CheckBox::OnMouseLeave(CFWL_MsgMouse* pMsg) { +void IFWL_CheckBox::OnMouseLeave() { if (m_bBtnDown) m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; else m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; - Repaint(&(m_rtBox)); + Repaint(&m_rtBox); } void IFWL_CheckBox::OnKeyDown(CFWL_MsgKey* pMsg) { diff --git a/xfa/fwl/core/ifwl_checkbox.h b/xfa/fwl/core/ifwl_checkbox.h index 06e8f703af..0b38e777b8 100644 --- a/xfa/fwl/core/ifwl_checkbox.h +++ b/xfa/fwl/core/ifwl_checkbox.h @@ -74,14 +74,14 @@ class IFWL_CheckBox : public IFWL_Widget { private: void SetCheckState(int32_t iCheck); void Layout(); - uint32_t GetPartStates(); + uint32_t GetPartStates() const; void UpdateTextOutStyles(); void NextStates(); - void OnFocusChanged(CFWL_Message* pMsg, bool bSet); - void OnLButtonDown(CFWL_MsgMouse* pMsg); + void OnFocusChanged(bool bSet); + void OnLButtonDown(); void OnLButtonUp(CFWL_MsgMouse* pMsg); void OnMouseMove(CFWL_MsgMouse* pMsg); - void OnMouseLeave(CFWL_MsgMouse* pMsg); + void OnMouseLeave(); void OnKeyDown(CFWL_MsgKey* pMsg); CFX_RectF m_rtClient; -- cgit v1.2.3