| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 | |
| 7 #include "xfa/src/fwl/basewidget/fwl_checkboximp.h" | |
| 8 | |
| 9 #include <algorithm> | |
| 10 | |
| 11 #include "xfa/include/fwl/basewidget/fwl_checkbox.h" | |
| 12 #include "xfa/include/fwl/core/fwl_theme.h" | |
| 13 #include "xfa/src/fde/tto/fde_textout.h" | |
| 14 #include "xfa/src/fwl/core/fwl_noteimp.h" | |
| 15 #include "xfa/src/fwl/core/fwl_targetimp.h" | |
| 16 #include "xfa/src/fwl/core/fwl_widgetimp.h" | |
| 17 #include "xfa/src/fwl/core/fwl_widgetmgrimp.h" | |
| 18 | |
| 19 #define FWL_CKB_CaptionMargin 5 | |
| 20 | |
| 21 // static | |
| 22 IFWL_CheckBox* IFWL_CheckBox::Create(const CFWL_WidgetImpProperties& properties, | |
| 23 IFWL_Widget* pOuter) { | |
| 24 IFWL_CheckBox* pCheckBox = new IFWL_CheckBox; | |
| 25 CFWL_CheckBoxImp* pCheckBoxImpl = new CFWL_CheckBoxImp(properties, pOuter); | |
| 26 pCheckBox->SetImpl(pCheckBoxImpl); | |
| 27 pCheckBoxImpl->SetInterface(pCheckBox); | |
| 28 return pCheckBox; | |
| 29 } | |
| 30 IFWL_CheckBox::IFWL_CheckBox() {} | |
| 31 int32_t IFWL_CheckBox::GetCheckState() { | |
| 32 return static_cast<CFWL_CheckBoxImp*>(GetImpl())->GetCheckState(); | |
| 33 } | |
| 34 FWL_ERR IFWL_CheckBox::SetCheckState(int32_t iCheck) { | |
| 35 return static_cast<CFWL_CheckBoxImp*>(GetImpl())->SetCheckState(iCheck); | |
| 36 } | |
| 37 | |
| 38 CFWL_CheckBoxImp::CFWL_CheckBoxImp(const CFWL_WidgetImpProperties& properties, | |
| 39 IFWL_Widget* pOuter) | |
| 40 : CFWL_WidgetImp(properties, pOuter), | |
| 41 m_dwTTOStyles(FDE_TTOSTYLE_SingleLine), | |
| 42 m_iTTOAlign(FDE_TTOALIGNMENT_Center), | |
| 43 m_bBtnDown(FALSE) { | |
| 44 m_rtClient.Reset(); | |
| 45 m_rtBox.Reset(); | |
| 46 m_rtCaption.Reset(); | |
| 47 m_rtFocus.Reset(); | |
| 48 } | |
| 49 CFWL_CheckBoxImp::~CFWL_CheckBoxImp() {} | |
| 50 FWL_ERR CFWL_CheckBoxImp::GetClassName(CFX_WideString& wsClass) const { | |
| 51 wsClass = FWL_CLASS_CheckBox; | |
| 52 return FWL_ERR_Succeeded; | |
| 53 } | |
| 54 FX_DWORD CFWL_CheckBoxImp::GetClassID() const { | |
| 55 return FWL_CLASSHASH_CheckBox; | |
| 56 } | |
| 57 FWL_ERR CFWL_CheckBoxImp::Initialize() { | |
| 58 if (CFWL_WidgetImp::Initialize() != FWL_ERR_Succeeded) | |
| 59 return FWL_ERR_Indefinite; | |
| 60 m_pDelegate = new CFWL_CheckBoxImpDelegate(this); | |
| 61 return FWL_ERR_Succeeded; | |
| 62 } | |
| 63 FWL_ERR CFWL_CheckBoxImp::Finalize() { | |
| 64 delete m_pDelegate; | |
| 65 m_pDelegate = nullptr; | |
| 66 return CFWL_WidgetImp::Finalize(); | |
| 67 } | |
| 68 FWL_ERR CFWL_CheckBoxImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | |
| 69 if (bAutoSize) { | |
| 70 rect.Set(0, 0, 0, 0); | |
| 71 if (!m_pProperties->m_pThemeProvider) | |
| 72 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
| 73 if (!m_pProperties->m_pThemeProvider) | |
| 74 return FWL_ERR_Indefinite; | |
| 75 if (!m_pProperties->m_pDataProvider) | |
| 76 return FWL_ERR_Indefinite; | |
| 77 CFX_WideString wsCaption; | |
| 78 m_pProperties->m_pDataProvider->GetCaption(m_pInterface, wsCaption); | |
| 79 if (wsCaption.GetLength() > 0) { | |
| 80 CFX_SizeF sz = CalcTextSize( | |
| 81 wsCaption, m_pProperties->m_pThemeProvider, | |
| 82 m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine); | |
| 83 rect.Set(0, 0, sz.x, sz.y); | |
| 84 } | |
| 85 rect.Inflate(FWL_CKB_CaptionMargin, FWL_CKB_CaptionMargin); | |
| 86 IFWL_CheckBoxDP* pData = | |
| 87 static_cast<IFWL_CheckBoxDP*>(m_pProperties->m_pDataProvider); | |
| 88 FX_FLOAT fCheckBox = pData->GetBoxSize(m_pInterface); | |
| 89 rect.width += fCheckBox; | |
| 90 if (rect.height < fCheckBox) { | |
| 91 rect.height = fCheckBox; | |
| 92 } | |
| 93 CFWL_WidgetImp::GetWidgetRect(rect, TRUE); | |
| 94 } else { | |
| 95 rect = m_pProperties->m_rtWidget; | |
| 96 } | |
| 97 return FWL_ERR_Succeeded; | |
| 98 } | |
| 99 FWL_ERR CFWL_CheckBoxImp::Update() { | |
| 100 if (IsLocked()) { | |
| 101 return FWL_ERR_Indefinite; | |
| 102 } | |
| 103 if (!m_pProperties->m_pThemeProvider) { | |
| 104 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
| 105 } | |
| 106 UpdateTextOutStyles(); | |
| 107 Layout(); | |
| 108 return FWL_ERR_Succeeded; | |
| 109 } | |
| 110 FWL_ERR CFWL_CheckBoxImp::DrawWidget(CFX_Graphics* pGraphics, | |
| 111 const CFX_Matrix* pMatrix) { | |
| 112 if (!pGraphics) | |
| 113 return FWL_ERR_Indefinite; | |
| 114 if (!m_pProperties->m_pThemeProvider) | |
| 115 return FWL_ERR_Indefinite; | |
| 116 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | |
| 117 if (HasBorder()) { | |
| 118 DrawBorder(pGraphics, FWL_PART_CKB_Border, m_pProperties->m_pThemeProvider, | |
| 119 pMatrix); | |
| 120 } | |
| 121 if (HasEdge()) { | |
| 122 DrawEdge(pGraphics, FWL_PART_CKB_Edge, pTheme, pMatrix); | |
| 123 } | |
| 124 int32_t dwStates = GetPartStates(); | |
| 125 { | |
| 126 CFWL_ThemeBackground param; | |
| 127 param.m_pWidget = m_pInterface; | |
| 128 param.m_iPart = FWL_PART_CKB_Background; | |
| 129 param.m_dwStates = dwStates; | |
| 130 param.m_pGraphics = pGraphics; | |
| 131 if (pMatrix) { | |
| 132 param.m_matrix.Concat(*pMatrix); | |
| 133 } | |
| 134 param.m_rtPart = m_rtClient; | |
| 135 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) { | |
| 136 param.m_pData = &m_rtFocus; | |
| 137 } | |
| 138 pTheme->DrawBackground(¶m); | |
| 139 param.m_iPart = FWL_PART_CKB_CheckBox; | |
| 140 param.m_rtPart = m_rtBox; | |
| 141 pTheme->DrawBackground(¶m); | |
| 142 } | |
| 143 if (!m_pProperties->m_pDataProvider) | |
| 144 return FWL_ERR_Indefinite; | |
| 145 { | |
| 146 CFX_WideString wsCaption; | |
| 147 m_pProperties->m_pDataProvider->GetCaption(m_pInterface, wsCaption); | |
| 148 int32_t iLen = wsCaption.GetLength(); | |
| 149 if (iLen <= 0) | |
| 150 return FWL_ERR_Indefinite; | |
| 151 CFWL_ThemeText textParam; | |
| 152 textParam.m_pWidget = m_pInterface; | |
| 153 textParam.m_iPart = FWL_PART_CKB_Caption; | |
| 154 textParam.m_dwStates = dwStates; | |
| 155 textParam.m_pGraphics = pGraphics; | |
| 156 if (pMatrix) { | |
| 157 textParam.m_matrix.Concat(*pMatrix); | |
| 158 } | |
| 159 textParam.m_rtPart = m_rtCaption; | |
| 160 textParam.m_wsText = wsCaption; | |
| 161 textParam.m_dwTTOStyles = m_dwTTOStyles; | |
| 162 textParam.m_iTTOAlign = m_iTTOAlign; | |
| 163 pTheme->DrawText(&textParam); | |
| 164 } | |
| 165 return FWL_ERR_Succeeded; | |
| 166 } | |
| 167 int32_t CFWL_CheckBoxImp::GetCheckState() { | |
| 168 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) && | |
| 169 ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == | |
| 170 FWL_STATE_CKB_Neutral)) { | |
| 171 return 2; | |
| 172 } | |
| 173 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == | |
| 174 FWL_STATE_CKB_Checked) { | |
| 175 return 1; | |
| 176 } | |
| 177 return 0; | |
| 178 } | |
| 179 FWL_ERR CFWL_CheckBoxImp::SetCheckState(int32_t iCheck) { | |
| 180 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask; | |
| 181 switch (iCheck) { | |
| 182 case 0: { | |
| 183 break; | |
| 184 } | |
| 185 case 1: { | |
| 186 m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; | |
| 187 break; | |
| 188 } | |
| 189 case 2: { | |
| 190 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) { | |
| 191 m_pProperties->m_dwStates |= FWL_STATE_CKB_Neutral; | |
| 192 } | |
| 193 break; | |
| 194 } | |
| 195 default: {} | |
| 196 } | |
| 197 Repaint(&m_rtClient); | |
| 198 return FWL_ERR_Succeeded; | |
| 199 } | |
| 200 void CFWL_CheckBoxImp::Layout() { | |
| 201 int32_t width = int32_t(m_pProperties->m_rtWidget.width + 0.5f); | |
| 202 int32_t height = int32_t(m_pProperties->m_rtWidget.height + 0.5f); | |
| 203 m_pProperties->m_rtWidget.width = (FX_FLOAT)width; | |
| 204 m_pProperties->m_rtWidget.height = (FX_FLOAT)height; | |
| 205 GetClientRect(m_rtClient); | |
| 206 FX_FLOAT fBoxTop = m_rtClient.top; | |
| 207 FX_FLOAT fBoxLeft = m_rtClient.left; | |
| 208 FX_FLOAT fTextLeft = 0.0, fTextRight = 0.0; | |
| 209 FX_FLOAT fClientRight = m_rtClient.right(); | |
| 210 FX_FLOAT fClientBottom = m_rtClient.bottom(); | |
| 211 if (!m_pProperties->m_pDataProvider) | |
| 212 return; | |
| 213 IFWL_CheckBoxDP* pData = | |
| 214 static_cast<IFWL_CheckBoxDP*>(m_pProperties->m_pDataProvider); | |
| 215 FX_FLOAT fCheckBox = pData->GetBoxSize(m_pInterface); | |
| 216 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) { | |
| 217 case FWL_STYLEEXT_CKB_Top: { | |
| 218 fBoxTop = m_rtClient.top; | |
| 219 break; | |
| 220 } | |
| 221 case FWL_STYLEEXT_CKB_Bottom: { | |
| 222 fBoxTop = fClientBottom - fCheckBox; | |
| 223 break; | |
| 224 } | |
| 225 case FWL_STYLEEXT_CKB_VCenter: | |
| 226 default: { | |
| 227 fBoxTop = m_rtClient.top + (m_rtClient.height - fCheckBox) / 2; | |
| 228 fBoxTop = FXSYS_floor(fBoxTop); | |
| 229 } | |
| 230 } | |
| 231 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_LeftText) { | |
| 232 fBoxLeft = fClientRight - fCheckBox; | |
| 233 fTextLeft = m_rtClient.left; | |
| 234 fTextRight = fBoxLeft; | |
| 235 } else { | |
| 236 fTextLeft = fBoxLeft + fCheckBox; | |
| 237 fTextRight = fClientRight; | |
| 238 } | |
| 239 m_rtBox.Set(fBoxLeft, fBoxTop, fCheckBox, fCheckBox); | |
| 240 m_rtCaption.Set(fTextLeft, m_rtClient.top, fTextRight - fTextLeft, | |
| 241 m_rtClient.height); | |
| 242 m_rtCaption.Inflate(-FWL_CKB_CaptionMargin, -FWL_CKB_CaptionMargin); | |
| 243 CFX_RectF rtFocus; | |
| 244 rtFocus.Set(m_rtCaption.left, m_rtCaption.top, m_rtCaption.width, | |
| 245 m_rtCaption.height); | |
| 246 CFX_WideString wsCaption; | |
| 247 m_pProperties->m_pDataProvider->GetCaption(m_pInterface, wsCaption); | |
| 248 if (wsCaption.IsEmpty()) { | |
| 249 m_rtFocus.Set(0, 0, 0, 0); | |
| 250 } else { | |
| 251 CalcTextRect(wsCaption, m_pProperties->m_pThemeProvider, m_dwTTOStyles, | |
| 252 m_iTTOAlign, rtFocus); | |
| 253 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) == 0) { | |
| 254 FX_FLOAT fWidth = std::max(m_rtCaption.width, rtFocus.width); | |
| 255 FX_FLOAT fHeight = std::min(m_rtCaption.height, rtFocus.height); | |
| 256 FX_FLOAT fLeft = m_rtCaption.left; | |
| 257 FX_FLOAT fTop = m_rtCaption.top; | |
| 258 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_HLayoutMask) == | |
| 259 FWL_STYLEEXT_CKB_Center) { | |
| 260 fLeft = m_rtCaption.left + (m_rtCaption.width - fWidth) / 2; | |
| 261 } else if ((m_pProperties->m_dwStyleExes & | |
| 262 FWL_STYLEEXT_CKB_HLayoutMask) == FWL_STYLEEXT_CKB_Right) { | |
| 263 fLeft = m_rtCaption.right() - fWidth; | |
| 264 } | |
| 265 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_VLayoutMask) == | |
| 266 FWL_STYLEEXT_CKB_VCenter) { | |
| 267 fTop = m_rtCaption.top + (m_rtCaption.height - fHeight) / 2; | |
| 268 } else if ((m_pProperties->m_dwStyleExes & | |
| 269 FWL_STYLEEXT_CKB_VLayoutMask) == FWL_STYLEEXT_CKB_Bottom) { | |
| 270 fTop = m_rtCaption.bottom() - fHeight; | |
| 271 } | |
| 272 m_rtFocus.Set(fLeft, fTop, fWidth, fHeight); | |
| 273 } else { | |
| 274 m_rtFocus.Set(rtFocus.left, rtFocus.top, rtFocus.width, rtFocus.height); | |
| 275 } | |
| 276 m_rtFocus.Inflate(1, 1); | |
| 277 } | |
| 278 } | |
| 279 FX_DWORD CFWL_CheckBoxImp::GetPartStates() { | |
| 280 int32_t dwStates = FWL_PARTSTATE_CKB_UnChecked; | |
| 281 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == | |
| 282 FWL_STATE_CKB_Neutral) { | |
| 283 dwStates = FWL_PARTSTATE_CKB_Neutral; | |
| 284 } else if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == | |
| 285 FWL_STATE_CKB_Checked) { | |
| 286 dwStates = FWL_PARTSTATE_CKB_Checked; | |
| 287 } | |
| 288 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { | |
| 289 dwStates |= FWL_PARTSTATE_CKB_Disabled; | |
| 290 } else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) { | |
| 291 dwStates |= FWL_PARTSTATE_CKB_Hovered; | |
| 292 } else if (m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) { | |
| 293 dwStates |= FWL_PARTSTATE_CKB_Pressed; | |
| 294 } else { | |
| 295 dwStates |= FWL_PARTSTATE_CKB_Normal; | |
| 296 } | |
| 297 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) { | |
| 298 dwStates |= FWL_PARTSTATE_CKB_Focused; | |
| 299 } | |
| 300 return dwStates; | |
| 301 } | |
| 302 void CFWL_CheckBoxImp::UpdateTextOutStyles() { | |
| 303 m_iTTOAlign = FDE_TTOALIGNMENT_Center; | |
| 304 switch (m_pProperties->m_dwStyleExes & | |
| 305 (FWL_STYLEEXT_CKB_HLayoutMask | FWL_STYLEEXT_CKB_VLayoutMask)) { | |
| 306 case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_Top: { | |
| 307 m_iTTOAlign = FDE_TTOALIGNMENT_TopLeft; | |
| 308 break; | |
| 309 } | |
| 310 case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_Top: { | |
| 311 m_iTTOAlign = FDE_TTOALIGNMENT_TopCenter; | |
| 312 break; | |
| 313 } | |
| 314 case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_Top: { | |
| 315 m_iTTOAlign = FDE_TTOALIGNMENT_TopRight; | |
| 316 break; | |
| 317 } | |
| 318 case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_VCenter: { | |
| 319 m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; | |
| 320 break; | |
| 321 } | |
| 322 case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_VCenter: { | |
| 323 m_iTTOAlign = FDE_TTOALIGNMENT_Center; | |
| 324 break; | |
| 325 } | |
| 326 case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_VCenter: { | |
| 327 m_iTTOAlign = FDE_TTOALIGNMENT_CenterRight; | |
| 328 break; | |
| 329 } | |
| 330 case FWL_STYLEEXT_CKB_Left | FWL_STYLEEXT_CKB_Bottom: { | |
| 331 m_iTTOAlign = FDE_TTOALIGNMENT_BottomLeft; | |
| 332 break; | |
| 333 } | |
| 334 case FWL_STYLEEXT_CKB_Center | FWL_STYLEEXT_CKB_Bottom: { | |
| 335 m_iTTOAlign = FDE_TTOALIGNMENT_BottomCenter; | |
| 336 break; | |
| 337 } | |
| 338 case FWL_STYLEEXT_CKB_Right | FWL_STYLEEXT_CKB_Bottom: { | |
| 339 m_iTTOAlign = FDE_TTOALIGNMENT_BottomRight; | |
| 340 break; | |
| 341 } | |
| 342 default: {} | |
| 343 } | |
| 344 m_dwTTOStyles = 0; | |
| 345 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) { | |
| 346 m_dwTTOStyles |= FDE_TTOSTYLE_RTL; | |
| 347 } | |
| 348 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_MultiLine) { | |
| 349 m_dwTTOStyles |= FDE_TTOSTYLE_LineWrap; | |
| 350 } else { | |
| 351 m_dwTTOStyles |= FDE_TTOSTYLE_SingleLine; | |
| 352 } | |
| 353 } | |
| 354 void CFWL_CheckBoxImp::NextStates() { | |
| 355 FX_DWORD dwFirststate = m_pProperties->m_dwStates; | |
| 356 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_RadioButton) { | |
| 357 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == | |
| 358 FWL_STATE_CKB_Unchecked) { | |
| 359 CFWL_WidgetMgr* pWidgetMgr = | |
| 360 static_cast<CFWL_WidgetMgr*>(FWL_GetWidgetMgr()); | |
| 361 if (!pWidgetMgr->IsFormDisabled()) { | |
| 362 CFX_PtrArray radioarr; | |
| 363 pWidgetMgr->GetSameGroupRadioButton(m_pInterface, radioarr); | |
| 364 IFWL_CheckBox* pCheckBox = NULL; | |
| 365 int32_t iCount = radioarr.GetSize(); | |
| 366 for (int32_t i = 0; i < iCount; i++) { | |
| 367 pCheckBox = static_cast<IFWL_CheckBox*>(radioarr[i]); | |
| 368 if (pCheckBox != m_pInterface && | |
| 369 pCheckBox->GetStates() & FWL_STATE_CKB_Checked) { | |
| 370 pCheckBox->SetCheckState(0); | |
| 371 CFX_RectF rt; | |
| 372 pCheckBox->GetWidgetRect(rt); | |
| 373 rt.left = rt.top = 0; | |
| 374 m_pWidgetMgr->RepaintWidget(pCheckBox, &rt); | |
| 375 break; | |
| 376 } | |
| 377 } | |
| 378 } | |
| 379 m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; | |
| 380 } | |
| 381 } else { | |
| 382 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == | |
| 383 FWL_STATE_CKB_Neutral) { | |
| 384 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask; | |
| 385 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) { | |
| 386 m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; | |
| 387 } | |
| 388 } else if ((m_pProperties->m_dwStates & FWL_STATE_CKB_CheckMask) == | |
| 389 FWL_STATE_CKB_Checked) { | |
| 390 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_CheckMask; | |
| 391 } else { | |
| 392 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CKB_3State) { | |
| 393 m_pProperties->m_dwStates |= FWL_STATE_CKB_Neutral; | |
| 394 } else { | |
| 395 m_pProperties->m_dwStates |= FWL_STATE_CKB_Checked; | |
| 396 } | |
| 397 } | |
| 398 } | |
| 399 Repaint(&m_rtClient); | |
| 400 FX_DWORD dwLaststate = m_pProperties->m_dwStates; | |
| 401 if (dwFirststate != dwLaststate) { | |
| 402 CFWL_EvtCkbCheckStateChanged wmCheckBoxState; | |
| 403 wmCheckBoxState.m_pSrcTarget = m_pInterface; | |
| 404 DispatchEvent(&wmCheckBoxState); | |
| 405 } | |
| 406 } | |
| 407 CFWL_CheckBoxImpDelegate::CFWL_CheckBoxImpDelegate(CFWL_CheckBoxImp* pOwner) | |
| 408 : m_pOwner(pOwner) {} | |
| 409 int32_t CFWL_CheckBoxImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
| 410 if (!pMessage) | |
| 411 return 0; | |
| 412 FX_DWORD dwMsgCode = pMessage->GetClassID(); | |
| 413 int32_t iRet = 1; | |
| 414 switch (dwMsgCode) { | |
| 415 case FWL_MSGHASH_Activate: { | |
| 416 OnActivate(pMessage); | |
| 417 break; | |
| 418 } | |
| 419 case FWL_MSGHASH_SetFocus: | |
| 420 case FWL_MSGHASH_KillFocus: { | |
| 421 OnFocusChanged(pMessage, dwMsgCode == FWL_MSGHASH_SetFocus); | |
| 422 break; | |
| 423 } | |
| 424 case FWL_MSGHASH_Mouse: { | |
| 425 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | |
| 426 FX_DWORD dwCmd = pMsg->m_dwCmd; | |
| 427 switch (dwCmd) { | |
| 428 case FWL_MSGMOUSECMD_LButtonDown: { | |
| 429 OnLButtonDown(pMsg); | |
| 430 break; | |
| 431 } | |
| 432 case FWL_MSGMOUSECMD_LButtonUp: { | |
| 433 OnLButtonUp(pMsg); | |
| 434 break; | |
| 435 } | |
| 436 case FWL_MSGMOUSECMD_MouseMove: { | |
| 437 OnMouseMove(pMsg); | |
| 438 break; | |
| 439 } | |
| 440 case FWL_MSGMOUSECMD_MouseLeave: { | |
| 441 OnMouseLeave(pMsg); | |
| 442 break; | |
| 443 } | |
| 444 default: {} | |
| 445 } | |
| 446 break; | |
| 447 } | |
| 448 case FWL_MSGHASH_Key: { | |
| 449 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); | |
| 450 if (pKey->m_dwCmd == FWL_MSGKEYCMD_KeyDown) { | |
| 451 OnKeyDown(pKey); | |
| 452 } | |
| 453 break; | |
| 454 } | |
| 455 default: { iRet = 0; } | |
| 456 } | |
| 457 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); | |
| 458 return iRet; | |
| 459 } | |
| 460 FWL_ERR CFWL_CheckBoxImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | |
| 461 const CFX_Matrix* pMatrix) { | |
| 462 return m_pOwner->DrawWidget(pGraphics, pMatrix); | |
| 463 } | |
| 464 void CFWL_CheckBoxImpDelegate::OnActivate(CFWL_Message* pMsg) { | |
| 465 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Deactivated; | |
| 466 m_pOwner->Repaint(&(m_pOwner->m_rtClient)); | |
| 467 } | |
| 468 void CFWL_CheckBoxImpDelegate::OnFocusChanged(CFWL_Message* pMsg, | |
| 469 FX_BOOL bSet) { | |
| 470 if (bSet) { | |
| 471 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | |
| 472 } else { | |
| 473 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | |
| 474 } | |
| 475 m_pOwner->Repaint(&(m_pOwner->m_rtClient)); | |
| 476 } | |
| 477 void CFWL_CheckBoxImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { | |
| 478 if (m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { | |
| 479 return; | |
| 480 } | |
| 481 if ((m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) { | |
| 482 m_pOwner->SetFocus(TRUE); | |
| 483 } | |
| 484 m_pOwner->m_bBtnDown = TRUE; | |
| 485 m_pOwner->m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; | |
| 486 m_pOwner->m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; | |
| 487 m_pOwner->Repaint(&(m_pOwner->m_rtClient)); | |
| 488 } | |
| 489 void CFWL_CheckBoxImpDelegate::OnLButtonUp(CFWL_MsgMouse* pMsg) { | |
| 490 if (!m_pOwner->m_bBtnDown) { | |
| 491 return; | |
| 492 } | |
| 493 m_pOwner->m_bBtnDown = FALSE; | |
| 494 if (!m_pOwner->m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 495 return; | |
| 496 } | |
| 497 m_pOwner->m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; | |
| 498 m_pOwner->m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Pressed; | |
| 499 m_pOwner->NextStates(); | |
| 500 } | |
| 501 void CFWL_CheckBoxImpDelegate::OnMouseMove(CFWL_MsgMouse* pMsg) { | |
| 502 if (m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { | |
| 503 return; | |
| 504 } | |
| 505 FX_BOOL bRepaint = FALSE; | |
| 506 if (m_pOwner->m_bBtnDown) { | |
| 507 if (m_pOwner->m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 508 if ((m_pOwner->m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) == 0) { | |
| 509 bRepaint = TRUE; | |
| 510 m_pOwner->m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; | |
| 511 } | |
| 512 if ((m_pOwner->m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered)) { | |
| 513 bRepaint = TRUE; | |
| 514 m_pOwner->m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; | |
| 515 } | |
| 516 } else { | |
| 517 if (m_pOwner->m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) { | |
| 518 bRepaint = TRUE; | |
| 519 m_pOwner->m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Pressed; | |
| 520 } | |
| 521 if ((m_pOwner->m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) == 0) { | |
| 522 bRepaint = TRUE; | |
| 523 m_pOwner->m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; | |
| 524 } | |
| 525 } | |
| 526 } else { | |
| 527 if (m_pOwner->m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 528 if ((m_pOwner->m_pProperties->m_dwStates & FWL_STATE_CKB_Hovered) == 0) { | |
| 529 bRepaint = TRUE; | |
| 530 m_pOwner->m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; | |
| 531 } | |
| 532 } | |
| 533 } | |
| 534 if (bRepaint) { | |
| 535 m_pOwner->Repaint(&(m_pOwner->m_rtBox)); | |
| 536 } | |
| 537 } | |
| 538 void CFWL_CheckBoxImpDelegate::OnMouseLeave(CFWL_MsgMouse* pMsg) { | |
| 539 if (m_pOwner->m_bBtnDown) { | |
| 540 m_pOwner->m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; | |
| 541 } else { | |
| 542 m_pOwner->m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; | |
| 543 } | |
| 544 m_pOwner->Repaint(&(m_pOwner->m_rtBox)); | |
| 545 } | |
| 546 void CFWL_CheckBoxImpDelegate::OnKeyDown(CFWL_MsgKey* pMsg) { | |
| 547 if (pMsg->m_dwKeyCode == FWL_VKEY_Tab) { | |
| 548 m_pOwner->DispatchKeyEvent(pMsg); | |
| 549 return; | |
| 550 } | |
| 551 if (pMsg->m_dwKeyCode == FWL_VKEY_Return || | |
| 552 pMsg->m_dwKeyCode == FWL_VKEY_Space) { | |
| 553 m_pOwner->NextStates(); | |
| 554 } | |
| 555 } | |
| OLD | NEW |