| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fwl/core/ifwl_checkbox.h" | 7 #include "xfa/fwl/core/ifwl_checkbox.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 m_rtCaption.Reset(); | 36 m_rtCaption.Reset(); |
| 37 m_rtFocus.Reset(); | 37 m_rtFocus.Reset(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 IFWL_CheckBox::~IFWL_CheckBox() {} | 40 IFWL_CheckBox::~IFWL_CheckBox() {} |
| 41 | 41 |
| 42 FWL_Type IFWL_CheckBox::GetClassID() const { | 42 FWL_Type IFWL_CheckBox::GetClassID() const { |
| 43 return FWL_Type::CheckBox; | 43 return FWL_Type::CheckBox; |
| 44 } | 44 } |
| 45 | 45 |
| 46 FWL_Error IFWL_CheckBox::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { | 46 void IFWL_CheckBox::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { |
| 47 if (bAutoSize) { | 47 if (bAutoSize) { |
| 48 rect.Set(0, 0, 0, 0); | 48 rect.Set(0, 0, 0, 0); |
| 49 if (!m_pProperties->m_pThemeProvider) | 49 if (!m_pProperties->m_pThemeProvider) |
| 50 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | 50 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
| 51 if (!m_pProperties->m_pThemeProvider) | 51 if (!m_pProperties->m_pThemeProvider) |
| 52 return FWL_Error::Indefinite; | 52 return; |
| 53 if (!m_pProperties->m_pDataProvider) | 53 if (!m_pProperties->m_pDataProvider) |
| 54 return FWL_Error::Indefinite; | 54 return; |
| 55 CFX_WideString wsCaption; | 55 CFX_WideString wsCaption; |
| 56 m_pProperties->m_pDataProvider->GetCaption(this, wsCaption); | 56 m_pProperties->m_pDataProvider->GetCaption(this, wsCaption); |
| 57 if (wsCaption.GetLength() > 0) { | 57 if (wsCaption.GetLength() > 0) { |
| 58 CFX_SizeF sz = CalcTextSize( | 58 CFX_SizeF sz = CalcTextSize( |
| 59 wsCaption, m_pProperties->m_pThemeProvider, | 59 wsCaption, m_pProperties->m_pThemeProvider, |
| 60 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine)); | 60 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine)); |
| 61 rect.Set(0, 0, sz.x, sz.y); | 61 rect.Set(0, 0, sz.x, sz.y); |
| 62 } | 62 } |
| 63 rect.Inflate(kCaptionMargin, kCaptionMargin); | 63 rect.Inflate(kCaptionMargin, kCaptionMargin); |
| 64 IFWL_CheckBoxDP* pData = | 64 IFWL_CheckBoxDP* pData = |
| 65 static_cast<IFWL_CheckBoxDP*>(m_pProperties->m_pDataProvider); | 65 static_cast<IFWL_CheckBoxDP*>(m_pProperties->m_pDataProvider); |
| 66 FX_FLOAT fCheckBox = pData->GetBoxSize(this); | 66 FX_FLOAT fCheckBox = pData->GetBoxSize(this); |
| 67 rect.width += fCheckBox; | 67 rect.width += fCheckBox; |
| 68 if (rect.height < fCheckBox) { | 68 if (rect.height < fCheckBox) { |
| 69 rect.height = fCheckBox; | 69 rect.height = fCheckBox; |
| 70 } | 70 } |
| 71 IFWL_Widget::GetWidgetRect(rect, true); | 71 IFWL_Widget::GetWidgetRect(rect, true); |
| 72 } else { | 72 } else { |
| 73 rect = m_pProperties->m_rtWidget; | 73 rect = m_pProperties->m_rtWidget; |
| 74 } | 74 } |
| 75 return FWL_Error::Succeeded; | |
| 76 } | 75 } |
| 77 | 76 |
| 78 FWL_Error IFWL_CheckBox::Update() { | 77 void IFWL_CheckBox::Update() { |
| 79 if (IsLocked()) { | 78 if (IsLocked()) { |
| 80 return FWL_Error::Indefinite; | 79 return; |
| 81 } | 80 } |
| 82 if (!m_pProperties->m_pThemeProvider) { | 81 if (!m_pProperties->m_pThemeProvider) { |
| 83 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | 82 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
| 84 } | 83 } |
| 85 UpdateTextOutStyles(); | 84 UpdateTextOutStyles(); |
| 86 Layout(); | 85 Layout(); |
| 87 return FWL_Error::Succeeded; | |
| 88 } | 86 } |
| 89 | 87 |
| 90 FWL_Error IFWL_CheckBox::DrawWidget(CFX_Graphics* pGraphics, | 88 void IFWL_CheckBox::DrawWidget(CFX_Graphics* pGraphics, |
| 91 const CFX_Matrix* pMatrix) { | 89 const CFX_Matrix* pMatrix) { |
| 92 if (!pGraphics) | 90 if (!pGraphics) |
| 93 return FWL_Error::Indefinite; | 91 return; |
| 94 if (!m_pProperties->m_pThemeProvider) | 92 if (!m_pProperties->m_pThemeProvider) |
| 95 return FWL_Error::Indefinite; | 93 return; |
| 96 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | 94 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
| 97 if (HasBorder()) { | 95 if (HasBorder()) { |
| 98 DrawBorder(pGraphics, CFWL_Part::Border, m_pProperties->m_pThemeProvider, | 96 DrawBorder(pGraphics, CFWL_Part::Border, m_pProperties->m_pThemeProvider, |
| 99 pMatrix); | 97 pMatrix); |
| 100 } | 98 } |
| 101 if (HasEdge()) { | 99 if (HasEdge()) { |
| 102 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); | 100 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); |
| 103 } | 101 } |
| 104 int32_t dwStates = GetPartStates(); | 102 int32_t dwStates = GetPartStates(); |
| 105 { | 103 { |
| 106 CFWL_ThemeBackground param; | 104 CFWL_ThemeBackground param; |
| 107 param.m_pWidget = this; | 105 param.m_pWidget = this; |
| 108 param.m_iPart = CFWL_Part::Background; | 106 param.m_iPart = CFWL_Part::Background; |
| 109 param.m_dwStates = dwStates; | 107 param.m_dwStates = dwStates; |
| 110 param.m_pGraphics = pGraphics; | 108 param.m_pGraphics = pGraphics; |
| 111 if (pMatrix) { | 109 if (pMatrix) { |
| 112 param.m_matrix.Concat(*pMatrix); | 110 param.m_matrix.Concat(*pMatrix); |
| 113 } | 111 } |
| 114 param.m_rtPart = m_rtClient; | 112 param.m_rtPart = m_rtClient; |
| 115 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) { | 113 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) { |
| 116 param.m_pData = &m_rtFocus; | 114 param.m_pData = &m_rtFocus; |
| 117 } | 115 } |
| 118 pTheme->DrawBackground(¶m); | 116 pTheme->DrawBackground(¶m); |
| 119 param.m_iPart = CFWL_Part::CheckBox; | 117 param.m_iPart = CFWL_Part::CheckBox; |
| 120 param.m_rtPart = m_rtBox; | 118 param.m_rtPart = m_rtBox; |
| 121 pTheme->DrawBackground(¶m); | 119 pTheme->DrawBackground(¶m); |
| 122 } | 120 } |
| 123 if (!m_pProperties->m_pDataProvider) | 121 if (!m_pProperties->m_pDataProvider) |
| 124 return FWL_Error::Indefinite; | 122 return; |
| 123 |
| 125 { | 124 { |
| 126 CFX_WideString wsCaption; | 125 CFX_WideString wsCaption; |
| 127 m_pProperties->m_pDataProvider->GetCaption(this, wsCaption); | 126 m_pProperties->m_pDataProvider->GetCaption(this, wsCaption); |
| 128 int32_t iLen = wsCaption.GetLength(); | 127 int32_t iLen = wsCaption.GetLength(); |
| 129 if (iLen <= 0) | 128 if (iLen <= 0) |
| 130 return FWL_Error::Indefinite; | 129 return; |
| 131 CFWL_ThemeText textParam; | 130 CFWL_ThemeText textParam; |
| 132 textParam.m_pWidget = this; | 131 textParam.m_pWidget = this; |
| 133 textParam.m_iPart = CFWL_Part::Caption; | 132 textParam.m_iPart = CFWL_Part::Caption; |
| 134 textParam.m_dwStates = dwStates; | 133 textParam.m_dwStates = dwStates; |
| 135 textParam.m_pGraphics = pGraphics; | 134 textParam.m_pGraphics = pGraphics; |
| 136 if (pMatrix) { | 135 if (pMatrix) { |
| 137 textParam.m_matrix.Concat(*pMatrix); | 136 textParam.m_matrix.Concat(*pMatrix); |
| 138 } | 137 } |
| 139 textParam.m_rtPart = m_rtCaption; | 138 textParam.m_rtPart = m_rtCaption; |
| 140 textParam.m_wsText = wsCaption; | 139 textParam.m_wsText = wsCaption; |
| 141 textParam.m_dwTTOStyles = m_dwTTOStyles; | 140 textParam.m_dwTTOStyles = m_dwTTOStyles; |
| 142 textParam.m_iTTOAlign = m_iTTOAlign; | 141 textParam.m_iTTOAlign = m_iTTOAlign; |
| 143 pTheme->DrawText(&textParam); | 142 pTheme->DrawText(&textParam); |
| 144 } | 143 } |
| 145 return FWL_Error::Succeeded; | |
| 146 } | 144 } |
| 147 | 145 |
| 148 int32_t IFWL_CheckBox::GetCheckState() { | 146 int32_t IFWL_CheckBox::GetCheckState() { |
| 149 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) && | 147 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) && |
| 150 ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == | 148 ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == |
| 151 FWL_STATE_CKB_Neutral)) { | 149 FWL_STATE_CKB_Neutral)) { |
| 152 return 2; | 150 return 2; |
| 153 } | 151 } |
| 154 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == | 152 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == |
| 155 FWL_STATE_CKB_Checked) { | 153 FWL_STATE_CKB_Checked) { |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 void IFWL_CheckBox::OnKeyDown(CFWL_MsgKey* pMsg) { | 529 void IFWL_CheckBox::OnKeyDown(CFWL_MsgKey* pMsg) { |
| 532 if (pMsg->m_dwKeyCode == FWL_VKEY_Tab) { | 530 if (pMsg->m_dwKeyCode == FWL_VKEY_Tab) { |
| 533 DispatchKeyEvent(pMsg); | 531 DispatchKeyEvent(pMsg); |
| 534 return; | 532 return; |
| 535 } | 533 } |
| 536 if (pMsg->m_dwKeyCode == FWL_VKEY_Return || | 534 if (pMsg->m_dwKeyCode == FWL_VKEY_Return || |
| 537 pMsg->m_dwKeyCode == FWL_VKEY_Space) { | 535 pMsg->m_dwKeyCode == FWL_VKEY_Space) { |
| 538 NextStates(); | 536 NextStates(); |
| 539 } | 537 } |
| 540 } | 538 } |
| OLD | NEW |