7#include "xfa/fxfa/cxfa_ffcheckbutton.h"
9#include "core/fxcrt/check.h"
10#include "v8/include/cppgc/visitor.h"
11#include "xfa/fwl/cfwl_checkbox.h"
12#include "xfa/fwl/cfwl_messagemouse.h"
13#include "xfa/fwl/cfwl_notedriver.h"
14#include "xfa/fwl/cfwl_widgetmgr.h"
15#include "xfa/fxfa/cxfa_ffapp.h"
16#include "xfa/fxfa/cxfa_ffdoc.h"
17#include "xfa/fxfa/cxfa_ffdocview.h"
18#include "xfa/fxfa/cxfa_ffexclgroup.h"
19#include "xfa/fxfa/cxfa_fffield.h"
20#include "xfa/fxfa/cxfa_ffpageview.h"
21#include "xfa/fxfa/cxfa_ffwidget.h"
22#include "xfa/fxfa/parser/cxfa_border.h"
23#include "xfa/fxfa/parser/cxfa_caption.h"
24#include "xfa/fxfa/parser/cxfa_checkbutton.h"
25#include "xfa/fxfa/parser/cxfa_para.h"
27CXFA_FFCheckButton::CXFA_FFCheckButton(
CXFA_Node* pNode,
28 CXFA_CheckButton* button)
33void CXFA_FFCheckButton::
Trace(
cppgc::Visitor* visitor)
const {
34 CXFA_FFField::Trace(visitor);
35 visitor->Trace(m_pOldDelegate);
36 visitor->Trace(button_);
42 CFWL_CheckBox* pCheckBox = cppgc::MakeGarbageCollected<CFWL_CheckBox>(
43 GetFWLApp()->GetHeap()->GetAllocationHandle(), GetFWLApp());
47 CFWL_NoteDriver* pNoteDriver = pCheckBox
->GetFWLApp()->GetNoteDriver();
49 m_pOldDelegate = pCheckBox->GetDelegate();
51 if (m_pNode->IsRadioButton())
64 auto* pCheckBox =
static_cast<CFWL_CheckBox*>(GetNormalWidget());
68 pCheckBox->SetBoxSize(m_pNode->GetCheckButtonSize());
70 switch (button_->GetMark()) {
71 case XFA_AttributeValue::Check:
74 case XFA_AttributeValue::Circle:
77 case XFA_AttributeValue::Cross:
79 case XFA_AttributeValue::Diamond:
82 case XFA_AttributeValue::Square:
85 case XFA_AttributeValue::Star:
89 if (button_->IsRound())
93 if (button_->IsAllowNeutral())
96 pCheckBox->ModifyStyleExts(
103 float fCheckSize = m_pNode->GetCheckButtonSize();
104 CXFA_Margin* margin = m_pNode->GetMarginIfExists();
109 float fCapReserve = 0;
110 CXFA_Caption* caption = m_pNode->GetCaptionIfExists();
112 m_CaptionRect = rtWidget;
115 if (fCapReserve <= 0) {
118 fCapReserve = rtWidget
.height - fCheckSize;
120 fCapReserve = rtWidget
.width - fCheckSize;
127 CXFA_Para* para = m_pNode->GetParaIfExists();
135 switch (iCapPlacement) {
137 m_CaptionRect.width = fCapReserve;
138 CapLeftRightPlacement(captionMargin);
139 m_UIRect.width -= fCapReserve;
140 m_UIRect.left += fCapReserve;
144 m_CaptionRect.height = fCapReserve;
145 XFA_RectWithoutMargin(&m_CaptionRect, captionMargin);
146 m_UIRect.height -= fCapReserve;
147 m_UIRect.top += fCapReserve;
151 m_CaptionRect.left = m_CaptionRect.right() - fCapReserve;
152 m_CaptionRect.width = fCapReserve;
153 CapLeftRightPlacement(captionMargin);
154 m_UIRect.width -= fCapReserve;
158 m_CaptionRect.top = m_CaptionRect.bottom() - fCapReserve;
159 m_CaptionRect.height = fCapReserve;
160 XFA_RectWithoutMargin(&m_CaptionRect, captionMargin);
161 m_UIRect.height -= fCapReserve;
171 if (iHorzAlign == XFA_AttributeValue::Center)
172 m_UIRect.left += (m_UIRect.width - fCheckSize) / 2;
173 else if (iHorzAlign == XFA_AttributeValue::Right)
174 m_UIRect.left = m_UIRect.right() - fCheckSize;
176 if (iVertAlign == XFA_AttributeValue::Middle)
177 m_UIRect.top += (m_UIRect.height - fCheckSize) / 2;
178 else if (iVertAlign == XFA_AttributeValue::Bottom)
179 m_UIRect.top = m_UIRect.bottom() - fCheckSize;
181 m_UIRect.width = fCheckSize;
182 m_UIRect.height = fCheckSize;
183 AddUIMargin(iCapPlacement);
184 m_CheckBoxRect = m_UIRect;
185 CXFA_Border* borderUI = m_pNode->GetUIBorder();
188 XFA_RectWithoutMargin(&m_UIRect, borderMargin);
191 m_UIRect.Normalize();
194 if (GetNormalWidget())
195 GetNormalWidget()->Update();
200void CXFA_FFCheckButton::CapLeftRightPlacement(
201 const CXFA_Margin* captionMargin) {
202 XFA_RectWithoutMargin(&m_CaptionRect, captionMargin);
203 if (m_CaptionRect.height < 0)
204 m_CaptionRect.top += m_CaptionRect.height;
205 if (m_CaptionRect.width < 0) {
206 m_CaptionRect.left += m_CaptionRect.width;
207 m_CaptionRect.width = -m_CaptionRect.width;
212 CFX_RectF rtUIMargin = m_pNode->GetUIMargin();
213 m_UIRect.top -= rtUIMargin.top / 2 - rtUIMargin.height / 2;
215 float fLeftAddRight = rtUIMargin
.left + rtUIMargin
.width;
216 float fTopAddBottom = rtUIMargin
.top + rtUIMargin
.height;
217 if (m_UIRect.width < fLeftAddRight) {
220 m_UIRect.left -= fLeftAddRight - m_UIRect.width;
222 m_UIRect.left -= 2 * (fLeftAddRight - m_UIRect.width);
224 m_UIRect.width += 2 * (fLeftAddRight - m_UIRect.width);
226 if (m_UIRect.height < fTopAddBottom) {
227 if (iCapPlacement == XFA_AttributeValue::Right)
228 m_UIRect.left -= fTopAddBottom - m_UIRect.height;
230 m_UIRect.top -= fTopAddBottom - m_UIRect.height;
231 m_UIRect.height += 2 * (fTopAddBottom - m_UIRect.height);
249 button_->IsRound() ? kRoundShape : kSquareShape);
252 GetApp()->GetFWLWidgetMgr()->OnDrawWidget(GetNormalWidget(), pGS, mt);
261 CFWL_MessageMouse msg(GetNormalWidget(),
269 uint32_t dwState = GetNormalWidget()->GetStates();
278 m_pNode->SetCheckState(FWLState2XFAState());
284 return m_pNode->GetCheckState() != eCheckState;
297 if (!GetNormalWidget())
301 GetNormalWidget()->Update();
306 m_pOldDelegate->OnProcessMessage(pMessage);
314 eParam.m_wsPrevText = m_pNode->GetValue(XFA_ValuePicture::kRaw);
315 CXFA_Node* exclNode = m_pNode->GetExclGroupIfExists();
318 m_pDocView->AddValidateNode(exclNode);
319 m_pDocView->AddCalculateNode(exclNode);
323 m_pNode->ProcessEvent(GetDocView(), XFA_AttributeValue::Change,
332 m_pNode->ProcessEvent(GetDocView(), XFA_AttributeValue::Click, &eParam);
338 m_pOldDelegate->OnProcessEvent(pEvent);
343 m_pOldDelegate->OnDrawWidget(pGraphics, matrix);
347 return FormFieldType::kXFA_CheckBox;
#define FWL_STYLEEXT_CKB_SignShapeMask
#define FWL_STYLEEXT_CKB_SignShapeSquare
#define FWL_STATE_CKB_Neutral
#define FWL_STYLEEXT_CKB_SignShapeCheck
#define FWL_STYLEEXT_CKB_SignShapeStar
#define FWL_STATE_CKB_Checked
#define FWL_STYLEEXT_CKB_SignShapeCircle
#define FWL_STYLEEXT_CKB_3State
#define FWL_STYLEEXT_CKB_RadioButton
#define FWL_STYLEEXT_CKB_SignShapeDiamond
#define FWL_STYLEEXT_CKB_SignShapeCross
constexpr CFX_Matrix(float a1, float b1, float c1, float d1, float e1, float f1)
void Concat(const CFX_Matrix &right)
CXFA_Margin * GetMarginIfExists()
XFA_AttributeValue GetPlacementType()
CXFA_EventParam(XFA_EVENTTYPE type)
CXFA_FFField(CXFA_Node *pNode)
void OnProcessEvent(pdfium::CFWL_Event *pEvent) override
CFX_PointF FWLToClient(const CFX_PointF &point)
void DrawHighlight(CFGAS_GEGraphics *pGS, const CFX_Matrix &pMatrix, HighlightOption highlight, ShapeOption shape)
bool ProcessCommittedData()
virtual void SetFWLRect()
bool LoadWidget() override
void SetNormalWidget(CFWL_Widget *widget)
void RenderCaption(CFGAS_GEGraphics *pGS, const CFX_Matrix &pMatrix)
void SendMessageToFWLWidget(CFWL_Message *pMessage)
XFA_EventError ProcessEvent(CXFA_FFDocView *pDocView, XFA_AttributeValue iActivity, CXFA_EventParam *pEventParam)
CXFA_Margin * GetMarginIfExists() const
XFA_AttributeValue GetHorizontalAlign()
XFA_AttributeValue GetVerticalAlign()
void RegisterEventTarget(CFWL_Widget *pListener, CFWL_Widget *pEventSource)
CFX_PTemplate< float > CFX_PointF