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 #ifndef XFA_FWL_CFWL_CHECKBOX_H_
8 #define XFA_FWL_CFWL_CHECKBOX_H_
9 
10 #include "xfa/fwl/cfwl_event.h"
11 #include "xfa/fwl/cfwl_widget.h"
12 #include "xfa/fwl/cfwl_widgetproperties.h"
13 
14 #define FWL_STYLEEXT_CKB_3State (1L << 6)
15 #define FWL_STYLEEXT_CKB_RadioButton (1L << 7)
16 #define FWL_STYLEEXT_CKB_SignShapeCheck 0
17 #define FWL_STYLEEXT_CKB_SignShapeCircle (1L << 10)
18 #define FWL_STYLEEXT_CKB_SignShapeCross (2L << 10)
19 #define FWL_STYLEEXT_CKB_SignShapeDiamond (3L << 10)
20 #define FWL_STYLEEXT_CKB_SignShapeSquare (4L << 10)
21 #define FWL_STYLEEXT_CKB_SignShapeStar (5L << 10)
22 #define FWL_STYLEEXT_CKB_SignShapeMask (7L << 10)
23 #define FWL_STATE_CKB_Hovered (1 << FWL_WGTSTATE_MAX)
24 #define FWL_STATE_CKB_Pressed (1 << (FWL_WGTSTATE_MAX + 1))
25 #define FWL_STATE_CKB_Unchecked 0
26 #define FWL_STATE_CKB_Checked (1 << (FWL_WGTSTATE_MAX + 2))
27 #define FWL_STATE_CKB_Neutral (2 << (FWL_WGTSTATE_MAX + 2))
28 #define FWL_STATE_CKB_CheckMask (3L << (FWL_WGTSTATE_MAX + 2))
29 
30 class CFWL_MessageMouse;
31 class CFWL_WidgetProperties;
32 class CFWL_Widget;
33 
34 class CFWL_CheckBox final : public CFWL_Widget {
35  public:
36   explicit CFWL_CheckBox(const CFWL_App* pApp);
37   ~CFWL_CheckBox() override;
38 
39   // CFWL_Widget
40   FWL_Type GetClassID() const override;
41   void Update() override;
42   void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
43 
44   void OnProcessMessage(CFWL_Message* pMessage) override;
45   void OnDrawWidget(CXFA_Graphics* pGraphics,
46                     const CFX_Matrix& matrix) override;
47 
48   void SetBoxSize(float fHeight);
49 
50  private:
51   void SetCheckState(int32_t iCheck);
52   void Layout();
53   uint32_t GetPartStates() const;
54   void UpdateTextOutStyles();
55   void NextStates();
56   void OnFocusChanged(bool bSet);
57   void OnLButtonDown();
58   void OnLButtonUp(CFWL_MessageMouse* pMsg);
59   void OnMouseMove(CFWL_MessageMouse* pMsg);
60   void OnMouseLeave();
61   void OnKeyDown(CFWL_MessageKey* pMsg);
62 
63   CFX_RectF m_rtClient;
64   CFX_RectF m_rtBox;
65   CFX_RectF m_rtCaption;
66   CFX_RectF m_rtFocus;
67   FDE_TextStyle m_TTOStyles;
68   FDE_TextAlignment m_iTTOAlign = FDE_TextAlignment::kCenter;
69   bool m_bBtnDown = false;
70   float m_fBoxHeight = 16.0f;
71 };
72 
73 #endif  // XFA_FWL_CFWL_CHECKBOX_H_
74