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