| 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 #include <memory> | 10 #include <memory> |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 53 } |
| 54 | 54 |
| 55 rect.Set(0, 0, 0, 0); | 55 rect.Set(0, 0, 0, 0); |
| 56 if (!m_pProperties->m_pThemeProvider) | 56 if (!m_pProperties->m_pThemeProvider) |
| 57 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | 57 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
| 58 if (!m_pProperties->m_pThemeProvider) | 58 if (!m_pProperties->m_pThemeProvider) |
| 59 return; | 59 return; |
| 60 if (!m_pProperties->m_pDataProvider) | 60 if (!m_pProperties->m_pDataProvider) |
| 61 return; | 61 return; |
| 62 | 62 |
| 63 CFX_WideString wsCaption; | 63 CFX_SizeF sz = CalcTextSize( |
| 64 m_pProperties->m_pDataProvider->GetCaption(this, wsCaption); | 64 L"Check box", m_pProperties->m_pThemeProvider, |
| 65 if (wsCaption.GetLength() > 0) { | 65 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine)); |
| 66 CFX_SizeF sz = CalcTextSize( | 66 rect.Set(0, 0, sz.x, sz.y); |
| 67 wsCaption, m_pProperties->m_pThemeProvider, | |
| 68 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine)); | |
| 69 rect.Set(0, 0, sz.x, sz.y); | |
| 70 } | |
| 71 rect.Inflate(kCaptionMargin, kCaptionMargin); | 67 rect.Inflate(kCaptionMargin, kCaptionMargin); |
| 72 | 68 |
| 73 IFWL_CheckBox::DataProvider* pData = | 69 IFWL_CheckBox::DataProvider* pData = |
| 74 static_cast<IFWL_CheckBox::DataProvider*>(m_pProperties->m_pDataProvider); | 70 static_cast<IFWL_CheckBox::DataProvider*>(m_pProperties->m_pDataProvider); |
| 75 FX_FLOAT fCheckBox = pData->GetBoxSize(this); | 71 FX_FLOAT fCheckBox = pData->GetBoxSize(this); |
| 76 rect.width += fCheckBox; | 72 rect.width += fCheckBox; |
| 77 rect.height = std::max(rect.height, fCheckBox); | 73 rect.height = std::max(rect.height, fCheckBox); |
| 78 IFWL_Widget::GetWidgetRect(rect, true); | 74 IFWL_Widget::GetWidgetRect(rect, true); |
| 79 } | 75 } |
| 80 | 76 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 param.m_pData = &m_rtFocus; | 113 param.m_pData = &m_rtFocus; |
| 118 pTheme->DrawBackground(¶m); | 114 pTheme->DrawBackground(¶m); |
| 119 | 115 |
| 120 param.m_iPart = CFWL_Part::CheckBox; | 116 param.m_iPart = CFWL_Part::CheckBox; |
| 121 param.m_rtPart = m_rtBox; | 117 param.m_rtPart = m_rtBox; |
| 122 pTheme->DrawBackground(¶m); | 118 pTheme->DrawBackground(¶m); |
| 123 | 119 |
| 124 if (!m_pProperties->m_pDataProvider) | 120 if (!m_pProperties->m_pDataProvider) |
| 125 return; | 121 return; |
| 126 | 122 |
| 127 CFX_WideString wsCaption; | |
| 128 m_pProperties->m_pDataProvider->GetCaption(this, wsCaption); | |
| 129 if (wsCaption.GetLength() <= 0) | |
| 130 return; | |
| 131 | |
| 132 CFWL_ThemeText textParam; | 123 CFWL_ThemeText textParam; |
| 133 textParam.m_pWidget = this; | 124 textParam.m_pWidget = this; |
| 134 textParam.m_iPart = CFWL_Part::Caption; | 125 textParam.m_iPart = CFWL_Part::Caption; |
| 135 textParam.m_dwStates = dwStates; | 126 textParam.m_dwStates = dwStates; |
| 136 textParam.m_pGraphics = pGraphics; | 127 textParam.m_pGraphics = pGraphics; |
| 137 if (pMatrix) | 128 if (pMatrix) |
| 138 textParam.m_matrix.Concat(*pMatrix); | 129 textParam.m_matrix.Concat(*pMatrix); |
| 139 textParam.m_rtPart = m_rtCaption; | 130 textParam.m_rtPart = m_rtCaption; |
| 140 textParam.m_wsText = wsCaption; | 131 textParam.m_wsText = L"Check box"; |
| 141 textParam.m_dwTTOStyles = m_dwTTOStyles; | 132 textParam.m_dwTTOStyles = m_dwTTOStyles; |
| 142 textParam.m_iTTOAlign = m_iTTOAlign; | 133 textParam.m_iTTOAlign = m_iTTOAlign; |
| 143 pTheme->DrawText(&textParam); | 134 pTheme->DrawText(&textParam); |
| 144 } | 135 } |
| 145 | 136 |
| 146 void IFWL_CheckBox::SetCheckState(int32_t iCheck) { | 137 void IFWL_CheckBox::SetCheckState(int32_t iCheck) { |
| 147 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask; | 138 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask; |
| 148 switch (iCheck) { | 139 switch (iCheck) { |
| 149 case 1: | 140 case 1: |
| 150 m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; | 141 m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 195 } |
| 205 m_rtBox.Set(fBoxLeft, fBoxTop, fCheckBox, fCheckBox); | 196 m_rtBox.Set(fBoxLeft, fBoxTop, fCheckBox, fCheckBox); |
| 206 m_rtCaption.Set(fTextLeft, m_rtClient.top, fTextRight - fTextLeft, | 197 m_rtCaption.Set(fTextLeft, m_rtClient.top, fTextRight - fTextLeft, |
| 207 m_rtClient.height); | 198 m_rtClient.height); |
| 208 m_rtCaption.Inflate(-kCaptionMargin, -kCaptionMargin); | 199 m_rtCaption.Inflate(-kCaptionMargin, -kCaptionMargin); |
| 209 | 200 |
| 210 CFX_RectF rtFocus; | 201 CFX_RectF rtFocus; |
| 211 rtFocus.Set(m_rtCaption.left, m_rtCaption.top, m_rtCaption.width, | 202 rtFocus.Set(m_rtCaption.left, m_rtCaption.top, m_rtCaption.width, |
| 212 m_rtCaption.height); | 203 m_rtCaption.height); |
| 213 | 204 |
| 214 CFX_WideString wsCaption; | 205 CalcTextRect(L"Check box", m_pProperties->m_pThemeProvider, m_dwTTOStyles, |
| 215 m_pProperties->m_pDataProvider->GetCaption(this, wsCaption); | |
| 216 if (wsCaption.IsEmpty()) { | |
| 217 m_rtFocus.Set(0, 0, 0, 0); | |
| 218 return; | |
| 219 } | |
| 220 | |
| 221 CalcTextRect(wsCaption, m_pProperties->m_pThemeProvider, m_dwTTOStyles, | |
| 222 m_iTTOAlign, rtFocus); | 206 m_iTTOAlign, rtFocus); |
| 223 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) == 0) { | 207 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) == 0) { |
| 224 FX_FLOAT fWidth = std::max(m_rtCaption.width, rtFocus.width); | 208 FX_FLOAT fWidth = std::max(m_rtCaption.width, rtFocus.width); |
| 225 FX_FLOAT fHeight = std::min(m_rtCaption.height, rtFocus.height); | 209 FX_FLOAT fHeight = std::min(m_rtCaption.height, rtFocus.height); |
| 226 FX_FLOAT fLeft = m_rtCaption.left; | 210 FX_FLOAT fLeft = m_rtCaption.left; |
| 227 FX_FLOAT fTop = m_rtCaption.top; | 211 FX_FLOAT fTop = m_rtCaption.top; |
| 228 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) == | 212 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) == |
| 229 FWL_STYLEEXT_CKB_Center) { | 213 FWL_STYLEEXT_CKB_Center) { |
| 230 fLeft = m_rtCaption.left + (m_rtCaption.width - fWidth) / 2; | 214 fLeft = m_rtCaption.left + (m_rtCaption.width - fWidth) / 2; |
| 231 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) == | 215 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) == |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 void IFWL_CheckBox::OnKeyDown(CFWL_MsgKey* pMsg) { | 486 void IFWL_CheckBox::OnKeyDown(CFWL_MsgKey* pMsg) { |
| 503 if (pMsg->m_dwKeyCode == FWL_VKEY_Tab) { | 487 if (pMsg->m_dwKeyCode == FWL_VKEY_Tab) { |
| 504 DispatchKeyEvent(pMsg); | 488 DispatchKeyEvent(pMsg); |
| 505 return; | 489 return; |
| 506 } | 490 } |
| 507 if (pMsg->m_dwKeyCode == FWL_VKEY_Return || | 491 if (pMsg->m_dwKeyCode == FWL_VKEY_Return || |
| 508 pMsg->m_dwKeyCode == FWL_VKEY_Space) { | 492 pMsg->m_dwKeyCode == FWL_VKEY_Space) { |
| 509 NextStates(); | 493 NextStates(); |
| 510 } | 494 } |
| 511 } | 495 } |
| OLD | NEW |