Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cxfa_ffcheckbutton.cpp
Go to the documentation of this file.
1// Copyright 2014 The PDFium Authors
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/fxfa/cxfa_ffcheckbutton.h"
8
9#include "third_party/base/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"
26
27CXFA_FFCheckButton::CXFA_FFCheckButton(CXFA_Node* pNode,
28 CXFA_CheckButton* button)
29 : CXFA_FFField(pNode), button_(button) {}
30
31CXFA_FFCheckButton::~CXFA_FFCheckButton() = default;
32
33void CXFA_FFCheckButton::Trace(cppgc::Visitor* visitor) const {
34 CXFA_FFField::Trace(visitor);
35 visitor->Trace(m_pOldDelegate);
36 visitor->Trace(button_);
37}
38
39bool CXFA_FFCheckButton::LoadWidget() {
40 DCHECK(!IsLoaded());
41
42 CFWL_CheckBox* pCheckBox = cppgc::MakeGarbageCollected<CFWL_CheckBox>(
43 GetFWLApp()->GetHeap()->GetAllocationHandle(), GetFWLApp());
44 SetNormalWidget(pCheckBox);
45 pCheckBox->SetAdapterIface(this);
46
47 CFWL_NoteDriver* pNoteDriver = pCheckBox->GetFWLApp()->GetNoteDriver();
48 pNoteDriver->RegisterEventTarget(pCheckBox, pCheckBox);
49 m_pOldDelegate = pCheckBox->GetDelegate();
50 pCheckBox->SetDelegate(this);
51 if (m_pNode->IsRadioButton())
53
54 {
55 CFWL_Widget::ScopedUpdateLock update_lock(pCheckBox);
57 SetFWLCheckState(m_pNode->GetCheckState());
58 }
59
61}
62
63void CXFA_FFCheckButton::UpdateWidgetProperty() {
64 auto* pCheckBox = static_cast<CFWL_CheckBox*>(GetNormalWidget());
65 if (!pCheckBox)
66 return;
67
68 pCheckBox->SetBoxSize(m_pNode->GetCheckButtonSize());
69 uint32_t dwStyleEx = FWL_STYLEEXT_CKB_SignShapeCross;
70 switch (button_->GetMark()) {
71 case XFA_AttributeValue::Check:
73 break;
74 case XFA_AttributeValue::Circle:
76 break;
77 case XFA_AttributeValue::Cross:
78 break;
79 case XFA_AttributeValue::Diamond:
81 break;
82 case XFA_AttributeValue::Square:
84 break;
85 case XFA_AttributeValue::Star:
87 break;
88 default: {
89 if (button_->IsRound())
91 } break;
92 }
93 if (button_->IsAllowNeutral())
94 dwStyleEx |= FWL_STYLEEXT_CKB_3State;
95
96 pCheckBox->ModifyStyleExts(
98}
99
100bool CXFA_FFCheckButton::PerformLayout() {
102
103 float fCheckSize = m_pNode->GetCheckButtonSize();
104 CXFA_Margin* margin = m_pNode->GetMarginIfExists();
105 CFX_RectF rtWidget = GetRectWithoutRotate();
106 XFA_RectWithoutMargin(&rtWidget, margin);
107
108 XFA_AttributeValue iCapPlacement = XFA_AttributeValue::Unknown;
109 float fCapReserve = 0;
110 CXFA_Caption* caption = m_pNode->GetCaptionIfExists();
111 if (caption && caption->IsVisible()) {
112 m_CaptionRect = rtWidget;
113 iCapPlacement = caption->GetPlacementType();
114 fCapReserve = caption->GetReserve();
115 if (fCapReserve <= 0) {
116 if (iCapPlacement == XFA_AttributeValue::Top ||
117 iCapPlacement == XFA_AttributeValue::Bottom) {
118 fCapReserve = rtWidget.height - fCheckSize;
119 } else {
120 fCapReserve = rtWidget.width - fCheckSize;
121 }
122 }
123 }
124
125 XFA_AttributeValue iHorzAlign = XFA_AttributeValue::Left;
126 XFA_AttributeValue iVertAlign = XFA_AttributeValue::Top;
127 CXFA_Para* para = m_pNode->GetParaIfExists();
128 if (para) {
129 iHorzAlign = para->GetHorizontalAlign();
130 iVertAlign = para->GetVerticalAlign();
131 }
132
133 m_UIRect = rtWidget;
134 CXFA_Margin* captionMargin = caption ? caption->GetMarginIfExists() : nullptr;
135 switch (iCapPlacement) {
136 case XFA_AttributeValue::Left: {
137 m_CaptionRect.width = fCapReserve;
138 CapLeftRightPlacement(captionMargin);
139 m_UIRect.width -= fCapReserve;
140 m_UIRect.left += fCapReserve;
141 break;
142 }
143 case XFA_AttributeValue::Top: {
144 m_CaptionRect.height = fCapReserve;
146 m_UIRect.height -= fCapReserve;
147 m_UIRect.top += fCapReserve;
148 break;
149 }
150 case XFA_AttributeValue::Right: {
152 m_CaptionRect.width = fCapReserve;
153 CapLeftRightPlacement(captionMargin);
154 m_UIRect.width -= fCapReserve;
155 break;
156 }
157 case XFA_AttributeValue::Bottom: {
159 m_CaptionRect.height = fCapReserve;
161 m_UIRect.height -= fCapReserve;
162 break;
163 }
164 case XFA_AttributeValue::Inline:
165 break;
166 default:
167 iHorzAlign = XFA_AttributeValue::Right;
168 break;
169 }
170
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;
175
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;
180
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();
186 if (borderUI) {
187 CXFA_Margin* borderMargin = borderUI->GetMarginIfExists();
189 }
190
193 SetFWLRect();
194 if (GetNormalWidget())
195 GetNormalWidget()->Update();
196
197 return true;
198}
199
200void CXFA_FFCheckButton::CapLeftRightPlacement(
201 const CXFA_Margin* captionMargin) {
203 if (m_CaptionRect.height < 0)
205 if (m_CaptionRect.width < 0) {
208 }
209}
210
211void CXFA_FFCheckButton::AddUIMargin(XFA_AttributeValue iCapPlacement) {
212 CFX_RectF rtUIMargin = m_pNode->GetUIMargin();
213 m_UIRect.top -= rtUIMargin.top / 2 - rtUIMargin.height / 2;
214
215 float fLeftAddRight = rtUIMargin.left + rtUIMargin.width;
216 float fTopAddBottom = rtUIMargin.top + rtUIMargin.height;
217 if (m_UIRect.width < fLeftAddRight) {
218 if (iCapPlacement == XFA_AttributeValue::Right ||
219 iCapPlacement == XFA_AttributeValue::Left) {
220 m_UIRect.left -= fLeftAddRight - m_UIRect.width;
221 } else {
222 m_UIRect.left -= 2 * (fLeftAddRight - m_UIRect.width);
223 }
224 m_UIRect.width += 2 * (fLeftAddRight - m_UIRect.width);
225 }
226 if (m_UIRect.height < fTopAddBottom) {
227 if (iCapPlacement == XFA_AttributeValue::Right)
228 m_UIRect.left -= fTopAddBottom - m_UIRect.height;
229
230 m_UIRect.top -= fTopAddBottom - m_UIRect.height;
231 m_UIRect.height += 2 * (fTopAddBottom - m_UIRect.height);
232 }
233}
234
235void CXFA_FFCheckButton::RenderWidget(CFGAS_GEGraphics* pGS,
236 const CFX_Matrix& matrix,
237 HighlightOption highlight) {
238 if (!HasVisibleStatus())
239 return;
240
241 CFX_Matrix mtRotate = GetRotateMatrix();
242 mtRotate.Concat(matrix);
243
244 CXFA_FFWidget::RenderWidget(pGS, mtRotate, highlight);
245 DrawBorderWithFlag(pGS, m_pNode->GetUIBorder(), m_UIRect, mtRotate,
246 button_->IsRound());
247 RenderCaption(pGS, mtRotate);
248 DrawHighlight(pGS, mtRotate, highlight,
249 button_->IsRound() ? kRoundShape : kSquareShape);
250 CFX_Matrix mt(1, 0, 0, 1, m_CheckBoxRect.left, m_CheckBoxRect.top);
251 mt.Concat(mtRotate);
252 GetApp()->GetFWLWidgetMgr()->OnDrawWidget(GetNormalWidget(), pGS, mt);
253}
254
255bool CXFA_FFCheckButton::OnLButtonUp(Mask<XFA_FWL_KeyFlag> dwFlags,
256 const CFX_PointF& point) {
257 if (!GetNormalWidget() || !IsButtonDown())
258 return false;
259
260 SetButtonDown(false);
261 CFWL_MessageMouse msg(GetNormalWidget(),
262 CFWL_MessageMouse::MouseCommand::kLeftButtonUp, dwFlags,
263 FWLToClient(point));
265 return true;
266}
267
268XFA_CheckState CXFA_FFCheckButton::FWLState2XFAState() {
269 uint32_t dwState = GetNormalWidget()->GetStates();
270 if (dwState & FWL_STATE_CKB_Checked)
271 return XFA_CheckState::kOn;
272 if (dwState & FWL_STATE_CKB_Neutral)
275}
276
277bool CXFA_FFCheckButton::CommitData() {
278 m_pNode->SetCheckState(FWLState2XFAState());
279 return true;
280}
281
282bool CXFA_FFCheckButton::IsDataChanged() {
283 XFA_CheckState eCheckState = FWLState2XFAState();
284 return m_pNode->GetCheckState() != eCheckState;
285}
286
287void CXFA_FFCheckButton::SetFWLCheckState(XFA_CheckState eCheckState) {
288 if (eCheckState == XFA_CheckState::kNeutral)
289 GetNormalWidget()->SetStates(FWL_STATE_CKB_Neutral);
290 else if (eCheckState == XFA_CheckState::kOn)
291 GetNormalWidget()->SetStates(FWL_STATE_CKB_Checked);
292 else
293 GetNormalWidget()->RemoveStates(FWL_STATE_CKB_Checked);
294}
295
296bool CXFA_FFCheckButton::UpdateFWLData() {
297 if (!GetNormalWidget())
298 return false;
299
300 SetFWLCheckState(m_pNode->GetCheckState());
301 GetNormalWidget()->Update();
302 return true;
303}
304
305void CXFA_FFCheckButton::OnProcessMessage(CFWL_Message* pMessage) {
306 m_pOldDelegate->OnProcessMessage(pMessage);
307}
308
309void CXFA_FFCheckButton::OnProcessEvent(CFWL_Event* pEvent) {
311 switch (pEvent->GetType()) {
314 eParam.m_wsPrevText = m_pNode->GetValue(XFA_ValuePicture::kRaw);
315 CXFA_Node* exclNode = m_pNode->GetExclGroupIfExists();
316 if (ProcessCommittedData()) {
317 if (exclNode) {
318 m_pDocView->AddValidateNode(exclNode);
319 m_pDocView->AddCalculateNode(exclNode);
321 &eParam);
322 }
323 m_pNode->ProcessEvent(GetDocView(), XFA_AttributeValue::Change,
324 &eParam);
325 } else {
326 SetFWLCheckState(m_pNode->GetCheckState());
327 }
328 if (exclNode) {
330 &eParam);
331 }
332 m_pNode->ProcessEvent(GetDocView(), XFA_AttributeValue::Click, &eParam);
333 break;
334 }
335 default:
336 break;
337 }
338 m_pOldDelegate->OnProcessEvent(pEvent);
339}
340
341void CXFA_FFCheckButton::OnDrawWidget(CFGAS_GEGraphics* pGraphics,
342 const CFX_Matrix& matrix) {
343 m_pOldDelegate->OnDrawWidget(pGraphics, matrix);
344}
345
346FormFieldType CXFA_FFCheckButton::GetFormFieldType() {
347 return FormFieldType::kXFA_CheckBox;
348}
#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
Type GetType() const
Definition cfwl_event.h:39
void RegisterEventTarget(CFWL_Widget *pListener, CFWL_Widget *pEventSource)
void SetDelegate(IFWL_WidgetDelegate *delegate)
void SetAdapterIface(AdapterIface *pItem)
virtual void ModifyStyleExts(uint32_t dwStyleExtsAdded, uint32_t dwStyleExtsRemoved)
CFWL_App * GetFWLApp() const
CFX_Matrix(float a1, float b1, float c1, float d1, float e1, float f1)
void Concat(const CFX_Matrix &right)
CFX_RectF & operator=(const CFX_RectF &other)=default
float bottom() const
void Normalize()
float right() const
float GetReserve() const
CXFA_Margin * GetMarginIfExists()
XFA_AttributeValue GetPlacementType()
CXFA_EventParam(XFA_EVENTTYPE type)
bool IsDataChanged() override
void Trace(cppgc::Visitor *visitor) const override
void SetFWLCheckState(XFA_CheckState eCheckState)
void UpdateWidgetProperty() override
bool PerformLayout() override
FormFieldType GetFormFieldType() override
bool OnLButtonUp(Mask< XFA_FWL_KeyFlag > dwFlags, const CFX_PointF &point) override
void OnProcessMessage(CFWL_Message *pMessage) override
void OnDrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
bool UpdateFWLData() override
bool LoadWidget() override
~CXFA_FFCheckButton() override
void RenderWidget(CFGAS_GEGraphics *pGS, const CFX_Matrix &matrix, HighlightOption highlight) override
void OnProcessEvent(CFWL_Event *pEvent) override
CXFA_FFField(CXFA_Node *pNode)
CFX_PointF FWLToClient(const CFX_PointF &point)
CFX_RectF m_UIRect
bool ProcessCommittedData()
virtual void SetFWLRect()
bool LoadWidget() override
void SetNormalWidget(CFWL_Widget *widget)
void OnProcessEvent(CFWL_Event *pEvent) override
void RenderCaption(CFGAS_GEGraphics *pGS, const CFX_Matrix &pMatrix)
CFX_RectF m_CaptionRect
void SendMessageToFWLWidget(CFWL_Message *pMessage)
CFX_Matrix GetRotateMatrix() override
virtual bool PerformLayout()
virtual void RenderWidget(CFGAS_GEGraphics *pGS, const CFX_Matrix &matrix, HighlightOption highlight)
bool HasVisibleStatus() const
void SetButtonDown(bool bSet)
CXFA_FFApp * GetApp()
CFX_RectF GetRectWithoutRotate()
CXFA_FFDocView * GetDocView() const
XFA_EventError ProcessEvent(CXFA_FFDocView *pDocView, XFA_AttributeValue iActivity, CXFA_EventParam *pEventParam)
CXFA_Margin * GetMarginIfExists() const
XFA_AttributeValue GetHorizontalAlign()
Definition cxfa_para.cpp:57
XFA_AttributeValue GetVerticalAlign()
Definition cxfa_para.cpp:63
FormFieldType
@ XFA_EVENT_Change
void XFA_RectWithoutMargin(CFX_RectF *rt, const CXFA_Margin *margin)
XFA_CheckState
Definition cxfa_node.h:64
XFA_FWL_KeyFlag
XFA_AttributeValue
Definition fxfa_basic.h:60
Definition heap.h:12