| 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/cfwl_checkbox.h" | 7 #include "xfa/fwl/cfwl_checkbox.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 } | 124 } |
| 125 | 125 |
| 126 void CFWL_CheckBox::Layout() { | 126 void CFWL_CheckBox::Layout() { |
| 127 m_pProperties->m_rtWidget.width = | 127 m_pProperties->m_rtWidget.width = |
| 128 FXSYS_round(m_pProperties->m_rtWidget.width); | 128 FXSYS_round(m_pProperties->m_rtWidget.width); |
| 129 m_pProperties->m_rtWidget.height = | 129 m_pProperties->m_rtWidget.height = |
| 130 FXSYS_round(m_pProperties->m_rtWidget.height); | 130 FXSYS_round(m_pProperties->m_rtWidget.height); |
| 131 m_rtClient = GetClientRect(); | 131 m_rtClient = GetClientRect(); |
| 132 | 132 |
| 133 FX_FLOAT fBoxTop = m_rtClient.top; | 133 FX_FLOAT fBoxTop = m_rtClient.top; |
| 134 FX_FLOAT fClientBottom = m_rtClient.bottom(); | |
| 135 | |
| 136 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) { | |
| 137 case FWL_STYLEEXT_CKB_Top: | |
| 138 break; | |
| 139 case FWL_STYLEEXT_CKB_Bottom: { | |
| 140 fBoxTop = fClientBottom - m_fBoxHeight; | |
| 141 break; | |
| 142 } | |
| 143 case FWL_STYLEEXT_CKB_VCenter: | |
| 144 default: { | |
| 145 fBoxTop = m_rtClient.top + (m_rtClient.height - m_fBoxHeight) / 2; | |
| 146 fBoxTop = FXSYS_floor(fBoxTop); | |
| 147 break; | |
| 148 } | |
| 149 } | |
| 150 | |
| 151 FX_FLOAT fBoxLeft = m_rtClient.left; | 134 FX_FLOAT fBoxLeft = m_rtClient.left; |
| 152 FX_FLOAT fTextLeft = 0.0; | 135 FX_FLOAT fTextLeft = fBoxLeft + m_fBoxHeight; |
| 153 FX_FLOAT fTextRight = 0.0; | 136 FX_FLOAT fTextRight = m_rtClient.right(); |
| 154 FX_FLOAT fClientRight = m_rtClient.right(); | |
| 155 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_LeftText) { | |
| 156 fBoxLeft = fClientRight - m_fBoxHeight; | |
| 157 fTextLeft = m_rtClient.left; | |
| 158 fTextRight = fBoxLeft; | |
| 159 } else { | |
| 160 fTextLeft = fBoxLeft + m_fBoxHeight; | |
| 161 fTextRight = fClientRight; | |
| 162 } | |
| 163 m_rtBox.Set(fBoxLeft, fBoxTop, m_fBoxHeight, m_fBoxHeight); | 137 m_rtBox.Set(fBoxLeft, fBoxTop, m_fBoxHeight, m_fBoxHeight); |
| 164 m_rtCaption.Set(fTextLeft, m_rtClient.top, fTextRight - fTextLeft, | 138 m_rtCaption.Set(fTextLeft, m_rtClient.top, fTextRight - fTextLeft, |
| 165 m_rtClient.height); | 139 m_rtClient.height); |
| 166 m_rtCaption.Inflate(-kCaptionMargin, -kCaptionMargin); | 140 m_rtCaption.Inflate(-kCaptionMargin, -kCaptionMargin); |
| 167 | 141 |
| 168 CFX_RectF rtFocus; | 142 CFX_RectF rtFocus; |
| 169 rtFocus.Set(m_rtCaption.left, m_rtCaption.top, m_rtCaption.width, | 143 rtFocus.Set(m_rtCaption.left, m_rtCaption.top, m_rtCaption.width, |
| 170 m_rtCaption.height); | 144 m_rtCaption.height); |
| 171 | 145 |
| 172 CalcTextRect(L"Check box", m_pProperties->m_pThemeProvider, m_dwTTOStyles, | 146 CalcTextRect(L"Check box", m_pProperties->m_pThemeProvider, m_dwTTOStyles, |
| 173 m_iTTOAlign, rtFocus); | 147 m_iTTOAlign, rtFocus); |
| 174 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) == 0) { | 148 |
| 175 FX_FLOAT fWidth = std::max(m_rtCaption.width, rtFocus.width); | 149 FX_FLOAT fWidth = std::max(m_rtCaption.width, rtFocus.width); |
| 176 FX_FLOAT fHeight = std::min(m_rtCaption.height, rtFocus.height); | 150 FX_FLOAT fHeight = std::min(m_rtCaption.height, rtFocus.height); |
| 177 FX_FLOAT fLeft = m_rtCaption.left; | 151 FX_FLOAT fLeft = m_rtCaption.left; |
| 178 FX_FLOAT fTop = m_rtCaption.top; | 152 FX_FLOAT fTop = m_rtCaption.top; |
| 179 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) == | 153 m_rtFocus.Set(fLeft, fTop, fWidth, fHeight); |
| 180 FWL_STYLEEXT_CKB_Center) { | |
| 181 fLeft = m_rtCaption.left + (m_rtCaption.width - fWidth) / 2; | |
| 182 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) == | |
| 183 FWL_STYLEEXT_CKB_Right) { | |
| 184 fLeft = m_rtCaption.right() - fWidth; | |
| 185 } | |
| 186 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) == | |
| 187 FWL_STYLEEXT_CKB_VCenter) { | |
| 188 fTop = m_rtCaption.top + (m_rtCaption.height - fHeight) / 2; | |
| 189 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) == | |
| 190 FWL_STYLEEXT_CKB_Bottom) { | |
| 191 fTop = m_rtCaption.bottom() - fHeight; | |
| 192 } | |
| 193 m_rtFocus.Set(fLeft, fTop, fWidth, fHeight); | |
| 194 } else { | |
| 195 m_rtFocus.Set(rtFocus.left, rtFocus.top, rtFocus.width, rtFocus.height); | |
| 196 } | |
| 197 m_rtFocus.Inflate(1, 1); | 154 m_rtFocus.Inflate(1, 1); |
| 198 } | 155 } |
| 199 | 156 |
| 200 uint32_t CFWL_CheckBox::GetPartStates() const { | 157 uint32_t CFWL_CheckBox::GetPartStates() const { |
| 201 int32_t dwStates = CFWL_PartState_Normal; | 158 int32_t dwStates = CFWL_PartState_Normal; |
| 202 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == | 159 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == |
| 203 FWL_STATE_CKB_Neutral) { | 160 FWL_STATE_CKB_Neutral) { |
| 204 dwStates = CFWL_PartState_Neutral; | 161 dwStates = CFWL_PartState_Neutral; |
| 205 } else if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == | 162 } else if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == |
| 206 FWL_STATE_CKB_Checked) { | 163 FWL_STATE_CKB_Checked) { |
| 207 dwStates = CFWL_PartState_Checked; | 164 dwStates = CFWL_PartState_Checked; |
| 208 } | 165 } |
| 209 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) | 166 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
| 210 dwStates |= CFWL_PartState_Disabled; | 167 dwStates |= CFWL_PartState_Disabled; |
| 211 else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) | 168 else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) |
| 212 dwStates |= CFWL_PartState_Hovered; | 169 dwStates |= CFWL_PartState_Hovered; |
| 213 else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) | 170 else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) |
| 214 dwStates |= CFWL_PartState_Pressed; | 171 dwStates |= CFWL_PartState_Pressed; |
| 215 else | 172 else |
| 216 dwStates |= CFWL_PartState_Normal; | 173 dwStates |= CFWL_PartState_Normal; |
| 217 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) | 174 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) |
| 218 dwStates |= CFWL_PartState_Focused; | 175 dwStates |= CFWL_PartState_Focused; |
| 219 return dwStates; | 176 return dwStates; |
| 220 } | 177 } |
| 221 | 178 |
| 222 void CFWL_CheckBox::UpdateTextOutStyles() { | 179 void CFWL_CheckBox::UpdateTextOutStyles() { |
| 223 switch (m_pProperties->m_dwStyleExes & | 180 m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; |
| 224 (FWL_STYLEEXT_CKB_HLayoutMask | FWL_STYLEEXT_CKB_VLayoutMask)) { | |
| 225 case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_Top: { | |
| 226 m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; | |
| 227 break; | |
| 228 } | |
| 229 case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_Top: { | |
| 230 m_iTTOAlign = FDE_TTOALIGNMENT_TopCenter; | |
| 231 break; | |
| 232 } | |
| 233 case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_Top: { | |
| 234 m_iTTOAlign = FDE_TTOALIGNMENT_TopRight; | |
| 235 break; | |
| 236 } | |
| 237 case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_VCenter: { | |
| 238 m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; | |
| 239 break; | |
| 240 } | |
| 241 case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_VCenter: { | |
| 242 m_iTTOAlign = FDE_TTOALIGNMENT_CenterRight; | |
| 243 break; | |
| 244 } | |
| 245 case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_Bottom: { | |
| 246 m_iTTOAlign = FDE_TTOALIGNMENT_BottomLeft; | |
| 247 break; | |
| 248 } | |
| 249 case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_Bottom: { | |
| 250 m_iTTOAlign = FDE_TTOALIGNMENT_BottomCenter; | |
| 251 break; | |
| 252 } | |
| 253 case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_Bottom: { | |
| 254 m_iTTOAlign = FDE_TTOALIGNMENT_BottomRight; | |
| 255 break; | |
| 256 } | |
| 257 case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_VCenter: | |
| 258 default: { | |
| 259 m_iTTOAlign = FDE_TTOALIGNMENT_Center; | |
| 260 break; | |
| 261 } | |
| 262 } | |
| 263 m_dwTTOStyles = 0; | 181 m_dwTTOStyles = 0; |
| 264 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) | 182 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) |
| 265 m_dwTTOStyles |= FDE_TTOSTYLE_RTL; | 183 m_dwTTOStyles |= FDE_TTOSTYLE_RTL; |
| 266 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) | 184 m_dwTTOStyles |= FDE_TTOSTYLE_SingleLine; |
| 267 m_dwTTOStyles |= FDE_TTOSTYLE_LineWrap; | |
| 268 else | |
| 269 m_dwTTOStyles |= FDE_TTOSTYLE_SingleLine; | |
| 270 } | 185 } |
| 271 | 186 |
| 272 void CFWL_CheckBox::NextStates() { | 187 void CFWL_CheckBox::NextStates() { |
| 273 uint32_t dwFirststate = m_pProperties->m_dwStates; | 188 uint32_t dwFirststate = m_pProperties->m_dwStates; |
| 274 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_RadioButton) { | 189 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_RadioButton) { |
| 275 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == | 190 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == |
| 276 FWL_STATE_CKB_Unchecked) { | 191 FWL_STATE_CKB_Unchecked) { |
| 277 CFWL_WidgetMgr* pWidgetMgr = GetOwnerApp()->GetWidgetMgr(); | 192 CFWL_WidgetMgr* pWidgetMgr = GetOwnerApp()->GetWidgetMgr(); |
| 278 if (!pWidgetMgr->IsFormDisabled()) { | 193 if (!pWidgetMgr->IsFormDisabled()) { |
| 279 CFX_ArrayTemplate<CFWL_Widget*> radioarr; | 194 CFX_ArrayTemplate<CFWL_Widget*> radioarr; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 } | 364 } |
| 450 | 365 |
| 451 void CFWL_CheckBox::OnKeyDown(CFWL_MessageKey* pMsg) { | 366 void CFWL_CheckBox::OnKeyDown(CFWL_MessageKey* pMsg) { |
| 452 if (pMsg->m_dwKeyCode == FWL_VKEY_Tab) | 367 if (pMsg->m_dwKeyCode == FWL_VKEY_Tab) |
| 453 return; | 368 return; |
| 454 if (pMsg->m_dwKeyCode == FWL_VKEY_Return || | 369 if (pMsg->m_dwKeyCode == FWL_VKEY_Return || |
| 455 pMsg->m_dwKeyCode == FWL_VKEY_Space) { | 370 pMsg->m_dwKeyCode == FWL_VKEY_Space) { |
| 456 NextStates(); | 371 NextStates(); |
| 457 } | 372 } |
| 458 } | 373 } |
| OLD | NEW |